int main(int argc, char** argv) { size_t l; unsigned int i; long index, code; FILE *config_file; 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; int dpi = 0, ptsize; Boolean hinting = True; Boolean quiet = False; Boolean no_dpi = False; Boolean testing = False; TeX_search_init(argv[0], "ttf2pk", "TTF2PK"); if (argc == 1) oops("Need at least two arguments.\n" "Try `ttf2pk --help' for more information."); if (argc == 2) { if (strcmp(argv[1], "--help") == 0) usage(); else if (strcmp(argv[1], "--version") == 0) version(); } while (argv[1][0] == '-') { if (argv[1][1] == 'q') quiet = True; else if (argv[1][1] == 'n') no_dpi = True; else if (argv[1][1] == 't') testing = True; else oops("Unknown option `%s'.\n" "Try `ttf2pk --help' for more information.", argv[1]); argv++; argc--; } if (testing) { if (argc != 2) oops("Need exactly one parameter for `-t' option.\n" "Try `ttf2pk --help' for more information."); } else if (argc != 3) oops("Need at most two arguments.\n" "Try `ttf2pk --help' for more information."); if (!quiet) printf("This is %s\n", ident); if (!testing) if ((dpi = atoi(argv[2])) <= 50) oops("dpi value must be larger than 50."); fontname = argv[1]; fontname_len = strlen(fontname); enc_filename = NULL; ptsize = 10; 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."); config_file = fopen(real_cfg_filename, "rt"); if (config_file == NULL) oops("Cannot open file ttfonts.map."); do { configline = get_line(config_file); if (!configline) oops("Error while reading ttfonts.map."); if (!*configline) { /* * 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); } } while (compare(&font, configline, fontname)); fclose(config_file); if (testing) { if (!quiet) fprintf(stdout, "%s\n", configline); exit(0); } /* * Parse the line from the config file. We split the config line buffer * into substrings according to the given options. */ l = strlen(configline); if (configline[l - 1] == '\n') configline[l - 1] = '\0'; /* strip newline */ oldconfigline = newstring(configline); p = configline; while (isspace(*p)) p++; while (*p && !isspace(*p)) p++; q = p; while (*p && isspace(*p)) p++; if (!*p) boops(oldconfigline, q - configline, "TTF file missing."); font.ttfname = p; while (*p && !isspace(*p)) p++; if (*p) *p++ = '\0'; for (; *p; p++) { if (isspace(*p)) continue; if (!strncmp(p, "Slant", 5)) { p = strip_equal(configline, oldconfigline, p + 5); if (sscanf(p, "%f", &(font.slant)) == 0) boops(oldconfigline, p - configline, "Bad `Slant' parameter."); } else if (!strncmp(p, "Encoding", 8)) { if (have_sfd) boops(oldconfigline, p - configline, "No `Encoding' parameter allowed for subfonts."); p = strip_equal(configline, oldconfigline, p + 8); if (!*p) boops(oldconfigline, p - configline, "Bad `Encoding' parameter."); enc_filename = p; } else if (!strncmp(p, "Extend", 6)) { p = strip_equal(configline, oldconfigline, p + 6); if (sscanf(p, "%f", &(font.efactor)) == 0) boops(oldconfigline, p - configline, "Bad `Extend' parameter."); } else if (!strncmp(p, "Fontindex", 9)) { p = strip_equal(configline, oldconfigline, p + 9); if (sscanf(p, "%lu", &(font.fontindex)) < 0) boops(oldconfigline, p - configline, "Bad `Fontindex' parameter."); } else if (!strncmp(p, "Pid", 3)) { p = strip_equal(configline, oldconfigline, p + 3); if (sscanf(p, "%hu", &(font.pid)) < 0) boops(oldconfigline, p - configline, "Bad `Pid' parameter."); have_pid = True; } else if (!strncmp(p, "Eid", 3)) { p = strip_equal(configline, oldconfigline, p + 3); if (sscanf(p, "%hu", &(font.eid)) < 0) boops(oldconfigline, p - configline, "Bad `Eid' parameter."); have_eid = True; } else if (!strncmp(p, "Hinting", 7)) { p = strip_equal(configline, oldconfigline, p + 7); if (p[1] == 'N' || p[1] == 'n' || p[0] == 'Y' || p[1] == 'y' || p[0] == '1') hinting = True; else if (p[1] == 'F' || p[1] == 'f' || p[0] == 'N' || p[1] == 'n' || p[0] == '0') hinting = False; else boops(oldconfigline, p - configline, "Bad `Hinting' parameter."); } else if (!strncmp(p, "PS", 2)) { p = strip_equal(configline, oldconfigline, p + 2); if (p[1] != '\0' && (p[2] == 'l' || p[2] == 'L')) font.PSnames = Only; else if (p[1] == 'N' || p[1] == 'n' || p[0] == 'Y' || p[0] == 'y' || p[0] == '1') font.PSnames = Yes; else if (p[1] == 'F' || p[1] == 'f' || p[0] == 'N' || p[0] == 'n' || p[0] == '0') font.PSnames = No; else boops(oldconfigline, p - configline, "Bad `PS' parameter."); if (have_sfd) boops(oldconfigline, p - configline, "No `PS' parameter allowed for subfonts."); } else if (!strncmp(p, "Rotate", 6)) { p = strip_equal(configline, oldconfigline, p + 6); if (p[1] == 'N' || p[1] == 'n' || p[0] == 'Y' || p[1] == 'y' || p[0] == '1') font.rotate = True; else if (p[1] == 'F' || p[1] == 'f' || p[0] == 'N' || p[1] == 'n' || p[0] == '0') font.rotate = False; else boops(oldconfigline, p - configline, "Bad `Rotate' parameter."); if (!have_sfd) boops(oldconfigline, p - configline, "No `Rotate' parameter allowed for non-subfonts."); } else if (!strncmp(p, "Y-Offset", 8)) { p = strip_equal(configline, oldconfigline, p + 8); if (sscanf(p, "%f", &(font.y_offset)) == 0) boops(oldconfigline, p - configline, "Bad `Y-Offset' parameter."); } else if (!strncmp(p, "Replacement", 11)) { p = strip_equal(configline, oldconfigline, p + 11); if (!*p) boops(oldconfigline, p - configline, "Bad `Replacement' parameter."); font.replacementname = p; } else { char *new_name, *old_name; stringlist *sl; old_name = p; while (*p && !isspace(*p) && *p != '=') p++; q = p; p = strip_equal(configline, oldconfigline, p); *q = '\0'; new_name = p; while (*p && !isspace(*p)) p++; if (*p) *p++ = '\0'; sl = newstringlist(); sl->new_name = new_name; sl->old_name = old_name; sl->next = font.replacements; font.replacements = sl; p--; /* to make the next while loop work */ } while (*p && !isspace(*p)) p++; if (*p) *p = '\0'; } if (font.PSnames == Only) if (have_pid || have_eid) boops(oldconfigline, 0, "No `Pid' or `Eid' parameters allowed if `PS=Only' is set."); font.replacementname = newstring(font.replacementname); get_replacements(&font); tfm_filename = newstring(fontname); TFMopen(&tfm_filename); pk_filename = mymalloc(fontname_len + 10); if (no_dpi) sprintf(pk_filename, "%s.pk", fontname); else sprintf(pk_filename, "%s.%dpk", fontname, dpi); PKopen(pk_filename, fontname, dpi); font.ttfname = newstring(font.ttfname); real_ttfname = TeX_search_ttf_file(&(font.ttfname)); if (!real_ttfname) oops("Cannot find `%s'.", font.ttfname); TTFopen(real_ttfname, &font, dpi, ptsize, quiet); enc_filename = newstring(enc_filename); enc = readencoding(&enc_filename, &font, True); if (enc) { char *name; restore_glyph(enc, &font); for (i = 0; i <= 0xFF; i++) { name = enc->vec[i]; if (!font.PSnames) { code = adobename_to_code(name); if (code < 0 && strcmp(name, ".notdef") != 0) warning("Cannot map character `%s'.", name); inenc_array[i] = code; } else { /* we search the glyph index */ index = TTFsearch_PS_name(name); if (index < 0) warning("Cannot map character `%s'.", name); inenc_array[i] = index | 0x10000; } } } else { if (font.replacements) warning("Replacement glyphs will be ignored."); if (have_sfd) TTFget_subfont(&font, inenc_array); else /* get the table of glyph names too */ enc = TTFget_first_glyphs(&font, inenc_array); } for (i = 0; i <= 0xFF; i++) { byte *bitmap; int w, h, hoff, voff; if ((code = inenc_array[i]) >= 0) { if (!quiet) { printf("Processing glyph %3ld %s index 0x%04x %s\n", (long)i, (code >= 0x10000) ? "glyph" : "code", (unsigned int)(code & 0xFFFF), enc ? enc->vec[i] : ""); fflush(stdout); } if (TTFprocess(&font, code, &bitmap, &w, &h, &hoff, &voff, hinting, quiet)) PKputglyph(i, -hoff, -voff, w - hoff, h - voff, w, h, bitmap); else warning("Cannot render glyph with %s index 0x%x.", (code >= 0x10000) ? "glyph" : "code", (unsigned int)(code & 0xFFFF)); } } PKclose(); exit(0); /* for safety reasons */ return 0; /* never reached */ }
int main(int argc, char *argv[]) { Font font; ttfinfo *ti; #ifdef MIKTEX miktex_initialize(); #endif init_font_structure(&font); TeX_search_init(argv[0], "ttf2tfm", "TTF2TFM"); if (argc == 1) { fputs("ttf2tfm: Need at least one file argument.\n", stderr); fputs("Try `ttf2tfm --help' for more information.\n", stderr); exit(1); } if (argc == 2) { if (strcmp(argv[1], "--help") == 0) usage(); else if (strcmp(argv[1], "--version") == 0) version(); } handle_options(argc, argv, &font); if (font.sfdname) { while (get_sfd(&font, True)) { char *temp, *ttemp; int i, start, end, len; get_tfm_fullname(&font); /* * Extract base name of sfd file. */ temp = newstring(font.sfdname); len = strlen(temp); start = 0; for (i = len - 1; i >= 0; i--) if (temp[i] == '/' || temp[i] == ':' || temp[i] == '\\') { start = i + 1; break; } end = len; for (i = len - 1; i >= 0; i--) if (temp[i] == '.') { end = i; break; } temp[end] = '\0'; ttemp = (char *)mymalloc(strlen(temp + start) + 4 + 1); sprintf(ttemp, "CJK-%s", temp + start); font.codingscheme = ttemp; free(temp); readttf(&font, quiet, True); if (font.replacements) warning("Replacement glyphs will be ignored."); /* second try to get an xheight value */ if (font.xheight == 0) { if (NULL != (ti = findadobe("x", font.charlist))) font.xheight = ti->ury; else if (font.pid == 3 && font.eid == 1 && NULL != (ti = findadobe(".c0x78", font.charlist))) font.xheight = ti->ury; else font.xheight = 400; } 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); if (font.ligname) get_sfd(&font, False); /* read sfd files for ligatures */ if (buildtfm(&font)) { writetfm(&font); if (font.write_enc) writeenc(&font); if (font.vplout) add_subfont_list(&font); } } close_sfd(); if (font.vplout) { writeovp(&font); fclose(font.vplout); release_subfont_list(&font); } } else { get_tfm_fullname(&font); readttf(&font, quiet, False); replace_glyphs(&font); /* second try to get an xheight value */ if (font.xheight == 0) { if (NULL != (ti = findadobe("x", font.charlist))) font.xheight = ti->ury; else if (font.pid == 3 && font.eid == 1 && NULL != (ti = findadobe(".c0x78", font.charlist))) font.xheight = ti->ury; else font.xheight = 400; } 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); handlereencoding(&font); buildtfm(&font); writetfm(&font); } if (makevpl) { assignchars(&font); if (makevpl > 1) upmap(&font); writevpl(&font, makevpl, forceoctal); fclose(font.vplout); } consttfonts(&font); exit(0); /* for safety reasons */ return 0; /* never reached */ }