1 /****************************************************************************
2 *
3 * ftgloadr.c
4 *
5 * The FreeType glyph loader (body).
6 *
7 * Copyright (C) 2002-2019 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 <ft2build.h>
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_GLYPH_LOADER_H
22 #include FT_INTERNAL_MEMORY_H
23 #include FT_INTERNAL_OBJECTS_H
24
25 #undef FT_COMPONENT
26 #define FT_COMPONENT gloader
27
129 {
130 if ( loader )
131 {
132 FT_Memory memory = loader->memory;
133
134
135 FT_GlyphLoader_Reset( loader );
136 FT_FREE( loader );
137 }
138 }
139
140
141 /* re-adjust the `current' outline fields */
142 static void
143 FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader )
144 {
145 FT_Outline* base = &loader->base.outline;
146 FT_Outline* current = &loader->current.outline;
147
148
149 current->points = base->points + base->n_points;
150 current->tags = base->tags + base->n_points;
151 current->contours = base->contours + base->n_contours;
152
153 /* handle extra points table - if any */
154 if ( loader->use_extra )
155 {
156 loader->current.extra_points = loader->base.extra_points +
157 base->n_points;
158
159 loader->current.extra_points2 = loader->base.extra_points2 +
160 base->n_points;
161 }
162 }
163
164
165 FT_BASE_DEF( FT_Error )
166 FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader )
167 {
168 FT_Error error;
169 FT_Memory memory = loader->memory;
170
171
172 if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
173 {
174 loader->use_extra = 1;
175 loader->base.extra_points2 = loader->base.extra_points +
176 loader->max_points;
177
178 FT_GlyphLoader_Adjust_Points( loader );
179 }
180 return error;
181 }
182
183
184 /* re-adjust the `current' subglyphs field */
185 static void
186 FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader )
187 {
188 FT_GlyphLoad base = &loader->base;
189 FT_GlyphLoad current = &loader->current;
190
191
192 current->subglyphs = base->subglyphs + base->num_subglyphs;
193 }
194
195
196 /* Ensure that we can add `n_points' and `n_contours' to our glyph. */
197 /* This function reallocates its outline tables if necessary. Note that */
198 /* it DOESN'T change the number of points within the loader! */
199 /* */
200 FT_BASE_DEF( FT_Error )
201 FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader,
202 FT_UInt n_points,
203 FT_UInt n_contours )
204 {
205 FT_Memory memory = loader->memory;
206 FT_Error error = FT_Err_Ok;
207 FT_Outline* base = &loader->base.outline;
208 FT_Outline* current = &loader->current.outline;
209 FT_Bool adjust = 0;
210
211 FT_UInt new_max, old_max;
212
213
214 /* check points & tags */
215 new_max = (FT_UInt)base->n_points + (FT_UInt)current->n_points +
216 n_points;
217 old_max = loader->max_points;
218
219 if ( new_max > old_max )
220 {
221 new_max = FT_PAD_CEIL( new_max, 8 );
222
223 if ( new_max > FT_OUTLINE_POINTS_MAX )
224 return FT_THROW( Array_Too_Large );
225
226 if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
227 FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
228 goto Exit;
229
230 if ( loader->use_extra )
231 {
232 if ( FT_RENEW_ARRAY( loader->base.extra_points,
233 old_max * 2, new_max * 2 ) )
234 goto Exit;
235
236 FT_ARRAY_MOVE( loader->base.extra_points + new_max,
237 loader->base.extra_points + old_max,
238 old_max );
239
240 loader->base.extra_points2 = loader->base.extra_points + new_max;
241 }
242
243 adjust = 1;
244 loader->max_points = new_max;
245 }
246
247 /* check contours */
248 old_max = loader->max_contours;
249 new_max = (FT_UInt)base->n_contours + (FT_UInt)current->n_contours +
250 n_contours;
251 if ( new_max > old_max )
252 {
253 new_max = FT_PAD_CEIL( new_max, 4 );
254
255 if ( new_max > FT_OUTLINE_CONTOURS_MAX )
256 return FT_THROW( Array_Too_Large );
257
258 if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
259 goto Exit;
260
261 adjust = 1;
262 loader->max_contours = new_max;
263 }
264
265 if ( adjust )
|
1 /****************************************************************************
2 *
3 * ftgloadr.c
4 *
5 * The FreeType glyph loader (body).
6 *
7 * Copyright (C) 2002-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
19 #include <ft2build.h>
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_GLYPH_LOADER_H
22 #include FT_INTERNAL_MEMORY_H
23 #include FT_INTERNAL_OBJECTS_H
24
25 #undef FT_COMPONENT
26 #define FT_COMPONENT gloader
27
129 {
130 if ( loader )
131 {
132 FT_Memory memory = loader->memory;
133
134
135 FT_GlyphLoader_Reset( loader );
136 FT_FREE( loader );
137 }
138 }
139
140
141 /* re-adjust the `current' outline fields */
142 static void
143 FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader )
144 {
145 FT_Outline* base = &loader->base.outline;
146 FT_Outline* current = &loader->current.outline;
147
148
149 current->points = FT_OFFSET( base->points, base->n_points );
150 current->tags = FT_OFFSET( base->tags, base->n_points );
151 current->contours = FT_OFFSET( base->contours, base->n_contours );
152
153 /* handle extra points table - if any */
154 if ( loader->use_extra )
155 {
156 loader->current.extra_points = loader->base.extra_points +
157 base->n_points;
158
159 loader->current.extra_points2 = loader->base.extra_points2 +
160 base->n_points;
161 }
162 }
163
164
165 FT_BASE_DEF( FT_Error )
166 FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader )
167 {
168 FT_Error error;
169 FT_Memory memory = loader->memory;
170
171
172 if ( loader->max_points == 0 ||
173 loader->base.extra_points != NULL )
174 return FT_Err_Ok;
175
176 if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
177 {
178 loader->use_extra = 1;
179 loader->base.extra_points2 = loader->base.extra_points +
180 loader->max_points;
181
182 FT_GlyphLoader_Adjust_Points( loader );
183 }
184 return error;
185 }
186
187
188 /* re-adjust the `current' subglyphs field */
189 static void
190 FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader )
191 {
192 FT_GlyphLoad base = &loader->base;
193 FT_GlyphLoad current = &loader->current;
194
195
196 current->subglyphs = FT_OFFSET( base->subglyphs, base->num_subglyphs );
197 }
198
199
200 /* Ensure that we can add `n_points' and `n_contours' to our glyph. */
201 /* This function reallocates its outline tables if necessary. Note that */
202 /* it DOESN'T change the number of points within the loader! */
203 /* */
204 FT_BASE_DEF( FT_Error )
205 FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader,
206 FT_UInt n_points,
207 FT_UInt n_contours )
208 {
209 FT_Memory memory = loader->memory;
210 FT_Error error = FT_Err_Ok;
211 FT_Outline* base = &loader->base.outline;
212 FT_Outline* current = &loader->current.outline;
213 FT_Bool adjust = 0;
214
215 FT_UInt new_max, old_max;
216
217
218 error = FT_GlyphLoader_CreateExtra( loader );
219 if ( error )
220 return error;
221
222 /* check points & tags */
223 new_max = (FT_UInt)base->n_points + (FT_UInt)current->n_points +
224 n_points;
225 old_max = loader->max_points;
226
227 if ( new_max > old_max )
228 {
229 new_max = FT_PAD_CEIL( new_max, 8 );
230
231 if ( new_max > FT_OUTLINE_POINTS_MAX )
232 return FT_THROW( Array_Too_Large );
233
234 if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
235 FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
236 goto Exit;
237
238 if ( loader->use_extra )
239 {
240 if ( FT_RENEW_ARRAY( loader->base.extra_points,
241 old_max * 2, new_max * 2 ) )
242 goto Exit;
243
244 FT_ARRAY_MOVE( loader->base.extra_points + new_max,
245 loader->base.extra_points + old_max,
246 old_max );
247
248 loader->base.extra_points2 = loader->base.extra_points + new_max;
249 }
250
251 adjust = 1;
252 loader->max_points = new_max;
253 }
254
255 error = FT_GlyphLoader_CreateExtra( loader );
256 if ( error )
257 return error;
258
259 /* check contours */
260 old_max = loader->max_contours;
261 new_max = (FT_UInt)base->n_contours + (FT_UInt)current->n_contours +
262 n_contours;
263 if ( new_max > old_max )
264 {
265 new_max = FT_PAD_CEIL( new_max, 4 );
266
267 if ( new_max > FT_OUTLINE_CONTOURS_MAX )
268 return FT_THROW( Array_Too_Large );
269
270 if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
271 goto Exit;
272
273 adjust = 1;
274 loader->max_contours = new_max;
275 }
276
277 if ( adjust )
|