• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ttgxvar.h                                                              */
4 /*                                                                         */
5 /*    TrueType GX Font Variation loader (specification)                    */
6 /*                                                                         */
7 /*  Copyright 2004-2017 by                                                 */
8 /*  David Turner, Robert Wilhelm, Werner Lemberg and George Williams.      */
9 /*                                                                         */
10 /*  This file is part of the FreeType project, and may only be used,       */
11 /*  modified, and distributed under the terms of the FreeType project      */
12 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
13 /*  this file you indicate that you have read the license and              */
14 /*  understand and accept it fully.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17 
18 
19 #ifndef TTGXVAR_H_
20 #define TTGXVAR_H_
21 
22 
23 #include <ft2build.h>
24 #include "ttobjs.h"
25 
26 
27 FT_BEGIN_HEADER
28 
29 
30   /*************************************************************************/
31   /*                                                                       */
32   /* <Struct>                                                              */
33   /*    GX_AVarCorrespondenceRec                                           */
34   /*                                                                       */
35   /* <Description>                                                         */
36   /*    A data structure representing `shortFracCorrespondence' in `avar'  */
37   /*    table according to the specifications from Apple.                  */
38   /*                                                                       */
39   typedef struct  GX_AVarCorrespondenceRec_
40   {
41     FT_Fixed  fromCoord;
42     FT_Fixed  toCoord;
43 
44   } GX_AVarCorrespondenceRec_, *GX_AVarCorrespondence;
45 
46 
47   /*************************************************************************/
48   /*                                                                       */
49   /* <Struct>                                                              */
50   /*    GX_AVarRec                                                         */
51   /*                                                                       */
52   /* <Description>                                                         */
53   /*    Data from the segment field of `avar' table.                       */
54   /*    There is one of these for each axis.                               */
55   /*                                                                       */
56   typedef struct  GX_AVarSegmentRec_
57   {
58     FT_UShort              pairCount;
59     GX_AVarCorrespondence  correspondence; /* array with pairCount entries */
60 
61   } GX_AVarSegmentRec, *GX_AVarSegment;
62 
63 
64   typedef struct  GX_ItemVarDataRec_
65   {
66     FT_UInt    itemCount;      /* number of delta sets per item         */
67     FT_UInt    regionIdxCount; /* number of region indices in this data */
68     FT_UInt*   regionIndices;  /* array of `regionCount' indices;       */
69                                /* these index `varRegionList'           */
70     FT_Short*  deltaSet;       /* array of `itemCount' deltas           */
71                                /* use `innerIndex' for this array       */
72 
73   } GX_ItemVarDataRec, *GX_ItemVarData;
74 
75 
76   /* contribution of one axis to a region */
77   typedef struct  GX_AxisCoordsRec_
78   {
79     FT_Fixed  startCoord;
80     FT_Fixed  peakCoord;      /* zero means no effect (factor = 1) */
81     FT_Fixed  endCoord;
82 
83   } GX_AxisCoordsRec, *GX_AxisCoords;
84 
85 
86   typedef struct  GX_VarRegionRec_
87   {
88     GX_AxisCoords  axisList;               /* array of axisCount records */
89 
90   } GX_VarRegionRec, *GX_VarRegion;
91 
92 
93   /* item variation store */
94   typedef struct  GX_ItemVarStoreRec_
95   {
96     FT_UInt         dataCount;
97     GX_ItemVarData  varData;            /* array of dataCount records;     */
98                                         /* use `outerIndex' for this array */
99     FT_UShort     axisCount;
100     FT_UInt       regionCount;          /* total number of regions defined */
101     GX_VarRegion  varRegionList;
102 
103   } GX_ItemVarStoreRec, *GX_ItemVarStore;
104 
105 
106   typedef struct  GX_DeltaSetIdxMapRec_
107   {
108     FT_UInt   mapCount;
109     FT_UInt*  outerIndex;             /* indices to item var data */
110     FT_UInt*  innerIndex;             /* indices to delta set     */
111 
112   } GX_DeltaSetIdxMapRec, *GX_DeltaSetIdxMap;
113 
114 
115   /*************************************************************************/
116   /*                                                                       */
117   /* <Struct>                                                              */
118   /*    GX_HVVarTableRec                                                   */
119   /*                                                                       */
120   /* <Description>                                                         */
121   /*    Data from either the `HVAR' or `VVAR' table.                       */
122   /*                                                                       */
123   typedef struct  GX_HVVarTableRec_
124   {
125     GX_ItemVarStoreRec    itemStore;        /* Item Variation Store  */
126     GX_DeltaSetIdxMapRec  widthMap;         /* Advance Width Mapping */
127 
128 #if 0
129     GX_DeltaSetIdxMapRec  lsbMap;           /* not implemented */
130     GX_DeltaSetIdxMapRec  rsbMap;           /* not implemented */
131 
132     GX_DeltaSetIdxMapRec  tsbMap;           /* not implemented */
133     GX_DeltaSetIdxMapRec  bsbMap;           /* not implemented */
134     GX_DeltaSetIdxMapRec  vorgMap;          /* not implemented */
135 #endif
136 
137   } GX_HVVarTableRec, *GX_HVVarTable;
138 
139 
140 #define MVAR_TAG_GASP_0  FT_MAKE_TAG( 'g', 's', 'p', '0' )
141 #define MVAR_TAG_GASP_1  FT_MAKE_TAG( 'g', 's', 'p', '1' )
142 #define MVAR_TAG_GASP_2  FT_MAKE_TAG( 'g', 's', 'p', '2' )
143 #define MVAR_TAG_GASP_3  FT_MAKE_TAG( 'g', 's', 'p', '3' )
144 #define MVAR_TAG_GASP_4  FT_MAKE_TAG( 'g', 's', 'p', '4' )
145 #define MVAR_TAG_GASP_5  FT_MAKE_TAG( 'g', 's', 'p', '5' )
146 #define MVAR_TAG_GASP_6  FT_MAKE_TAG( 'g', 's', 'p', '6' )
147 #define MVAR_TAG_GASP_7  FT_MAKE_TAG( 'g', 's', 'p', '7' )
148 #define MVAR_TAG_GASP_8  FT_MAKE_TAG( 'g', 's', 'p', '8' )
149 #define MVAR_TAG_GASP_9  FT_MAKE_TAG( 'g', 's', 'p', '9' )
150 
151 #define MVAR_TAG_CPHT  FT_MAKE_TAG( 'c', 'p', 'h', 't' )
152 #define MVAR_TAG_HASC  FT_MAKE_TAG( 'h', 'a', 's', 'c' )
153 #define MVAR_TAG_HCLA  FT_MAKE_TAG( 'h', 'c', 'l', 'a' )
154 #define MVAR_TAG_HCLD  FT_MAKE_TAG( 'h', 'c', 'l', 'd' )
155 #define MVAR_TAG_HCOF  FT_MAKE_TAG( 'h', 'c', 'o', 'f' )
156 #define MVAR_TAG_HCRN  FT_MAKE_TAG( 'h', 'c', 'r', 'n' )
157 #define MVAR_TAG_HCRS  FT_MAKE_TAG( 'h', 'c', 'r', 's' )
158 #define MVAR_TAG_HDSC  FT_MAKE_TAG( 'h', 'd', 's', 'c' )
159 #define MVAR_TAG_HLGP  FT_MAKE_TAG( 'h', 'l', 'g', 'p' )
160 #define MVAR_TAG_SBXO  FT_MAKE_TAG( 's', 'b', 'x', 'o' )
161 #define MVAR_TAG_SBXS  FT_MAKE_TAG( 's', 'b', 'x', 's' )
162 #define MVAR_TAG_SBYO  FT_MAKE_TAG( 's', 'b', 'y', 'o' )
163 #define MVAR_TAG_SBYS  FT_MAKE_TAG( 's', 'b', 'y', 's' )
164 #define MVAR_TAG_SPXO  FT_MAKE_TAG( 's', 'p', 'x', 'o' )
165 #define MVAR_TAG_SPXS  FT_MAKE_TAG( 's', 'p', 'x', 's' )
166 #define MVAR_TAG_SPYO  FT_MAKE_TAG( 's', 'p', 'y', 'o' )
167 #define MVAR_TAG_SPYS  FT_MAKE_TAG( 's', 'p', 'y', 's' )
168 #define MVAR_TAG_STRO  FT_MAKE_TAG( 's', 't', 'r', 'o' )
169 #define MVAR_TAG_STRS  FT_MAKE_TAG( 's', 't', 'r', 's' )
170 #define MVAR_TAG_UNDO  FT_MAKE_TAG( 'u', 'n', 'd', 'o' )
171 #define MVAR_TAG_UNDS  FT_MAKE_TAG( 'u', 'n', 'd', 's' )
172 #define MVAR_TAG_VASC  FT_MAKE_TAG( 'v', 'a', 's', 'c' )
173 #define MVAR_TAG_VCOF  FT_MAKE_TAG( 'v', 'c', 'o', 'f' )
174 #define MVAR_TAG_VCRN  FT_MAKE_TAG( 'v', 'c', 'r', 'n' )
175 #define MVAR_TAG_VCRS  FT_MAKE_TAG( 'v', 'c', 'r', 's' )
176 #define MVAR_TAG_VDSC  FT_MAKE_TAG( 'v', 'd', 's', 'c' )
177 #define MVAR_TAG_VLGP  FT_MAKE_TAG( 'v', 'l', 'g', 'p' )
178 #define MVAR_TAG_XHGT  FT_MAKE_TAG( 'x', 'h', 'g', 't' )
179 
180 
181   typedef struct  GX_ValueRec_
182   {
183     FT_ULong   tag;
184     FT_UShort  outerIndex;
185     FT_UShort  innerIndex;
186 
187     FT_Short  unmodified;  /* values are either FT_Short or FT_UShort */
188 
189   } GX_ValueRec, *GX_Value;
190 
191 
192   /*************************************************************************/
193   /*                                                                       */
194   /* <Struct>                                                              */
195   /*    GX_MVarTableRec                                                    */
196   /*                                                                       */
197   /* <Description>                                                         */
198   /*    Data from the `MVAR' table.                                        */
199   /*                                                                       */
200   typedef struct  GX_MVarTableRec_
201   {
202     FT_UShort  valueCount;
203 
204     GX_ItemVarStoreRec  itemStore;        /* Item Variation Store  */
205     GX_Value            values;           /* Value Records         */
206 
207   } GX_MVarTableRec, *GX_MVarTable;
208 
209 
210   /*************************************************************************/
211   /*                                                                       */
212   /* <Struct>                                                              */
213   /*    GX_BlendRec                                                        */
214   /*                                                                       */
215   /* <Description>                                                         */
216   /*    Data for interpolating a font from a distortable font specified    */
217   /*    by the GX *var tables ([fgca]var).                                 */
218   /*                                                                       */
219   /* <Fields>                                                              */
220   /*    num_axis         :: The number of axes along which interpolation   */
221   /*                         may happen                                    */
222   /*                                                                       */
223   /*    normalizedcoords :: A normalized value (between [-1,1]) indicating */
224   /*                        the contribution along each axis to the final  */
225   /*                        interpolated font.                             */
226   /*                                                                       */
227   typedef struct  GX_BlendRec_
228   {
229     FT_UInt         num_axis;
230     FT_Fixed*       normalizedcoords;
231 
232     FT_MM_Var*      mmvar;
233     FT_Offset       mmvar_len;
234 
235     FT_Bool         avar_checked;
236     GX_AVarSegment  avar_segment;
237 
238     FT_Bool         hvar_loaded;
239     FT_Bool         hvar_checked;
240     FT_Error        hvar_error;
241     GX_HVVarTable   hvar_table;
242 
243     FT_Bool         vvar_loaded;
244     FT_Bool         vvar_checked;
245     FT_Error        vvar_error;
246     GX_HVVarTable   vvar_table;
247 
248     GX_MVarTable    mvar_table;
249 
250     FT_UInt         tuplecount;      /* shared tuples in `gvar'           */
251     FT_Fixed*       tuplecoords;     /* tuplecoords[tuplecount][num_axis] */
252 
253     FT_UInt         gv_glyphcnt;
254     FT_ULong*       glyphoffsets;
255 
256     FT_ULong        gvar_size;
257 
258   } GX_BlendRec;
259 
260 
261   /*************************************************************************/
262   /*                                                                       */
263   /* <enum>                                                                */
264   /*    GX_TupleCountFlags                                                 */
265   /*                                                                       */
266   /* <Description>                                                         */
267   /*    Flags used within the `TupleCount' field of the `gvar' table.      */
268   /*                                                                       */
269   typedef enum  GX_TupleCountFlags_
270   {
271     GX_TC_TUPLES_SHARE_POINT_NUMBERS = 0x8000,
272     GX_TC_RESERVED_TUPLE_FLAGS       = 0x7000,
273     GX_TC_TUPLE_COUNT_MASK           = 0x0FFF
274 
275   } GX_TupleCountFlags;
276 
277 
278   /*************************************************************************/
279   /*                                                                       */
280   /* <enum>                                                                */
281   /*    GX_TupleIndexFlags                                                 */
282   /*                                                                       */
283   /* <Description>                                                         */
284   /*    Flags used within the `TupleIndex' field of the `gvar' and `cvar'  */
285   /*    tables.                                                            */
286   /*                                                                       */
287   typedef enum  GX_TupleIndexFlags_
288   {
289     GX_TI_EMBEDDED_TUPLE_COORD  = 0x8000,
290     GX_TI_INTERMEDIATE_TUPLE    = 0x4000,
291     GX_TI_PRIVATE_POINT_NUMBERS = 0x2000,
292     GX_TI_RESERVED_TUPLE_FLAG   = 0x1000,
293     GX_TI_TUPLE_INDEX_MASK      = 0x0FFF
294 
295   } GX_TupleIndexFlags;
296 
297 
298 #define TTAG_wght  FT_MAKE_TAG( 'w', 'g', 'h', 't' )
299 #define TTAG_wdth  FT_MAKE_TAG( 'w', 'd', 't', 'h' )
300 #define TTAG_opsz  FT_MAKE_TAG( 'o', 'p', 's', 'z' )
301 #define TTAG_slnt  FT_MAKE_TAG( 's', 'l', 'n', 't' )
302 
303 
304   FT_LOCAL( FT_Error )
305   TT_Set_MM_Blend( TT_Face    face,
306                    FT_UInt    num_coords,
307                    FT_Fixed*  coords );
308 
309   FT_LOCAL( FT_Error )
310   TT_Get_MM_Blend( TT_Face    face,
311                    FT_UInt    num_coords,
312                    FT_Fixed*  coords );
313 
314   FT_LOCAL( FT_Error )
315   TT_Set_Var_Design( TT_Face    face,
316                      FT_UInt    num_coords,
317                      FT_Fixed*  coords );
318 
319   FT_LOCAL( FT_Error )
320   TT_Get_MM_Var( TT_Face      face,
321                  FT_MM_Var*  *master );
322 
323   FT_LOCAL( FT_Error )
324   TT_Get_Var_Design( TT_Face    face,
325                      FT_UInt    num_coords,
326                      FT_Fixed*  coords );
327 
328   FT_LOCAL( FT_Error )
329   tt_face_vary_cvt( TT_Face    face,
330                     FT_Stream  stream );
331 
332 
333   FT_LOCAL( FT_Error )
334   TT_Vary_Apply_Glyph_Deltas( TT_Face      face,
335                               FT_UInt      glyph_index,
336                               FT_Outline*  outline,
337                               FT_UInt      n_points );
338 
339   FT_LOCAL( FT_Error )
340   tt_hadvance_adjust( TT_Face  face,
341                       FT_UInt  gindex,
342                       FT_Int  *adelta );
343 
344   FT_LOCAL( FT_Error )
345   tt_vadvance_adjust( TT_Face  face,
346                       FT_UInt  gindex,
347                       FT_Int  *adelta );
348 
349   FT_LOCAL( void )
350   tt_apply_mvar( TT_Face  face );
351 
352   FT_LOCAL( FT_Error )
353   tt_get_var_blend( TT_Face      face,
354                     FT_UInt     *num_coords,
355                     FT_Fixed*   *coords,
356                     FT_MM_Var*  *mm_var );
357 
358   FT_LOCAL( void )
359   tt_done_blend( TT_Face  face );
360 
361 
362 FT_END_HEADER
363 
364 
365 #endif /* TTGXVAR_H_ */
366 
367 
368 /* END */
369