1 /***************************************************************************/
2 /* */
3 /* cffgload.c */
4 /* */
5 /* OpenType Glyph Loader (body). */
6 /* */
7 /* Copyright 1996-2018 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_STREAM_H
22 #include FT_INTERNAL_SFNT_H
23 #include FT_INTERNAL_CALC_H
24 #include FT_INTERNAL_POSTSCRIPT_AUX_H
25 #include FT_OUTLINE_H
26 #include FT_DRIVER_H
27
28 #include "cffload.h"
29 #include "cffgload.h"
30
31 #include "cfferrs.h"
32
33
34 /*************************************************************************/
35 /* */
36 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
37 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
38 /* messages during execution. */
39 /* */
40 #undef FT_COMPONENT
41 #define FT_COMPONENT trace_cffgload
42
43
44 FT_LOCAL_DEF( FT_Error )
45 cff_get_glyph_data( TT_Face face,
46 FT_UInt glyph_index,
47 FT_Byte** pointer,
48 FT_ULong* length )
49 {
50 #ifdef FT_CONFIG_OPTION_INCREMENTAL
51 /* For incremental fonts get the character data using the */
52 /* callback function. */
53 if ( face->root.internal->incremental_interface )
54 {
55 FT_Data data;
56 FT_Error error =
57 face->root.internal->incremental_interface->funcs->get_glyph_data(
58 face->root.internal->incremental_interface->object,
59 glyph_index, &data );
60
61
263
264
265 error = sfnt->load_sbit_image( face,
266 size->strike_index,
267 glyph_index,
268 (FT_UInt)load_flags,
269 stream,
270 &glyph->root.bitmap,
271 &metrics );
272
273 if ( !error )
274 {
275 FT_Bool has_vertical_info;
276 FT_UShort advance;
277 FT_Short dummy;
278
279
280 glyph->root.outline.n_points = 0;
281 glyph->root.outline.n_contours = 0;
282
283 glyph->root.metrics.width = (FT_Pos)metrics.width << 6;
284 glyph->root.metrics.height = (FT_Pos)metrics.height << 6;
285
286 glyph->root.metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6;
287 glyph->root.metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6;
288 glyph->root.metrics.horiAdvance = (FT_Pos)metrics.horiAdvance << 6;
289
290 glyph->root.metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6;
291 glyph->root.metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6;
292 glyph->root.metrics.vertAdvance = (FT_Pos)metrics.vertAdvance << 6;
293
294 glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
295
296 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
297 {
298 glyph->root.bitmap_left = metrics.vertBearingX;
299 glyph->root.bitmap_top = metrics.vertBearingY;
300 }
301 else
302 {
303 glyph->root.bitmap_left = metrics.horiBearingX;
304 glyph->root.bitmap_top = metrics.horiBearingY;
305 }
306
307 /* compute linear advance widths */
308
309 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 0,
310 glyph_index,
311 &dummy,
312 &advance );
397 {
398 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
399 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face );
400 #endif
401
402
403 FT_Byte* charstring;
404 FT_ULong charstring_len;
405
406
407 decoder_funcs->init( &decoder, face, size, glyph, hinting,
408 FT_LOAD_TARGET_MODE( load_flags ),
409 cff_get_glyph_data,
410 cff_free_glyph_data );
411
412 /* this is for pure CFFs */
413 if ( load_flags & FT_LOAD_ADVANCE_ONLY )
414 decoder.width_only = TRUE;
415
416 decoder.builder.no_recurse =
417 (FT_Bool)( load_flags & FT_LOAD_NO_RECURSE );
418
419 /* now load the unscaled outline */
420 error = cff_get_glyph_data( face, glyph_index,
421 &charstring, &charstring_len );
422 if ( error )
423 goto Glyph_Build_Finished;
424
425 error = decoder_funcs->prepare( &decoder, size, glyph_index );
426 if ( error )
427 goto Glyph_Build_Finished;
428
429 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
430 /* choose which CFF renderer to use */
431 if ( driver->hinting_engine == FT_HINTING_FREETYPE )
432 error = decoder_funcs->parse_charstrings_old( &decoder,
433 charstring,
434 charstring_len,
435 0 );
436 else
437 #endif
|
1 /****************************************************************************
2 *
3 * cffgload.c
4 *
5 * OpenType Glyph Loader (body).
6 *
7 * Copyright (C) 1996-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_STREAM_H
22 #include FT_INTERNAL_SFNT_H
23 #include FT_INTERNAL_CALC_H
24 #include FT_INTERNAL_POSTSCRIPT_AUX_H
25 #include FT_OUTLINE_H
26 #include FT_DRIVER_H
27
28 #include "cffload.h"
29 #include "cffgload.h"
30
31 #include "cfferrs.h"
32
33
34 /**************************************************************************
35 *
36 * The macro FT_COMPONENT is used in trace mode. It is an implicit
37 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
38 * messages during execution.
39 */
40 #undef FT_COMPONENT
41 #define FT_COMPONENT cffgload
42
43
44 FT_LOCAL_DEF( FT_Error )
45 cff_get_glyph_data( TT_Face face,
46 FT_UInt glyph_index,
47 FT_Byte** pointer,
48 FT_ULong* length )
49 {
50 #ifdef FT_CONFIG_OPTION_INCREMENTAL
51 /* For incremental fonts get the character data using the */
52 /* callback function. */
53 if ( face->root.internal->incremental_interface )
54 {
55 FT_Data data;
56 FT_Error error =
57 face->root.internal->incremental_interface->funcs->get_glyph_data(
58 face->root.internal->incremental_interface->object,
59 glyph_index, &data );
60
61
263
264
265 error = sfnt->load_sbit_image( face,
266 size->strike_index,
267 glyph_index,
268 (FT_UInt)load_flags,
269 stream,
270 &glyph->root.bitmap,
271 &metrics );
272
273 if ( !error )
274 {
275 FT_Bool has_vertical_info;
276 FT_UShort advance;
277 FT_Short dummy;
278
279
280 glyph->root.outline.n_points = 0;
281 glyph->root.outline.n_contours = 0;
282
283 glyph->root.metrics.width = (FT_Pos)metrics.width * 64;
284 glyph->root.metrics.height = (FT_Pos)metrics.height * 64;
285
286 glyph->root.metrics.horiBearingX = (FT_Pos)metrics.horiBearingX * 64;
287 glyph->root.metrics.horiBearingY = (FT_Pos)metrics.horiBearingY * 64;
288 glyph->root.metrics.horiAdvance = (FT_Pos)metrics.horiAdvance * 64;
289
290 glyph->root.metrics.vertBearingX = (FT_Pos)metrics.vertBearingX * 64;
291 glyph->root.metrics.vertBearingY = (FT_Pos)metrics.vertBearingY * 64;
292 glyph->root.metrics.vertAdvance = (FT_Pos)metrics.vertAdvance * 64;
293
294 glyph->root.format = FT_GLYPH_FORMAT_BITMAP;
295
296 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
297 {
298 glyph->root.bitmap_left = metrics.vertBearingX;
299 glyph->root.bitmap_top = metrics.vertBearingY;
300 }
301 else
302 {
303 glyph->root.bitmap_left = metrics.horiBearingX;
304 glyph->root.bitmap_top = metrics.horiBearingY;
305 }
306
307 /* compute linear advance widths */
308
309 (void)( (SFNT_Service)face->sfnt )->get_metrics( face, 0,
310 glyph_index,
311 &dummy,
312 &advance );
397 {
398 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
399 PS_Driver driver = (PS_Driver)FT_FACE_DRIVER( face );
400 #endif
401
402
403 FT_Byte* charstring;
404 FT_ULong charstring_len;
405
406
407 decoder_funcs->init( &decoder, face, size, glyph, hinting,
408 FT_LOAD_TARGET_MODE( load_flags ),
409 cff_get_glyph_data,
410 cff_free_glyph_data );
411
412 /* this is for pure CFFs */
413 if ( load_flags & FT_LOAD_ADVANCE_ONLY )
414 decoder.width_only = TRUE;
415
416 decoder.builder.no_recurse =
417 FT_BOOL( load_flags & FT_LOAD_NO_RECURSE );
418
419 /* now load the unscaled outline */
420 error = cff_get_glyph_data( face, glyph_index,
421 &charstring, &charstring_len );
422 if ( error )
423 goto Glyph_Build_Finished;
424
425 error = decoder_funcs->prepare( &decoder, size, glyph_index );
426 if ( error )
427 goto Glyph_Build_Finished;
428
429 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
430 /* choose which CFF renderer to use */
431 if ( driver->hinting_engine == FT_HINTING_FREETYPE )
432 error = decoder_funcs->parse_charstrings_old( &decoder,
433 charstring,
434 charstring_len,
435 0 );
436 else
437 #endif
|