    CFIndex i, glyph_count;
    CFIndex *indices = NULL;
    const CGGlyph *cgglyphs;
-+  const char *cur = text;
-+  gint cur_index = 0;
++  const char *text_offset_ptr = text;
++  CFIndex index = 0;
  
    CFTypeRef keys[] = {
        (CFTypeRef) kCTFontAttributeName

-        set_glyph (font, glyphs, real_i,
-                   g_utf8_offset_to_pointer (text, indices[real_i]) - text,
-                   PANGO_GET_UNKNOWN_GLYPH (wc));
+	set_glyph (font, glyphs, real_i, cur_index, PANGO_GET_UNKNOWN_GLYPH (wc));
     }
 
   free (indices);

 
       result = pango_coverage_get (coverage, wc);
 
+      text_offset_ptr = g_utf8_offset_to_pointer (text_offset_ptr, indices[real_i] - index);
+      index = indices[real_i];
+
       if (result != PANGO_COVERAGE_NONE)
         {
-          set_glyph (font, glyphs, real_i,
-                     g_utf8_offset_to_pointer (text, indices[real_i]) - text,
-                     cgglyphs[real_i]);
+          set_glyph (font, glyphs, real_i, text_offset_ptr - text, cgglyphs[real_i]);
 
           if (g_unichar_type (wc) == G_UNICODE_NON_SPACING_MARK)
             {
