| OLD | NEW |
| 1 /***************************************************************************/ | 1 /***************************************************************************/ |
| 2 /* */ | 2 /* */ |
| 3 /* cidgload.c */ | 3 /* cidgload.c */ |
| 4 /* */ | 4 /* */ |
| 5 /* CID-keyed Type1 Glyph Loader (body). */ | 5 /* CID-keyed Type1 Glyph Loader (body). */ |
| 6 /* */ | 6 /* */ |
| 7 /* Copyright 1996-2007, 2009, 2010, 2013 by */ | 7 /* Copyright 1996-2015 by */ |
| 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ | 8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
| 9 /* */ | 9 /* */ |
| 10 /* This file is part of the FreeType project, and may only be used, */ | 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 */ | 11 /* modified, and distributed under the terms of the FreeType project */ |
| 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ | 12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
| 13 /* this file you indicate that you have read the license and */ | 13 /* this file you indicate that you have read the license and */ |
| 14 /* understand and accept it fully. */ | 14 /* understand and accept it fully. */ |
| 15 /* */ | 15 /* */ |
| 16 /***************************************************************************/ | 16 /***************************************************************************/ |
| 17 | 17 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 37 #define FT_COMPONENT trace_cidgload | 37 #define FT_COMPONENT trace_cidgload |
| 38 | 38 |
| 39 | 39 |
| 40 FT_CALLBACK_DEF( FT_Error ) | 40 FT_CALLBACK_DEF( FT_Error ) |
| 41 cid_load_glyph( T1_Decoder decoder, | 41 cid_load_glyph( T1_Decoder decoder, |
| 42 FT_UInt glyph_index ) | 42 FT_UInt glyph_index ) |
| 43 { | 43 { |
| 44 CID_Face face = (CID_Face)decoder->builder.face; | 44 CID_Face face = (CID_Face)decoder->builder.face; |
| 45 CID_FaceInfo cid = &face->cid; | 45 CID_FaceInfo cid = &face->cid; |
| 46 FT_Byte* p; | 46 FT_Byte* p; |
| 47 FT_UInt fd_select; | 47 FT_ULong fd_select; |
| 48 FT_Stream stream = face->cid_stream; | 48 FT_Stream stream = face->cid_stream; |
| 49 FT_Error error = FT_Err_Ok; | 49 FT_Error error = FT_Err_Ok; |
| 50 FT_Byte* charstring = 0; | 50 FT_Byte* charstring = NULL; |
| 51 FT_Memory memory = face->root.memory; | 51 FT_Memory memory = face->root.memory; |
| 52 FT_ULong glyph_length = 0; | 52 FT_ULong glyph_length = 0; |
| 53 PSAux_Service psaux = (PSAux_Service)face->psaux; | 53 PSAux_Service psaux = (PSAux_Service)face->psaux; |
| 54 | 54 |
| 55 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 55 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 56 FT_Incremental_InterfaceRec *inc = | 56 FT_Incremental_InterfaceRec *inc = |
| 57 face->root.internal->incremental_interface; | 57 face->root.internal->incremental_interface; |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 | 60 |
| 61 FT_TRACE1(( "cid_load_glyph: glyph index %d\n", glyph_index )); | 61 FT_TRACE1(( "cid_load_glyph: glyph index %d\n", glyph_index )); |
| 62 | 62 |
| 63 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 63 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 64 | 64 |
| 65 /* For incremental fonts get the character data using */ | 65 /* For incremental fonts get the character data using */ |
| 66 /* the callback function. */ | 66 /* the callback function. */ |
| 67 if ( inc ) | 67 if ( inc ) |
| 68 { | 68 { |
| 69 FT_Data glyph_data; | 69 FT_Data glyph_data; |
| 70 | 70 |
| 71 | 71 |
| 72 error = inc->funcs->get_glyph_data( inc->object, | 72 error = inc->funcs->get_glyph_data( inc->object, |
| 73 glyph_index, &glyph_data ); | 73 glyph_index, &glyph_data ); |
| 74 if ( error ) | 74 if ( error ) |
| 75 goto Exit; | 75 goto Exit; |
| 76 | 76 |
| 77 p = (FT_Byte*)glyph_data.pointer; | 77 p = (FT_Byte*)glyph_data.pointer; |
| 78 fd_select = (FT_UInt)cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); | 78 fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); |
| 79 | 79 |
| 80 if ( glyph_data.length != 0 ) | 80 if ( glyph_data.length != 0 ) |
| 81 { | 81 { |
| 82 glyph_length = glyph_data.length - cid->fd_bytes; | 82 glyph_length = (FT_ULong)( glyph_data.length - cid->fd_bytes ); |
| 83 (void)FT_ALLOC( charstring, glyph_length ); | 83 (void)FT_ALLOC( charstring, glyph_length ); |
| 84 if ( !error ) | 84 if ( !error ) |
| 85 ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes, | 85 ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes, |
| 86 glyph_length ); | 86 glyph_length ); |
| 87 } | 87 } |
| 88 | 88 |
| 89 inc->funcs->free_glyph_data( inc->object, &glyph_data ); | 89 inc->funcs->free_glyph_data( inc->object, &glyph_data ); |
| 90 | 90 |
| 91 if ( error ) | 91 if ( error ) |
| 92 goto Exit; | 92 goto Exit; |
| 93 } | 93 } |
| 94 | 94 |
| 95 else | 95 else |
| 96 | 96 |
| 97 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ | 97 #endif /* FT_CONFIG_OPTION_INCREMENTAL */ |
| 98 | 98 |
| 99 /* For ordinary fonts read the CID font dictionary index */ | 99 /* For ordinary fonts read the CID font dictionary index */ |
| 100 /* and charstring offset from the CIDMap. */ | 100 /* and charstring offset from the CIDMap. */ |
| 101 { | 101 { |
| 102 FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes; | 102 FT_UInt entry_len = (FT_UInt)( cid->fd_bytes + cid->gd_bytes ); |
| 103 FT_ULong off1; | 103 FT_ULong off1; |
| 104 | 104 |
| 105 | 105 |
| 106 if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + | 106 if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + |
| 107 glyph_index * entry_len ) || | 107 glyph_index * entry_len ) || |
| 108 FT_FRAME_ENTER( 2 * entry_len ) ) | 108 FT_FRAME_ENTER( 2 * entry_len ) ) |
| 109 goto Exit; | 109 goto Exit; |
| 110 | 110 |
| 111 p = (FT_Byte*)stream->cursor; | 111 p = (FT_Byte*)stream->cursor; |
| 112 fd_select = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); | 112 fd_select = cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); |
| 113 off1 = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); | 113 off1 = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); |
| 114 p += cid->fd_bytes; | 114 p += cid->fd_bytes; |
| 115 glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1; | 115 glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1; |
| 116 FT_FRAME_EXIT(); | 116 FT_FRAME_EXIT(); |
| 117 | 117 |
| 118 if ( fd_select >= (FT_UInt)cid->num_dicts ) | 118 if ( fd_select >= (FT_ULong)cid->num_dicts ) |
| 119 { | 119 { |
| 120 error = FT_THROW( Invalid_Offset ); | 120 error = FT_THROW( Invalid_Offset ); |
| 121 goto Exit; | 121 goto Exit; |
| 122 } | 122 } |
| 123 if ( glyph_length == 0 ) | 123 if ( glyph_length == 0 ) |
| 124 goto Exit; | 124 goto Exit; |
| 125 if ( FT_ALLOC( charstring, glyph_length ) ) | 125 if ( FT_ALLOC( charstring, glyph_length ) ) |
| 126 goto Exit; | 126 goto Exit; |
| 127 if ( FT_STREAM_READ_AT( cid->data_offset + off1, | 127 if ( FT_STREAM_READ_AT( cid->data_offset + off1, |
| 128 charstring, glyph_length ) ) | 128 charstring, glyph_length ) ) |
| 129 goto Exit; | 129 goto Exit; |
| 130 } | 130 } |
| 131 | 131 |
| 132 /* Now set up the subrs array and parse the charstrings. */ | 132 /* Now set up the subrs array and parse the charstrings. */ |
| 133 { | 133 { |
| 134 CID_FaceDict dict; | 134 CID_FaceDict dict; |
| 135 CID_Subrs cid_subrs = face->subrs + fd_select; | 135 CID_Subrs cid_subrs = face->subrs + fd_select; |
| 136 FT_Int cs_offset; | 136 FT_UInt cs_offset; |
| 137 | 137 |
| 138 | 138 |
| 139 /* Set up subrs */ | 139 /* Set up subrs */ |
| 140 decoder->num_subrs = cid_subrs->num_subrs; | 140 decoder->num_subrs = cid_subrs->num_subrs; |
| 141 decoder->subrs = cid_subrs->code; | 141 decoder->subrs = cid_subrs->code; |
| 142 decoder->subrs_len = 0; | 142 decoder->subrs_len = 0; |
| 143 | 143 |
| 144 /* Set up font matrix */ | 144 /* Set up font matrix */ |
| 145 dict = cid->font_dicts + fd_select; | 145 dict = cid->font_dicts + fd_select; |
| 146 | 146 |
| 147 decoder->font_matrix = dict->font_matrix; | 147 decoder->font_matrix = dict->font_matrix; |
| 148 decoder->font_offset = dict->font_offset; | 148 decoder->font_offset = dict->font_offset; |
| 149 decoder->lenIV = dict->private_dict.lenIV; | 149 decoder->lenIV = dict->private_dict.lenIV; |
| 150 | 150 |
| 151 /* Decode the charstring. */ | 151 /* Decode the charstring. */ |
| 152 | 152 |
| 153 /* Adjustment for seed bytes. */ | 153 /* Adjustment for seed bytes. */ |
| 154 cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); | 154 cs_offset = decoder->lenIV >= 0 ? (FT_UInt)decoder->lenIV : 0; |
| 155 | 155 |
| 156 /* Decrypt only if lenIV >= 0. */ | 156 /* Decrypt only if lenIV >= 0. */ |
| 157 if ( decoder->lenIV >= 0 ) | 157 if ( decoder->lenIV >= 0 ) |
| 158 psaux->t1_decrypt( charstring, glyph_length, 4330 ); | 158 psaux->t1_decrypt( charstring, glyph_length, 4330 ); |
| 159 | 159 |
| 160 error = decoder->funcs.parse_charstrings( | 160 error = decoder->funcs.parse_charstrings( |
| 161 decoder, charstring + cs_offset, | 161 decoder, charstring + cs_offset, |
| 162 (FT_Int)glyph_length - cs_offset ); | 162 glyph_length - cs_offset ); |
| 163 } | 163 } |
| 164 | 164 |
| 165 FT_FREE( charstring ); | 165 FT_FREE( charstring ); |
| 166 | 166 |
| 167 #ifdef FT_CONFIG_OPTION_INCREMENTAL | 167 #ifdef FT_CONFIG_OPTION_INCREMENTAL |
| 168 | 168 |
| 169 /* Incremental fonts can optionally override the metrics. */ | 169 /* Incremental fonts can optionally override the metrics. */ |
| 170 if ( !error && inc && inc->funcs->get_glyph_metrics ) | 170 if ( !error && inc && inc->funcs->get_glyph_metrics ) |
| 171 { | 171 { |
| 172 FT_Incremental_MetricsRec metrics; | 172 FT_Incremental_MetricsRec metrics; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 FIXED_TO_INT( decoder.builder.advance.x ); | 350 FIXED_TO_INT( decoder.builder.advance.x ); |
| 351 | 351 |
| 352 internal->glyph_matrix = font_matrix; | 352 internal->glyph_matrix = font_matrix; |
| 353 internal->glyph_delta = font_offset; | 353 internal->glyph_delta = font_offset; |
| 354 internal->glyph_transformed = 1; | 354 internal->glyph_transformed = 1; |
| 355 } | 355 } |
| 356 else | 356 else |
| 357 { | 357 { |
| 358 FT_BBox cbox; | 358 FT_BBox cbox; |
| 359 FT_Glyph_Metrics* metrics = &cidglyph->metrics; | 359 FT_Glyph_Metrics* metrics = &cidglyph->metrics; |
| 360 FT_Vector advance; | |
| 361 | 360 |
| 362 | 361 |
| 363 /* copy the _unscaled_ advance width */ | 362 /* copy the _unscaled_ advance width */ |
| 364 metrics->horiAdvance = | 363 metrics->horiAdvance = |
| 365 FIXED_TO_INT( decoder.builder.advance.x ); | 364 FIXED_TO_INT( decoder.builder.advance.x ); |
| 366 cidglyph->linearHoriAdvance = | 365 cidglyph->linearHoriAdvance = |
| 367 FIXED_TO_INT( decoder.builder.advance.x ); | 366 FIXED_TO_INT( decoder.builder.advance.x ); |
| 368 cidglyph->internal->glyph_transformed = 0; | 367 cidglyph->internal->glyph_transformed = 0; |
| 369 | 368 |
| 370 /* make up vertical ones */ | 369 /* make up vertical ones */ |
| 371 metrics->vertAdvance = ( face->cid.font_bbox.yMax - | 370 metrics->vertAdvance = ( face->cid.font_bbox.yMax - |
| 372 face->cid.font_bbox.yMin ) >> 16; | 371 face->cid.font_bbox.yMin ) >> 16; |
| 373 cidglyph->linearVertAdvance = metrics->vertAdvance; | 372 cidglyph->linearVertAdvance = metrics->vertAdvance; |
| 374 | 373 |
| 375 cidglyph->format = FT_GLYPH_FORMAT_OUTLINE; | 374 cidglyph->format = FT_GLYPH_FORMAT_OUTLINE; |
| 376 | 375 |
| 377 if ( cidsize->metrics.y_ppem < 24 ) | 376 if ( cidsize->metrics.y_ppem < 24 ) |
| 378 cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; | 377 cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION; |
| 379 | 378 |
| 380 /* apply the font matrix */ | 379 /* apply the font matrix, if any */ |
| 381 FT_Outline_Transform( &cidglyph->outline, &font_matrix ); | 380 if ( font_matrix.xx != 0x10000L || font_matrix.yy != 0x10000L || |
| 381 font_matrix.xy != 0 || font_matrix.yx != 0 ) |
| 382 { |
| 383 FT_Outline_Transform( &cidglyph->outline, &font_matrix ); |
| 382 | 384 |
| 383 FT_Outline_Translate( &cidglyph->outline, | 385 metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, |
| 384 font_offset.x, | 386 font_matrix.xx ); |
| 385 font_offset.y ); | 387 metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, |
| 388 font_matrix.yy ); |
| 389 } |
| 386 | 390 |
| 387 advance.x = metrics->horiAdvance; | 391 if ( font_offset.x || font_offset.y ) |
| 388 advance.y = 0; | 392 { |
| 389 FT_Vector_Transform( &advance, &font_matrix ); | 393 FT_Outline_Translate( &cidglyph->outline, |
| 390 metrics->horiAdvance = advance.x + font_offset.x; | 394 font_offset.x, |
| 395 font_offset.y ); |
| 391 | 396 |
| 392 advance.x = 0; | 397 metrics->horiAdvance += font_offset.x; |
| 393 advance.y = metrics->vertAdvance; | 398 metrics->vertAdvance += font_offset.y; |
| 394 FT_Vector_Transform( &advance, &font_matrix ); | 399 } |
| 395 metrics->vertAdvance = advance.y + font_offset.y; | |
| 396 | 400 |
| 397 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ) | 401 if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 ) |
| 398 { | 402 { |
| 399 /* scale the outline and the metrics */ | 403 /* scale the outline and the metrics */ |
| 400 FT_Int n; | 404 FT_Int n; |
| 401 FT_Outline* cur = decoder.builder.base; | 405 FT_Outline* cur = decoder.builder.base; |
| 402 FT_Vector* vec = cur->points; | 406 FT_Vector* vec = cur->points; |
| 403 FT_Fixed x_scale = glyph->x_scale; | 407 FT_Fixed x_scale = glyph->x_scale; |
| 404 FT_Fixed y_scale = glyph->y_scale; | 408 FT_Fixed y_scale = glyph->y_scale; |
| 405 | 409 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 433 metrics->vertAdvance ); | 437 metrics->vertAdvance ); |
| 434 } | 438 } |
| 435 } | 439 } |
| 436 | 440 |
| 437 Exit: | 441 Exit: |
| 438 return error; | 442 return error; |
| 439 } | 443 } |
| 440 | 444 |
| 441 | 445 |
| 442 /* END */ | 446 /* END */ |
| OLD | NEW |