Strange superimposition of text characters drawn with pangocairo


I’m writing a small toy program to draw a keyboard layout from a JSON description (coming from Keyboard Layout Editor). It’s written in C, using GTK.
with a first version, I’ve used Cairo to draw the key labels, using « text toy » API. It works quite well, but it can’t handle glyphs from multiple fonts, so I tried to write a second version using PangoCairo (as suggested in Cairo documenation).
I’ve tried to adapt cairo text drawing by pangocairo equivalent calls, but I get a strange result : when drawing a single letter, it works quite well, but drawing a word (or more) results in having all their word letters superimposed !!
Here is an illustration of the problem : one capture with the correct cairo version, one incorrect with pangocairo code :

To draw a text with pange from a cairo context, I do following statements, derived from examples found in documentation :

  PangoLayout *layout = pango_cairo_create_layout (cr);

  PangoFontDescription *font_description = pango_font_description_new();

  pango_font_description_set_family (font_description, default_font);
  pango_font_description_set_weight (font_description, PANGO_WEIGHT_BOLD);
  pango_layout_set_font_description (layout, font_description);

  pango_layout_set_width (layout, -1);   
  pango_layout_set_height (layout, 0);   
  pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);   
  pango_layout_set_justify(layout, false); 
  pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT); 

  pango_layout_set_text (layout, label, -1);


  cairo_set_source_rgba (cr, posLabel->color.r, posLabel->color.g, posLabel->color.b, 0.7);
  cairo_move_to(cr, base.x - extentsLabel.x_bearing, base.y - extentsLabel.y_bearing);

  pango_cairo_show_layout (cr, layout);

  g_object_unref (layout);
  pango_font_description_free (font_description);

I can’t understand what is going on, have you any clue of my mistake ?

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.