Re: Pango::Layout::create ({ImageSurface Cairo Context})



On Wed, 2007-11-21 at 06:22 +0000, Dale Mellor wrote:
> On Fri, 2007-11-16 at 11:15 -0600, Jonathon Jongsma wrote:
> > On Wed, 2007-11-14 at 05:35 +0000, Dale Mellor wrote:
> > > I'm trying to use pango to write text into a PNG file.  I have a
> > > Cairo::Context on a Cairo::ImageSurface which works perfectly well with
> > > graphics, but when I do Pango::Layout::create from this I get a NULL
> > > object.
> > > 
> > > I have seen in the cairofontmap.h header file that the wrapping around
> > > pango_cairo_font_map_get_default is commented out, so I can't use that
> > > from which to create a Pango::Context.
> > > 
> > > Ideas anybody?
> > > Thanks in advance.
> > 
> > If you could provide a minimal test case to illustrate the issue, that might help people respond more easily.
> 
> Here you go.
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> #include <cairomm/cairomm.h>
> #include <pangomm.h>
> 
> int main ()
> {
>   Cairo::RefPtr<Cairo::ImageSurface> surface
>               = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 750,
> 600);
>   
>   Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create
> (surface);
> 
>   Glib::RefPtr <Pango::Layout> pango = Pango::Layout::create (cairo);
>   
>   return 0;
> }

This produces these warnings. I know they are cryptic, but you can't
just ignore them:

(process:8207): glibmm-CRITICAL **: Glib::ObjectBase*
Glib::wrap_create_new_wrapper(GObject*): assertion `wrap_func_table !=
0' failed

(process:8207): glibmm-WARNING **: failed to wrap type of 'PangoLayout'

It works if you initialize pangomm. In the attached corrected example I
have done that by instantiating Gtk::Main. If you don't want to use
gtkmm then you can use Pango::init() instead, I believe.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com
// Build with:
// g++ pango_cairomm_test.cc `pkg-config gtkmm-2.4 --libs --cflags`

#include <gtkmm.h>
#include <iostream>

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  Cairo::RefPtr<Cairo::ImageSurface> surface
    = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, 750, 600);
  
  Cairo::RefPtr<Cairo::Context> cairo = Cairo::Context::create(surface);

  Glib::RefPtr <Pango::Layout> pango = Pango::Layout::create (cairo);
  if(pango)
    std::cout << "pango layout is not null" << std::endl;
  else
    std::cout << "pango layout is null" << std::endl;
  
  return 0;
}


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