Re: How to start using Pango?



On Tue, 2007-03-06 at 15:48 +0100, J�Herz wrote:
> Owen Taylor wrote:
> 
> >> It nevertheless took me quite some time to find out how to convert from
> >> one object to another to be able to call a desired function. E.g. to
> >> call pango_ot_info_list_scripts() you've to have PangoOTInfo and in
> >> order to get that you need a FT_Face. To get this you need a PangoFont
> >> for which you need three other objects which have to be created somehow.
> >> That's a long way babe.
> > 
> > Well, you *are* way off into the deep internals of Pango there... most
> > Pango users never will get beyond PangoLayout.
> 
> Granted, I missed that point. But maybe I may ask another
> deep-down-question.
> 
> The following code (checks, frees a.s.o. omited)
> 
> int main ()
> {
>   PangoFontDescription *fontDesc =
> pango_font_description_from_string("Arial, Roman 64");
>   PangoFontMap *fontMap = pango_ft2_font_map_new();
>   PangoContext *context = pango_ft2_get_context(100, 100);
>   pango_context_set_font_description(context, fontDesc);
>   pango_context_set_font_map(context, fontMap);
> 
>   char text[] = "Test";
>   PangoAttrList* attrList = pango_attr_list_new();
>   GList *list = pango_itemize(context, text, 0, strlen(text), attrList,
> NULL);
>   PangoItem *item = list->data;
> 
>   PangoGlyphString *glyphs = pango_glyph_string_new();
>   pango_shape(text, strlen(text), &item->analysis, glyphs);
> 
>   cairo_surface_t *surface =
> cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
>   cairo_t *cr = cairo_create(surface);
>   cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
> /*
>   PangoLayout *layout = pango_cairo_create_layout(cr);
>   pango_layout_set_text(layout, text, -1);
>   pango_layout_set_font_description (layout, fontDesc);
>   pango_cairo_show_layout(cr, layout);
> */
>   pango_cairo_show_glyph_string(cr, item->analysis.font, glyphs);
> 
>   cairo_surface_write_to_png(surface, "test.png");
> 
>   return 0;
> }
> 
> results in
> 
> process:9075): Pango-WARNING **: _pango_cairo_font_install called with
> bad font, expect ugly output
> 
> (process:9075): Pango-WARNING **: _pango_cairo_font_get_scaled_font
> called with bad font, expect ugly output
> 
> 
> If I instead use the commented out part to paint to the surface, it
> succeeds. Both are using the same fontDesc so it can't be that bad. What
> am I overlooking?

Well, I'm not sure it's the *only* thing wrong with the above, but the
obvious problem is that you can't use fonts from a PangoFT2Fontmap with
a cairo surface.

Replace:

  PangoFontMap *fontMap = pango_ft2_font_map_new();
  PangoContext *context = pango_ft2_get_context(100, 100);
  pango_context_set_font_map(context, fontMap);

(the last line is unnecessary even for FT2), with:

  PangoFontMap *fontmap = pango_cairo_font_map_get_default();
  context = pango_cairo_font_map_create_context (fontmap);

You also, as documented, need to call pango_cairo_update_context() to
set the appropriate options on the context for the cairo_t that you are
rendering to. 

If you don't mind me asking... what's the big picture thing you are
trying to accomplish? Why are you looking to avoid PangoLayout?

					- Owen





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