Debian Codegraph @

doc/sphinx/techref/splinefont.rst

raw
1 Data Types
2 ==========
3
4 .. highlight:: c
5
6 .. warning::
7 While much of what is described remains relevant, it has *not* been kept up
8 to date with recent code changes. Cross-reference this with the current
9 state of affairs in the `repository <https://github.com/fontforge/fontforge>`__.
10
11 This describes two different types of fonts, a SplineFont (which is a postscript
12 or truetype font) and a BDFFont (bitmap font, essentially a bdf file). There are
13 some similarities between the two data structures, each is basically an array
14 (possibly with holes in it) of characters. Each font also contains information
15 like the fontname.
16
17 The :ref:`SplineFont <splinefont.SplineFont>` consists of a bunch of
18 :ref:`SplineChars <splinefont.SplineChar>`, each containing four layers,
19
20 * A foreground layer which contains all the interesting stuff that gets put into
21 the final font
22
23 * a series of paths (called :ref:`SplineSet <splinefont.SplinePointList>`\ s or
24 :ref:`SplinePointList <splinefont.SplinePointList>` sorry, I gave the data
25 structure two different names)
26 * a series of references to other characters (called
27 :ref:`RefChar <splinefont.RefChar>`\ s)
28 * a width
29 * :ref:`undoes <splinefont.Undoes>`
30 * A background layer (which is used to allow people to trace images of characters)
31 and can contain
32
33 * a series of :ref:`SplineSet <splinefont.SplinePointList>`\ s
34 * A series of :ref:`images <splinefont.ImageList>`
35 * :ref:`undoes <splinefont.Undoes>`
36 * A grid layer, which is shared by all the characters in a font and in which you
37 can put lines to indicate the Cap Height, X Height, etc. Actually you can put
38 anything there but those are the obviously useful things. It will be seen in all
39 characters. It contains
40
41 * A series of :ref:`SplineSet <splinefont.SplinePointList>`\ s
42 * :ref:`undoes <splinefont.Undoes>`
43 * A hint layer, whose format is completely different from anything else and
44 consists of horizontal and vertical hints, which in turn are just a starting
45 location and a width (indicating the stem. The width can be negative.)
46
47 * A set of :ref:`hints <splinefont.Hints>`. Hints need the special tools from the
48 hint menu for editing them.
49 * **!!!! I do not have a way of undoing hint operations !!!!**
50
51 In multilayered mode there can be many foreground layers which can be stroked or
52 filled. Bitmap images may also be included.
53
54 Every SplineChar has a name associated with it, a unicode encoding and a its
55 original position in the font.
56
57 A SplineSet consists of a start point and an end point, and whatever splines
58 connect them. The start point and the end point may be the same, this either
59 indicates a closed path, or a degenerate path with only one point on it.
60
61 A SplinePoint contains an x,y location of the point, and the locations of the
62 two control points associated with that point. A control point may be coincident
63 with the main point. SplinePoints may connect to two splines, a previous Spline
64 and a next Spline. A Spline contains pointers to two SplinePoints (a start and
65 an end point) it also contains the parameters of the Bézier curve that those two
66 points describe (x = a*t^3+b*t^2+c*t+d, y=ditto). Splines are straight lines if
67 the two control points that are meaningful to that spline are coincident with
68 their respective SplinePoints. A spline contains a bit indicating whether it is
69 order2 (truetype quadratic format) or order3 (postscript cubic format). If it is
70 quadratic there is really only one control point, ff uses the convention that
71 the control points on the start and end SplinePoints have the same location.
72
73 A font's encoding is stored in a separate data structure called an EncMap. This
74 structure controls what glyph goes where and also contains a pointer to an
75 Encoding structure which provides a name for the encoding. The EncMap contains
76 two arrays, the ``map`` and the ``backmap``. The map is indexed by the
77 character's encoding and provides the position (in the associated splinefont's
78 glyph list) of the associated glyph. The backmap provides the reverse mapping,
79 it is indexed by a glyph's position in the splinefont and provides an encoding
80 for that glyph. (Note: the map array may map several encodings to one glyph, the
81 backmap will only indicate one of those.)
82
83 A :ref:`BDFFont <splinefont.BDFFont>` is always associated with a (possibly
84 empty) SplineFont and its EncMap, it consists of an array of
85 :ref:`BDFChars <splinefont.BDFChar>`, each containing
86
87 * a bitmap
88 * possibly a floating selection
89 * a name
90 * :ref:`undoes <splinefont.Undoes>`
91 * A pointer to the :ref:`SplineChar <splinefont.SplineChar>` with which it is
92 associated
93
94 The array is ordered the same way the SplineFont's array is ordered, and the
95 same EncMap can be used for both.
96
97 ::
98
99 /* Copyright (C) 2000-2003 by George Williams */
100 /*
101 * Redistribution and use in source and binary forms, with or without
102 * modification, are permitted provided that the following conditions are met:
103
104 * Redistributions of source code must retain the above copyright notice, this
105 * list of conditions and the following disclaimer.
106
107 * Redistributions in binary form must reproduce the above copyright notice,
108 * this list of conditions and the following disclaimer in the documentation
109 * and/or other materials provided with the distribution.
110
111 * The name of the author may not be used to endorse or promote products
112 * derived from this software without specific prior written permission.
113
114 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
115 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
116 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
117 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
118 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
119 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
120 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
121 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
122 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
123 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124 */
125 #ifndef _SPLINEFONT_H
126 #define _SPLINEFONT_H
127
128 #include "basics.h"
129 #include "charset.h"
130
131 enum linejoin {
132 lj_miter, /* Extend lines until they meet */
133 lj_round, /* circle centered at the join of expand radius */
134 lj_bevel /* Straight line between the ends of next and prev */
135 };
136 enum linecap {
137 lc_butt, /* equiv to lj_bevel, straight line extends from one side to other */
138 lc_round, /* semi-circle */
139 lc_square /* Extend lines by radius, then join them */
140 };
141
142 typedef struct strokeinfo {
143 double radius;
144 enum linejoin join;
145 enum linecap cap;
146 unsigned int calligraphic: 1;
147 double penangle;
148 double thickness; /* doesn't work */
149 } StrokeInfo;
150
151 The above data structure is used by the ExpandStroke routines which will turn a
152 path into a filled shape. The information above provides the various controls
153 for those routines. They mean essentially what you expect them to me in
154 postscript.
155
156 ::
157
158 typedef struct ipoint {
159 int x;
160 int y;
161 } IPoint;
162
163 An integer point.
164
165 ::
166
167 typedef struct basepoint {
168 double x;
169 double y;
170 } BasePoint;
171
172 A double point. This provides the location of
173 :ref:`SplinePoints <splinefont.SplinePoint>` and their control points.
174
175 ::
176
177 typedef struct tpoint {
178 double x;
179 double y;
180 double t;
181 } TPoint;
182
183 A double point with a "t" value. Indicates where that location occurs on a
184 spline. (the start point itself is a t=0, the end point at t=1, intermediate
185 points have intermediate values). Used when trying to approximate new splines.
186
187 ::
188
189 typedef struct dbounds {
190 double minx, maxx;
191 double miny, maxy;
192 } DBounds;
193
194 The bounding box of a :ref:`Spline <splinefont.Spline>`,
195 :ref:`SplineChar <splinefont.SplineChar>`, :ref:`RefChar <splinefont.RefChar>`,
196 :ref:`Image <splinefont.ImageList>`, or whatever else needs a bounding box.
197
198 .. code-block:: default
199 :name: splinefont.BDFFloat
200
201 typedef struct bdffloat {
202 int16 xmin,xmax,ymin,ymax;
203 int16 bytes_per_line;
204 uint8 *bitmap;
205 } BDFFloat;
206
207 The floating selection in a :ref:`BDFChar <splinefont.BDFChar>`.
208
209 .. code-block:: default
210 :name: splinefont.Undoes
211
212 typedef struct undoes {
213 struct undoes *next;
214 enum undotype { ut_none=0, ut_state, ut_tstate, ut_width,
215 ut_bitmap, ut_bitmapsel, ut_composite, ut_multiple } undotype;
216 union {
217 struct {
218 int16 width;
219 int16 lbearingchange;
220 struct splinepointlist *splines;
221 struct refchar *refs;
222 struct imagelist *images;
223 } state;
224 int width;
225 struct {
226 /*int16 width;*/ /* width should be controlled by postscript */
227 int16 xmin,xmax,ymin,ymax;
228 int16 bytes_per_line;
229 uint8 *bitmap;
230 BDFFloat *selection;
231 int pixelsize;
232 } bmpstate;
233 struct { /* copy contains an outline state and a set of bitmap states */
234 struct undoes *state;
235 struct undoes *bitmaps;
236 } composite;
237 struct {
238 struct undoes *mult; /* copy contains several sub copies (composites, or states or widths or...) */
239 } multiple;
240 uint8 *bitmap;
241 } u;
242 } Undoes;
243
244 The undo data structure. Used by both :ref:`SplineChar <splinefont.SplineChar>`
245 and :ref:`BDFChar <splinefont.BDFChar>`. Also used to contain the local
246 clipboard. Every character layer has several Undoes (up to about 10 or so, it's
247 configurable) that allow it to go back several operations, these are linked
248 together on the next field (redos are handled similarly, of course).
249
250 Undoes come in several types, ut_none is only used by the clipboard when it is
251 empty.
252
253 ut_state is used by SplineChars and it contains a dump of the current state of
254 one layer of the character. Obviously things could be optimized a great deal
255 here, but this is easy. ut_tstate has the same data structure as ut_state, it is
256 used during transformations and is just a flag that tells the display to draw
257 the original as well as the currently transformed thing (so you can see what
258 you've done).
259
260 ut_state is also used by the clipboard when copying a SplineChar or a piece of a
261 SplineChar.
262
263 ut_width is used by SplineChars when the width (and nothing else) changes.
264
265 ut_bitmap is used by BDFChars and is a dump of the current state of the bitmap.
266 Again there is room for optimization here, but this is easy.
267
268 ut_bitmapsel is used when doing a copy of a BDFChar. If there is a selection it
269 (and it alone) gets copied into the selection field of the bmpstate structure.
270 If there is no selection the entire bitmap is converted into a
271 :ref:`floating selection <splinefont.BDFFloat>` and copied into the selection
272 field.
273
274 ut_composite is used when doing a copy from the FontView where you are copying
275 both the splines and the bitmaps of a character.
276
277 ut_mult is used when doing a copy from the FontView where you are copying more
278 than one character.
279
280 .. code-block:: default
281 :name: splinefont.BDFChar
282
283 typedef struct bdfchar {
284 struct splinechar *sc;
285 int16 xmin,xmax,ymin,ymax;
286 int16 width;
287 int16 bytes_per_line;
288 uint8 *bitmap;
289 int orig_pos;
290 struct bitmapview *views;
291 Undoes *undoes;
292 Undoes *redoes;
293 unsigned int changed: 1;
294 unsigned int byte_data: 1; /* for anti-aliased chars entries are grey-scale bytes not bw bits */
295 BDFFloat *selection;
296 } BDFChar;
297
298 The basic bitmap character structure. There's a link to the SplineChar used to
299 create the bitmap. Then the bounding box of the bitmap, the character's width
300 (in pixels of course), the number of bytes per row of the bitmap array, a
301 pointer to an array containing the bitmap. The bitmap is stored with 8bits
302 packed into a byte, the high order bit is left most. Every row begins on a new
303 byte boundary. There are (xmax-xmin+1) bits in each row and (xmax-xmin+8)/8
304 bytes in each row. There are (ymax-ymin+1) rows. A bit-value of 1 means there
305 bit should be drawn, 0 means it is transparent. Then the encoding in the current
306 font. A linked list of BitmapView structures all of which look at this bitmap
307 (so any changes to this bitmap need to cause a redraw in all views). A set of
308 undoes and redoes. A flag indicating whether the thing has been changed since it
309 was last saved to disk.
310
311 Up to this point I've been talking about bitmaps. It is also possible to have a
312 bytemap. The data structure is exactly the same, except that each pixel is
313 represented by a byte rather than a bit. There is a clut for this in the BDFFont
314 (it's the same for every character), but basically 0=>transparent, (2^n-1)
315 =>fully drawn, other values are shades of grey between. Can handle depths of
316 1,2,4 and 8 bits/pixel.
317
318 The last thing in the BDFChar is a (/an optional) floating selection. Only
319 present if the user has made a selection or done a paste or something like that.
320
321 .. code-block:: default
322 :name: splinefont.BDFFont
323
324 typedef struct bdffont {
325 struct splinefont *sf;
326 int glyphcnt;
327 BDFChar **glyphs; /* an array of charcnt entries */
328 int pixelsize;
329 int ascent, descent;
330 struct bdffont *next;
331 struct clut *clut; /* Only for anti-aliased fonts */
332 } BDFFont;
333
334 The basic bitmap font. Contains a reference to the
335 :ref:`SplineFont <splinefont.SplineFont>` to which it is attached. Then a size
336 and an array of BDFChars (note there may be NULL entries in the array if no
337 character is defined for that encoding). Then a temporary array which is used in
338 one set of routines while reencoding the font. The pixelsize of the em-square.
339 The ascent and descent (in pixels), these should sum to the em-square. A
340 character set which will match that in the SplineFont. A pointer to the next
341 bitmap font associated with this SplineFont.
342
343 If we are dealing with a byte font, then there will also be a clut. This
344 contains a count of the number of entries in the array, and then the array
345 itself. Currently the number of entries here is always 16, but that could
346 change.
347
348 .. code-block:: default
349 :name: splinefont.SplinePoint
350
351 enum pointtype { pt_curve, pt_corner, pt_tangent };
352 typedef struct splinepoint {
353 BasePoint me;
354 BasePoint nextcp; /* control point */
355 BasePoint prevcp; /* control point */
356 unsigned int nonextcp:1;
357 unsigned int noprevcp:1;
358 unsigned int nextcpdef:1;
359 unsigned int prevcpdef:1;
360 unsigned int selected:1; /* for UI */
361 unsigned int pointtype:2;
362 unsigned int isintersection: 1;
363 uint16 flex; /* This is a flex serif have to go through icky flex output */
364 struct spline *next;
365 struct spline *prev;
366 } SplinePoint;
367
368 A SplinePoint is located at the position specified by "me". The control point
369 associated with the next :ref:`Spline <splinefont.Spline>` is positioned at
370 nextcp, while that associated with the previous Spline is at prevcp. Then there
371 are a couple of flags that simplify tests. If the nextcp is degenerate (ie. at
372 the same place as me) then nonextcp is set, similarly for prevcp. If the user
373 has not touched the control points then they will have their default values, and
374 when the user moves the point around fontforge will update the control points
375 appropriately, if they do not have default values then fontforge will only
376 offset them.
377
378 If the point is selected then that bit will be set.
379
380 Every point is classified as a curve point, a corner point and a tangent point.
381
382 The isintersection bit is used internally to the SplineOverlap routines. The
383 flex value is for flex hints. It is read in from a type1 font and then ignored.
384 Someday I may use it.
385
386 Finally we have pointers to the two Splines than connect to this point.
387
388 ::
389
390 typedef struct linelist {
391 IPoint here;
392 struct linelist *next;
393 } LineList;
394
395 typedef struct linearapprox {
396 double scale;
397 unsigned int oneline: 1;
398 unsigned int onepoint: 1;
399 struct linelist *lines;
400 struct linearapprox *next;
401 } LinearApprox;
402
403 These are the lines used to approximate a :ref:`Spline <splinefont.Spline>` when
404 drawing it. They are cached so they don't need to be regenerated each time.
405 There's a different set of lines for every scale (as there is a different amount
406 of visible detail). They get freed and regenerated if the Spline changes.
407
408 .. code-block:: default
409 :name: splinefont.Spline
410
411 typedef struct spline1d {
412 double a, b, c, d;
413 } Spline1D;
414
415 typedef struct spline {
416 unsigned int islinear: 1;
417 unsigned int isticked: 1;
418 unsigned int isneeded: 1;
419 unsigned int isunneeded: 1;
420 unsigned int ishorvert: 1;
421 unsigned int order2: 1;
422 SplinePoint *from, *to;
423 Spline1D splines[2]; /* splines[0] is the x spline, splines[1] is y */
424 struct linearapprox *approx;
425 /* Possible optimizations:
426 Precalculate bounding box
427 Precalculate points of inflection
428 */
429 } Spline;
430
431 A spline runs from the ``from`` :ref:`SplinePoint <splinefont.SplinePoint>` to
432 the ``to`` SplinePoint. If both control points of a Spline are degenerate, then
433 the Spline is linear (actually there are some other case that will lead to
434 linear splines, sometimes these will be detected and turned into the canonical
435 case, other times they will not be). The remaining bits are used when processing
436 Splines in various functions. Most are used in the SplineOverlap routines, but
437 some are used in other places too.
438
439 The Spline1D structures give the equations for the x and y coordinates
440 respectively (splines[0] is for x, splines[1] is for y).
441
442 .. code-block:: default
443 :name: splinefont.SplinePointList
444
445 typedef struct splinepointlist {
446 SplinePoint *first, *last;
447 struct splinepointlist *next;
448 } SplinePointList, SplineSet;
449
450 A SplinePointList (or a SplineSet) is a collection of
451 :ref:`Spline <splinefont.Spline>`\ s and
452 :ref:`SplinePoint <splinefont.SplinePoint>`\ s. Every SplinePoint can connect to
453 two Splines (next and prev). Every Spline connects to two SplinePoints (from and
454 to). A SplinePointList is a connected path. There are three cases:
455
456 * ``first != last`` which means that we have an open path. Here first->prev==NULL
457 and last->next==NULL.
458 * ``first == last`` and :menuselection:`first --> prev==NULL` which means we have
459 a degenerate path consisting of a single point, and last->next==NULL as well
460 * ``first == last`` and :menuselection:`first --> prev!=NULL` which means we have
461 a closed path. This should be the most common case.
462
463 Generally a series of paths will make up a character, and they are linked
464 together on the next field.
465
466 .. code-block:: default
467 :name: splinefont.RefChar
468
469 typedef struct refchar {
470 int16 adobe_enc, orig_pos
471 int unicode_enc; /* used by paste */
472 double transform[6]; /* transformation matrix (first 2 rows of a 3x3 matrix, missing row is 0,0,1) */
473 SplinePointList *splines;
474 struct refchar *next;
475 unsigned int checked: 1;
476 unsigned int selected: 1;
477 DBounds bb;
478 struct splinechar *sc;
479 } RefChar;
480
481 A :ref:`SplineChar <splinefont.SplineChar>` may contain a reference to another
482 character. For instance "Agrave" might contain a reference to an "A" and a
483 "grave". There are three different encoding values, of which orig_pos is not
484 always up to date. Adobe_enc gives the location in the Adobe Standard Encoding
485 which is used by the seac command in type1 fonts. If this is -1 then the
486 character isn't in the adobe encoding and it won't be possible to put a
487 reference to it into a Type1 font (truetype doesn't have this restriction, it
488 has other ones). The transformation matrix is a standard postscript
489 transformation matrix (3 rows of 2 columns. First 2 rows provide standard
490 rotation/scaling/flipping/skewing/... transformations, last row provides for
491 translations. (Both postscript and truetype have restrictions on what kinds of
492 transformations are acceptable). The splines field provides a quick way of
493 drawing the referred character, it is the result of applying the transformation
494 matrix on all splines in the referred character. There may be several referred
495 characters and they are linked together on the next field. The checked field is
496 used to insure that we don't have any loops (ie. on characters which refer to
497 themselves). The selected field indicates that the reference is selected. The bb
498 field provides a transformed bounding box. And the sc field points to the
499 SplineChar we are referring to.
500
501 .. code-block:: default
502 :name: splinefont.KernPair
503
504 typedef struct kernpair {
505 struct splinechar *sc;
506 int off;
507 struct kernpair *next;
508 } KernPair;
509
510 If a character should be kerned with another, then this structure provides that
511 info. Every SplineChar has a linked list of KernPairs attached to it. In that
512 list the sc field indicates the other character in the pair, and off defines the
513 offset between them (or rather the difference from what their respective left
514 and right bearings would lead you to believe it should be). Next points to the
515 next kernpair.
516
517 .. code-block:: default
518 :name: splinefont.Hints
519
520 typedef struct hints {
521 double base, width;
522 double b1, b2, e1, e2;
523 double ab, ae;
524 unsigned int adjustb: 1;
525 unsigned int adjuste: 1;
526 struct hints *next;
527 } Hints;
528
529 The only important fields here are base, width and next. The others are used
530 temporarily by the SplineFill routines. Base gives the location (in either x or
531 y space) of where the stem starts, and width is how long it is. Width may be
532 negative (in which case base is where the stem ends). Next points to the next
533 hint for the character.
534
535 .. code-block:: default
536 :name: splinefont.ImageList
537
538 typedef struct imagelist {
539 struct gimage *image;
540 double xoff, yoff; /* position in character space of upper left corner of image */
541 double xscale, yscale; /* scale to convert one pixel of image to one unit of character space */
542 DBounds bb;
543 struct imagelist *next;
544 unsigned int selected: 1;
545 } ImageList;
546
547 SplineChars may have images in their backgrounds (or foregrounds for multilayer
548 characters). This structure contains a pointer to the image to be displayed, an
549 indication of where it should be positioned, and how it should be scaled (I do
550 not support any other transformations on images). The bounding box is after the
551 transformations have been applied. The next field points to the next image, and
552 selected indicates whether this one is selected or not.
553
554 .. code-block:: default
555 :name: splinefont.SplineChar
556
557 typedef struct splinechar {
558 char *name;
559 int enc, unicodeenc;
560 int width;
561 int16 lsidebearing; /* only used when reading in a type1 font */
562 int16 ttf_glyph; /* only used when writing out a ttf font */
563 SplinePointList *splines;
564 Hints *hstem; /* hstem hints have a vertical offset but run horizontally */
565 Hints *vstem; /* vstem hints have a horizontal offset but run vertically */
566 RefChar *refs;
567 struct charview *views; /* All CharViews that look at us */
568 struct splinefont *parent;
569 unsigned int changed: 1;
570 unsigned int changedsincelasthhinted: 1;
571 unsigned int changedsincelastvhinted: 1;
572 unsigned int manualhints: 1;
573 unsigned int ticked: 1; /* For reference character processing */
574 unsigned int changed_since_autosave: 1;
575 unsigned int widthset: 1; /* needed so an emspace char doesn't disappear */
576 struct splinecharlist { struct splinechar *sc; struct splinecharlist *next;} *dependents;
577 /* The dependents list is a list of all characters which reference*/
578 /* the current character directly */
579 SplinePointList *backgroundsplines;
580 ImageList *backimages;
581 Undoes *undoes[2];
582 Undoes *redoes[2];
583 KernPair *kerns;
584 uint8 *origtype1; /* The original type1 (unencoded) character string */
585 int origlen; /* its length. These get freed once the user has changed */
586 /* the character. Until then the preserve things like */
587 /* hint substitution which we wouldn't otherwise understand */
588 } SplineChar;
589
590 Every character has a name (sometimes it is ".notdef" but it's there). A
591 location (encoding) in the current font, a unicode code point (which may be -1
592 if not in unicode). Every character has a width. The next two fields are only
593 meaningful when loading or saving a font in the appropriate format. lbearing is
594 needed to handle seac commands, and the ttf_glyph is needed for just about
595 everything when writing a ttf font. The splines field gives all the foreground
596 paths (:ref:`SplinePointLists <splinefont.SplinePointList>`). Hints for
597 horizontal and vertical stems. A set of other characters referenced in this one,
598 again only in the foreground. Then a linked list of all CharViews displaying this
599 SplineChar (if this guy changes, all must be updated to reflect the change). A pointer
600 to the :ref:`SplineFont <splinefont.SplineFont>` that contains us. A set of bits:
601 changed means the character has changed since the last save to disk,
602 changedsincelasthhinted means that we need to run autohint on the horizontal
603 stems, changedsincelastvhinted for vertical stems. Manual hints means the user
604 has taken control of providing hints, and we should only run autohint if
605 explicitly asked to. Ticked is a temporary field usually to avoid infinite loops
606 of referred characters. changed_since_autosave indicates that the next time we
607 update our autosave database we should write this character to it. Widthset
608 means the user has changed the width. If we didn't have this bit we might think
609 that an em space had nothing in it (instead of having an em-space in it).
610
611 If a SplineChar is referred to in another character, then when we change the
612 original we must also update anything that refers to it (if we change A, we must
613 also redisplay Agrave).
614
615 Then backgroundsplines represent the SplinePointLists in the background layer,
616 and backimages represent the images in the background layers.
617
618 Undoes[0] contains undoes for the foreground and undoes[1] contains undoes for
619 the background. Same for redoes.
620
621 Finally kerns provides a list of kerning data for any special characters that
622 follow this one. For instance the combination "VA" might need kerning, then the
623 SplineChar representing "V" would have a pointer to a
624 :ref:`KernPair <splinefont.KernPair>` with data on "A".
625
626 .. code-block:: default
627 :name: splinefont.SplineFont
628
629 typedef struct splinefont {
630 char *fontname, *fullname, *familyname, *weight;
631 char *copyright;
632 char *filename;
633 char *version;
634 double italicangle, upos, uwidth;
635 int ascent, descent;
636 int glyphcnt;
637 SplineChar **glyphs;
638 unsigned int changed: 1;
639 unsigned int changed_since_autosave: 1;
640 unsigned int display_antialias: 1;
641 unsigned int dotlesswarn: 1; /* User warned that font doesn't have a dotless i character */
642 /*unsigned int wasbinary: 1;*/
643 struct fontview *fv;
644 enum charset encoding_name;
645 SplinePointList *gridsplines;
646 Undoes *gundoes, *gredoes;
647 BDFFont *bitmaps;
648 char *origname; /* filename of font file (ie. if not an sfd) */
649 char *autosavename;
650 int display_size;
651 } SplineFont;
652
653 The first four names are taken straight out of PostScript, as are copyright,
654 version, italicangle, underlinepos, underlineweight. Ascent and descent together
655 sum to make the em-square. Normally this will be 1000, but you can change that
656 if you want.
657
658 Charcnt says how big the chars array will be. There may be holes (ie. NULL
659 values) in the array.
660
661 Changed indicates that some character, bitmap, metric, something has changed
662 since we last saved the file. changed_since_autosave means that something has
663 changed since autosave last happened (so we should actually process this font
664 the next time autosave rolls around).
665
666 Display_antialias means we are displaying an antialias bytemap font in the
667 FontView, rather than a bitmap font. These look better but are slower.
668
669 Dotlesswarn means that we've warned the user when s/he attempted to create an
670 accented character based on i or j and a dotless version of those characters was
671 not present in the font (there's no point in warning him again. The operation
672 proceeded with a dotted version).
673
674 There is only one FontView associated with a font (other
675 data structures allowed for multiple views, but the font does not).
676
677 The font has a characterset and an encoding.
678
679 Gridsplines contains the :ref:`SplinePointLists <splinefont.SplinePointList>`
680 for all the splines displayed as background grids for characters. And gundoes
681 and gredoes are the un/redoes associated with them.
682
683 Bitmaps contains all the bitmaps that have been generated for this SplineFont.
684
685 Origname contains the name of the file we read in to get this one. Filename
686 above contains the name of an .sfd file associated with this font, but origname
687 can also contain random postscript or truetype fonts.
688
689 Autosavename indicates the name currently being used to save crash recovery
690 stuff to disk.
691
692 Display_size indicates how big we'd like the FontView to display our font.
693
694
695 Function declarations
696 ---------------------
697
698 ::
699
700 struct fontdict; /* the next four data structures are in psfont.h */
701 struct chars;
702 struct findsel;
703 struct charprocs;
704 enum charset; /* in charset.h */
705
706 extern SplineFont *SplineFontFromPSFont(struct fontdict *fd);
707 extern bool SFIsFixedWidth(SplineFont *sf);
708 extern struct chars *SplineFont2Chrs(SplineFont *sf, int round);
709 enum fontformat { ff_pfa, ff_pfb, ff_ptype3, ff_ptype0, ff_ttf, ff_none };
710 extern int WritePSFont(char *fontname,SplineFont *sf,enum fontformat format);
711 extern int WriteTTFFont(char *fontname,SplineFont *sf);
712 int SFReencodeFont(SplineFont *sf,enum charset new_map);
713
714 extern int DoubleNear(double a,double b);
715 extern int DoubleNearish(double a,double b);
716
717 extern void LineListFree(LineList *ll);
718 extern void LinearApproxFree(LinearApprox *la);
719 extern void SplineFree(Spline *spline);
720 extern void SplinePointFree(SplinePoint *sp);
721 extern void SplinePointListFree(SplinePointList *spl);
722 extern void SplinePointListsFree(SplinePointList *head);
723 extern void RefCharFree(RefChar *ref);
724 extern void RefCharsFree(RefChar *ref);
725 extern void UndoesFree(Undoes *undo);
726 extern void HintsFree(Hints *h);
727 extern Hints *HintsCopy(Hints *h);
728 extern SplineChar *SplineCharCopy(SplineChar *sc);
729 extern BDFChar *BDFCharCopy(BDFChar *bc);
730 extern void ImageListsFree(ImageList *imgs);
731 extern void SplineCharFree(SplineChar *sc);
732 extern void SplineFontFree(SplineFont *sf);
733 extern void SplineRefigure(Spline *spline);
734 extern Spline *SplineMake(SplinePoint *from, SplinePoint *to);
735 extern LinearApprox *SplineApproximate(Spline *spline, double scale);
736 extern int SplinePointListIsClockwise(SplineSet *spl);
737 extern void SplineSetFindBounds(SplinePointList *spl, DBounds *bounds);
738 extern void SplineCharFindBounds(SplineChar *sc,DBounds *bounds);
739 extern void SplineFontFindBounds(SplineFont *sf,DBounds *bounds);
740 extern void SplinePointCategorize(SplinePoint *sp);
741 extern void SCCategorizePoints(SplineChar *sc);
742 extern SplinePointList *SplinePointListCopy(SplinePointList *base);
743 extern SplinePointList *SplinePointListCopySelected(SplinePointList *base);
744 extern SplinePointList *SplinePointListTransform(SplinePointList *base, double transform[6], int allpoints );
745 extern SplinePointList *SplinePointListShift(SplinePointList *base, double xoff, int allpoints );
746 extern SplinePointList *SplinePointListRemoveSelected(SplinePointList *base);
747 extern void SplinePointListSet(SplinePointList *tobase, SplinePointList *frombase);
748 extern void SplinePointListSelect(SplinePointList *spl,int sel);
749 extern void SCRefToSplines(SplineChar *sc,RefChar *rf);
750 extern void SCReinstanciateRefChar(SplineChar *sc,RefChar *rf);
751 extern void SCReinstanciateRef(SplineChar *sc,SplineChar *rsc);
752 extern void SCRemoveDependent(SplineChar *dependent,RefChar *rf);
753 extern void SCRemoveDependents(SplineChar *dependent);
754 extern RefChar *SCCanonicalRefs(SplineChar *sc, int isps);
755 extern void BCCompressBitmap(BDFChar *bdfc);
756 extern void BCRegularizeBitmap(BDFChar *bdfc);
757 extern void BCPasteInto(BDFChar *bc,BDFChar *rbc,int ixoff,int iyoff, int invert);
758 extern BDFChar *SplineCharRasterize(SplineChar *sc, int pixelsize);
759 extern BDFFont *SplineFontRasterize(SplineFont *sf, int pixelsize);
760 extern BDFChar *SplineCharAntiAlias(SplineChar *sc, int pixelsize,int linear_scale);
761 extern BDFFont *SplineFontAntiAlias(SplineFont *sf, int pixelsize,int linear_scale);
762 extern void BDFCharFree(BDFChar *bdfc);
763 extern void BDFFontFree(BDFFont *bdf);
764 extern void BDFFontDump(char *filename,BDFFont *font, char *encodingname);
765 extern double SplineSolve(Spline1D *sp, double tmin, double tmax, double sought_y, double err);
766 extern void SplineFindInflections(Spline1D *sp, double *_t1, double *_t2 );
767 extern int NearSpline(struct findsel *fs, Spline *spline);
768 extern double SplineNearPoint(Spline *spline, BasePoint *bp, double fudge);
769 extern void SCMakeDependent(SplineChar *dependent,SplineChar *base);
770 extern SplinePoint *SplineBisect(Spline *spline, double t);
771 extern Spline *ApproximateSplineFromPoints(SplinePoint *from, SplinePoint *to,
772 TPoint *mid, int cnt);
773 extern int SplineIsLinear(Spline *spline);
774 extern int SplineInSplineSet(Spline *spline, SplineSet *spl);
775 extern void SplineCharMerge(SplineSet **head);
776 extern void SplineCharSimplify(SplineSet *head);
777 extern void SplineCharRemoveTiny(SplineSet *head);
778 extern SplineFont *SplineFontNew(void);
779 extern SplineFont *SplineFontBlank(int enc,int charcnt);
780 extern SplineSet *SplineSetReverse(SplineSet *spl);
781 extern SplineSet *SplineSetsExtractOpen(SplineSet **tbase);
782 extern SplineSet *SplineSetsCorrect(SplineSet *base);
783 extern void SPAverageCps(SplinePoint *sp);
784 extern void SplineCharDefaultPrevCP(SplinePoint *base, SplinePoint *prev);
785 extern void SplineCharDefaultNextCP(SplinePoint *base, SplinePoint *next);
786 extern void SplineCharTangentNextCP(SplinePoint *sp);
787 extern void SplineCharTangentPrevCP(SplinePoint *sp);
788 extern int PointListIsSelected(SplinePointList *spl);
789 extern void SplineSetsUntick(SplineSet *spl);
790 extern void SFOrderBitmapList(SplineFont *sf);
791
792 extern SplineSet *SplineSetStroke(SplineSet *spl,StrokeInfo *si);
793 extern SplineSet *SplineSetRemoveOverlap(SplineSet *base);
794
795 extern void FindBlues( SplineFont *sf, double blues[14], double otherblues[10]);
796 extern void FindHStems( SplineFont *sf, double snaps[12], double cnt[12]);
797 extern void FindVStems( SplineFont *sf, double snaps[12], double cnt[12]);
798 extern void SplineCharAutoHint( SplineChar *sc);
799 extern void SplineFontAutoHint( SplineFont *sf);
800 extern int AfmSplineFont(FILE *afm, SplineFont *sf,int type0);
801 extern char *EncodingName(int map);
802
803 extern int SFDWrite(char *filename,SplineFont *sf);
804 extern int SFDWriteBak(SplineFont *sf);
805 extern SplineFont *SFDRead(char *filename);
806 extern SplineFont *SFReadTTF(char *filename);
807 extern SplineFont *LoadSplineFont(char *filename);
808 extern SplineFont *ReadSplineFont(char *filename); /* Don't use this, use LoadSF instead */
809
810 extern SplineChar *SCBuildDummy(SplineChar *dummy,SplineFont *sf,int i);
811 extern SplineChar *SFMakeChar(SplineFont *sf,int i);
812 extern BDFChar *BDFMakeChar(BDFFont *bdf,int i);
813
814 extern void SCUndoSetLBearingChange(SplineChar *sc,int lb);
815 extern Undoes *SCPreserveState(SplineChar *sc);
816 extern Undoes *SCPreserveWidth(SplineChar *sc);
817 extern Undoes *BCPreserveState(BDFChar *bc);
818 extern void BCDoRedo(BDFChar *bc,struct fontview *fv);
819 extern void BCDoUndo(BDFChar *bc,struct fontview *fv);
820
821 extern int SFIsCompositBuildable(SplineFont *sf,int unicodeenc);
822 extern void SCBuildComposit(SplineFont *sf, SplineChar *sc, int copybmp,
823 struct fontview *fv);
824
825 extern void BDFFontDump(char *filename,BDFFont *font, char *encodingname);
826 extern int getAdobeEnc(char *name);
827
828 extern SplinePointList *SplinePointListInterpretPS(FILE *ps);
829 extern void PSFontInterpretPS(FILE *ps,struct charprocs *cp);
830
831 extern int SFFindChar(SplineFont *sf, int unienc, char *name );
832
833 extern char *getFontForgeDir(char *buffer);
834 extern void DoAutoSaves(void);
835 extern int DoAutoRecovery(void);
836 extern SplineFont *SFRecoverFile(char *autosavename);
837 extern void SFAutoSave(SplineFont *sf);
838 extern void SFClearAutoSave(SplineFont *sf);
839 #endif