]> git.donarmstrong.com Git - xournal.git/blob - src/sft.h
workaround for GTK+ 2.17 crasher bugs (text edit box, combo box)
[xournal.git] / src / sft.h
1 /* modified from sft.h in libgnomeprint */
2
3 /*
4  * Copyright © 2002, 2003 Sun Microsystems, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of Sun Microsystems, Inc. nor the names of 
19  *    contributors may be used to endorse or promote products derived from
20  *    this software without specific prior written permission.
21  *
22  * This software is provided "AS IS," without a warranty of any kind.
23  *
24  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
25  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
26  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
27  * SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR
28  * LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR RELATING TO USE,
29  * MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES.
30  * IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
31  * PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
32  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
33  * THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
34  * SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
35  *
36  */
37
38 /* $Id$ */
39
40 /* @(#)sft.h 1.17 03/01/08 SMI */
41
42 /*
43  * @file sft.h
44  * @brief Sun Font Tools
45  * @author Alexander Gelfenbain <adg@sun.com>
46  * @version 1.0
47  */
48
49 /*
50  *        Generated fonts contain an XUID entry in the form of:
51  *
52  *                  103 0 T C1 N C2 C3
53  *
54  *        103 - Sun's Adobe assigned XUID number. Contact person: Alexander Gelfenbain <gelf@eng.sun.com>
55  *
56  *        T  - font type. 0: Type 3, 1: Type 42
57  *        C1 - CRC-32 of the entire source TrueType font
58  *        N  - number of glyphs in the subset
59  *        C2 - CRC-32 of the array of glyph IDs used to generate the subset
60  *        C3 - CRC-32 of the array of encoding numbers used to generate the subset
61  *
62  */
63  
64
65 #ifndef __SUBFONT_H
66 #define __SUBFONT_H
67
68 #include <sys/types.h>
69 #include <unistd.h>
70 #include <stdio.h>
71
72 #define false 0               /**< standard false value */
73 #define true  1               /**< standard true value */
74
75 /* glib already deals with different compilers */
76 #include <glibconfig.h>
77
78 /*@{*/
79     typedef gint16       F2Dot14;            /**< fixed: 2.14 */
80     typedef gint32       F16Dot16;           /**< fixed: 16.16 */
81 /*@}*/
82
83     typedef struct {
84         guint16 s;
85         guint16 d;
86     } uint16pair;
87
88 /** Return value of OpenTTFont() and CreateT3FromTTGlyphs() */
89     enum SFErrCodes {
90         SF_OK,                              /**< no error                                     */
91         SF_BADFILE,                         /**< file not found                               */
92         SF_FILEIO,                          /**< file I/O error                               */
93         SF_MEMORY,                          /**< memory allocation error                      */
94         SF_GLYPHNUM,                        /**< incorrect number of glyphs                   */
95         SF_BADARG,                          /**< incorrect arguments                          */
96         SF_TTFORMAT,                        /**< incorrect TrueType font format               */
97         SF_TABLEFORMAT,                     /**< incorrect format of a TrueType table         */
98         SF_FONTNO                           /**< incorrect logical font number of a TTC font  */
99     };
100
101 #ifndef FW_THIN /* WIN32 compilation would conflict */
102 /** Value of the weight member of the TTGlobalFontInfo struct */
103     enum WeightClass {
104         FW_THIN = 100,                      /**< Thin                               */
105         FW_EXTRALIGHT = 200,                /**< Extra-light (Ultra-light)          */
106         FW_LIGHT = 300,                     /**< Light                              */
107         FW_NORMAL = 400,                    /**< Normal (Regular)                   */
108         FW_MEDIUM = 500,                    /**< Medium                             */
109         FW_SEMIBOLD = 600,                  /**< Semi-bold (Demi-bold)              */
110         FW_BOLD = 700,                      /**< Bold                               */
111         FW_EXTRABOLD = 800,                 /**< Extra-bold (Ultra-bold)            */
112         FW_BLACK = 900                      /**< Black (Heavy)                      */
113     };
114
115 /** Value of the width member of the TTGlobalFontInfo struct */
116     enum WidthClass {
117         FWIDTH_ULTRA_CONDENSED = 1,         /**< 50% of normal                      */
118         FWIDTH_EXTRA_CONDENSED = 2,         /**< 62.5% of normal                    */
119         FWIDTH_CONDENSED = 3,               /**< 75% of normal                      */
120         FWIDTH_SEMI_CONDENSED = 4,          /**< 87.5% of normal                    */
121         FWIDTH_NORMAL = 5,                  /**< Medium, 100%                       */
122         FWIDTH_SEMI_EXPANDED = 6,           /**< 112.5% of normal                   */
123         FWIDTH_EXPANDED = 7,                /**< 125% of normal                     */
124         FWIDTH_EXTRA_EXPANDED = 8,          /**< 150% of normal                     */
125         FWIDTH_ULTRA_EXPANDED = 9           /**< 200% of normal                     */
126     };
127 #endif /* FW_THIN */
128
129 /** Type of the 'kern' table, stored in _TrueTypeFont::kerntype */
130     enum KernType {
131
132         KT_NONE         = 0,                /**< no kern table                      */
133         KT_APPLE_NEW    = 1,                /**< new Apple kern table               */
134         KT_MICROSOFT    = 2                 /**< Microsoft table                    */
135     };
136
137 /* Composite glyph flags definition */
138     enum CompositeFlags {
139         ARG_1_AND_2_ARE_WORDS     = 1,
140         ARGS_ARE_XY_VALUES        = 1<<1,
141         ROUND_XY_TO_GRID          = 1<<2,
142         WE_HAVE_A_SCALE           = 1<<3,
143         MORE_COMPONENTS           = 1<<5,
144         WE_HAVE_AN_X_AND_Y_SCALE  = 1<<6,
145         WE_HAVE_A_TWO_BY_TWO      = 1<<7,
146         WE_HAVE_INSTRUCTIONS      = 1<<8,
147         USE_MY_METRICS            = 1<<9,
148         OVERLAP_COMPOUND          = 1<<10
149     };
150
151 /** Flags for TrueType generation */
152     enum TTCreationFlags {
153         TTCF_AutoName = 1,                  /**< Automatically generate a compact 'name' table.
154                                                If this flag is not set, name table is generated
155                                                either from an array of NameRecord structs passed as
156                                                arguments or if the array is NULL, 'name' table
157                                                of the generated TrueType file will be a copy
158                                                of the name table of the original file.
159                                                If this flag is set the array of NameRecord structs
160                                                is ignored and a very compact 'name' table is automatically
161                                                generated. */
162
163         TTCF_IncludeOS2 = 2                 /** If this flag is set OS/2 table from the original font will be
164                                                 copied to the subset */
165     };
166
167     /** Structure used by GetTTGlyphMetrics() */
168     /*- In horisontal writing mode right sidebearing is calculated using this formula
169      *- rsb = aw - (lsb + xMax - xMin) -*/
170      typedef struct {
171          gint16  xMin;
172          gint16  yMin;
173          gint16  xMax;
174          gint16  yMax;
175          guint16 aw;                /*- Advance Width (horisontal writing mode)    */
176          gint16  lsb;               /*- Left sidebearing (horisontal writing mode) */
177          guint16 ah;                /*- advance height (vertical writing mode)     */
178          gint16  tsb;               /*- top sidebearing (vertical writing mode)    */
179      } TTGlyphMetrics;
180
181
182     /** Structure used by GetTTSimpleGlyphMetrics() and GetTTSimpleCharMetrics() functions */
183     typedef struct {
184         guint16 adv;                         /**< advance width or height            */
185         gint16 sb;                           /**< left or top sidebearing            */
186     } TTSimpleGlyphMetrics;
187
188     /** Structure returned by ReadGlyphMetrics() */
189     typedef struct {
190         guint16 aw, ah;
191         gint16 lsb, tsb;
192     } TTFullSimpleGlyphMetrics;
193
194
195 /** Structure used by the TrueType Creator and GetRawGlyphData() */
196
197     typedef struct {
198         guint32 glyphID;                     /**< glyph ID                           */
199         guint16 nbytes;                      /**< number of bytes in glyph data      */
200         guint8  *ptr;                         /**< pointer to glyph data              */
201         guint16 aw;                          /**< advance width                      */
202         gint16  lsb;                         /**< left sidebearing                   */
203         guint16 compflag;                    /**< 0- if non-composite, 1- otherwise  */
204         guint16 npoints;                     /**< number of points                   */
205         guint16 ncontours;                   /**< number of contours                 */
206         /* */
207         guint32 newID;                       /**< used internally by the TTCR        */
208     } GlyphData;
209
210
211     /* STSF defines NameRecord and FUnitBBox structures in its own include file sttypes.h */
212
213     typedef struct {
214         gint16 xMin;
215         gint16 yMin;
216         gint16 xMax;
217         gint16 yMax;
218     } FUnitBBox;
219
220 /** Structure used by the TrueType Creator and CreateTTFromTTGlyphs() */
221     typedef struct {
222         guint16 platformID;                  /**< Platform ID                                            */
223         guint16 encodingID;                  /**< Platform-specific encoding ID                          */
224         guint16 languageID;                  /**< Language ID                                            */
225         guint16 nameID;                      /**< Name ID                                                */
226         guint16 slen;                        /**< String length in bytes                                 */
227         guint8  *sptr;                        /**< Pointer to string data (not zero-terminated!)          */
228     } NameRecord;
229
230
231 /** Return value of GetTTGlobalFontInfo() */
232
233     typedef struct {
234         char *family;             /**< family name                                             */
235         guint16 *ufamily;                 /**< family name UCS2                                         */
236         char *subfamily;          /**< subfamily name                                          */
237         char *psname;             /**< PostScript name                                         */
238         int   weight;             /**< value of WeightClass or 0 if can't be determined        */
239         int   width;              /**< value of WidthClass or 0 if can't be determined         */
240         int   pitch;              /**< 0: proportianal font, otherwise: monospaced             */
241         int   italicAngle;        /**< in counter-clockwise degrees * 65536                    */
242         guint16 fsSelection;       /**< fsSelection field of OS/2 table                         */
243         int   xMin;               /**< global bounding box: xMin                               */
244         int   yMin;               /**< global bounding box: yMin                               */
245         int   xMax;               /**< global bounding box: xMax                               */
246         int   yMax;               /**< global bounding box: yMax                               */
247         int   ascender;           /**< typographic ascent.                                     */
248         int   descender;          /**< typographic descent.                                    */
249         int   linegap;            /**< typographic line gap.\ Negative values are treated as
250                                      zero in Win 3.1, System 6 and System 7.                 */
251         int   vascent;            /**< typographic ascent for vertical writing mode            */
252         int   vdescent;           /**< typographic descent for vertical writing mode           */
253         int   typoAscender;       /**< OS/2 portable typographic ascender                      */
254         int   typoDescender;      /**< OS/2 portable typographic descender                     */
255         int   typoLineGap;        /**< OS/2 portable typographc line gap                       */
256         int   winAscent;          /**< ascender metric for Windows                             */
257         int   winDescent;         /**< descender metric for Windows                            */
258         int   symbolEncoded;      /**< 1: MS symbol encoded 0: not symbol encoded              */
259         int   rangeFlag;          /**< if set to 1 Unicode Range flags are applicable          */
260         guint32 ur1;               /**< bits 0 - 31 of Unicode Range flags                      */
261         guint32 ur2;               /**< bits 32 - 63 of Unicode Range flags                     */
262         guint32 ur3;               /**< bits 64 - 95 of Unicode Range flags                     */
263         guint32 ur4;               /**< bits 96 - 127 of Unicode Range flags                    */
264         guint8   panose[10];        /**< PANOSE classification number                            */
265         guint16 typeFlags;                /**< type flags (copyright information)                      */
266     } TTGlobalFontInfo;
267
268 /** Structure used by KernGlyphs()      */
269     typedef struct {
270         int x;                    /**< positive: right, negative: left                        */
271         int y;                    /**< positive: up, negative: down                           */
272     } KernData;
273
274
275 /** ControlPoint structure used by GetTTGlyphPoints() */
276     typedef struct {
277         guint32 flags;             /**< 00000000 00000000 e0000000 bbbbbbbb */
278         /**< b - guint8 flags from the glyf array  */
279         /**< e == 0 - regular point              */
280         /**< e == 1 - end contour                */
281         gint16 x;                  /**< X coordinate in EmSquare units      */
282         gint16 y;                  /**< Y coordinate in EmSquare units      */
283     } ControlPoint;
284
285     typedef struct _TrueTypeFont TrueTypeFont;
286
287 /*
288  * @defgroup sft Sun Font Tools Exported Functions
289  */
290
291
292 /*
293  * Get the number of fonts contained in a TrueType collection
294  * @param  fname - file name
295  * @return number of fonts or zero, if file is not a TTC file.
296  * @ingroup sft
297  */
298     int CountTTCFonts(const char* fname);
299
300
301 /*
302  * TrueTypeFont constructor. 
303  * Reads the font file and allocates the memory for the structure.
304  * @param  facenum - logical font number within a TTC file. This value is ignored
305  *                   for TrueType fonts
306  * @return value of SFErrCodes enum
307  * @ingroup sft
308  */
309     int  OpenTTFont(const char *fname, guint32 facenum, TrueTypeFont**);
310
311 /*
312  * TrueTypeFont destructor. Deallocates the memory.
313  * @ingroup sft
314  */
315     void CloseTTFont(TrueTypeFont *);
316
317 /*
318  * Extracts TrueType control points, and stores them in an allocated array pointed to
319  * by *pointArray. This function returns the number of extracted points.
320  *
321  * @param ttf         pointer to the TrueTypeFont structure
322  * @param glyphID     Glyph ID
323  * @param pointArray  Return value - address of the pointer to the first element of the array
324  *                    of points allocated by the function
325  * @return            Returns the number of points in *pointArray or -1 if glyphID is
326  *                    invalid.
327  * @ingroup sft
328  *
329  */
330 int GetTTGlyphPoints(TrueTypeFont *ttf, guint32 glyphID, ControlPoint **pointArray);
331
332 /*
333  * Extracts bounding boxes in normalized FUnits (1000/em) for all glyphs in the
334  * font and allocates an array of FUnitBBox structures. There are ttf->nglyphs
335  * elements in the array.
336  *
337  * @param ttf     pointer to the TrueTypeFont structure
338  *
339  * @return        an array of FUnitBBox structures with values normalized to 1000 UPEm
340  *
341  * @ingroup sft
342  */
343 FUnitBBox *GetTTGlyphBoundingBoxes(TrueTypeFont *ttf);
344
345 /*
346  * Extracts raw glyph data from the 'glyf' table and returns it in an allocated
347  * GlyphData structure.
348  *
349  * @param ttf         pointer to the TrueTypeFont structure
350  * @param glyphID     Glyph ID
351  *
352  * @return            pointer to an allocated GlyphData structure or NULL if
353  *                    glyphID is not present in the font
354  * @ingroup sft
355  *
356  */
357     GlyphData *GetTTRawGlyphData(TrueTypeFont *ttf, guint32 glyphID);
358
359 /*
360  * Extracts all Name Records from the font and stores them in an allocated
361  * array of NameRecord structs
362  *
363  * @param ttf       pointer to the TrueTypeFont struct
364  * @param nr        pointer to the array of NameRecord structs
365  *
366  * @return          number of NameRecord structs
367  * @ingroup sft
368  */
369
370     int GetTTNameRecords(TrueTypeFont *ttf, NameRecord **nr);
371
372 /*
373  * Deallocates previously allocated array of NameRecords.
374  *
375  * @param nr        array of NameRecord structs
376  * @param n         number of elements in the array
377  *
378  * @ingroup sft
379  */
380     void DisposeNameRecords(NameRecord* nr, int n);
381
382
383 #ifndef NO_TYPE3
384 /*
385  * Generates a new PostScript Type 3 font and dumps it to <b>outf</b> file.
386  * This functions subsititues glyph 0 for all glyphIDs that are not found in the font.
387  * @param ttf         pointer to the TrueTypeFont structure
388  * @param outf        the resulting font is written to this stream
389  * @param fname       font name for the new font. If it is NULL the PostScript name of the
390  *                    original font will be used
391  * @param glyphArray  pointer to an array of glyphs that are to be extracted from ttf
392  * @param encoding    array of encoding values. encoding[i] specifies the position of the glyph
393  *                    glyphArray[i] in the encoding vector of the resulting Type3 font
394  * @param nGlyphs     number of glyph IDs in glyphArray and encoding values in encoding
395  * @param wmode       writing mode for the output file: 0 - horizontal, 1 - vertical
396  * @return            return the value of SFErrCodes enum
397  * @see               SFErrCodes
398  * @ingroup sft
399  *
400  */
401     int  CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname, guint16 *glyphArray, guint8 *encoding, int nGlyphs, int wmode);
402 #endif
403
404 #ifndef NO_TTCR
405 /*
406  * Generates a new TrueType font and dumps it to <b>outf</b> file.
407  * This functions subsititues glyph 0 for all glyphIDs that are not found in the font.
408  * @param ttf         pointer to the TrueTypeFont structure
409  * @param fname       file name for the output TrueType font file
410  * @param glyphArray  pointer to an array of glyphs that are to be extracted from ttf. The first
411  *                    element of this array has to be glyph 0 (default glyph)
412  * @param encoding    array of encoding values. encoding[i] specifies character code for
413  *                    the glyphID glyphArray[i]. Character code 0 usually points to a default
414  *                    glyph (glyphID 0)
415  * @param nGlyphs     number of glyph IDs in glyphArray and encoding values in encoding
416  * @param nNameRecs   number of NameRecords for the font, if 0 the name table from the
417  *                    original font will be used
418  * @param nr          array of NameRecords
419  * @param flags       or'ed TTCreationFlags
420  * @return            return the value of SFErrCodes enum
421  * @see               SFErrCodes
422  * @ingroup sft
423  *
424  */
425     int  CreateTTFromTTGlyphs(TrueTypeFont  *ttf,
426                               const char    *fname,
427                               guint16        *glyphArray,
428                               guint8          *encoding,
429                               int            nGlyphs,
430                               int            nNameRecs,
431                               NameRecord    *nr,
432                               guint32        flags);
433 #endif
434
435 #ifndef NO_TYPE42
436 /*
437  * Generates a new PostScript Type42 font and dumps it to <b>outf</b> file.
438  * This functions subsititues glyph 0 for all glyphIDs that are not found in the font.
439  * @param ttf         pointer to the TrueTypeFont structure
440  * @param outf        output stream for a resulting font
441  * @param psname      PostScript name of the resulting font
442  * @param glyphArray  pointer to an array of glyphs that are to be extracted from ttf. The first
443  *                    element of this array has to be glyph 0 (default glyph)
444  * @param encoding    array of encoding values. encoding[i] specifies character code for
445  *                    the glyphID glyphArray[i]. Character code 0 usually points to a default
446  *                    glyph (glyphID 0)
447  * @param nGlyphs     number of glyph IDs in glyphArray and encoding values in encoding
448  * @return            SF_OK - no errors
449  *                    SF_GLYPHNUM - too many glyphs (> 255)
450  *                    SF_TTFORMAT - corrupted TrueType fonts
451  *
452  * @see               SFErrCodes
453  * @ingroup sft
454  *
455  */
456     int  CreateT42FromTTGlyphs(TrueTypeFont  *ttf,
457                                FILE          *outf,
458                                const char    *psname,
459                                guint16        *glyphArray,
460                                guint8          *encoding,
461                                int            nGlyphs);
462 #endif
463
464 /*
465  * Queries full glyph metrics for one glyph
466  */
467 void GetTTGlyphMetrics(TrueTypeFont *ttf, guint32 glyphID, TTGlyphMetrics *metrics);
468
469
470 /*
471  * Queries glyph metrics. Allocates an array of TTSimpleGlyphMetrics structs and returns it.
472  *
473  * @param ttf         pointer to the TrueTypeFont structure
474  * @param glyphArray  pointer to an array of glyphs that are to be extracted from ttf
475  * @param nGlyphs     number of glyph IDs in glyphArray and encoding values in encoding
476  * @param mode        writing mode: 0 - horizontal, 1 - vertical
477  * @ingroup sft
478  *
479  */
480 TTSimpleGlyphMetrics *GetTTSimpleGlyphMetrics(TrueTypeFont *ttf, guint16 *glyphArray, int nGlyphs, int mode);
481
482 #ifndef NO_MAPPERS
483 /*
484  * Queries character metrics. Allocates an array of TTSimpleGlyphMetrics structs and returns it.
485  * This function behaves just like GetTTSimpleGlyphMetrics() but it takes a range of Unicode
486  * characters instead of an array of glyphs.
487  *
488  * @param ttf         pointer to the TrueTypeFont structure
489  * @param firstChar   Unicode value of the first character in the range
490  * @param nChars      number of Unicode characters in the range
491  * @param mode        writing mode: 0 - horizontal, 1 - vertical
492  *
493  * @see GetTTSimpleGlyphMetrics
494  * @ingroup sft
495  *
496  */
497     TTSimpleGlyphMetrics *GetTTSimpleCharMetrics(TrueTypeFont *ttf, guint16 firstChar, int nChars, int mode);
498
499 /*
500  * Maps a Unicode (UCS-2) string to a glyph array. Returns the number of glyphs in the array,
501  * which for TrueType fonts is always the same as the number of input characters.
502  *
503  * @param ttf         pointer to the TrueTypeFont structure
504  * @param str         pointer to a UCS-2 string
505  * @param nchars      number of characters in <b>str</b>
506  * @param glyphArray  pointer to the glyph array where glyph IDs are to be recorded.
507  *
508  * @return MapString() returns -1 if the TrueType font has no usable 'cmap' tables.
509  *         Otherwise it returns the number of characters processed: <b>nChars</b>
510  *
511  * glyphIDs of TrueType fonts are 2 guint8 positive numbers. glyphID of 0 denotes a missing
512  * glyph and traditionally defaults to an empty square.
513  * glyphArray should be at least sizeof(guint16) * nchars bytes long. If glyphArray is NULL
514  * MapString() replaces the UCS-2 characters in str with glyphIDs.
515  * @ingroup sft
516  */
517 #ifdef USE_GSUB
518     int MapString(TrueTypeFont *ttf, guint16 *str, int nchars, guint16 *glyphArray, int bvertical);
519 #else
520     int MapString(TrueTypeFont *ttf, guint16 *str, int nchars, guint16 *glyphArray);
521 #endif
522
523 /*
524  * Maps a Unicode (UCS-2) character to a glyph ID and returns it. Missing glyph has
525  * a glyphID of 0 so this function can be used to test if a character is encoded in the font.
526  *
527  * @param ttf         pointer to the TrueTypeFont structure
528  * @param ch          Unicode (UCS-2) character
529  * @return glyph ID, if the character is missing in the font, the return value is 0.
530  * @ingroup sft
531  */
532 #ifdef USE_GSUB
533     guint16 MapChar(TrueTypeFont *ttf, guint16 ch, int bvertical);
534 #else
535     guint16 MapChar(TrueTypeFont *ttf, guint16 ch);
536 #endif
537 #endif
538
539 /*
540  * Returns global font information about the TrueType font.
541  * @see TTGlobalFontInfo
542  *
543  * @param ttf         pointer to a TrueTypeFont structure
544  * @param info        pointer to a TTGlobalFontInfo structure
545  * @ingroup sft
546  *
547  */
548     void GetTTGlobalFontInfo(TrueTypeFont *ttf, TTGlobalFontInfo *info);
549
550 /*
551  * Returns kerning information for an array of glyphs.
552  * Kerning is not cumulative.
553  * kern[i] contains kerning information for a pair of glyphs at positions i and i+1
554  *
555  * @param ttf         pointer to a TrueTypeFont structure
556  * @param glyphs      array of source glyphs
557  * @param nglyphs     number of glyphs in the array
558  * @param wmode       writing mode: 0 - horizontal, 1 - vertical
559  * @param kern        array of KernData structures. It should contain nglyphs-1 elements
560  * @see KernData
561  * @ingroup sft
562  *
563  */
564 void KernGlyphs(TrueTypeFont *ttf, guint16 *glyphs, int nglyphs, int wmode, KernData *kern);
565
566 /*
567  * Returns nonzero if font is a symbol encoded font
568  */
569 int CheckSymbolEncoding(TrueTypeFont* ttf);
570
571 /*
572  * Extracts a 'cmap' table from a font, allocates memory for it and returns a pointer to it.
573  * DEPRECATED - use ExtractTable instead
574  */
575 #if 0
576 guint8 *ExtractCmap(TrueTypeFont *ttf);
577 #endif
578
579 /*
580  * Extracts a table from a font, allocates memort for it and returns a pointer to it.
581  */
582 guint8 *ExtractTable(TrueTypeFont *ttf, guint32 tag);
583
584 /*
585  * Returns a pointer to the table but does not allocate memory for it.
586  */
587 const guint8 *GetTable(TrueTypeFont *ttf, guint32 tag);
588
589 /*
590  * Functions that do not use TrueTypeFont structure
591  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
592  */
593
594 /*
595  * Reads full (vertical and horisontal) glyph metrics for an array of glyphs from hmtx and vmtx tables
596  *
597  * @param hmtx       TrueType hmtx table
598  * @param vmtx       TrueType vmtx table
599  * @param hcount     numberOfHMetrics value
600  * @param vcount     numOfLongVerMetrics value
601  * @param gcount     total number of glyphs in the font
602  * @param UPEm       units per Em value
603  * @param glyphArray array of source glyph IDs
604  * @param nGlyphs    number of glyphs in the glyphArray array
605  *
606  * @return           array of TTFullSimpleGlyphMetrics data structures
607  *
608  */
609
610 TTFullSimpleGlyphMetrics *ReadGlyphMetrics(guint8 *hmtx, guint8 *vmtx, int hcount, int vcount, int gcount, int UPEm, guint16 *glyphArray, int nGlyphs);
611
612 void ReadSingleGlyphMetrics(guint8 *hmtx, guint8 *vmtx, int hcount, int vcount, int gcount, int UPEm, guint16 glyphID, TTFullSimpleGlyphMetrics *metrics);
613
614
615 /*
616  * Returns the length of the 'kern' subtable
617  *
618  * @param kern       pointer to the 'kern' subtable
619  *
620  * @return           number of bytes in it
621  */
622 guint32 GetKernSubtableLength(guint8 *kern);
623
624 /*
625  *  Kerns a pair of glyphs.
626  *
627  * @param kerntype   type of the kern table
628  * @param nkern      number of kern subtables
629  * @param kern       array of pointers to kern subtables
630  * @pram unitsPerEm  units per Em value
631  * @param wmode      writing mode: 0 - horizontal, 1 - vertical
632  * @param a          ID of the first glyoh
633  * @param b          ID of the second glyoh
634  * @param x          X-axis kerning value is returned here
635  * @param y          Y-axis kerning value is returned here
636  */
637 void KernGlyphPair(int kerntype, guint32 nkern, guint8 **kern, int unitsPerEm, int wmode, guint32 a, guint32 b, int *x, int *y);
638
639
640
641 /*- private definitions */ /*FOLD00*/
642
643 struct _TrueTypeFont {
644     guint32 tag;
645
646     char   *fname;
647     off_t  fsize;
648     guint8   *ptr;
649
650     char   *psname;
651     char   *family;
652     guint16  *ufamily;
653     char   *subfamily;
654
655     guint32 ntables;
656     guint32 tdoffset;                              /* offset to the table directory (!= 0 for TrueType collections)      */
657     guint32 *goffsets;
658     int    nglyphs;
659     int    unitsPerEm;
660     int    numberOfHMetrics;
661     int    numOfLongVerMetrics;                   /* if this number is not 0, font has vertical metrics information */
662     guint8   *cmap;
663     int    cmapType;
664     guint16 (*mapper)(const guint8 *, guint16);       /* character to glyphID translation function                          */
665     void   **tables;                              /* array of pointers to tables                                        */
666     guint32 *tlens;                                /* array of table lengths                                             */
667     int    kerntype;                              /* Defined in the KernType enum                                       */
668     guint32 nkern;                                 /* number of kern subtables                                           */
669     guint8   **kerntables;                          /* array of pointers to kern subtables                                */
670 #ifdef USE_GSUB
671     void   *pGSubstitution;                       /* info provided by GSUB for UseGSUB()                                */
672 #endif
673 #if 0
674     GnomePrintBuffer gp_buf;
675 #endif
676 };
677
678 #endif /* __SUBFONT_H */