static int comp_fd_entry(const void *pa, const void *pb, void *p) { int i; const fd_entry *p1 = (const fd_entry *) pa, *p2 = (const fd_entry *) pb; assert(p1->fm != NULL && is_fontfile(p1->fm) && p2->fm != NULL && is_fontfile(p2->fm)); if ((i = strcmp(p1->fm->ff_name, p2->fm->ff_name)) != 0) return i; cmp_return(p1->fm->slant, p2->fm->slant); cmp_return(p1->fm->extend, p2->fm->extend); return 0; }
static fd_entry *lookup_fontdescriptor(fo_entry * fo) { assert(fo != NULL); assert(fo->fm != NULL); assert(is_fontfile(fo->fm)); return lookup_fd_entry(fo->fm->ff_name, fo->fm->slant, fo->fm->extend); }
void register_fd_entry(fd_entry * fd) { void **aa; if (fd_tree == NULL) { fd_tree = avl_create(comp_fd_entry, NULL, &avl_xallocator); assert(fd_tree != NULL); } assert(fd != NULL && fd->fm != NULL && is_fontfile(fd->fm)); assert(lookup_fd_entry(fd->fm->ff_name, fd->fm->slant, fd->fm->extend) == NULL); /* font descriptor not yet registered */ aa = avl_probe(fd_tree, fd); assert(aa != NULL); }
static boolean fm_valid_for_font_replacement(fm_entry * fm) { ff_entry *ff; assert(fm != NULL); assert(is_fontfile(fm)); /* ps_tree should contain only entries with font file */ assert(is_type1(fm)); /* ps_tree should contain only Type1 entries */ ff = check_ff_exist(fm->ff_name, false); assert(ff != NULL); if (ff->ff_path == NULL) /* ...there is no font file available */ return false; return true; /* all tests passed */ }
static void fm_scan_line() { int a, b, c, j, u = 0, v = 0; float d; fm_entry *fm; char fm_line[FM_BUF_SIZE], buf[FM_BUF_SIZE]; char *p, *q, *r, *s; switch (mitem->type) { case MAPFILE: p = fm_line; do { c = fm_getchar(); append_char_to_buf(c, p, fm_line, FM_BUF_SIZE); } while (c != 10 && !fm_eof()); *(--p) = '\0'; r = fm_line; break; case MAPLINE: r = mitem->line; /* work on string from makecstring() */ break; default: assert(0); } if (*r == '\0' || is_cfg_comment(*r)) return; fm = new_fm_entry(); read_field(r, q, buf); set_field(tfm_name); if (!isdigit(*r)) { /* 2nd field ps_name may not start with a digit */ read_field(r, q, buf); set_field(ps_name); } if (isdigit(*r)) { /* font descriptor /Flags given? */ for (s = r; isdigit(*s); s++); if (*s == ' ' || *s == '"' || *s == '<' || *s == '\0') { /* not e. g. 8r.enc */ fm->fd_flags = atoi(r); while (isdigit(*r)) r++; } } while (1) { /* loop through "specials", encoding, font file */ skip(r, ' '); switch (*r) { case '\0': goto done; case '"': /* opening quote */ r++; u = v = 0; do { skip(r, ' '); if (sscanf(r, "%f %n", &d, &j) > 0) { s = r + j; /* jump behind number, eat also blanks, if any */ if (*(s - 1) == 'E' || *(s - 1) == 'e') s--; /* e. g. 0.5ExtendFont: %f = 0.5E */ if (str_prefix(s, "SlantFont")) { d *= 1000.0; /* correct rounding also for neg. numbers */ fm->slant = (integer) (d > 0 ? d + 0.5 : d - 0.5); r = s + strlen("SlantFont"); } else if (str_prefix(s, "ExtendFont")) { d *= 1000.0; fm->extend = (integer) (d > 0 ? d + 0.5 : d - 0.5); if (fm->extend == 1000) fm->extend = 0; r = s + strlen("ExtendFont"); } else { /* unknown name */ for (r = s; *r != ' ' && *r != '"' && *r != '\0'; r++); /* jump over name */ c = *r; /* remember char for temporary end of string */ *r = '\0'; pdftex_warn ("invalid entry for `%s': unknown name `%s' ignored", fm->tfm_name, s); *r = c; } } else for (; *r != ' ' && *r != '"' && *r != '\0'; r++); } while (*r == ' '); if (*r == '"') /* closing quote */ r++; else { pdftex_warn ("invalid entry for `%s': closing quote missing", fm->tfm_name); goto bad_line; } break; case 'P': /* handle cases for subfonts like 'PidEid=3,1' */ if (sscanf(r, "PidEid=%i, %i %n", &a, &b, &c) >= 2) { fm->pid = a; fm->eid = b; r += c; break; } default: /* encoding or font file specification */ a = b = 0; if (*r == '<') { a = *r++; if (*r == '<' || *r == '[') b = *r++; } read_field(r, q, buf); /* encoding, formats: '8r.enc' or '<8r.enc' or '<[8r.enc' */ if (strlen(buf) > 4 && strcasecmp(strend(buf) - 4, ".enc") == 0) { fm->encname = add_encname(buf); u = v = 0; /* u, v used if intervening blank: "<< foo" */ } else if (strlen(buf) > 0) { /* file name given */ /* font file, formats: * subsetting: '<cmr10.pfa' * no subsetting: '<<cmr10.pfa' * no embedding: 'cmr10.pfa' */ if (a == '<' || u == '<') { set_included(fm); if ((a == '<' && b == 0) || (a == 0 && v == 0)) set_subsetted(fm); /* otherwise b == '<' (or '[') => no subsetting */ } set_field(ff_name); u = v = 0; } else { u = a; v = b; } } } done: if (fm->ps_name != NULL && check_std_t1font(fm->ps_name)) set_std_t1font(fm); if (is_fontfile(fm)) { if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".ttf") == 0) set_truetype(fm); else if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".otf") == 0) set_opentype(fm); else set_type1(fm); } else set_type1(fm); /* assume a builtin font is Type1 */ if (check_fm_entry(fm, true) != 0) goto bad_line; /* Until here the map line has been completely scanned without errors; fm points to a valid, freshly filled-out fm_entry structure. Now follows the actual work of registering/deleting. */ if (handle_subfont_fm(fm, mitem->mode)) /* is this a subfont? */ return; if (avl_do_entry(fm, mitem->mode) == 0) /* if success */ return; bad_line: delete_fm_entry(fm); }
int check_fm_entry(fm_entry * fm, boolean warn) { int a = 0; assert(fm != NULL); if (is_fontfile(fm) && !is_included(fm)) { if (warn) pdftex_warn ("ambiguous entry for `%s': font file present but not included, " "will be treated as font file not present", fm->tfm_name); xfree(fm->ff_name); /* do not set variable |a| as this entry will be still accepted */ } /* if both ps_name and font file are missing, drop this entry */ if (fm->ps_name == NULL && !is_fontfile(fm)) { if (warn) pdftex_warn ("invalid entry for `%s': both ps_name and font file missing", fm->tfm_name); a += 1; } /* TrueType fonts cannot be reencoded without subsetting */ if (is_truetype(fm) && is_reencoded(fm) && !is_subsetted(fm)) { if (warn) pdftex_warn ("invalid entry for `%s': only subsetted TrueType font can be reencoded", fm->tfm_name); a += 2; } /* SlantFont and ExtendFont can be used only with Type1 fonts */ if ((fm->slant != 0 || fm->extend != 0) && !(is_t1fontfile(fm) && is_included(fm))) { if (warn) pdftex_warn ("invalid entry for `%s': SlantFont/ExtendFont can be used only with embedded Type1 fonts", fm->tfm_name); a += 4; } /* the value of SlantFont and ExtendFont must be reasonable */ if (abs(fm->slant) > 1000) { if (warn) pdftex_warn ("invalid entry for `%s': too big value of SlantFont (%g)", fm->tfm_name, fm->slant / 1000.0); a += 8; } if (abs(fm->extend) > 2000) { if (warn) pdftex_warn ("invalid entry for `%s': too big value of ExtendFont (%g)", fm->tfm_name, fm->extend / 1000.0); a += 16; } /* subfonts must be used with subsetted non-reencoded TrueType fonts */ if (fm->pid != -1 && !(is_truetype(fm) && is_subsetted(fm) && !is_reencoded(fm))) { if (warn) pdftex_warn ("invalid entry for `%s': PidEid can be used only with subsetted non-reencoded TrueType fonts", fm->tfm_name); a += 32; } return a; }