📄 otf2bdf.c
字号:
for (i = 1; i < slen; i += 2) {
if (dash_to_space)
*name++ = (s[i] != '-') ? s[i] : ' ';
else if (s[i] == '\r' || s[i] == '\n') {
if (s[i] == '\r' && i + 2 < slen && s[i + 2] == '\n')
i += 2;
*name++ = ' ';
*name++ = ' ';
} else
*name++ = s[i];
}
*name = 0;
return (slen >> 1);
}
}
/*
* No MS English name found, attempt to find an Apple Unicode English
* name.
*/
for (i = 0; i < nrec; i++) {
FT_Get_Sfnt_Name(face, i, &sfntName);
if (sfntName.platform_id == 0 && sfntName.language_id == 0 &&
sfntName.name_id == nameID) {
s = sfntName.string;
slen = sfntName.string_len;
break;
}
}
if (i < nrec) {
if (slen >> 1 >= name_size) {
fprintf(stderr, "%s: warning: %s string longer than buffer. Truncating to %d bytes.\n", prog, string_names[nameID], name_size);
slen = name_size << 1;
}
/*
* Found the Apple Unicode English name. The name is by definition
* encoded in Unicode, so copy every second byte into the `name'
* parameter, assuming there is enough space.
*/
for (i = 1; i < slen; i += 2) {
if (dash_to_space)
*name++ = (s[i] != '-') ? s[i] : ' ';
else if (s[i] == '\r' || s[i] == '\n') {
if (s[i] == '\r' && i + 2 < slen && s[i + 2] == '\n')
i += 2;
*name++ = ' ';
*name++ = ' ';
} else
*name++ = s[i];
}
*name = 0;
return (slen >> 1);
}
return 0;
}
/**************************************************************************
*
* Encoding table related functions.
*
**************************************************************************/
static char *
platform_name(short pid)
{
return (pid < nplatform_names) ?
platform_names[pid] : platform_names[nplatform_names - 1];
}
static char *
encoding_name(short pid, short eid)
{
int nnames;
char **names;
switch (pid) {
case 0: return "-ISO10646-1";
case 1:
nnames = nmac_encodings;
names = mac_encodings;
break;
case 2:
nnames = niso_encodings;
names = iso_encodings;
break;
case 3:
nnames = nms_encodings;
names = ms_encodings;
break;
default: return "-Unknown-0";
}
return (eid < nnames) ? names[eid] : "-Unknown-0";
}
static char *spaces = " ";
static void
print_encoding_table(void)
{
int ncmaps, i, j;
short pid, eid, lasteid;
char *np, *platform, encoding[64];
printf("Encoding tables available in the font:\n\n");
printf("Platform%.*sEncoding\n", 6, spaces);
printf("-------------------------------------------\n");
printf("Default%.*sDefault%.*s(-pid %d -eid %d)\n",
7, spaces, 7, spaces, DEFAULT_PLATFORM_ID, DEFAULT_ENCODING_ID);
ncmaps = face->num_charmaps;
for (lasteid = -1, i = 0; i < ncmaps; i++) {
pid = face->charmaps[i]->platform_id;
eid = face->charmaps[i]->encoding_id;
platform = platform_name(pid);
np = encoding_name(pid, eid);
np++;
for (j = 0; j < 63 && *np != '-'; np++, j++)
encoding[j] = *np;
encoding[j] = 0;
printf("%s%.*s%s%.*s(-pid %hd -eid %hd)\n",
platform, 14 - strlen(platform), spaces,
encoding, 14 - strlen(encoding), spaces, pid, eid);
}
}
/**************************************************************************
*
* General code.
*
**************************************************************************/
/*
* Create an XLFD name. Assumes there is enough space in the string passed
* to fit a reasonably long XLFD name into, up to the 256 byte maximum.
*/
static void
make_xlfd_name(char *name, int name_size, FT_Long awidth, int ismono)
{
FT_Long i;
FT_ULong val;
char *r, *e;
double dr, dp;
TT_OS2 *os2 = FT_Get_Sfnt_Table(face, ft_sfnt_os2);
/*
* Default the foundry name to "FreeType" in honor of the project and
* because the foundry name is too difficult to automatically determine
* from the names in TT fonts. But the user can provide his own.
*/
if (foundry_name == 0) {
(void) strcpy(name, "-FreeType");
name += 9;
} else {
*(name++)='-';
strcpy(name,foundry_name);
name+=strlen(foundry_name);
}
/*
* Add the typeface name from the font. The fallback default will be
* "Unknown".
*/
*name++ = '-';
if (face_name == 0) {
if((i = otf_get_english_string(face, BDFOTF_FAMILY_STRING, dashchar,
name, name_size)))
name += i;
else {
(void) strcpy(name, "Unknown");
name += 7;
}
} else {
(void) strcpy(name, face_name);
name += strlen(face_name);
}
/*
* Add the weight name. The default will be "Medium".
*/
if (weight_name != 0) {
sprintf(name, "-%s", weight_name);
name += strlen(weight_name) + 1;
} else {
if (os2->fsSelection & 0x20) {
(void) strcpy(name, "-Bold");
name += 5;
} else {
(void) strcpy(name, "-Medium");
name += 7;
}
}
/*
* Add the slant name. The default will be 'R'.
*/
if (slant_name) {
sprintf(name, "-%s", slant_name);
name += strlen(slant_name) + 1;
} else {
*name++ = '-';
if (os2->fsSelection & 0x01)
*name++ = 'I';
else
*name++ = 'R';
}
/*
* Default the setwidth name to "Normal" but user can specify one.
*/
if (width_name == 0) {
(void) strcpy(name, "-Normal");
name += 7;
} else {
*(name++)='-';
(void) strcpy(name, width_name);
name += strlen(width_name);
}
/*
* Default the additional style name to NULL but user can specify one.
*/
*name++ = '-';
if (style_name != 0) {
(void) strcpy(name, style_name);
name += strlen(style_name);
}
/*
* Determine the pixel size from the point size and resolution.
*/
dr = (double) vres;
dp = (double) (point_size * 10);
val = (unsigned long) (((dp * dr) / 722.7) + 0.5);
/*
* Set the pixel size, point size, and resolution.
*/
sprintf(name, "-%ld-%d-%d-%d", val, point_size * 10, hres, vres);
name += strlen(name);
switch (spacing) {
case 'p': case 'P': spacing = 'P'; break;
case 'm': case 'M': spacing = 'M'; break;
case 'c': case 'C': spacing = 'C'; break;
default: spacing = 0; break;
}
/*
* Set the spacing.
*/
if (!spacing)
spacing = (ismono) ? 'M' : 'P';
*name++ = '-';
*name++ = spacing;
/*
* Add the average width.
*/
sprintf(name, "-%ld", awidth);
name += strlen(name);
/*
* Check to see if the remapping table specified a registry and encoding
* and use those if they both exist.
*/
otf2bdf_remap_charset(&r, &e);
if (r != 0 && e != 0) {
sprintf(name, "-%s-%s", r, e);
return;
}
/*
* If the cmap for the platform and encoding id was not found, or the
* platform id is unknown, assume the character set registry and encoding
* are the XLFD default.
*/
if (nocmap || pid > 3)
(void) strcpy(name, DEFAULT_XLFD_CSET);
else {
/*
* Finally, determine the character set registry and encoding from the
* platform and encoding ID.
*/
switch (pid) {
case 0:
/*
* Apple Unicode platform, so "-Apple-Unicode" is the default.
*/
(void) strcpy(name, "-Apple-Unicode");
break;
case 1:
/*
* Macintosh platform, so choose from the Macintosh encoding
* strings.
*/
if (eid < 0 || eid >= nmac_encodings)
(void) strcpy(name, DEFAULT_XLFD_CSET);
else
(void) strcpy(name, mac_encodings[eid]);
break;
case 2:
/*
* ISO platform, so choose from the ISO encoding strings.
*/
if (eid < 0 || eid >= niso_encodings)
(void) strcpy(name, DEFAULT_XLFD_CSET);
else
(void) strcpy(name, iso_encodings[eid]);
break;
case 3:
/*
* Microsoft platform, so choose from the MS encoding strings.
*/
if (eid < 0 || eid >= nms_encodings)
(void) strcpy(name, DEFAULT_XLFD_CSET);
else
(void) strcpy(name, ms_encodings[eid]);
break;
}
}
}
static int
generate_font(FILE *out, char *iname, char *oname)
{
int eof, ismono, i;
FILE *tmp;
FT_Short x, y, dwidth, swidth;
FT_Short y_off, x_off;
FT_UShort sx, sy, ex, ey, wd, ht;
FT_Long code, idx, ng, aw;
FT_UShort remapped_code;
unsigned char *bp;
double dw;
char *xp, xlfd[BUFSIZ];
char *tmpdir, tmpfile[BUFSIZ];
imetrics = face->size->metrics;
horizontal = FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
/*
* Clear the BBX.
*/
memset((char *) &bbx, 0, sizeof(bbx_t));
/*
* Open a temporary file to store the bitmaps in until the exact number
* of bitmaps are known.
*/
if ((tmpdir = getenv("TMPDIR")) == 0)
tmpdir = "/tmp";
sprintf(tmpfile, "%s/otf2bdf%ld", tmpdir, (long) getpid());
if ((tmp = fopen(tmpfile, "w")) == 0) {
fprintf(stderr, "%s: unable to open temporary file '%s'.\n",
prog, tmpfile);
return -1;
}
/*
* Calculate the scale factor for the SWIDTH field.
*/
swscale = ((double) vres) * ((double) point_size);
/*
* Initialize the flag that tracks if the font is monowidth or not and
* initialize the glyph width variable that is used for testing for a
* monowidth font.
*/
wd = 0xffff;
ismono = 1;
for (ng = code = 0, eof = 0, aw = 0; eof != EOF && code < 0xffff; code++) {
/*
* If a remap is indicated, attempt to remap the code. If a remapped
* code is not found, then skip generating the glyph.
*/
remapped_code = (FT_UShort) code;
if (do_remap && !otf2bdf_remap(&remapped_code))
continue;
/*
* If a subset is being generated and the code is greater than the max
* code of the subset, break out of the loop to avoid doing any more
* work.
*/
if (do_subset && remapped_code > maxcode)
break;
/*
* If a subset is being generated and the index is not in the subset
* bitmap, just continue.
*/
if (do_subset &&
!(subset[remapped_code >> 5] & (1 << (remapped_code & 31))))
continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -