xref: /inferno-os/libfreetype/otlayout.h (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 #ifndef __OT_LAYOUT_H__
2 #define __OT_LAYOUT_H__
3 
4 
5 #include "otlconf.h"
6 
7 OTL_BEGIN_HEADER
8 
9  /************************************************************************/
10  /************************************************************************/
11  /*****                                                              *****/
12  /*****                       BASE DATA TYPES                        *****/
13  /*****                                                              *****/
14  /************************************************************************/
15  /************************************************************************/
16 
17   typedef unsigned char     OTL_Byte;
18   typedef const OTL_Byte*   OTL_Bytes;
19 
20   typedef int               OTL_Error;
21 
22   typedef void*             OTL_Pointer;
23 
24   typedef int               OTL_Int;
25   typedef unsigned int      OTL_UInt;
26 
27   typedef long              OTL_Long;
28   typedef unsigned long     OTL_ULong;
29 
30   typedef short             OTL_Int16;
31   typedef unsigned short    OTL_UInt16;
32 
33 
34 #if OTL_SIZEOF_INT == 4
35 
36   typedef int               OTL_Int32;
37   typedef unsigned int      OTL_UInt32;
38 
39 #elif OTL_SIZEOF_LONG == 4
40 
41   typedef long              OTL_Int32;
42   typedef unsigned long     OTL_UInt32;
43 
44 #else
45 #  error "no 32-bits type found"
46 #endif
47 
48   typedef OTL_UInt32        OTL_Tag;
49 
50  /************************************************************************/
51  /************************************************************************/
52  /*****                                                              *****/
53  /*****                       ERROR CODES                            *****/
54  /*****                                                              *****/
55  /************************************************************************/
56  /************************************************************************/
57 
58   typedef enum
59   {
60     OTL_Err_Ok = 0,
61     OTL_Err_InvalidArgument,
62     OTL_Err_InvalidFormat,
63     OTL_Err_InvalidOffset,
64 
65     OTL_Err_Max
66 
67   } OTL_Error;
68 
69 
70  /************************************************************************/
71  /************************************************************************/
72  /*****                                                              *****/
73  /*****                     MEMORY MANAGEMENT                        *****/
74  /*****                                                              *****/
75  /************************************************************************/
76  /************************************************************************/
77 
78   typedef OTL_Pointer  (*OTL_AllocFunc)( OTL_ULong    size,
79                                          OTL_Pointer  data );
80 
81   typedef OTL_Pointer  (*OTL_ReallocFunc)( OTL_Pointer   block,
82                                            OTL_ULong     size,
83                                            OTL_Pointer   data );
84 
85   typedef void         (*OTL_FreeFunc)( OTL_Pointer  block,
86                                         OTL_Pointer  data );
87 
88   typedef struct OTL_MemoryRec_
89   {
90     OTL_Pointer      mem_data;
91     OTL_AllocFunc    mem_alloc;
92     OTL_ReallocFunc  mem_realloc;
93     OTL_FreeFunc     mem_free;
94 
95   } OTL_MemoryRec, *OTL_Memory;
96 
97  /************************************************************************/
98  /************************************************************************/
99  /*****                                                              *****/
100  /*****                        ENUMERATIONS                          *****/
101  /*****                                                              *****/
102  /************************************************************************/
103  /************************************************************************/
104 
105 /* re-define OTL_MAKE_TAG to something different if you're not */
106 /* using an ASCII-based character set (Vaxes anyone ?)         */
107 #ifndef  OTL_MAKE_TAG
108 #define  OTL_MAKE_TAG(c1,c2,c3,c4)         \
109            ( ( (OTL_UInt32)(c1) << 24 ) |  \
110                (OTL_UInt32)(c2) << 16 ) |  \
111                (OTL_UInt32)(c3) <<  8 ) |  \
112                (OTL_UInt32)(c4)         )
113 #endif
114 
115   typedef enum OTL_ScriptTag_
116   {
117     OTL_SCRIPT_NONE = 0,
118 
119 #define OTL_SCRIPT_TAG(c1,c2,c3,c4,s,n)  OTL_SCRIPT_TAG_ ## n = OTL_MAKE_TAG(c1,c2,c3,c4),
120 #include "otltags.h"
121 
122     OTL_SCRIPT_MAX
123 
124   } OTL_ScriptTag;
125 
126 
127   typedef enum OTL_LangTag_
128   {
129     OTL_LANG_DEFAULT = 0,
130 
131 #define OTL_LANG_TAG(c1,c2,c3,c4,s,n)  OTL_LANG_TAG_ ## n = OTL_MAKE_TAG(c1,c2,c3,c4),
132 #include "otltags.h"
133 
134     OTL_LANG_MAX
135 
136   } OTL_LangTag;
137 
138 
139  /************************************************************************/
140  /************************************************************************/
141  /*****                                                              *****/
142  /*****                       MEMORY READS                           *****/
143  /*****                                                              *****/
144  /************************************************************************/
145  /************************************************************************/
146 
147 #define  OTL_PEEK_USHORT(p)  ( ((OTL_UInt)((p)[0]) << 8) |  \
148                                ((OTL_UInt)((p)[1])     ) )
149 
150 #define  OTL_PEEK_ULONG(p)   ( ((OTL_UInt32)((p)[0]) << 24) |  \
151                                ((OTL_UInt32)((p)[1]) << 16) |  \
152                                ((OTL_UInt32)((p)[2]) <<  8) |  \
153                                ((OTL_UInt32)((p)[3])      ) )
154 
155 #define  OTL_PEEK_SHORT(p)     ((OTL_Int16)OTL_PEEK_USHORT(p))
156 
157 #define  OTL_PEEK_LONG(p)      ((OTL_Int32)OTL_PEEK_ULONG(p))
158 
159 #define  OTL_NEXT_USHORT(p)  ( (p) += 2, OTL_PEEK_USHORT((p)-2) )
160 #define  OTL_NEXT_ULONG(p)   ( (p) += 4, OTL_PEEK_ULONG((p)-4) )
161 
162 #define  OTL_NEXT_SHORT(p)   ((OTL_Int16)OTL_NEXT_USHORT(p))
163 #define  OTL_NEXT_LONG(p)    ((OTL_Int32)OTL_NEXT_ULONG(p))
164 
165  /************************************************************************/
166  /************************************************************************/
167  /*****                                                              *****/
168  /*****                        VALIDATION                            *****/
169  /*****                                                              *****/
170  /************************************************************************/
171  /************************************************************************/
172 
173   typedef struct OTL_ValidatorRec_*  OTL_Validator;
174 
175   typedef struct OTL_ValidatorRec_
176   {
177     OTL_Bytes    limit;
178     OTL_Bytes    base;
179     OTL_Error    error;
180     OTL_jmp_buf  jump_buffer;
181 
182   } OTL_ValidatorRec;
183 
184   typedef void  (*OTL_ValidateFunc)( OTL_Bytes  table,
185                                      OTL_Valid  valid );
186 
187   OTL_API( void )
188   otl_validator_error( OTL_Validator  validator,
189                        OTL_Error      error );
190 
191 #define  OTL_INVALID(e)  otl_validator_error( valid, e )
192 
193 #define  OTL_INVALID_TOO_SHORT  OTL_INVALID( OTL_Err_InvalidOffset )
194 #define  OTL_INVALID_DATA       OTL_INVALID( OTL_Err_InvalidFormat )
195 
196 #define  OTL_CHECK(_count)   OTL_BEGIN_STMNT                       \
197                                if ( p + (_count) > valid->limit )  \
198                                  OTL_INVALID_TOO_SHORT;            \
199                              OTL_END_STMNT
200 
201  /* */
202 
203 OTL_END_HEADER
204 
205 #endif /* __OPENTYPE_LAYOUT_H__ */
206