[gs-cvs] rev 8776 - trunk/gs/src
leonardo at ghostscript.com
leonardo at ghostscript.com
Sun May 25 00:23:38 PDT 2008
Author: leonardo
Date: 2008-05-25 00:23:38 -0700 (Sun, 25 May 2008)
New Revision: 8776
Modified:
trunk/gs/src/gstype42.c
trunk/gs/src/ttfmain.c
Log:
Fix (True Type font loader) : Work around incorrect numGlyphs.
DETAILS :
Bug 689516 "problem reading PDF: Failed to interpret TT instructions (ref 7814)".
The bug report supplies a PDF document, which embeds a TT font
with a too small numGlyphs. The loca table contains more glyphs and
they are referenced in a text. The font is incorrect, but Acrobat handles the document.
This patch checks whether there are glyphs behind numGlyphs and
extends numGlyphs to cover them. Also improved error handling in ttfmain.c .
Besides that, now we print a warning about an incorrect numGlyphs
in release build. The olkd code did with debug buil only.
I believe that users need to know whether a font is broken, and that
its rendering is hewristic.
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/src/gstype42.c
===================================================================
--- trunk/gs/src/gstype42.c 2008-05-25 05:45:15 UTC (rev 8775)
+++ trunk/gs/src/gstype42.c 2008-05-25 07:23:38 UTC (rev 8776)
@@ -243,11 +243,23 @@
Continue using trueNumGlyphs since the document of
the bug 688467 fails otherwise.
*/
-# ifdef DEBUG
- /* pfont->key_name.chars is ASCIIZ due to copy_font_name. */
+ /* pfont->key_name.chars is ASCIIZ due to copy_font_name. */
eprintf3("Warning: 'loca' length %d is greater than numGlyphs %d in the font %s.\n",
pfont->data.numGlyphs + 1, pfont->data.trueNumGlyphs, pfont->key_name.chars);
-# endif
+ if (loca_size > pfont->data.trueNumGlyphs + 1) {
+ /* Bug 689516 demonstrates a font, in which numGlyps is smaller than loca size,
+ and there are useful glyphs behind maxp.numGlyphs. */
+ for (i = loca_size - 1; i > pfont->data.trueNumGlyphs; i--) {
+ glyph_offset = get_glyph_offset(pfont, i);
+ if (glyph_offset < glyph_size)
+ break;
+ }
+ if (i > pfont->data.trueNumGlyphs) {
+ /* loca contains more good offsets, fix maxp.numGlyphs.
+ Note a code below will fix bad offsets if any. */
+ pfont->data.numGlyphs = pfont->data.trueNumGlyphs = loca_size - 1;
+ }
+ }
pfont->data.numGlyphs = pfont->data.trueNumGlyphs;
loca_size = pfont->data.numGlyphs + 1;
}
@@ -279,7 +291,10 @@
glyph_offset = get_glyph_offset(pfont, i);
glyph_length = glyph_offset - glyph_start;
if (glyph_length > 0x80000000)
- break; /* out of order loca */
+ break;
+ if (glyph_offset > glyph_size)
+ break;
+ /* out of order loca */
pfont->data.len_glyphs[i - 1] = glyph_length;
glyph_start = glyph_offset;
}
Modified: trunk/gs/src/ttfmain.c
===================================================================
--- trunk/gs/src/ttfmain.c 2008-05-25 05:45:15 UTC (rev 8775)
+++ trunk/gs/src/ttfmain.c 2008-05-25 07:23:38 UTC (rev 8776)
@@ -220,7 +220,7 @@
{ char sVersion[4], sVersion1[4] = {0, 1, 0, 0};
char sVersion2[4] = {0, 2, 0, 0};
unsigned int nNumTables, i;
- TT_Error code;
+ TT_Error code, code1 = 0;
int k;
TT_Instance I;
ttfMemory *mem = tti->ttf_memory;
@@ -328,8 +328,8 @@
if (code == TT_Err_Out_Of_Memory)
return fMemoryError;
if (code >= TT_Err_Invalid_Opcode && code <= TT_Err_Invalid_Displacement)
- return fBadInstruction;
- if (code)
+ code1 = fBadInstruction;
+ else if (code)
return fBadFontData;
I.z = this->inst;
if (design_grid)
@@ -349,6 +349,8 @@
return fBadInstruction;
if (code)
return fBadFontData;
+ if (code1)
+ return code1;
return code;
}
More information about the gs-cvs
mailing list