📄 otf2bdf.c
字号:
*/
if (*s == '_') {
s++;
for (; *s && isdig(*s); s++)
r = (r * 10) + (*s - '0');
} else
r = l;
/*
* Add the range just collected to the subset bitmap and set the flag
* that indicates a subset is wanted.
*/
for (; l <= r; l++) {
do_subset = 1;
subset[l >> 5] |= (1 << (l & 31));
if (l > maxcode)
maxcode = l;
}
/*
* Skip all non-digit characters.
*/
while (*s && !isdig(*s))
s++;
}
}
static void
usage(int eval)
{
printf("Usage: %s [options below] font.ttf\n", prog);
printf("-h\t\tThis message.\n");
printf("-v\t\tPrint warning messages during conversion.\n");
printf("-l \"subset\"\tSpecify a subset of glyphs to generate.\n");
printf("-m mapfile\tGlyph reencoding file.\n");
printf("-n\t\tTurn off glyph hinting.\n");
printf("-et\t\tDisplay the encoding tables available in the font.\n");
printf("-c c\t\tSet the character spacing (default: from font).\n");
printf("-f name\t\tSet the foundry name (default: freetype).\n");
printf("-t name\t\tSet the typeface name (default: from font).\n");
printf("-w name\t\tSet the weight name (default: Medium).\n");
printf("-s name\t\tSet the slant name (default: R).\n");
printf("-k name\t\tSet the width name (default: Normal).\n");
printf("-d name\t\tSet the additional style name (default: empty).\n");
printf("-u char\t\tSet the character to replace '-' in names ");
printf("(default: space).\n");
printf("-pid id\t\tSet the platform ID for encoding (default: %d).\n",
DEFAULT_PLATFORM_ID);
printf("-eid id\t\tSet the encoding ID for encoding (default: %d).\n",
DEFAULT_ENCODING_ID);
printf("-p n\t\tSet the point size (default: %dpt).\n",
DEFAULT_POINT_SIZE);
printf("-r n\t\tSet the horizontal and vertical resolution ");
printf("(default: %ddpi).\n", DEFAULT_RESOLUTION);
printf("-rh n\t\tSet the horizontal resolution ");
printf("(default: %ddpi)\n", DEFAULT_RESOLUTION);
printf("-rv n\t\tSet the vertical resolution ");
printf("(default: %ddpi)\n", DEFAULT_RESOLUTION);
printf("-o outfile\tSet the output filename (default: stdout).\n");
exit(eval);
}
int
main(int argc, char *argv[])
{
int res, pet;
char *infile, *outfile, *iname, *oname;
FILE *out, *mapin;
if ((prog = strrchr(argv[0], '/')))
prog++;
else
prog = argv[0];
/*
* Flag indicating whether the encoding tables are supposed to be printed
* or not.
*/
pet = 0;
out = stdout;
infile = outfile = 0;
argc--;
argv++;
while (argc > 0) {
if (argv[0][0] == '-') {
switch (argv[0][1]) {
case 'v': case 'V':
verbose = 1;
break;
case 'l': case 'L':
argc--;
argv++;
parse_subset(argv[0]);
break;
case 'n': case 'N':
load_flags |= FT_LOAD_NO_HINTING;
break;
case 'c': case 'C':
argc--;
argv++;
spacing = argv[0][0];
break;
case 't': case 'T':
argc--;
argv++;
face_name = argv[0];
break;
case 'w': case 'W':
argc--;
argv++;
weight_name = argv[0];
break;
case 's': case 'S':
argc--;
argv++;
slant_name = argv[0];
break;
case 'k': case 'K':
argc--;
argv++;
width_name = argv[0];
break;
case 'd': case 'D':
argc--;
argv++;
style_name = argv[0];
break;
case 'f': case 'F':
argc--;
argv++;
foundry_name = argv[0];
break;
case 'u': case 'U':
argc--;
argv++;
dashchar = argv[0][0];
break;
case 'p': case 'P':
res = argv[0][2];
argc--;
argv++;
if (res == 'i' || res == 'I') {
/*
* No need to print the encoding tables if the user
* is supplying a platform ID.
*/
pet = 0;
/*
* Set the platform ID.
*/
pid = atoi(argv[0]);
} else
/*
* Set the point size.
*/
point_size = atoi(argv[0]);
break;
case 'e': case 'E':
if (argv[0][2] == 't' || argv[0][2] == 'T')
pet = 1;
else {
/*
* No need to print the encoding tables if the user
* is supplying a platform ID.
*/
pet = 0;
/*
* Set the encoding ID.
*/
argc--;
argv++;
eid = atoi(argv[0]);
}
break;
case 'r':
/*
* Set the horizontal and vertical resolutions.
*/
if (argv[0][2] == 'h')
hres = atoi(argv[1]);
else if (argv[0][2] == 'v')
vres = atoi(argv[1]);
else
hres = vres = atoi(argv[1]);
argc--;
argv++;
break;
case 'm': case 'M':
/*
* Try to load a remap table.
*/
argc--;
argv++;
/*
* Always reset the `do_remap' variable here in case more than
* one map file appears on the command line.
*/
do_remap = 0;
if ((mapin = fopen(argv[0], "r")) == 0)
fprintf(stderr, "%s: unable to open the remap table '%s'.\n",
prog, argv[0]);
else {
if (otf2bdf_load_map(mapin) < 0) {
fprintf(stderr,
"%s: problem loading remap table '%s'.\n",
prog, argv[0]);
do_remap = 0;
} else
do_remap = 1;
fclose(mapin);
}
break;
case 'o': case 'O':
/*
* Set the output file name.
*/
argc--;
argv++;
outfile = argv[0];
break;
default:
usage(1);
}
} else
/*
* Set the input file name.
*/
infile = argv[0];
argc--;
argv++;
}
/*
* Validate the values passed on the command line.
*/
if (infile == 0) {
fprintf(stderr, "%s: no input file provided.\n", prog);
usage(1);
}
/*
* Set the input filename that will be passed to the generator
* routine.
*/
if ((iname = strrchr(infile, '/')))
iname++;
else
iname = infile;
/*
* Check the platform and encoding IDs.
*/
if (pid < 0 || pid > 255) {
fprintf(stderr, "%s: invalid platform ID '%d'.\n", prog, pid);
exit(1);
}
if (eid < 0 || eid > 65535) {
fprintf(stderr, "%s: invalid encoding ID '%d'.\n", prog, eid);
exit(1);
}
/*
* Arbitrarily limit the point size to a minimum of 2pt and maximum of
* 256pt.
*/
if (point_size < 2 || point_size > 256) {
fprintf(stderr, "%s: invalid point size '%dpt'.\n", prog, point_size);
exit(1);
}
/*
* Arbitrarily limit the resolutions to a minimum of 10dpi and a maximum
* of 1200dpi.
*/
if (hres < 10 || hres > 1200) {
fprintf(stderr, "%s: invalid horizontal resolution '%ddpi'.\n",
prog, hres);
exit(1);
}
if (vres < 10 || vres > 1200) {
fprintf(stderr, "%s: invalid vertical resolution '%ddpi'.\n",
prog, vres);
exit(1);
}
/*
* Open the output file if specified.
*/
if (outfile != 0) {
/*
* Attempt to open the output file.
*/
if ((out = fopen(outfile, "w")) == 0) {
fprintf(stderr, "%s: unable to open the output file '%s'.\n",
prog, outfile);
exit(1);
}
/*
* Set the output filename to be passed to the generator routine.
*/
if ((oname = strrchr(outfile, '/')))
oname++;
else
oname = outfile;
} else
/*
* Set the default output file name to <stdout>.
*/
oname = "<stdout>";
/*
* Intialize Freetype.
*/
if ((res = FT_Init_FreeType(&library))) {
/*
* Close the output file.
*/
if (out != stdout) {
fclose(out);
(void) unlink(outfile);
}
fprintf(stderr, "%s[%d]: unable to initialize renderer.\n",
prog, res);
exit(1);
}
/*
* Open the input file.
*/
if ((res = FT_New_Face(library, infile, 0, &face))) {
if (out != stdout) {
fclose(out);
(void) unlink(outfile);
}
fprintf(stderr, "%s[%d]: unable to open input file '%s'.\n",
prog, res, infile);
exit(1);
}
if (pet)
/*
* Simply print the encoding tables and do nothing else.
*/
print_encoding_table();
else {
/*
* Set the instance resolution and point size and the relevant
* metrics.
*/
FT_Set_Char_Size(face, 0, point_size * 64, hres, vres);
/*
* Set the global units per em value for convenience.
*/
upm = face->units_per_EM;
/*
* Generate the BDF font from the TrueType font.
*/
res = generate_bdf(out, iname, oname);
}
/*
* Free up the mapping table if one was loaded.
*/
otf2bdf_free_map();
/*
* Close the input and output files.
*/
(void) FT_Done_Face(face);
if (out != stdout) {
fclose(out);
if (res < 0)
/*
* An error occured when generating the font, so delete the
* output file.
*/
(void) unlink(outfile);
}
/*
* Shut down the renderer.
*/
FT_Done_FreeType(library);
exit(res);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -