ReactOS 0.4.16-dev-2358-g0df3463
ttbdf.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * ttbdf.c
4 *
5 * TrueType and OpenType embedded BDF properties (body).
6 *
7 * Copyright (C) 2005-2020 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
21#include <freetype/tttags.h>
22#include "ttbdf.h"
23
24#include "sferrors.h"
25
26
27#ifdef TT_CONFIG_OPTION_BDF
28
29 /**************************************************************************
30 *
31 * The macro FT_COMPONENT is used in trace mode. It is an implicit
32 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
33 * messages during execution.
34 */
35#undef FT_COMPONENT
36#define FT_COMPONENT ttbdf
37
38
39 FT_LOCAL_DEF( void )
40 tt_face_free_bdf_props( TT_Face face )
41 {
42 TT_BDF bdf = &face->bdf;
43
44
45 if ( bdf->loaded )
46 {
47 FT_Stream stream = FT_FACE( face )->stream;
48
49
50 if ( bdf->table )
51 FT_FRAME_RELEASE( bdf->table );
52
53 bdf->table_end = NULL;
54 bdf->strings = NULL;
55 bdf->strings_size = 0;
56 }
57 }
58
59
60 static FT_Error
61 tt_face_load_bdf_props( TT_Face face,
63 {
64 TT_BDF bdf = &face->bdf;
67
68
69 FT_ZERO( bdf );
70
72 if ( error ||
73 length < 8 ||
74 FT_FRAME_EXTRACT( length, bdf->table ) )
75 {
76 error = FT_THROW( Invalid_Table );
77 goto Exit;
78 }
79
80 bdf->table_end = bdf->table + length;
81
82 {
83 FT_Byte* p = bdf->table;
85 FT_UInt num_strikes = FT_NEXT_USHORT( p );
88 FT_Byte* strike;
89
90
91 if ( version != 0x0001 ||
92 strings < 8 ||
93 ( strings - 8 ) / 4 < num_strikes ||
94 strings + 1 > length )
95 {
96 goto BadTable;
97 }
98
99 bdf->num_strikes = num_strikes;
100 bdf->strings = bdf->table + strings;
101 bdf->strings_size = length - strings;
102
103 count = bdf->num_strikes;
104 p = bdf->table + 8;
105 strike = p + count * 4;
106
107
108 for ( ; count > 0; count-- )
109 {
110 FT_UInt num_items = FT_PEEK_USHORT( p + 2 );
111
112 /*
113 * We don't need to check the value sets themselves, since this
114 * is done later.
115 */
116 strike += 10 * num_items;
117
118 p += 4;
119 }
120
121 if ( strike > bdf->strings )
122 goto BadTable;
123 }
124
125 bdf->loaded = 1;
126
127 Exit:
128 return error;
129
130 BadTable:
131 FT_FRAME_RELEASE( bdf->table );
132 FT_ZERO( bdf );
133 error = FT_THROW( Invalid_Table );
134 goto Exit;
135 }
136
137
139 tt_face_find_bdf_prop( TT_Face face,
140 const char* property_name,
141 BDF_PropertyRec *aprop )
142 {
143 TT_BDF bdf = &face->bdf;
144 FT_Size size = FT_FACE( face )->size;
146 FT_Byte* p;
148 FT_Byte* strike;
149 FT_Offset property_len;
150
151
153
154 if ( bdf->loaded == 0 )
155 {
156 error = tt_face_load_bdf_props( face, FT_FACE( face )->stream );
157 if ( error )
158 goto Exit;
159 }
160
161 count = bdf->num_strikes;
162 p = bdf->table + 8;
163 strike = p + 4 * count;
164
165 error = FT_ERR( Invalid_Argument );
166
167 if ( !size || !property_name )
168 goto Exit;
169
170 property_len = ft_strlen( property_name );
171 if ( property_len == 0 )
172 goto Exit;
173
174 for ( ; count > 0; count-- )
175 {
176 FT_UInt _ppem = FT_NEXT_USHORT( p );
177 FT_UInt _count = FT_NEXT_USHORT( p );
178
179
180 if ( _ppem == size->metrics.y_ppem )
181 {
182 count = _count;
183 goto FoundStrike;
184 }
185
186 strike += 10 * _count;
187 }
188 goto Exit;
189
190 FoundStrike:
191 p = strike;
192 for ( ; count > 0; count-- )
193 {
194 FT_UInt type = FT_PEEK_USHORT( p + 4 );
195
196
197 if ( ( type & 0x10 ) != 0 )
198 {
199 FT_UInt32 name_offset = FT_PEEK_ULONG( p );
200 FT_UInt32 value = FT_PEEK_ULONG( p + 6 );
201
202 /* be a bit paranoid for invalid entries here */
203 if ( name_offset < bdf->strings_size &&
204 property_len < bdf->strings_size - name_offset &&
205 ft_strncmp( property_name,
206 (const char*)bdf->strings + name_offset,
207 bdf->strings_size - name_offset ) == 0 )
208 {
209 switch ( type & 0x0F )
210 {
211 case 0x00: /* string */
212 case 0x01: /* atoms */
213 /* check that the content is really 0-terminated */
214 if ( value < bdf->strings_size &&
215 ft_memchr( bdf->strings + value, 0, bdf->strings_size ) )
216 {
218 aprop->u.atom = (const char*)bdf->strings + value;
220 goto Exit;
221 }
222 break;
223
224 case 0x02:
226 aprop->u.integer = (FT_Int32)value;
228 goto Exit;
229
230 case 0x03:
232 aprop->u.cardinal = value;
234 goto Exit;
235
236 default:
237 ;
238 }
239 }
240 }
241 p += 10;
242 }
243
244 Exit:
245 return error;
246 }
247
248#else /* !TT_CONFIG_OPTION_BDF */
249
250 /* ANSI C doesn't like empty source files */
251 typedef int _tt_bdf_dummy;
252
253#endif /* !TT_CONFIG_OPTION_BDF */
254
255
256/* END */
#define FT_LOCAL_DEF(x)
#define NULL
Definition: types.h:112
static const WCHAR version[]
Definition: asmname.c:66
return FT_Err_Ok
Definition: ftbbox.c:526
@ BDF_PROPERTY_TYPE_CARDINAL
Definition: ftbdf.h:78
@ BDF_PROPERTY_TYPE_NONE
Definition: ftbdf.h:75
@ BDF_PROPERTY_TYPE_ATOM
Definition: ftbdf.h:76
@ BDF_PROPERTY_TYPE_INTEGER
Definition: ftbdf.h:77
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_ZERO(p)
Definition: ftmemory.h:246
#define FT_FACE(x)
Definition: ftobjs.h:597
#define ft_strncmp
Definition: ftstdlib.h:89
#define ft_strlen
Definition: ftstdlib.h:88
#define ft_memchr
Definition: ftstdlib.h:80
#define FT_FRAME_RELEASE(bytes)
Definition: ftstream.h:562
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:244
#define FT_PEEK_USHORT(p)
Definition: ftstream.h:186
#define FT_FRAME_EXTRACT(size, bytes)
Definition: ftstream.h:556
#define FT_PEEK_ULONG(p)
Definition: ftstream.h:194
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:256
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
int FT_Error
Definition: fttypes.h:299
#define FT_ERR(e)
Definition: fttypes.h:599
unsigned int FT_UInt
Definition: fttypes.h:231
size_t FT_Offset
Definition: fttypes.h:323
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizei const GLchar *const * strings
Definition: glext.h:7622
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLfloat GLfloat p
Definition: glext.h:8902
#define error(str)
Definition: mkdosfs.c:1605
static void Exit(void)
Definition: sock.c:1330
FT_Int32 integer
Definition: ftbdf.h:122
BDF_PropertyType type
Definition: ftbdf.h:119
const char * atom
Definition: ftbdf.h:121
FT_UInt32 cardinal
Definition: ftbdf.h:123
union BDF_PropertyRec_::@4563 u
Definition: parse.h:23
int _tt_bdf_dummy
Definition: ttbdf.c:251
tt_face_goto_table(TT_Face face, FT_ULong tag, FT_Stream stream, FT_ULong *length)
Definition: ttload.c:131
#define TTAG_BDF
Definition: tttags.h:38
Definition: pdh_main.c:96