Re: How to start using Pango?



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?

Bye,
J�


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