ReactOS 0.4.16-dev-297-gc569aee
otvmath.c
Go to the documentation of this file.
1/***************************************************************************/
2/* */
3/* otvmath.c */
4/* */
5/* OpenType MATH table validation (body). */
6/* */
7/* Copyright 2007-2018 by */
8/* David Turner, Robert Wilhelm, and Werner Lemberg. */
9/* */
10/* Written by George Williams. */
11/* */
12/* This file is part of the FreeType project, and may only be used, */
13/* modified, and distributed under the terms of the FreeType project */
14/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
15/* this file you indicate that you have read the license and */
16/* understand and accept it fully. */
17/* */
18/***************************************************************************/
19
20
21#include "otvalid.h"
22#include "otvcommn.h"
23#include "otvgpos.h"
24
25
26 /*************************************************************************/
27 /* */
28 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
29 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
30 /* messages during execution. */
31 /* */
32#undef FT_COMPONENT
33#define FT_COMPONENT trace_otvmath
34
35
36
37 /*************************************************************************/
38 /*************************************************************************/
39 /***** *****/
40 /***** MATH TYPOGRAPHIC CONSTANTS *****/
41 /***** *****/
42 /*************************************************************************/
43 /*************************************************************************/
44
45 static void
47 OTV_Validator otvalid )
48 {
50 FT_UInt i;
52
53 OTV_OPTIONAL_TABLE( DeviceTableOffset );
54
55
56 OTV_NAME_ENTER( "MathConstants" );
57
58 /* 56 constants, 51 have device tables */
59 OTV_LIMIT_CHECK( 2 * ( 56 + 51 ) );
60 table_size = 2 * ( 56 + 51 );
61
62 p += 4 * 2; /* First 4 constants have no device tables */
63 for ( i = 0; i < 51; i++ )
64 {
65 p += 2; /* skip the value */
66 OTV_OPTIONAL_OFFSET( DeviceTableOffset );
67 OTV_SIZE_CHECK( DeviceTableOffset );
68 if ( DeviceTableOffset )
69 otv_Device_validate( table + DeviceTableOffset, otvalid );
70 }
71
73 }
74
75
76 /*************************************************************************/
77 /*************************************************************************/
78 /***** *****/
79 /***** MATH ITALICS CORRECTION *****/
80 /***** MATH TOP ACCENT ATTACHMENT *****/
81 /***** *****/
82 /*************************************************************************/
83 /*************************************************************************/
84
85 static void
87 OTV_Validator otvalid,
88 FT_Int isItalic )
89 {
91 FT_UInt i, cnt, table_size;
92
93 OTV_OPTIONAL_TABLE( Coverage );
94 OTV_OPTIONAL_TABLE( DeviceTableOffset );
95
96 FT_UNUSED( isItalic ); /* only used if tracing is active */
97
98
99 OTV_NAME_ENTER( isItalic ? "MathItalicsCorrectionInfo"
100 : "MathTopAccentAttachment" );
101
102 OTV_LIMIT_CHECK( 4 );
103
104 OTV_OPTIONAL_OFFSET( Coverage );
105 cnt = FT_NEXT_USHORT( p );
106
107 OTV_LIMIT_CHECK( 4 * cnt );
108 table_size = 4 + 4 * cnt;
109
110 OTV_SIZE_CHECK( Coverage );
111 otv_Coverage_validate( table + Coverage, otvalid, (FT_Int)cnt );
112
113 for ( i = 0; i < cnt; i++ )
114 {
115 p += 2; /* Skip the value */
116 OTV_OPTIONAL_OFFSET( DeviceTableOffset );
117 OTV_SIZE_CHECK( DeviceTableOffset );
118 if ( DeviceTableOffset )
119 otv_Device_validate( table + DeviceTableOffset, otvalid );
120 }
121
122 OTV_EXIT;
123 }
124
125
126 /*************************************************************************/
127 /*************************************************************************/
128 /***** *****/
129 /***** MATH KERNING *****/
130 /***** *****/
131 /*************************************************************************/
132 /*************************************************************************/
133
134 static void
136 OTV_Validator otvalid )
137 {
138 FT_Bytes p = table;
139 FT_UInt i, cnt, table_size;
140
141 OTV_OPTIONAL_TABLE( DeviceTableOffset );
142
143
144 /* OTV_NAME_ENTER( "MathKern" );*/
145
146 OTV_LIMIT_CHECK( 2 );
147
148 cnt = FT_NEXT_USHORT( p );
149
150 OTV_LIMIT_CHECK( 4 * cnt + 2 );
151 table_size = 4 + 4 * cnt;
152
153 /* Heights */
154 for ( i = 0; i < cnt; i++ )
155 {
156 p += 2; /* Skip the value */
157 OTV_OPTIONAL_OFFSET( DeviceTableOffset );
158 OTV_SIZE_CHECK( DeviceTableOffset );
159 if ( DeviceTableOffset )
160 otv_Device_validate( table + DeviceTableOffset, otvalid );
161 }
162
163 /* One more Kerning value */
164 for ( i = 0; i < cnt + 1; i++ )
165 {
166 p += 2; /* Skip the value */
167 OTV_OPTIONAL_OFFSET( DeviceTableOffset );
168 OTV_SIZE_CHECK( DeviceTableOffset );
169 if ( DeviceTableOffset )
170 otv_Device_validate( table + DeviceTableOffset, otvalid );
171 }
172
173 OTV_EXIT;
174 }
175
176
177 static void
179 OTV_Validator otvalid )
180 {
181 FT_Bytes p = table;
182 FT_UInt i, j, cnt, table_size;
183
184 OTV_OPTIONAL_TABLE( Coverage );
185 OTV_OPTIONAL_TABLE( MKRecordOffset );
186
187
188 OTV_NAME_ENTER( "MathKernInfo" );
189
190 OTV_LIMIT_CHECK( 4 );
191
192 OTV_OPTIONAL_OFFSET( Coverage );
193 cnt = FT_NEXT_USHORT( p );
194
195 OTV_LIMIT_CHECK( 8 * cnt );
196 table_size = 4 + 8 * cnt;
197
198 OTV_SIZE_CHECK( Coverage );
199 otv_Coverage_validate( table + Coverage, otvalid, (FT_Int)cnt );
200
201 for ( i = 0; i < cnt; i++ )
202 {
203 for ( j = 0; j < 4; j++ )
204 {
205 OTV_OPTIONAL_OFFSET( MKRecordOffset );
206 OTV_SIZE_CHECK( MKRecordOffset );
207 if ( MKRecordOffset )
208 otv_MathKern_validate( table + MKRecordOffset, otvalid );
209 }
210 }
211
212 OTV_EXIT;
213 }
214
215
216 /*************************************************************************/
217 /*************************************************************************/
218 /***** *****/
219 /***** MATH GLYPH INFO *****/
220 /***** *****/
221 /*************************************************************************/
222 /*************************************************************************/
223
224 static void
226 OTV_Validator otvalid )
227 {
228 FT_Bytes p = table;
229 FT_UInt MathItalicsCorrectionInfo, MathTopAccentAttachment;
230 FT_UInt ExtendedShapeCoverage, MathKernInfo;
231
232
233 OTV_NAME_ENTER( "MathGlyphInfo" );
234
235 OTV_LIMIT_CHECK( 8 );
236
237 MathItalicsCorrectionInfo = FT_NEXT_USHORT( p );
238 MathTopAccentAttachment = FT_NEXT_USHORT( p );
239 ExtendedShapeCoverage = FT_NEXT_USHORT( p );
240 MathKernInfo = FT_NEXT_USHORT( p );
241
242 if ( MathItalicsCorrectionInfo )
244 table + MathItalicsCorrectionInfo, otvalid, TRUE );
245
246 /* Italic correction and Top Accent Attachment have the same format */
247 if ( MathTopAccentAttachment )
249 table + MathTopAccentAttachment, otvalid, FALSE );
250
251 if ( ExtendedShapeCoverage )
252 {
253 OTV_NAME_ENTER( "ExtendedShapeCoverage" );
254 otv_Coverage_validate( table + ExtendedShapeCoverage, otvalid, -1 );
255 OTV_EXIT;
256 }
257
258 if ( MathKernInfo )
259 otv_MathKernInfo_validate( table + MathKernInfo, otvalid );
260
261 OTV_EXIT;
262 }
263
264
265 /*************************************************************************/
266 /*************************************************************************/
267 /***** *****/
268 /***** MATH GLYPH CONSTRUCTION *****/
269 /***** *****/
270 /*************************************************************************/
271 /*************************************************************************/
272
273 static void
275 OTV_Validator otvalid )
276 {
277 FT_Bytes p = table;
278 FT_UInt pcnt, table_size;
279 FT_UInt i;
280
281 OTV_OPTIONAL_TABLE( DeviceTableOffset );
282
283
284 /* OTV_NAME_ENTER( "GlyphAssembly" ); */
285
286 OTV_LIMIT_CHECK( 6 );
287
288 p += 2; /* Skip the Italics Correction value */
289 OTV_OPTIONAL_OFFSET( DeviceTableOffset );
290 pcnt = FT_NEXT_USHORT( p );
291
292 OTV_LIMIT_CHECK( 8 * pcnt );
293 table_size = 6 + 8 * pcnt;
294
295 OTV_SIZE_CHECK( DeviceTableOffset );
296 if ( DeviceTableOffset )
297 otv_Device_validate( table + DeviceTableOffset, otvalid );
298
299 for ( i = 0; i < pcnt; i++ )
300 {
301 FT_UInt gid;
302
303
304 gid = FT_NEXT_USHORT( p );
305 if ( gid >= otvalid->glyph_count )
307 p += 2*4; /* skip the Start, End, Full, and Flags fields */
308 }
309
310 /* OTV_EXIT; */
311 }
312
313
314 static void
316 OTV_Validator otvalid )
317 {
318 FT_Bytes p = table;
319 FT_UInt vcnt, table_size;
320 FT_UInt i;
321
322 OTV_OPTIONAL_TABLE( GlyphAssembly );
323
324
325 /* OTV_NAME_ENTER( "MathGlyphConstruction" ); */
326
327 OTV_LIMIT_CHECK( 4 );
328
329 OTV_OPTIONAL_OFFSET( GlyphAssembly );
330 vcnt = FT_NEXT_USHORT( p );
331
332 OTV_LIMIT_CHECK( 4 * vcnt );
333 table_size = 4 + 4 * vcnt;
334
335 for ( i = 0; i < vcnt; i++ )
336 {
337 FT_UInt gid;
338
339
340 gid = FT_NEXT_USHORT( p );
341 if ( gid >= otvalid->glyph_count )
343 p += 2; /* skip the size */
344 }
345
346 OTV_SIZE_CHECK( GlyphAssembly );
347 if ( GlyphAssembly )
348 otv_GlyphAssembly_validate( table+GlyphAssembly, otvalid );
349
350 /* OTV_EXIT; */
351 }
352
353
354 static void
356 OTV_Validator otvalid )
357 {
358 FT_Bytes p = table;
359 FT_UInt vcnt, hcnt, i, table_size;
360
361 OTV_OPTIONAL_TABLE( VCoverage );
362 OTV_OPTIONAL_TABLE( HCoverage );
364
365
366 OTV_NAME_ENTER( "MathVariants" );
367
368 OTV_LIMIT_CHECK( 10 );
369
370 p += 2; /* Skip the MinConnectorOverlap constant */
371 OTV_OPTIONAL_OFFSET( VCoverage );
372 OTV_OPTIONAL_OFFSET( HCoverage );
373 vcnt = FT_NEXT_USHORT( p );
374 hcnt = FT_NEXT_USHORT( p );
375
376 OTV_LIMIT_CHECK( 2 * vcnt + 2 * hcnt );
377 table_size = 10 + 2 * vcnt + 2 * hcnt;
378
379 OTV_SIZE_CHECK( VCoverage );
380 if ( VCoverage )
381 otv_Coverage_validate( table + VCoverage, otvalid, (FT_Int)vcnt );
382
383 OTV_SIZE_CHECK( HCoverage );
384 if ( HCoverage )
385 otv_Coverage_validate( table + HCoverage, otvalid, (FT_Int)hcnt );
386
387 for ( i = 0; i < vcnt; i++ )
388 {
392 }
393
394 for ( i = 0; i < hcnt; i++ )
395 {
399 }
400
401 OTV_EXIT;
402 }
403
404
405 /*************************************************************************/
406 /*************************************************************************/
407 /***** *****/
408 /***** MATH TABLE *****/
409 /***** *****/
410 /*************************************************************************/
411 /*************************************************************************/
412
413 /* sets otvalid->glyph_count */
414
415 FT_LOCAL_DEF( void )
417 FT_UInt glyph_count,
418 FT_Validator ftvalid )
419 {
420 OTV_ValidatorRec otvalidrec;
421 OTV_Validator otvalid = &otvalidrec;
422 FT_Bytes p = table;
423 FT_UInt MathConstants, MathGlyphInfo, MathVariants;
424
425
426 otvalid->root = ftvalid;
427
428 FT_TRACE3(( "validating MATH table\n" ));
429 OTV_INIT;
430
431 OTV_LIMIT_CHECK( 10 );
432
433 if ( FT_NEXT_ULONG( p ) != 0x10000UL ) /* Version */
435
436 MathConstants = FT_NEXT_USHORT( p );
437 MathGlyphInfo = FT_NEXT_USHORT( p );
438 MathVariants = FT_NEXT_USHORT( p );
439
440 otvalid->glyph_count = glyph_count;
441
442 otv_MathConstants_validate( table + MathConstants,
443 otvalid );
444 otv_MathGlyphInfo_validate( table + MathGlyphInfo,
445 otvalid );
446 otv_MathVariants_validate ( table + MathVariants,
447 otvalid );
448
449 FT_TRACE4(( "\n" ));
450 }
451
452
453/* END */
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
#define FT_UNUSED(arg)
Definition: ftconfig.h:101
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:238
unsigned int FT_UInt
Definition: fttypes.h:231
const FT_Byte * FT_Bytes
Definition: fttypes.h:165
signed int FT_Int
Definition: fttypes.h:220
#define FT_INVALID_FORMAT
Definition: ftvalid.h:142
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
#define FT_INVALID_GLYPH_ID
Definition: ftvalid.h:146
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
otv_Coverage_validate(FT_Bytes table, OTV_Validator otvalid, FT_Int expected_count)
Definition: otvcommn.c:41
otv_Device_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvcommn.c:307
#define OTV_SIZE_CHECK(_size)
Definition: otvcommn.h:97
typedefFT_BEGIN_HEADER struct OTV_ValidatorRec_ * OTV_Validator
Definition: otvcommn.h:39
#define OTV_OPTIONAL_OFFSET(_offset)
Definition: otvcommn.h:79
#define OTV_INIT
Definition: otvcommn.h:225
#define OTV_EXIT
Definition: otvcommn.h:228
#define OTV_NAME_ENTER(name)
Definition: otvcommn.h:227
#define OTV_LIMIT_CHECK(_count)
Definition: otvcommn.h:91
#define OTV_OPTIONAL_TABLE(_table)
Definition: otvcommn.h:73
otv_MATH_validate(FT_Bytes table, FT_UInt glyph_count, FT_Validator ftvalid)
Definition: otvmath.c:416
static void otv_MathItalicsCorrectionInfo_validate(FT_Bytes table, OTV_Validator otvalid, FT_Int isItalic)
Definition: otvmath.c:86
static void otv_MathConstants_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:46
static void otv_GlyphAssembly_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:274
static void otv_MathGlyphConstruction_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:315
static void otv_MathKern_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:135
static void otv_MathGlyphInfo_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:225
static void otv_MathVariants_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:355
static void otv_MathKernInfo_validate(FT_Bytes table, OTV_Validator otvalid)
Definition: otvmath.c:178
LOCAL int table_size
Definition: write.c:65