📄 ttf2pk.c
字号:
/* * ttf2pk.c * * This file is part of the ttf2pk package. * * Copyright 1997-1999, 2000, 2002 by * Frederic Loyer <loyer@ensta.fr> * Werner Lemberg <wl@gnu.org> */#include <stdio.h>#include <stdlib.h>#include <stddef.h> /* for size_t */#include <string.h>#include <math.h>#include <ctype.h>#ifdef MIKTEX#include <miktex.h>#endif#include "ttf2tfm.h"#include "newobj.h"#include "pklib.h"#include "ttfenc.h"#include "ttflib.h"#include "errormsg.h"#include "filesrch.h"#include "parse.h"#include "subfont.h"char ident[] = "ttf2pk version 1.5";char progname[] = "ttf2pk"; /* for error/warning messages */static char *cfg_filename = "ttf2pk.cfg";char *mapfiles;Boolean have_sfd = False;Boolean have_pid = False;Boolean have_eid = False;/* * Checks for an equal sign surrounded by whitespace. */static char *strip_equal(char *s, char *os, char *p){ while (isspace(*p)) p++; if (*p != '=') boops(os, p - s, "Missing `='."); p++; while (isspace(*p)) p++; return p;}#define USAGE "\ Convert a TrueType font to TeX's PK format.\n\\n\-q suppress informational output\n\-n only use `.pk' as extension\n\-t test for <font> (returns 0 on success)\n\--help print this message and exit\n\--version print version number and exit\n\"static voidusage(void){ fputs("Usage: ttf2pk [-q] [-n] <font> <dpi>\n", stdout); fputs(" ttf2pk -t [-q] <font>\n", stdout); fputs(USAGE, stdout); exit(0);}#define VERSION "\Copyright (C) 1997-1999, 2000, 2002 Frederic Loyer and Werner Lemberg.\n\There is NO warranty. You may redistribute this software\n\under the terms of the GNU General Public License\n\and the gsftopk copyright.\n\\n\For more information about these matters, see the files\n\named COPYING and pklib.c.\n\\n\Primary authors of ttf2pk: F. Loyer and W. Lemberg.\n\\n\ttf2pk is partially based on gsftopk from P. Vojta\n\and the FreeType project from\n\David Turner, Robert Wilhelm, and Werner Lemberg\n\"static voidversion(void){ fputs(ident, stdout); fprintf(stdout, " (%s)\n", TeX_search_version()); fputs(VERSION, stdout); exit(0);}static intcompare(Font *fnt, char *s, char *key){ char c; char *p; char *temp, *temp1; int value; int sfd_begin, postfix_begin; /* * We isolate the fontname. */ while (isspace(*s)) s++; p = s; while (*p && !isspace(*p)) p++; c = *p; *p = '\0'; temp = newstring(s); *p = c; /* * We search for a subfont definition file name. */ handle_sfd(temp, &sfd_begin, &postfix_begin); if (sfd_begin == -1) value = strcmp(temp, key); else { size_t len, len1, len2; /* * The sfd file will be only searched if prefix and postfix match. */ len = strlen(key); len1 = strlen(temp); len2 = strlen(temp + postfix_begin); if (len1 + len2 >= len) value = -1; else if (!strncmp(temp, key, len1) && !strcmp(temp + postfix_begin, key + (len - len2))) { c = key[len - len2]; key[len - len2] = '\0'; temp1 = newstring(key + len1); key[len - len2] = c; if (fnt->sfdname) free(fnt->sfdname); fnt->sfdname = newstring(temp + sfd_begin); /* * If the sfd file can't be opened the search is continued. */ value = !init_sfd(fnt, False); if (!value) { value = -1; while (get_sfd(fnt, True)) { if (!strcmp(fnt->subfont_name, temp1)) { value = 0; /* success */ have_sfd = True; break; } } close_sfd(); } free(temp1); } else value = -1; } free(temp); return value;}static voidadd_mapfile(char *p){ char *q; if (*p != '+') /* if the first character is not '+' reset mapfiles */ { if (mapfiles) { free(mapfiles); mapfiles = NULL; } } else while (isspace(*++p)) ; for (q = p; *q != 0 && !isspace(*q); q++) ; *q = '\n'; /* '\n' is the splitting character */ if (mapfiles == NULL) { mapfiles = (char *)mymalloc(q - p + 2); *mapfiles = '\0'; } else mapfiles = (char *)myrealloc(mapfiles, strlen(mapfiles) + q - p + 2); strncat(mapfiles, p, (unsigned)(q - p)); strcat(mapfiles, "\n");}static voidread_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++; /* ignore comments */ if (*p == '*' || *p == '#' || *p == ';' || *p == '%') 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); } else if (!quiet) warning("Unknown configuration option `%s'.", p); } fclose(config_file); } else if (!quiet) warning("Cannot open file `%s'.", cfg_filename); } else if (!quiet) warning("Cannot find file `%s'.\n" "Use `ttfonts.map' instead as map file.", cfg_filename); if (mapfiles == NULL) mapfiles = newstring("ttfonts.map\n");}int main(int argc, char** argv){ size_t l; unsigned int i; long index, code; FILE *map_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, *map_filename; char *real_ttfname, *real_map_filename; int dpi = 0, ptsize; Boolean hinting = True; Boolean quiet = False; Boolean no_dpi = False; Boolean testing = False;#ifdef MIKTEX miktex_initialize();#endif 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -