Re: [gtkmm] problems using pangomm to render text on a drawable (1.3.21)



thanks for the further investigations.  i've found the whole pango
experience frustrating.  perhaps these problems are why there's no
example code out there.

here's the result of my efforts, with the various results listed in
the comments:


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);
}

// main fn omitted...sets up gtkmm, pWin, etc.

so basically it seems like whenever a Pango::Context is used, there
are problems.

if anyone is using pangomm more successfully, or could tell me the
right way to use it, it would be much appreciated.  i'm going to stick
to using only Pango::Layout methods for now...

thanks.

patrick


Martin Schulze (MHL Schulze t-online de) wrote:
> Am 03.09.2002 22:12 schrieb(en) Martin Schulze:
> >Am 03.09.2002 21:05 schrieb(en) Patrick Crosby:
> >>in converting one of my apps to gtkmm2 (using v1.3.21), i've been
> >>trying to use pango for font rendering but haven't had much luck.  the
> >>following program:
> >>
> >>#include <gtkmm/main.h>
> >>#include <gtkmm/window.h>
> >>#include <pangomm/layout.h>
> >>
> >>int
> >>main(int argc, char* argv[])
> >>{
> >>    Gtk::Main kit(argc, argv);
> >>
> >>    Gtk::Window win(Gtk::WINDOW_TOPLEVEL);
> >>
> >>    win.set_default_size(500, 100);
> >>    win.show_all();
> >>	     Glib::RefPtr<Pango::Context> pContext = 
> >>Pango::Context::create();
> >>    pContext->set_font_description(Pango::FontDescription("fixed"));
> >>    Glib::RefPtr<Pango::Layout> pLayout =
> >>Pango::Layout::create(pContext);
> >>    pLayout->set_text("Pango Test Application");
> >>
> >>    Glib::RefPtr<Gdk::GC> gc = win.get_style()->get_black_gc();
> >>    win.get_window()->draw_layout(gc, 10, 10, pLayout);
> >>	     kit.run();
> >>}
> >
> >I guess you should try:
> >
> >Glib::RefPtr<Pango::Context> pContext = win.get_pango_context();
> >
> >or
> >
> >Glib::RefPtr<Pango::Layout> pLayout = win.create_pango_layout("Pango 
> >Test Application");
> >
> >The output sounds as if some fields of the context were not set.
> 
> Further investigations lead to the result that Pango::Context::create()
> is malfunctioning. It doesn't initialize the Context object correctly.
> This is due to the fact that the generation of PangoContext structures
> in pango is only provided by backend specific c functions,
> e.g. pango_x_get_context(). These functions are currently not wrapped.
> 
> I don't find them very user friendly either because a program aiming
> to be platform independant can't know which backend to use. So until
> the pango people learn how to write a proper backend infrastructure
> (like the one the ggi people use: http://www.ggi-project.org) I
> propose to just get rid of Pango::Context::create() and not to
> wrap the backend specific stuff. If you want to create a pango
> Context, you have to use:
> 
> Gtk::Widget::create_pango_context() or Gtk::Widget::get_pango::context()
> 
> which automatically chooses the right backend or you must create the
> context with an unwrapped c function like:
> 
> Glib::wrap(pango_x_get_context())
> 
> Regards,
> 
>   Martin
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]