diff -urN ttf2pk.orig/newobj.c ttf2pk/newobj.c --- ttf2pk.orig/newobj.c Tue Jan 8 21:48:28 2002 +++ ttf2pk/newobj.c Wed Apr 24 00:23:26 2002 @@ -288,6 +288,8 @@ fnt->outname_postfix = NULL; fnt->fullname = NULL; + fnt->ofm_level = -1; + fnt->vplout = NULL; fnt->tfmout = NULL; @@ -323,6 +325,7 @@ fnt->xheight = 400; fnt->fontspace = 0; + fnt->font_dir = 0; fnt->y_offset = 0.25; diff -urN ttf2pk.orig/tfmaux.c ttf2pk/tfmaux.c --- ttf2pk.orig/tfmaux.c Tue Jan 8 21:48:28 2002 +++ ttf2pk/tfmaux.c Wed Apr 24 14:27:32 2002 @@ -33,17 +33,20 @@ static long nextd; /* smallest value that will give a different mincover */ -static int lf, lh, nw, nh, nd, ni, nl, nk, ne, np; -static int bc, ec; +static long lf, lh, nw, nh, nd, ni, nl, nk, ne, np; +static long bc, ec; + +static long nco, ncw, npc; +static long nki, nwi, nkf, nwf, nkm, nwm, nkr, nwr, nkg, nwg, nkp, nwp; static long *header, *charinfo, *width, *height, *depth, *ligkern, *kerns, *tparam, - *italic; + *italic, *exten; -static int source[257]; /* utility variables for sorting tfm arrays */ -static int unsort[257]; +static long source[65537]; /* utility variables for sorting tfm arrays */ +static long unsort[65537]; /* @@ -88,11 +91,11 @@ * Tells how many clusters result, given max difference d. */ -static int +static long mincover(long *what, register long d) { - register int m; + register long m; register long l; register long *p; @@ -116,12 +119,12 @@ static void remap(long *what, - int oldn, - int newn, - int *source, - int *unsort) + long oldn, + long newn, + long *source, + long *unsort) { - register int i, j; + register long i, j; register long d, l; what[oldn] = 0x7FFFFFFFL; @@ -162,7 +165,7 @@ } -void +static void write16(register short what, register FILE *out) { @@ -171,28 +174,32 @@ } -void +static void +write32(register long what, + register FILE *out) +{ + write16((short)(what >> 16), out); + write16(what & 0xFFFF, out); +} + + +static void writearr(register long *p, - register int n, + register long n, register FILE *out) { - while (n) - { - write16((short)(*p >> 16), out); - write16((short)(*p & 65535), out); - p++; - n--; - } + while (n--) + write32(*p++, out); } -void +static void writesarr(long *what, - int len, + long len, FILE *out) { register long *p; - int i; + long i; p = what; @@ -242,15 +249,15 @@ static long -checksum(ttfinfo **array) +checksum(ttfinfo **array, long size) { - int i; + long i; unsigned long s1 = 0, s2 = 0; char *p; ttfinfo *ti; - for (i = 0; i < 256; i++) + for (i = 0; i < size; i++) if (NULL != (ti = array[i])) { s1 = ((s1 << 1) ^ (s1 >> 31)) ^ ti->width; /* cyclic left shift */ @@ -366,7 +373,7 @@ } header = (long *)mymalloc(40000L); - cksum = checksum(fnt->inencptrs); + cksum = checksum(fnt->inencptrs, 256); header[0] = cksum; header[1] = 0xA00000; /* 10pt design size */ @@ -629,6 +636,336 @@ } fputs("\n] def\n", out); + fclose(out); +} + + +int +buildofm(Font *fnt) +{ + register long i, j; + register ttfinfo *ti, *tj; + long cksum, tmparray[65537]; + double Slant; + char buffer[256]; + ttfinfo *of_array[65536]; + + for (i = 0; i <= 0xFFFF; i++) + of_array[i] = NULL; + + for (ti = fnt->charlist; ti != NULL; ti = ti->next) + if (ti->charcode >= 0 && ti->charcode <= 0xFFFF) + of_array[ti->charcode] = ti; + + for (i = 0; i <= 0xFFFF && of_array[i] == NULL; i++) + ; + bc = i; + for (i = 0xFFFF; i >= 0 && of_array[i] == NULL; i--) + ; + ec = i; + + if (ec < bc) + oops("No TTF characters."); + + + /* header : array [0..lh-1] of stuff */ + header = (long *)mymalloc(100 * sizeof(long)); + cksum = checksum(of_array, 65536); + header[0] = cksum; + header[1] = 0xA00000; /* 10pt design size */ + + (void)makebcpl(header + 2, fnt->codingscheme, 39); + (void)makebcpl(header + 12, fnt->outname, 19); + + header[17] = 0; /* 4 bytes are left free for the unused FACE value */ + /* 0, 2, 4 : medium, bold, light + * 0, 1 : roman, italic + * 0, 6, 12 : regular, condensed, extended + */ + + buffer[0] = '\0'; + strncat(buffer, "Created by `", 12); + strncat(buffer, fnt->titlebuf, 255 - 12 - 1); + strncat(buffer, "'", 1); + lh = makebcpl(header + 18, buffer, 255) - header; + + + /* width : array [0..nw-1] of fix-word */ + width = tmparray; + width[0] = 0; + nw = 1; + + for (i = bc; i <= ec && nw < 65537; i++) + if (NULL != (ti = of_array[i])) + { + width[nw] = ti->width; + for (j = 1; width[j] != ti->width; j++) + ; + ti->wptr = j; + if (j == nw) + nw++; + } + if (nw > 65536) + oops("65536 chars with different widths."); + width = (long *)mymalloc(nw * sizeof(long)); + memmove(width, tmparray, nw * sizeof(long)); + + + /* height : array [0..nh-1] of fix-word */ + height = tmparray; + height[0] = 0; + nh = 1; + + for (i = bc; i <= ec && nh < 65537; i++) + if (NULL != (ti = of_array[i])) + { + height[nh] = ti->ury; + for (j = 0; height[j] != ti->ury; j++) + ; + ti->hptr = j; + if (j == nh) + nh++; + } + + if (nh > 256) + { + remap(height, nh, 256, source, unsort); + nh = 256; + for (i = bc; i <= ec; i++) + if (NULL != (ti = of_array[i])) + ti->hptr = unsort[ti->hptr]; + } + height = (long *)mymalloc(nh * sizeof(long)); + memmove(height, tmparray, nh * sizeof(long)); + + + /* depth : array [0..nd-1] of fix-word */ + depth = tmparray; + depth[0] = 0; + nd = 1; + + for (i = bc; i <= ec && nd < 65537; i++) + if (NULL != (ti = of_array[i])) + { + depth[nd] = -ti->lly; + for (j = 0; depth[j] != -ti->lly; j++) + ; + ti->dptr = j; + if (j == nd) + nd++; + } + + if (nd > 256) + { + remap(depth, nd, 256, source, unsort); + nd = 256; + for (i = bc; i <= ec; i++) + if (NULL != (ti = of_array[i])) + ti->dptr = unsort[ti->dptr]; + } + depth = (long *)mymalloc(nd * sizeof(long)); + memmove(depth, tmparray, nd * sizeof(long)); + + + /* italic : array [0..ni-1] of fix-word */ + italic = tmparray; + italic[0] = 0; + ni = 1; + + for (i = bc; i <= ec && ni < 65537; i++) + if (NULL != (ti = of_array[i])) + { + italic[ni] = ti->urx - ti->width; + if (italic[ni] < 0) + italic[ni] = 0; + for (j = 0; italic[j] != italic[ni]; j++) + ; + ti->iptr = j; + if (j == ni) + ni++; + } + + if (ni > 256) + { + remap(italic, ni, 256, source, unsort); + ni = 256; + for (i = bc; i <= ec; i++) + if (NULL != (ti = of_array[i])) + ti->iptr = unsort[ti->iptr]; + } + italic = (long *)mymalloc(ni * sizeof(long)); + memmove(italic, tmparray, ni * sizeof(long)); + + +#define MAX_NCW_ALLOC 1500 + /* char-info : array [0..ncw-1] of char-info-word */ + if (fnt->ofm_level == 0) + { + ncw = 2 * (ec - bc + 1); + charinfo = (long *)mymalloc(ncw * sizeof(long)); + + for (i = bc; i <= ec; i++) + if (NULL != (ti = of_array[i])) + { + charinfo[2*(i-bc)] = ((long)(ti->wptr) << 16) + + ((long)(ti->hptr & 0x00FF) << 8) + + ((long)(ti->dptr & 0x00FF)); + charinfo[2*(i-bc)+1] = ((long)(ti->iptr & 0x00FF) << 18); + } + else + { + charinfo[2*(i-bc)] = 0; + charinfo[2*(i-bc)+1] = 0; + } + } + else /* fnt->ofm_level == 1 */ + { + long max_ncw = MAX_NCW_ALLOC; + nki = nwi = nkf = nwf = nkm = nwm = nkr = nwr = nkg = nwg = nkp = nwp = 0; + nco = 29 + lh; + ncw = 0; + npc = 0; + + charinfo = (long *)mymalloc(max_ncw * sizeof(long)); + for (i = bc; i <= ec;) + { + if ((ti = of_array[i]) == NULL) + { + charinfo[ncw++] = 0; + charinfo[ncw++] = 0; + } + else + { + charinfo[ncw++] = ((long)(ti->wptr) << 16) + + ((long)(ti->hptr & 0x00FF) << 8) + + ((long)(ti->dptr & 0x00FF)); + charinfo[ncw++] = ((long)(ti->iptr & 0x00FF) << 24); + } + j = i++; + while (i <= ec) + { + tj = of_array[i]; + if ((ti == NULL && tj == NULL) || + (ti != NULL && tj != NULL && + ti->wptr == tj->wptr && ti->hptr == tj->hptr && + ti->dptr == tj->dptr && ti->iptr == tj->iptr)) + i++; + else + break; + } + charinfo[ncw++] = (i - j - 1) << 16; + if (ncw >= max_ncw) + { + max_ncw += MAX_NCW_ALLOC; + charinfo = (long *)myrealloc(charinfo, max_ncw * sizeof(long)); + } + } + } + + + /* lig-kern : array [0..nl-1] of lig-kern-command */ + nl = 0; + /* kern : array [0..nk-1] of fix-word */ + nk = 0; + /* exten : array [0..ne-1] of extensible-recipe */ + ne = 0; + + + Slant = fnt->slant - fnt->efactor * tan(fnt->italicangle * (PI / 180.0)); + /* param: array [1..np] of fix-word */ + np = 6; + tparam = (long *)mymalloc(np * sizeof(long)); + tparam[0] = (long)(FIXFACTOR * Slant + 0.5); + tparam[1] = scale((long)fnt->fontspace); + tparam[2] = (fnt->fixedpitch ? 0 : scale((long)(300 * fnt->efactor + 0.5))); + tparam[3] = (fnt->fixedpitch ? 0 : scale((long)(100 * fnt->efactor + 0.5))); + tparam[4] = scale((long)fnt->xheight); + tparam[5] = scale((long)(1000 * fnt->efactor + 0.5)); + + return 1; +} + + +void +writeofm(Font *fnt) +{ + FILE *out; + char *ofm_name; + int len = 0; + + + if (fnt->tfm_path) + len += strlen(fnt->tfm_path); + len += strlen(fnt->outname); + len += 5; /* fnt->ofm_ext = ".ofm" */ + + ofm_name = (char *)mymalloc(len); + ofm_name[0] = '\0'; + if (fnt->tfm_path) + strcat(ofm_name, fnt->tfm_path); + strcat(ofm_name, fnt->outname); + strcat(ofm_name, ".ofm"); + + if ((out = fopen(ofm_name, "wb")) == NULL) + oops("Cannot open ofm file `%s'.", ofm_name); + + free(ofm_name); + + + lf = lh + ncw + nw + nh + nd + ni + 2 * nl + nk + 2 * ne + np; + lf += (fnt->ofm_level == 1 ? 29 : 14); + + write32(fnt->ofm_level, out); + write32(lf, out); + write32(lh, out); + write32(bc, out); + write32(ec, out); + write32(nw, out); + write32(nh, out); + write32(nd, out); + write32(ni, out); + write32(nl, out); + write32(nk, out); + write32(ne, out); + write32(np, out); + write32(fnt->font_dir, out); + if (fnt->ofm_level == 1) + { + write32(nco, out); + write32(ncw, out); + write32(npc, out); + write32(nki, out); + write32(nwi, out); + write32(nkf, out); + write32(nwf, out); + write32(nkm, out); + write32(nwm, out); + write32(nkr, out); + write32(nwr, out); + write32(nkg, out); + write32(nwg, out); + write32(nkp, out); + write32(nwp, out); + } + writearr(header, lh, out); + /* Level 1 new parameter tables here, but we skip. */ + writearr(charinfo, ncw, out); + writesarr(width, nw, out); + writesarr(height, nh, out); + writesarr(depth, nd, out); + writesarr(italic, ni, out); + writearr(ligkern, 2 * nl, out); + writesarr(kerns, nk, out); + writearr(exten, 2 * ne, out); + writearr(tparam, np, out); + + free(header); + free(charinfo); + free(width); + free(height); + free(depth); + free(italic); + free(tparam); fclose(out); } diff -urN ttf2pk.orig/tfmaux.h ttf2pk/tfmaux.h --- ttf2pk.orig/tfmaux.h Tue Jan 8 21:48:28 2002 +++ ttf2pk/tfmaux.h Tue Apr 23 23:27:58 2002 @@ -23,6 +23,9 @@ void writetfm(Font *fnt); void writeenc(Font *fnt); +int buildofm(Font *fnt); +void writeofm(Font *fnt); + #endif /* TFMAUX_H */ diff -urN ttf2pk.orig/ttf2tfm.c ttf2pk/ttf2tfm.c --- ttf2pk.orig/ttf2tfm.c Tue Jan 8 21:48:28 2002 +++ ttf2pk/ttf2tfm.c Wed Apr 24 14:36:42 2002 @@ -272,6 +272,7 @@ -L LIGFILE[.sfd] create 1st/2nd byte ligatures in subfonts using LIGFILE\n\ -n use PS names of TrueType font\n\ -N use only PS names and no cmap\n\ +-o INT make an OFM file with level INT\n\ -O use octal for all character codes in the vpl file\n\ -p ENCFILE[.enc] read ENCFILE for the TTF->raw TeX mapping\n\ -P INT select INT as the TTF platform ID [3]\n\ @@ -528,6 +529,13 @@ arginc = 1; break; + case 'o': + if (argc <= 3) + oops("Missing parameter for -o option."); + if (sscanf(argv[3], "%hu", &(fnt->ofm_level)) == 0) + oops("Invalid OFM level."); + break; + default: if (argc <= 3 || argv[3][0] == '-') { @@ -679,6 +687,11 @@ warning("Ignoring `-n' or '-N' switch for subfonts."); fnt->PSnames = No; } + if (fnt->ofm_level > 1) + { + warning("Invalid OFM level, use the default level 1."); + fnt->ofm_level = 1; + } init_sfd(fnt, True); } @@ -711,6 +724,12 @@ if (fnt->y_offsetparam) warning("Ignoring `-y' switch for non-subfont."); + + if (fnt->ofm_level >= 0) + { + warning("Ignoring `-o' switch for non-subfont."); + fnt->ofm_level = -1; + } } if (fnt->PSnames == Only) @@ -913,6 +932,26 @@ } consttfonts(&font); + + if (font.ofm_level >= 0) + { + int i; + + for (i = 0; i < 255; i++) + font.sf_code[i] = i; + + readttf(&font, quiet, True); + + if (NULL != (ti = findadobe("space", font.charlist))) + font.fontspace = ti->width; + else if (NULL != (ti = findadobe(".c0x20", font.charlist))) + font.fontspace = ti->width; + else + font.fontspace = transform(500, 0, font.efactor, font.slant); + + buildofm(&font); + writeofm(&font); + } exit(0); /* for safety reasons */ return 0; /* never reached */ diff -urN ttf2pk.orig/ttf2tfm.h ttf2pk/ttf2tfm.h --- ttf2pk.orig/ttf2tfm.h Tue Jan 8 21:48:28 2002 +++ ttf2pk/ttf2tfm.h Wed Apr 24 00:23:50 2002 @@ -76,7 +76,7 @@ Boolean constructed; pcc *pccs; /* we use the composite feature for */ /* `germandbls' <--> `SS' only */ - unsigned char wptr, hptr, dptr, iptr; + unsigned short wptr, hptr, dptr, iptr; }; @@ -140,6 +140,8 @@ char *outname_postfix; /* NULL if not used */ char *fullname; /* outname + subfont_name + outname_postfix */ + short ofm_level; /* OFM level = 0 or 1 */ + FILE *vplout; FILE *tfmout; @@ -204,6 +206,7 @@ short xheight; /* xheight for TeX */ short fontspace; /* font space for TeX */ + char font_dir; /* * These values can be specified on the command line.