Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
gxvprop.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* gxvprop.c */
4 /* */
5 /* TrueTypeGX/AAT prop table validation (body). */
6 /* */
7 /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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 /* */
20 /* gxvalid is derived from both gxlayout module and otvalid module. */
21 /* Development of gxlayout is supported by the Information-technology */
22 /* Promotion Agency(IPA), Japan. */
23 /* */
24 /***************************************************************************/
25 
26 
27 #include "gxvalid.h"
28 #include "gxvcommn.h"
29 
30 
31  /*************************************************************************/
32  /* */
33  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
34  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
35  /* messages during execution. */
36  /* */
37 #undef FT_COMPONENT
38 #define FT_COMPONENT trace_gxvprop
39 
40 
41  /*************************************************************************/
42  /*************************************************************************/
43  /***** *****/
44  /***** Data and Types *****/
45  /***** *****/
46  /*************************************************************************/
47  /*************************************************************************/
48 
49 #define GXV_PROP_HEADER_SIZE ( 4 + 2 + 2 )
50 #define GXV_PROP_SIZE_MIN GXV_PROP_HEADER_SIZE
51 
52  typedef struct GXV_prop_DataRec_
53  {
55 
57 
58 #define GXV_PROP_DATA( field ) GXV_TABLE_DATA( prop, field )
59 
60 #define GXV_PROP_FLOATER 0x8000U
61 #define GXV_PROP_USE_COMPLEMENTARY_BRACKET 0x1000U
62 #define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET 0x0F00U
63 #define GXV_PROP_ATTACHING_TO_RIGHT 0x0080U
64 #define GXV_PROP_RESERVED 0x0060U
65 #define GXV_PROP_DIRECTIONALITY_CLASS 0x001FU
66 
67 
68  /*************************************************************************/
69  /*************************************************************************/
70  /***** *****/
71  /***** UTILITY FUNCTIONS *****/
72  /***** *****/
73  /*************************************************************************/
74  /*************************************************************************/
75 
76  static void
77  gxv_prop_zero_advance_validate( FT_UShort gid,
78  GXV_Validator valid )
79  {
80  FT_Face face;
82  FT_GlyphSlot glyph;
83 
84 
85  GXV_NAME_ENTER( "zero advance" );
86 
87  face = valid->face;
88 
89  error = FT_Load_Glyph( face,
90  gid,
92  if ( error )
94 
95  glyph = face->glyph;
96 
97  if ( glyph->advance.x != (FT_Pos)0 ||
98  glyph->advance.y != (FT_Pos)0 )
99  {
100  GXV_TRACE(( " found non-zero advance in zero-advance glyph\n" ));
102  }
103 
104  GXV_EXIT;
105  }
106 
107 
108  /* Pass 0 as GLYPH to check the default property */
109  static void
110  gxv_prop_property_validate( FT_UShort property,
111  FT_UShort glyph,
112  GXV_Validator valid )
113  {
114  if ( glyph != 0 && ( property & GXV_PROP_FLOATER ) )
115  gxv_prop_zero_advance_validate( glyph, valid );
116 
117  if ( property & GXV_PROP_USE_COMPLEMENTARY_BRACKET )
118  {
120  char complement;
121 
122 
123  offset = (FT_UShort)( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET );
124  if ( offset == 0 )
125  {
126  GXV_TRACE(( " found zero offset to property\n" ));
128  }
129 
130  complement = (char)( offset >> 8 );
131  if ( complement & 0x08 )
132  {
133  /* Top bit is set: negative */
134 
135  /* Calculate the absolute offset */
136  complement = (char)( ( complement & 0x07 ) + 1 );
137 
138  /* The gid for complement must be greater than 0 */
139  if ( glyph <= complement )
140  {
141  GXV_TRACE(( " found non-positive glyph complement\n" ));
143  }
144  }
145  else
146  {
147  /* The gid for complement must be the face. */
148  gxv_glyphid_validate( (FT_UShort)( glyph + complement ), valid );
149  }
150  }
151  else
152  {
153  if ( property & GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET )
154  GXV_TRACE(( "glyph %d cannot have complementary bracketing\n",
155  glyph ));
156  }
157 
158  /* this is introduced in version 2.0 */
159  if ( property & GXV_PROP_ATTACHING_TO_RIGHT )
160  {
161  if ( GXV_PROP_DATA( version ) == 0x00010000UL )
162  {
163  GXV_TRACE(( " found older version (1.0) in new version table\n" ));
165  }
166  }
167 
168  if ( property & GXV_PROP_RESERVED )
169  {
170  GXV_TRACE(( " found non-zero bits in reserved bits\n" ));
172  }
173 
174  if ( ( property & GXV_PROP_DIRECTIONALITY_CLASS ) > 11 )
175  {
176  /* TODO: Too restricted. Use the validation level. */
177  if ( GXV_PROP_DATA( version ) == 0x00010000UL ||
178  GXV_PROP_DATA( version ) == 0x00020000UL )
179  {
180  GXV_TRACE(( " found too old version in directionality class\n" ));
182  }
183  }
184  }
185 
186 
187  static void
188  gxv_prop_LookupValue_validate( FT_UShort glyph,
189  GXV_LookupValueCPtr value_p,
190  GXV_Validator valid )
191  {
192  gxv_prop_property_validate( value_p->u, glyph, valid );
193  }
194 
195 
196  /*
197  +===============+ --------+
198  | lookup header | |
199  +===============+ |
200  | BinSrchHeader | |
201  +===============+ |
202  | lastGlyph[0] | |
203  +---------------+ |
204  | firstGlyph[0] | | head of lookup table
205  +---------------+ | +
206  | offset[0] | -> | offset [byte]
207  +===============+ | +
208  | lastGlyph[1] | | (glyphID - firstGlyph) * 2 [byte]
209  +---------------+ |
210  | firstGlyph[1] | |
211  +---------------+ |
212  | offset[1] | |
213  +===============+ |
214  |
215  ... |
216  |
217  16bit value array |
218  +===============+ |
219  | value | <-------+
220  ...
221  */
222 
223  static GXV_LookupValueDesc
224  gxv_prop_LookupFmt4_transit( FT_UShort relative_gindex,
225  GXV_LookupValueCPtr base_value_p,
226  FT_Bytes lookuptbl_limit,
227  GXV_Validator valid )
228  {
229  FT_Bytes p;
230  FT_Bytes limit;
233 
234  /* XXX: check range? */
235  offset = (FT_UShort)( base_value_p->u +
236  relative_gindex * sizeof ( FT_UShort ) );
237  p = valid->lookuptbl_head + offset;
238  limit = lookuptbl_limit;
239 
240  GXV_LIMIT_CHECK ( 2 );
241  value.u = FT_NEXT_USHORT( p );
242 
243  return value;
244  }
245 
246 
247  /*************************************************************************/
248  /*************************************************************************/
249  /***** *****/
250  /***** prop TABLE *****/
251  /***** *****/
252  /*************************************************************************/
253  /*************************************************************************/
254 
255  FT_LOCAL_DEF( void )
257  FT_Face face,
258  FT_Validator ftvalid )
259  {
260  FT_Bytes p = table;
261  FT_Bytes limit = 0;
262  GXV_ValidatorRec validrec;
263  GXV_Validator valid = &validrec;
264 
265  GXV_prop_DataRec proprec;
266  GXV_prop_Data prop = &proprec;
267 
270  FT_UShort defaultProp;
271 
272 
273  valid->root = ftvalid;
274  valid->table_data = prop;
275  valid->face = face;
276 
277  FT_TRACE3(( "validating `prop' table\n" ));
278  GXV_INIT;
279 
280  GXV_LIMIT_CHECK( 4 + 2 + 2 );
281  version = FT_NEXT_ULONG( p );
282  format = FT_NEXT_USHORT( p );
283  defaultProp = FT_NEXT_USHORT( p );
284 
285  GXV_TRACE(( " version 0x%08x\n", version ));
286  GXV_TRACE(( " format 0x%04x\n", format ));
287  GXV_TRACE(( " defaultProp 0x%04x\n", defaultProp ));
288 
289  /* only versions 1.0, 2.0, 3.0 are defined (1996) */
290  if ( version != 0x00010000UL &&
291  version != 0x00020000UL &&
292  version != 0x00030000UL )
293  {
294  GXV_TRACE(( " found unknown version\n" ));
296  }
297 
298 
299  /* only formats 0x0000, 0x0001 are defined (1996) */
300  if ( format > 1 )
301  {
302  GXV_TRACE(( " found unknown format\n" ));
304  }
305 
306  gxv_prop_property_validate( defaultProp, 0, valid );
307 
308  if ( format == 0 )
309  {
310  FT_TRACE3(( "(format 0, no per-glyph properties, "
311  "remaining %d bytes are skipped)", limit - p ));
312  goto Exit;
313  }
314 
315  /* format == 1 */
317 
319  valid->lookupval_func = gxv_prop_LookupValue_validate;
320  valid->lookupfmt4_trans = gxv_prop_LookupFmt4_transit;
321 
322  gxv_LookupTable_validate( p, limit, valid );
323 
324  Exit:
325  FT_TRACE4(( "\n" ));
326  }
327 
328 
329 /* END */
struct GXV_prop_DataRec_ * GXV_prop_Data
int FT_Error
Definition: fttypes.h:296
FT_BEGIN_HEADER typedef signed long FT_Pos
Definition: ftimage.h:59
GLfloat GLfloat p
#define FT_INVALID_FORMAT
Definition: ftvalid.h:133
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
#define GXV_PROP_COMPLEMENTARY_BRACKET_OFFSET
Definition: gxvprop.c:62
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
sizeof(AF_ModuleRec)
gxv_prop_validate(FT_Bytes table, FT_Face face, FT_Validator ftvalid)
Definition: gxvprop.c:256
#define GXV_PROP_USE_COMPLEMENTARY_BRACKET
Definition: gxvprop.c:61
#define GXV_PROP_DATA(field)
Definition: gxvprop.c:58
FT_Vector advance
Definition: freetype.h:1623
void * table_data
Definition: gxvcommn.h:242
GLenum GLuint GLint GLenum face
#define GXV_PROP_FLOATER
Definition: gxvprop.c:60
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
Definition: ftobjs.c:574
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
struct GXV_prop_DataRec_ GXV_prop_DataRec
#define GXV_EXIT
Definition: gxvcommn.h:302
FT_Bytes lookuptbl_head
Definition: gxvcommn.h:249
#define GXV_PROP_RESERVED
Definition: gxvprop.c:64
FT_Error error
Definition: cffdrivr.c:411
FT_Pos x
Definition: ftimage.h:77
FT_Pos y
Definition: ftimage.h:78
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
#define GXV_PROP_DIRECTIONALITY_CLASS
Definition: gxvprop.c:65
int const char * version
Definition: zlib.h:813
const FT_Byte * FT_Bytes
Definition: fttypes.h:161
GLintptr offset
GLsizei const GLfloat * value
gxv_LookupTable_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvcommn.c:755
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
#define FT_INVALID_OFFSET
Definition: ftvalid.h:129
signed long FT_Fixed
Definition: fttypes.h:284
FT_GlyphSlot glyph
Definition: freetype.h:956
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:238
GXV_Lookup_Fmt4_Transit_Func lookupfmt4_trans
Definition: gxvcommn.h:248
FT_Validator root
Definition: gxvcommn.h:239
#define FT_INVALID_DATA
Definition: ftvalid.h:141
#define FT_INVALID_GLYPH_ID
Definition: ftvalid.h:137
GXV_Lookup_Value_Validate_Func lookupval_func
Definition: gxvcommn.h:247
GXV_LookupValue_SignSpec lookupval_sign
Definition: gxvcommn.h:246
#define FT_LOAD_IGNORE_TRANSFORM
Definition: freetype.h:2559
unsigned short FT_UShort
Definition: fttypes.h:205
GLenum GLsizei GLenum GLenum const GLvoid * table
#define GXV_INIT
Definition: gxvcommn.h:300
gxv_glyphid_validate(FT_UShort gid, GXV_Validator valid)
Definition: gxvcommn.c:813
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLint limit
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:236
#define GXV_PROP_ATTACHING_TO_RIGHT
Definition: gxvprop.c:63
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272