[gs-cvs] rev 7518 - trunk/gs/src
leonardo at ghostscript.com
leonardo at ghostscript.com
Mon Dec 18 09:56:27 PST 2006
Author: leonardo
Date: 2006-12-18 09:56:27 -0800 (Mon, 18 Dec 2006)
New Revision: 7518
Modified:
trunk/gs/src/gxttfb.c
trunk/gs/src/ttfmain.c
trunk/gs/src/ttfoutl.h
Log:
Fix (TrueType renderer) : Always access metrics via get_metrics callback.
DETAILS :
This change is important for PCL interpreter.
Some PCL downloadable fonts have no hmtx, vmtx tables
and define glyph metrics externally.
Likely we missed this functionality when attached
the TrueType bytecode interpreter from FreeType.
For both Postscript and PCL the new code is not equivalent
to old one when processing a composite glyph
with grid fitting. For each subglyph, the old code sets phantom points
with the subglyph's metrics. The new code does with the glyph's metrics.
We believe that the old code was not correct because its grid fitting
can wrongly account the placement of a subglyph in the main glyph.
Rether we didn't find a practical case when it happens.
We can't directly access the font's get_metrics callback from ttfmain.c,
therefore we introduce an intermediate callback ttfReader::get_metrics.
It happens because TrueType bytecode interpreter doesn't compile
with Ghostscript headers.
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/src/gxttfb.c
===================================================================
--- trunk/gs/src/gxttfb.c 2006-12-18 05:00:00 UTC (rev 7517)
+++ trunk/gs/src/gxttfb.c 2006-12-18 17:56:27 UTC (rev 7518)
@@ -191,9 +191,35 @@
gs_free_object(this->memory, this, "gx_ttfReader__destroy");
}
+private int
+gx_ttfReader__default_get_metrics(const ttfReader *ttf, uint glyph_index, bool bVertical,
+ short *sideBearing, unsigned short *nAdvance)
+{
+ gx_ttfReader *this = (gx_ttfReader *)ttf;
+ float sbw[4];
+ int sbw_offset = bVertical;
+ int code;
+ int factor = this->pfont->data.unitsPerEm;
+
+ if (bVertical)
+ factor = factor; /* See simple_glyph_metrics */
+ code = this->pfont->data.get_metrics(this->pfont, glyph_index, bVertical, sbw);
+ if (code < 0)
+ return code;
+ /* Due to an obsolete convention, simple_glyph_metrics scales
+ the metrics into 1x1 rectangle as Postscript like.
+ In same time, the True Type interpreter needs
+ the original design units.
+ Undo the scaling here with accurate rounding. */
+ *sideBearing = (short)floor(sbw[0 + sbw_offset] * factor + 0.5);
+ *nAdvance = (short)floor(sbw[2 + sbw_offset] * factor + 0.5);
+ return 0;
+}
+
void gx_ttfReader__set_font(gx_ttfReader *this, gs_font_type42 *pfont)
{
this->pfont = pfont;
+ this->super.get_metrics = gx_ttfReader__default_get_metrics;
}
Modified: trunk/gs/src/ttfmain.c
===================================================================
--- trunk/gs/src/ttfmain.c 2006-12-18 05:00:00 UTC (rev 7517)
+++ trunk/gs/src/ttfmain.c 2006-12-18 17:56:27 UTC (rev 7518)
@@ -488,31 +488,10 @@
const byte *glyph = NULL;
int glyph_size;
- if(this->bVertical && pFont->t_vhea.nPos && pFont->t_vmtx.nPos) {
- nLongMetrics = pFont->nLongMetricsVert;
- nMtxPos = pFont->t_vmtx.nPos;
- } else {
- nLongMetrics = pFont->nLongMetricsHorz;
- nMtxPos = pFont->t_hmtx.nPos;
- }
- if (this->bVertical && (!pFont->t_vhea.nPos || pFont->t_vmtx.nPos) && nMtxGlyph < nLongMetrics) {
- /* A bad font fix. */
- nMtxGlyph = nLongMetrics;
- if(nMtxGlyph >= pFont->nNumGlyphs)
- nMtxGlyph = pFont->nNumGlyphs - 1;
- }
- if (nMtxGlyph < nLongMetrics) {
- r->Seek(r, nMtxPos + 4 * nMtxGlyph);
- nAdvance = ttfReader__Short(r);
- sideBearing = ttfReader__Short(r);
- } else {
- r->Seek(r, nMtxPos + 4 * (nLongMetrics - 1));
- nAdvance = ttfReader__Short(r);
- r->Seek(r, nMtxPos + 4 * nLongMetrics + 2 * (nMtxGlyph - nLongMetrics));
- sideBearing = ttfReader__Short(r);
- }
- if (r->Error(r))
+ if (r->get_metrics(r, glyphIndex, this->bVertical, &sideBearing, &nAdvance) < 0) {
+ /* fixme: the error code is missing due to interface restrictions. */
goto errex;
+ }
gOutline->sideBearing = shortToF26Dot6(sideBearing);
gOutline->advance.x = shortToF26Dot6(nAdvance);
gOutline->advance.y = 0;
Modified: trunk/gs/src/ttfoutl.h
===================================================================
--- trunk/gs/src/ttfoutl.h 2006-12-18 05:00:00 UTC (rev 7517)
+++ trunk/gs/src/ttfoutl.h 2006-12-18 17:56:27 UTC (rev 7518)
@@ -106,6 +106,8 @@
bool (*Error)(ttfReader *);
int (*LoadGlyph)(ttfReader *, int nIndex, const byte **, int *);
void (*ReleaseGlyph)(ttfReader *, int nIndex);
+ int (*get_metrics)(const ttfReader *ttf, uint glyph_index, bool bVertical,
+ short *sideBearing, unsigned short *nAdvance);
};
/* Define an auxiliary structure for ttfFont. */
More information about the gs-cvs
mailing list