(ft_drive_otf): Fix indexing gstring->glyphs.
authorhanda <handa>
Wed, 7 Nov 2007 12:00:23 +0000 (12:00 +0000)
committerhanda <handa>
Wed, 7 Nov 2007 12:00:23 +0000 (12:00 +0000)
src/font-ft.c

index 8701d3f..fb8e1e6 100644 (file)
@@ -2187,7 +2187,7 @@ ft_check_otf (MFLTFont *font, MFLTOtfSpec *spec)
        return 0;
     }
   return 1;
-#endif
+#endif /* HAVE_OTF */
  not_otf:
   return ((! spec->features[0] || spec->features[0][0] == 0xFFFFFFFF)
          && (! spec->features[1] || spec->features[1][0] == 0xFFFFFFFF));
@@ -2225,7 +2225,7 @@ adjust_anchor (OTF_Anchor *anchor, FT_Face ft_face,
        *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem);
     }
 }
-#endif
+#endif /* HAVE_OTF */
 
 static int 
 ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
@@ -2238,6 +2238,8 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
   MRealizedFontFT *ft_rfont = rfont->info;
   MFontFT *ft_info = (MFontFT *) rfont->font;
 #ifdef HAVE_OTF
+  MGlyph *in_glyphs = (MGlyph *) (in->glyphs);
+  MGlyph *out_glyphs = (MGlyph *) (out->glyphs);
   OTF *otf;
   OTF_GlyphString otf_gstring;
   OTF_Glyph *otfg;
@@ -2326,15 +2328,15 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
        return -2;
       for (i = 0, otfg = otf_gstring.glyphs; i < otf_gstring.used; i++, otfg++)
        {
-         MGlyph *g = ((MGlyph *) out->glyphs) + out->used;
+         MGlyph *g = out_glyphs + out->used;
          int j;
 
-         *g = ((MGlyph *) in->glyphs)[from + otfg->f.index.from];
+         *g = in_glyphs[from + otfg->f.index.from];
          g->g.c = 0;
          for (j = from + otfg->f.index.from; j <= from + otfg->f.index.to; j++)
-           if (((MGlyph *)in->glyphs)[j].g.code == otfg->glyph_id)
+           if (in_glyphs[j].g.code == otfg->glyph_id)
              {
-               g->g.c = ((MGlyph *)in->glyphs)[j].g.c;
+               g->g.c = in_glyphs[j].g.c;
                break;
              }
          if (g->g.code != otfg->glyph_id)
@@ -2350,13 +2352,13 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
       if (out->allocated < out->used + len)
        return -2;
       for (i = 0; i < len; i++)
-       ((MGlyph *) out->glyphs)[out->used++] = ((MGlyph *) in->glyphs)[from + i];
+       out_glyphs[out->used++] = in_glyphs[from + i];
     }
 
   if (gpos_features)
     {
       FT_Face face;
-      MFLTGlyph *base = NULL, *mark = NULL, *g;
+      MGlyph *base = NULL, *mark = NULL, *g;
       int x_ppem, y_ppem, x_scale, y_scale;
 
       if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features)
@@ -2369,10 +2371,10 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
       x_scale = face->size->metrics.x_scale;
       y_scale = face->size->metrics.y_scale;
 
-      for (i = 0, otfg = otf_gstring.glyphs, g = out->glyphs + gidx;
+      for (i = 0, otfg = otf_gstring.glyphs, g = out_glyphs + gidx;
           i < otf_gstring.used; i++, otfg++, g++)
        {
-         MFLTGlyph *prev;
+         MGlyph *prev;
 
          if (! otfg->glyph_id)
            continue;
@@ -2380,7 +2382,8 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
            {
            case 0:
              break;
-           case 1: case 2:
+           case 1:             /* Single */
+           case 2:             /* Pair */
              {
                int format = otfg->f.f1.format;
 
@@ -2411,15 +2414,16 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
                adjustment[i].set = 1;
              }
              break;
-           case 3:
+           case 3:             /* Cursive */
              /* Not yet supported.  */
              break;
-           case 4: case 5:
+           case 4:             /* Mark-to-Base */
+           case 5:             /* Mark-to-Ligature */
              if (! base)
                break;
              prev = base;
              goto label_adjust_anchor;
-           default:            /* i.e. case 6 */
+           default:            /* i.e. case 6 Mark-to-Mark */
              if (! mark)
                break;
              prev = mark;
@@ -2427,6 +2431,7 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
            label_adjust_anchor:
              {
                int base_x, base_y, mark_x, mark_y;
+               int this_from, this_to;
 
                base_x = otfg->f.f4.base_anchor->XCoordinate * x_scale / 0x10000;
                base_y = otfg->f.f4.base_anchor->YCoordinate * y_scale / 0x10000;
@@ -2434,10 +2439,10 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
                mark_y = otfg->f.f4.mark_anchor->YCoordinate * y_scale / 0x10000;;
 
                if (otfg->f.f4.base_anchor->AnchorFormat != 1)
-                 adjust_anchor (otfg->f.f4.base_anchor, face, prev->code,
+                 adjust_anchor (otfg->f.f4.base_anchor, face, prev->g.code,
                                 x_ppem, y_ppem, &base_x, &base_y);
                if (otfg->f.f4.mark_anchor->AnchorFormat != 1)
-                 adjust_anchor (otfg->f.f4.mark_anchor, face, g->code,
+                 adjust_anchor (otfg->f.f4.mark_anchor, face, g->g.code,
                                 x_ppem, y_ppem, &mark_x, &mark_y);
                adjustment[i].xoff = (base_x - mark_x);
                adjustment[i].yoff = - (base_y - mark_y);
@@ -2445,6 +2450,20 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
                adjustment[i].xadv = 0;
                adjustment[i].advance_is_absolute = 1;
                adjustment[i].set = 1;
+               this_from = g->g.from;
+               this_to = g->g.to;
+               for (j = 0; prev + j < g; j++)
+                 {
+                   if (this_from > prev[j].g.from)
+                     this_from = prev[j].g.from;
+                   if (this_to < prev[j].g.to)
+                     this_to = prev[j].g.to;
+                 }
+               for (; prev <= g; prev++)
+                 {
+                   prev->g.from = this_from;
+                   prev->g.to = this_to;
+                 }
              }
            }
          if (otfg->GlyphClass == OTF_GlyphClass0)
@@ -2459,6 +2478,7 @@ ft_drive_otf (MFLTFont *font, MFLTOtfSpec *spec,
   return to;
 
  simple_copy:
+#endif /* HAVE_OTF */
   if (out->allocated < out->used + len)
     return -2;
   font->get_metrics (font, in, from, to);
@@ -2548,7 +2568,7 @@ mfont__ft_init ()
     msymbol_put (monospace, Mgeneric_family, monospace);
     msymbol_put (msymbol ("mono"), Mgeneric_family, monospace);
   }
-#endif
+#endif /* HAVE_FONTCONFIG */
 
   return 0;
 }
@@ -2680,7 +2700,4 @@ mfont__ft_unparse_name (MFont *font)
 }
 #endif /* HAVE_FONTCONFIG */
 
-\f
-#endif /* HAVE_OTF */
-
 #endif /* HAVE_FREETYPE */