1 /* Copyright (C) 2001-2008 by George Williams */ 2 /* 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are met: 5 6 * Redistributions of source code must retain the above copyright notice, this 7 * list of conditions and the following disclaimer. 8 9 * Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 13 * The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #include "psfont.h" /* for struct fddata */ 29 30 #define MAC_DELETED_GLYPH_NAME "<Delete>" 31 32 /* Some glyphs have multiple encodings ("A" might be used for Alpha and Cyrillic A) */ 33 struct dup { 34 SplineChar *sc; 35 int enc; 36 int uni; 37 struct dup *prev; 38 }; 39 40 struct ttfinfo { 41 int emsize; /* ascent + descent? from the head table */ 42 int ascent, descent; /* from the hhea table */ 43 /* not the usWinAscent from the OS/2 table */ 44 int vertical_origin; /* if vmetrics are present */ 45 int width_cnt; /* from the hhea table, in the hmtx table */ 46 int glyph_cnt; /* from maxp table (or cff table) */ 47 unsigned int index_to_loc_is_long:1; /* in head table */ 48 unsigned int is_ttc:1; /* Is it a font collection? */ 49 unsigned int is_onebyte:1; /* Is it a one byte encoding? */ 50 unsigned int twobytesymbol:1; /* it had a symbol encoding which we converted to unicode */ 51 unsigned int complainedbeyondglyfend:1; /* Don't complain about this more than once */ 52 unsigned int extensionrequested:1; /* Only ask once for a copy of a font containing extension subtables */ 53 unsigned int to_order2:1; /* We are to leave the font as truetype (order2) splines, else convert to ps */ 54 unsigned int complainedmultname:1; /* Don't complain about this more than once */ 55 unsigned int strokedfont: 1; /* painttype==2 for otf */ 56 unsigned int use_typo_metrics: 1; 57 unsigned int weight_width_slope_only: 1; 58 unsigned int optimized_for_cleartype: 1; 59 unsigned int apply_lsb: 1; 60 enum openflags openflags; 61 /* Mac fonts platform=0/1, platform specific enc id, roman=0, english is lang code 0 */ 62 /* iso platform=2, platform specific enc id, latin1=0/2, no language */ 63 /* microsoft platform=3, platform specific enc id, 1, english is lang code 0x??09 */ 64 char *copyright; /* from the name table, nameid=0 */ 65 char *familyname; /* nameid=1 */ 66 char *fullname; /* nameid=4 */ 67 char *weight; 68 char *version; /* nameid=5 */ 69 char *fontname; /* postscript font name, nameid=6 */ 70 char *xuid; /* Only for open type cff fonts */ 71 int uniqueid; 72 real italicAngle; /* from post table */ 73 int upos, uwidth; /* underline pos, width from post table */ 74 real strokewidth; 75 int fstype; 76 struct psdict *private; /* Only for open type cff fonts */ 77 EncMap *map; 78 enum uni_interp uni_interp; 79 struct pfminfo pfminfo; 80 short os2_version; 81 short gasp_version; 82 int dupnamestate; 83 struct ttflangname *names; 84 char *fontcomments, *fontlog; 85 char **cvt_names; 86 SplineChar **chars; /* from all over, glyf table for contours */ 87 /* cmap table for encodings */ 88 /* hmtx table for widths */ 89 /* post table for names */ 90 /* Or from CFF table for everything in opentype */ 91 LayerInfo *layers; 92 int layer_cnt; 93 BDFFont *bitmaps; 94 char *cidregistry, *ordering; 95 int supplement; 96 real cidfontversion; 97 int subfontcnt; 98 SplineFont **subfonts; 99 char *inuse; /* What glyphs are used by this font in the ttc */ 100 101 int numtables; 102 /* BASE */ 103 uint32 base_start; /* Offset from sof to start of 'BASE' table */ 104 /* CFF */ 105 uint32 cff_start; /* Offset from sof to start of postscript compact font format */ 106 uint32 cff_length; 107 /* cmap */ 108 uint32 encoding_start; /* Offset from sof to start of encoding table */ 109 uint32 vs_start; /* Offset within 'cmap' to variant selector table */ 110 /* gasp */ 111 uint32 gasp_start; 112 /* glyf */ 113 uint32 glyph_start; /* Offset from sof to start of glyph table */ 114 uint32 glyph_length; 115 /* GDEF */ 116 uint32 gdef_start; /* Offset from sof to start of GDEF table (glyph class defn, ligature carets) */ 117 uint32 gdef_length; 118 /* GPOS */ 119 uint32 gpos_start; /* Offset from sof to start of GPOS table */ 120 uint32 gpos_length; 121 /* GSUB */ 122 uint32 gsub_start; /* Offset from sof to start of GSUB table */ 123 uint32 gsub_length; 124 uint32 g_bounds; /* Filled in with g???_start+g???_length */ 125 /* EBDT, bdat */ 126 uint32 bitmapdata_start; /* Offset to start of bitmap data */ 127 uint32 bitmapdata_length; 128 /* EBLT, bloc */ 129 uint32 bitmaploc_start; /* Offset to start of bitmap locator data */ 130 uint32 bitmaploc_length; 131 /* head */ 132 uint32 head_start; 133 /* hhea */ 134 uint32 hhea_start; 135 /* hmtx */ 136 uint32 hmetrics_start; 137 /* kern */ 138 uint32 kern_start; 139 /* loca */ 140 uint32 glyphlocations_start;/* there are glyph_cnt of these, from maxp tab */ 141 uint32 loca_length; /* actually glypn_cnt is wrong. Use the table length (divided by size) instead */ 142 /* maxp */ 143 uint32 maxp_start; /* maximum number of glyphs */ 144 uint32 maxp_len; 145 /* name */ 146 uint32 copyright_start; /* copyright and fontname */ 147 /* post */ 148 uint32 postscript_start; /* names for the glyphs, italic angle, etc. */ 149 /* OS/2 */ 150 uint32 os2_start; 151 /* TYP1 */ 152 uint32 typ1_start; /* For Adobe's? Apple's? attempt to stuff a type1 font into an sfnt wrapper */ 153 uint32 typ1_length; 154 /* vhea */ 155 uint32 vhea_start; 156 /* vmtx */ 157 uint32 vmetrics_start; 158 /* VORG */ 159 uint32 vorg_start; 160 161 /* PfEd -- FontForge/PfaEdit specific info */ 162 uint32 pfed_start; 163 /* TeX -- TeX table, also non-standard */ 164 uint32 tex_start; 165 /* BDF -- BDF properties, also non-standard */ 166 uint32 bdf_start; 167 /* FFTM -- FontForge timestamps */ 168 uint32 fftm_start; 169 170 /* MATH Table */ 171 uint32 math_start; 172 uint32 math_length; 173 174 /* Info for instructions */ 175 uint32 cvt_start, cvt_len; 176 uint32 prep_start, prep_len; 177 uint32 fpgm_start, fpgm_len; 178 179 unsigned int one_of_many: 1; /* A TTCF file, or a opentype font with multiple fonts */ 180 unsigned int obscomplain: 1; /* We've complained about obsolete format 3 in EBDT table */ 181 unsigned int cmpcomplain: 1; /* We've complained about compressed format 4 in EBDT */ 182 unsigned int unkcomplain: 1; /* We've complained about unknown formats in EBDT */ 183 unsigned int comcomplain: 1; /* We've complained about composit formats in EBDT */ 184 unsigned int onlystrikes: 1; /* Only read in the bitmaps, not the outlines */ 185 unsigned int onlyonestrike: 1; /* Only read in one bitmap (strike) */ 186 unsigned int barecff: 1; /* pay attention to the encoding in the cff file, we won't have a cmap */ 187 188 int platform, specific; /* values of the encoding we chose to use */ 189 190 int anchor_class_cnt; /* For GPOS */ 191 int anchor_merge_cnt; 192 AnchorClass *ahead, *alast; 193 194 KernClass *khead, *klast, *vkhead, *vklast; 195 196 OTLookup *gpos_lookups, *gsub_lookups, *cur_lookups; 197 198 struct ttf_table *tabs; 199 FPST *possub; 200 char *chosenname; 201 int macstyle; 202 int lookup_cnt; /* Max lookup in current GPOS/GSUB table */ 203 int feature_cnt; /* Max feature in current GPOS/GSUB table */ 204 struct fontdict *fd; /* For reading in Type42 fonts. Glyph names in postscript section must be associated with glyphs in TTF section */ 205 int savecnt; 206 struct savetab { 207 uint32 tag; 208 uint32 offset; 209 int len; 210 } *savetab; 211 int32 last_size_pos; 212 uint16 design_size; 213 uint16 fontstyle_id; 214 struct otfname *fontstyle_name; 215 uint16 design_range_bottom, design_range_top; 216 struct texdata texdata; 217 int mark_class_cnt; 218 char **mark_classes; /* glyph name list */ 219 char **mark_class_names; /* used within ff (utf8) */ 220 SplineChar **badgids; /* which use out of range glyph IDs as temporary flags */ 221 #ifdef _HAS_LONGLONG 222 long long creationtime; /* seconds since 1970 */ 223 long long modificationtime; 224 #else 225 long creationtime; 226 long modificationtime; 227 #endif 228 int gasp_cnt; 229 struct gasp *gasp; 230 struct MATH *math; 231 /* Set of errors we found when loading the font */ 232 unsigned int bad_ps_fontname: 1; 233 unsigned int bad_glyph_data: 1; 234 unsigned int bad_cff: 1; 235 unsigned int bad_metrics: 1; 236 unsigned int bad_cmap: 1; 237 unsigned int bad_embedded_bitmap: 1; 238 unsigned int bad_gx: 1; 239 unsigned int bad_ot: 1; 240 unsigned int bad_os2_version: 1; 241 unsigned int bad_sfnt_header: 1; 242 Layer guidelines; 243 struct Base *horiz_base, *vert_base; 244 }; 245 246 enum gsub_inusetype { git_normal, git_justinuse, git_findnames }; 247 248 #define MAX_TAB 48 249 struct tabdir { 250 int32 version; /* 0x00010000 */ 251 uint16 numtab; 252 uint16 searchRange; /* (Max power of 2 <= numtab) *16 */ 253 uint16 entrySel; /* Log2(Max power of 2 <= numtab ) */ 254 uint16 rangeShift; /* numtab*16 - searchRange */ 255 struct taboff { 256 uint32 tag; /* Table name */ 257 uint32 checksum;/* for table */ 258 uint32 offset; /* to start of table in file */ 259 uint32 length; 260 FILE *data; 261 uint16 dup_of; 262 uint16 orderingval; 263 } tabs[MAX_TAB]; /* room for all the above tables */ 264 /* Not in any particular order. */ 265 struct taboff *ordered[MAX_TAB]; /* Ordered the way the tables should be output in file */ 266 struct taboff *alpha[MAX_TAB]; /* Ordered alphabetically by tag for the ttf header */ 267 }; 268 269 struct glyphhead { 270 int16 numContours; 271 int16 xmin; 272 int16 ymin; 273 int16 xmax; 274 int16 ymax; 275 }; 276 277 struct head { 278 int32 version; /* 0x00010000 */ 279 int32 revision; /* 0 */ 280 uint32 checksumAdj; /* set to 0, sum entire font, store 0xb1b0afba-sum */ 281 uint32 magicNum; /* 0x5f0f3cf5 */ 282 uint16 flags; /* 1 */ 283 uint16 emunits; /* sf->ascent+sf->descent */ 284 int32 createtime[2];/* number of seconds since 1904 */ 285 int32 modtime[2]; 286 int16 xmin; /* min for entire font */ 287 int16 ymin; 288 int16 xmax; 289 int16 ymax; 290 uint16 macstyle; /* 1=>Bold, 2=>Italic */ 291 uint16 lowestreadable; /* size in pixels. Say about 10? */ 292 int16 dirhint; /* 0=>mixed directional characters, */ 293 int16 locais32; /* is the location table 32bits or 16, 0=>16, 1=>32 */ 294 int16 glyphformat; /* 0 */ 295 uint16 mbz; /* padding */ 296 }; 297 298 struct hhead { 299 int32 version; /* 0x00010000 */ 300 int16 ascender; /* sf->ascender */ 301 int16 descender; /* -sf->descender */ 302 int16 linegap; /* 0 */ 303 int16 maxwidth; /* of all characters */ 304 int16 minlsb; /* How is this different from xmin above? */ 305 int16 minrsb; 306 int16 maxextent; /* How is this different from xmax above? */ 307 int16 caretSlopeRise;/* Uh... let's say 1? */ 308 int16 caretSlopeRun;/* Uh... let's say 0 */ 309 /* not exactly specified, but FontValidator wants this to match italicangle */ 310 int16 mbz[5]; 311 int16 metricformat; /* 0 */ 312 uint16 numMetrics; /* just set to glyph count */ 313 }; 314 315 struct hmtx { 316 uint16 width; /* NOTE: TTF only allows positive widths!!! */ 317 int16 lsb; 318 }; 319 320 struct kern { 321 uint16 version; /* 0 */ 322 uint16 ntab; /* 1, number of subtables */ 323 /* first (and only) subtable */ 324 uint16 stversion; /* 0 */ 325 uint16 length; /* length of subtable beginning at &stversion */ 326 uint16 coverage; /* 1, (set of flags&format) */ 327 uint16 nPairs; /* number of kern pairs */ 328 uint16 searchRange; /* (Max power of 2 <= nPairs) *6 */ 329 uint16 entrySel; /* Log2(Max power of 2 <= nPairs ) */ 330 uint16 rangeShift; /* numtab*6 - searchRange */ 331 struct kp { 332 uint16 left; /* left glyph num */ 333 uint16 right; /* right glyph num */ 334 /* table is ordered by these two above treated as uint32 */ 335 int16 offset; /* kern amount */ 336 } *kerns; /* Array should be nPairs big */ 337 }; 338 339 struct maxp { 340 int32 version; /* 0x00010000 */ 341 uint16 numGlyphs; 342 uint16 maxPoints; /* max number of points in a simple glyph */ 343 uint16 maxContours; /* max number of paths in a simple glyph */ 344 uint16 maxCompositPts; 345 uint16 maxCompositCtrs; 346 uint16 maxZones; /* 1 */ 347 uint16 maxTwilightPts; /* 0 */ 348 uint16 maxStorage; /* 0 */ 349 uint16 maxFDEFs; /* 0 */ 350 uint16 maxIDEFs; /* 0 */ 351 uint16 maxStack; /* 0 */ 352 uint16 maxglyphInstr;/* 0 */ 353 uint16 maxnumcomponents; /* Maximum number of refs in any composit */ 354 uint16 maxcomponentdepth; 355 /* Apple docs say: 0 (if no composits), maximum value 1 (one level of composit) */ 356 /* OpenType docs say: 1 (if no composits), any depth allowed */ 357 }; 358 359 struct nametab { 360 uint16 format; /* 0 */ 361 uint16 numrec; /* 1 */ 362 uint16 startOfStrings; /* offset from start of table to start of strings */ 363 struct namerec { 364 uint16 platform; /* 3 => MS */ 365 uint16 specific; /* 1 */ 366 uint16 language; /* 0x0409 */ 367 uint16 nameid; /* 0=>copyright, 1=>family, 2=>weight, 4=>fullname */ 368 /* 5=>version, 6=>postscript name */ 369 uint16 strlen; 370 uint16 stroff; 371 } nr[6]; 372 }; 373 374 struct os2 { 375 uint16 version; /* 1 */ 376 int16 avgCharWid; /* average all chars (v3) see v2 definition below */ 377 uint16 weightClass; /* 100=>thin, 200=>extra-light, 300=>light, 400=>normal, */ 378 /* 500=>Medium, 600=>semi-bold, 700=>bold, 800=>extra-bold, */ 379 /* 900=>black */ 380 uint16 widthClass; /* 75=>condensed, 100, 125=>expanded */ 381 int16 fstype; /* 0x0008 => allow embedded editing */ 382 int16 ysubXSize; /* emsize/5 */ 383 int16 ysubYSize; /* emsize/5 */ 384 int16 ysubXOff; /* 0 */ 385 int16 ysubYOff; /* emsize/5 */ 386 int16 ysupXSize; /* emsize/5 */ 387 int16 ysupYSize; /* emsize/5 */ 388 int16 ysupXOff; /* 0 */ 389 int16 ysupYOff; /* emsize/5 */ 390 int16 yStrikeoutSize; /* 102/2048 *emsize */ 391 int16 yStrikeoutPos; /* 530/2048 *emsize */ 392 int16 sFamilyClass; /* ??? 0 */ 393 /* high order byte is the "class", low order byte the sub class */ 394 /* class = 0 => no classification */ 395 /* class = 1 => old style serifs */ 396 /* subclass 0, no class; 1 ibm rounded; 2 garalde; 3 venetian; 4 mod venitian; 5 dutch modern; 6 dutch trad; 7 contemporary; 8 caligraphic; 15 misc */ 397 /* class = 2 => transitional serifs */ 398 /* subclass 0, no class; 1 drect line; 2 script; 15 misc */ 399 /* class = 3 => modern serifs */ 400 /* subclass: 1, italian; 2, script */ 401 /* class = 4 => clarendon serifs */ 402 /* subclass: 1, clarendon; 2, modern; 3 trad; 4 newspaper; 5 stub; 6 monotone; 7 typewriter */ 403 /* class = 5 => slab serifs */ 404 /* subclass: 1, monotone; 2, humanist; 3 geometric; 4 swiss; 5 typewriter */ 405 /* class = 7 => freeform serifs */ 406 /* subclass: 1, modern */ 407 /* class = 8 => sans serif */ 408 /* subclass: 1, ibm neogrotesque; 2 humanist; 3 low-x rounded; 4 high-x rounded; 5 neo-grotesque; 6 mod neo-grot; 9 typewriter; 10 matrix */ 409 /* class = 9 => ornamentals */ 410 /* subclass: 1, engraver; 2 black letter; 3 decorative; 4 3D */ 411 /* class = 10 => scripts */ 412 /* subclass: 1, uncial; 2 brush joined; 3 formal joined; 4 monotone joined; 5 calligraphic; 6 brush unjoined; 7 formal unjoined; 8 monotone unjoined */ 413 /* class = 12 => symbolic */ 414 /* subclass: 3 mixed serif; 6 old style serif; 7 neo-grotesque sans; */ 415 char panose[10]; /* can be set to zero */ 416 uint32 unicoderange[4]; 417 /* 1<<0=>ascii, 1<<1 => latin1, 2=>100-17f, 3=>180-24f, 4=>250-2af */ 418 /* 5=> 2b0-2ff, 6=>300-36f, ... */ 419 char achVendID[4]; /* can be zero */ 420 uint16 fsSel; /* 1=> italic, 32=>bold, 64 => regular */ 421 /* 2=>underscore, 4=>negative, 8->outlined, 16=>strikeout */ 422 /* version 4 of OS/2 */ 423 /* 128->don't use win_ascent/descent for line spacing */ 424 /* 256=>family varies on weight width slope only */ 425 /* 512=>oblique (as opposed to italic) */ 426 uint16 firstcharindex; /* minimum unicode encoding */ 427 uint16 lastcharindex; /* maximum unicode encoding */ 428 uint16 ascender; /* font ascender height (not ascent) */ 429 uint16 descender; /* font descender height */ 430 uint16 linegap; /* 0 */ 431 uint16 winascent; /* ymax */ 432 uint16 windescent; /* ymin */ 433 uint32 ulCodePage[2]; 434 /* 1<<0 => latin1, 1<<1=>latin2, cyrillic, greek, turkish, hebrew, arabic */ 435 /* 1<<30 => mac, 1<<31 => symbol */ 436 /* OTF stuff (version 2 of OS/2) */ 437 short xHeight; 438 short capHeight; 439 short defChar; 440 short breakChar; 441 short maxContext; 442 /* V3 of OS/2 has no additional data */ 443 /* V4 of OS/2 has no additional data */ 444 445 int v1_avgCharWid; /* 1&2 Weighted average of the lower case letters and space */ 446 int v3_avgCharWid; /* 3&4 average over all non-zero width glyphs */ 447 }; 448 449 struct post { 450 int32 formattype; /* 0x00020000 */ 451 int32 italicAngle; /* in fixed format */ 452 int16 upos; 453 int16 uwidth; 454 uint32 isfixed; 455 uint32 minmem42; 456 uint32 maxmem42; 457 uint32 minmem1; 458 uint32 maxmem1; 459 uint16 numglyphs; 460 uint16 glyphnameindex[1]; 461 }; 462 463 struct glyphinfo { 464 struct maxp *maxp; /* this one is given to dumpglyphs, rest blank */ 465 uint32 *loca; 466 FILE *glyphs; 467 FILE *hmtx; 468 int hmtxlen; 469 FILE *vmtx; 470 int vmtxlen; 471 int next_glyph; 472 int glyph_len; 473 int xmin, ymin, xmax, ymax; 474 BlueData bd; 475 int strikecnt; /* number of bitmaps to dump */ 476 int lasthwidth, lastvwidth; /* encoding of last glyph for which we generate a full metrics entry */ 477 int hfullcnt, vfullcnt; 478 int flags; 479 int fixed_width; 480 int32 *bsizes; 481 unsigned int onlybitmaps: 1; 482 unsigned int has_instrs: 1; 483 unsigned int is_ttf: 1; 484 SplineFont *sf; 485 int32 *pointcounts; 486 int *bygid; /* glyph list */ 487 int gcnt; 488 int layer; 489 }; 490 491 struct vorg { 492 uint16 majorVersion; /* 1 */ 493 uint16 minorVersion; /* 0 */ 494 short defaultVertOriginY; /* Y coord of default vertical origin in the design coordinate system */ 495 uint16 numVertOriginYMetrics; /* exceptions to the above, elements in following array */ 496 #if 0 497 struct { 498 uint16 glyphindex; /* ordered */ 499 short vertOrigin; 500 } origins[]; 501 #endif 502 }; 503 504 struct alltabs { 505 struct tabdir tabdir; 506 struct head head; 507 struct hhead hhead; 508 struct hhead vhead; 509 struct maxp maxp; 510 struct os2 os2; 511 struct vorg vorg; 512 FILE *loca; 513 int localen; 514 FILE *name; 515 int namelen; 516 FILE *post; 517 int postlen; 518 FILE *gpos; /* Used instead of kern for opentype (and other glyph positioning) */ 519 int gposlen; 520 FILE *gsub; /* Used for ligatures and other substitutions */ 521 int gsublen; 522 FILE *gdef; /* If we use mark to base we need this to tell the text processor what things are marks (the opentype docs say it is optional. They are wrong) */ 523 int gdeflen; 524 FILE *kern; 525 int kernlen; 526 FILE *cmap; 527 int cmaplen; 528 FILE *headf; 529 int headlen; 530 FILE *hheadf; 531 int hheadlen; 532 FILE *maxpf; 533 int maxplen; 534 FILE *os2f; 535 int os2len; 536 FILE *math; 537 int mathlen; 538 FILE *base; 539 int baselen; 540 FILE *cvtf; 541 int cvtlen; 542 FILE *fpgmf; /* Copied from an original ttf file and dumped out. Never generated */ 543 int fpgmlen; 544 FILE *prepf; /* Copied from an original ttf file and dumped out. Never generated */ 545 int preplen; 546 FILE *vheadf; 547 int vheadlen; 548 FILE *vorgf; 549 int vorglen; 550 FILE *gaspf; 551 int gasplen; 552 FILE *cfff; 553 int cfflen; 554 FILE *sidf; 555 FILE *sidh; 556 FILE *charset; 557 FILE *encoding; 558 FILE *globalsubrs; 559 FILE *private; 560 FILE *charstrings; 561 FILE *fdselect; 562 FILE *fdarray; 563 FILE *bdat; /* might be EBDT */ 564 int bdatlen; 565 FILE *bloc; /* might be EBLC */ 566 int bloclen; 567 FILE *ebsc; 568 int ebsclen; 569 FILE *pfed; 570 int pfedlen; 571 FILE *tex; 572 int texlen; 573 FILE *bdf; 574 int bdflen; 575 FILE *fftmf; 576 int fftmlen; 577 FILE *dsigf; 578 int dsiglen; 579 FILE *hdmxf; 580 int hdmxlen; 581 int defwid, nomwid; 582 int sidcnt; 583 int lenpos; 584 int privatelen; 585 unsigned int sidlongoffset: 1; 586 unsigned int cfflongoffset: 1; 587 unsigned int applemode: 1; /* Where apple & ms differ do things apple's way (bitmaps, name table PostScript) */ 588 unsigned int opentypemode: 1; /* Where apple & ms differ do things opentype's way (bitmaps, name table PostScript) */ 589 /* If both are set then try to generate both types of tables. Some things can't be fudged though (name table postscript) */ 590 unsigned int msbitmaps: 1; 591 unsigned int applebitmaps: 1; 592 unsigned int otbbitmaps: 1; 593 unsigned int isotf: 1; 594 unsigned int error: 1; 595 struct glyphinfo gi; 596 int isfixed; 597 struct fd2data *fds; 598 int next_strid; 599 600 int next_lookup; /* for doing nested lookups in contextual features */ 601 short *gn_sid; 602 enum fontformat format; 603 int fontstyle_name_strid; /* For GPOS 'size' */ 604 SplineFont *sf; 605 EncMap *map; 606 struct ttf_table *oldcvt; 607 int oldcvtlen; 608 }; 609 610 struct subhead { uint16 first, cnt, delta, rangeoff; }; /* a sub header in 8/16 cmap table */ 611 612 enum touchflags { tf_x=1, tf_y=2, tf_d=4, tf_endcontour=0x80, tf_startcontour=0x40 }; 613 614 struct contexttree { 615 int depth; 616 int branch_cnt; /* count of subbranches of this node */ 617 struct ct_branch { 618 uint16 classnum; 619 struct contexttree *branch; 620 } *branches; 621 struct fpst_rule *ends_here; 622 int rule_cnt; /* count of rules which are active here */ 623 struct ct_subs { 624 struct fpst_rule *rule; 625 struct contexttree *branch;/* if the rule ends here this will be null */ 626 uint16 thisclassnum; 627 } *rules; 628 int pending_pos; 629 OTLookup *applymarkedsubs; 630 OTLookup *applycursubs; 631 uint16 marked_index, cur_index; 632 uint8 markme; 633 int state, next_state; 634 struct contexttree *parent; 635 }; 636 637 /* TrueType Composite glyph flags */ 638 #define _ARGS_ARE_WORDS 1 639 #define _ARGS_ARE_XY 2 640 #define _ROUND 4 /* round offsets so componant is on grid */ 641 #define _SCALE 8 642 /* 0x10 is reserved */ 643 #define _MORE 0x20 644 #define _XY_SCALE 0x40 645 #define _MATRIX 0x80 646 #define _INSTR 0x100 647 #define _USE_MY_METRICS 0x200 648 #define _OVERLAP_COMPOUND 0x400 /* Used in Apple GX fonts */ 649 /* Means the components overlap (which? this one and what other?) */ 650 /* Described in OpenType specs, not by Apple */ 651 /* amusingly, Apple supports but MS does not */ 652 /* MS says they support this after Win 2000 */ 653 #define _SCALED_OFFSETS 0x800 /* Use Apple definition of offset interpretation */ 654 #define _UNSCALED_OFFSETS 0x1000 /* Use MS definition */ 655 656 extern int ttfFixupRef(SplineChar **chars,int i); 657 658 /* Open type Advanced Typography Tables */ 659 extern void otf_dumpgpos(struct alltabs *at, SplineFont *sf); 660 extern void otf_dumpgsub(struct alltabs *at, SplineFont *sf); 661 extern void otf_dumpgdef(struct alltabs *at, SplineFont *sf); 662 extern void otf_dumpbase(struct alltabs *at, SplineFont *sf); 663 extern void otf_dump_dummydsig(struct alltabs *at, SplineFont *sf); 664 extern int gdefclass(SplineChar *sc); 665 666 extern void ttf_dumpkerns(struct alltabs *at, SplineFont *sf); 667 668 /* TrueType instructions */ 669 extern struct ttf_table *SFFindTable(SplineFont *sf,uint32 tag); 670 extern int TTF__getcvtval(SplineFont *sf,int val); 671 extern int TTF_getcvtval(SplineFont *sf,int val); 672 extern void SCinitforinstrs(SplineChar *sc); 673 extern int SSAddPoints(SplineSet *ss,int ptcnt,BasePoint *bp, char *flags); 674 675 /* Used by both otf and apple */ 676 extern int LigCaretCnt(SplineChar *sc); 677 extern uint16 *ClassesFromNames(SplineFont *sf,char **classnames,int class_cnt, 678 int numGlyphs, SplineChar ***glyphs, int apple_kc); 679 extern SplineChar **SFGlyphsFromNames(SplineFont *sf,char *names); 680 681 682 extern void AnchorClassOrder(SplineFont *sf); 683 extern SplineChar **EntryExitDecompose(SplineFont *sf,AnchorClass *ac, 684 struct glyphinfo *gi); 685 extern void AnchorClassDecompose(SplineFont *sf,AnchorClass *_ac, int classcnt, int *subcnts, 686 SplineChar ***marks,SplineChar ***base, 687 SplineChar ***lig,SplineChar ***mkmk, 688 struct glyphinfo *gi); 689 690 #ifdef _HAS_LONGLONG 691 extern void cvt_unix_to_1904( long long time, int32 result[2]); 692 #else 693 extern void cvt_unix_to_1904( long time, int32 result[2]); 694 #endif 695 696 697 /* Non-standard tables */ 698 /* My PfEd table for FontForge/PfaEdit specific info */ 699 extern void pfed_dump(struct alltabs *at, SplineFont *sf); 700 extern void pfed_read(FILE *ttf,struct ttfinfo *info); 701 /* The TeX table, to contain stuff the TeX people want */ 702 extern void tex_dump(struct alltabs *at, SplineFont *sf); 703 extern void tex_read(FILE *ttf,struct ttfinfo *info); 704 /* The BDF table, to contain bdf properties the X people want */ 705 extern int ttf_bdf_dump(SplineFont *sf,struct alltabs *at,int32 *sizes); 706 extern void ttf_bdf_read(FILE *ttf,struct ttfinfo *info); 707 /* The FFTM table, to some timestamps I'd like */ 708 extern int ttf_fftm_dump(SplineFont *sf,struct alltabs *at); 709 710 /* The MATH table */ 711 extern void otf_dump_math(struct alltabs *at, SplineFont *sf); 712 extern void otf_read_math(FILE *ttf,struct ttfinfo *info); 713 extern void otf_read_math_used(FILE *ttf,struct ttfinfo *info); 714 extern void GuessNamesFromMATH(FILE *ttf,struct ttfinfo *info); 715 716 /* Parsing advanced typography */ 717 extern void readttfkerns(FILE *ttf,struct ttfinfo *info); 718 extern void readttfgsubUsed(FILE *ttf,struct ttfinfo *info); 719 extern void GuessNamesFromGSUB(FILE *ttf,struct ttfinfo *info); 720 extern void readttfgpossub(FILE *ttf,struct ttfinfo *info,int gpos); 721 extern void readttfgdef(FILE *ttf,struct ttfinfo *info); 722 extern void readttfbase(FILE *ttf,struct ttfinfo *info); 723 724 extern struct otfname *FindAllLangEntries(FILE *ttf, struct ttfinfo *info, int id ); 725 726 /* Known font parameters for 'TeX ' table (fontdims, spacing params, whatever you want to call them) */ 727 /* Used by all fonts */ 728 #define TeX_Slant CHR('S','l','n','t') 729 #define TeX_Space CHR('S','p','a','c') 730 #define TeX_Stretch CHR('S','t','r','e') 731 #define TeX_Shrink CHR('S','h','n','k') 732 #define TeX_XHeight CHR('X','H','g','t') 733 #define TeX_Quad CHR('Q','u','a','d') 734 /* Used by text fonts */ 735 #define TeX_ExtraSp CHR('E','x','S','p') 736 /* Used by all math fonts */ 737 #define TeX_MathSp CHR('M','t','S','p') 738 /* Used by math fonts */ 739 #define TeX_Num1 CHR('N','u','m','1') 740 #define TeX_Num2 CHR('N','u','m','2') 741 #define TeX_Num3 CHR('N','u','m','3') 742 #define TeX_Denom1 CHR('D','n','m','1') 743 #define TeX_Denom2 CHR('D','n','m','2') 744 #define TeX_Sup1 CHR('S','u','p','1') 745 #define TeX_Sup2 CHR('S','u','p','2') 746 #define TeX_Sup3 CHR('S','u','p','3') 747 #define TeX_Sub1 CHR('S','u','b','1') 748 #define TeX_Sub2 CHR('S','u','b','2') 749 #define TeX_SupDrop CHR('S','p','D','p') 750 #define TeX_SubDrop CHR('S','b','D','p') 751 #define TeX_Delim1 CHR('D','l','m','1') 752 #define TeX_Delim2 CHR('D','l','m','2') 753 #define TeX_AxisHeight CHR('A','x','H','t') 754 /* Used by math extension fonts */ 755 #define TeX_DefRuleThick CHR('R','l','T','k') 756 #define TeX_BigOpSpace1 CHR('B','O','S','1') 757 #define TeX_BigOpSpace2 CHR('B','O','S','2') 758 #define TeX_BigOpSpace3 CHR('B','O','S','3') 759 #define TeX_BigOpSpace4 CHR('B','O','S','4') 760 #define TeX_BigOpSpace5 CHR('B','O','S','5') 761 762 extern void SFDummyUpCIDs(struct glyphinfo *gi,SplineFont *sf); 763