Debian Codegraph @

doc/sphinx/index.rst

raw
1 FontForge Documentation
2 =======================
3
4 FontForge allows you to create and modify postscript, truetype and opentype
5 fonts. You can save fonts in many different outline formats, and generate
6 bitmaps.
7
8 .. epigraph::
9
10 Eeyore had three sticks on the ground, and was looking at them. Two of the
11 sticks were touching at one end, but not at the other, and the third stick
12 was laid across them. Piglet thought that perhaps it was a Trap of some
13 kind.
14
15 | "Oh, Eeyore," he began again, "just ---"
16 | "Is that little Piglet?" said Eeyore, still looking hard at his sticks.
17 | "Yes, Eeyore, and I---"
18 | "Do you know what this is?"
19 | "No," said Piglet.
20 | "It's an A."
21 | "Oh," said Piglet.
22 | "Not O, A," said Eeyore severely.
23
24 -- *The House At Pooh Corner* -- A. A. Milne, 1928
25
26 Font design can be a Trap, but I find it a rather pleasant one. *Caveat utor*.
27
28
29 .. toctree::
30 :maxdepth: 4
31 :hidden:
32 :includehidden:
33
34 tutorial
35 ui
36 scripting/scripting
37 techref
38 fontutils
39 faq
40 appendices
41 glossary
42
43 Indices and tables
44 ------------------
45
46 * :ref:`genindex`
47 * :ref:`modindex`
48 * :ref:`search`
49
50
51 Er... What is a font editor?
52 ----------------------------
53
54 A font editor is a program designed to create and modify fonts.
55
56 The most obvious aspect is that it is a drawing program like FreeHand, Inkscape
57 or Illustrator which lets you draw the outlines of your letters. Unlike other
58 drawing programs it expects you to draw many pictures at once (one or more for
59 each letter) and collects them into a database.
60
61 It allows you to describe the way these pictures interact with each other (if
62 you put one picture after the other then they should normally be separated by a
63 certain distance -- the font's metrics, or if these two pictures are placed
64 adjacent to one another then they turn into a third -- the font's ligatures, and
65 so on).
66
67 Finally a font editor will bundle up all the pictures you have drawn, and all
68 the metadata about how those pictures fit together, and will turn that bundle of
69 stuff into a font that your computer can use to display text.
70
71
72 .. _overview.intro:
73
74 Introductory concepts: Fonts, Splines, Lines, Points, Paths and the em-unit
75 ---------------------------------------------------------------------------
76
77 Most simply a font is a collection of glyphs. But computer fonts must contain
78 more than this, at the least they must also contain information on how to map an
79 input string of bytes into an output display of visual glyphs. This mapping is
80 called an encoding. Many fonts will also contain rules for how adjacent glyphs
81 should be arranged. For instance, in fonts for the latin alphabet, there is
82 often a rule saying that if "f" and "i" are adjacent then a special glyph, a
83 ligature of "f" and "i" should be used instead. Fonts for latin letters
84 generally do not require such rules (but can be enhanced by them), fonts for
85 other scripts like arabic require them.
86
87
88 What's the difference between a character and a glyph?
89 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90
91 A character is a concept and a glyph is a reification of that concept. The
92 letter "A" is a character, while |As| are all glyphs that represent an "A".
93 In latin fonts there is often a single glyph for every character and a single
94 character for every glyph, but not always -- in renaissance printing there were
95 two glyphs for a lower-case s, |short-long-s| the short and the long s. Whereas
96 a ligature is an example of a glyph that represents two (or more) characters.
97 In arabic most of the letters (characters) have at least four different glyphs,
98 the appropriate glyph being determined by the letters around it. Here are four
99 forms of the arabic character "seen" |arabic-seen|.
100
101 .. |As| image:: /images/As.png
102 .. |short-long-s| image:: /images/short-long-s.png
103 .. |arabic-seen| image:: /images/arabic-seen.png
104
105
106 What is an outline font? What is a bitmap font?
107 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108
109 Each glyph in a font has a shape and there are various ways of describing that
110 shape on a computer. PostScript and truetype fonts generally describe the
111 outline of the shape and then color in the interior of that outline, this
112 coloring process is called rasterizing. On the other hand a bitmap font
113 describes each glyph by drawing a picture of that character on a rectangular
114 grid of pixels. There is a third type, a stroked font, where each stem of the
115 glyph is represented by one line down the center of the stem, and the line is
116 later drawn with a certain width. Most of the time we will not deal with stroked
117 fonts directly (the :ref:`Expand Stroke <elementmenu.Expand>` command can be
118 used to turn them into outlines), but if you wish to edit stroked fonts, see the
119 section on :doc:`multi-layered editing </ui/dialogs/multilayer>`.
120
121 .. flex-grid::
122
123 * - .. figure:: /images/outlinechar.png
124
125 A glyph's outline
126 - .. figure:: /images/bitmapchar.png
127
128 A glyph's bitmap
129 - .. figure:: /images/strokechar.png
130
131 A stroked glyph (showing the equiv. outline in grey)
132
133 An outline is composed of a set of contours or paths. In the picture on the
134 above left the letter A is described by three different paths. The main one is
135 on the outside and the two smaller ones are internal. Each of these paths is
136 composed of a series of (Bézier) splines and line segments. FontForge can handle
137 cubic and quadratic splines. PostScript fonts use cubic splines, TrueType fonts
138 use quadratic (SVG fonts can be either).
139
140 .. _overview.spline:
141
142 Each cubic spline is defined by four points, two of which mark the end points of
143 the spline and two more to describe the slope of the spline at those end points.
144 Here are :doc:`two cubic splines </techref/bezier>` with all their points shown:
145
146 .. image:: /images/splines.gif
147 :align: left
148
149 The points which describe the slope are called control points. They are
150 represented here (and in fontforge) by little colored x's. Moving a control
151 point will change the shape of the spline, but it will not alter where the
152 spline begins or ends.
153
154 .. image:: /images/pnts.gif
155 :align: right
156
157 A series of splines and lines are joined together to make a path. There are
158 several possible ways to make these joins as is shown in the example to the
159 right. In each case we have three points in approximately the same relative
160 positions. The three points are joined by splines or lines, but the type of
161 joins alters the appearance of the connections.
162
163 In the first case there are no control points and the result is two straight
164 lines, in the second case there is a line and a curved spline which are tangent
165 at their point of intersection, in the third case there are two splines which
166 are again tangent at their point of intersection. The point of intersection in
167 the first case is called a corner point, and the incoming and outgoing splines
168 or lines may be in any orientation with respect to each other. This is
169 represented in fontforge by a square box. In the second case the point of
170 intersection is called a tangent point, it is represented by a triangle. The
171 third case is a curved point and is represented by a circle.
172
173 .. _overview.quadratic:
174
175 .. image:: /images/quadraticspline.gif
176 :align: left
177
178 FontForge can also edit quadratic splines (the splines used in truetype fonts),
179 here there is only one control point and it controls the slopes at both
180 end-points. Because of this quadratic splines cannot bend in as many ways as
181 cubic splines (the first spline above left would need at least two quadratic
182 splines to draw), and you will often need more splines to achieve the same
183 curve. You can control whether a font contains cubic or quadratic splines with
184 the :ref:`Element->Font Info <fontinfo.PS-General>` command.
185
186 There are many different types of splines in the world. The ones described above
187 are Béziers -- these are numerically simple and have a number of nice properties
188 -- which is why they are used internally in fonts. However, there are some even
189 nicer splines. It is easy to give Bézier splines the same slope on either side
190 of a point, but a curve will look much nicer if it has the same curvature on
191 either side of a point. Clothoid splines have this property.
192
193 `Raph Levien <http://www.levien.com/>`__ has kindly donated to the open source
194 community a `library <http://libspiro.sf.net/>`__ for converting clothoid
195 splines into Béziers.
196
197 Clothoid splines are much easier to work with than Béziers -- there are no
198 control points, just a sequence of on-curve points, and magically a beautiful
199 curve will appear between them. FontForge can
200 :ref:`either <charview.spiro-mode>` edit a curve as a set of Béziers or as a set
201 of clothoids.
202
203 A path is closed when it comes back and joins its start. All paths in an outline
204 font should be closed. Once a path is closed in may be said to have a direction,
205 essentially this may be thought of as "Was the path created in a clockwise or a
206 counter-clockwise fashion?" (this is actually a little simplistic, if a path
207 intersects itself, as in a figure 8, then the direction cannot be described as
208 either clockwise or counter-clockwise, but most paths do not self-intersect (and
209 paths in a font **SHOULD NOT** self-intersect) and we will simplify our life by
210 pretending that we can call paths clockwise or counter).
211
212 When time comes to draw our outline glyph we want to make dark everything in the
213 interior of the outline. But let's look at the outline of our A above. We have
214 two paths inside the main outline path, and we want the interior of those two
215 paths to be white rather than dark. How do we make this distinction? We do it by
216 the direction of the paths. Consider any point in the glyph. If we draw an
217 imaginary line from that point out to infinity (in any direction) and count the
218 number of times we cross a path, each time we cross a clockwise path we add one
219 to our count, each time we cross a counter clockwise path we subtract one. If
220 the result of our count is non-zero then we color the point dark, otherwise we
221 leave it white. So to make the A above work we make the outer path be clockwise
222 and the two inner ones be counter-clockwise (Things could be done the other way
223 around, but the convention is that the outer path should be clockwise).
224
225 All of these points (both the end points and the control points) are described
226 mathematically. Each point is positioned on a cartesian coordinate system which
227 has its origin on the glyph's :ref:`baseline <overview.Baseline>` (the line on
228 which letters without descenders rest). Most font formats expect coordinates to
229 be integers between -32768 and 32767, FontForge uses real numbers internally but
230 (usually) rounds to the nearest integer when generating a font file.
231
232 Generally it is a good idea to restrict yourself to integral coordinates.
233 TrueType fonts can only contain integral coordinates so if you use a
234 non-integral value FontForge will be forced to round it to an integer and this
235 will alter the shape of the curve. PostScript fonts can contain non-integral
236 values, but the various formats are optimized for integers. So use integers when
237 you can. If you need more precision you can increase the "em-size" of the font.
238
239 .. _overview.em-unit:
240
241 When displaying a font we use the word "em" to represent the size of the font.
242 If a font is displayed at 12points then 1em will be 12points. If the font is
243 displayed at 18points then an em will be 18points. (traditionally a 12 point
244 font is one where the metal slugs are 12 points tall -- or where the baseline to
245 baseline spacing of unleaded text is 12 points, so an em was the size of the
246 metal.).
247
248 When designing an outline font, you can no longer think in terms of points --
249 these fonts are scalable and can be any pointsize. You must think in terms of
250 the em and fractions of the em. When you create a font you choose how many
251 internal units (called "em-units") to use to represent 1 em -- this number is
252 called the "em-size". In most PostScript fonts there are 1000 units to the em,
253 TrueType fonts often have either 1024 or 2048 units to the em (TrueType
254 recommends that you use a power of two). But you can choose any (positive)
255 number you like (well, as long as it is less than 32767), the numbers above are
256 conventions not requirements).
257
258 Suppose you have a dash in a PostScript font, and that dash is 500 units long,
259 and the font has 1000 units to the em. Suppose a someone displays that dash at
260 12 points. Then that dash will be drawn with a length of 500/1000 * 12 = 6
261 points. On a 72 dot per inch screen where a pixel is almost exactly one point,
262 the dash will be 6 pixels long.
263
264 .. image:: /images/sidebearings.png
265 :align: right
266
267 Every glyph has its own coordinate system. The font's
268 :ref:`baseline <overview.Baseline>` (the line upon which most latin glyphs will
269 rest) is 0 in the vertical direction. The horizontal origin is where the glyph
270 will start being drawn (what is "drawn" will usually be empty space for a short
271 while -- as there is usually some space between the origin and the edge of the
272 glyph). This horizontal distance between the origin and the leftmost edge of the
273 glyph is called the left side bearing (it may be negative, positive or zero).
274 All glyphs have a width (sometimes called an advance width), this is the
275 distance from the origin of the current glyph to the origin of the next. The
276 distance between the right edge of the glyph and the width is called the right
277 side bearing.
278
279 CJK text (Chinese, Japanese or Korean) can be written either vertically or
280 horizontally, and so CJK fonts usually have a vertical advance width as well as
281 the more common horizontal advance (and concomittant top and bottom side
282 bearings).
283
284 A glyph like "g" or "y" extends below the baseline, this is called a descender,
285 while a glyph like "k" or "l" extends above the x-height, this is called an
286 ascender. Most latin (and greek and cyrillic) fonts have certain standard
287 heights: the height of a lower case letter (without an ascender) is called the
288 x-height, the height of a capital letter is called the cap-height, the height of
289 the ascenders is called the ascender height (some, but not all, fonts have the
290 ascenders and capitals at the same approximate height). Often these will not be
291 exactly the same for all glyphs, the letter "O" is usually slightly taller than
292 the letter "I", but they both are within the range of the cap height for the
293 font.
294
295 The font itself has an ascent and descent associated with it. In the old days of
296 metal type nothing could ascend above or descend below these values, nowadays
297 accents and ascenders may reach above the font-wide ascent and descenders below
298 the descent, but the concept is still a convenient one to retain. It is true
299 that in almost all cases the glyphs will not ascend above or descend below the
300 font-wide ascent and descent. The sum of the ascent and descent is the size of
301 the font. The point size of a piece of metal type was determined by this value
302 (essentially the height of the metal block holding the glyph). In a postscript
303 font the local coordinate system is independent of the final size at which the
304 font will be drawn.
305
306
307 .. _overview.PT:
308
309 TrueType vs. PostScript vs OpenType vs SVG fonts
310 ------------------------------------------------
311
312 FontForge can produce many font types. What's the difference?
313
314 PostScript is based on a :doc:`cubic spline </techref/bezier>` technology, while TrueType
315 is based on a :doc:`quadratic </techref/bezier>` technology. Cubic splines are generally
316 easier to edit (more shapes are possible with them). Any quadratic spline can be
317 converted to a cubic spline with essentially no loss. A cubic spline can be
318 converted to a quadratic with arbitrary precision, but there will be a slight
319 loss of accuracy in most cases.
320
321 Within FontForge a font may contain either cubic or quadratic splines. These are
322 converted to the appropriate format when a font is generated.
323
324 The other major difference between the two is how they solve the problem of
325 drawing nice images at small pointsizes. PostScript calls this "Hinting", while
326 TrueType calls it "Instructing" a font.
327
328
329 What's OpenType?
330 ^^^^^^^^^^^^^^^^
331
332 Unfortunately the word "OpenType" has come to have several meanings.
333
334 The first meaning describes the glyph (and spline) format of the font. In this
335 sense Open Type is just a postscript font put into a truetype file format --
336 From the outside it looks like a truetype font except that the outline
337 descriptions are postscript Type2 font descriptions rather than TrueType.
338 Technically it is a :term:`CFF` font inside an :term:`sfnt <SFNT>` wrapper.
339
340 In a second sense of the word OpenType refers to a set of tables containing
341 advanced typographic information. These tables may be added to either fonts
342 specified with quadratic splines (truetype) or fonts with cubic splines.
343
344 Finally MS Windows uses an OpenType icon for a font if that font contains a
345 'DSIG' (Digital Signature) table.
346
347 To make things even more confusing the OpenType specification includes the old
348 TrueType specification, so technically any TrueType font can be called an
349 OpenType font.
350
351 FontForge does not support the DSIG table (if you want one there is a free tool
352 from MS which will add one). When generating a font, FontForge uses the term
353 "OpenType (CFF)" to represent a PostScript (CFF) font inside an sfont wrapper.
354 To include OpenType typography tables you would press the ``[Options]`` button
355 and select the ``[] OpenType`` check box.
356
357
358 What's SVG?
359 ^^^^^^^^^^^
360
361 SVG (Scalable Vector Graphics) provides a relatively new font format, written in
362 an xml dialect. SVG fonts can be either cubic or quadratic (or can use both, but
363 FontForge is limited and will force a font to be either all cubic or all
364 quadratic). SVG allows for two different types of fonts, one corresponds roughly
365 to PostScript Type1 fonts, and the other, roughly to PostScript Type3 fonts.
366
367
368 What are Type3 fonts?
369 ^^^^^^^^^^^^^^^^^^^^^
370
371 Back in the early days of PostScript, the Type1 format was proprietary, only
372 Adobe could make Type1 fonts, but anyone could make Type3 fonts. Type3 fonts
373 were unhinted, but could include any postscript command and so could produce a
374 wider range of pictures (multi-colored glyphs, stroked glyphs, glyphs based on
375 scaled images, etc.). Most of the time these extensions are unnecessary, and the
376 disadvantage of being unhinted is onerous -- but sometimes you want to play.
377
378
379 What are Type1 fonts?
380 ^^^^^^^^^^^^^^^^^^^^^
381
382 These were the standard stand-alone PostScript fonts of the '80s and '90s.
383
384
385 What are Type2 fonts?
386 ^^^^^^^^^^^^^^^^^^^^^
387
388 These use a slightly different internal format (a more compact one) to express
389 the same information as type1. This is the format that lives inside a CFF font
390 which lives inside an OpenType font.
391
392
393 What are CFF fonts?
394 ^^^^^^^^^^^^^^^^^^^
395
396 This is the font format that is designed to store PostScript Type2 information.
397 It is most commonly found inside an OpenType (PostScript) font.
398
399
400 What is Apple Advanced Typography?
401 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
402
403 This is another way of specifying typographic information (like ligatures,
404 kerning, glyph substitutions). It appeared before OpenType and is only used on
405 Apple computers. It is based on state machines and is a little harder to work
406 with than OpenType.
407
408
409 .. _overview.Hints:
410
411 Hints
412 -----
413
414 At small pixel sizes, the process of drawing the interior of an outline font is
415 quite difficult to do well. PostScript and TrueType have different approaches to
416 the problem of providing extra information to the rasterizer about how to draw
417 small fonts.
418
419 .. rubric:: Rasterization improvements from hinting TrueType. 18pt font
420 rasterized by Windows (scaled by a factor of 2)
421
422 .. flex-grid::
423 :class: flex-center
424
425 * :flex-widths: 0 0
426
427 - .. figure:: /images/HI.nohints.png
428
429 no hints
430 - .. figure:: /images/HI.hints.png
431
432 hints
433
434 **PostScript**
435
436 Adobe incorporated several different ways of providing hints for the
437 rasterizer about how things should be treated. The most obvious of these are
438 the horizontal and vertical stem hints. Each glyph has its own set of hints
439 to tell the rasterizer where to find stems. FontForge can usually figure out
440 a reasonable set of stem hints (a process called
441 :ref:`autohinting <hintsmenu.AutoHint>`), but some glyphs are too complex for
442 it and it can make bad choices. It also provides a mode for you to override
443 its choices.
444
445 Adobe also has a mechanism for handling dished serifs called flex hinting.
446 This means a curve that is only slightly deformed from the horizontal (or
447 vertical) will display as a line at small point sizes and as a curve at
448 larger ones. FontForge will use these when it seems appropriate.
449
450 The original version of hints did not allow them to overlap, this meant that
451 most serifs could not be described, Adobe then developed a mechanism called
452 hint substitution which allows for different sets of non-overlapping hints to
453 exist in different parts of the glyph. There are still shapes which cannot be
454 fully hinted, but hint substitution is an improvement. The
455 :menuselection:`Hints --> AutoHint` command will figure out what stems
456 overlap and where to change the current set of hints. The
457 :menuselection:`Hints --> Hint Substitution Pts` command will also figure
458 where hint changes should occur, and the Hint Mask pane of the Point Info
459 dialog gives the user direct control over this.
460
461 Most recently Adobe has provide a means to control the counters, the spaces
462 between stems, in a glyph. The original Type1 description provided support
463 for the horizontal counters in "m" and the vertical counters in "E" but more
464 complex shapes could not be dealt with. Counter Hints (in a type1 font) may
465 only be used with non-latin (non-greek, non-cyrillic) glyph sets, in type2
466 (OpenType) things are a bit more complicated,. FontForge will generate
467 counter hints when appropriate.
468
469 .. _overview.HintOrder:
470
471 Adobe provides some font-wide hinting mechanisms. The two most obvious are
472 the BlueValues and StemSnap settings in the
473 :ref:`private dictionary <fontinfo.Private>`. BlueValues provides a list of
474 vertical zones in which interesting things happen (so in a latin font this
475 might include the ascender height, the cap-height, the x-height, the baseline
476 and the descender height. At small point sizes everything within one of these
477 zones will snap to the same height, while at larger point sizes the heights
478 will be slightly different (for instance an "o" and an "x" usually have
479 slightly different heights, but displaying that at a small point size would
480 be ugly). Similarly the StemSnap variables specify standard stem widths for
481 the font. FontForge will try to guess reasonable values for these. It also
482 allows you to override these guesses and
483 :ref:`specify your own values <fontinfo.Private>`. For a more comprehensible
484 description of the private dictionary and what it can do, look at
485 `Adobe's Type1 font specification <http://partners.adobe.com/asn/developer/PDFS/TN/T1_SPEC.PDF>`__.
486
487 FontForge's :ref:`AutoHint <hintsmenu.AutoHint>` command will work better if
488 the BlueValues have been set. So before running AutoHint go to
489 :ref:`Element-> FontInfo-> Private <fontinfo.Private>` to set this array.
490 After AutoHinting you should regenerate the StemSnaps (also at
491 :menuselection:`Element --> FontInfo --> Private`).
492
493 .. _overview.TrueType:
494
495 **True Type**
496
497 .. figure:: /images/GridFitM.png
498
499 Grid Fit M
500
501 On the other hand, True Type says that figuring out what pixels to turn on
502 would be a lot simpler if only the points and the splines were in the right
503 place (ie. at pixel boundaries). And so True Type provides a set of
504 instructions that move points around until they are positioned appropriately
505 for a given size.
506
507 FontForge's hinting of True Type (properly called "instructing") is based on
508 the stem hints also used by PostScript and on diagonal hints. It uses these
509 hints to determine which points to move and where to move them.
510
511 When FontForge reads in a TrueType font it will store the instructions used,
512 and when it next generates that font it will use those instructions --
513 provided no significant change has happened to a glyph.
514
515 Most of my :doc:`hinting user interface </techref/hinting>` is designed with PostScript
516 fonts in mind.
517
518
519 .. _overview.References:
520
521 References
522 ----------
523
524 In addition to a set of outlines (splines) glyphs may be built out of references
525 to other glyphs. This is especially handy for the accented glyphs, "à" can be
526 made up of a reference to the "a" glyph and another reference to the
527 "\`" glyph. This can result in significant space savings, and in ease of design
528 (if you change the "a" glyph after making a reference to it the "à" glyph will
529 automatically change too, whereas if you just copied the "a" you would have to recopy it.
530
531 FontForge has three commands for manipulating references, and one higher level
532 command for building accented glyphs. The
533 :ref:`Edit->Copy Reference <editmenu.Reference>` command will put a reference to
534 the current glyph into the clipboard, which a subsequent
535 :ref:`Edit->Paste <editmenu.Paste>` command will install as a reference. The
536 :ref:`Edit->Unlink Reference <editmenu.Unlink>` command will turn a reference in
537 a glyph into it's component splines. The
538 :ref:`Element->Get Info <elementmenu.Info>` command (when applied to a
539 reference) will bring up a dialog showing you what glyph is referred to, and
540 allowing you to bring up an editing window on that glyph. Finally the
541 :ref:`Element->Build->Accented Glyphs <elementmenu.Accented>` command will
542 figure out what glyphs should be referred to to build this composite glyph, and
543 then will make those references and position them appropriately. So if "à" were
544 selected and you did a
545 :ref:`Element->Build->Accented Glyphs <elementmenu.Accented>` command, FontForge
546 would make a reference to "a" and another to
547 "\`", and place the accent above the letter, and centered on it.
548
549 Some bitmap formats (OK, only one that I'm aware of) support references, so
550 FontForge allows references in bitmap glyphs as well as in outline glyphs.
551
552 Sadly life is not always that simple. The references FontForge uses internally
553 cannot always be converted into something equivalent in the output font.
554 Generally this causes no problems (FontForge will simply unlink the reference in
555 the output, which just makes the font a little bigger, but it has implications
556 for instructing TrueType, and, to a lesser extent, hinting PostScript. Most
557 people can ignore this, but if you are interested
558 :doc:`follow this link </techref/ref-caveats>`).
559
560 Most font formats require that a glyph contain either a set of outlines (or
561 bitmap rasters) or a set of references. FontForge allows glyphs with a
562 combination of the two, but, as above, when it comes time to output the results,
563 FontForge will clean up the glyph (generally by unlinking references) so that it
564 can be output in the current format.
565
566
567 .. _overview.Layers:
568
569 Layers
570 ------
571
572 A font may have several layers. When FontForge creates a new font it will have 2
573 real layers (the foreground and background layers) and a sort of half-layer for
574 guidelines which is shared by all glyphs. In normal fonts all glyphs have the
575 same number of layers (This is not true of Type3 fonts, and
576 :ref:`I'll talk about them later. <overview.Type3>`)
577
578 Both the foreground layer and the background layer have certain predefined
579 meanings: The foreground layer is the default layer for dialogs where there is
580 no clear way to specify a layer. The background layer can contain all sorts of
581 stuff, basically whatever you want it to, but any images in it may be autotraced
582 into the foreground layer.
583
584 You may add other layers with the
585 :ref:`Element->Font Info->Layers <fontinfo.Layers>` pane. Each layer may have a
586 name and a different kind of splines (quadratic or cubic).
587
588 One potential use of additional layers: Many people find it easier to edit using
589 cubic splines but like to produce truetype fonts with quadratic splines. You can
590 use one layer to hold the cubic splines and another to hold the quadratics.
591 There are commands for comparing layers
592 (:ref:`Element->Compare Layer To Layer <elementmenu.CompareL2L>`) and others for
593 copying one layer to another (and adjusting the splines to fit the new layer:
594 :ref:`Edit->Copy Layer To Layer <editmenu.CopyL2L>`).
595
596 It seems a shame to have both a valid cubic and a valid quadratic font in a
597 database and only be able to produce a font from one of them, so the font view
598 will allow you to switch between layers
599 (:ref:`View->Layers->* <viewmenu.FVLayers>`) and
600 :doc:`File->Generate Fonts </ui/dialogs/generate>` command will allow you to output whatever
601 layer you want into the font. (Note that all layers will share the same hints,
602 instructions, character set, bitmaps, etc. It is only the outlines which
603 differ.) Furthermore, you may choose to store all the layers of a font into an
604 sfnt (TrueType / OpenType font) with the
605 :ref:`[]Layers checkbox of the PfaEdit table of the [Options] <generate.Options>`
606 dialog.
607
608
609 .. _overview.Type3:
610
611 Type3 Fonts
612 ^^^^^^^^^^^
613
614 Most people aren't interested in editing
615 :doc:`Type3 PostScript fonts </ui/dialogs/multilayer>` (nor the equivalent SVG font), but if
616 you want to, FontForge can. Here each layer represents a different drawing
617 operation, and may specify a different color, stroke, fill, etc. Layers are not
618 font-wide, each glyph has its own set of layers (which are not named). You can
619 :ref:`create new layers with a popup menu <multilayer.Layer>` in the layers pane
620 of the outline view.
621
622
623 Guidelines
624 ^^^^^^^^^^
625
626 In FontForge guidelines live in their own mini-layer (it isn't a full layer
627 because all glyphs share the same set of guidelines rather than having an
628 individual layer for each glyph). It can be edited just like any other layer and
629 you may have guidelines of any shape you desire. You may also drag out
630 horizontal and vertical guidelines from the edges of the outline glyph view.
631
632
633 .. _overview.Scripts:
634
635 Scripts
636 -------
637
638 A script is a collection of letter shapes and rules for putting letters
639 together. For instance the latin script consists of the letters A-Z, written
640 left to right, along with a transformation from upper to lower case, a few
641 ligatures and rules for generating accents. Arabic is a script consisting of its
642 own character set, written right to left, along with transformations for
643 initial, medial, final and isolated forms, many ligatures and rules for placing
644 vowel marks.
645
646
647 .. _overview.Glyph-names:
648
649 Glyph names & Namelists
650 -----------------------
651
652 Within fontforge every glyph will have a name. Generally the glyph name will be
653 something that provides information about what the glyph looks like so the name
654 for the glyph representing "9" is "nine". Adobe has established a
655 `standard for what names may be assigned to what glyphs
656 <http://partners.adobe.com/public/developer/en/opentype/aglfn13.txt>`__,
657 and when producing a font for general use it is best to stick to that standard
658 (Acrobat uses the glyph names and recognizes the standard ones. If you try and
659 use "neuf" for "nine" Acrobat will not recognize it and surprising things will
660 fail).
661
662 Adobe's standard provides reasonably mnemonic names for most latin and greek
663 glyphs (to English speakers anyway), some rather incomprehensible names for
664 cyrillic and hebrew (afiiXXXXX) and identifies most other glyphs by unicode code
665 point (uniXXXX or uXXXXX where "X" represents a hex digit and XXXX is the
666 unicode code point in hex).
667
668 If you are an english speaker and you are working with latin glyphs this is fine
669 and dandy. But if you are French you might wish that "adieresis" were named
670 "atréma" -- for that matter even if you are an English speaker you might prefer
671 it to be named "aumlaut". No matter who you are you might prefer more mnemonic
672 names for the code block you are working on.
673
674 FontForge has a concept called a :ref:`namelist <encodingmenu.namelist>`, each
675 of which is simply a mapping from unicode code point to name. Several namelists
676 may be defined, different lists may apply to different fonts and a font may have
677 all its glyphs renamed from one namelist to another.
678
679 Namelists can also help navigating in a font. Even if a list does not apply to a
680 given font its names may be used in the goto dialog to find glyphs. So if you've
681 loaded a french namelist you can search for "atréma" and FontForge will show you
682 the glyph "adieresis" or "uni00E4" or "aumlaut" or whatever.
683
684 A few caveats: Adobe's glyph name standard expects all glyph names to be in
685 ASCII characters. Syntactically postscript permits a wider range of glyph names,
686 but if you use non-ASCII characters some rasterizers might have problems. Best
687 to keep non-ASCII names within fontforge (and rename glyphs to adobe's standard
688 names before generating a font).
689
690
691 .. _overview.Lookups:
692
693 Lookups, Features, Scripts and Languages
694 ----------------------------------------
695
696 OpenType (and Apple Advanced Typography) allow various transformations to be
697 applied to the input glyph stream to produce an output glyph stream. These
698 transformations might include forming ligatures, kerning glyphs closer to each
699 other, attaching vowel marks or diacritics to letters, conditionally replacing
700 one glyph with another depending on the glyphs around it, etc.
701
702 The commands for each transformation are stored in what are called lookups. If
703 you were designing a set of lookups to handle latin ligatures, you might have
704 one lookup for ff, fl and ffl -- ligatures that happen almost all the time,
705 another for fi and ffi -- ligatures which don't happen in Turkish but do in
706 other languages, and lookups for ct and st -- ligatures which rarely happen in
707 English but are more frequent in German (I think).
708
709 A Feature is a tagged collection of lookups. The tags are all 4 letter sequences
710 (like 'liga') with standardized meanings. The 'liga' tag means standard
711 ligatures. The 'dlig' tag means discretionary ligatures, and 'kern' means
712 kerning. There are many others.
713
714 Every script (latin, cyrillic, han ideographs, ...) will have its own set of
715 features that are meaningful to it. Sometimes things will be even more
716 complicated, and each language within a script will have it's own set of
717 features. In the example above we might assign scripts, languages, features and
718 lookups thusly:
719
720 +--------+----------+----------------------+----------------------------------+
721 | Script | Language | Feature | Lookups |
722 +========+==========+======================+==================================+
723 | latn | default | liga (standard) | lookup for ff, fl and ffl |
724 | | | +----------------------------------+
725 | | | | lookup for fi and ffi |
726 | | +----------------------+----------------------------------+
727 | | | dlig (discretionary) | lookup for ct and st |
728 | +----------+----------------------+----------------------------------+
729 | | Turkish | liga | lookup for ff, fl and ffl [#f1]_ |
730 | +----------+----------------------+----------------------------------+
731 | | German | liga | lookup for ff, fl and ffl |
732 | | | +----------------------------------+
733 | | | | lookup for fi and ffi |
734 | | | +----------------------------------+
735 | | | | lookup for ct and st [#f2]_ |
736 +--------+----------+----------------------+----------------------------------+
737
738 .. [#f1] Lookups may be shared, so this can be the same lookup as above
739 (Turkish distinguishes between i and dotlessi and fi ligatures hide
740 this distinction.)
741 .. [#f2] Lookups may even be shared by a different feature type, so for English
742 and Spanish ct might count as a discretionary ligature, one rarely used,
743 while in German it mght be more common and be part of the standard
744 ligature set.
745
746 The default language means any language in the script which is not specifically
747 named. So in the above example the default language would be any language except
748 Turkish and German that might use the latin script.
749
750 It is also possible to have a default script. The digits 0-9, are used in many
751 writing systems, not just Latin and are considered Common to most scripts. If
752 you have lookups which apply to the digits (conversion to oldstyle digits, or to
753 proportional digits, or to superscripts...) you should attach those lookups to
754 features in all scripts (and languages) that could use them, and to the default
755 script (just in case).
756
757 +--------+----------+---------+----------------------------------+
758 | Script | Language | Feature | Lookups |
759 +========+==========+=========+==================================+
760 | latn | default | pnum | proportional number lookup |
761 | | +---------+----------------------------------+
762 | | | onum | old style number lookup |
763 | | +---------+----------------------------------+
764 | | | subs | subscript lookup |
765 | +----------+---------+----------------------------------+
766 | | Turkish | pnum | proportional number lookup |
767 | | +---------+----------------------------------+
768 | | | onum | old style number lookup |
769 | | +---------+----------------------------------+
770 | | | subs | subscript lookup |
771 | +----------+---------+----------------------------------+
772 | | German | pnum | proportional number lookup |
773 | | +---------+----------------------------------+
774 | | | onum | old style number lookup |
775 | | +---------+----------------------------------+
776 | | | subs | subscript lookup |
777 +--------+----------+---------+----------------------------------+
778 | cyrl | default | pnum | proportional number lookup |
779 | | +---------+----------------------------------+
780 | | | onum | old style number lookup |
781 | | +---------+----------------------------------+
782 | | | subs | subscript lookup |
783 +--------+----------+---------+----------------------------------+
784 | DFLT | default | pnum | proportional number lookup |
785 | | +---------+----------------------------------+
786 | | | onum | old style number lookup |
787 | | +---------+----------------------------------+
788 | | | subs | subscript lookup |
789 +--------+----------+---------+----------------------------------+
790
791 There are roughly 15 different types of lookups which contain different
792 information. Different kinds of lookup are needed to specify ligature data,
793 glyph substitution data and kerning data.
794
795 Lookups may be specified with the :ref:`Element->Font Info <fontinfo.Lookups>`
796 dialog
797
798
799 Lookup subtables
800 ^^^^^^^^^^^^^^^^
801
802 I talk above about lookups as if they were simple things. Unfortunately they
803 aren't. Each lookup is composed of "Subtables" which actually do the work.
804
805 A lookup may contain several subtables. Most contain exactly one. (If a lookup
806 contains no subtables it will do nothing).
807
808 I said there were about 15 kinds of lookup, there are even more kinds of
809 subtable. For instance a subtable which specifies glyph to glyph kerning is
810 different from one which specifies glyph class to glyph class kerning.
811
812 At first glance the subtable may seem an unnecessary complication, but it turns
813 out to be desirable for one lookup to contain several kinds of sub-table data.
814 For instance, a kerning lookup might include one subtable providing glyph class
815 kerning, and then another subtable providing exceptions to that on a glyph by
816 glyph basis.
817
818
819 How lookups are applied
820 ^^^^^^^^^^^^^^^^^^^^^^^
821
822 When a word processor deals with text, it will figure out what script is in use
823 in the text. Somehow it will figure out what the language is (maybe it will just
824 assume the "DFLT" language, maybe the user told it the text was in French, maybe
825 the locale is Spanish, ...).
826
827 In any script/language some features are applied by default, while others may be
828 applied at the user's discression. So in English the "liga" feature should
829 always be applied, while the "dlig" feature should only be applied if the user
830 asked for it. (Not all programs follow this at the moment, but that's the
831 theory).
832
833 The word processor will build up a list of features that might be active. Then
834 it looks in the font and sees which of those features are available for this
835 script and language. In turn each feature is composed of lookups, and all
836 lookups in all active features will be marked as active.
837
838 Lookups will be executed in the order in which they occur in the lookup list
839 (which is also the order shown in the :menuselection:`Font Info --> Lookup`
840 pane, but may be quite different from the order in which the features were
841 listed). And all active lookups will be executed.
842
843 This ordering can be important. If you have both a small-caps lookup and a
844 ligature lookup active, and the text is "fi" then the order of the lookups will
845 probably matter. If the small-caps lookup happens first then the "fi" will
846 become ":small:`FI`" and the ligature feature will not be applied. If the
847 ligature happens first then you will see an "fi" ligature for which there is
848 probably no small-caps glyph. In one case you get small-caps, in another a
849 ligature. Probably, here, you would like the small-caps lookup to happen first.
850
851 Lookup subtables make life even more interesting. When a lookup is executed the
852 subtables within that lookup are activated in turn *until one succeeds*. After
853 that no further subtables will be applied.
854
855 So in the kerning example mentioned above, you would want to put the special
856 case glyph to glyph subtable first, and then the glyph class to class subtable
857 second. When a special case combination occurs the first subtable will succeed
858 (and kern the combination) and the class subtable will not be used. For
859 combinations which aren't special cases, then the first subtable will fail, and
860 the second will be applied.
861
862
863 GPOS and GSUB
864 ^^^^^^^^^^^^^
865
866 Up till now I have spoken as there were one list of lookups. That was a
867 simplification. There are two broad classes of lookup, and two lists. There are
868 those involved in manipulating the glyphs themselves (glyph substitution,
869 ligation, decomposition, etc.) and those involved in positioning glyphs relative
870 to others (kerning, mark attachment, etc.).
871
872 The GSUB table contains all the glyph substitution lookups and *all* of them
873 will be processed before any positioning lookups are attempted.
874
875 The GPOS table contains all the glyph positioning lookups.
876
877
878 .. _overview.Anchors:
879
880 Anchor Points and Classes
881 -------------------------
882
883 Anchor points allow fine control of the positioning of two (or several) glyphs.
884 There are several different styles of attachment based on anchors: cursive, mark
885 to base, mark to ligature and mark to mark positioning. The first style is used
886 to join glyphs in flowing scripts (cursive) where the exit from one glyph joins
887 the entry point of the next. In the second style one of the glyphs is the base
888 glyph, and it will be positioned normally, the other glyph which will often be a
889 diacritic or vowel mark will be positioned so that the anchor points in each
890 glyph are coincident. Mark to ligature behaves similarly to mark to base except
891 that there may be more that one attachment point on the ligature depending on
892 which component a given mark is connected to. Finally, mark to mark allows you
893 to position two marks with respect to each other (as you might need to do in
894 vietnamese or hebrew where you may get several marks for one glyph).
895
896 That is badly said. Consider the following two glyphs and how they are joined to
897 make the final result:
898
899 .. flex-grid::
900 :class: flex-nobreak flex-middle
901
902 * :flex-widths: 0 0 0 0 0
903
904 - .. image:: /images/a_with_anchor.png
905 - \+
906 - .. image:: /images/grave_with_anchor.png
907 - =>
908 - .. image:: /images/agrave_anchored.png
909
910 The grave accent has been raised and moved to the right so that its anchor point
911 is positioned where the anchor from "a" was.
912
913 FontForge does not compose these glyphs (well, it can, but that's a completely
914 different area), instead it provides information within the
915 :doc:`font </techref/gposgsub>` to a text layout program so that the program can do the
916 composition.
917
918 The example above is unlikely to be very useful since most latin fonts contain
919 pre-composed a-grave glyphs, but the same concepts apply to arabic and hebrew
920 where the number of variants is larger and the precomposed glyphs fewer.
921
922 That's roughly how anchor points are used. Now the mechanics.
923
924 Each of the different attachment styles mentioned above (cursive, mark to base,
925 mark to ligature and mark to mark) is a different type of GPOS lookup. If you
926 want to do attachment positioning you must first create the appropriate lookup
927 (:ref:`Element->Font Info->Lookups->GPOS <fontinfo.Lookups>`, then a lookup
928 subtable, and then an anchor class within the lookup subtable. An anchor class
929 is specified by providing a name for it (in the above example the class was
930 called "Top").
931
932 Cursive attachments are a little different from the other attachment types. Each
933 glyph has two attachment points, an entry and an exit (instead of just the one
934 shown in the mark to base example above). The text layout program will attach
935 the exit point of one glyph to the entry point of the next.
936
937 A glyph may contain several Anchor Points, but only one for each mark to base
938 anchor class (ligatures may have more than one for a class, and 'curs' and
939 'mkmk' classes will usually have two). Inside a glyph may create a point with
940 the :ref:`Point->Add Anchor command <pointmenu.AddAnchor>`. You must specify an
941 anchor class, and whether this point is in a base glyph or in a mark glyph, and
942 a location. So in the example above the anchor point in "a" has class "Top" and
943 is a base glyph, while the anchor point in "grave" also has class "Top" but is a
944 mark glyph. There may be many base glyphs with an anchor point named "Top" and
945 many mark glyphs also with "Top" anchor points. Any base glyph with a "Top"
946 anchor point maybe composed with any mark glyph with a "Top" anchor point. So
947 instead of specifying the exact composed form for all possible combinations we
948 specify far fewer anchor points for the same effect.
949
950 But life is not really that simple. Ligatures may need several anchor points of
951 the same class (one above each component for example). When you create your
952 anchor point you may say that it is to be in a ligature, in which case you will
953 also be asked for a ligature index -- a number running from 0 to the number of
954 components in the ligature -1. This allows you to position several anchor points
955 with the same class. The text layout program will place the first mark over the
956 first anchor point, the second mark over the second and so on (this is a gross
957 simplification).
958
959 Finally you may need to position two marks based on the same anchor point, for
960 example the glyph |a_dieresis_macron| has a diaeresis and a macron over it.
961 Both of which might normally be positioned with the Top anchor class. Instead
962 we define a special class for positioning one mark with respect to another.
963 When creating the anchor class specify a tag of 'mkmk' (mark to mark) and call
964 it something like "TopMark". When you create a new anchor point for diaeresis
965 you specify that it is a *base mark* and you position it above the glyph, while
966 the new anchor point in macron should be of type mark and should be positioned
967 at the same place as the "Top" anchor point. Thus when given the sequence of
968 glyphs "a diaeresis macron" the text layout program should position "a"
969 normally, position "diaeresis" so that the its Top anchor point is where "a"'s
970 is, and position macron so that its TopMark anchor point is where
971 "diaeresis"'s is.
972
973 Anchor points may be selected, dragged, transformed, cut, copied and pasted.
974
975 .. |a_dieresis_macron| image:: /images/a_dieresis_macron.png
976
977
978 .. _overview.Baseline:
979
980 Baselines
981 ---------
982
983 To a user of the latin alphabet it makes sense for the vertical origin of a
984 glyph to be the baseline on which most letters rest |latinBaseline|. This means
985 that if you change the pointsize of a glyph it will still line up properly
986 |latinNormalBaseline|. This is so obvious we don't even think about it. But if
987 you put the vertical origin at the top of the letter then the letters will be
988 aligned quite differently, and to our eyes, unexpectedly |latinHangBaseline|.
989
990 Different scripts have different expectations of how glyphs should be aligned.
991 In latin (cyrillic, greek, arabic, hebrew, etc.) the alignment point, the
992 baseline, is somewhere in the middle of the possible extent of a glyph -- that
993 is the script has both ascenders above the baseline and descenders below it.
994
995 But not all scripts are like that. In Devanagari the alignment point is near the
996 top of the glyph -- indeed most glyphs will draw in the baseline explicitly
997 |devaBaseline|. If you change the pointsize you want glyphs to line up on this
998 line |devaHangBaseline|, and not down at the bottom of the glyph
999 |devaLatinBaseline|.
1000
1001 .. |latinBaseline| image:: /images/latinBaseline.png
1002 .. |latinNormalBaseline| image:: /images/latinNormalBaseline.png
1003 .. |latinHangBaseline| image:: /images/latinHangBaseline.png
1004 .. |devaBaseline| image:: /images/devaBaseline.png
1005 .. |devaHangBaseline| image:: /images/devaHangBaseline.png
1006 .. |devaLatinBaseline| image:: /images/devaLatinBaseline.png
1007
1008 In CJK ideographs the baseline is usually drawn at the bottom edge of the square
1009 which contains the glyph.
1010
1011 However if you try and typeset these different scripts together with their
1012 baselines in the same place you get a mess:
1013
1014 .. image:: /images/misalignedBaselines.png
1015
1016 It would be much nicer if it were possible to say that these different scripts
1017 have their baselines in different places so that the glyphs can fit together
1018 reasonably:
1019
1020 .. image:: /images/alignedBaselines.png
1021
1022 Both Apple Typography and OpenType allow for this. There is a
1023 :doc:`baseline table </ui/dialogs/baseline>` which says how the baselines for each script
1024 (or each glyph) should be aligned with respect to other baselines.
1025
1026
1027 .. _overview.FontView:
1028
1029 Font View
1030 ---------
1031
1032 The :doc:`font view </ui/mainviews/fontview>` displays all the glyphs in the font (or all that
1033 will fit in the window). Every line has two parts, at the top is a label, often
1034 small clear letters, underneath that, somewhat larger is a 24 pixel
1035 rasterization of the font you have designed. As you edit a glyph in an
1036 :ref:`outline glyph view <overview.CharView>` its small version in the font view
1037 will change as you work.
1038
1039 Double-clicking on a glyph will bring up an outline glyph view of that glyph
1040 which will allow you to edit it.
1041
1042 Selecting several glyphs will allow you to apply various operations to all of
1043 them, or to cut and paste them.
1044
1045 .. image:: /images/AmbrosiaFV.png
1046
1047 Fonts do not need to be for the latin alphabet alone. Below is a view of one of
1048 `Wadalab <ftp://ftp.ipl.t.u-tokyo.ac.jp/Font/>`__'s public domain Kanji fonts...
1049
1050 .. image:: /images/kanjifont.png
1051
1052 Another Wadalab font encapsulated in a CID keyed font
1053
1054 .. image:: /images/fontview-cid.png
1055
1056
1057 .. _overview.CharView:
1058
1059 Outline Glyph View
1060 ------------------
1061
1062 The :doc:`outline view </ui/mainviews/charview>` is probably the most complex view in
1063 FontForge. This is where you actually edit the splines
1064 (:doc:`Bézier splines </techref/bezier>`) that make up your glyphs.
1065
1066 You may have a background image loaded into the view to help you trace out the
1067 shape you are working on (it is displayed in grey). There are various grid lines
1068 visible, some created by default (the baseline, the ascent line, the descent
1069 line, and a line at x=0), you may add others yourself.
1070
1071 There is a layer showing the glyph's hints.
1072
1073 In the foreground are the splines and points of the glyph itself, and the width
1074 line (you may adjust the glyph's width by moving this line). If a point is
1075 selected then its control points will be displayed.
1076
1077 To the left of the main window (the image below shows them on the right, that
1078 was just to keep them from crowding things, you can move them around) are two
1079 palettes, one a palette of tools, and the other a palette controlling what
1080 layers (foreground, background, grid, hints) are visible and editable.
1081
1082 .. image:: /images/charview2.png
1083
1084
1085 .. _overview.BitmapView:
1086
1087 Bitmap View
1088 -----------
1089
1090 The :doc:`bitmap view </ui/mainviews/bitmapview>` is similar to the outline view above. It
1091 also has a tools and layer palette.
1092
1093 This allows you to edit bitmap versions of the outline glyphs you create above.
1094
1095 In the background is a small rendition of the outline, and in the foreground are
1096 the bits of the image. You may make the program calculate which bits should be
1097 set by pressing the "Recalculate button", the results usually need to be tweaked
1098 by hand. In the upper left corner is a full sized image of your bitmap glyph.
1099
1100 .. image:: /images/BitmapView.png
1101
1102
1103 .. _overview.MetricsView:
1104
1105 Metrics View
1106 ------------
1107
1108 The :doc:`metrics view </ui/mainviews/metricsview>` allows you to see how the glyphs look
1109 together.
1110
1111 You can change the width and left/right bearings of a glyph, either by dragging
1112 in the upper part of the window or by entering an appropriate number in the
1113 lower.
1114
1115 You can also provide kerning information for any two adjacent glyphs. You can
1116 view how various OpenType features affect the glyph stream.
1117
1118 Note that in Hebrew, or Arabic (or any other right to left alphabet) the glyphs
1119 will start on the right and run to the left. While in CJK fonts you may want to
1120 see things arranged vertically.
1121
1122 .. flex-grid::
1123
1124 * - .. image:: /images/MetricsView.png
1125 - .. image:: /images/MetricsView-features.png
1126 * - .. image:: /images/HebrewMetrics.png
1127 - .. image:: /images/VerticalMetrics.png
1128