From: handa Date: Fri, 17 Aug 2007 07:31:49 +0000 (+0000) Subject: (get_glyph_metric): New function. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc129950353b876239f91acc70bf106630ba5bfc;p=m17n%2Fm17n-lib.git (get_glyph_metric): New function. (DEVICE_DELTA): Return 26.6 fixed point value. (adjust_anchor): Likewise. (mfont__ft_drive_otf): Use get_glyph_metric. --- diff --git a/src/font-ft.c b/src/font-ft.c index 95a8a5e..85c1298 100644 --- a/src/font-ft.c +++ b/src/font-ft.c @@ -2129,6 +2129,19 @@ ft_close (MRealizedFont *rfont) free (rfont); } +static void +get_glyph_metric (FT_Face ft_face, MGlyph *g) +{ + FT_Glyph_Metrics *metrics; + + FT_Load_Glyph (ft_face, (FT_UInt) g->code, FT_LOAD_DEFAULT); + metrics = &ft_face->glyph->metrics; + g->lbearing = metrics->horiBearingX; + g->rbearing = metrics->horiBearingX + metrics->width; + g->width = metrics->horiAdvance; + g->ascent = metrics->horiBearingY; + g->descent = metrics->height - metrics->horiBearingY; +} /* Internal API */ @@ -2345,7 +2358,7 @@ mfont__ft_unparse_name (MFont *font) #define DEVICE_DELTA(table, size) \ (((size) >= (table).StartSize && (size) <= (table).EndSize) \ - ? (table).DeltaValue[(size) - (table).StartSize] \ + ? (table).DeltaValue[(size) - (table).StartSize] << 6 \ : 0) void @@ -2368,9 +2381,9 @@ adjust_anchor (OTF_Anchor *anchor, FT_Face ft_face, else if (anchor->AnchorFormat == 3) { if (anchor->f.f2.XDeviceTable.offset) - *x += (DEVICE_DELTA (anchor->f.f2.XDeviceTable, x_ppem)) << 6; + *x += DEVICE_DELTA (anchor->f.f2.XDeviceTable, x_ppem); if (anchor->f.f2.YDeviceTable.offset) - *y += (DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem)) << 6; + *y += DEVICE_DELTA (anchor->f.f2.YDeviceTable, y_ppem); } } @@ -2504,29 +2517,26 @@ mfont__ft_drive_otf (MGlyphString *gstring, int from, int to, MLIST_APPEND1 (gstring, glyphs, temp, MERROR_FONT_OTF); } - (rfont->driver->find_metric) (rfont, gstring, gidx, gstring->used); - - if (gpos_features) + if (gpos_features + && (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) + >= 0)) { - FT_Face face; + FT_Face ft_face; MGlyph *base = NULL, *mark = NULL; int x_ppem, y_ppem, x_scale, y_scale; - if (OTF_drive_gpos (otf, &otf_gstring, script, langsys, gpos_features) - < 0) - return to; - - face = ((MRealizedFontFT *) rfont->info)->ft_face; - x_ppem = face->size->metrics.x_ppem; - y_ppem = face->size->metrics.y_ppem; - x_scale = face->size->metrics.x_scale; - y_scale = face->size->metrics.y_scale; + ft_face = ((MRealizedFontFT *) rfont->info)->ft_face; + x_ppem = ft_face->size->metrics.x_ppem; + y_ppem = ft_face->size->metrics.y_ppem; + x_scale = ft_face->size->metrics.x_scale; + y_scale = ft_face->size->metrics.y_scale; for (i = 0, otfg = otf_gstring.glyphs, g = MGLYPH (gidx); i < otf_gstring.used; i++, otfg++, g++) { MGlyph *prev; + get_glyph_metric (ft_face, g); if (! otfg->glyph_id) continue; switch (otfg->positioning_type) @@ -2538,19 +2548,19 @@ mfont__ft_drive_otf (MGlyphString *gstring, int from, int to, int format = otfg->f.f1.format; if (format & OTF_XPlacement) - g->xoff = otfg->f.f1.value->XPlacement * x_scale / 0x400000; + g->xoff = otfg->f.f1.value->XPlacement * x_scale / 0x10000; if (format & OTF_XPlaDevice) g->xoff += DEVICE_DELTA (otfg->f.f1.value->XPlaDevice, x_ppem); if (format & OTF_YPlacement) g->yoff - = - (otfg->f.f1.value->YPlacement * y_scale / 0x400000); + = - (otfg->f.f1.value->YPlacement * y_scale / 0x10000); if (format & OTF_YPlaDevice) g->yoff -= DEVICE_DELTA (otfg->f.f1.value->YPlaDevice, y_ppem); if (format & OTF_XAdvance) g->width - += otfg->f.f1.value->XAdvance * x_scale / 0x400000; + += otfg->f.f1.value->XAdvance * x_scale / 0x10000; if (format & OTF_XAdvDevice) g->width += DEVICE_DELTA (otfg->f.f1.value->XAdvDevice, y_ppem); @@ -2584,8 +2594,8 @@ mfont__ft_drive_otf (MGlyphString *gstring, int from, int to, if (otfg->f.f4.mark_anchor->AnchorFormat != 1) adjust_anchor (otfg->f.f4.mark_anchor, rfont->fontp, g->code, x_ppem, y_ppem, &mark_x, &mark_y); - g->xoff = prev->xoff - prev->width + ((base_x - mark_x) >> 6); - g->yoff = prev->yoff + ((mark_y - base_y) >> 6); + g->xoff = prev->xoff - prev->width + (base_x - mark_x); + g->yoff = prev->yoff + (mark_y - base_y); g->combining_code = MAKE_PRECOMPUTED_COMBINDING_CODE (); } } @@ -2596,7 +2606,20 @@ mfont__ft_drive_otf (MGlyphString *gstring, int from, int to, else base = g; } + + for (i = 0, g = MGLYPH (gidx); i < otf_gstring.used; i++, g++) + { + g->lbearing >>= 6; + g->rbearing >>= 6; + g->width >>= 6; + g->ascent >>= 6; + g->descent >>= 6; + g->xoff >>= 6; + g->yoff >>= 6; + } } + else + rfont->driver->find_metric (rfont, gstring, gidx, gstring->used); free (otf_gstring.glyphs); return to;