Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: third_party/freetype/src/cid/cidload.c

Issue 1413673003: Update bundled freetype to 2.6.1 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: DEPS for corpus Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/freetype/src/cid/cidload.h ('k') | third_party/freetype/src/cid/cidobjs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /***************************************************************************/ 1 /***************************************************************************/
2 /* */ 2 /* */
3 /* cidload.c */ 3 /* cidload.c */
4 /* */ 4 /* */
5 /* CID-keyed Type1 font loader (body). */ 5 /* CID-keyed Type1 font loader (body). */
6 /* */ 6 /* */
7 /* Copyright 1996-2006, 2009, 2011-2014 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 13 matching lines...) Expand all
31 /* */ 31 /* */
32 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ 32 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
33 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ 33 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
34 /* messages during execution. */ 34 /* messages during execution. */
35 /* */ 35 /* */
36 #undef FT_COMPONENT 36 #undef FT_COMPONENT
37 #define FT_COMPONENT trace_cidload 37 #define FT_COMPONENT trace_cidload
38 38
39 39
40 /* read a single offset */ 40 /* read a single offset */
41 FT_LOCAL_DEF( FT_Long ) 41 FT_LOCAL_DEF( FT_ULong )
42 cid_get_offset( FT_Byte* *start, 42 cid_get_offset( FT_Byte* *start,
43 FT_Byte offsize ) 43 FT_Byte offsize )
44 { 44 {
45 FT_ULong result; 45 FT_ULong result;
46 FT_Byte* p = *start; 46 FT_Byte* p = *start;
47 47
48 48
49 for ( result = 0; offsize > 0; offsize-- ) 49 for ( result = 0; offsize > 0; offsize-- )
50 { 50 {
51 result <<= 8; 51 result <<= 8;
52 result |= *p++; 52 result |= *p++;
53 } 53 }
54 54
55 *start = p; 55 *start = p;
56 return (FT_Long)result; 56 return result;
57 } 57 }
58 58
59 59
60 /*************************************************************************/ 60 /*************************************************************************/
61 /*************************************************************************/ 61 /*************************************************************************/
62 /***** *****/ 62 /***** *****/
63 /***** TYPE 1 SYMBOL PARSING *****/ 63 /***** TYPE 1 SYMBOL PARSING *****/
64 /***** *****/ 64 /***** *****/
65 /*************************************************************************/ 65 /*************************************************************************/
66 /*************************************************************************/ 66 /*************************************************************************/
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 { 160 {
161 FT_Matrix* matrix; 161 FT_Matrix* matrix;
162 FT_Vector* offset; 162 FT_Vector* offset;
163 FT_Int result; 163 FT_Int result;
164 164
165 165
166 dict = face->cid.font_dicts + parser->num_dict; 166 dict = face->cid.font_dicts + parser->num_dict;
167 matrix = &dict->font_matrix; 167 matrix = &dict->font_matrix;
168 offset = &dict->font_offset; 168 offset = &dict->font_offset;
169 169
170 /* input is scaled by 1000 to accommodate default FontMatrix */
170 result = cid_parser_to_fixed_array( parser, 6, temp, 3 ); 171 result = cid_parser_to_fixed_array( parser, 6, temp, 3 );
171 172
172 if ( result < 6 ) 173 if ( result < 6 )
173 return FT_THROW( Invalid_File_Format ); 174 return FT_THROW( Invalid_File_Format );
174 175
175 temp_scale = FT_ABS( temp[3] ); 176 temp_scale = FT_ABS( temp[3] );
176 177
177 if ( temp_scale == 0 ) 178 if ( temp_scale == 0 )
178 { 179 {
179 FT_ERROR(( "cid_parse_font_matrix: invalid font matrix\n" )); 180 FT_ERROR(( "cid_parse_font_matrix: invalid font matrix\n" ));
180 return FT_THROW( Invalid_File_Format ); 181 return FT_THROW( Invalid_File_Format );
181 } 182 }
182 183
183 /* Set Units per EM based on FontMatrix values. We set the value to */ 184 /* atypical case */
184 /* 1000 / temp_scale, because temp_scale was already multiplied by */
185 /* 1000 (in t1_tofixed, from psobjs.c). */
186
187 root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale );
188
189 /* we need to scale the values by 1.0/temp[3] */
190 if ( temp_scale != 0x10000L ) 185 if ( temp_scale != 0x10000L )
191 { 186 {
187 /* set units per EM based on FontMatrix values */
188 root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale );
189
192 temp[0] = FT_DivFix( temp[0], temp_scale ); 190 temp[0] = FT_DivFix( temp[0], temp_scale );
193 temp[1] = FT_DivFix( temp[1], temp_scale ); 191 temp[1] = FT_DivFix( temp[1], temp_scale );
194 temp[2] = FT_DivFix( temp[2], temp_scale ); 192 temp[2] = FT_DivFix( temp[2], temp_scale );
195 temp[4] = FT_DivFix( temp[4], temp_scale ); 193 temp[4] = FT_DivFix( temp[4], temp_scale );
196 temp[5] = FT_DivFix( temp[5], temp_scale ); 194 temp[5] = FT_DivFix( temp[5], temp_scale );
197 temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L; 195 temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L;
198 } 196 }
199 197
200 matrix->xx = temp[0]; 198 matrix->xx = temp[0];
201 matrix->yx = temp[1]; 199 matrix->yx = temp[1];
(...skipping 13 matching lines...) Expand all
215 parse_fd_array( CID_Face face, 213 parse_fd_array( CID_Face face,
216 CID_Parser* parser ) 214 CID_Parser* parser )
217 { 215 {
218 CID_FaceInfo cid = &face->cid; 216 CID_FaceInfo cid = &face->cid;
219 FT_Memory memory = face->root.memory; 217 FT_Memory memory = face->root.memory;
220 FT_Error error = FT_Err_Ok; 218 FT_Error error = FT_Err_Ok;
221 FT_Long num_dicts; 219 FT_Long num_dicts;
222 220
223 221
224 num_dicts = cid_parser_to_int( parser ); 222 num_dicts = cid_parser_to_int( parser );
223 if ( num_dicts < 0 )
224 {
225 FT_ERROR(( "parse_fd_array: invalid number of dictionaries\n" ));
226 error = FT_THROW( Invalid_File_Format );
227 goto Exit;
228 }
225 229
226 if ( !cid->font_dicts ) 230 if ( !cid->font_dicts )
227 { 231 {
228 FT_Int n; 232 FT_Int n;
229 233
230 234
231 if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) ) 235 if ( FT_NEW_ARRAY( cid->font_dicts, num_dicts ) )
232 goto Exit; 236 goto Exit;
233 237
234 cid->num_dicts = (FT_UInt)num_dicts; 238 cid->num_dicts = num_dicts;
235 239
236 /* don't forget to set a few defaults */ 240 /* don't forget to set a few defaults */
237 for ( n = 0; n < cid->num_dicts; n++ ) 241 for ( n = 0; n < cid->num_dicts; n++ )
238 { 242 {
239 CID_FaceDict dict = cid->font_dicts + n; 243 CID_FaceDict dict = cid->font_dicts + n;
240 244
241 245
242 /* default value for lenIV */ 246 /* default value for lenIV */
243 dict->private_dict.lenIV = 4; 247 dict->private_dict.lenIV = 4;
244 } 248 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 T1_FIELD_CALLBACK( "ExpansionFactor", parse_expansion_factor, 0 ) 287 T1_FIELD_CALLBACK( "ExpansionFactor", parse_expansion_factor, 0 )
284 288
285 { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 } 289 { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 }
286 }; 290 };
287 291
288 292
289 static FT_Error 293 static FT_Error
290 cid_parse_dict( CID_Face face, 294 cid_parse_dict( CID_Face face,
291 CID_Loader* loader, 295 CID_Loader* loader,
292 FT_Byte* base, 296 FT_Byte* base,
293 FT_Long size ) 297 FT_ULong size )
294 { 298 {
295 CID_Parser* parser = &loader->parser; 299 CID_Parser* parser = &loader->parser;
296 300
297 301
298 parser->root.cursor = base; 302 parser->root.cursor = base;
299 parser->root.limit = base + size; 303 parser->root.limit = base + size;
300 parser->root.error = FT_Err_Ok; 304 parser->root.error = FT_Err_Ok;
301 305
302 { 306 {
303 FT_Byte* cur = base; 307 FT_Byte* cur = base;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if ( cur >= limit ) 339 if ( cur >= limit )
336 break; 340 break;
337 341
338 cid_parser_skip_PS_token( parser ); 342 cid_parser_skip_PS_token( parser );
339 if ( parser->root.cursor >= limit || parser->root.error ) 343 if ( parser->root.cursor >= limit || parser->root.error )
340 break; 344 break;
341 345
342 /* look for immediates */ 346 /* look for immediates */
343 if ( *cur == '/' && cur + 2 < limit ) 347 if ( *cur == '/' && cur + 2 < limit )
344 { 348 {
345 FT_PtrDist len; 349 FT_UInt len;
346 350
347 351
348 cur++; 352 cur++;
349 len = parser->root.cursor - cur; 353 len = (FT_UInt)( parser->root.cursor - cur );
350 354
351 if ( len > 0 && len < 22 ) 355 if ( len > 0 && len < 22 )
352 { 356 {
353 /* now compare the immediate name to the keyword table */ 357 /* now compare the immediate name to the keyword table */
354 T1_Field keyword = (T1_Field)cid_field_records; 358 T1_Field keyword = (T1_Field)cid_field_records;
355 359
356 360
357 for (;;) 361 for (;;)
358 { 362 {
359 FT_Byte* name; 363 FT_Byte* name;
360 364
361 365
362 name = (FT_Byte*)keyword->ident; 366 name = (FT_Byte*)keyword->ident;
363 if ( !name ) 367 if ( !name )
364 break; 368 break;
365 369
366 if ( cur[0] == name[0] && 370 if ( cur[0] == name[0] &&
367 len == (FT_PtrDist)ft_strlen( (const char*)name ) ) 371 len == ft_strlen( (const char*)name ) )
368 { 372 {
369 FT_PtrDist n; 373 FT_UInt n;
370 374
371 375
372 for ( n = 1; n < len; n++ ) 376 for ( n = 1; n < len; n++ )
373 if ( cur[n] != name[n] ) 377 if ( cur[n] != name[n] )
374 break; 378 break;
375 379
376 if ( n >= len ) 380 if ( n >= len )
377 { 381 {
378 /* we found it - run the parsing callback */ 382 /* we found it - run the parsing callback */
379 parser->root.error = cid_load_keyword( face, 383 parser->root.error = cid_load_keyword( face,
(...skipping 20 matching lines...) Expand all
400 static FT_Error 404 static FT_Error
401 cid_read_subrs( CID_Face face ) 405 cid_read_subrs( CID_Face face )
402 { 406 {
403 CID_FaceInfo cid = &face->cid; 407 CID_FaceInfo cid = &face->cid;
404 FT_Memory memory = face->root.memory; 408 FT_Memory memory = face->root.memory;
405 FT_Stream stream = face->cid_stream; 409 FT_Stream stream = face->cid_stream;
406 FT_Error error; 410 FT_Error error;
407 FT_Int n; 411 FT_Int n;
408 CID_Subrs subr; 412 CID_Subrs subr;
409 FT_UInt max_offsets = 0; 413 FT_UInt max_offsets = 0;
410 FT_ULong* offsets = 0; 414 FT_ULong* offsets = NULL;
411 PSAux_Service psaux = (PSAux_Service)face->psaux; 415 PSAux_Service psaux = (PSAux_Service)face->psaux;
412 416
413 417
414 if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) ) 418 if ( FT_NEW_ARRAY( face->subrs, cid->num_dicts ) )
415 goto Exit; 419 goto Exit;
416 420
417 subr = face->subrs; 421 subr = face->subrs;
418 for ( n = 0; n < cid->num_dicts; n++, subr++ ) 422 for ( n = 0; n < cid->num_dicts; n++, subr++ )
419 { 423 {
420 CID_FaceDict dict = cid->font_dicts + n; 424 CID_FaceDict dict = cid->font_dicts + n;
(...skipping 22 matching lines...) Expand all
443 goto Fail; 447 goto Fail;
444 } 448 }
445 449
446 if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) ) 450 if ( FT_RENEW_ARRAY( offsets, max_offsets, new_max ) )
447 goto Fail; 451 goto Fail;
448 452
449 max_offsets = new_max; 453 max_offsets = new_max;
450 } 454 }
451 455
452 /* read the subrmap's offsets */ 456 /* read the subrmap's offsets */
453 if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) || 457 if ( FT_STREAM_SEEK( cid->data_offset + dict->subrmap_offset ) ||
454 FT_FRAME_ENTER( ( num_subrs + 1 ) * dict->sd_bytes ) ) 458 FT_FRAME_ENTER( ( num_subrs + 1 ) * (FT_UInt)dict->sd_bytes ) )
455 goto Fail; 459 goto Fail;
456 460
457 p = (FT_Byte*)stream->cursor; 461 p = (FT_Byte*)stream->cursor;
458 for ( count = 0; count <= num_subrs; count++ ) 462 for ( count = 0; count <= num_subrs; count++ )
459 offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes ); 463 offsets[count] = cid_get_offset( &p, (FT_Byte)dict->sd_bytes );
460 464
461 FT_FRAME_EXIT(); 465 FT_FRAME_EXIT();
462 466
463 /* offsets must be ordered */ 467 /* offsets must be ordered */
464 for ( count = 1; count <= num_subrs; count++ ) 468 for ( count = 1; count <= num_subrs; count++ )
(...skipping 28 matching lines...) Expand all
493 for ( count = 0; count < num_subrs; count++ ) 497 for ( count = 0; count < num_subrs; count++ )
494 { 498 {
495 FT_ULong len; 499 FT_ULong len;
496 500
497 501
498 len = offsets[count + 1] - offsets[count]; 502 len = offsets[count + 1] - offsets[count];
499 psaux->t1_decrypt( subr->code[count], len, 4330 ); 503 psaux->t1_decrypt( subr->code[count], len, 4330 );
500 } 504 }
501 } 505 }
502 506
503 subr->num_subrs = num_subrs; 507 subr->num_subrs = (FT_Int)num_subrs;
504 } 508 }
505 509
506 Exit: 510 Exit:
507 FT_FREE( offsets ); 511 FT_FREE( offsets );
508 return error; 512 return error;
509 513
510 Fail: 514 Fail:
511 if ( face->subrs ) 515 if ( face->subrs )
512 { 516 {
513 for ( n = 0; n < cid->num_dicts; n++ ) 517 for ( n = 0; n < cid->num_dicts; n++ )
(...skipping 25 matching lines...) Expand all
539 CID_Parser* parser = &loader->parser; 543 CID_Parser* parser = &loader->parser;
540 544
541 545
542 /* finalize parser */ 546 /* finalize parser */
543 cid_parser_done( parser ); 547 cid_parser_done( parser );
544 } 548 }
545 549
546 550
547 static FT_Error 551 static FT_Error
548 cid_hex_to_binary( FT_Byte* data, 552 cid_hex_to_binary( FT_Byte* data,
549 FT_Long data_len, 553 FT_ULong data_len,
550 FT_ULong offset, 554 FT_ULong offset,
551 CID_Face face ) 555 CID_Face face )
552 { 556 {
553 FT_Stream stream = face->root.stream; 557 FT_Stream stream = face->root.stream;
554 FT_Error error; 558 FT_Error error;
555 559
556 FT_Byte buffer[256]; 560 FT_Byte buffer[256];
557 FT_Byte *p, *plimit; 561 FT_Byte *p, *plimit;
558 FT_Byte *d, *dlimit; 562 FT_Byte *d, *dlimit;
559 FT_Byte val; 563 FT_Byte val;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 696
693 error = cid_read_subrs( face ); 697 error = cid_read_subrs( face );
694 698
695 Exit: 699 Exit:
696 cid_done_loader( &loader ); 700 cid_done_loader( &loader );
697 return error; 701 return error;
698 } 702 }
699 703
700 704
701 /* END */ 705 /* END */
OLDNEW
« no previous file with comments | « third_party/freetype/src/cid/cidload.h ('k') | third_party/freetype/src/cid/cidobjs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698