Monday, July 10, 2006

Oops. Found quite a few issues with the Zero UI. The builds that I posted on my site on July 8th have a few known issues. Nobody has complained yet, though.

Anyway, here's a piece of code that I wrote in the process of fixing things.


/**
* Pick the first available monospace font in a widget's
* Pango context
*/
bool
get_monospace_font(Pango::FontDescription& font, Gtk::Widget& w)
{
bool success = false;

if (Glib::RefPtr<Pango::Context> ctxt = w.get_pango_context())
{
Glib::ArrayHandle<Glib::RefPtr<Pango::FontFamily> > ff =
ctxt->list_families();

Glib::ArrayHandle<Glib::RefPtr<
Pango::FontFamily> >::const_iterator
i = ff.begin(), end = ff.end();

for (; i != end; ++i)
{
if ((*i)->is_monospace())
{
font = Pango::FontDescription((*i)->get_name());

w.ensure_style();
if (Glib::RefPtr <Gtk::Style> style = w.get_style())
{
font.merge(style->get_font(), false);
}
if (Glib::RefPtr<Pango::Font> f = ctxt->load_font(font))
{
font = f->describe();
}
success = true;
break;
}
}
}
return success;
}



Note to self: write a sed script for "fixing" templates and pointers in code snippets posted on this blog.

Second note to self: make a custom T-shirt on Zazzle, printed with said sed script.

No comments: