GNOME Bugzilla – Bug 92511
Pango::Context::set_font_description causes app to abort when layout is drawn
Last modified: 2004-12-22 21:47:04 UTC
if i try to change the font using a pango context, the app aborts when i try to draw the pango layout. here is some example code: Gtk::Window* pWin = NULL; // excuse the global...it's just a test app typedef Glib::ArrayHandle< Glib::RefPtr<Pango::FontFamily> > tFontList; bool draw(GdkEventExpose* pEvent) { // ------------------------------------------------------------------- // this is the only way that works and allows you to change the font: // ------------------------------------------------------------------- // // Glib::RefPtr<Pango::Layout> pLayout = // pWin->create_pango_layout("Pango Test Application"); // Pango::FontDescription font("fixed"); // pLayout->set_font_description(font); // ------------------------------------------------------------------ // broken examples below: // ------------------------------------------------------------------ // this never works // // Glib::RefPtr<Pango::Context> pContext = Pango::Context::create(); // both of these work as long as i don't call set_font_description below // // Glib::RefPtr<Pango::Context> pContext = pWin->get_pango_context(); Glib::RefPtr<Pango::Context> pContext = pWin->create_pango_context(); // this displays a list of all my fonts, including "fixed" // tFontList pArray = pContext->list_families(); for (tFontList::const_iterator itr = pArray.begin(); itr != pArray.end(); ++itr) { Glib::RefPtr<Pango::FontFamily> pFamily = *itr; std::cout << pFamily->get_name() << std::endl; } // calling set_font_description causes the app to abort when // draw_layout // is called, saying it can't find font "fixed" or any fallbacks, // even though "fixed" is listed by the above code. i've tried it // with many other font names and it's always the same result. // Pango::FontDescription font("fixed"); pContext->set_font_description(font); Glib::RefPtr<Pango::Layout> pLayout = Pango::Layout::create(pContext); pLayout->set_text("Pango Test Application"); Glib::RefPtr<Gdk::GC> gc = pWin->get_style()->get_black_gc(); pWin->get_window()->draw_layout(gc, 10, 10, pLayout); } int main(int argc, char* argv[]) { Gtk::Main kit(argc, argv); pWin = new Gtk::Window(Gtk::WINDOW_TOPLEVEL); pWin->set_default_size(500, 100); pWin->signal_expose_event().connect(SigC::slot(draw)); pWin->show_all(); kit.run(); }
Your draw() function does not return a value. Please _attach_ a complete simple-as-possible file that compiles and shows the problem. Do you see any warnings? Ifo so, does the debugger show anything useful when you run with --g-fatal-warnings?
Please respond.
I investigated this and came to result that this is not a bug. The font description you create is not valid, because its size is 0. Because you replace the context's default font (= the fallback font for the layout you created from this context) with an invalid font, the layout doesn't find a valid font it can use for rendering. Replacing Pango::FontDescription font("fixed"); with Pango::FontDescription font("Courier 12"); makes your example work on my system. The "default size 0" phenomenon is documented here: file:///home/martin/build/gtkmm-1.3/docs/reference/html/class_Pango__FontDescription.html#a8
Martin, ask on the #bugs irc.gnome.org channel for the right to close bugs. Thanks.