After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 92511 - Pango::Context::set_font_description causes app to abort when layout is drawn
Pango::Context::set_font_description causes app to abort when layout is drawn
Status: RESOLVED NOTABUG
Product: gtkmm
Classification: Bindings
Component: general
2.0
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2002-09-04 20:00 UTC by pcrosby
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description pcrosby 2002-09-04 20:00:17 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();
}
Comment 1 Murray Cumming 2002-09-12 14:18:22 UTC
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?
Comment 2 Murray Cumming 2002-09-19 13:58:24 UTC
Please respond.
Comment 3 Martin Schulze 2002-09-26 20:58:26 UTC
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
Comment 4 Murray Cumming 2002-09-27 07:44:02 UTC
Martin, ask on the #bugs irc.gnome.org channel for the right to close
bugs. Thanks.