>Date: Sat, 27 Jul 2002 21:45:46 -0400 >From: Zhuo Meng >To: cai@neurophys.wisc.edu Hi! Attached to the end of this message please find a patch containing my suggested changes to the ttfb330b.c file to enhance the TTF support for cnprint. The patch addresses 3 issues. The first one is support of ttc file. It simply selects the first font in the ttc file. The second one is a different method to estimate CJK character bondingbox, as suggested in TTF documentation. The old method only works if the CJK characters are the largest sized ones and will cause multi-script fonts such the Arial Unicode MS font to generate exceedingly small sized characters. The third one is rangecheck error in ufill due to a hardcoded glyph boundingbox in BuildGlyph() which is not big enough for some fonts. The Arial font is again an example for this problem. Hope this patch helps. Best wishes, -Zhuo Meng --- ttfb330b.c Fri Jul 26 17:52:23 2002 +++ ttfb330b-new.c Fri Jul 26 17:52:01 2002 @@ -39,7 +39,7 @@ struct TableEntry { char name[5]; unsigned long offset, len; -} cmap, glyf, head, loca, maxp, name, cvt, prep; +} cmap, glyf, head, loca, maxp, name, cvt, prep, hhea; /* CVT */ short *CVT_table; @@ -122,11 +122,22 @@ char s[5]; int j, Ntable; int n; + unsigned long DirOffset; struct TableEntry tmp, *a; - fseek(fp, 4L, 0); + fread(s, 1, 4, fp); + s[4] = 0; + if (strcmp(s, "ttcf")==0) { + fseek(fp, 12L, 0); + DirOffset = get4(fp) + 4L; + fseek(fp, DirOffset, 0); + } + else + fseek(fp, 4L, 0); Ntable = get2(fp); - fseek(fp, 12L, 0); + get2(fp); + get2(fp); + get2(fp); n = (Ntable > 50) ? 50 : Ntable; cmap.name[0]='\0'; for (j = 0; j < n; j++) { @@ -140,6 +151,7 @@ else if (strcmp(s, "name")==0) a = &name; else if (strcmp(s, "cvt ")==0) a = &cvt; else if (strcmp(s, "prep")==0) a = &prep; + else if (strcmp(s, "hhea")==0) a = &hhea; else a = &tmp; strcpy(a->name, s); get4(fp); /*** skip checksum ***/ @@ -298,13 +310,20 @@ max_depth = get2(fp); } +int GetUnitsPerEm(FILE *fp) +{ + fseek(fp, head.offset+18L, 0); + return get2(fp); +} + void GetBoundingBox(FILE *fp) /* get glyph bounding box */ { - fseek(fp, head.offset+36L, 0); - xmin = (short) get2(fp); + xmin = 0; + fseek(fp, hhea.offset+4L, 0); + ymax = (short) get2(fp); ymin = (short) get2(fp); - xmax = (short) get2(fp) - xmin; - ymax = (short) get2(fp) - ymin; + xmax = GetUnitsPerEm(fp); + ymax -= ymin; mx=xmax; my=ymax; /* for CNPRINT */ if (xmax < 1000) { scl=4; @@ -319,12 +338,6 @@ return (int) get2(fp); } -int GetUnitsPerEm(FILE *fp) -{ - fseek(fp, head.offset+18L, 0); - return get2(fp); -} - long LocalOffset(FILE *fp, int index) /* offset to locations of glyphs re. beginning of glyphData table */ { @@ -428,8 +441,8 @@ /* first set ufill bounding box: no harm to set it bigger than needed */ point[pidx++] = 0; point[pidx++] = 0; - point[pidx++] = 1248; /* xmax + 200 */ - point[pidx++] = 1248; /* ymax + 200 */ + point[pidx++] = mx + 200; + point[pidx++] = my + 200; op[oidx++] = 0; for (i = 0, j = 0; i < glyf_nctours; i++) {