📄 ttf2tfm.c
字号:
if (argc <= 3) oops("Missing parameter for -y option."); if (sscanf(argv[3], "%f", &(fnt->y_offset)) == 0) oops("Invalid y-offset."); fnt->y_offsetparam = argv[3]; break; case 'O': forceoctal = True; arginc = 1; break; case 'n': fnt->PSnames = Yes; arginc = 1; break; case 'N': fnt->PSnames = Only; arginc = 1; break; case 'u': pedantic = True; arginc = 1; break; case 'q': quiet = True; arginc = 1; break; 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; case 'l': fnt->subfont_ligs = True; arginc = 1; break; case 'w': fnt->write_enc = True; arginc = 1; break; case 'x': fnt->rotate = True; arginc = 1; break; default: if (argc <= 3 || argv[3][0] == '-') { warning("Unknown option `%s' will be ignored.\n", argv[2]); arginc = 1; } else warning("Unknown option `%s %s' will be ignored.\n", argv[2], argv[3]); } for (i = 0; i < arginc; i++) { l = strlen(fnt->titlebuf); fnt->titlebuf = (char *)myrealloc((void *)fnt->titlebuf, l + strlen(argv[2]) + 1 + 1); sprintf(fnt->titlebuf + strlen(fnt->titlebuf), " %s", argv[2]); argv++; argc--; } } /* Read replacement glyph name file */ get_replacements(fnt); if (argc > 3 || (argc == 3 && *argv[2] == '-')) oops("Need at most two non-option arguments."); /* * The tfm file name. */ if (argc == 2) temp = newstring(fnt->ttfname); else { temp = newstring(argv[2]); l = strlen(fnt->titlebuf); fnt->titlebuf = (char *)myrealloc((void *)fnt->titlebuf, l + strlen(argv[2]) + 1 + 1); sprintf(fnt->titlebuf + strlen(fnt->titlebuf), " %s", argv[2]); } handle_sfd(temp, &sfd_begin, &postfix_begin); if (sfd_begin > -1) { have_sfd = True; i = sfd_begin - 2; } else i = strlen(temp) - 1; /* * Now we search the beginning of the name without directory. */ for (; i >= 0; i--) if (temp[i] == '/' || temp[i] == ':' || temp[i] == '\\') break; base_name = i + 1; /* * We store the path (with the final directory separator). */ if (base_name > 0) { c = temp[base_name]; temp[base_name] = '\0'; fnt->tfm_path = newstring(temp); temp[base_name] = c; } if (have_sfd) { /* the prefix and the sfd file name */ if (temp[base_name]) fnt->outname = newstring(temp + base_name); fnt->sfdname = newstring(temp + sfd_begin); } else postfix_begin = base_name; /* * Get the extension. */ lastext = -1; for (i = postfix_begin; temp[i]; i++) if (temp[i] == '.') lastext = i; if (argc == 2 && lastext >= 0) { temp[lastext] = '\0'; /* remove TTF file extension */ lastext = -1; } if (lastext == -1) fnt->tfm_ext = newstring(".tfm"); else { fnt->tfm_ext = newstring(temp + lastext); temp[lastext] = '\0'; } if (have_sfd) { if (temp[postfix_begin]) fnt->outname_postfix = newstring(temp + postfix_begin); } else { if (temp[base_name]) fnt->outname = newstring(temp + base_name); else oops("Invalid tfm file name."); } /* * Now we can process the remaining parameters. */ if (have_sfd) { if (makevpl) { warning("Ignoring `-v' and `-V' switches for subfonts."); makevpl = 0; } if (have_capheight) warning("Ignoring `-c' switch for subfonts."); if (fnt->inencname || fnt->outencname) { warning("Ignoring `-p', `-t', and `-T' switches for subfonts."); fnt->inencname = NULL; fnt->outencname = NULL; } if (fnt->y_offsetparam && !fnt->rotate) warning("Ignoring `-y' switch for non-rotated subfonts."); if (fnt->PSnames) { warning("Ignoring `-n' or '-N' switch for subfonts."); fnt->PSnames = No; } init_sfd(fnt, True); } else { if (have_capheight && fnt->capheight < 0.01) oops("Bad small caps height."); if (vpl_name) if ((fnt->vplout = fopen(vpl_name, "wt")) == NULL) oops("Cannot open vpl output file."); if (fnt->subfont_ligs) { warning("Ignoring `-l' switch for non-subfont."); fnt->subfont_ligs = False; } if (fnt->rotate) { warning("Ignoring `-x' switch for non-subfont."); 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."); } if (fnt->PSnames == Only) { if (fnt->pidparam || fnt->eidparam) { warning("Ignoring `-P' and `-E' options if `-N' switch is selected."); fnt->pidparam = NULL; fnt->eidparam = NULL; } } if (vpl_name) free(vpl_name); free(temp);}/* * This routine prints out the line that needs to be added to ttfonts.map. */static voidconsttfonts(Font *fnt){ if (!quiet) printf("\n"); if (fnt->outname) printf("%s", fnt->outname); if (fnt->sfdname) printf("@%s@", fnt->sfdname); if (fnt->outname_postfix) printf("%s", fnt->outname_postfix); printf(" %s", fnt->ttfname); if (fnt->slantparam || fnt->efactorparam || fnt->inencname || fnt->pidparam || fnt->eidparam || fnt->fontindexparam || fnt->replacements || fnt->replacementname || fnt->PSnames || fnt->rotate || fnt->y_offsetparam) { if (fnt->slantparam) printf(" Slant=%s", fnt->slantparam); if (fnt->efactorparam) printf(" Extend=%s", fnt->efactorparam); if (fnt->inencname) printf(" Encoding=%s", fnt->inencname); if (fnt->pidparam) printf(" Pid=%s", fnt->pidparam); if (fnt->eidparam) printf(" Eid=%s", fnt->eidparam); if (fnt->fontindexparam) printf(" Fontindex=%s", fnt->fontindexparam); if (fnt->PSnames) printf(" PS=%s", fnt->PSnames == Yes ? "Yes" : "Only"); if (fnt->rotate) printf(" Rotate=Yes"); if (fnt->y_offsetparam) printf(" Y-Offset=%s", fnt->y_offsetparam); if (fnt->replacementname && fnt->inencoding) printf(" Replacement=%s", fnt->replacementname); if (fnt->replacements && fnt->inencoding) { stringlist *sl; for (sl = fnt->replacements; sl; sl = sl->next) if (sl->single_replacement) printf(" %s=%s", sl->old_name, sl->new_name); } } printf("\n");}intmain(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; 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'; font.codingscheme = (char *)mymalloc(strlen(temp + start) + 4 + 1); sprintf(font.codingscheme, "CJK-%s", temp + start); 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); } } close_sfd(); } 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 */}/* end */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -