📄 ttf2pk.c
字号:
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); mapfiles = NULL; read_config_file(quiet); p = mapfiles; while (*p) { map_filename = p; while (*p != '\n') p++; *p++ = '\0'; real_map_filename = TeX_search_map_file(&map_filename); if (!real_map_filename) { if (!quiet) 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; } } 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 map files.\n", progname, fontname); exit(2);font_found: 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 | 0x1000000; } } } 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%04lx %s\n", (long)i, (code >= 0x1000000) ? "glyph" : "code", (code & 0xFFFFFF), 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%lx.", (code >= 0x1000000) ? "glyph" : "code", (code & 0xFFFFFF)); } } PKclose(); exit(0); /* for safety reasons */ return 0; /* never reached */}/* end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -