Pango offscreen at client side?

How hard it can be? I spend several hours in compiling the following
code from various sources (there seems to be no good standalone
example) and it does not work. The text is corrupted with noise.

  PangoContext *context;
  PangoLanguage *language;
  PangoFontDescription *font_desc;
  PangoLayout *layout;
  GdkPixmap *pixmap;
  GdkImage *image;
  int width,height;

  // context = pango_context_new();
  context = gdk_pango_context_get();
  // language = pango_language_from_string("");
  language = gtk_get_default_language();
  pango_context_set_language (context, language);
  pango_context_set_base_dir (context, PANGO_DIRECTION_LTR);

  font_desc = pango_font_description_from_string ("courier 12");
  pango_context_set_font_description (context, font_desc);

  layout = pango_layout_new(context);
  pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
  pango_layout_set_text (layout, "Test", -1);
  pango_layout_get_pixel_size (layout, &width, &height);

  pixmap = gdk_pixmap_new(NULL,width,height,1); // 1-bit image
  gdk_draw_layout(pixmap, gdk_gc_new(pixmap), 0, 0, layout);
  image = gdk_drawable_get_image (pixmap, 0, 0, width, height);

Then gdk_image_get_pixel(image,x,y) is used to examine the pixel
values. The pixels are incorrect at this point.

Is gdk_gc_new(pixmap) correct way to get the required GC?

I have tested the 8-bit image as well. All results looks like
in the screenshot at "";
(texts are "i01"-"i19" in the first column).
Note that the texts in the screenshot are not on a gdk drawable.
All texts together are composed of about 7000 opengl quads in 3D
space. The code above is used to generate the quads.

I wish there would be an easier way to generate texts. Because
modern fonts (Metafont, PostScript) are vector outline fonts,
Pango could give out a polygonal approximation of the outline
easily. The polygon could then be used to draw the texts in opengl.


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