<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">The following program reproduces the bug. Tested on Ubuntu 12. I am attaching the snapshot too.<div><br></div><div>I am sure that the bug depends on the combination of FT_Set_Char_Size and cairo_scale. Moving the call to FT_Set_Char_Size to another point or calling it again inside the loop produces different results (different bugs, unfortunately).</div><div><br></div><div>#include <stdlib.h><br>#include <stdio.h><br>#include <assert.h><br><br>#include <ft2build.h><br>#include FT_FREETYPE_H<br>#include <ftadvanc.h><br>#include <ftsnames.h><br>#include <tttables.h><br><br>#include <harfbuzz/hb.h><br>#include <harfbuzz/hb-ft.h><br>#include <harfbuzz/hb-glib.h><br><br>#include <cairo/cairo.h><br>#include <cairo/cairo-ft.h><br><br>const char *texts[3] = {<br> "File", "Edit", "http://"<br>};<br><br>int main () {<br> double ptSize = 13.0;<br> int device_dpi = 72;<br> double dpi_scale = device_dpi / 72.;<br><br> FT_Library ft_library;<br> assert(!FT_Init_FreeType(&ft_library));<br><br> FT_Face ft_face;<br> assert(!FT_New_Face(ft_library, "/usr/share/fonts/truetype/freefont/FreeSans.ttf", 0, &ft_face));<br> assert(!FT_Set_Char_Size(ft_face, 0, ptSize*64, device_dpi, device_dpi ));<br><br> cairo_font_face_t *cairo_ft_face;<br> cairo_ft_face = cairo_ft_font_face_create_for_ft_face(ft_face, 0);<br><br> hb_font_t *hb_ft_font;<br> hb_face_t *hb_ft_face;<br> hb_ft_font = hb_ft_font_create(ft_face, NULL);<br> hb_ft_face = hb_ft_face_create(ft_face, NULL);<br><br> int width = 800;<br> int height = 300;<br><br> cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);<br><span class="Apple-tab-span" style="white-space:pre"> </span>cairo_t *cr = cairo_create(surface);<br><br> cairo_scale(cr, 2, 2);<br><br> cairo_font_options_t *fontOptions = cairo_font_options_create();<br> cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_GRAY);<br> cairo_font_options_set_hint_style(fontOptions, CAIRO_HINT_STYLE_SLIGHT);<br> cairo_set_font_options(cr, fontOptions);<br><br> cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);<br><span class="Apple-tab-span" style="white-space:pre"> </span>cairo_paint(cr);<br><br> double x = 10;<br> double y = 20;<br><br> int k;<br> for (k = 0; k < 3; ++k) {<br> x = 10;<br><br> hb_buffer_t *buf = hb_buffer_create();<br> hb_buffer_set_unicode_funcs(buf, hb_glib_get_unicode_funcs());<br> hb_buffer_set_direction(buf, HB_DIRECTION_LTR);<br> hb_buffer_set_script(buf, HB_SCRIPT_LATIN);<br><br> FT_Set_Char_Size(ft_face, 0, ptSize*64, device_dpi, device_dpi );<br><br> hb_buffer_add_utf8(buf, texts[k], strlen(texts[k]), 0, strlen(texts[k]));<br> hb_shape(hb_ft_font, buf, NULL, 0);<br><br> unsigned int glyph_count;<br> hb_glyph_info_t *glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);<br> hb_glyph_position_t *glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);<br> cairo_glyph_t *cairo_glyphs = malloc(sizeof(cairo_glyph_t) * glyph_count);<br><br> int j;<br> for (j=0; j < glyph_count; ++j) {<br> cairo_glyphs[j].index = glyph_info[j].codepoint;<br> cairo_glyphs[j].x = (int)(x + (glyph_pos[j].x_offset/64));<br> cairo_glyphs[j].y = (int)(y - (glyph_pos[j].y_offset/64));<br> x += glyph_pos[j].x_advance/64;<br> y -= glyph_pos[j].y_advance/64;<br> }<br><br> cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 1.0);<br> cairo_set_font_face(cr, cairo_ft_face);<br> cairo_set_font_size(cr, ptSize * dpi_scale);<br> cairo_show_glyphs(cr, cairo_glyphs, glyph_count);<br><br> free(cairo_glyphs);<br> hb_buffer_destroy(buf);<br><br> y += 36;<br> }<br><br> cairo_surface_write_to_png(surface, "./out.png");<br><br> cairo_surface_destroy(surface);<br> cairo_destroy(cr);<br><br> cairo_font_face_destroy(cairo_ft_face);<br> hb_font_destroy(hb_ft_font);<br> hb_face_destroy(hb_ft_face);<br><br> FT_Done_FreeType(ft_library);<br><br> return 0;<br>}<br><br></div><div><img apple-inline="yes" id="941C85AB-0F00-406D-810A-6B2B533DBF4E" height="205" width="203" apple-width="yes" apple-height="yes" src="cid:E549AA06-B8F3-4AC3-8539-A28A5BF7CEDC@fastwebnet.it"></div><div><br></div></body></html>