Pango Perf & Basic QnA



Hello All,
     I have a few questions regarding pango performance.  I'm new to
Pango, and font rendering in general, so hopefully these are questions
aren't too bad.  I'm running Pango 1.22 on an OMAP2/ARM on Linux
2.6.22.  I'm using FT 2.3.9 as my backend for font rendering (I don't
think cairo is an option for legacy purposes, but I haven't really
explored that route).  I have font-config, installed, and presumably
working.  I can run fc-list and see all my installed fonts.  I've
hacked together a basic test program to try and understand what I need
to do to use Pango to render basic strings.  It was surprisingly
simple once I figured out what I needed.


PangoContext *pango_context;
pango_context = pango_ft2_get_context(96, 96);
PangoLayout *layout = pango_layout_new (pango_context);
PangoRectangle logical_rect, ink_rect;

  memset(&logical_rect, 0, sizeof(PangoRectangle));
  memset(&ink_rect, 0, sizeof(PangoRectangle));
  const char *font_family = "KacstDecorative";

  PangoLanguage *lang = pango_language_get_default();

  printf("Default language is: %s - sample string for language:
\n\t%s\n", pango_language_to_string (lang),
pango_language_get_sample_string(lang));
  font_description = pango_font_description_from_string(font_family);
  pango_font_description_set_size (font_description, 25 * PANGO_SCALE);
  pango_layout_set_font_description(layout, font_description);
  printf("Using font: %s, family: %s\n",
pango_font_description_to_filename(font_description),
pango_font_description_get_family(font_description));
  pango_font_description_free(font_description);

   pango_layout_set_text (layout,
                         msg,
                         -1 );

   pango_layout_get_pixel_extents(layout,
                    NULL, &ink_rect);
    int byte_width = (logical_rect.width + 7) / 8 * 8;
    bm.rows = logical_rect.height;
    bm.width = byte_width;
    bm.pitch = byte_width;
    bm.buffer = (unsigned char*)malloc(byte_width * logical_rect.height);
    memset(bm.buffer, 0, byte_width * logical_rect.height);
    bm.num_grays = 256;
    bm.pixel_mode = FT_PIXEL_MODE_GRAY;

    pango_ft2_render_layout(&bm, layout, 0, 0);


// dump to bmp file

The first run of pango_layout_get_pixel_extents is very slow (1/3
second) such that rendering a screen w/ 50 or so blocks of text
results in a 20 second page draw. However, it seems subsequent runs
use the cache (based on the source in pango-layout.c anyway) and run
very quickly.  Perhaps those w/ more experience w/ Pango could help
shed some light on my dilemna:

1 - Currently, I'm not doing anything w/ a fontmap/font_description.
Is there something I need to do to load the fonts, cache, etc that
might help this issue?  Thus far, I've not had to do anything beyond
build/install fontconfig.  Maybe thats the sign of a good library,
but...
2 - Is the expected way to handle things to keep a context around for
the life of the text?  Our old system (non international friendly)
used FT to simply render each glyph on the fly as needed.  A page that
once rendered in milliseconds now takes tens of seconds when using the
above function for each block of text.
3 - what is the purpose of the fontmap?
4 - what's the life expectancy of a layout?  Of a context?

I can't really fault our drawing engine as the same page loads quickly
when simply rendering w/ FT (a la FT_Load_Glyph)

Apologies for html text -- I'll look for a gmail setting to disable.

Thanks.


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