added cmap support
[swftools.git] / lib / ttf.h
1 /* ttf.h
2    Parser and writer for truetype font files.
3
4    Part of the swftools package.
5    
6    Copyright (c) 2010 Matthias Kramm <kramm@quiss.org> 
7  
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #ifndef __ttf_h__
23 #define __ttf_h__
24
25 #include "types.h"
26
27 typedef struct _ttf_table {
28     U32 id;
29     struct _ttf_table*prev;
30     struct _ttf_table*next;
31
32     U8*data;
33     int len;
34     int memsize;
35 } ttf_table_t;
36
37 typedef struct _table_maxp {
38     U16 maxPoints;
39     U16 maxContours;
40     U16 maxComponentPoints;
41     U16 maxComponentContours;
42     U16 maxZones;
43     U16 maxTwilightPoints;
44     U16 maxStorage;
45     U16 maxFunctionDefs;
46     U16 maxInstructionDefs;
47     U16 maxStackElements;
48     U16 maxSizeOfInstructions;
49     U16 maxComponentElements;
50     U16 maxComponentDepth;
51 } table_maxp_t;
52
53 typedef struct _table_os2 {
54     S16 xAvgCharWidth;
55     U16 usWeightClass;
56     U16 usWidthClass;
57     U16 fsType;
58     U16 ySubscriptXSize;
59     U16 ySubscriptYSize;
60     U16 ySubscriptXOffset;
61     U16 ySubscriptYOffset;
62     U16 ySuperscriptXSize;
63     U16 ySuperscriptYSize;
64     U16 ySuperscriptXOffset;
65     U16 ySuperscriptYOffset;
66     U16 yStrikeoutSize;
67     U16 yStrikeoutPosition;
68     U16 sFamilyClass;
69     U8 panose_FamilyType;
70     U8 panose_SerifStyle;
71     U8 panose_Weight;
72     U8 panose_Proportion;
73     U8 panose_Contrast;
74     U8 panose_StrokeVariation;
75     U8 panose_ArmStyle;
76     U8 panose_Letterform;
77     U8 panose_Midline;
78     U8 panose_XHeight;
79     U32 ulCharRange[4];
80     U8 achVendID[4];
81
82     U16 fsSelection;
83     U16 fsFirstCharIndex;
84     U16 fsLastCharIndex;
85
86     S16 sTypoAscender;
87     S16 sTypoDescender;
88     S16 sTypoLineGap;
89     U16 usWinAscent;
90     U16 usWinDescent;
91
92     /* for version >= 0x0001 */
93     U32 ulCodePageRange1;
94     U32 ulCodePageRange2;
95     
96     /* for version >= 0x0002 */
97     S16 sxHeight;
98     S16 sCapHeight;
99     U16 usDefaultChar;
100     U16 usBreakChar;
101     U16 usMaxContext;
102 } table_os2_t;
103
104 typedef struct _table_hea
105 {
106     S16 ascent;
107     S16 descent;
108     S16 lineGap;
109     U16 advanceWidthMax;
110     S16 minLeftSideBearing;
111     S16 minRightSideBearing;
112     S16 xMaxExtent;
113     S16 caretSlopeRise;
114     S16 caretSlopeRun;
115     S16 caretOffset;
116 } table_hea_t;
117
118 #define GLYPH_ON_CURVE 0x01
119 #define GLYPH_CONTOUR_START 0x40
120 #define GLYPH_CONTOUR_END 0x80
121
122 typedef U32 unicode_t;
123
124 typedef struct _ttfpoint {
125     int x,y;
126     U8 flags;
127 } ttfpoint_t;
128 typedef struct _ttfglyph {
129     U16 advance;
130     U16 bearing;
131     S16 xmin,ymin,xmax,ymax;
132     int code_size;
133     U8*code;
134     int num_points;
135     ttfpoint_t*points;
136 } ttfglyph_t;
137
138 typedef struct _table_head {
139     U16 flags;
140     U16 units_per_em;
141     S16 xmin,ymin,xmax,ymax;
142     U16 macStyle;
143     U16 lowest_readable_size;
144     S16 dir_hint;
145 } table_head_t;
146
147 typedef struct _ttf {
148     ttf_table_t*tables;
149
150     table_head_t*head;
151     table_maxp_t*maxp;
152     table_os2_t*os2;
153     table_hea_t*hea;
154
155     U16 flags;
156     char is_vertical;
157     int num_glyphs;
158     ttfglyph_t*glyphs;
159     
160     int unicode_size;
161     unicode_t*unicode;
162
163     U32 version;
164 } ttf_t;
165
166
167 ttf_t*load_ttf(void*data, int length);
168 ttf_table_t*ttf_addtable(ttf_t*ttf, U32 tag);
169
170 #endif