1Spline Font Database
2====================
3
4.. warning::
5
6   This page is often out of date. I thought it was a correct on 16 Feb 2011. A
7   :doc:`changelog <sfdchangelog>` file is available. Even if out of date it
8   should be helpful, but if you really need to know the current format look at
9   `fontforge/sfd.c <https://github.com/fontforge/fontforge/blob/master/fontforge/sfd.c>`_
10   and see what it parses. Some descriptions of esoteric features are not
11   complete, but I hope they give you enough hints that you can figure the
12   format out (especially after looking it up in sfd.c)
13
14.. epigraph::
15
16   | **TYSON:**
17   | What is the meaning of this?
18   |
19   | **THOMAS**
20   | That's the most relevant
21   | Question in the world.
22
23   -- *The Lady's not for Burning*
24   -- Christopher Fry
25
26The sfd [#sfdext]_ format evolves over time. I hope the current parser can handle old sfd
27formats. Most changes have been small, but in Feb 2008 I allowed multiple layers
28in fonts and this turned out to be an incompatible change and I raised the sfd
29version number to 3, and in March of 2007 the way fontforge handled lookups and
30features changed radically (and I bumped the SFD file version number for the
31first time) and sfd files created before then are better understood if you look
32at an
33`older version of this document <https://github.com/fontforge/fontforge/commits/master/htdocs/sfdformat.html>`_.
34
35FontForge's sfd files are ASCII files (so they can be copied easily
36across the internet and so that diffs are somewhat meaningful). They contain a
37full description of your font. As of 14 May 2008 there is a registered (with
38IANA) MIME type for them
39`application/vnd.font-fontforge-sfd <http://www.iana.org/assignments/media-types/application/>`_.
40
41They are vaguely modeled on bdf files. The first few lines contain general font
42properties, then there's a section for each character, then a section for each
43bitmap font.
44
45.. contents::
46   :depth: 2
47   :backlinks: none
48
49.. warning::
50
51   It is tempting to cut and paste information from one sfd file to another.
52   This is usually ok, but there are a couple of cases than need to be avoided:
53
54* If you copy a glyph with truetype instructions, those instructions may call
55  subroutines defined in the old font but not the new. Unexpected things may
56  happen when the glyph is grid fit (including system crashes)
57* If you copy a substitution (ligature, kern, contextual chaining, ...) item from
58  one font to another, the substitution contains the name of a lookup-subtable.
59  Bad things will probably happen if the lookup subtable isn't in the font.
60* If you copy a glyph containing references -- these are done by glyph index
61  (which is probably different from font to font). You may end up refering to the
62  wrong glyph.
63
64
65.. _sfdformat.Font-Header:
66
67Font Header
68-----------
69
70Here is an example of what the first few lines look like:
71
72::
73
74   SplineFontDB: 3.0
75   FontName: Ambrosia
76   FullName: Ambrosia
77   FamilyName: Ambrosia
78   DefaultBaseFilename: Ambrosia-1.0
79   Weight: Medium
80   Copyright: Copyright (C) 1995-2000 by George Williams
81   Comments: This is a funny font.
82   UComments: "This is a funny font."
83   FontLog: "Create Jan 2008"
84   Version: 001.000
85   ItalicAngle: 0
86   UnderlinePosition: -133
87   UnderlineWidth: 20
88   Ascent: 800
89   Descent: 200
90   sfntRevision: 0x00078106
91   WidthSeparation: 140
92   LayerCount: 4
93   Layer: 0 0 "Back" 1
94   Layer: 1 1 "Fore" 0
95   Layer: 2 0 "Cubic_Fore" 0
96   Layer: 3 0 "Test" 1
97   DisplaySize: -24
98   DisplayLayer: 1
99   AntiAlias: 1
100   WinInfo: 64 16 4
101   FitToEm: 1
102   UseUniqueID: 0
103   UseXUID: 1
104   XUID: 3 18 21
105   Encoding: unicode
106   Order2: 1
107   OnlyBitmaps: 0
108   MacStyle: 0
109   TeXData: 1 10485760 0 269484 134742 89828 526385 1048576 89828
110   CreationTime: 1151539072
111   ModificationTime: 11516487392
112   GaspTable 3 8 2 16 1 65535 3 0
113   DEI: 91125
114   ExtremaBound: 30
115
116The first line just identifies the file as an sfd file and provides a version
117number. IT MUST BE FIRST in the file. The rest of the file is basically a set of
118keyword value pairs. Within a given section, order is largely irrelevant. The
119next few lines give the various different names that postscript allows fonts to
120have. Then some fairly self-explanatory items (if they don't make sense, look
121them up in the :doc:`font info </ui/dialogs/fontinfo>` dlg). A few things need some
122explanation:
123
124.. object:: Comments
125
126   This is deprecated. A string of ASCII characters
127
128.. object:: UComments
129
130   New format for font comments. A string of utf7 characters.
131
132.. object:: FontLog
133
134   A string of utf7 characters.
135
136.. object:: TeXData
137
138   These are the TeX font parameters (and some similar info). The first number
139   is 1,2 or 3 and indicates that the font is a text, math or math ext font. The
140   next number is the design pointsize (times (1<<20)). Then follow the font
141   parameters. These values are usually in TeX fix_word format where there is a
142   binary point after the first 20 binary digits (so to get the number divide by
143   (1<<20)).
144
145.. object:: sfntRevision
146
147   This is the revision number field of the 'head' table of an sfnt. It is
148   stored in hex in a 16.16 fixed number (that is, a 32 bit number where the
149   binary point is after the 16th binary bit).
150
151.. object:: WidthSeparation
152
153   This is internal information that the user never sees directly. It indicates
154   the most recent value for the desired separation between glyphs that was used
155   in the AutoWidth command. It is also used as a default for the separation in
156   AutoKern.
157
158.. object:: LayerCount
159
160   The number of layers in a font, must be at least 2.
161
162.. object:: Layer
163
164   One entry for each layer to name it and describe its splines «Layer: 1 1
165   "Fore" 0» means this is layer 1, it has quadratic splines, is named "Fore"
166   and is not a background layer, while «Layer: 2 0 "Cubic_Fore" 0» means this
167   is layer 2, it does not have quadratic splines (so it has cubic), is named
168   "Cubic_Fore" and is also not a background layer.
169
170   Layer <layer-number> <quadratic-flag> <name> [<background-flag>]
171
172.. object:: DisplaySize
173
174   This is the number of pixels per em that will be used by default to display
175   the font in fontviews (it may be changed of course). Negative numbers mean to
176   rasterize the display from the outlines, positive numbers mean to use a
177   prebuilt bitmap font of that size.
178
179.. object:: DisplayLayer
180
181   The layer that should be displayed by default on opening the font.
182
183.. object:: AntiAlias
184
185   Whether the fontview should display the font as antialiased or black and
186   white. (AntiAliased looks better, but will be slower)
187
188.. object:: FitToEm
189
190   Controls whether Fit to Em is checked by default in a fontview that displays
191   this font.
192
193.. object:: WinInfo
194
195   Has three pieces of data on the default display of windows containing this
196   font. The first datum says that the window should be scrolled so that glyph
197   at encoding 64 should be visible, the second that the window should have 16
198   character columns horizontally, and the last that there should be 4 character
199   rows vertically.
200
201.. object:: Encoding
202
203   For normal fonts this will be one of the names (or a close approximation
204   thereto) that appears in the Encoding pulldown list. CID keyed fonts will not
205   have encodings. Instead they'll have something like:
206
207   ::
208
209      Registry: Adobe
210      Ordering: japan1
211      Supplement: 4
212      CIDVersion: 1.2
213
214.. object:: CreationTime
215
216.. object:: ModificationTime
217
218   These two dates are expressed as seconds since 00:00:00, 1 January, 1970 --
219   standard unix dates.
220
221.. object:: GaspTable
222
223   The first number following the keyword gives the number of ppem/flag pairs on
224   the line. The next two numbers are the first ppem and first flag. The last
225   number is gasp table version.
226
227.. object:: UseXUID
228
229   Nowadays Adobe says XUID is deprecated. If this flag is set then fontforge
230   will still generate an XUID entry for a postscript font.
231
232.. object:: DEI
233
234   It's too hard to explain, see the minutes of the CalTech OddHack committee
235   from 15 Jan 1980. You can safely ignore it.
236
237.. object:: ExtremaBound
238
239   Adobe says that short splines are allowed to have internal extrema, but that
240   big splines are not. But they don't define "big". This allows the user to
241   specify that number. Splines where the distance between end-points is longer
242   than this number will be checked for extrema.
243
244For WOFF files
245
246::
247
248   woffMajor: 7
249   woffMinor: 504
250   woffMetadata: "<?xml version+AD0AIgAA-1.0+ACIA encoding ..."
251
252.. object:: woffMajor
253
254   The major version number to be stored in a woff file.
255
256.. object:: woffMinor
257
258   The minor version number of the woff file.
259
260.. object:: woffMetadata
261
262   Metadata for the woff file, stored in UTF7.
263
264For UFO files
265
266::
267
268   UFOAscent: 697
269   UFODescent: -154
270
271.. object:: UFOAscent
272
273   The value of the "ascender" field in the fontinfo.plist file of a UFO font.
274
275.. object:: UFODescent
276
277   The value of the "descender" field in the fontinfo.plist file of a UFO font.
278
279Some fonts will have some TrueType information in them too (look at the
280`truetype spec <http://www.microsoft.com/typography/tt/tt.htm>`_ for the
281meanings of these, they usually live in the OS/2, hhea, or vhea tables).
282
283::
284
285   FSType: 4
286   PFMFamily: 17
287   TTFWeight: 400
288   TTFWidth: 5
289   Panose: 2 0 5 3 0 0 0 0 0 0
290   LineGap: 252
291   OS2LineGap: 252
292   VLineGap: 0
293   OS2Vendor: 'PfEd'
294   OS2FamilyClass: 2050
295   OS2Version: 4
296   OS2_WeightWidthSlopeOnly: 1
297   OS2_UseTypoMetrics: 1
298   OS2CodePages: 6000009f.9fd70000
299   OS2UnicodeRanges: 800002ef.50002049.00000000.00000000
300
301The following items also come from the OS/2 and hhea tables but are slightly
302more complex. The keywords are paired, so ``HheadAscent`` and ``HheadAOffset``
303work together. If the offset keyword is 1 (true) then the other keyword is
304treated as a value relative to what FontForge thinks should be the correct
305value, FontForge will calculate what it thinks the value should be and then will
306add the value specified in the keyword. So in the example below, FF will figure
307out what it thinks ``HheadAscent`` should be and then add "0" to it to get the
308value stored in a truetype font's OS/2 table. However if the Offset flag is set
309to 0 (false) then the Ascent would be used exactly as specified.
310
311::
312
313   HheadAscent: 0
314   HheadAOffset: 1
315   HheadDescent: 0
316   HheadDOffset: 1
317   OS2TypoAscent: 0
318   OS2TypoAOffset: 1
319   OS2TypoDescent: 0
320   OS2TypoDOffset: 1
321   OS2WinAscent: 0
322   OS2WinAOffset: 1
323   OS2WinDescent: 0
324   OS2WinDOffset: 1
325
326These represent different definitions of ascent and descent that are stored in
327various places in the truetype file (Horizontal header and OS/2 tables).
328
329The OS/2 table contains information on the position of subscripts, superscripts
330and strike throughs:
331
332::
333
334   OS2SubXSize: 1351
335   OS2SubYSize: 1228
336   OS2SubXOff: 0
337   OS2SubYOff: -446
338   OS2SupXSize: 1351
339   OS2SupYSize: 1228
340   OS2SupXOff: 0
341   OS2SupYOff: 595
342   OS2StrikeYSize: 143
343   OS2StrikeYPos: 614
344
345The MacStyle field (if present) indicates whether the font is bold, italic,
346condensed, extended, etc.
347
348Some fonts will have PostScript specific information contained in the Private
349dictionary (the value is preceeded by an integer holding the number of
350characters needed for the string representation. It makes reading the file
351slightly faster, but is ugly. I should not have done that, but too late now).
352
353::
354
355   BeginPrivate: 1
356   BlueValues 23 [-19 0 502 517 750 768]
357   EndPrivate
358
359Some fonts may have python data:
360
361::
362
363   PickledData: "I3
364   ."
365
366This is arbetrary python pickled data (protocol=0) which got set by a python
367script. FontForge stores it as a string. If there are either double quotes or
368backslashes inside the string they will be preceded by a backslash.
369
370If your font has any lookups
371
372::
373
374   Lookup: 6 0 0 "calt"  {"calt-1"  } ['calt' ('DFLT' <'dflt' > 'latn' <'dflt' > ) ]
375   Lookup: 1 0 0 "'smcp' Lowercase to Small Capitals in Latin lookup 0"  {"'smcp' Lowercase to Small Capitals in Latin lookup 0"  } ['smcp' ('latn' <'dflt' > ) ]
376   Lookup: 4 0 1 "'liga' Standard Ligatures in Latin lookup 1"  {"'liga' Standard Ligatures in Latin lookup 1"  } ['liga' ('latn' <'dflt' > ) ]
377   Lookup: 258 0 0 "'kern' Horizontal Kerning in Latin lookup 0"  {"'kern' Horizontal Kerning in Latin lookup 0" [150,0,0]  } ['kern' ('latn' <'dflt' > ) ]
378
379All entries in the lookup list start with the "Lookup:" keyword. They are
380followed by a lookup type, and flags, and the save-in-afm flag. Then within
381curly braces is a list of all subtable names in this lookup. Then within backets
382a list of all features each followed (within parens) by a list of all scripts
383each followed (within brockets) by a list of all languages. (the lookup flags
384field is now a 32 bit number, the low order 16 bits being the traditional flags,
385and the high order being the mark attachment set index, if any).
386
387GSUB single substitution subtable names may be followed by a pair parentheses
388containing a utf7 string with the default suffix used for this subtable.
389
390Kerning subtable names may be followed by a "(1)" to indicated they are vertical
391kerning, or by a pair of brackets containing three numbers. These numbers
392represent default values for autokerning in this subtable, the first is the
393desired separation between glyphs, the next is the minimum (absolute) value that
394will generate a kerning pair (kerning by 1 em unit isn't interesting and if
395that's what autokern comes up with, there is really no point to it and it wastes
396time), and the last is a set of bit flags: if the number is odd then it means
397separation is based on closest approach (touching), if the number has bit 2 set,
398then only negative (closer) kerning values will be generated by autokerning and
399if the number has bit 4 set then no auto- kerning will happen at all.
400
401The order in which lookups are applied is the order listed here. The order in
402which subtables are applied is the order listed here.
403
404If your font has any kerning classes
405
406::
407
408   KernClass2: 31 64 2 "'kern' Horizontal Kerning in Latin lookup 0"
409    1 F
410    41 L Lacute glyph78 Lcommaaccent Ldot Lslash
411    1 P
412   ...
413    6 hyphen
414    5 space
415   ...
416    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
417    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -152 -195 -152 -225 0 0 0 0 0 0 0 0 0 0 0 0 0 -145 -145 -130
418    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -130 0 0 0 0 0 0 0 0 0 0 -145 0 -115 0 0 0 0 -65 0 -140 -120 -120
419   ...
420
421The first line says that this Kerning Class has 31 different classes for the
422first character, and 64 for the second. It lives in the lookup subtable named
423"'kern' Horizontal Kerning in Latin lookup 0".. The next line says that the
424first character class of the first character (numbered 1, class 0 is reserved
425and usually is not defined) consists of only one character "F" (the number in
426front is the string length of the line. It speeds up processing the sfd file but
427has no semantic content). The next line is for class 2 of the first character,
428it has more characters in it and a longer string length. After 30 entries we
429start on the classes for the second character. They look exactly like classes
430for the first character. After all the second character classes have been
431defined we have an array of numbers, <char1 class cnt>*<char2 class cnt> of them
432in fact. This specifies the amount of kerning that should be placed between a
433characters of the given classes of left and right characters (ie. if char1 was
434in left class 2 and char2 was in right class 4 then we would index this array
435with 3*<char2 class cnt> + 4).
436
437In some cases it is possible to specify class 0 of the first glyph in a kerning
438by classes entry (but not class 0 of the second glyph). In this case there will
439be a plus sign after the count of classes for the first glyph. Then the first
440list of names will be class 0.
441
442You may find :ref:`device <sfdformat.device-table>` tables interspersed among
443the kerning offsets array:
444
445::
446
447   ...
448   0 {} 0 {} 0 {} ...
449   -145 {12-13 -1,1} -145 {} -130 {8-9 -1,-1} ...
450
451If your font has GDEF Mark attachement classes or sets these look like
452
453::
454
455   MarkAttachClasses: 2
456   "ABClass" 3 A B
457   MarkAttachSets: 2
458   "ABSet" 3 A B
459   "ASet" 1 A
460
461In the example above there are (sort of) 2 mark attachment classes, but class 0
462is always empty and isn't listed. So there's really one class. It is named (the
463name is a FontForge thing, not exported to opentype) "ABClass", is 3 characters
464long and is "A B".
465
466Similarly, there are 2 mark attachment sets. Here set 0 is used, and must be
467specified. Set 0 is called "ABSet" is 3 characters long and is "A B", while set
4681 is called "ASet", is 1 character long and is "A".
469
470If your font has any baseline data
471
472::
473
474   BaseHoriz: 3 'hang' 'ideo' 'romn'
475   BaseScript: 'cyrl' 2  1405 -288 0
476   BaseScript: 'grek' 2  1405 -288 0
477   BaseScript: 'latn' 2  1405 -288 0 { 'dflt' -576 1913} { 'ENG ' -576 1482} { 'VIT ' -578 2150}
478
479The BaseHoriz (or BaseVert) line indicates how many and which baselines are
480active for this axis (Horizontal or Vertical). There is one BaseScript line for
481each script. The first number after it indicates which baseline is the default
482baseline for this script, subsequent numbers indicate how other baselines are
483configured with respect to the default one. Language specific information
484appears inside {} pairs. (feature specific information would be in {} pairs
485inside the language specific curly braces).
486
487If your font has any JSTF (justification) data
488
489::
490
491   Justify: 'arab'
492   JstfExtender: afii57440 afii5739
493   Justify: 'latn'
494   JstfLang: 'dflt' 5
495   JstfPrio:
496   JstfMaxShrink: "JSTF shrinkage max at priority 0 #0 for dflt in latn"
497   JstfMaxExtend: "JSTF extension max at priority 0 #1 for dflt in latn"
498   JstfPrio:
499   JstfEnableShrink: "'mark' Mark Positioning in Latin lookup 5"  "'kern' Horizontal Kerning in Latin lookup 6"  "'kern' Horizontal Kerning in Cyrillic lookup 7"
500   JstfPrio:
501   JstfEnableShrink: "'liga' Standard Ligatures in Latin lookup 10"  "'alig' Ancient Ligatures in Latin lookup 11"  "'liga' Standard Ligatures in Latin lookup 12"
502   JstfDisableExtend: "'liga' Standard Ligatures in Latin lookup 10"  "'alig' Ancient Ligatures in Latin lookup 11"  "'liga' Standard Ligatures in Latin lookup 12"
503   JstfPrio:
504   JstfMaxShrink: "JSTF shrinkage max at priority 3 #2 for dflt in latn"
505   JstfMaxExtend: "JSTF extension max at priority 3 #3 for dflt in latn"
506   JstfPrio:
507   JstfMaxShrink: "JSTF shrinkage max at priority 4 #4 for dflt in latn"
508   JstfMaxExtend: "JSTF extension max at priority 4 #5 for dflt in latn"
509   Justify: 'cyrl'
510   JstfLang: 'dflt' 1
511   JstfPrio:
512   JstfMaxShrink: "JSTF shrinkage max at priority 0 #6 for dflt in cyrl"
513   JstfMaxExtend: "JSTF extension max at priority 0 #7 for dflt in cyrl"
514   EndJustify
515
516A block of justification information begins with a ``Justify:`` keyword and is
517followed by a script tag. There may be several ``Justify:`` instances if information is
518provided for several scripts, the final block must be terminated with a
519``EndJustify`` keyword.
520
521Within a block extender glyphs (kashidas) may be specified with a
522``JstfExtender:`` keyword followed by a list of glyph names.
523
524Each language within the script is started by a ``JstfLang:`` keyword and is
525followed by a language tag and a count of the number of priority levels.
526
527Each priority level is started with a ``JstfPrio:`` keyword, after which you may
528find any of the keywords
529``JstfEnableShrink, JstfDisableShrink, JstfMaxShrink, JstfEnableExtend, JstfDisableExtend, JstfMaxExtend``
530each of which is followed by a list of lookup names.
531
532If the font contains ttf hinting, then the file may contain truetype tables,
533these may be stored in several formats depending on the table. For containting
534truetype instructions (fpgm, prep):
535
536::
537
538   TtTable: prep
539   PUSHW_1
540    640
541   NPUSHB
542    255
543    251
544    254
545    3
546    ...
547
548The first line says that this is the 'prep' table, subsequent lines provide the
549instructions of that table. These are stored in the format used by fontforge,
550there's a table giving the conversion between bytecode and instruction name in
551the file ttfinstrs.c (I won't introduce it here because it is rather long).
552
553::
554
555   ShortTable: cvt  255
556     309 "Big stem width, vertical"
557     184 "Small stem width, vertical"
558     203 "Stem width, horizontal"
559     203
560    ...
561
562The next table format is used for the ``'cvt '`` and ``'maxp'`` tables. It is
563simply a list of short numbers. The first line identifies it as the cvt table
564and indicates that there will be 255 numbers (note: NOT 255 *bytes*, but 2*255
565bytes).
566
567In the ``'cvt '`` table (but not in ``'maxp'``) there may be additional
568comments, one for each number. These are simply descriptive comments which
569remind people what each cvt entry is supposed to do. They are totally optional.
570
571::
572
573   TtfTable: LILY 4360
574   5S;o3()It?eJ8r@H[HSJH[H^@!b&BQ*?Vcm@'XSh+1MACZ>Up/\,o1+Ca't2!<ocH+Wn2p"@,t&
575   +Wo+[()Is6G8:u7D/^7,*,KO/(E=N5!=s)LCMjn,:Mp3:DSL&j05dG#cY`hLCN"!<CBO$@s(_ZX
576   ...
577
578FontForge will also store tables it doesn't understand, these will be stored in
579uninterpreted binary which is packed using the ASCII85Encode [#ascii85]_ encoding
580filter. The first line says that the 'LILY' table is 4360 bytes long.
581Subsequent lines will provide those 4360 bytes of data ASCII85Encode [#ascii85]_. See
582the PostScript Reference Manual (3rd edition, pages 131-132) for a description
583of this packing, or ``$ man btoa``).
584
585The ``LangName`` entries represent the TrueType name table: the number
586represents the language and is followed by a list of strings encoded in UTF-7.
587The first string corresponds to ID=0 (Copyright), the second to ID=1 (Family),
588... trailing empty strings will be omitted. In the American English language
589(1033) section, if one of these names exactly matches the equivalent postscript
590item then that name will be omitted (this makes it easier to handle updates,
591users only have to change the copyright in one place)
592
593::
594
595   LangName: 1033 "" "" "Regular" "GWW:Caliban Regular: Version 1.0" "" "Version 1.0"
596   LangName: 1032 "" "" "+A5oDsQ09A78DvQ05A7oDrAAA"
597
598With version 1.6 of OpenType, you are allowed to provide name table entries for
599the feature names 'ss01' - 'ss20'. These look like:
600
601::
602
603   OtfFeatName: 'ss01'  1036 "Riable"  1033 "Risible"
604
605Which binds feature 'ss01' to the name "Riable" in French (language 1036) and to
606"Risible" in English (language 1033).
607
608If your font has any anchor classes:
609
610::
611
612   AnchorClass2: "top" "Latin marks-1" "bottom" "Latin marks-1" "Anchor-2" "Latin marks-1" "Anchor-3" "Latin marks-2" "Anchor-4" "Latin marks-2" "Anchor-5" "Latin marks-2" "Anchor-6" "Latin marks-2"
613
614There is an Anchor Class named "top" which lives in lookup subtable "Latin
615marks-1". The next class is named "bottom", the next "Anchor-2" and so forth.
616(Anchor class names are output in UTF7)
617
618Contextual or contextual chaining lookups are also stored in the font header.
619The are introduced by one of the keywords: "ContextPos2", "ContextSub2",
620"ChainPos2", "ChainSub2" and "ReverseChain2", and are ended by "EndFPST".
621Contextual chaining lookups may check previous glyphs (called backtracking),
622current glyphs and lookahead glyphs, while Contextual lookups only check for a
623string of current glyphs. There are four formats:
624
625By coverage tables
626
627::
628
629   ChainSub2: coverage "calt-1" 0 0 0 1
630    1 1 0
631     Coverage: 7 uni0C40
632     BCoverage: 8 glyph388
633    1
634     SeqLookup: 0 "high"
635   EndFPST
636
637This defines a simple context chaining substitution by coverage class. It lives
638in the lookup subtable named "calt-1". There are no classes, no backtracking
639classes and no lookahead classes defined (it's by coverage table). There is one
640rule. (For a greater explanation of these cryptic comments see the OpenType
641specs on contextual lookups).
642
643Then follows the first rule. The first line, "1 1 0", says how many coverage
644tables there are in the normal list (1), how many in the backtrack list (1) and
645how many in the lookahead list (0). Then we get the one normal coverage table,
646which describes a single glyph (uni0C40). Then one backtracking coverage table
647which also defines one glyph (glyph388). Finally there is one sequence lookup,
648at normal position 0, we should apply the substitution named '0013'.
649
650That is to say: If we find the glyph stream "glyph388 uni0C40", then it will
651match this lookup and we should apply lookup "high" (found elsewhere) to
652uni0C40.
653
654By classes
655
656::
657
658   ChainSub2: class "calt-1" 3 3 0 1
659     Class: 52 b o v w b.high o.high v.high w.high r.alt.high r.alt
660     Class: 43 a c d e f g h i j k l m n p q r s t u x y z
661     BClass: 52 b o v w b.high o.high v.high w.high r.alt.high r.alt
662     BClass: 43 a c d e f g h i j k l m n p q r s t u x y z
663    1 1 0
664     ClsList: 2
665     BClsList: 1
666     FClsList:
667    1
668     SeqLookup: 0 "high"
669   EndFPST
670
671This defines a context chaining substitution, by classes. The format of the
672first line is the same as described above. Here we have three classes for the
673normal match and three for the backtracking match, and one rule. The next 4
674lines define the classes. As with kerning by classes, class 0 does not need to
675be explicitly defined, it is implicitly defined to be "any glyph not defined in
676another class". So we define class 1 to be "b,o,v,..." and class 2 to be
677"a,c,d,e,...". And then we define the backtracking classes (which here happen to
678be the same as the classes for the normal match, but that isn't always the
679case).
680
681The one rule says that if we get something in normal class 2 following something
682in backtracking class 1 (that is, if we get something like "ba" or "oc") then
683apply lookup "high"
684
685By glyphs
686
687::
688
689   ChainSub2: glyph "calt-1" 0 0 0 1
690    String: 1 D
691    BString: 3 c b
692    FString: 1 e
693    1
694     SeqLookup: 0 "high"
695   EndFPST
696
697Again we have one rule. That rule says that if we get the sequence of glyphs "c
698b D e" then we should apply substitution "high" to glyph "D".
699
700And finally by reverse coverage tables
701
702::
703
704   ChainSub2: revcov "calt-1" 0 0 0 1
705    1 1 0
706     Coverage: 7 uni0C40
707     BCoverage: 8 glyph388
708    1
709     Replace: 11 uni0C40.alt
710   EndFPST
711
712Which says that when glyph388 precedes uni0C40 then uni0C40 should be replaced
713by uni0C40.alt
714
715There may be apple state machines. These are introduced by one of the keywords:
716"MacIndic2", "MacContext2", "MacInsert2" and "MacKern2", and they are terminated
717with "EndASM".
718
719::
720
721   MacContext2: "calt-1" 16384 9 5
722     Class: 320 yehhamzaabovearabic beharabic teharabic theharabic jeemarabic haharabic khaharabic seenarabic sheenarabic sadarabic dadarabic taharabic zaharabic ainarabic ghainarabic feharabic qafarabic kafarabic lamarabic meemarabic noonarabic heharabic alefmaksuraarabic yeharabic peharabic tteharabic tcheharabic veharabic gafarabic
723     Class: 227 noonghunnaarabic alefmaddaabovearabic alefhamzaabovearabic wawhamzaabovearabic alefhamzabelowarabic alefarabic tehmarbutaarabic dalarabic thalarabic reharabic zainarabic wawarabic ddalarabic rreharabic jeharabic yehbarreearabic
724     Class: 201 shaddakasraarabic shaddakasratanarabic shaddafathaarabic shaddadammaarabic shaddadammatanarabic fathatanarabic dammatanarabic kasratanarabic fathaarabic dammaarabic kasraarabic shaddaarabic sukunarabic
725     Class: 13 tatweelarabic
726     Class: 17 ttehinitialarabic
727    0 0 ~ ~
728    0 0 ~ ~
729    0 0 ~ ~
730    0 0 ~ ~
731    2 32768 ~ ~
732    ...
733    3 32768 "high" "low"
734    ...
735   EndASM
736
737The state machine begins with a line defining what lookup subtable invokes it,
738some mac flags, the number of classes, and number of states in the machine. The
739first four states on the mac are predefined, so we start with class 4
740(yehhamzaabovearabic...). Finally there will be <number of classes>*<number of
741states> lines describing transitions. We begin with the transition for state 0,
742class 0, then the transition for state 0, class 1, ...
743
744Each transition contains the next state to go to, a set of flags. There may also
745be other arguments depending on the type of the state machine.
746
747.. object::MacIndic2
748
749   This format has no additional arguments
750
751.. object:: MacContext2
752
753   This format potentially contains the names of two lookup substitutions. One
754   to be applied to the marked glyph, one to be applied to the current glyph
755   (the special substitution "~" means do nothing and is used as a place
756   holder). See above.
757
758.. object:: MacInsert2
759
760   This format contains two glyph lists, each preceded by a number indicating
761   how many bytes follow.
762
763   ::
764
765      2 0 0 3 a b
766      0 32768 4 fi q 0
767
768   The first line indicates that no characters should be insert at the marked
769   glyph but that "a" and "b" should be insert at the current glyph. The second
770   line indicates that "fi" and "q" should be insert at the marked glyph and no
771   characters at the current glyph. The flags determine whether characters are
772   insert before or after the glyph.
773
774.. object:: MacKern2
775
776   This format contains a list of kerning offsets. First is a count field saying
777   how many numbers follow, then a list of numbers which adjust the kerning for
778   glyphs that have previously been pushed on the kerning stack.
779
780There may be a list of Mac Feature/Setting names
781
782::
783
784   MacFeat: 0 0 0
785   MacName: 0 0 24 "All Typographic Features"
786   MacSetting: 0
787   MacName: 0 0 12 "All Features"
788   MacFeat: 1 0 0
789   MacName: 0 0 9 "Ligatures"
790   MacSetting: 0
791   MacName: 0 0 18 "Required Ligatures"
792   MacSetting: 2
793   MacName: 0 0 16 "Common Ligatures"
794   MacFeat: 2 1 2
795
796There may be a Grid entry near the top of the font, this specifies the splines
797to be drawn in the grid layer for the font,
798:ref:`see below for a description of the splineset format <sfdformat.splineset>`:
799
800::
801
802   Grid
803   678 -168 m 5
804    -40 -168 l 5
805   -678 729 m 1
806    1452 729 l 1
807   -678 525 m 1
808    1452 525 l 1
809   EndSplineSet
810
811If your font contains a 'MATH' table you will see lines like:
812
813::
814
815   MATH:ScriptPercentScaleDown: 80
816   MATH:ScriptScriptPercentScaleDown: 60
817
818I shall not list all the posible entries. Basically there is one for every
819constant that lives in the math table. The names are the same as the names in
820the (English) MATH Info dialog.
821
822Most math constants may also specify device tables (for more on
823:ref:`device tables see below <sfdformat.device-table>`):
824
825::
826
827   MATH:SubscriptShiftDown: 483 {12-17 1,0,0,0,1,1}
828
829
830.. _sfdformat.Outline-Char-Data:
831
832Outline Character Data
833----------------------
834
835Then for non-CID fonts you should find a line like:
836
837::
838
839   BeginChars: 285 253
840
841This means that the font's encoding has room for 285 characters and that there
842are a total of 253 glyphs defined (usually control characters are not defined).
843
844Most encodings entail specific constraints on how many encoding slots must exist
845and how they must be used (which glyphs where, and in what order). That is what
846an encoding means. For instance, in the UnicodeBmp encoding, there must be at
847least 65536 slots numbered 0 to 65535 for the Unicode characters U+0000 to
848U+FFFF. Glyphs with Unicode code points in that range must be encoded in those
849slots in order according to their code points. Glyphs without Unicode code
850points must be encoded in additional slots numbered consecutively starting from
85165536. A file with a BeginChars: line inconsistent with its encoding or
852inconsistent with the number of glyphs it actually contains is not an SFD file.
853FontForge may, but does not promise to, treat attempts to load invalid files as
854fatal errors, or renumber or reorder glyphs to make them match the requirements
855of the encoding. Consider using "Custom" or "Original" encodings if the
856requirements of other encodings are not appropriate; these encodings are less
857restrictive than the others.
858
859A character looks like:
860
861::
862
863   StartChar: exclam
864   Encoding: 33 33 3
865   Width: 258
866   Flags:
867   HStem: 736 13<39 155>  -14 88<162 180>
868   VStem: 71 84<49 396>
869   DStem2: 510 435 225 423 0.568682 -0.822558<0 124.816>
870   Fore
871   SplineSet
872   195 742 m 0
873    195 738 193 736 189 736 c 0
874    175 736 155 743 155 682 c 0
875    155 661 130 249 130 131 c 0
876    130 100 96 99 96 131 c 0
877    96 149 71 662 71 682 c 0
878    71 731 51 736 37 736 c 0
879    33 736 31 738 31 742 c 0
880    31 748 36 747 38 749 c 1
881    188 749 l 1
882    190 747 195 748 195 742 c 0
883   80 32 m 0
884    81 53 95 75 116 74 c 0
885    137 73 150 53 150 32 c 0
886    150 10 137 -14 115 -14 c 0
887    93 -14 79 10 80 32 c 0
888   EndSplineSet
889   EndChar
890
891The first line names the character. If you are using a non-standard glyph
892namelist with utf8 names rather than ASCII names, the name will be UTF7 encoded
893and included in quotation marks. The next line gives the encoding, first in the
894current font, then in unicode, and finally the original position (GID). Then the
895advance width.
896
897Then a set of flags (there are currently five flags: "H" => the character has
898been changed since last hinted, "M" the character's hints have been adjusted
899manually, "W" the width has been set explicitly, "O" => the character was open
900when last saved, and "I" the character's instructions are out of date).
901
902Then horizontal and vertical (postscript) stem hints (set of several two number
903pairs, the first number in the pair is the location of the stem, the next number
904is the width of the stem, the numbers in brokets (<>) indicate where the hint is
905valid).
906
907Diagonal stems (DStem2) are more complex. There are 6 numbers, in 3 pairs of
908two. The first pair represents a point on the left side of the hint, the second
909pair a point on the right and the third pair is a unit vector in the hint
910direction. Again there are numbers in brokets indicating where the hint is
911valid.
912
913For fonts with vertical metrics there may also be a
914
915::
916
917   VWidth: 1000
918
919specifying the vertical advance width.
920
921.. _sfdformat.splineset:
922
923The entry ``Fore`` starts the foreground splines, they are encoded as postscript
924commands with moveto abbreviated to m, curveto to c and lineto to l (lower case
925el). The digit after after the letter is a set of flags whose bits have the
926following meanings:
927
928.. object:: 0x3
929
930   indicates whether the point is curve (0), corner (1) or tangent (2).
931
932.. object:: 0x4
933
934   point selected
935
936.. object:: 0x8
937
938   point has default next control point
939
940.. object:: 0x10
941
942   point has default prev control point
943
944.. object:: 0x20
945
946   point is to be rounded in x (truetype hinting. doesn't really work)
947
948.. object:: 0x40
949
950   point is to be rounded in y (truetype hinting. doesn't really work)
951
952.. object:: 0x80
953
954   point was interpolated between two control points (when read from a ttf file) and so has no point number of its own
955
956.. object:: 0x100
957
958   point should never be interpolated
959
960.. object:: 0x200
961
962   Any extrema on the preceding spline are marked as acceptable to the validator
963
964
965Splines for a truetype font will have two additional numbers after the flags.
966These are the truetype point numbers for the point itself and for the subsequent
967control point. If the value is -1 then this point has no number.
968
969Splines for a font with hint substitution will have a hint mask after any point
970before which hint substitution occurs,
971
972::
973
974   459 422 m 1xc0
975    339 442 l 1xa0
976    312 243 l 1
977
978So the first two points have hint masks "xc0" and "xa0", these masks may be
979(almost) arbitrarily long, depending on the number of hints in the glyph. "xc0"
980means that the first two hints are active (0x80 & 0x40) while "xa0" means that
981the first and third are (0x80 and 0x20).
982
983If you have been using
984`Raph Levien's Spiro package <http://www.levien.com/spiro/>`_ you may also have
985a set of Spiro control points. These appear inside the SplineSet list after each
986contour. It is quite possible that some contours will have spiros and that
987others may not.
988
989The following is the lower case 'a' glyph from Raph's
990`Inconsolata font <http://www.levien.com/type/myfonts/inconsolata.html>`_,
991converted into an sfd file.
992
993::
994
995   Fore
996   SplineSet
997   115 467 m 1
998    134.212 486.845 157.062 503.125 182 515 c 0
999    221.656 533.883 266.084 541.787 310 541 c 0
1000    338.088 540.496 366.236 536.384 392.804 527.254 c 0
1001    419.37 518.123 444.305 503.666 464.14 483.772 c 0
1002    483.975 463.879 498.253 438.648 505.793 411.587 c 0
1003    513.333 384.526 514 356.092 514 328 c 2
1004    514 0 l 1
1005    435 0 l 1
1006    435 58 l 1
1007    381.951 14.5264 314.586 -12.708 246 -13 c 0
1008    205.572 -13.1719 164.446 -3.24219 131.088 19.5986 c 0
1009    97.7295 42.4385 73.3516 78.9277 68 119 c 0
1010    64.5488 144.84 68.8574 171.584 79.7275 195.279 c 0
1011    90.5977 218.975 107.824 239.525 128.391 255.545 c 0
1012    169.524 287.585 222.188 301.168 274 307 c 0
1013    321.422 312.338 369.278 312 417 312 c 2
1014    434 312 l 1
1015    434 331 l 2
1016    434 346.261 434.018 361.578 431.955 376.699 c 0
1017    429.892 391.819 425.593 406.762 418 420 c 0
1018    407.035 439.119 389.166 453.909 368.792 462.316 c 0
1019    348.418 470.724 326.037 473.348 304 473 c 0
1020    272.076 472.496 240.025 466.302 211 453 c 0
1021    190.445 443.58 171.617 430.351 156 414 c 1
1022    115 467 l 1
1023     Spiro
1024       115 467 v
1025       182 515 o
1026       310 541 o
1027       514 328 [
1028       514 0 v
1029       435 0 v
1030       435 58 v
1031       246 -13 o
1032       68 119 o
1033       274 307 o
1034       417 312 [
1035       434 312 v
1036       434 331 ]
1037       418 420 o
1038       304 473 o
1039       211 453 o
1040       156 414 v
1041       0 0 z
1042     EndSpiro
1043   437 248 m 1
1044    418 248 l 2
1045    372.981 248 327.844 249.961 283 246 c 0
1046    248.938 242.992 213.941 235.036 187.152 213.785 c 0
1047    173.758 203.159 162.801 189.275 156.555 173.36 c 0
1048    150.308 157.445 148.943 139.609 153 123 c 0
1049    158.267 101.438 172.606 82.5566 191.107 70.2959 c 0
1050    209.608 58.0342 231.83 52.0508 254 51 c 0
1051    293.532 49.126 333.197 61.8564 366 84 c 0
1052    387.405 98.4502 407.011 116.318 420.258 138.489 c 0
1053    426.881 149.574 431.634 161.775 434.188 174.434 c 0
1054    436.742 187.092 437 200.087 437 213 c 2
1055    437 248 l 1
1056     Spiro
1057       437 248 v
1058       418 248 ]
1059       283 246 o
1060       153 123 o
1061       254 51 o
1062       366 84 ]
1063       437 213 [
1064       0 0 z
1065     EndSpiro
1066   EndSplineSet
1067
1068The spiro data follows Raph's "Plate file" conventions. Each control point has a
1069location (x,y) and a point type. A point type is either:
1070
1071* ``{`` -- May only be on the first control point, indicates that the contour is
1072  open
1073* ``v`` -- Indicates a corner point
1074* ``o`` -- Indicates a G4 curve point
1075* ``c`` -- Indicates a G2 curve point
1076* ``[`` -- Indicates a left point
1077* ``]`` -- Indicates a right point
1078
1079The last spiro should have a point type of ``z``. It is not part of the contour,
1080it merely marks the end of the contour.
1081
1082(Actually this doesn't quite follow Raph's conventions: His plate files have a
1083different coordinate system, and his final ``z`` doesn't have any coordinates).
1084
1085If the glyph should open in spiro mode (displaying spiro control points rather
1086than bezier controls) there will be an "InSpiro" entry
1087
1088::
1089
1090   InSpiro: 1
1091   Flags: HO
1092   Fore
1093
1094A character need not contain any splines:
1095
1096::
1097
1098   StartChar: semicolon
1099   Encoding: 59 59
1100   Width: 264
1101   Flags:
1102   HStem:
1103   VStem:
1104   Fore
1105   Refer: 33 44 N 1 0 0 1 0 0 1
1106   Refer: 35 46 N 1 0 0 1 0 414 2
1107   EndChar
1108
1109Above is one with just references to other characters (a semi-colon is drawn
1110here by drawing a comma and stacking a period on top of it). The first number is
1111the glyph index of the character being refered to (in the current font of
1112course), the next number is the unicode code point, the N says the reference is
1113not selected (An "S" indicates it is selected), the following 6 numbers are a
1114postscript transformation matrix, the one for comma (unicode 44) is the identity
1115matrix, while the one for period (unicode 46) just translates it vertically 414
1116units. The final number is a set of truetype flags:
1117
1118* 1 => Use My Metrics
1119* 2 => Round to Grid
1120* 4 => Position reference by point match (rather than by offset)
1121
1122  If this is set there will be two additional numbers, the first indicating the
1123  point number in the base glyph, and the second the point number in the current
1124  reference.
1125* ::
1126
1127     Ref: 33 44 N 1 0 0 1 0 0 1
1128     Ref: 35 46 N 1 0 0 1 0 414 6 3 7 O
1129* The bottom line indicates that point 3 and point 7 will be positioned together.
1130  The optional "O" is a flag which indicates that this information is out of date.
1131
1132A set of splines in the background is similar, it will be introduced by a
1133``Back`` entry, it may also have spiros.
1134
1135::
1136
1137   Back
1138   SplineSet
1139   195 742 m 0
1140    195 738 193 736 189 736 c 0
1141    175 736 155 743 155 682 c 0
1142   ...
1143   Refer 33 44 N 1 0 0 1 0 0 1
1144
1145While a background image is stored in the following horrible format:
1146
1147::
1148
1149   StartChar: A
1150   ...
1151   Back
1152   Image: 167 301 0 21 2 1 23 753 2.53892 2.53892
1153   J:N0SYd"0-qu?]szzz!!#7`s7cQozzz!!!!(s8Viozzzz"98E!zzzz!!3-"rVuouzzz!!!'"
1154   s8N'!zzz!!!!$s8W,7zzzz"98E$huE`WzJ+s!Dz!"],0s6p!g!!!!"s8W-!n,NFg!!!Q0s8Vio
1155   z5QCc`s82is!!!!`s8W,gz!WW3"s8W&uzJ,fQKp](9o!!iQ(s8W-!z!<<*!s7cQo!!",@s8W-!
1156   ...
1157   EndImage
1158   EndChar
1159
1160Where the numbers on the image line mean respectively: width (of image in
1161pixels), height, image type (0=>mono, 1=>indexed, 2=>rgb (true color), 3=>rgba),
1162bytes per line, number of color entries in the color table, the index in the
1163color table of the transparent color (or for true color images the transparent
1164color itself), the x and y coordinates of the upper left corner of the image,
1165the x and y scale factors to convert image pixels into character units. Then
1166follows a bunch of binary data encoded using Adobe's Encode85 filter (See the
1167PostScript Reference manual for a description). These data contain all the
1168colors in the color table followed by a dump of the image pixel data.
1169
1170Bitmap data will be compressed by run length encoding. I'm not going to go into
1171that in detail, if you want to understand it I suggest you look at the file
1172sfd.c and search for image2rle to see how it is done. The image is compressed
1173using rle and then output as above, only now there is one more parameter on the
1174"Image:" line which gives the number of bytes to be read from the data stream.
1175
1176In multilayered fonts the foreground layers may contain images too. They are
1177stored in the same way.
1178
1179If a glyph has extra layers beyond foreground and background they are introduced
1180with
1181
1182::
1183
1184   Layer: 2
1185   SplineSet
1186   ...
1187
1188A postscript glyph may also contain countermasks:
1189
1190::
1191
1192   StartChar: m
1193   Encoding: 109 109 77
1194   Width: 785
1195   HStem: 0 18<28 224 292 488 566 752> 445 27<280 296 542 558>
1196   VStem: 98 56<45 376> 362 56<45 378> 626 56<45 378>
1197   CounterMasks: 1 38
1198   ...
1199   EndChar
1200
1201The CounterMasks line in this example declares one counter group (first
1202argument). The "38" (and any other values following it) is a bitmask, given in
1203hex, that describes a group. The size of the bitmask is always a multiple of
1204eight (i.e. always an even number of hex digits). The highest-order bit in the
1205mask specifies whether the first stem hint is present (1) or absent (0) in the
1206counter group. The second-highest-order bit does the same for the second hint,
1207and so on. Any extra low-order bits not corresponding to any hint are ignored.
1208(I know, starting from the high bit instead of the low bit seems strange, but
1209that was Adobe's design decision.) Here, the third (0x20), fourth (0x10) and
1210fifth (0x08) stem hints (i.e. the three vertical stems) are in the group,
1211yielding a counter mask of 0x38. If we were to add four more VStem hints to the
1212glyph, making nine hints in all, then the mask would have to be given as 0x3800
1213(because two bytes are needed to accommodate nine bits).
1214
1215Glyphs in quadratic fonts (truetype) may containing truetype instructions, these
1216may be output in two formats, either an text format or an old binary format:
1217
1218::
1219
1220   TtInstrs:
1221   NPUSHB
1222    4
1223    251
1224    0
1225    6
1226    251
1227   MDAP[rnd]
1228   MDRP[rnd,grey]
1229   MDRP[rp0,rnd,grey]
1230   ...
1231
1232As with the 'prep' table above this is simply a list of truetype instruction
1233names as used by FontForge (see ttfinstrs.c for a table of these).
1234
1235An older format is simply a binary dump in ASCII85 encoding. (Note that these
1236are distinguished by the initial keyword ``TtInstrs`` vs. ``Tt\ *f*Instrs``)
1237
1238::
1239
1240   TtfInstrs: 107
1241   5Xtqo&gTLA(_S)TQj!Kq"UP8<!<rr:&$QcW!"K,K&kWe?(^pl]#mUY<!s\f7"U>G:!%\s-3WRec
1242   $pP.r$uZOWNsl$t"H>'?EW%CM&Cer:&f3P>eEnad5<Qq=rQYuk3AE2g>q7E*
1243   EndTtf
1244
1245This is 107 bytes of ASCII85Encode [#ascii85]_ encoded binary data.
1246
1247If the character contains Anchor Points these will be included:
1248
1249::
1250
1251   AnchorPoint: "bottom" 780 -60 basechar 0
1252   AnchorPoint: "top" 803 1487 basechar 0
1253
1254the point names the anchor class it belongs to (in UTF-7), its location, what
1255type of point it is (basechar, mark, baselig, basemark, entry, exit), and for
1256ligatures a number indicating which ligature component it refers to. You may
1257also see:
1258
1259::
1260
1261   AnchorPoint: "bottom" 780 -60 basechar 0 {12-13 -1,-1} {8-14 1,0,-1,-1,-2,-2,-2}
1262
1263.. _sfdformat.device-table:
1264
1265Where the items in braces are horizontal/vertical device tables. The first
1266indicates that the (horizontal) device table applies to pixel sizes 12 through
126713 with pixel adjustments of -1 pixel each. The second indicates a vertical
1268device table applies to pixel sizes 8 through 14 with pixel adjustments of 1, 0,
1269-1, -1, -2, -2, -2 pixels.
1270
1271Finally a TrueType font may position an anchor point based on a normal point
1272within the glyph (if this is done a device table may not be present).
1273
1274::
1275
1276   AnchorPoint: "bottom" 780 -60 basechar 0 23
1277
1278Indicates that this anchor point will be positioned at the same location (which
1279is normally 780,-60 but which might be moved by an instruction) as truetype
1280point 23.
1281
1282If the user has set the glyph class
1283
1284::
1285
1286   GlyphClass: 2
1287
1288Where the number is 1 more than the 'GDEF' glyph class it represents. (so the 2
1289above means a base glyph (class 1)).
1290
1291If a glyph has multiple unicode encodings (the glyph for latin "A" might be used
1292for greek "Alpha"), or is specified by variation selector then alternative
1293unicode information will be provided:
1294
1295::
1296
1297   AltUni2: 000061.00fe01.0
1298
1299Where the first number in the dotted triple is the alternate unicode code point
1300(in hex), the next number is the variation selector (or ffffffff), and the last
1301number is reserved for future use (and must currently be 0). There may be more
1302than one triple on the line.
1303
1304If the character is the first in any kern pairs (not a pair defined by a kern
1305class, however)
1306
1307::
1308
1309   Kerns2: 60 -100 "Kern Latin" {12-13 -1,-1} 63 -92 "Kern Latin" 70 -123 "Kern Latin" 45 -107 "Kern Latin" 76 -107 "Kern Latin"
1310
1311Where each kern pair is represented by 2 numbers and a lookup subtable (and an
1312optional :ref:`device <sfdformat.device-table>` table, see above). The first is
1313the original position of the second character (in the current font), the next is
1314the horizontal kerning amount, then the lookup subtable name. Then we start over
1315with the next kernpair.
1316
1317Data that are to go into other GPOS, GSUB or GDEF sub-tables are stored like
1318this:
1319
1320::
1321
1322   Position2: "Inferiors" dx=0 dy=-900 dh=0 dv=0
1323   PairPos2: "Distances" B dx=0 dy=0 dh=0 dv=0  dx=-10 dy=0 dh=0 dv=0
1324   Ligature2: "Latin Ligatures" one slash four
1325   Substitution2: "Latin Smallcaps" agrave.sc
1326   AlternateSubs2: "Latin Swash" glyph490 A.swash
1327   MultipleSubs2: "Latin Decomposition" a grave
1328   LCarets2: 1 650
1329
1330In most of these lines the first string is the lookup subtable name (except for
1331LCarets where there is nothing). A simple position change is expressed by the
1332amount of movement of the glyph and of the glyph's advance width. A pairwise
1333positioning controls the positioning of two adjacent glyphs (kerning is a
1334special case of this). A ligature contains the names of the characters that make
1335it up. A simple substitution contains the name of the character that it will
1336become. An alternate sub contains the list of characters that the user may
1337choose from. A multiple substitution contains the characters the current glyph
1338is to be decomposed into. A ligature caret contains a count of the number of
1339carets defined, and a list of the locations of those carets.
1340
1341Some glyphs may have python data:
1342
1343::
1344
1345   PickledData: "I3
1346   ."
1347
1348This is arbetrary python pickled data (protocol=0) which got set by a python
1349script. FontForge stores it as a string. If there are either double quotes or
1350backslashes inside the string they will be preceded by a backslash.
1351
1352A glyph may also have
1353
1354::
1355
1356   Comment: Hi
1357   Colour: ff0000
1358   Validated: 1
1359   UnlinkRmOvrlpSave: 1
1360
1361The first is an arbitrary comment, this will be output in UTF-7, the second a
1362color (output as a 6 hex digit RGB value), the cached validation state (a
1363bitmask, see the python docs for the bits' meanings, there can be one of these
1364for every layer), and a flag that the glyph should have its references unlinked
1365and remove overlap run before the font is saved.
1366
1367
1368TeX & MATH data
1369^^^^^^^^^^^^^^^
1370
1371A line like
1372
1373::
1374
1375   TEX: 0 425
1376
1377Specifies the tfm height and depth of a glyph.
1378
1379::
1380
1381   ItalicCorrection: 50
1382   TopAccentHorizontal: 400
1383   IsExtendedShape: 1
1384   GlyphVariantsVertical: parenleft.big parenleft.bigger parenleft.biggest
1385   GlyphConstructionVertical: 3  uni239D%0,0,300,4733 uni239C%1,2500,2500,2501 uni239B%0,300,0,4733
1386   TopRightVertex: 2 0,0{13-15 1,0,1} 100,10
1387
1388Specifies the Italic Correction (either from a tfm file or the MATH table).
1389Italic Correction may also include a device table.
1390
1391Specifies the horizontal placement of top accents in mathmatical typesetting.
1392This may also include a device table.
1393
1394Specifies the current glyph is an extended shape (and therefore may need special
1395superscript positioning).
1396
1397For both glyph variants and construction the word "Vertical" may be replaced
1398with Horizontal for glyphs that grow horizontally.
1399
1400The first number in GlyphConstruction is the number of components. Each
1401component is represented by a glyphname, followed by "%", followed by an
1402indication of whether this is an extender, followed by the start overlap length,
1403the end overlap length and the full length.
1404
1405Math Kerning info may be specified for each vertex of the glyph (TopRight,
1406TopLeft, BottomRight, BottomLeft). First is a count of the number of points,
1407then the height, kerning pairs for each. Device tables are permitted and may
1408follow directly after either the height or the kerning value.
1409
1410
1411Outline character extensions for multilayered fonts (type3)
1412^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1413
1414Instead of having a single "Fore"ground layer, multilayered type3 fonts have
1415(potentially) several layers, each one introduced by a Layer line which
1416specifies things like filling and stroking info for this layer. Then within each
1417layer you may find a splineset, a list of references and a list of images (any
1418or all may be omitted). The syntax for these is the same as in the normal case
1419above.
1420
1421::
1422
1423   LayerCount: 3
1424   Layer: 1  1 1 1  #fffffffe 1  #fffffffe 1 40 round round [1 0 0 1] []
1425   FillGradient: 220;260 490;450 0 pad 2 {0 #808080 1} {1 #000000 1}
1426   SplineSet
1427   ...
1428   EndSplineSet
1429   Layer: 2  1 0 1  #00ff00 1  #0000ff 1 19 miter butt [0.5 0 0 1] [10 5]
1430   FillGradient: 400;400 400;400 400 repeat 2 {0 #ffffff 1} {1 #808080 1}
1431   SplineSet
1432   ...
1433   EndSplineSet
1434   Layer: 3  1 0 1  #00ff00 1  #0000ff 1 19 miter butt [0.5 0 0 1] [10 5]
1435   FillPattern: E 200;200 [0.707 0.707 -0.707 0.707 0 0]
1436   SplineSet
1437   ...
1438   EndSplineSet
1439
1440The LayerCount line gives the number of layers in the glyph (the background
1441layer is layer 0, so this number is one more than the number of layers that will
1442actually be specified -- the background layer is still specified the way it was
1443before, but is included in this count). This line is not required, if omitted
1444(or wrong) FontForge will figure that out.
1445
1446The Layer line contains too much information. First is a number saying which
1447layer, next are three booleans, the first specifies whether to fill the
1448splineset (or use an imagemask for images), the second whether to stroke the
1449splineset, the third is currently pretty much meaningless. Next follows the RGB
1450value of the fill color (the special value of #fffffffe means the color is
1451inherited), then the opacity (the special value -1 means inherited), then the
1452stroke color and opacity. Then the stroke width (again -1 means inherited), the
1453linejoin type (miter, round, bevel, inherited), the linecap type (butt,
1454round,square,inherited), the transformation matrix to be applied to the pen and
1455finally the dash array.
1456
1457Any SplineSet, Ref, Images between this Layer and the next (or the end of the
1458character) are part of this layer.
1459
1460The FillGradient lines allow you to specify linear or radial gradient fills (or
1461StrokeGradient lets you specify a gradient for the strokes). It is followed by
1462two points, the start and end points of a linear gradient, the focus and center
1463of a radial gradient. Then a radius (if this is 0 then we have a linear
1464gradient, otherwise a radial one). A keyword which specifies how the gradient
1465should behave outside the region specified by the start and end points. Finally
1466there is a number which gives the number of "stop-points". Each stop point is in
1467curly braces and contains three numbers, one between 0 and 1 (indicating the
1468location from the start of the gradient to it's end), one a hex colour, and one
1469the opacity, also between 0 and 1.
1470
1471The FillPattern line allows you to specify a pattern tiled instead of more
1472traditional single colour fills (or StrokePattern lets you specify a pattern for
1473the strokes). It is followed by the name of a glyph (which contains the
1474pattern), the size of the pattern (width, height) in the current coordinate
1475system (so the pattern glyph will be scaled until it is this size). And a
1476transformation matrix to be applied after the pattern has been tiled across the
1477plain (the one here rotates the tiles by 45 degrees).
1478
1479If a glyph is used as a tile it may have one of the following additional
1480keywords:
1481
1482::
1483
1484   TileMargin: 20
1485   TileBounds: -20 -220 1020 820
1486
1487If neither of these is specified the tile's size will be its bounding box. If
1488TileBounds is specified, the size is taken from the box information specified
1489there (minx, miny, maxx, maxy). If TileMargin is specified then the bounding box
1490will be extended by this amount (to provide a whitespace margin around the
1491tile).
1492
1493Inside a SplineSet a contour may be modified by a PathFlags keyword (output
1494after the contour has been completed). Currently there is only one flag (1)
1495which indicates the that contour is part of the cliping path of the glyph.
1496
1497::
1498
1499   SplineSet
1500   102 699 m 5
1501    1176 699 l 5
1502    1176 -120 l 5
1503    102 -120 l 5
1504    102 699 l 5
1505     PathFlags: 1
1506   EndSplineSet
1507
1508
1509.. _sfdformat.Bitmap-Fonts:
1510
1511Bitmap Fonts
1512------------
1513
1514After all the outline characters have been described there is an EndChars entry
1515and then follow any bitmap fonts:
1516
1517::
1518
1519   EndChars
1520   BitmapFont: 12 285 10 2 1
1521   BDFStartProperties: 2
1522   COMMENT 0 "This is a bdf comment property"
1523   FONT_DESCENT 18 2
1524   BDFEndProperties
1525   Resolution: 75
1526   BDFChar: 32 3 0 0 0 0
1527   z
1528   BDFChar: 3 33 3 0 1 0 9
1529   ^d(.M5X7S"!'gMa
1530   BDFRefChar: 302 488 7 1 N
1531   BDFRefChar: 302 58 0 0 N
1532
1533The bitmap font line contains the following numbers: the pixelsize of the font,
1534the number of potential characters in the font, the ascent and the descent of
1535the font and the depth of font (number of bits in a pixel).
1536
1537Optionally there may be a set of BDF properties. If there are any properties
1538there will be a line "BDFStartProperties:" with a count of properties. There
1539should be that many property lines, and then a "BDFEndProperties" line. Each
1540property is of the form:
1541
1542``<NAME> <TYPE> <VALUE>``
1543
1544Where <NAME> is the property name, <TYPE> is 0 for a string, 1 for an atom, 2
1545for an int, 3 for an unsigned int. In addition <TYPE> may have a 16 ored to one
1546of the above values indicating the line is a true property (rather than
1547information from somewhere else in the BDF header). <VALUE> will either be a
1548quoted string or an integer.
1549
1550Optionally there may be a resolution line, which specifies the design resolution
1551of the font.
1552
1553This is followed by a list of bitmap characters, the bitmap character line
1554contains the following numbers: the original position (glyph ID), the encoding
1555(local), the width, the minimum x value, the minimum y value, the maximum x
1556value and the maximum y value. If the bitmap font has vertical metrics there
1557will also be a vwidth. This is followed by another set of binary data encoded as
1558above. There will be (ymax-ymin+1)* ((xmax-xmin)/(8/depth)+1) (unencoded) bytes,
1559there is no color table here (the high order bit comes first in the image, set
1560bits should be colored black, clear bits transparent).
1561
1562If there are any bitmap glyphs with bitmap references then these will appear
1563near the end of the bitmap strike. Each ``BDFRefChar`` line defines a reference,
1564the first number is the glyph ID of the composite glyph, the second the glyph ID
1565of the referred glyph, and the last two the horizontal and vertical translation
1566of the reference in the composite glyph.
1567
1568A bitmap font is ended by:
1569
1570::
1571
1572   EndBitmapFont
1573   BitmapFont: 17 285 14 3 1
1574   BDFChar: 0 17 0 0 0 0
1575   z
1576   ...
1577   EndBitmapFont
1578   EndSplineFont
1579
1580
1581.. _sfdformat.CID-keyed-fonts:
1582
1583CID keyed fonts
1584^^^^^^^^^^^^^^^
1585
1586A CID font is saved slighlty differently. It begins with the normal font header
1587which contains the information in the top level CID font dictionary. As
1588mentioned above this will include special keys that specify the CID charset
1589(registry, ordering, supplement). It will also include:
1590
1591::
1592
1593   CIDVersion: 2.0
1594   BeginSubFonts: 5 8318
1595
1596The ``CIDVersion`` is self-explanatory. The ``BeginSubFonts`` line says that
1597there are 5 subfonts the largest of which contains slots for 8318 characters
1598(again some of these may not be defined). This will be followed by a list of the
1599subfonts (dumped out just like normal fonts) and their characters. Only the top
1600level font will contain any bitmap characters, anchor classes, etc.
1601
1602
1603.. _sfdformat.Multiple-Master-fonts:
1604
1605Multiple Master fonts
1606^^^^^^^^^^^^^^^^^^^^^
1607
1608Multiple master fonts start with a different style of file header, and are
1609followed by a set of sub fonts. If the mm font has 4 instances then there will
1610be 5 subfonts (one for each instance, and one for the blended font). The font
1611header looks like:
1612
1613::
1614
1615   SplineFontDB: 1.0
1616   MMCounts: 4 2 0 0
1617   MMAxis: Weight Width
1618   MMPositions: 0 0 1 0 0 1 1 1
1619   MMWeights: 0.31502 0.13499 0.38499 0.16499
1620   MMAxisMap: 0 2 0=>50 1=>1450
1621   MMAxisMap: 1 2 0=>50 1=>1450
1622   MMCDV:
1623   {
1624   1 index 1 2 index sub mul 3 1 roll
1625   1 2 index sub 1 index mul 3 1 roll
1626   1 index 1 index mul 3 1 roll
1627   pop pop
1628   0 1 1 3 {index add} for 1 exch sub 4 1 roll
1629   }
1630   EndMMSubroutine
1631   MMNDV:
1632   {
1633   exch 50 sub 1400 div
1634   exch 50 sub 1400 div
1635   }
1636   EndMMSubroutine
1637   BeginMMFonts: 5 0
1638
1639The "MMCounts" line gives the number of instances (4) and the number of axes (2)
1640in this font also whether it is an apple distortable font (0) and if so the
1641number of named styles (0) in that font. The "MMAxis" line gives the names of
1642the axes. The MMPositions line is an array of real numbers (with
1643instance_count*axis_count elements) describing the coordinates of each instance
1644along each axis. The MMWeights line provides the weights (blends) of the
1645instance fonts to which, when interpolated, yield the default font. There will
1646be one AxisMap line for each axis, it provides the mapping from design space to
1647normalized space. The first line
1648
1649::
1650
1651   MMAxisMap: 0 2 0=>50 1=>1450
1652
1653says that axis 0 has two mapping points. One is at normalized position 0 and
1654corresponds to design position 50, the other is at normalized position 1 and
1655corresponds to design position 1450. There are two subroutines stored here, both
1656are simple postscript. The first is the /NormalizeDesignVector routine and the
1657second is the /ConvertDesignVector routine.
1658
1659Finally we have the actual instance fonts.
1660
1661--------------------------------------------------------------------------------
1662
1663Fonts with information for Apple's '\*var' tables ('fvar', 'gvar', 'avar' and
1664'cvar') have a slightly different format:
1665
1666::
1667
1668   MMCounts: 8 2 1 10
1669   MMAxis: Weight Width
1670   MMPositions: 1 0 -1 0 0 1 0 -1 -1 -1 1 -1 1 1 -1 1
1671   MMWeights: 0 0 0 0 0 0 0 0
1672   MMAxisMap: 0 3 -1=>0.479996 0=>1 1=>3.2
1673   MacName: 0 0 6 "Weight"
1674   MacName: 0 1 15 "Type de graisse"
1675   ...
1676   MMAxisMap: 1 3 -1=>0.619995 0=>1 1=>1.3
1677   MacName: 0 0 5 "Width"
1678   MacName: 0 1 7 "Largeur"
1679   ...
1680   MMNamedInstance: 0  3.2 1
1681   MacName: 0 0 5 "Black"
1682   MacName: 0 1 9 "Tr\217s gras"
1683   ...
1684
1685In Adobe's format coordinates range between [0,1], while in Apple's format they
1686range [-1,1]. Adobe generally specifies 2 instances per axis (at the extrema)
1687while Apple expects 3 (the extrema and the default setting at 0). So a two axis
1688font for Adobe will normally contain 4 instances and a default version, while
1689one for Apple will contain 8 instances and a default version. The MMWeights
1690field is irrelevant for Apple. Each axis has a set of names, for that axis
1691translated into various languages. Finally Apple allows certain points in design
1692space to be given names, here the point Weight=3.2, Width=1 is named "Black" or
1693"Trés gras".
1694
1695
1696.. _sfdformat.sfdir:
1697
1698SplineFont Directories
1699----------------------
1700
1701In late 2006 some people wanted a font format where each glyph was stored in a
1702single file (to give version control systems a finer granularity and reduce the
1703amount of stuff to download after changes). I have extended the format slightly
1704by creating what I call SplineFont Directories. These are basically sfd files
1705split up into little bits in directories with an extension of ".sfdir". The
1706directory contains the following:
1707
1708* A file ``font.props`` which contains the
1709  :ref:`font header <sfdformat.Font-Header>` and includes everything up to (but
1710  not including) the ``BeginChars`` line
1711* For non-CID-keyed fonts the directory will contain one file for each glyph in
1712  the font, these files will be named ``\ *<glyph-name>*.glyph`` and will be in
1713  the format specified for :ref:`outline data <sfdformat.Outline-Char-Data>`.
1714* If the font contains any bitmap strikes then there will be subdirectories named
1715  ``\ *<pixel-size>*.strike``. And these directories will contain a
1716  ``strike.props`` file and one file per glyph in the strike, these files named
1717  ``\ * <glyph-name>*.bitmap``. The ``strike.props`` file will contan the bitmap
1718  header and bdf properties, while the ``*.bitmap`` files will contain the
1719  per-glyph bitmap data. These will be in the format described in the section on
1720  :ref:`bitmaps <sfdformat.Bitmap-Fonts>`.
1721* For CID-keyed fonts there will be subdirectories named
1722  ``\ *<subfontname>*.subfont``, each subfont will contain its own ``font.props``
1723  file and its own set of glyph files.
1724* For Multiple Master fonts there will be subdirectories named
1725  ``\ *<instancename>*.instance``
1726
1727
1728.. _sfdformat.Autosave-Format:
1729
1730Autosave Format
1731---------------
1732
1733:doc:`Error recovery </appendices/errrecovery>` files are saved in ~/.FontForge/autosave,
1734they have quite random looking names and end in .asfd. They look very similar to
1735.sfd files above.
1736
1737If an asfd file starts with a line:
1738
1739::
1740
1741   Base: /home/gww/myfonts/fontforge/Ambrosia.sfd
1742
1743Then it is assumed to be a list of changes applied to that file (which may be an
1744sfd file or a font file). If it does not start with a "\ ``Base:``" line then it
1745is assumed to be a new font. The next line contains the encoding, as above. The
1746next line is a ``BeginChars`` line. The number given on the line is not the
1747number of characters in the file, but is the maximum number that could appear in
1748the font. Then follows a list of all changed characters in the font (in the
1749format described above).
1750
1751Bitmaps are not preserved. Grid changes are not preserved.
1752
1753
1754.. rubric:: Footnotes
1755
1756.. [#sfdext]
1757
1758   **The SFD extension**
1759
1760   Yes, I know it stands for sub-file directory on the dear old PDP-10s.
1761
1762   But they aren't really around any more, so I'll reuse it. And probably nobody
1763   else remembers them...
1764
1765   Oh, it's also used by TeX for Sub Font Definition files (see ttf2afm).
1766
1767.. [#ascii85]
1768
1769   **ASCII85Encode**
1770
1771   An encoding which takes 4 binary bytes and converts them
1772   to 5 ASCII characters between '!' and 'u'. Suppose we have 4 binary bytes: (b1
1773   b2 b3 b4) then we want to find (c1 c2 c3 c4 c5) such that:
1774
1775   ::
1776
1777      b1 * 2563  +  b2 * 2562  +  b3 * 256  +  b4 =
1778         c1 * 854  +  c2 * 853  +  c3 * 852  +  c4 * 85  +  c5
1779
1780   The final output is obtained by adding 33 ('!') to each of the c\ :sub:`i`. If
1781   all four bytes are 0, then rather than writing '!!!!!', the letter 'z' may be
1782   used instead.
1783
1784   Unfortunately, not all streams of binary data have a length divisible by 4. So
1785   at the end of the run, assume there are *n* bytes left over. Append *4-n* zero
1786   bytes to the data stream, and apply the above transformation (without the 'z'
1787   special case for all zeros), and output *n+1* of the c\ :sub:`i` bytes.
1788
1789   So to encode a single 0 byte we would:
1790
1791   * append 3 additional 0 bytes (n==1 => add 4-1=3 bytes)
1792   * find that all the c\ :sub:`i` were also zero
1793   * add '!' to each (all are now '!')
1794   * output two '!' (n+1 = 2)
1795