Debian Codegraph @

fontforge/splinefont.h

raw symbols SCIP
1 /* Copyright (C) 2000-2012 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 #ifndef FONTFORGE_SPLINEFONT_H
29 #define FONTFORGE_SPLINEFONT_H
30
31 #include "basics.h"
32 #include "dlist.h"
33 #include "gwwiconv.h"
34 #include "ustring.h"
35 #include "splinechar.h"
36 #include "splinefont_enums.h"
37
38 #include <locale.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define extended double
45 /* Solaris wants to define extended to be unsigned [3] unless we do this*/
46 #define _EXTENDED
47
48 #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
49
50 /* The maximum number of layers allowed in a normal font (this includes the */
51 /* default foreground and background layers) -- this does not limit type3 */
52 /* fonts */
53 #define BACK_LAYER_MAX 256
54
55 typedef struct dbasepoint {
56 bigreal x;
57 bigreal y;
58 } DBasePoint;
59
60 #define DBASEPOINT_EMPTY { (bigreal)0.0, (bigreal)0.0 }
61
62 typedef struct ibounds {
63 int minx, maxx;
64 int miny, maxy;
65 } IBounds;
66
67 #define IBOUNDS_EMPTY { 0, 0, 0, 0 }
68
69
70 enum val_type { v_int, v_real, v_str, v_unicode, v_lval, v_arr, v_arrfree,
71 v_void };
72
73 enum val_flags {
74 vf_none = 0,
75 vf_dontfree = (1 << 1)
76 };
77
78 typedef struct val {
79 enum val_type type;
80 enum val_flags flags;
81 union {
82 int ival;
83 real fval;
84 char *sval;
85 struct val *lval;
86 struct array *aval;
87 } u;
88 } Val; /* Used by scripting */
89
90 struct psdict {
91 int cnt; /* *key[0..cnt] and *values[0..cnt] currently available */
92 int next; /* **key[0..next] and **values[0..next] currently used */
93 char **keys;
94 char **values;
95 };
96
97 struct pschars {
98 int cnt, next;
99 char **keys;
100 uint8_t **values;
101 int *lens;
102 int bias; /* for type2 strings */
103 };
104
105 enum linejoin {
106 lj_miter, /* Extend lines until they meet */
107 lj_round, /* connect with arc (not w/ stroking - see "nib") */
108 lj_bevel, /* Straight line between the ends of next and prev */
109 lj_miterclip, /* Extend lines until they meet */
110 lj_nib, /* Join with the nib shape */
111 lj_arcs,
112 lj_inherited
113 };
114 enum linecap {
115 lc_butt, /* Finish with line perpendicular to end tangent */
116 lc_round, /* semi-circle (not w/ stroking - see "nib") */
117 lc_square, /* Not used w/ stroking - use lc_butt w/ extend */
118 lc_nib, /* cap with the nib shape */
119 lc_bevel, /* Just join endpoints with a line */
120 lc_inherited
121 };
122 enum stroke_rmov {
123 srmov_layer = 0,
124 srmov_contour = 1,
125 srmov_none = 2
126 };
127 enum stroke_arclimit {
128 sal_auto = 0,
129 sal_svg2 = 1,
130 sal_ratio = 2
131 };
132
133 #define JLIMIT_INHERITED (-1)
134
135 struct spline;
136 enum si_type { si_round, si_calligraphic, si_nib, si_centerline };
137 /* If you change this structure you may need to update MakeStrokeDlg */
138 /* and cvpalettes.c -- both contain statically initialized StrokeInfos */
139 typedef struct strokeinfo {
140 bigreal width; /* or major axis of pen */
141 enum linejoin join;
142 enum linecap cap;
143 enum si_type stroke_type;
144 enum stroke_rmov rmov;
145 enum stroke_arclimit al;
146 // Could be bits but the python interface would be annoying
147 int removeinternal, removeexternal, simplify, extrema;
148 int leave_users_center, jlrelative, ecrelative;
149 bigreal penangle, height, extendcap, joinlimit, accuracy_target;
150 struct splinepointlist *nib;
151 /* For freehand tool, not currently used in practice */
152 real radius2;
153 int pressure1, pressure2;
154 void *data;
155 bigreal (*factor)(void *data,struct spline *spline,real t);
156 /* End freehand */
157 } StrokeInfo;
158
159 extern StrokeInfo *InitializeStrokeInfo(StrokeInfo *sip);
160 extern void SITranslatePSArgs(StrokeInfo *sip, enum linejoin lj,
161 enum linecap lc);
162
163 enum overlap_type { over_remove, over_rmselected, over_intersect, over_intersel,
164 over_exclude, over_findinter, over_fisel };
165
166 enum simpify_flags { sf_cleanup=-1, sf_normal=0, sf_ignoreslopes=1,
167 sf_ignoreextremum=2, sf_smoothcurves=4, sf_choosehv=8,
168 sf_forcelines=0x10, sf_nearlyhvlines=0x20,
169 sf_mergelines=0x40, sf_setstart2extremum=0x80,
170 sf_rmsingletonpoints=0x100 };
171 struct simplifyinfo {
172 int flags;
173 bigreal err;
174 bigreal tan_bounds;
175 bigreal linefixup;
176 bigreal linelenmax; /* Don't simplify any straight lines longer than this */
177 int set_as_default;
178 int check_selected_contours;
179 };
180
181 struct hsquash { double lsb_percent, stem_percent, counter_percent, rsb_percent; };
182
183 enum serif_type { srf_flat, srf_simpleslant, srf_complexslant };
184 /* | | (flat) | | (simple) | | (complex) */
185 /* | | | / | / */
186 /* | | | / | / */
187 /* +----+ |/ \ / */
188
189 typedef struct italicinfo {
190 double italic_angle;
191 double xheight_percent;
192 struct hsquash lc, uc, neither;
193 enum serif_type secondary_serif;
194
195 unsigned int transform_bottom_serifs: 1;
196 unsigned int transform_top_xh_serifs: 1; /* Those at x-height */
197 unsigned int transform_top_as_serifs: 1; /* Those at ascender-height */
198 unsigned int transform_diagon_serifs: 1; /* Those at baseline/xheight */
199
200 unsigned int a_from_d: 1; /* replace the "a" glyph with the variant which looks like a "d" without an ascender */
201 /* When I say "f" I also mean "f_f" ligature, "longs", cyrillic phi and other things shaped like "f" */
202 unsigned int f_long_tail: 1; /* Some Italic fonts have the "f" grow an extension of the main stem below the baseline */
203 unsigned int f_rotate_top: 1; /* Most Italic fonts take the top curve of the "f", rotate it 180 and attach to the bottom */
204 unsigned int pq_deserif: 1; /* Remove a serif from the descender of p or q and replace with a secondary serif as above */
205
206 /* Unsupported */
207 /* e becomes rounder, cross bar slightly slanted */
208 /* g closed counter at bottom */
209 /* k closed counter at top */
210 /* v-z diagonal stems become more curvatious */
211
212 unsigned int cyrl_phi: 1; /* Gains an "f" like top, bottom treated like "f" */
213 unsigned int cyrl_i: 1; /* Turns into a latin u */
214 unsigned int cyrl_pi: 1; /* Turns into a latin n */
215 unsigned int cyrl_te: 1; /* Turns into a latin m */
216 unsigned int cyrl_sha: 1; /* Turns into a latin m rotated 180 */
217 unsigned int cyrl_dje: 1; /* Turns into a latin smallcaps T */
218 unsigned int cyrl_dzhe: 1; /* Turns into a latin u */
219 /* Is there a difference between dzhe and i? both look like u to me */
220
221 /* Unsupported */
222 /* u432 curved B */
223 /* u433 strange gamma */
224 /* u434 normal delta */
225 /* u436 */
226 /* u43b lambda ? */
227 /* u43c */
228 /* u446 */
229 /* u449 */
230 /* u449 */
231 /* u44a */
232
233 /* This half of the structure gets filled in later - see ITALICINFO_REMAINDER */
234 double tan_ia;
235 double x_height;
236 double pq_depth;
237 double ascender_height;
238 double emsize;
239 int order2;
240 struct splinefont *sf;
241 int layer;
242 double serif_extent, serif_height;
243 struct splinepoint *f_start, *f_end; /* start has next pointing into the f head and up */
244 struct splinepoint *ff_start1, *ff_end1, *ff_start2, *ff_end2;
245 double f_height, ff_height;
246 } ItalicInfo;
247
248 #define ITALICINFO_REMAINDER 0, 0, 0, 0, 0, 0, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0
249
250
251 typedef struct bluedata {
252 real xheight, xheighttop; /* height of "x" and "o" (u,v,w,x,y,z) */
253 real caph, caphtop; /* height of "I" and "O" */
254 real base, basebelow; /* bottom of "I" and "O" */
255 real ascent; /* height of "l" */
256 real descent; /* depth of "p" */
257 real numh, numhtop; /* height of "7" and "8" */ /* numbers with ascenders */
258 int bluecnt; /* If the private dica contains bluevalues... */
259 real blues[12][2]; /* 7 pairs from bluevalues, 5 from otherblues */
260 } BlueData;
261
262 #define BLUEDATA_EMPTY { \
263 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0, \
264 { { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, \
265 { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 }, { 0.0, 0.0 } \
266 } \
267 }
268
269 /* OpenType does not document 'dflt' as a language, but we'll use it anyway. */
270 /* (Adobe uses it too) we'll turn it into a default entry when we output it. */
271 #define DEFAULT_LANG CHR('d','f','l','t')
272 /* The OpenType spec says in one place that the default script is 'dflt' and */
273 /* in another that it is 'DFLT'. 'DFLT' is correct */
274 #define DEFAULT_SCRIPT CHR('D','F','L','T')
275 #define REQUIRED_FEATURE CHR(' ','R','Q','D')
276
277 enum otlookup_type {
278 ot_undef = 0, /* Not a lookup type */
279 gsub_start = 0x000, /* Not a lookup type */
280 gsub_single = 0x001,
281 gsub_multiple = 0x002,
282 gsub_alternate = 0x003,
283 gsub_ligature = 0x004,
284 gsub_context = 0x005,
285 gsub_contextchain = 0x006,
286 /* GSUB extension 7 */
287 gsub_reversecchain = 0x008,
288 /* mac state machines */
289 morx_indic = 0x0fd,
290 morx_context = 0x0fe,
291 morx_insert = 0x0ff,
292 /* ********************* */
293 gpos_start = 0x100, /* Not a lookup type */
294
295 gpos_single = 0x101,
296 gpos_pair = 0x102,
297 gpos_cursive = 0x103,
298 gpos_mark2base = 0x104,
299 gpos_mark2ligature = 0x105,
300 gpos_mark2mark = 0x106,
301 gpos_context = 0x107,
302 gpos_contextchain = 0x108,
303 /* GPOS extension 9 */
304 kern_statemachine = 0x1ff
305
306 /* otlookup&0xff == lookup type for the appropriate table */
307 /* otlookup>>8: 0=>GSUB, 1=>GPOS */
308 };
309
310 enum otlookup_typemasks {
311 gsub_single_mask = 0x00001,
312 gsub_multiple_mask = 0x00002,
313 gsub_alternate_mask = 0x00004,
314 gsub_ligature_mask = 0x00008,
315 gsub_context_mask = 0x00010,
316 gsub_contextchain_mask = 0x00020,
317 gsub_reversecchain_mask = 0x00040,
318 morx_indic_mask = 0x00080,
319 morx_context_mask = 0x00100,
320 morx_insert_mask = 0x00200,
321 /* ********************* */
322 gpos_single_mask = 0x00400,
323 gpos_pair_mask = 0x00800,
324 gpos_cursive_mask = 0x01000,
325 gpos_mark2base_mask = 0x02000,
326 gpos_mark2ligature_mask = 0x04000,
327 gpos_mark2mark_mask = 0x08000,
328 gpos_context_mask = 0x10000,
329 gpos_contextchain_mask = 0x20000,
330 kern_statemachine_mask = 0x40000
331 };
332
333 #define MAX_LANG 4 /* If more than this we allocate more_langs in chunks of MAX_LANG */
334 struct scriptlanglist {
335 uint32_t script;
336 uint32_t langs[MAX_LANG];
337 uint32_t *morelangs;
338 int lang_cnt;
339 struct scriptlanglist *next;
340 };
341
342 extern struct opentype_feature_friendlynames {
343 uint32_t tag;
344 char *tagstr;
345 char *friendlyname;
346 int masks;
347 } friendlies[];
348
349 #define OPENTYPE_FEATURE_FRIENDLYNAMES_EMPTY { 0, NULL, NULL, 0 }
350
351
352 typedef struct featurescriptlanglist {
353 uint32_t featuretag;
354 struct scriptlanglist *scripts;
355 struct featurescriptlanglist *next;
356 unsigned int ismac: 1; /* treat the featuretag as a mac feature/setting */
357 } FeatureScriptLangList;
358
359 /* https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#lookupFlags */
360 /* Low order: traditional flags, High order: markset index, only meaningful if pst_usemarkfilteringset set */
361 enum pst_flags { pst_r2l=1, pst_ignorebaseglyphs=2, pst_ignoreligatures=4,
362 pst_ignorecombiningmarks=8, pst_usemarkfilteringset=0x10,
363 pst_markclass=0xff00 };
364 #define pst_markset 0xffff0000 /* Used as a bitmask to filter to the markset index */
365
366 struct lookup_subtable {
367 char *subtable_name;
368 char *suffix; /* for gsub_single, used to find a default replacement */
369 int16_t separation, minkern; /* for gpos_pair, used to guess default kerning values */
370 struct otlookup *lookup;
371 unsigned int unused: 1;
372 unsigned int per_glyph_pst_or_kern: 1;
373 unsigned int anchor_classes: 1;
374 unsigned int vertical_kerning: 1;
375 unsigned int ticked: 1;
376 unsigned int kerning_by_touch: 1; /* for gpos_pair, calculate kerning so that glyphs will touch */
377 unsigned int onlyCloser: 1; /* for kerning classes */
378 unsigned int dontautokern: 1; /* for kerning classes */
379 struct kernclass *kc;
380 struct generic_fpst *fpst;
381 struct generic_asm *sm;
382 /* Each time an item is added to a lookup we must place it into a */
383 /* subtable. If it's a kerning class, fpst or state machine it has */
384 /* a subtable all to itself. If it's an anchor class it can share */
385 /* a subtable with other anchor classes (merge with). If it's a glyph */
386 /* PST it may share a subtable with other PSTs */
387 /* Note items may only be placed in lookups in which they fit. Can't */
388 /* put kerning data in a gpos_single lookup, etc. */
389 struct lookup_subtable *next;
390 int32_t subtable_offset;
391 int32_t *extra_subtables;
392 /* If a kerning subtable has too much stuff in it, we are prepared to */
393 /* break it up into several smaller subtables, each of which has */
394 /* an offset in this list (extra-subtables[0]==subtable_offset) */
395 /* the list is terminated by an entry of -1 */
396 };
397
398 typedef struct otlookup {
399 struct otlookup *next;
400 enum otlookup_type lookup_type;
401 uint32_t lookup_flags; /* Low order: traditional flags, High order: markset index, only meaningful if pst_usemarkfilteringset set */
402 char *lookup_name;
403 FeatureScriptLangList *features;
404 struct lookup_subtable *subtables;
405 unsigned int unused: 1; /* No subtable is used (call SFFindUnusedLookups before examining) */
406 unsigned int empty: 1; /* No subtable is used, and no anchor classes are used */
407 unsigned int store_in_afm: 1; /* Used for ligatures, some get stored */
408 /* 'liga' generally does, but 'frac' doesn't */
409 unsigned int needs_extension: 1; /* Used during opentype generation */
410 unsigned int temporary_kern: 1; /* Used when decomposing kerning classes into kern pairs for older formats */
411 unsigned int def_lang_checked: 1;
412 unsigned int def_lang_found: 1;
413 unsigned int ticked: 1;
414 unsigned int in_gpos: 1;
415 unsigned int in_jstf: 1;
416 unsigned int only_jstf: 1;
417 int16_t subcnt; /* Actual number of subtables we will output */
418 /* Some of our subtables may contain no data */
419 /* Some may be too big and need to be broken up.*/
420 /* So this field may be different than just counting the subtables */
421 int lookup_index; /* used during opentype generation */
422 uint32_t lookup_offset;
423 uint32_t lookup_length;
424 char *tempname;
425 } OTLookup;
426
427 #define LOOKUP_SUBTABLE_EMPTY { NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, 0, NULL }
428 #define OTLOOKUP_EMPTY { NULL, 0, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL }
429
430
431 typedef struct devicetab {
432 uint16_t first_pixel_size, last_pixel_size; /* A range of point sizes to which this table applies */
433 int8_t *corrections; /* a set of pixel corrections, one for each point size */
434 } DeviceTable;
435
436 typedef struct valdev { /* Value records can have four associated device tables */
437 DeviceTable xadjust;
438 DeviceTable yadjust;
439 DeviceTable xadv;
440 DeviceTable yadv;
441 } ValDevTab;
442
443 enum anchorclass_type { act_mark, act_mkmk, act_curs, act_mklg, act_unknown };
444 typedef struct anchorclass {
445 char *name; /* in utf8 */
446 struct lookup_subtable *subtable;
447 uint8_t type; /* anchorclass_type */
448 uint8_t has_base;
449 uint8_t processed, has_mark, matches, ac_num;
450 uint8_t ticked;
451 struct anchorclass *next;
452 } AnchorClass;
453
454 enum anchor_type { at_mark, at_basechar, at_baselig, at_basemark, at_centry, at_cexit, at_max };
455 typedef struct anchorpoint {
456 AnchorClass *anchor;
457 BasePoint me;
458 DeviceTable xadjust, yadjust;
459 unsigned int type: 4;
460 unsigned int selected: 1;
461 unsigned int ticked: 1;
462 unsigned int has_ttf_pt: 1;
463 uint16_t ttf_pt_index;
464 int16_t lig_index;
465 struct anchorpoint *next;
466 } AnchorPoint;
467
468 typedef struct kernpair {
469 // Note that the left character in the pair has the reference to the kerning pair, which in turn references the right character.
470 struct lookup_subtable *subtable;
471 struct splinechar *sc;
472 int16_t off;
473 uint16_t kcid; /* temporary value */
474 DeviceTable *adjust; /* Only adjustment in one dimen, if more needed use pst */
475 struct kernpair *next;
476 } KernPair;
477
478 #define FF_KERNCLASS_FLAG_NATIVE 2 // If set, the class goes into groups.plist or kerning.plist.
479 #define FF_KERNCLASS_FLAG_FEATURE 4 // If set, the class or rule goes into the feature file. In the present configuration, this ought to be zero always.
480 #define FF_KERNCLASS_FLAG_NAMETYPE 8 // If unset (default), the class has a standard name, which translates to a U. F. O. name starting in public.kern, which may be illegal in the feature file. If set, it has a name like @MMK_.
481 #define FF_KERNCLASS_FLAG_NAMELEGACY 16 // If set, the class has a U. F. O. name starting in @kc as FontForge liked to do in the past.
482 #define FF_KERNCLASS_FLAG_VIRTUAL 32 // If unset (default), the class is a real character class and does not conflict with same-sided classes. If set, FontForge mostly ignores the class except for U. F. O. input/output.
483 #define FF_KERNCLASS_FLAG_FLATTEN 64 // If unset (default), the class gets exported as a class. If set, it gets exported as its first member (in order to support class-character kerns).
484 #define FF_KERNCLASS_FLAG_SINGLECHAR (FF_KERNCLASS_FLAG_VIRTUAL | FF_KERNCLASS_FLAG_FLATTEN) // We expect to see these used together.
485
486 typedef struct kernclass {
487 int first_cnt, second_cnt; /* Count of classes for first and second chars */
488 char **firsts; /* list of a space separated list of char names */
489 char **seconds; /* one entry for each class. Entry 0 is null */
490 /* and means everything not specified elsewhere */
491 char **firsts_names; // We need to track the names of the classes in order to round-trip U. F. O. data.
492 char **seconds_names;
493 int *firsts_flags; // This tracks the storage format of the class in U. F. O. (groups.plist or features.fea) and whether it's a single-character class.
494 int *seconds_flags; // We also track the name format (@MMK or public.kern).
495 struct lookup_subtable *subtable;
496 uint16_t kcid; /* Temporary value, used for many things briefly */
497 int16_t *offsets; /* array of first_cnt*second_cnt entries with 0 representing no data */
498 int *offsets_flags;
499 DeviceTable *adjusts; /* array of first_cnt*second_cnt entries representing resolution-specific adjustments */
500 struct kernclass *next; // Note that, in most cases, a typeface needs only one struct kernclass since it can contain all classes.
501 int feature; // This indicates whether the kerning class came from a feature file. This is important during export.
502 } KernClass;
503
504 typedef struct generic_pst {
505 unsigned int ticked: 1;
506 unsigned int temporary: 1; /* Used in afm ligature closure */
507 /* enum possub_type*/ uint8_t type;
508 struct lookup_subtable *subtable;
509 struct generic_pst *next;
510 union {
511 struct vr pos;
512 struct { char *paired; struct vr *vr; } pair;
513 struct { char *variant; } subs;
514 struct { char *components; } mult, alt;
515 struct { char *components; struct splinechar *lig; } lig;
516 struct { int16_t *carets; int cnt; } lcaret; /* Ligature caret positions */
517 } u;
518 } PST;
519
520 typedef struct liglist {
521 PST *lig;
522 struct splinechar *first; /* First component */
523 struct splinecharlist *components; /* Other than the first */
524 struct liglist *next;
525 int ccnt; /* Component count. (includes first component) */
526 } LigList;
527
528 enum fpossub_format { pst_glyphs, pst_class, pst_coverage,
529 pst_reversecoverage, pst_formatmax };
530
531 struct seqlookup {
532 int seq;
533 struct otlookup *lookup;
534 };
535
536 struct fpg { char *names, *back, *fore; };
537 struct fpc { int ncnt, bcnt, fcnt; uint16_t *nclasses, *bclasses, *fclasses, *allclasses; };
538 struct fpv { int ncnt, bcnt, fcnt; char **ncovers, **bcovers, **fcovers; };
539 struct fpr { int always1, bcnt, fcnt; char **ncovers, **bcovers, **fcovers; char *replacements; };
540
541 struct fpst_rule {
542 union {
543 /* Note: Items in backtrack area are in reverse order because that's how the OT wants them */
544 /* they need to be reversed again to be displayed to the user */
545 struct fpg glyph;
546 struct fpc fpc_class;
547 struct fpv coverage;
548 struct fpr rcoverage;
549 } u;
550 int lookup_cnt;
551 struct seqlookup *lookups;
552 };
553
554 typedef struct generic_fpst {
555 uint16_t /*enum possub_type*/ type;
556 uint16_t /*enum fpossub_format*/ format;
557 struct lookup_subtable *subtable;
558 struct generic_fpst *next;
559 uint16_t nccnt, bccnt, fccnt;
560 uint16_t rule_cnt;
561 char **nclass, **bclass, **fclass;
562 struct fpst_rule *rules;
563 uint8_t ticked;
564 uint8_t effectively_by_glyphs;
565 char **nclassnames, **bclassnames, **fclassnames;
566 } FPST;
567
568 enum asm_type { asm_indic, asm_context, asm_lig, asm_simple=4, asm_insert,
569 asm_kern=0x11 };
570 enum asm_flags { asm_vert=0x8000, asm_descending=0x4000, asm_always=0x2000 };
571
572 struct asm_state {
573 uint16_t next_state;
574 uint16_t flags;
575 union {
576 struct {
577 struct otlookup *mark_lookup; /* for contextual glyph subs (tag of a nested lookup) */
578 struct otlookup *cur_lookup; /* for contextual glyph subs */
579 } context;
580 struct {
581 char *mark_ins;
582 char *cur_ins;
583 } insert;
584 struct {
585 int16_t *kerns;
586 int kcnt;
587 } kern;
588 } u;
589 };
590
591 typedef struct generic_asm { /* Apple State Machine */
592 struct generic_asm *next;
593 uint16_t /*enum asm_type*/ type;
594 struct lookup_subtable *subtable; /* Lookup contains feature setting info */
595 uint16_t flags; /* 0x8000=>vert, 0x4000=>r2l, 0x2000=>hor&vert */
596 uint8_t ticked;
597
598 uint16_t class_cnt, state_cnt;
599 char **classes;
600 struct asm_state *state;
601 } ASM;
602 /* State Flags:
603 Indic:
604 0x8000 mark current glyph as first in rearrangement
605 0x4000 don't advance to next glyph
606 0x2000 mark current glyph as last
607 0x000f verb
608 0 = no change 8 = AxCD => CDxA
609 1 = Ax => xA 9 = AxCD => DCxA
610 2 = xD => Dx a = ABxD => DxAB
611 3 = AxD => DxA b = ABxD => DxBA
612 4 = ABx => xAB c = ABxCD => CDxAB
613 5 = ABx => xBA d = ABxCD => CDxBA
614 6 = xCD => CDx e = ABxCD => DCxAB
615 7 = xCD => DCx f = ABxCD => DCxBA
616 Contextual:
617 0x8000 mark current glyph
618 0x4000 don't advance to next glyph
619 Insert:
620 0x8000 mark current glyph
621 0x4000 don't advance to next glyph
622 0x2000 current is Kashida like
623 0x1000 mark is Kashida like
624 0x0800 current insert before
625 0x0400 mark insert before
626 0x03e0 count of chars to be inserted at current (31 max)
627 0x001f count of chars to be inserted at mark (31 max)
628 Kern:
629 0x8000 add current glyph to kerning stack
630 0x4000 don't advance to next glyph
631 0x3fff value offset
632 */
633
634 struct jstf_prio {
635 OTLookup **enableShrink; /* Points to an array of lookups (GSUB or GPOS)*/
636 OTLookup **disableShrink; /* NULL terminated */
637 OTLookup **maxShrink; /* Array of GPOS like lookups */
638 OTLookup **enableExtend;
639 OTLookup **disableExtend;
640 OTLookup **maxExtend;
641 };
642
643 struct jstf_lang {
644 uint32_t lang;
645 struct jstf_lang *next;
646 int cnt;
647 struct jstf_prio *prios;
648 };
649
650 typedef struct jstf_script {
651 uint32_t script;
652 struct jstf_script *next;
653 char *extenders; /* list of glyph names */
654 struct jstf_lang *langs;
655 } Justify;
656
657 struct macname {
658 struct macname *next;
659 uint16_t enc; /* Platform specific encoding. 0=>mac roman, 1=>sjis, 7=>russian */
660 uint16_t lang; /* Mac languages 0=>english, 1=>french, 2=>german */
661 char *name; /* Not a unicode string, uninterpreted mac encoded string */
662 };
663
664 /* Wow, the GPOS 'size' feature stores a string in the name table just as mac */
665 /* features do */
666 /* And now (OTF 1.6) GSUB 'ss01'-'ss20' do too */
667 struct otfname {
668 struct otfname *next;
669 uint16_t lang; /* windows language code */
670 char *name; /* utf8 */
671 };
672
673 enum otffn_field {
674 otffn_featname, otffn_tooltiptext, otffn_sampletext,
675 otffn_characters /* reserved */,
676 otffn_paramname_begin /* this is the beginning of parameter block, so */
677 /* there should be no enum elements beyond this */
678 };
679 struct otffeatname {
680 uint32_t tag; /* Feature tag */
681 struct otfname *names;
682 struct otffeatname *next;
683 enum otffn_field field;
684 uint16_t nid; /* temporary value */
685 };
686
687 struct macsetting {
688 struct macsetting *next;
689 uint16_t setting;
690 uint16_t strid;
691 struct macname *setname;
692 unsigned int initially_enabled: 1;
693 };
694
695 typedef struct macfeat {
696 struct macfeat *next;
697 uint16_t feature;
698 uint8_t ismutex;
699 uint8_t default_setting; /* Apple's docs say both that this is a byte and a short. It's a byte */
700 uint16_t strid; /* Temporary value, used when reading in */
701 struct macname *featname;
702 struct macsetting *settings;
703 } MacFeat;
704
705 enum sfundotype
706 {
707 sfut_none=0,
708 sfut_lookups,
709 sfut_lookups_kerns,
710 sfut_fontinfo,
711 sfut_noop
712 };
713
714 /**
715 * A spline font level undo stack. undoes are doubly linked using the
716 * 'ln' member and carry some user presentable description of what the
717 * undo relates to in 'msg'.
718 *
719 * The sfdchunk is a pointer to an SFD fragment which will apply the
720 * undo to the current state. For example, it might contain
721 * information about the old value of kerning pairs which can be used
722 * to restore state to how it was. Note that the sfdchunk might only
723 * be partial, containing only enough information to restore the state
724 * which changed when the undo was created.
725 */
726 typedef struct sfundoes {
727 struct dlistnode ln;
728 char* msg;
729 enum sfundotype type;
730 union {
731 int dummy;
732 } u;
733 char* sfdchunk;
734 } SFUndoes;
735
736
737 typedef struct enc {
738 char *enc_name;
739 int char_cnt; /* Size of the next two arrays */
740 int32_t *unicode; /* unicode value for each encoding point */
741 char **psnames; /* optional postscript name for each encoding point */
742 struct enc *next;
743 unsigned int builtin: 1;
744 unsigned int hidden: 1;
745 unsigned int only_1byte: 1;
746 unsigned int has_1byte: 1;
747 unsigned int has_2byte: 1;
748 unsigned int is_unicodebmp: 1;
749 unsigned int is_unicodefull: 1;
750 unsigned int is_custom: 1;
751 unsigned int is_original: 1;
752 unsigned int is_compact: 1;
753 unsigned int is_japanese: 1;
754 unsigned int is_korean: 1;
755 unsigned int is_tradchinese: 1;
756 unsigned int is_simplechinese: 1;
757 char iso_2022_escape[8];
758 int iso_2022_escape_len;
759 int low_page, high_page;
760 char *iconv_name; /* For compatibility to old versions we might use a different name from that used by iconv. */
761 iconv_t tounicode;
762 iconv_t fromunicode;
763 int (*tounicode_func)(int);
764 int (*fromunicode_func)(int);
765 unsigned int is_temporary: 1; /* freed when the map gets freed */
766 int char_max; /* Used by temporary encodings */
767 } Encoding;
768
769 struct renames { char *from; char *to; };
770
771 typedef struct namelist {
772 struct namelist *basedon;
773 char *title;
774 const char ***unicode[17];
775 struct namelist *next;
776 struct renames *renames;
777 int uses_unicode;
778 char *a_utf8_name;
779 } NameList;
780
781 enum uni_interp { ui_unset= -1, ui_none, ui_adobe, ui_greek, ui_japanese,
782 ui_trad_chinese, ui_simp_chinese, ui_korean, ui_ams };
783
784 struct remap { uint32_t firstenc, lastenc; int32_t infont; };
785
786 typedef struct encmap { /* A per-font map of encoding to glyph id */
787 int32_t *map; /* Map from encoding to glyphid */
788 int32_t *backmap; /* Map from glyphid to encoding */
789 int enccount; /* used size of the map array */
790 /* strictly speaking this might include */
791 /* glyphs that are not encoded, but which */
792 /* are displayed after the proper encoding */
793 int encmax; /* allocated size of the map array */
794 int backmax; /* allocated size of the backmap array */
795 struct remap *remap;
796 Encoding *enc;
797 unsigned int ticked: 1;
798 } EncMap;
799
800 enum property_type { prt_string, prt_atom, prt_int, prt_uint, prt_property=0x10 };
801
802 typedef struct bdfprops {
803 char *name; /* These include both properties (like SLANT) and non-properties (like FONT) */
804 int type;
805 union {
806 char *str;
807 char *atom;
808 int val;
809 } u;
810 } BDFProperties;
811
812 typedef struct bdffont {
813 struct splinefont *sf;
814 int glyphcnt, glyphmax; /* used & allocated sizes of glyphs array */
815 BDFChar **glyphs; /* an array of charcnt entries */
816 int16_t pixelsize;
817 int16_t ascent, descent;
818 int16_t layer; /* for piecemeal fonts */
819 unsigned int piecemeal: 1;
820 unsigned int bbsized: 1;
821 unsigned int ticked: 1;
822 unsigned int unhinted_freetype: 1;
823 unsigned int recontext_freetype: 1;
824 struct bdffont *next;
825 struct clut *clut;
826 char *foundry;
827 int res;
828 void *freetype_context;
829 uint16_t truesize; /* for bbsized fonts */
830 int16_t prop_cnt;
831 int16_t prop_max; /* only used within bdfinfo dlg */
832 BDFProperties *props;
833 uint16_t ptsize, dpi; /* for piecemeal fonts */
834 } BDFFont;
835
836 struct gv_part {
837 char *component;
838 unsigned int is_extender: 1; /* This component may be skipped or repeated */
839 uint16_t startConnectorLength;
840 uint16_t endConnectorLength;
841 uint16_t fullAdvance;
842 };
843
844 /* For the 'MATH' table (and for TeX) */
845 struct glyphvariants {
846 char *variants; /* Space separated list of glyph names */
847 /* Glyph assembly */
848 int16_t italic_correction; /* Of the composed glyph */
849 DeviceTable *italic_adjusts;
850 int part_cnt;
851 struct gv_part *parts;
852 };
853
854 struct mathkerndata {
855 int16_t height,kern;
856 DeviceTable *height_adjusts;
857 DeviceTable *kern_adjusts;
858 };
859
860 /* For the 'MATH' table */
861 struct mathkernvertex {
862 int cnt; /* There is one more kern entry than height entry */
863 /* So the last mkd should have its height ignored */
864 /* The MATH table stores the height count, I think the kern count */
865 /* is more useful (and that's what I use here). They differ by 1 */
866 struct mathkerndata *mkd;
867 };
868
869 struct mathkern {
870 struct mathkernvertex top_right;
871 struct mathkernvertex top_left;
872 struct mathkernvertex bottom_right;
873 struct mathkernvertex bottom_left;
874 };
875
876 enum privatedict_state {
877 pds_odd = 0x1, /* Odd number of entries */
878 pds_outoforder = 0x2, /* Bluevalues should be listed in order */
879 pds_toomany = 0x4, /* arrays are of limited sizes */
880 pds_tooclose = 0x8, /* adjacent zones must not be within 2*bluefuzz+1 (or 3, if bluefuzz omitted) */
881 pds_notintegral= 0x10, /* Must be integers */
882 pds_toobig = 0x20, /* within pair difference have some relation to BlueScale but the docs make no sense to me */
883 pds_shift = 8, /* BlueValues/OtherBlues, unshifted, FamilyBlues/FamilyOtherBlues shifted once */
884
885 pds_missingblue = 0x010000,
886 pds_badbluefuzz = 0x020000,
887 pds_badbluescale = 0x040000,
888 pds_badstdhw = 0x080000,
889 pds_badstdvw = 0x100000,
890 pds_badstemsnaph = 0x200000,
891 pds_badstemsnapv = 0x400000,
892 pds_stemsnapnostdh = 0x0800000,
893 pds_stemsnapnostdv = 0x1000000,
894 pds_badblueshift = 0x2000000
895
896 };
897
898 enum validation_state { vs_unknown = 0,
899 vs_known=0x01, /* It has been validated */
900 vs_opencontour=0x02,
901 vs_selfintersects=0x04,
902 vs_wrongdirection=0x08,
903 vs_flippedreferences=0x10, /* special case of wrong direction */
904 vs_missingextrema=0x20,
905 vs_missingglyphnameingsub=0x40,
906 /* Next few are postscript only */
907 vs_toomanypoints=0x80,
908 vs_toomanyhints=0x100,
909 vs_badglyphname=0x200,
910 /* Next few are only for fontlint */
911 /* These are relative to maxp values which ff would fix on generating a font */
912 vs_maxp_toomanypoints =0x400,
913 vs_maxp_toomanypaths =0x800,
914 vs_maxp_toomanycomppoints=0x1000,
915 vs_maxp_toomanycomppaths =0x2000,
916 vs_maxp_instrtoolong =0x4000,
917 vs_maxp_toomanyrefs =0x8000,
918 vs_maxp_refstoodeep =0x10000,
919 /* vs_maxp_prepfpgmtoolong=0x20000, */ /* I think I was wrong about this "error" */
920 /* Oops, we need another one, two, for the glyphs */
921 vs_pointstoofarapart = 0x40000,
922 vs_nonintegral = 0x80000, /* This will never be interesting in a real font, but might be in an sfd file */
923 vs_missinganchor = 0x100000,
924 vs_dupname = 0x200000,
925 vs_dupunicode = 0x400000,
926 vs_overlappedhints = 0x800000,
927
928 vs_last = vs_overlappedhints,
929 vs_maskps = 0x3fe | vs_pointstoofarapart | vs_missinganchor | vs_dupname | vs_dupunicode | vs_overlappedhints,
930 vs_maskcid = 0x1fe | vs_pointstoofarapart | vs_missinganchor | vs_dupname | vs_overlappedhints,
931 vs_maskttf = 0x7e | vs_pointstoofarapart | vs_nonintegral | vs_missinganchor | vs_dupunicode,
932 vs_maskfindproblems = 0x1be | vs_pointstoofarapart | vs_nonintegral | vs_missinganchor | vs_overlappedhints
933 };
934
935 struct splinecharlist { struct splinechar *sc; struct splinecharlist *next;};
936
937 struct altuni { struct altuni *next; int32_t unienc, vs; uint32_t fid; };
938 /* vs is the "variation selector" a unicode codepoint which modifieds */
939 /* the code point before it. If vs is -1 then unienc is just an */
940 /* alternate encoding (greek Alpha and latin A), but if vs is one */
941 /* of unicode's variation selectors then this glyph is somehow a */
942 /* variant shape. The specifics depend on the selector and script */
943 /* fid is currently unused, but may, someday, be used to do ttcs */
944 /* NOTE: GlyphInfo displays vs==-1 as vs==0, and fixes things up */
945
946
947 #define TEX_UNDEF 0x7fff
948
949 enum ttfnames { ttf_copyright=0, ttf_family, ttf_subfamily, ttf_uniqueid,
950 ttf_fullname, ttf_version, ttf_postscriptname, ttf_trademark,
951 ttf_manufacturer, ttf_designer, ttf_descriptor, ttf_venderurl,
952 ttf_designerurl, ttf_license, ttf_licenseurl, ttf_idontknow/*reserved*/,
953 ttf_preffamilyname, ttf_prefmodifiers, ttf_compatfull, ttf_sampletext,
954 ttf_cidfindfontname, ttf_wwsfamily, ttf_wwssubfamily, ttf_namemax };
955 struct ttflangname {
956 int lang;
957 char *names[ttf_namemax]; /* in utf8 */
958 int frommac[(ttf_namemax+31)/32]; /* Used when parsing the 'name' table */
959 struct ttflangname *next;
960 };
961
962 struct MATH {
963 /* From the MATH Constants subtable (constants for positioning glyphs. Not PI)*/
964 int16_t ScriptPercentScaleDown;
965 int16_t ScriptScriptPercentScaleDown;
966 uint16_t DelimitedSubFormulaMinHeight;
967 uint16_t DisplayOperatorMinHeight;
968 int16_t MathLeading;
969 DeviceTable *MathLeading_adjust;
970 int16_t AxisHeight;
971 DeviceTable *AxisHeight_adjust;
972 int16_t AccentBaseHeight;
973 DeviceTable *AccentBaseHeight_adjust;
974 int16_t FlattenedAccentBaseHeight;
975 DeviceTable *FlattenedAccentBaseHeight_adjust;
976 int16_t SubscriptShiftDown;
977 DeviceTable *SubscriptShiftDown_adjust;
978 int16_t SubscriptTopMax;
979 DeviceTable *SubscriptTopMax_adjust;
980 int16_t SubscriptBaselineDropMin;
981 DeviceTable *SubscriptBaselineDropMin_adjust;
982 int16_t SuperscriptShiftUp;
983 DeviceTable *SuperscriptShiftUp_adjust;
984 int16_t SuperscriptShiftUpCramped;
985 DeviceTable *SuperscriptShiftUpCramped_adjust;
986 int16_t SuperscriptBottomMin;
987 DeviceTable *SuperscriptBottomMin_adjust;
988 int16_t SuperscriptBaselineDropMax;
989 DeviceTable *SuperscriptBaselineDropMax_adjust;
990 int16_t SubSuperscriptGapMin;
991 DeviceTable *SubSuperscriptGapMin_adjust;
992 int16_t SuperscriptBottomMaxWithSubscript;
993 DeviceTable *SuperscriptBottomMaxWithSubscript_adjust;
994 int16_t SpaceAfterScript;
995 DeviceTable *SpaceAfterScript_adjust;
996 int16_t UpperLimitGapMin;
997 DeviceTable *UpperLimitGapMin_adjust;
998 int16_t UpperLimitBaselineRiseMin;
999 DeviceTable *UpperLimitBaselineRiseMin_adjust;
1000 int16_t LowerLimitGapMin;
1001 DeviceTable *LowerLimitGapMin_adjust;
1002 int16_t LowerLimitBaselineDropMin;
1003 DeviceTable *LowerLimitBaselineDropMin_adjust;
1004 int16_t StackTopShiftUp;
1005 DeviceTable *StackTopShiftUp_adjust;
1006 int16_t StackTopDisplayStyleShiftUp;
1007 DeviceTable *StackTopDisplayStyleShiftUp_adjust;
1008 int16_t StackBottomShiftDown;
1009 DeviceTable *StackBottomShiftDown_adjust;
1010 int16_t StackBottomDisplayStyleShiftDown;
1011 DeviceTable *StackBottomDisplayStyleShiftDown_adjust;
1012 int16_t StackGapMin;
1013 DeviceTable *StackGapMin_adjust;
1014 int16_t StackDisplayStyleGapMin;
1015 DeviceTable *StackDisplayStyleGapMin_adjust;
1016 int16_t StretchStackTopShiftUp;
1017 DeviceTable *StretchStackTopShiftUp_adjust;
1018 int16_t StretchStackBottomShiftDown;
1019 DeviceTable *StretchStackBottomShiftDown_adjust;
1020 int16_t StretchStackGapAboveMin;
1021 DeviceTable *StretchStackGapAboveMin_adjust;
1022 int16_t StretchStackGapBelowMin;
1023 DeviceTable *StretchStackGapBelowMin_adjust;
1024 int16_t FractionNumeratorShiftUp;
1025 DeviceTable *FractionNumeratorShiftUp_adjust;
1026 int16_t FractionNumeratorDisplayStyleShiftUp;
1027 DeviceTable *FractionNumeratorDisplayStyleShiftUp_adjust;
1028 int16_t FractionDenominatorShiftDown;
1029 DeviceTable *FractionDenominatorShiftDown_adjust;
1030 int16_t FractionDenominatorDisplayStyleShiftDown;
1031 DeviceTable *FractionDenominatorDisplayStyleShiftDown_adjust;
1032 int16_t FractionNumeratorGapMin;
1033 DeviceTable *FractionNumeratorGapMin_adjust;
1034 int16_t FractionNumeratorDisplayStyleGapMin;
1035 DeviceTable *FractionNumeratorDisplayStyleGapMin_adjust;
1036 int16_t FractionRuleThickness;
1037 DeviceTable *FractionRuleThickness_adjust;
1038 int16_t FractionDenominatorGapMin;
1039 DeviceTable *FractionDenominatorGapMin_adjust;
1040 int16_t FractionDenominatorDisplayStyleGapMin;
1041 DeviceTable *FractionDenominatorDisplayStyleGapMin_adjust;
1042 int16_t SkewedFractionHorizontalGap;
1043 DeviceTable *SkewedFractionHorizontalGap_adjust;
1044 int16_t SkewedFractionVerticalGap;
1045 DeviceTable *SkewedFractionVerticalGap_adjust;
1046 int16_t OverbarVerticalGap;
1047 DeviceTable *OverbarVerticalGap_adjust;
1048 int16_t OverbarRuleThickness;
1049 DeviceTable *OverbarRuleThickness_adjust;
1050 int16_t OverbarExtraAscender;
1051 DeviceTable *OverbarExtraAscender_adjust;
1052 int16_t UnderbarVerticalGap;
1053 DeviceTable *UnderbarVerticalGap_adjust;
1054 int16_t UnderbarRuleThickness;
1055 DeviceTable *UnderbarRuleThickness_adjust;
1056 int16_t UnderbarExtraDescender;
1057 DeviceTable *UnderbarExtraDescender_adjust;
1058 int16_t RadicalVerticalGap;
1059 DeviceTable *RadicalVerticalGap_adjust;
1060 int16_t RadicalDisplayStyleVerticalGap;
1061 DeviceTable *RadicalDisplayStyleVerticalGap_adjust;
1062 int16_t RadicalRuleThickness;
1063 DeviceTable *RadicalRuleThickness_adjust;
1064 int16_t RadicalExtraAscender;
1065 DeviceTable *RadicalExtraAscender_adjust;
1066 int16_t RadicalKernBeforeDegree;
1067 DeviceTable *RadicalKernBeforeDegree_adjust;
1068 int16_t RadicalKernAfterDegree;
1069 DeviceTable *RadicalKernAfterDegree_adjust;
1070 uint16_t RadicalDegreeBottomRaisePercent;
1071 /* Global constants from other subtables */
1072 uint16_t MinConnectorOverlap; /* in the math variants sub-table */
1073 };
1074
1075 enum backedup_state { bs_dontknow=0, bs_not=1, bs_backedup=2 };
1076 enum loadvalidation_state {
1077 lvs_bad_ps_fontname = 0x001,
1078 lvs_bad_glyph_table = 0x002,
1079 lvs_bad_cff_table = 0x004,
1080 lvs_bad_metrics_table = 0x008,
1081 lvs_bad_cmap_table = 0x010,
1082 lvs_bad_bitmaps_table = 0x020,
1083 lvs_bad_gx_table = 0x040,
1084 lvs_bad_ot_table = 0x080,
1085 lvs_bad_os2_version = 0x100,
1086 lvs_bad_sfnt_header = 0x200
1087 };
1088
1089 typedef struct layerinfo {
1090 char *name;
1091 unsigned int background: 1; /* Layer is to be treated as background: No width, images, not worth outputting */
1092 unsigned int order2: 1; /* Layer's data are order 2 bezier splines (truetype) rather than order 3 (postscript) */
1093 /* In all glyphs in the font */
1094 unsigned int ticked: 1;
1095 char * ufo_path;
1096 } LayerInfo;
1097
1098 /* Baseline data from the 'BASE' table */
1099 struct baselangextent {
1100 uint32_t lang; /* also used for feature tag */
1101 struct baselangextent *next;
1102 int16_t ascent, descent;
1103 struct baselangextent *features;
1104 };
1105
1106 struct basescript {
1107 uint32_t script;
1108 struct basescript *next;
1109 int def_baseline; /* index [0-baseline_cnt) */
1110 int16_t *baseline_pos; /* baseline_cnt of these */
1111 struct baselangextent *langs; /* Language specific extents (may be NULL) */
1112 /* The default one has the tag DEFAULT_LANG */
1113 };
1114
1115 struct Base {
1116 int baseline_cnt;
1117 uint32_t *baseline_tags;
1118 /* A font does not need to provide info on all baselines, but if one script */
1119 /* talks about a baseline, then all must. So the set of baselines is global*/
1120 struct basescript *scripts;
1121 };
1122
1123 struct pfminfo { /* A misnomer now. OS/2 info would be more accurate, but that's stuff in here from all over ttf files */
1124 unsigned int pfmset: 1;
1125 unsigned int winascent_add: 1;
1126 unsigned int windescent_add: 1;
1127 unsigned int hheadascent_add: 1;
1128 unsigned int hheaddescent_add: 1;
1129 unsigned int typoascent_add: 1;
1130 unsigned int typodescent_add: 1;
1131 unsigned int subsuper_set: 1;
1132 unsigned int panose_set: 1;
1133 unsigned int hheadset: 1;
1134 unsigned int vheadset: 1;
1135 unsigned int hascodepages: 1;
1136 unsigned int hasunicoderanges: 1;
1137 unsigned char pfmfamily;
1138 int16_t weight;
1139 int16_t width;
1140 char panose[10];
1141 /* A subset of OS/2 fsSelection, used for style mapping. */
1142 /* Must agree with macStyle per otspec, takes precedence. */
1143 /* Can't use macStyle because it doesn't have a "regular" bit unlike the OS/2 component. */
1144 int16_t stylemap;
1145 int16_t fstype;
1146 int16_t linegap; /* from hhea */
1147 int16_t vlinegap; /* from vhea */
1148 int16_t hhead_ascent, hhead_descent;
1149 int16_t os2_typoascent, os2_typodescent, os2_typolinegap;
1150 int16_t os2_winascent, os2_windescent;
1151 int16_t os2_subxsize, os2_subysize, os2_subxoff, os2_subyoff;
1152 int16_t os2_supxsize, os2_supysize, os2_supxoff, os2_supyoff;
1153 int16_t os2_strikeysize, os2_strikeypos;
1154 int16_t os2_capheight, os2_xheight;
1155 char os2_vendor[4];
1156 int16_t os2_family_class;
1157 uint32_t codepages[2];
1158 uint32_t unicoderanges[4];
1159 };
1160
1161 struct ttf_table {
1162 uint32_t tag;
1163 uint32_t len, maxlen;
1164 uint8_t *data;
1165 struct ttf_table *next;
1166 FILE *temp; /* Temporary storage used during generation */
1167 };
1168
1169 enum texdata_type { tex_unset, tex_text, tex_math, tex_mathext };
1170
1171 struct texdata {
1172 enum texdata_type type;
1173 int32_t params[22]; /* param[6] has different meanings in normal and math fonts */
1174 };
1175
1176 struct gasp {
1177 uint16_t ppem;
1178 uint16_t flags;
1179 };
1180
1181 struct ff_glyphclasses {
1182 // This matches struct glyphclasses from featurefile.c for now. We may make the references numeric in the future.
1183 // There may be a matching entry as a class elsewhere. For now, the output driver is responsible for eliminating duplicates.
1184 // In the interest of preserving orderings, we shall output from here, checking for value overrides from kerning classes on each kerning group entry.
1185 char *classname, *glyphs;
1186 struct ff_glyphclasses *next;
1187 };
1188
1189 struct ff_rawoffsets {
1190 // This stores raw offsets as read from kerning.plist.
1191 // FontForge shall output these after native data and shall output only those for which it has not emitted native data.
1192 char *left;
1193 char *right;
1194 int offset;
1195 struct ff_rawoffsets *next;
1196 };
1197
1198 typedef struct splinefont {
1199 char *fontname, *fullname, *familyname, *weight;
1200 char *familyname_with_timestamp;
1201 char *copyright;
1202 char *filename; /* sfd name. NULL if we open a font, that's origname */
1203 char *defbasefilename;
1204 char *version;
1205 real italicangle, upos, uwidth; /* In font info */
1206 int ascent, descent, invalidem; // If invalidem, then we use the format-specific ascent and descent on export.
1207 int uniqueid; /* Not copied when reading in!!!! */
1208 int glyphcnt, glyphmax; /* allocated size of glyphs array */
1209 SplineChar **glyphs;
1210 unsigned int changed: 1;
1211 unsigned int changed_since_autosave: 1;
1212 unsigned int changed_since_xuidchanged: 1;
1213 unsigned int display_antialias: 1;
1214 unsigned int display_bbsized: 1;
1215 unsigned int dotlesswarn: 1; /* User warned that font doesn't have a dotless i character */
1216 unsigned int onlybitmaps: 1; /* it's a bdf editor, not a postscript editor */
1217 unsigned int serifcheck: 1; /* Have we checked to see if we have serifs? */
1218 unsigned int issans: 1; /* We have no serifs */
1219 unsigned int isserif: 1; /* We have serifs. If neither set then we don't know. */
1220 unsigned int hasvmetrics: 1; /* We've got vertical metric data and should output vhea/vmtx/VORG tables */
1221 unsigned int loading_cid_map: 1;
1222 unsigned int dupnamewarn: 1; /* Warn about duplicate names when loading bdf font */
1223 unsigned int encodingchanged: 1; /* Font's encoding has changed since it was loaded */
1224 unsigned int multilayer: 1; /* only applies if TYPE3 is set, means this font can contain strokes & fills */
1225 /* I leave it in so as to avoid cluttering up code with #ifdefs */
1226 unsigned int strokedfont: 1;
1227 unsigned int isnew: 1; /* A new and unsaved font */
1228 unsigned int compacted: 1; /* only used when opening a font */
1229 unsigned int backedup: 2; /* 0=>don't know, 1=>no, 2=>yes */
1230 unsigned int use_typo_metrics: 1; /* The standard says to. But MS */
1231 /* seems to feel that isn't good */
1232 /* enough and has created a bit */
1233 /* to mean "really use them" */
1234 unsigned int weight_width_slope_only: 1; /* This bit seems stupid to me */
1235 unsigned int save_to_dir: 1; /* Loaded from an sfdir collection rather than a simple sfd file */
1236 unsigned int head_optimized_for_cleartype: 1;/* Bit in the 'head' flags field, if unset "East Asian fonts in the Windows Presentation Framework (Avalon) will not be hinted" */
1237 unsigned int ticked: 1;
1238 unsigned int internal_temp: 1; /* Internal temporary font to be passed to freetype for rasterizing. Don't complain about oddities. Don't generate GPOS/GSUB tables, etc. */
1239 unsigned int complained_about_spiros: 1;
1240 unsigned int use_xuid: 1; /* Adobe has deprecated these two */
1241 unsigned int use_uniqueid: 1; /* fields. Mostly we don't want to use them */
1242 /* 2 bits left */
1243 struct fontviewbase *fv;
1244 struct metricsview *metrics;
1245 enum uni_interp uni_interp;
1246 NameList *for_new_glyphs;
1247 EncMap *map; /* only used when opening a font to provide original default encoding */
1248 Layer grid;
1249 BDFFont *bitmaps;
1250 char *origname; /* filename of font file (ie. if not an sfd) */
1251 char *autosavename;
1252 int display_size; /* a val <0 => Generate our own images from splines, a value >0 => find a bdf font of that size */
1253 struct psdict *private_dict; /* read in from type1 file or provided by user */
1254 char *xuid;
1255 struct pfminfo pfminfo;
1256 struct ttflangname *names;
1257 char *cidregistry, *ordering;
1258 int supplement;
1259 int subfontcnt;
1260 struct splinefont **subfonts;
1261 struct splinefont *cidmaster; /* Top level cid font */
1262 float cidversion;
1263 #if HANYANG
1264 struct compositionrules *rules;
1265 #endif
1266 char *comments; /* Used to be restricted to ASCII, now utf8 */
1267 char *fontlog;
1268 int tempuniqueid;
1269 int top_enc;
1270 uint16_t desired_row_cnt, desired_col_cnt;
1271 struct glyphnamehash *glyphnames;
1272 struct ttf_table *ttf_tables, *ttf_tab_saved;
1273 /* We copy: fpgm, prep, cvt, maxp (into ttf_tables) user can ask for others, into saved*/
1274 char **cvt_names;
1275 /* The end of this array is marked by a special entry: */
1276 #define END_CVT_NAMES ((char *) (~(intptr_t) 0))
1277 struct instrdata *instr_dlgs; /* Pointer to all table and character instruction dlgs in this font */
1278 struct shortview *cvt_dlg;
1279 struct kernclasslistdlg *kcld, *vkcld;
1280 struct kernclassdlg *kcd;
1281 struct texdata texdata;
1282 OTLookup *gsub_lookups, *gpos_lookups;
1283 /* Apple morx subtables become gsub, and kern subtables become gpos */
1284 AnchorClass *anchor;
1285 KernClass *kerns, *vkerns;
1286 FPST *possub;
1287 ASM *sm; /* asm is a keyword */
1288 MacFeat *features;
1289 char *chosenname; /* Set for files with multiple fonts in them */
1290 struct mmset *mm; /* If part of a multiple master set */
1291 int16_t macstyle;
1292 char *fondname; /* For use in generating mac families */
1293 /* from the GPOS 'size' feature. design_size, etc. are measured in tenths of a point */
1294 /* bottom is exclusive, top is inclusive */
1295 /* if any field is 0, it is undefined. All may be undefined, All may be */
1296 /* defined, or design_size may be defined without any of the others */
1297 /* but we can't define the range without defining the other junk */
1298 /* Name must contain an English language name, may contain others */
1299 uint16_t design_size;
1300 uint16_t fontstyle_id;
1301 struct otfname *fontstyle_name;
1302 uint16_t design_range_bottom, design_range_top;
1303 struct otffeatname *feat_names;
1304 real strokewidth;
1305 /* For GDEF Mark Attachment Class -- used in lookup flags */
1306 /* As usual, class 0 is unused */
1307 int mark_class_cnt;
1308 char **mark_classes; /* glyph name list */
1309 char **mark_class_names; /* used within ff, utf8 (the name we've given to this class of marks) */
1310 /* For GDEF Mark Attachment Sets -- used in lookup flags */
1311 /* but here, set 0 is meaningful, since pst_usemarkfilteringset tells us */
1312 int mark_set_cnt;
1313 char **mark_sets; /* glyph name list */
1314 char **mark_set_names; /* used within ff, utf8 (the name we've given to this class of marks) */
1315 struct ff_glyphclasses *groups; // This stores arbitrary named character lists for use in kerning or in the feature file.
1316 struct ff_rawoffsets *groupkerns;
1317 struct ff_rawoffsets *groupvkerns;
1318 long long creationtime; /* seconds since 1970 */
1319 long long modificationtime;
1320 short os2_version; /* 0 means default rather than the real version 0 */
1321 short compression; /* If we opened a compressed sfd file, then save it out compressed too */
1322 short gasp_version; /* 0/1 currently */
1323 short gasp_cnt;
1324 struct gasp *gasp;
1325 struct MATH *MATH;
1326 float sfd_version; /* Used only when reading in an sfd file */
1327 struct gfi_data *fontinfo;
1328 struct val_data *valwin;
1329 #if !defined(_NO_PYTHON)
1330 void *python_temporary;
1331 #endif
1332 void *python_persistent; /* If python this will hold a python object, if not python this will hold a string containing a pickled object. We do nothing with it (if not python) except save it back out unchanged */
1333 int python_persistent_has_lists; // This affects whether arrays exist as tuples or as lists (thus allowing us to use tuples for foreign data).
1334 enum loadvalidation_state loadvalidation_state;
1335 LayerInfo *layers;
1336 int layer_cnt;
1337 int display_layer;
1338 struct Base *horiz_base, *vert_base;
1339 Justify *justify;
1340 int extrema_bound; /* Splines do not count for extrema complaints when the distance between the endpoints is less than or equal to this */
1341 int width_separation;
1342 int sfntRevision;
1343 #define sfntRevisionUnset 0x44445555
1344 int woffMajor;
1345 #define woffUnset 0x4455
1346 int woffMinor;
1347 char *woffMetadata;
1348 real ufo_ascent, ufo_descent; /* I don't know what these mean, they don't seem to correspond to any other ascent/descent pair, but retain them so round-trip ufo input/output leaves them unchanged */
1349 /* ufo_descent is negative */
1350 struct sfundoes *undoes;
1351 int preferred_kerning; // 1 for U. F. O. native, 2 for feature file, 0 undefined. Input functions shall flag 2, I think. This is now in S. F. D. in order to round-trip U. F. O. consistently.
1352 } SplineFont;
1353
1354 struct axismap {
1355 int points; /* size of the next two arrays */
1356 real *blends; /* between [0,1] ordered so that blend[0]<blend[1]<... */
1357 real *designs; /* between the design ranges for this axis, typically [1,999] or [6,72] */
1358 real min, def, max; /* For mac */
1359 struct macname *axisnames; /* For mac */
1360 };
1361
1362 struct named_instance { /* For mac */
1363 real *coords; /* array[axis], these are in user units */
1364 struct macname *names;
1365 };
1366
1367 /* I am going to simplify my life and not encourage intermediate designs */
1368 /* this means I can easily calculate ConvertDesignVector, and don't have */
1369 /* to bother the user with specifying it. */
1370 /* (NormalizeDesignVector is fairly basic and shouldn't need user help ever) */
1371 /* (As long as they want piecewise linear) */
1372 /* I'm not going to support intermediate designs at all for apple var tables */
1373 typedef struct mmset {
1374 int axis_count;
1375 char *axes[4];
1376 int instance_count;
1377 SplineFont **instances;
1378 SplineFont *normal;
1379 real *positions; /* array[instance][axis] saying where each instance lies on each axis */
1380 real *defweights; /* array[instance] saying how much of each instance makes the normal font */
1381 /* for adobe */
1382 struct axismap *axismaps; /* array[axis] */
1383 char *cdv, *ndv; /* for adobe */
1384 int named_instance_count;
1385 struct named_instance *named_instances;
1386 unsigned int changed: 1;
1387 unsigned int apple: 1;
1388 } MMSet;
1389
1390 /* mac styles. Useful idea we'll just steal it */
1391 enum style_flags { sf_bold = 1, sf_italic = 2, sf_underline = 4, sf_outline = 8,
1392 sf_shadow = 0x10, sf_condense = 0x20, sf_extend = 0x40 };
1393
1394 struct sflist {
1395 SplineFont *sf;
1396 int32_t *sizes;
1397 FILE *tempttf; /* For ttf */
1398 int id; /* For ttf */
1399 int* ids; /* One for each size */
1400 BDFFont **bdfs; /* Ditto */
1401 EncMap *map;
1402 struct sflist *next;
1403 char **former_names;
1404 int len;
1405 };
1406
1407 /* Used for drawing text with mark to base anchors */
1408 typedef struct anchorpos {
1409 SplineChar *sc; /* This is the mark being positioned */
1410 int x,y; /* Its origin should be shifted this much relative to that of the original base char */
1411 AnchorPoint *apm; /* The anchor point in sc used to position it */
1412 AnchorPoint *apb; /* The anchor point in the base character against which we are positioned */
1413 int base_index; /* Index in this array to the base character (-1=> original base char) */
1414 unsigned int ticked: 1; /* Used as a mark to mark */
1415 } AnchorPos;
1416
1417 enum archive_list_style { ars_tar, ars_zip };
1418
1419 struct archivers {
1420 char *ext, *unarchive, *archive, *listargs, *extractargs, *appendargs;
1421 enum archive_list_style ars;
1422 };
1423 #define ARCHIVERS_EMPTY { NULL, NULL, NULL, NULL, NULL, NULL, 0 }
1424
1425 struct fontdict;
1426 struct pschars;
1427 struct findsel;
1428 struct charprocs;
1429 struct enc;
1430
1431 #define chunkalloc(size) calloc(1,size)
1432 #define chunkfree(item,size) free(item)
1433
1434 extern char *strconcat(const char *str, const char *str2);
1435
1436 extern void SFApplyFeatureFile(SplineFont *sf,FILE *file,char *filename,bool ignore_invalid_replacement);
1437 extern struct pschars *SplineFont2ChrsSubrs(SplineFont *sf, int iscjk,
1438 struct pschars *subrs,int flags,enum fontformat format,int layer);
1439 struct cidbytes;
1440 struct fd2data;
1441 struct ttfinfo;
1442 struct alltabs;
1443
1444 typedef struct growbuf {
1445 unsigned char *pt;
1446 unsigned char *base;
1447 unsigned char *end;
1448 } GrowBuf;
1449 extern void GrowBuffer(GrowBuf *gb);
1450
1451 struct glyphdata;
1452 extern struct pschars *CID2ChrsSubrs(SplineFont *cidmaster,struct cidbytes *cidbytes,int flags,int layer);
1453 extern const char *GetAuthor(void);
1454 extern int WriteUFOFont(const char *fontname, SplineFont *sf, enum fontformat format, int flags, const EncMap *enc,int layer, int version);
1455 extern int SLIContainsR2L(SplineFont *sf,int sli);
1456 extern void SFFindNearTop(SplineFont *);
1457 extern void SFRestoreNearTop(SplineFont *);
1458 extern const char *_GetModifiers(const char *fontname, const char *familyname, const char *weight);
1459 extern const char *SFGetModifiers(const SplineFont *sf);
1460 extern const unichar_t *_uGetModifiers(const unichar_t *fontname, const unichar_t *familyname,
1461 const unichar_t *weight);
1462 extern void ttfdumpbitmap(SplineFont *sf,struct alltabs *at,int32_t *sizes);
1463 extern void SplineFontSetUnChanged(SplineFont *sf);
1464
1465 extern bool RealNear(real a,real b);
1466
1467
1468 extern void UndoesFree(Undoes *undo);
1469 extern void StemInfosFree(StemInfo *h);
1470 extern void StemInfoFree(StemInfo *h);
1471 extern void SCOrderAP(SplineChar *sc);
1472 extern int AnchorClassesNextMerge(AnchorClass *ac);
1473 extern void AnchorClassMerge(SplineFont *sf,AnchorClass *into,AnchorClass *from);
1474 extern void SCInsertPST(SplineChar *sc,PST *new_);
1475 extern void PSTFree(PST *lig);
1476 extern uint16_t PSTDefaultFlags(enum possub_type type,SplineChar *sc );
1477 extern StemInfo *StemInfoCopy(StemInfo *h);
1478 extern void SPChangePointType(SplinePoint *sp, int pointtype);
1479
1480 struct lookup_cvt { OTLookup *from, *to; int old;};
1481 struct sub_cvt { struct lookup_subtable *from, *to; int old;};
1482 struct ac_cvt { AnchorClass *from, *to; int old;};
1483
1484 struct sfmergecontext {
1485 SplineFont *sf_from, *sf_to;
1486 int lcnt;
1487 struct lookup_cvt *lks;
1488 int scnt;
1489 struct sub_cvt *subs;
1490 int acnt;
1491 struct ac_cvt *acs;
1492 char *prefix;
1493 int preserveCrossFontKerning;
1494 int lmax;
1495 };
1496 extern void AltUniRemove(SplineChar *sc,int uni);
1497 extern void AltUniAdd(SplineChar *sc,int uni);
1498 extern void AltUniAdd_DontCheckDups(SplineChar *sc,int uni);
1499 extern SplineChar *SplineCharCreate(int layer_cnt);
1500 extern void SCAddRef(SplineChar *sc,SplineChar *rsc,int layer, real xoff, real yoff);
1501 extern void SplineCharFree(SplineChar *sc);
1502 extern void ScriptLangListFree(struct scriptlanglist *sl);
1503
1504 enum pconvert_flags {
1505 // Point selection (mutually exclusive)
1506 pconvert_flag_none = 0x01,
1507 pconvert_flag_all = 0x02,
1508 pconvert_flag_smooth = 0x04,
1509 pconvert_flag_incompat = 0x08,
1510 // Conversion modes (mutually exclusive)
1511 pconvert_flag_by_geom = 0x100,
1512 pconvert_flag_force_type = 0x200,
1513 pconvert_flag_downgrade = 0x400,
1514 pconvert_flag_check_compat = 0x0800,
1515 // Additional
1516 pconvert_flag_hvcurve = 0x4000
1517 };
1518
1519 #if 1
1520 // These relate to experimental support for U. F. O. groups.
1521 #define GROUP_NAME_KERNING_UFO 1
1522 #define GROUP_NAME_KERNING_FEATURE 2
1523 #define GROUP_NAME_VERTICAL 4 // Otherwise horizontal.
1524 #define GROUP_NAME_RIGHT 8 // Otherwise left (or above).
1525 #endif // 1
1526 extern void MMSetFree(MMSet *mm);
1527 extern void SFRemoveUndoes(SplineFont *sf,uint8_t *selected,EncMap *map);
1528 extern void SplineRefigure(Spline *spline);
1529 extern void SPLCategorizePoints(SplinePointList *spl);
1530 extern int _SPLCategorizePoints(SplinePointList *spl, int flags);
1531 extern SplinePointList *SplinePointListCopy(const SplinePointList *base);
1532 /* The order of the enum elements below doesn't make much sense, but it's done*/
1533 /* this way to preserve binary compatibility */
1534 enum transformPointType { tpt_OnlySelected, tpt_AllPoints, tpt_OnlySelectedInterpCPs };
1535 /*
1536 * As SplinePointListTransform() does a few things, this is a mask to selectively be
1537 * able to disable some of them.
1538 */
1539 enum transformPointMask {
1540 tpmask_dontFixControlPoints = 1 << 1,
1541 tpmask_operateOnSelectedBCP = 1 << 2,
1542 tpmask_dontTrimValues = 1 << 3
1543 };
1544 extern SplinePointList *SplinePointListTransform(SplinePointList *base, real transform[6], enum transformPointType allpoints );
1545 extern void SCReinstanciateRef(SplineChar *sc,SplineChar *rsc,int layer);
1546 extern SplineChar *MakeDupRef(SplineChar *base, int local_enc, int uni_enc);
1547 extern void BDFClut(BDFFont *bdf, int linear_scale);
1548 struct xlfd_components {
1549 char foundry[80];
1550 char family[100];
1551 char weight[80];
1552 char slant[40];
1553 char setwidth[50];
1554 char add_style[50];
1555 int pixel_size;
1556 int point_size;
1557 int res_x;
1558 int res_y;
1559 char spacing[40];
1560 int avg_width;
1561 char cs_reg[80]; /* encoding */
1562 char cs_enc[80]; /* encoding version? */
1563 int char_cnt;
1564 };
1565 struct std_bdf_props {
1566 const char *name;
1567 int type;
1568 int defaultable;
1569 };
1570 #define STD_BDF_PROPS_EMPTY { NULL, 0, 0 }
1571
1572 extern int CubicSolve(const Spline1D *sp,bigreal sought,extended ts[3]);
1573 /* Uses an algebraic solution */
1574 extern extended SplineSolve(const Spline1D *sp, real tmin, real tmax, extended sought_y);
1575 /* Tries to fixup rounding errors that crept in to the solution */
1576 extern extended SplineSolveFixup(const Spline1D *sp, real tmin, real tmax, extended sought_y);
1577 /* Uses an iterative approximation */
1578 /* Uses an iterative approximation and then tries to fix things up */
1579
1580
1581 #define CURVATURE_ERROR INFINITY
1582
1583 extern bigreal SplineLength(Spline *spline);
1584 extern int SplineIsLinear(Spline *spline);
1585 extern void SFOrderBitmapList(SplineFont *sf);
1586
1587 extern Spline *SplineMake(SplinePoint *from, SplinePoint *to, int order2);
1588 extern Spline *SFSplineMake(SplineFont *sf,SplinePoint *from, SplinePoint *to);
1589
1590
1591 extern double BlueScaleFigure(struct psdict *private_,real bluevalues[], real otherblues[]);
1592
1593 typedef struct bluezone {
1594 real base;
1595 int cvtindex;
1596 real family_base; /* NaN if none */
1597 int family_cvtindex;
1598 real overshoot; /* relative to baseline, NOT to base */
1599 int highest; /* used in autoinstructing for HStem positioning */
1600 int lowest; /* as above */
1601 } BlueZone;
1602
1603 typedef struct stdstem {
1604 real width; /* -1 if none */
1605 int cvtindex;
1606 struct stdstem *snapto;/* NULL means stem isn't snapped to any other */
1607 int stopat; /* at which ppem stop snapping to snapto */
1608 } StdStem;
1609
1610 typedef struct globalinstrct {
1611 SplineFont *sf;
1612 int layer;
1613 BlueData *bd;
1614 double fudge;
1615
1616 /* Did we initialize the tables needed? 'maxp' is skipped because */
1617 /* its initialization always succeeds. */
1618 int cvt_done;
1619 int fpgm_done;
1620 int prep_done;
1621
1622 /* PS private data with truetype-specific information added */
1623 BlueZone blues[12]; /* like in BlueData */
1624 int bluecnt;
1625 StdStem stdhw;
1626 StdStem *stemsnaph; /* StdHW excluded */
1627 int stemsnaphcnt;
1628 StdStem stdvw;
1629 StdStem *stemsnapv; /* StdVW excluded */
1630 int stemsnapvcnt;
1631 } GlobalInstrCt;
1632
1633 extern void InitGlobalInstrCt( GlobalInstrCt *gic,SplineFont *sf,int layer,
1634 BlueData *bd );
1635 extern void FreeGlobalInstrCt( GlobalInstrCt *gic );
1636 extern void NowakowskiSCAutoInstr( GlobalInstrCt *gic,SplineChar *sc );
1637 extern void CVT_ImportPrivate(SplineFont *sf);
1638
1639 extern void SplineFontAutoHint( SplineFont *sf, int layer);
1640 extern int SCDrawsSomething(SplineChar *sc);
1641 extern int SCSetMetaData(SplineChar *sc,const char *name,int unienc,
1642 const char *comment);
1643
1644 extern char* DumpSplineFontMetadata( SplineFont *sf );
1645
1646
1647 enum ttfflags { ttf_onlystrikes=1, ttf_onlyonestrike=2, ttf_onlykerns=4, ttf_onlynames=8 };
1648 extern SplineFont *SFReadUFO(char *filename,int flags);
1649 extern SplineFont *LoadSplineFont(const char *filename,enum openflags);
1650 extern SplineFont *_ReadSplineFont(FILE *file, const char *filename, enum openflags openflags);
1651 extern SplineFont *ReadSplineFont(const char *filename,enum openflags); /* Don't use this, use LoadSF instead */
1652 extern void ArchiveCleanup(char *archivedir);
1653 extern char *Unarchive(char *name, char **_archivedir);
1654 extern char *Decompress(char *name);
1655 extern uint16_t MacStyleCode( SplineFont *sf, uint16_t *psstyle );
1656 extern char **NamesReadUFO(char *filename);
1657 extern char *SFSubfontnameStart(char *fname);
1658
1659
1660 extern const char *UnicodeRange(int unienc);
1661 extern SplineChar *SCBuildDummy(SplineChar *dummy,SplineFont *sf,EncMap *map,int i);
1662 extern SplineChar *SFMakeChar(SplineFont *sf,EncMap *map,int i);
1663 extern char *AdobeLigatureFormat(char *name);
1664 extern uint32_t LigTagFromUnicode(int uni);
1665 extern void SCLigCaretheck(SplineChar *sc,int clean);
1666
1667 extern void SCUndoSetLBearingChange(SplineChar *sc,int lb);
1668
1669
1670
1671 extern SplineSet *SplinePointListInterpretGlif(SplineFont *sf,char *filename,char *memory, int memlen, int em_size, int ascent,int stroked);
1672 #define UNDEFINED_WIDTH -999999
1673 struct pscontext {
1674 int is_type2;
1675 int painttype;
1676 int instance_count;
1677 real blend_values[17];
1678 int blend_warn;
1679 };
1680
1681 extern int NameToEncoding(SplineFont *sf,EncMap *map,const char *uname);
1682 extern SplineChar *SFGetOrMakeChar(SplineFont *sf, int unienc, const char *name );
1683 extern SplineChar *SFGetOrMakeCharFromUnicode( SplineFont *sf, EncMap *map, int ch );
1684
1685 extern int DoAutoRecovery(int);
1686 typedef void (*DoAutoRecoveryPostRecoverFunc)(SplineFont *sf);
1687
1688 extern int SFPrivateGuess(SplineFont *sf,int layer, struct psdict *private_dict,
1689 char *name, int onlyone);
1690
1691 extern void SFRemoveLayer(SplineFont *sf,int l);
1692 extern void SFAddLayer(SplineFont *sf,char *name,int order2, int background);
1693 extern void SFLayerSetBackground(SplineFont *sf,int layer,int is_back);
1694
1695 extern void SplineSetsRound2Int(SplineSet *spl,real factor,int inspiro,int onlysel);
1696 extern void SCRound2Int(SplineChar *sc,int layer, real factor);
1697
1698 extern void SFFlatten(SplineFont **cidmaster);
1699
1700 extern void SCCopyLayerToLayer(SplineChar *sc, int from, int to,int doclear);
1701
1702 extern int hasFreeType(void);
1703 extern int hasFreeTypeDebugger(void);
1704 extern int hasFreeTypeByteCode(void);
1705 extern int FreeTypeAtLeast(int major, int minor, int patch);
1706 extern char *FreeTypeStringVersion(void);
1707 extern void doneFreeType(void);
1708 extern void *_FreeTypeFontContext(SplineFont *sf,SplineChar *sc,struct fontviewbase *fv,
1709 int layer, enum fontformat ff,int flags,void *shared_ftc);
1710 extern void *FreeTypeFontContext(SplineFont *sf,SplineChar *sc,struct fontviewbase *fv,int layer);
1711 extern BDFFont *SplineFontFreeTypeRasterize(void *freetypecontext,int pixelsize,int depth);
1712 extern BDFChar *SplineCharFreeTypeRasterize(void *freetypecontext,int gid,
1713 int ptsize, int dpi,int depth);
1714 extern void FreeTypeFreeContext(void *freetypecontext);
1715 extern SplineSet *FreeType_GridFitChar(void *single_glyph_context,
1716 int enc, real ptsizey, real ptsizex, int dpi, uint16_t *width,
1717 SplineChar *sc, int depth, int scaled);
1718 extern struct freetype_raster *FreeType_GetRaster(void *single_glyph_context,
1719 int enc, real ptsizey, real ptsizex, int dpi,int depth);
1720 extern BDFChar *SplineCharFreeTypeRasterizeNoHints(SplineChar *sc,int layer,
1721 int ptsize, int dpi,int depth);
1722 extern BDFFont *SplineFontFreeTypeRasterizeNoHints(SplineFont *sf,int layer,
1723 int pixelsize,int depth);
1724 extern void FreeType_FreeRaster(struct freetype_raster *raster);
1725 struct TT_ExecContextRec_;
1726 extern struct freetype_raster *DebuggerCurrentRaster(struct TT_ExecContextRec_ *exc,int depth);
1727
1728
1729 extern AnchorPos *AnchorPositioning(SplineChar *sc,unichar_t *ustr,SplineChar **sstr );
1730
1731 extern int SF_CloseAllInstrs(SplineFont *sf);
1732 extern int SSTtfNumberPoints(SplineSet *ss);
1733 extern int SCNumberPoints(SplineChar *sc,int layer);
1734 extern int SCPointsNumberedProperly(SplineChar *sc,int layer);
1735
1736 extern int SFRenameTheseFeatureTags(SplineFont *sf, uint32_t tag, int sli, int flags,
1737 uint32_t totag, int tosli, int toflags, int ismac);
1738 extern int SFRemoveUnusedNestedFeatures(SplineFont *sf);
1739
1740
1741
1742 extern struct macsetting *FindMacSetting(SplineFont *sf, int feat, int set,struct macsetting **secondary);
1743
1744
1745
1746 extern int BpColinear(BasePoint *first, BasePoint *mid, BasePoint *last);
1747 extern int BpWithin(BasePoint *first, BasePoint *mid, BasePoint *last);
1748 /* Colinear & between */
1749
1750 # if HANYANG
1751 extern void SFDDumpCompositionRules(FILE *sfd,struct compositionrules *rules);
1752 extern struct compositionrules *SFDReadCompositionRules(FILE *sfd);
1753 extern void SFModifyComposition(SplineFont *sf);
1754 extern void SFBuildSyllables(SplineFont *sf);
1755 # endif
1756
1757
1758
1759 extern void SFSetModTime(SplineFont *sf);
1760
1761
1762
1763 extern struct lookup_subtable *SFFindLookupSubtable(SplineFont *sf,const char *name);
1764 extern int FeatureTagInFeatureScriptList(uint32_t tag, FeatureScriptLangList *fl);
1765
1766 extern void SplinePointRound(SplinePoint *,real);
1767
1768 extern KernClass *SFFindKernClass(SplineFont *sf,SplineChar *first,SplineChar *last,
1769 int *index,int allow_zero);
1770 extern KernClass *SFFindVKernClass(SplineFont *sf,SplineChar *first,SplineChar *last,
1771 int *index,int allow_zero);
1772
1773 extern void SCClearRounds(SplineChar *sc,int layer);
1774 extern void MDReplace(MinimumDistance *md,SplineSet *old,SplineSet *rpl);
1775 extern void SCSynchronizeWidth(SplineChar *sc,real newwidth, real oldwidth,struct fontviewbase *fv);
1776 extern RefChar *HasUseMyMetrics(SplineChar *sc,int layer);
1777 extern void SCSynchronizeLBearing(SplineChar *sc,real off,int layer);
1778 extern void RevertedGlyphReferenceFixup(SplineChar *sc, SplineFont *sf);
1779
1780 extern void SFUntickAll(SplineFont *sf);
1781
1782
1783 extern int _ExportGlif(FILE *glif,SplineChar *sc,int layer,int version);
1784
1785 extern void SCCopyWidth(SplineChar *sc,enum undotype);
1786 extern void SCClearBackground(SplineChar *sc);
1787 extern void BackgroundImageTransform(SplineChar *sc, ImageList *img,real transform[6]);
1788 extern int SFIsDuplicatable(SplineFont *sf, SplineChar *sc);
1789
1790 extern void SCClearLayer(SplineChar *sc,int layer);
1791 extern void SCClearContents(SplineChar *sc,int layer);
1792 extern void SCClearAll(SplineChar *sc,int layer);
1793
1794 #if !defined(_NO_PYTHON)
1795 extern void FontForge_InitializeEmbeddedPython(void);
1796 extern void FontForge_FinalizeEmbeddedPython(void);
1797 extern void PyFF_ErrorString(const char *msg,const char *str);
1798 extern void PyFF_ErrorF3(const char *frmt, const char *str, int size, int depth);
1799 extern void PyFF_Stdin(int no_inits, int no_plugins);
1800 extern void PyFF_Main(int argc,char **argv,int start, int no_init, int no_plugins);
1801 extern void PyFF_ScriptFile(struct fontviewbase *fv,SplineChar *sc,char *filename);
1802 extern void PyFF_ScriptString(struct fontviewbase *fv,SplineChar *sc,int layer,char *str);
1803 extern void PyFF_FreeFV(struct fontviewbase *fv);
1804 extern void PyFF_FreeSC(SplineChar *sc);
1805 void PyFF_FreeSCLayer(SplineChar *sc, int layer);
1806 extern void PyFF_FreeSF(SplineFont *sf);
1807 extern void PyFF_FreePythonPersistent(void *python_persistent);
1808 extern void PyFF_ProcessInitFiles(int no_inits, int no_plugins);
1809 extern char *PyFF_PickleMeToString(void *pydata);
1810 extern void *PyFF_UnPickleMeToObjects(char *str);
1811 struct _object; /* Python Object */
1812 extern void PyFF_CallDictFunc(struct _object *dict,const char *key,const char *argtypes, ... );
1813 #endif
1814
1815
1816
1817
1818 extern struct math_constants_descriptor {
1819 char *ui_name;
1820 char *script_name;
1821 int offset;
1822 int devtab_offset;
1823 char *message;
1824 int new_page;
1825 } math_constants_descriptor[];
1826
1827 #define MATH_CONSTANTS_DESCRIPTOR_EMPTY { NULL, NULL, 0, 0, NULL, 0 }
1828
1829 extern const char *knownweights[], *realweights[], **noticeweights[];
1830
1831 extern int BPTooFar(BasePoint *bp1, BasePoint *bp2);
1832 extern StemInfo *SCHintOverlapInMask(SplineChar *sc,HintMask *hm);
1833 extern char *VSErrorsFromMask(int mask,int private_mask);
1834 extern int SCValidate(SplineChar *sc, int layer, int force);
1835 extern AnchorClass *SCValidateAnchors(SplineChar *sc);
1836 extern void SCTickValidationState(SplineChar *sc,int layer);
1837 extern int ValidatePrivate(SplineFont *sf);
1838 extern int SFValidate(SplineFont *sf, int layer, int force);
1839 extern enum validation_state VSMaskFromFormat(SplineFont *sf, int layer, enum fontformat format);
1840
1841 extern char *RandomParaFromScript(uint32_t script, uint32_t *lang, SplineFont *sf);
1842
1843 extern void PatternSCBounds(SplineChar *sc,DBounds *b);
1844
1845 extern char *SFDefaultImage(SplineFont *sf,char *filename);
1846 extern void SCClearInstrsOrMark(SplineChar *sc, int layer, int complain);
1847 extern void instrcheck(SplineChar *sc,int layer);
1848 extern void TTFPointMatches(SplineChar *sc,int layer,int top);
1849
1850 extern bigreal SFCapHeight(SplineFont *sf, int layer, int return_error);
1851 extern bigreal SFXHeight(SplineFont *sf, int layer, int return_error);
1852 extern bigreal SFAscender(SplineFont *sf, int layer, int return_error);
1853 extern bigreal SFDescender(SplineFont *sf, int layer, int return_error);
1854
1855 extern void SCRemoveKern(SplineChar* sc);
1856 extern void SCRemoveVKern(SplineChar* sc);
1857
1858 /**
1859 * Return falise if the container does not contain "sought"
1860 * Return true if sought is in the container.
1861 */
1862 extern int SplinePointListContains( SplinePointList* container, SplinePointList* sought );
1863
1864 /**
1865 * Return falise if the container does not contain the single splint point "sp",
1866 * Return true if "sp" is in the container.
1867 */
1868 extern int SplinePointListContainsPoint( SplinePointList* container, SplinePoint* sp );
1869
1870 /**
1871 * Visitor for SPLFirstVisitSplines()
1872 */
1873 typedef void (*SPLFirstVisitSplinesVisitor)( SplinePoint* splfirst, Spline* s, void* udata );
1874
1875 /**
1876 * Visitor Function: print debug information about each spline
1877 *
1878 * Visitor for SPLFirstVisit()
1879 */
1880 extern void SPLFirstVisitorDebug(SplinePoint* splfirst, Spline* spline, void* udata );
1881
1882 /**
1883 * Visitor Function: print debug information about the current
1884 * selection state including the secondary BCP selection for each
1885 * spline
1886 *
1887 * Visitor for SPLFirstVisit()
1888 */
1889 extern void SPLFirstVisitorDebugSelectionState(SplinePoint* splfirst, Spline* spline, void* udata );
1890
1891 /**
1892 * Given a SplinePointList* that you want to visit each spline in the
1893 * iteration is not as simple as it could be, so you can call this
1894 * function passing spl->first as 'splfirst' and a visitor function
1895 * which will see each spline in the splfirst colleciton.
1896 *
1897 * For debug, you can pass SPLFirstVisitorDebug which will print
1898 * information for each item in the splfirst collection.
1899 *
1900 * You can pass any arbitrary data in as udata and SPLFirstVisit()
1901 * will pass that udata to your visitor function without change. If
1902 * you want a return value from your visitor, pass a pointer to a
1903 * struct as udata. eg:
1904 *
1905 * typedef struct SPLFirstVisitorFoundSoughtDataS
1906 * {
1907 * SplinePoint* sought;
1908 * int found;
1909 * } SPLFirstVisitorFoundSoughtData;
1910 *
1911 * // ...
1912 *
1913 * SPLFirstVisitorFoundSoughtData d;
1914 * d.sought = sought;
1915 * d.found = 0;
1916 * SPLFirstVisit( spl->first, SPLFirstVisitorFoundSought, &d );
1917 * if( d.found )
1918 * return 1;
1919 *
1920 */
1921 extern void SPLFirstVisitSplines( SplinePoint* splfirst, SPLFirstVisitSplinesVisitor f, void* udata );
1922
1923 /**
1924 * Visitor for SPLFirstVisitPoints()
1925 */
1926 typedef void (*SPLFirstVisitPointsVisitor)( SplinePoint* splfirst, Spline* s, SplinePoint* sp, void* udata );
1927
1928 /**
1929 * Visit all the SplinePoints on the spline starting at splfirst.
1930 */
1931 extern void SPLFirstVisitPoints( SplinePoint* splfirst, SPLFirstVisitPointsVisitor f, void* udata );
1932
1933
1934
1935 /**
1936 * Applies a visitor to the container and returns false if no point in the SPL
1937 * has an x coordinate of 'x'.
1938 */
1939 extern SplinePoint* SplinePointListContainsPointAtX( SplinePointList* container, real x );
1940 extern SplinePoint* SplinePointListContainsPointAtY( SplinePointList* container, real y );
1941 extern SplinePoint* SplinePointListContainsPointAtXY( SplinePointList* container, real x, real y );
1942
1943
1944 /**
1945 * True if the spline with from/to is part of the guide splines.
1946 *
1947 * Handy for telling if the user has just clicked on a guide for example,
1948 * you might want to also check the active layer first with cv->b.drawmode == dm_grid
1949 */
1950 extern bool isSplinePointPartOfGuide( SplineFont *sf, SplinePoint *sp );
1951
1952
1953 extern void debug_printHint( StemInfo *h, char* msg );
1954
1955 #if defined(_WIN32) || defined(__HAIKU__)
1956 #define BAD_LOCALE_HACK
1957 typedef char* locale_t;
1958 #define LC_GLOBAL_LOCALE ((locale_t)-1)
1959 #define LC_ALL_MASK LC_ALL
1960 #define LC_COLLATE_MASK LC_COLLATE
1961 #define LC_CTYPE_MASK LC_CTYPE
1962 #define LC_MONETARY_MASK LC_MONETARY
1963 #define LC_NUMERIC_MASK LC_NUMERIC
1964 #define LC_TIME_MASK LC_TIME
1965 #endif
1966
1967 static inline void switch_to_c_locale(locale_t * tmplocale_p, locale_t * oldlocale_p) {
1968 #ifndef BAD_LOCALE_HACK
1969 *tmplocale_p = newlocale(LC_NUMERIC_MASK, "C", NULL);
1970 if (*tmplocale_p == NULL) fprintf(stderr, "Failed to create temporary locale.\n");
1971 else if ((*oldlocale_p = uselocale(*tmplocale_p)) == NULL) {
1972 fprintf(stderr, "Failed to change locale.\n");
1973 freelocale(*tmplocale_p); *tmplocale_p = NULL;
1974 }
1975 #else
1976 // Yes, it is dirty. But so is an operating system that doesn't support threaded locales.
1977 *oldlocale_p = (locale_t)copy(setlocale(LC_NUMERIC_MASK, "C"));
1978 if (*oldlocale_p == NULL) fprintf(stderr, "Failed to change locale.\n");
1979 #endif
1980 }
1981
1982 static inline void switch_to_old_locale(locale_t * tmplocale_p, locale_t * oldlocale_p) {
1983 #ifndef BAD_LOCALE_HACK
1984 if (*oldlocale_p != NULL) { uselocale(*oldlocale_p); } else { uselocale(LC_GLOBAL_LOCALE); }
1985 *oldlocale_p = NULL; // This ends the lifecycle of the temporary old locale storage.
1986 if (*tmplocale_p != NULL) { freelocale(*tmplocale_p); *tmplocale_p = NULL; }
1987 #else
1988 if (*oldlocale_p != NULL) {
1989 setlocale(LC_NUMERIC_MASK, (char*)(*oldlocale_p));
1990 free((char*)(*oldlocale_p));
1991 *oldlocale_p = NULL;
1992 }
1993 #endif
1994 }
1995
1996 static inline locale_t newlocale_hack(int category_mask, const char *locale, locale_t base) {
1997 // Note that, in the interest of minimizing the hack, we drop the category mask on Wingdows.
1998 #ifndef BAD_LOCALE_HACK
1999 return newlocale(category_mask, locale, base);
2000 #else
2001 return (locale_t)copy(locale);
2002 #endif
2003 }
2004
2005 static inline locale_t uselocale_hack(locale_t dataset) {
2006 #ifndef BAD_LOCALE_HACK
2007 return uselocale(dataset);
2008 #else
2009 return (locale_t)copy(setlocale(LC_ALL_MASK, (char*)dataset));
2010 #endif
2011 }
2012
2013 static inline void freelocale_hack(locale_t dataset) {
2014 #ifndef BAD_LOCALE_HACK
2015 freelocale(dataset);
2016 #else
2017 if (dataset != NULL) { free(dataset); }
2018 #endif
2019 }
2020
2021 #if 0
2022 #define DECLARE_TEMP_LOCALE() char oldloc[25];
2023 #define SWITCH_TO_C_LOCALE() strncpy( oldloc,setlocale(LC_NUMERIC,NULL),24 ); oldloc[24]='\0'; setlocale(LC_NUMERIC,"C");
2024 #define SWITCH_TO_OLD_LOCALE() setlocale(LC_NUMERIC,oldloc);
2025 #else
2026 #define DECLARE_TEMP_LOCALE() locale_t tmplocale; locale_t oldlocale; // Declare temporary locale storage.
2027 #define SWITCH_TO_C_LOCALE() switch_to_c_locale(&tmplocale, &oldlocale); // Switch to the C locale temporarily and cache the old locale.
2028 #define SWITCH_TO_OLD_LOCALE() switch_to_old_locale(&tmplocale, &oldlocale); // Switch to the cached locale.
2029 #endif
2030
2031 #ifdef __cplusplus
2032 }
2033 #endif
2034
2035 #endif /* FONTFORGE_SPLINEFONT_H */