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]
otvgdef.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* otvgdef.c */
4 /* */
5 /* OpenType GDEF table validation (body). */
6 /* */
7 /* Copyright 2004, 2005, 2007 by */
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 #include "otvalid.h"
20 #include "otvcommn.h"
21 
22 
23  /*************************************************************************/
24  /* */
25  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
26  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
27  /* messages during execution. */
28  /* */
29 #undef FT_COMPONENT
30 #define FT_COMPONENT trace_otvgdef
31 
32 
33  /*************************************************************************/
34  /*************************************************************************/
35  /***** *****/
36  /***** UTILITY FUNCTIONS *****/
37  /***** *****/
38  /*************************************************************************/
39  /*************************************************************************/
40 
41 #define AttachListFunc otv_O_x_Ox
42 #define LigCaretListFunc otv_O_x_Ox
43 
44  /* sets valid->extra1 (0) */
45 
46  static void
47  otv_O_x_Ox( FT_Bytes table,
48  OTV_Validator valid )
49  {
50  FT_Bytes p = table;
51  FT_Bytes Coverage;
52  FT_UInt GlyphCount;
54 
55 
56  OTV_ENTER;
57 
58  OTV_LIMIT_CHECK( 4 );
59  Coverage = table + FT_NEXT_USHORT( p );
60  GlyphCount = FT_NEXT_USHORT( p );
61 
62  OTV_TRACE(( " (GlyphCount = %d)\n", GlyphCount ));
63 
64  otv_Coverage_validate( Coverage, valid, GlyphCount );
65  if ( GlyphCount != otv_Coverage_get_count( Coverage ) )
67 
68  OTV_LIMIT_CHECK( GlyphCount * 2 );
69 
70  valid->nesting_level++;
71  func = valid->func[valid->nesting_level];
72  valid->extra1 = 0;
73 
74  for ( ; GlyphCount > 0; GlyphCount-- )
75  func( table + FT_NEXT_USHORT( p ), valid );
76 
77  valid->nesting_level--;
78 
79  OTV_EXIT;
80  }
81 
82 
83  /*************************************************************************/
84  /*************************************************************************/
85  /***** *****/
86  /***** LIGATURE CARETS *****/
87  /***** *****/
88  /*************************************************************************/
89  /*************************************************************************/
90 
91 #define CaretValueFunc otv_CaretValue_validate
92 
93  static void
94  otv_CaretValue_validate( FT_Bytes table,
95  OTV_Validator valid )
96  {
97  FT_Bytes p = table;
98  FT_UInt CaretValueFormat;
99 
100 
101  OTV_ENTER;
102 
103  OTV_LIMIT_CHECK( 4 );
104 
105  CaretValueFormat = FT_NEXT_USHORT( p );
106 
107  OTV_TRACE(( " (format = %d)\n", CaretValueFormat ));
108 
109  switch ( CaretValueFormat )
110  {
111  case 1: /* CaretValueFormat1 */
112  /* skip Coordinate, no test */
113  break;
114 
115  case 2: /* CaretValueFormat2 */
116  /* skip CaretValuePoint, no test */
117  break;
118 
119  case 3: /* CaretValueFormat3 */
120  p += 2; /* skip Coordinate */
121 
122  OTV_LIMIT_CHECK( 2 );
123 
124  /* DeviceTable */
125  otv_Device_validate( table + FT_NEXT_USHORT( p ), valid );
126  break;
127 
128  default:
130  }
131 
132  OTV_EXIT;
133  }
134 
135 
136  /*************************************************************************/
137  /*************************************************************************/
138  /***** *****/
139  /***** GDEF TABLE *****/
140  /***** *****/
141  /*************************************************************************/
142  /*************************************************************************/
143 
144  /* sets valid->glyph_count */
145 
146  FT_LOCAL_DEF( void )
148  FT_Bytes gsub,
149  FT_Bytes gpos,
150  FT_UInt glyph_count,
151  FT_Validator ftvalid )
152  {
153  OTV_ValidatorRec validrec;
154  OTV_Validator valid = &validrec;
155  FT_Bytes p = table;
156  FT_UInt table_size;
157  FT_Bool need_MarkAttachClassDef;
158 
159  OTV_OPTIONAL_TABLE( GlyphClassDef );
160  OTV_OPTIONAL_TABLE( AttachListOffset );
161  OTV_OPTIONAL_TABLE( LigCaretListOffset );
162  OTV_OPTIONAL_TABLE( MarkAttachClassDef );
163 
164 
165  valid->root = ftvalid;
166 
167  FT_TRACE3(( "validating GDEF table\n" ));
168  OTV_INIT;
169 
170  OTV_LIMIT_CHECK( 12 );
171 
172  if ( FT_NEXT_ULONG( p ) != 0x10000UL ) /* Version */
174 
175  /* MarkAttachClassDef has been added to the OpenType */
176  /* specification without increasing GDEF's version, */
177  /* so we use this ugly hack to find out whether the */
178  /* table is needed actually. */
179 
180  need_MarkAttachClassDef = FT_BOOL(
183 
184  if ( need_MarkAttachClassDef )
185  table_size = 12; /* OpenType >= 1.2 */
186  else
187  table_size = 10; /* OpenType < 1.2 */
188 
189  valid->glyph_count = glyph_count;
190 
191  OTV_OPTIONAL_OFFSET( GlyphClassDef );
192  OTV_SIZE_CHECK( GlyphClassDef );
193  if ( GlyphClassDef )
194  otv_ClassDef_validate( table + GlyphClassDef, valid );
195 
196  OTV_OPTIONAL_OFFSET( AttachListOffset );
197  OTV_SIZE_CHECK( AttachListOffset );
198  if ( AttachListOffset )
199  {
200  OTV_NEST2( AttachList, AttachPoint );
201  OTV_RUN( table + AttachListOffset, valid );
202  }
203 
204  OTV_OPTIONAL_OFFSET( LigCaretListOffset );
205  OTV_SIZE_CHECK( LigCaretListOffset );
206  if ( LigCaretListOffset )
207  {
208  OTV_NEST3( LigCaretList, LigGlyph, CaretValue );
209  OTV_RUN( table + LigCaretListOffset, valid );
210  }
211 
212  if ( need_MarkAttachClassDef )
213  {
214  OTV_OPTIONAL_OFFSET( MarkAttachClassDef );
215  OTV_SIZE_CHECK( MarkAttachClassDef );
216  if ( MarkAttachClassDef )
217  otv_ClassDef_validate( table + MarkAttachClassDef, valid );
218  }
219 
220  FT_TRACE4(( "\n" ));
221  }
222 
223 
224 /* END */
#define OTV_EXIT
Definition: otvcommn.h:198
GLfloat GLfloat p
#define OTV_TRACE(s)
Definition: otvcommn.h:200
#define OTV_OPTIONAL_TABLE(_table)
Definition: otvcommn.h:73
#define FT_INVALID_FORMAT
Definition: ftvalid.h:133
#define OTV_INIT
Definition: otvcommn.h:195
#define OTV_ENTER
Definition: otvcommn.h:196
void(* OTV_Validate_Func)(FT_Bytes table, OTV_Validator valid)
Definition: otvcommn.h:41
#define OTV_NEST2(x, y)
Definition: otvcommn.h:180
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
otv_ClassDef_validate(FT_Bytes table, OTV_Validator valid)
Definition: otvcommn.c:221
#define OTV_RUN
Definition: otvcommn.h:205
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
const FT_Byte * FT_Bytes
Definition: fttypes.h:161
#define OTV_LIMIT_CHECK(_count)
Definition: otvcommn.h:82
#define FT_BOOL(x)
Definition: fttypes.h:574
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
otv_GSUBGPOS_have_MarkAttachmentType_flag(FT_Bytes table)
Definition: otvcommn.c:1047
otv_Coverage_validate(FT_Bytes table, OTV_Validator valid, FT_Int expected_count)
Definition: otvcommn.c:41
typedefFT_BEGIN_HEADER struct OTV_ValidatorRec_ * OTV_Validator
Definition: otvcommn.h:39
unsigned int FT_UInt
Definition: fttypes.h:227
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:238
GLenum func
#define OTV_SIZE_CHECK(_size)
Definition: otvcommn.h:88
otv_Device_validate(FT_Bytes table, OTV_Validator valid)
Definition: otvcommn.c:307
#define FT_INVALID_DATA
Definition: ftvalid.h:141
#define OTV_NEST3(x, y, z)
Definition: otvcommn.h:187
otv_GDEF_validate(FT_Bytes table, FT_Bytes gsub, FT_Bytes gpos, FT_UInt glyph_count, FT_Validator ftvalid)
Definition: otvgdef.c:147
GLenum GLsizei GLenum GLenum const GLvoid * table
#define OTV_OPTIONAL_OFFSET(_offset)
Definition: otvcommn.h:76
otv_Coverage_get_count(FT_Bytes table)
Definition: otvcommn.c:175
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:236