[gs-cvs] rev 8785 - trunk/gs/src
leonardo at ghostscript.com
leonardo at ghostscript.com
Wed May 28 14:52:04 PDT 2008
Author: leonardo
Date: 2008-05-28 14:52:03 -0700 (Wed, 28 May 2008)
New Revision: 8785
Modified:
trunk/gs/src/gstype42.c
Log:
Fix (True Type font loader) : Work around incorrect numGlyphs (continued).
DETAILS :
Bug 689516 "problem reading PDF: Failed to interpret TT instructions (ref 7814)".
Bug 689866 "Regression: with TrueType fonts (possibly related to loca); file Bug688467.ps"
The last patch appears to cause a conflict with the revision 5707 change.
which introduced a hewristic for reapring fonts with unsorted loca.
When sortinmg the full loca (including glyphs behind numGlyps), the test cases
of bugs 688467 and 688461 cause overlapping glyphs,
so that the hewristic gives a wrong glyph length.
This patch improves the hewristic with checking the glyph length
obtained from the unsorted loca, and replaces it only if it looks incorrect.
f
which may need further adjustments.
EXPECTED DIFFERENCES :
None.
Modified: trunk/gs/src/gstype42.c
===================================================================
--- trunk/gs/src/gstype42.c 2008-05-28 18:16:26 UTC (rev 8784)
+++ trunk/gs/src/gstype42.c 2008-05-28 21:52:03 UTC (rev 8785)
@@ -108,6 +108,7 @@
typedef struct gs_type42_font_init_sort_s {
ulong glyph_offset;
int glyph_num;
+ int glyph_length;
} gs_type42_font_init_sort_t;
static int
gs_type42_font_init_compare (const void *a, const void *b)
@@ -307,6 +308,7 @@
*/
ulong last_glyph_offset = glyph_size;
ulong num_valid_loca_elm = loca_size;
+ long last_offset = 0;
gs_type42_font_init_sort_t *psort;
gs_type42_font_init_sort_t *psortary =
(gs_type42_font_init_sort_t *)gs_alloc_byte_array(pfont->memory,
@@ -314,18 +316,31 @@
if (psortary == 0)
return_error(gs_error_VMerror);
- for (i = 0, psort = psortary; i < loca_size; i++, psort++) {
+ /* loca_size > 0 due to condition above, so we always have the 0th element. */
+ psortary->glyph_num = 0;
+ psortary->glyph_offset = get_glyph_offset(pfont, 0);
+ for (i = 1, psort = psortary + 1; i < loca_size; i++, psort++) {
psort->glyph_num = i;
psort->glyph_offset = get_glyph_offset(pfont, i);
- }
+ psort[-1].glyph_length = psort->glyph_offset - last_offset;
+ last_offset = psort->glyph_offset;
+ }
+ psort[-1].glyph_length = 0; /* Dummy element. */
qsort(psortary, loca_size, sizeof(gs_type42_font_init_sort_t), gs_type42_font_init_compare);
while (num_valid_loca_elm > 0 && psortary[num_valid_loca_elm - 1].glyph_offset > glyph_size)
num_valid_loca_elm --;
if (0 == num_valid_loca_elm)
return_error(gs_error_invalidfont);
for (i = num_valid_loca_elm; i--;) {
+ long old_length;
+
psort = psortary + i;
- pfont->data.len_glyphs[psort->glyph_num] = last_glyph_offset - psort->glyph_offset;
+ old_length = psort->glyph_length;
+ if (old_length < 0 || old_length > 2000 /* arbitrary */) {
+ pfont->data.len_glyphs[psort->glyph_num] = last_glyph_offset - psort->glyph_offset;
+ /* Note the new length may be so big as old_length. */
+ } else
+ pfont->data.len_glyphs[psort->glyph_num] = old_length;
last_glyph_offset = psort->glyph_offset;
}
for (i = num_valid_loca_elm; i < loca_size; i++) {
More information about the gs-cvs
mailing list