Debian Codegraph @

podofo/3rdparty/adobe/afdko/include/varread.h

raw
1 /* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved.
2 This software is licensed as OpenSource, under the Apache License, Version 2.0.
3 This license is available at: http://opensource.org/licenses/Apache-2.0. */
4
5 #ifndef VARREAD_H
6 #define VARREAD_H
7
8 #include "sfntread.h"
9 #include "supportpublictypes.h"
10 #include "supportfp.h"
11 #include "absfont.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 /* Variable Font Tables Reader Library
18 =======================================
19 This library parses tables common tables used by variable OpenType fonts.
20 */
21
22 #define VARREAD_VERSION CTL_MAKE_VERSION(1, 0, 8)
23 #define F2DOT14_TO_FIXED(v) (((Fixed)(v)) << 2)
24 #define FIXED_TO_F2DOT14(v) ((var_F2dot14)(((Fixed)(v) + 0x00000002) >> 2))
25
26 typedef Int16 var_F2dot14; /* 2.14 fixed point number */
27
28 /* item variation store */
29
30 typedef struct region_ {
31 Fixed startCoord;
32 Fixed peakCoord;
33 Fixed endCoord;
34 } variationRegion;
35
36 typedef struct variationRegionList_ {
37 unsigned short axisCount;
38 unsigned short regionCount;
39 dnaDCL(variationRegion, regions);
40 } variationRegionList;
41
42 typedef dnaDCL(unsigned short, indexArray);
43
44 typedef struct itemVariationDataSubtable_ {
45 unsigned short itemCount;
46 unsigned short regionCount;
47 dnaDCL(short, regionIndices);
48 dnaDCL(short, deltaValues);
49 } itemVariationDataSubtable;
50
51 typedef struct itemVariationDataSubtableList_ {
52 dnaDCL(itemVariationDataSubtable, ivdSubtables);
53 } itemVariationDataSubtableList;
54
55 struct var_itemVariationStore_ {
56 variationRegionList regionList;
57 itemVariationDataSubtableList dataList;
58 };
59
60 /* glyph width and side-bearing */
61 typedef struct glyphMetrics_ {
62 float width;
63 float sideBearing;
64 } var_glyphMetrics;
65
66 /* variable font axis tables */
67 struct var_axes_;
68 typedef struct var_axes_ *var_axes;
69
70 /* convert 2.14 fixed value to float */
71 float var_F2dot14ToFloat(var_F2dot14 v);
72
73 var_axes var_loadaxes(sfrCtx sfr, ctlSharedStmCallbacks *sscb);
74
75 /* var_loadaxes() loads the axes table data (fvar and avar tables) from an SFNT font.
76 If not found, NULL is returned.
77
78 sfr - context pointer created by calling sfrNew in sfntread library.
79
80 sscb - a pointer to shared stream callback functions.
81 */
82
83 void var_freeaxes(ctlSharedStmCallbacks *sscb, var_axes axes);
84
85 /* var_freeaxes() frees the axes table data loaded by calling var_loadaxes().
86
87 sscb - a pointer to shared stream callback functions.
88
89 axes - a pointer to the axes table data to be freed.
90 */
91
92 unsigned short var_getAxisCount(var_axes axes);
93
94 /* var_getAxisCount() retrieves the number of axes from the axes table data.
95
96 axes - a pointer to the axes table data.
97 */
98
99 int var_getAxis(var_axes axes, unsigned short index, unsigned long *tag, Fixed *minValue, Fixed *defaultValue, Fixed *maxValue, unsigned short *flags);
100
101 /* var_getAxis() retrieves info on an axis from the axes table data.
102 return 0 for success, 1 for failure.
103
104 axes - a pointer to the axes table data.
105
106 index - specifies an axis index.
107
108 tag - where the four-letter axis tag is returned.
109 May be NULL if tag is not needed.
110
111 minValue - where the minimum coordinate value for the axis is returned.
112 May be NULL if the minimum value is not needed.
113
114 defaultValue - where the default coordinate value for the axis is returned.
115 May be NULL if the minimum value is not needed.
116
117 maxValue - where the maximum coordinate value for the axis is returned.
118 May be NULL if the maximum value is not needed.
119
120 flags - where the axis flags value is returned.
121 May be NULL if the flags value is not needed.
122 */
123
124 int var_normalizeCoords(ctlSharedStmCallbacks *sscb, var_axes axes, Fixed *userCoords, Fixed *normCoords);
125
126 /* var_normalizeCoords() normalizes a variable font value coordinates.
127 return 0 for success, 1 for failure.
128
129 sscb - a pointer to shared stream callback functions.
130
131 axes - a pointer to the axes table data.
132
133 userCoords - a pointer to user coordinates to be normalized (unmodified).
134
135 normCoords - where the resulting normalized coordinates are returned as 2.14 fixed point values.
136 */
137
138 unsigned short var_getInstanceCount(var_axes axes);
139
140 /* var_getInstanceCount() returns the number of named instances from the axes table data.
141
142 axes - a pointer to the axes table data.
143 */
144
145 int var_findInstance(var_axes axes, float *userCoords, unsigned short axisCount, unsigned short *subfamilyID, unsigned short *postscriptID);
146
147 /* var_findInstance() searches for a named instance matching the given coordinates.
148 return the instance index if >= 0, -1 if not found.
149
150 axes - a pointer to the axes table data.
151
152 axisCount - the number of axes.
153
154 subfamilyID - where the name ID of the subfamily name of the instance is returned.
155
156 postscriptID - where the name ID of the PostScript name of the instance is returned.
157 0 is returned if no PostScript name ID is provided.
158 */
159
160 var_itemVariationStore var_loadItemVariationStore(ctlSharedStmCallbacks *sscb, unsigned long tableOffset, unsigned long tableLength, unsigned long ivsOffset);
161
162 /* var_loadItemVariationStore() parses the Item Variation Store (IVS) sub-table.
163 return a pointer to IVS data, or NULL if not found.
164
165 sscb - a pointer to shared stream callback functions.
166
167 tableOffset - offset to the beginning of the container table from the beginning of the stream.
168
169 tableLength - length of the container table.
170
171 ivsOffset - offset to the IVS data from the beginning of the container table.
172 */
173
174 void var_freeItemVariationStore(ctlSharedStmCallbacks *sscb, var_itemVariationStore ivs);
175
176 /* var_freeItemVariationStore() frees the IVS data loaded by var_loadItemVariationStore.
177
178 sscb - a pointer to shared stream callback functions.
179
180 ivs - a pointer to the IVS data to be freed.
181 */
182
183 unsigned short var_getIVSRegionCount(var_itemVariationStore ivs);
184
185 /* var_getIVSRegionCount() returns the number of regions in the region list in the IVS data.
186
187 ivs - a pointer to the IVS data.
188 */
189
190 unsigned short var_getIVDRegionCountForIndex(var_itemVariationStore ivs, unsigned short vsIndex);
191
192 /* var_getIVDRegionCountForIndex() returns the number of sub-regions applicable to an IVS sub-table.
193
194 ivs - a pointer to the IVS data.
195
196 vsIndex - IVS ItemVariationData sub-table index.
197 */
198
199 long var_getIVSRegionIndices(var_itemVariationStore ivs, unsigned short vsIndex, unsigned short *regionIndices, long regionCount);
200
201 /* var_getIVSRegionIndices() returns indices of sub-regions applicable to an an IVS sub-table.
202
203 ivs - a pointer to the IVS data.
204
205 vsIndex - IVS sub-table index.
206
207 regionIndices - where region indices are returned.
208
209 regionCount - the length of regionIndices array.
210 */
211
212 void var_calcRegionScalars(ctlSharedStmCallbacks *sscb, var_itemVariationStore ivs, unsigned short *axisCount, Fixed *instCoords, float *scalars);
213
214 /* var_calcRegionScalars() calculates scalars for all regions given a normalized design vector for an instance.
215
216 sscb - a pointer to shared stream callback functions.
217
218 ivs - a pointer to the IVS data.
219
220 axisCount - the number axes. this is taken from the fvar table. If a naked CFF2 is being dumped,
221 then it is updated from the CFF2 VarationStore.
222
223 instCoords - a pointer to normalized design vector of a font instance.
224
225 scalars - where scalars are returned as float values.
226 */
227
228 /* horizontal metrics tables */
229 struct var_hmtx_;
230 typedef struct var_hmtx_ *var_hmtx;
231
232 var_hmtx var_loadhmtx(sfrCtx sfr, ctlSharedStmCallbacks *sscb);
233
234 /* var_loadhmtx() loads the horizontal metrics tables.
235 If not found, NULL is returned.
236
237 sfr - context pointer created by calling sfrNew in sfntread library.
238
239 sscb - a pointer to shared stream callback functions.
240 */
241
242 void var_freehmtx(ctlSharedStmCallbacks *sscb, var_hmtx hmtx);
243
244 /* var_freehmtx() frees the horizontal metrics table data loaded by calling var_loadhmtx().
245
246 sscb - a pointer to shared stream callback functions.
247
248 hmtx - a pointer to the horizontal metrics table data to be freed.
249 */
250
251 int var_lookuphmtx(ctlSharedStmCallbacks *sscb, var_hmtx hmtx, unsigned short axisCount, Fixed *instCoords, unsigned short gid, var_glyphMetrics *metrics);
252
253 /* var_lookuphmtx() lookup horizontal metrics for a glyph optionally blended using font instance coordinates.
254 returns 0 if successful, otherwise non-zero.
255
256 sscb - a pointer to shared stream callback functions.
257
258 hmtx - a pointer to the horizontal metrics table.
259
260 axisCount - the number of axes.
261
262 instCoords - a pointer to normalized font instance coordinates. May be NULL if no blending required.
263
264 gid - the glyph ID to be looked up.
265
266 metrics - where the horizontal glyph metrics are returned.
267 */
268
269 /* vertical metrics tables */
270 struct var_vmtx_;
271 typedef struct var_vmtx_ *var_vmtx;
272
273 var_vmtx var_loadvmtx(sfrCtx sfr, ctlSharedStmCallbacks *sscb);
274
275 /* var_loadvmtx() loads the vertical metrics tables.
276 If not found, NULL is returned.
277
278 sfr - context pointer created by calling sfrNew in sfntread library.
279
280 sscb - a pointer to shared stream callback functions.
281 */
282
283 void var_freevmtx(ctlSharedStmCallbacks *sscb, var_vmtx vmtx);
284
285 /* var_freevmtx() frees the vertical metrics table data loaded by calling var_loadvmtx().
286
287 sscb - a pointer to shared stream callback functions.
288
289 vmtx - a pointer to the horizontal metrics table data to be freed.
290 */
291
292 int var_lookupvmtx(ctlSharedStmCallbacks *sscb, var_vmtx vmtx, unsigned short axisCount, Fixed *instCoords, unsigned short gid, var_glyphMetrics *metrics);
293
294 /* var_lookupvmtx() lookup vertical metrics for a glyph optionally blended using font instance coordinates.
295 returns 0 if successful, otherwise non-zero.
296
297 sscb - a pointer to shared stream callback functions.
298
299 vmtx - a pointer to the vertical metrics table.
300
301 axisCount - the number of axes.
302
303 instCoords - a pointer to normalized font instance coordinates. May be NULL if no blending required.
304
305 gid - the glyph ID to be looked up.
306
307 metrics - where the vertical glyph metrics are returned.
308 */
309
310 /* Predefined MVAR tags */
311 #define MVAR_hasc_tag CTL_TAG('h', 'a', 's', 'c') /* ascender OS/2.sTypoAscender */
312 #define MVAR_hdsc_tag CTL_TAG('h', 'd', 's', 'c') /* horizontal descender OS/2.sTypoDescender */
313 #define MVAR_hlgp_tag CTL_TAG('h', 'l', 'g', 'p') /* horizontal line gap OS/2.sTypoLineGap */
314 #define MVAR_hcla_tag CTL_TAG('h', 'c', 'l', 'a') /* horizontal clipping ascent OS/2.usWinAscent */
315 #define MVAR_hcld_tag CTL_TAG('h', 'c', 'l', 'd') /* horizontal clipping descent OS/2.usWinDescent */
316 #define MVAR_vasc_tag CTL_TAG('v', 'a', 's', 'c') /* vertical ascender vhea.ascent */
317 #define MVAR_vdsc_tag CTL_TAG('v', 'd', 's', 'c') /* vertical descender vhea.descent */
318 #define MVAR_vlgp_tag CTL_TAG('v', 'l', 'g', 'p') /* vertical line gap vhea.lineGap */
319 #define MVAR_hcrs_tag CTL_TAG('h', 'c', 'r', 's') /* horizontal caret rise hhea.caretSlopeRise */
320 #define MVAR_hcrn_tag CTL_TAG('h', 'c', 'r', 'n') /* horizontal caret run hhea.caretSlopeRun */
321 #define MVAR_hcof_tag CTL_TAG('h', 'c', 'o', 'f') /* horizontal caret offset hhea.caretOffset */
322 #define MVAR_vcrs_tag CTL_TAG('v', 'c', 'r', 's') /* vertical caret rise vhea.caretSlopeRise */
323 #define MVAR_vcrn_tag CTL_TAG('v', 'c', 'r', 'n') /* vertical caret run vhea.caretSlopeRun */
324 #define MVAR_vcof_tag CTL_TAG('v', 'c', 'o', 'f') /* vertical caret offset vhea.caretOffset */
325 #define MVAR_xhgt_tag CTL_TAG('x', 'h', 'g', 't') /* x height OS/2.sxHeight */
326 #define MVAR_cpht_tag CTL_TAG('c', 'p', 'h', 't') /* cap height OS/2.sCapHeight */
327 #define MVAR_sbxs_tag CTL_TAG('s', 'b', 'x', 's') /* subscript em x size OS/2.ySubscriptXSize */
328 #define MVAR_sbys_tag CTL_TAG('s', 'b', 'y', 's') /* subscript em y size OS/2.ySubscriptYSize */
329 #define MVAR_sbxo_tag CTL_TAG('s', 'b', 'x', 'o') /* subscript em x offset OS/2.ySubscriptXOffset */
330 #define MVAR_sbyo_tag CTL_TAG('s', 'b', 'y', 'o') /* subscript em y offset OS/2.ySubscriptYOffset */
331 #define MVAR_spxs_tag CTL_TAG('s', 'p', 'x', 's') /* superscript em x size OS/2.ySuperscriptXSize */
332 #define MVAR_spys_tag CTL_TAG('s', 'p', 'y', 's') /* superscript em y size OS/2.ySuperscriptYSize */
333 #define MVAR_spxo_tag CTL_TAG('s', 'p', 'x', 'o') /* superscript em x offset OS/2.ySuperscriptXOffset */
334 #define MVAR_spyo_tag CTL_TAG('s', 'p', 'y', 'o') /* superscript em y offset OS/2.ySuperscriptYOffset */
335 #define MVAR_strs_tag CTL_TAG('s', 't', 'r', 's') /* strikeout size OS/2.yStrikeoutSize */
336 #define MVAR_stro_tag CTL_TAG('s', 't', 'r', 'o') /* strikeout offset OS/2.yStrikeoutPosition */
337 #define MVAR_unds_tag CTL_TAG('u', 'n', 'd', 's') /* underline size post.underlineThickness */
338 #define MVAR_undo_tag CTL_TAG('u', 'n', 'd', 'o') /* underline offset post.underlinePosition */
339
340 #define MVAR_gsp0_tag CTL_TAG('g', 's', 'p', '0') /* gaspRange[0] gasp.gaspRange[0].rangeMaxPPEM */
341 #define MVAR_gsp1_tag CTL_TAG('g', 's', 'p', '1') /* gaspRange[1] gasp.gaspRange[1].rangeMaxPPEM */
342 #define MVAR_gsp2_tag CTL_TAG('g', 's', 'p', '2') /* gaspRange[2] gasp.gaspRange[2].rangeMaxPPEM */
343 #define MVAR_gsp3_tag CTL_TAG('g', 's', 'p', '3') /* gaspRange[3] gasp.gaspRange[3].rangeMaxPPEM */
344 #define MVAR_gsp4_tag CTL_TAG('g', 's', 'p', '4') /* gaspRange[4] gasp.gaspRange[4].rangeMaxPPEM */
345 #define MVAR_gsp5_tag CTL_TAG('g', 's', 'p', '5') /* gaspRange[5] gasp.gaspRange[5].rangeMaxPPEM */
346 #define MVAR_gsp6_tag CTL_TAG('g', 's', 'p', '6') /* gaspRange[6] gasp.gaspRange[6].rangeMaxPPEM */
347 #define MVAR_gsp7_tag CTL_TAG('g', 's', 'p', '7') /* gaspRange[7] gasp.gaspRange[7].rangeMaxPPEM */
348 #define MVAR_gsp8_tag CTL_TAG('g', 's', 'p', '8') /* gaspRange[8] gasp.gaspRange[8].rangeMaxPPEM */
349 #define MVAR_gsp9_tag CTL_TAG('g', 's', 'p', '9') /* gaspRange[9] gasp.gaspRange[9].rangeMaxPPEM */
350
351 /* MVAR table */
352 struct var_MVAR_;
353 typedef struct var_MVAR_ *var_MVAR;
354
355 var_MVAR var_loadMVAR(sfrCtx sfr, ctlSharedStmCallbacks *sscb);
356
357 /* var_loadMVAR() loads the MVAR table.
358 If not found, NULL is returned.
359
360 sfr - context pointer created by calling sfrNew in sfntread library.
361
362 sscb - a pointer to shared stream callback functions.
363 */
364
365 int var_lookupMVAR(ctlSharedStmCallbacks *sscb, var_MVAR mvar, unsigned short axisCount, Fixed *instCoords, ctlTag tag, float *value);
366
367 /* var_lookupMVAR() lookup font-wide metric values for a tag blended using font instance coordinates.
368 returns 0 if successful, otherwise non-zero.
369
370 sscb - a pointer to shared stream callback functions.
371
372 mvar - a pointer to the MVAR metrics table.
373
374 axisCount - the number of axes.
375
376 instCoords - a pointer to normalized font instance coordinates. May be NULL if no blending required.
377
378 tag - the tag of the metric value to be looked up.
379
380 value - where the blended metric value is returned.
381 */
382
383 void var_freeMVAR(ctlSharedStmCallbacks *sscb, var_MVAR mvar);
384
385 /* var_freeMVAR() frees the metrics table data loaded by calling var_loadMVAR().
386
387 sscb - a pointer to shared stream callback functions.
388
389 mvar - a pointer to the horizontal metrics table data to be freed.
390 */
391
392 void varreadGetVersion(ctlVersionCallbacks *cb);
393
394 /* varreadGetVersion() returns the library version number and name via the client
395 callbacks passed with the "cb" parameter (see ctlshare.h). */
396
397 #ifdef __cplusplus
398 }
399 #endif
400
401 #endif /* VARREAD_H */