diff -urN ttf2pk.orig/newobj.c ttf2pk/newobj.c --- ttf2pk.orig/newobj.c Thu Sep 7 22:00:30 2000 +++ ttf2pk/newobj.c Thu Dec 27 01:02:16 2001 @@ -304,6 +304,12 @@ fnt->sawligkern = False; fnt->subfont_ligs = False; +/* Patched by ChoF on Dec 27, 2001 */ + fnt->ligname = NULL; +/* End of patch by ChoF */ +/* Patched by ChoF on Nov 27, 2001 */ + fnt->write_enc = False; +/* End of patch by ChoF */ fnt->charlist = NULL; diff -urN ttf2pk.orig/subfont.c ttf2pk/subfont.c --- ttf2pk.orig/subfont.c Thu Sep 7 22:00:30 2000 +++ ttf2pk/subfont.c Thu Dec 27 01:05:08 2001 @@ -20,30 +20,31 @@ #include "errormsg.h" -static char *real_sfd_name; -static FILE *sfd; - - +/* init_sfd() was patched by ChoF on Dec 27, 2001 to call several times */ /* * Initialize subfont functionality. The argument is the subfont * definition file name. If `fatal' is `True', the routine exits * with an error. If `fatal' is `False', a warning message is emitted - * and `False' returned if an error occurs; in case of success `True' - * will be returned. + * and -1 returned if an error occurs; in case of success the file + * descriptor will be returned. */ -Boolean -init_sfd(Font *fnt, Boolean fatal) +FILE * +init_sfd(char *sfdname, Boolean fatal) { - real_sfd_name = TeX_search_sfd_file(&(fnt->sfdname)); + char *real_sfd_name; + FILE *sfd; + + + real_sfd_name = TeX_search_sfd_file(&sfdname); if (!real_sfd_name) { if (fatal) - oops("Cannot find subfont definition file `%s'.", fnt->sfdname); + oops("Cannot find subfont definition file `%s'.", sfdname); else { - warning("Cannot find subfont definition file `%s'.", fnt->sfdname); - return False; + warning("Cannot find subfont definition file `%s'.", sfdname); + return NULL; } } @@ -51,18 +52,19 @@ if (sfd == NULL) { if (fatal) - oops("Cannot open subfont definition file `%s'.", fnt->sfdname); + oops("Cannot open subfont definition file `%s'.", sfdname); else { - warning("Cannot open subfont definition file `%s'.", fnt->sfdname); - return False; + warning("Cannot open subfont definition file `%s'.", sfdname); + return NULL; } } - return True; + return sfd; } +/* get_sfd() was patched by ChoF on Dec 27, 2001 to call several times */ /* * This function fills the font structure sequentially with subfont * entries; it returns `False' if no more subfont entries are available, @@ -74,7 +76,7 @@ */ Boolean -get_sfd(Font *fnt) +get_sfd(FILE *sfd, Font *fnt) { long i, offset; long begin, end = -1; @@ -88,7 +90,7 @@ buffer = get_line(sfd); if (!buffer) - oops("Error reading subfont definition file `%s'.", real_sfd_name); + oops("Error reading subfont definition file `%s'.", fnt->sfdname); if (!*buffer) return False; @@ -127,7 +129,7 @@ bufp++; if (*bufp == '\0') - oops("Invalid subfont entry in `%s'.", real_sfd_name); + oops("Invalid subfont entry in `%s'.", fnt->sfdname); if (fnt->subfont_name) free(fnt->subfont_name); @@ -203,8 +205,9 @@ } +/* close_sfd() was patched by ChoF on Dec 27, 2001 to call several times */ void -close_sfd(void) +close_sfd(FILE *sfd) { if (sfd) fclose(sfd); diff -urN ttf2pk.orig/subfont.h ttf2pk/subfont.h --- ttf2pk.orig/subfont.h Thu Sep 7 22:00:30 2000 +++ ttf2pk/subfont.h Thu Dec 27 01:05:46 2001 @@ -14,9 +14,11 @@ #include "ttf2tfm.h" -Boolean init_sfd(Font *fnt, Boolean fatal); -Boolean get_sfd(Font *fnt); -void close_sfd(void); +/* Patched by ChoF on Dec 27, 2001 */ +FILE *init_sfd(char *sfdname, Boolean fatal); +Boolean get_sfd(FILE *sfd, Font *fnt); +void close_sfd(FILE *sfd); +/* End of patch by ChoF */ void handle_sfd(char *s, int *sfd_begin, int *postfix_begin); diff -urN ttf2pk.orig/tfmaux.c ttf2pk/tfmaux.c --- ttf2pk.orig/tfmaux.c Thu Sep 7 22:00:30 2000 +++ ttf2pk/tfmaux.c Thu Dec 27 01:08:32 2001 @@ -291,6 +291,23 @@ if (fnt->subfont_ligs) { +/* + * Patched by ChoF on Dec 27, 2001 to support HLaTeX ligature. + * + * TrueType fonts with Pid=3, Eid=1 (Unicode) do not contain KSX-1001 + * character codes (Wansung) so that the original program could not + * generate valid ligatures for HLaTeX. + */ + if (fnt->ligname) { + for (i = 0; i < 256; i++) + { + sf_array[i].sf_code = fnt->sf_code[i]; + sf_array[i].position = (fnt->sf_code[i] == -1 ? -1 : i); + } + } + else + { +/* End of patch by ChoF */ for (i = 0; i < 256; i++) { ti = fnt->inencptrs[i]; @@ -305,6 +322,9 @@ sf_array[i].position = -1; } } +/* Patched by ChoF on Dec 27, 2001 */ + } /* endif */ +/* End of patch by ChoF */ /* we sort the subfont character codes before we build a ligkern list */ qsort(sf_array, 256, sizeof (struct sf), compare_sf); @@ -572,6 +592,57 @@ writearr(tparam, np, out); free(header); + fclose(out); +} + + +/* + * writeenc() was written by ChoF on Nov 27, 2001 to generate enconding + * vectors containing glyph indices. The new option -w enables this + * feature. + */ +void +writeenc(Font *fnt) +{ + FILE *out; + char *enc_name; + int i, len = 0; + + + if (fnt->tfm_path) + len += strlen(fnt->tfm_path); + len += strlen(fnt->fullname); + len += 5; /* ".enc" + 1 */ + + enc_name = (char *)mymalloc(len); + enc_name[0] = '\0'; + if (fnt->tfm_path) + strcat(enc_name, fnt->tfm_path); + strcat(enc_name, fnt->fullname); + strcat(enc_name, ".enc"); + + if ((out = fopen(enc_name, "wb")) == NULL) + oops("Cannot open enc file `%s'.", enc_name); + + free(enc_name); + + fprintf(out, "/%sEncoding [", fnt->fullname); + for (i = 0; i < 256; i++) + { + if (i % 4 == 0) + fputc('\n', out); + if (fnt->inencptrs[i] == NULL) + fputs("/.notdef ", out); + else if (strcmp(fnt->inencptrs[i]->adobename, ".notdef") == 0 || + strcmp(fnt->inencptrs[i]->adobename, ".null") == 0 || + strcmp(fnt->inencptrs[i]->adobename, ".nonmarkingreturn") == 0 || + strcmp(fnt->inencptrs[i]->adobename, ".dummy") == 0) + fputs("/.notdef ", out); + else + fprintf(out, "/index0x%04X ", fnt->inencptrs[i]->glyphindex); + } + fputs("\n] def", out); + fclose(out); } diff -urN ttf2pk.orig/tfmaux.h ttf2pk/tfmaux.h --- ttf2pk.orig/tfmaux.h Thu Sep 7 22:00:30 2000 +++ ttf2pk/tfmaux.h Thu Dec 27 01:09:20 2001 @@ -21,6 +21,9 @@ int buildtfm(Font *fnt); void writetfm(Font *fnt); +/* Patched by ChoF on Nov 27, 2001 */ +void writeenc(Font *fnt); +/* End of patch by ChoF */ #endif /* TFMAUX_H */ diff -urN ttf2pk.orig/ttf2pk.c ttf2pk/ttf2pk.c --- ttf2pk.orig/ttf2pk.c Sat Apr 15 02:53:50 2000 +++ ttf2pk/ttf2pk.c Thu Dec 27 01:47:50 2001 @@ -27,9 +27,15 @@ #include "subfont.h" -char ident[] = "ttf2pk version 1.4"; +/* Patched by ChoF on Dec 27, 2001 */ +char ident[] = "ttf2pk version 1.4 (patched by ChoF on Dec 27, 2001)"; +/* End of patch by ChoF */ char progname[] = "ttf2pk"; /* for error/warning messages */ +/* Patched by ChoF on Nov 27, 2001 */ +static char *cfg_filename = "ttf2pk.cfg"; +char *mapfiles; +/* End of patch by ChoF */ Boolean have_sfd = False; Boolean have_pid = False; @@ -88,6 +94,8 @@ ttf2pk is partially based on gsftopk from P. Vojta\n\ and the FreeType project from\n\ David Turner, Robert Wilhelm, and Werner Lemberg\n\ +\n\ +Patched by ChoF on Dec 27, 2001 to support multiple map files.\n\ " static void @@ -137,6 +145,9 @@ else { size_t len, len1, len2; +/* Patched by ChoF on Dec 27, 2001 */ + FILE *sfd; +/* End of patch by ChoF */ /* @@ -165,13 +176,18 @@ * If the sfd file can't be opened the search is continued. */ - value = !init_sfd(fnt, False); +/* Patched by ChoF on Dec 27, 2001 */ + value = -1; + sfd = init_sfd(fnt->sfdname, False); - if (!value) + if (sfd != NULL) +/* End of patch by ChoF */ { value = -1; - while (get_sfd(fnt)) +/* Patched by ChoF on Dec 27, 2001 */ + while (get_sfd(sfd, fnt)) +/* End of patch by ChoF */ { if (!strcmp(fnt->subfont_name, temp1)) { @@ -181,7 +197,9 @@ } } - close_sfd(); +/* Patched by ChoF on Dec 27, 2001 */ + close_sfd(sfd); +/* End of patch by ChoF */ } free(temp1); @@ -196,21 +214,109 @@ } +/* + * add_mapfile() was written by ChoF on Nov 27, 2001 to support + * multiple map files. Basic structure comes from pdfTeX. + */ +static void +add_mapfile(char *p) +{ + char *q; + + if (*p != '+') /* if the fist character is not '+' reset mapfiles */ + { + if (mapfiles != 0) + { + free(mapfiles); + mapfiles = 0; + } + } + else + while (isspace(*++p)); + for (q = p; *q != 0 && !isspace(*q); q++); + *q = '\n'; /* '\n' is the splitting character */ + if (mapfiles == 0) + { + mapfiles = (char *)malloc((q - p + 2) * sizeof(char)); + *mapfiles = '\0'; + } + else + mapfiles = (char *)realloc(mapfiles, + (strlen(mapfiles) + q - p + 2) * sizeof(char *)); + strncat(mapfiles, p, (unsigned)(q - p)); + strcat(mapfiles, "\n"); +} + + +/* + * read_config_file() was written by ChoF on Nov 27, 2001 to support + * multiple map files. Basic structure comes from pdfTeX. + */ +static void +read_config_file(Boolean quiet) +{ + FILE *config_file; + char *p, *configline, *real_cfg_filename; + + + real_cfg_filename = TeX_search_config_file(&cfg_filename); + if (real_cfg_filename) + { + config_file = fopen(real_cfg_filename, "rt"); + if (config_file != NULL) + { + for (;;) + { + if (!(configline = get_line(config_file))) + oops("Error while reading %s.", cfg_filename); + if (!*configline) + break; + p = configline; + while (isspace(*p)) + p++; + if (*p == '*' || *p == '#' || *p == ';' || *p == '%') /* ignore comments */ + continue; + if (strlen(p) > 4 && strncmp(p, "map", 3) == 0) + { + p+=3; /* move by the size of "map" */ + while (isspace(*p)) + p++; + if (*p) + add_mapfile(p); + } + } + fclose(config_file); + } + else if (!quiet) + warning("Cannot open file %s.", cfg_filename); + } + else if (!quiet) + warning("Cannot find file %s. Use ttfonts.map instead.", cfg_filename); + + if (mapfiles == 0) + mapfiles = newstring("ttfonts.map\n"); +} + + int main(int argc, char** argv) { size_t l; unsigned int i; long index, code; - FILE *config_file; +/* Patched by ChoF on Nov 27, 2001 */ + FILE *map_file; +/* End of patch by ChoF */ char *configline, *oldconfigline, *p, *q; Font font; encoding *enc; long inenc_array[256]; char *fontname; size_t fontname_len; - char *pk_filename, *tfm_filename, *enc_filename, *cfg_filename; - char *real_ttfname, *real_cfg_filename; +/* Patched by ChoF on Nov 27, 2001 */ + char *pk_filename, *tfm_filename, *enc_filename, *map_filename; + char *real_ttfname, *real_map_filename; +/* End of patch by ChoF */ int dpi = 0, ptsize; Boolean hinting = True; Boolean quiet = False; @@ -273,36 +379,61 @@ init_font_structure(&font); - cfg_filename = newstring("ttfonts.map"); - real_cfg_filename = TeX_search_config_file(&cfg_filename); - if (!real_cfg_filename) - oops("Cannot find file ttfonts.map."); +/* Patched by ChoF on Nov 27, 2001 */ + mapfiles = 0; + read_config_file(quiet); - config_file = fopen(real_cfg_filename, "rt"); - if (config_file == NULL) - oops("Cannot open file ttfonts.map."); - - do + p = mapfiles; + while (*p != 0) { - configline = get_line(config_file); - if (!configline) - oops("Error while reading ttfonts.map."); - if (!*configline) + map_filename = p; + while (*p != '\n') p++; + *p++ = '\0'; + + real_map_filename = TeX_search_config_file(&map_filename); + if (!real_map_filename) { - /* - * This is the only error message we suppress if the -q flag - * is set, making it possible to call ttf2pk silently. - */ if (!quiet) - fprintf(stdout, - "%s: ERROR: Cannot find font %s in ttfonts.map.\n", - progname, fontname); - exit(2); + warning("Cannot find file %s.", map_filename); + continue; + } + + map_file = fopen(real_map_filename, "rt"); + if (map_file == NULL) + { + if (!quiet) + warning("Cannot open file %s.", map_filename); + continue; + } + + for (;;) + { + if (!(configline = get_line(map_file))) + oops("Error while reading %s.", map_filename); + if (!*configline) + break; + if (compare(&font, configline, fontname) == 0) + { + fclose(map_file); + goto font_found; + } } - } while (compare(&font, configline, fontname)); - fclose(config_file); + fclose(map_file); + } + /* + * This is the only error message we suppress if the -q flag + * is set, making it possible to call ttf2pk silently. + */ + if (!quiet) + fprintf(stdout, + "%s: ERROR: Cannot find font %s in the map files.\n", + progname, fontname); + exit(2); + +font_found: +/* End of patch by ChoF */ if (testing) { if (!quiet) diff -urN ttf2pk.orig/ttf2tfm.c ttf2pk/ttf2tfm.c --- ttf2pk.orig/ttf2tfm.c Sat Apr 15 02:53:50 2000 +++ ttf2pk/ttf2tfm.c Thu Dec 27 01:52:42 2001 @@ -38,9 +38,14 @@ #include "subfont.h" -char ident[] = "ttf2tfm version 1.4"; +/* Patched by ChoF on Dec 27, 2001 */ +char ident[] = "ttf2tfm version 1.4 (patched by ChoF on Dec 27, 2001)"; +/* End of patch by ChoF */ char progname[] = "ttf2tfm"; /* for error/warning messages */ +/* Patched by ChoF on Dec 27, 2001 */ +static FILE *sfd, *lfd; +/* End of patch by ChoF */ /* command line options */ static char makevpl; /* can be 1 or 2 */ @@ -245,6 +250,9 @@ ttf2tfm is based on afm2tfm from T. Rokicki\n\ and the FreeType project from\n\ David Turner, Robert Wilhelm, and Werner Lemberg.\n\ +\n\ +Patched by ChoF on Dec 27, 2001 to support HLaTeX ligature\n\ +and generate encoding vectors.\n\ " static void @@ -265,6 +273,7 @@ -E INT select INT as the TTF encoding ID [1]\n\ -f INT select INT as the font index in a TTC [0]\n\ -l create 1st/2nd byte ligatures in subfonts\n\ +-L LIGFILE[.sfd] create 1st/2nd byte ligatures in subfonts with LIGFILE\n\ -n use PS names of TrueType font\n\ -N use only PS names and no cmap\n\ -O use octal for all character codes in the vpl file\n\ @@ -279,6 +288,7 @@ -u output only characters from encodings, nothing extra\n\ -v FILE[.vpl] make a VPL file for conversion to VF\n\ -V SCFILE[.vpl] like -v, but synthesize smallcaps as lowercase\n\ +-w generate encoding vectors containing glyph indices\n\ -x rotate subfont glyphs by 90 degrees\n\ -y REAL move rotated glyphs down by a factor of REAL [0.25]\n\ --help print this message and exit\n\ @@ -498,11 +508,29 @@ arginc = 1; break; +/* Patched by ChoF on Dec 27, 2001 */ + case 'L': + if (argc <= 3) + oops("Missing parameter for -L option."); + if (fnt->ligname) + free(fnt->ligname); + fnt->ligname = newstring(argv[3]); + fnt->subfont_ligs = True; + break; +/* End of patch by ChoF */ + case 'l': fnt->subfont_ligs = True; arginc = 1; break; +/* Patched by ChoF on Nov 27, 2001 */ + case 'w': + fnt->write_enc = True; + arginc = 1; + break; +/* End of patch by ChoF */ + case 'x': fnt->rotate = True; arginc = 1; @@ -660,7 +688,11 @@ fnt->PSnames = No; } - init_sfd(fnt, True); +/* Patched by ChoF on Dec 27, 2001 */ + sfd = init_sfd(fnt->sfdname, True); + if (fnt->ligname) + lfd = init_sfd(fnt->ligname, True); +/* End of patch by ChoF */ } else { @@ -683,6 +715,12 @@ fnt->rotate = False; } + if (fnt->write_enc) + { + warning("Ignoring `-w' switch for non-subfont."); + fnt->write_enc = False; + } + if (fnt->y_offsetparam) warning("Ignoring `-y' switch for non-subfont."); } @@ -793,7 +831,9 @@ if (font.sfdname) { - while (get_sfd(&font)) +/* Patched by ChoF on Dec 27, 2001 */ + while (get_sfd(sfd, &font)) +/* End of patch by ChoF */ { char *temp; int i, start, end, len; @@ -840,11 +880,26 @@ else font.fontspace = transform(500, 0, font.efactor, font.slant); +/* Patched by ChoF on Dec 27, 2001 */ + if (font.ligname) + get_sfd(lfd, &font); +/* End of patch by ChoF */ + if (buildtfm(&font)) + { writetfm(&font); +/* Patched by ChoF on Nov 27, 2001 */ + if (font.write_enc) + writeenc(&font); +/* End of patch by ChoF */ + } } - close_sfd(); +/* Patched by ChoF on Dec 27, 2001 */ + close_sfd(sfd); + if (font.ligname) + close_sfd(lfd); +/* End of patch by ChoF */ } else { diff -urN ttf2pk.orig/ttf2tfm.h ttf2pk/ttf2tfm.h --- ttf2pk.orig/ttf2tfm.h Sat Apr 15 02:53:50 2000 +++ ttf2pk/ttf2tfm.h Thu Dec 27 01:53:28 2001 @@ -173,6 +173,14 @@ output encoding file */ Boolean subfont_ligs; /* ligatures 1st byte/2nd byte in subfonts wanted */ +/* Patched by ChoF on Dec 27, 2001 */ + char *ligname; /* ligatures 1st byte/2nd byte in + subfonts with ligaturename */ +/* End of patch by ChoF */ +/* Patched by ChoF on Nov 27, 2001 */ + Boolean write_enc; /* generate encoding vectors + containing glyph indices wanted */ +/* End of patch by ChoF */ ttfinfo *charlist; /* a linked list of all valid chars */