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

Side by Side Diff: src/autofit/afloader.c

Issue 89753003: Update freetype to latest version of ASOP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src/third_party/freetype.git@master
Patch Set: Created 7 years 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 | « src/autofit/afloader.h ('k') | src/autofit/afmodule.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 /* afloader.c */ 3 /* afloader.c */
4 /* */ 4 /* */
5 /* Auto-fitter glyph loading routines (body). */ 5 /* Auto-fitter glyph loading routines (body). */
6 /* */ 6 /* */
7 /* Copyright 2003-2009, 2011-2012 by */ 7 /* Copyright 2003-2009, 2011-2013 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
18 18
19 #include "afglobal.h"
19 #include "afloader.h" 20 #include "afloader.h"
20 #include "afhints.h" 21 #include "afhints.h"
21 #include "afglobal.h"
22 #include "aferrors.h" 22 #include "aferrors.h"
23 #include "afmodule.h"
23 24
24 25
25 /* Initialize glyph loader. */ 26 /* Initialize glyph loader. */
26 27
27 FT_LOCAL_DEF( FT_Error ) 28 FT_LOCAL_DEF( FT_Error )
28 af_loader_init( AF_Loader loader, 29 af_loader_init( AF_Module module )
29 FT_Memory memory )
30 { 30 {
31 AF_Loader loader = module->loader;
32 FT_Memory memory = module->root.library->memory;
33
34
31 FT_ZERO( loader ); 35 FT_ZERO( loader );
32 36
33 af_glyph_hints_init( &loader->hints, memory ); 37 af_glyph_hints_init( &loader->hints, memory );
34 #ifdef FT_DEBUG_AUTOFIT 38 #ifdef FT_DEBUG_AUTOFIT
35 _af_debug_hints = &loader->hints; 39 _af_debug_hints = &loader->hints;
36 #endif 40 #endif
37 return FT_GlyphLoader_New( memory, &loader->gloader ); 41 return FT_GlyphLoader_New( memory, &loader->gloader );
38 } 42 }
39 43
40 44
41 /* Reset glyph loader and compute globals if necessary. */ 45 /* Reset glyph loader and compute globals if necessary. */
42 46
43 FT_LOCAL_DEF( FT_Error ) 47 FT_LOCAL_DEF( FT_Error )
44 af_loader_reset( AF_Loader loader, 48 af_loader_reset( AF_Module module,
45 FT_Face face ) 49 FT_Face face )
46 { 50 {
47 FT_Error error = AF_Err_Ok; 51 FT_Error error = FT_Err_Ok;
52 AF_Loader loader = module->loader;
48 53
49 54
50 loader->face = face; 55 loader->face = face;
51 loader->globals = (AF_FaceGlobals)face->autohint.data; 56 loader->globals = (AF_FaceGlobals)face->autohint.data;
52 57
53 FT_GlyphLoader_Rewind( loader->gloader ); 58 FT_GlyphLoader_Rewind( loader->gloader );
54 59
55 if ( loader->globals == NULL ) 60 if ( loader->globals == NULL )
56 { 61 {
57 error = af_face_globals_new( face, &loader->globals ); 62 error = af_face_globals_new( face, &loader->globals, module );
58 if ( !error ) 63 if ( !error )
59 { 64 {
60 face->autohint.data = 65 face->autohint.data =
61 (FT_Pointer)loader->globals; 66 (FT_Pointer)loader->globals;
62 face->autohint.finalizer = 67 face->autohint.finalizer =
63 (FT_Generic_Finalizer)af_face_globals_free; 68 (FT_Generic_Finalizer)af_face_globals_free;
64 } 69 }
65 } 70 }
66 71
67 return error; 72 return error;
68 } 73 }
69 74
70 75
71 /* Finalize glyph loader. */ 76 /* Finalize glyph loader. */
72 77
73 FT_LOCAL_DEF( void ) 78 FT_LOCAL_DEF( void )
74 af_loader_done( AF_Loader loader ) 79 af_loader_done( AF_Module module )
75 { 80 {
81 AF_Loader loader = module->loader;
82
83
76 af_glyph_hints_done( &loader->hints ); 84 af_glyph_hints_done( &loader->hints );
77 85
78 loader->face = NULL; 86 loader->face = NULL;
79 loader->globals = NULL; 87 loader->globals = NULL;
80 88
81 #ifdef FT_DEBUG_AUTOFIT 89 #ifdef FT_DEBUG_AUTOFIT
82 _af_debug_hints = NULL; 90 _af_debug_hints = NULL;
83 #endif 91 #endif
84 FT_GlyphLoader_Done( loader->gloader ); 92 FT_GlyphLoader_Done( loader->gloader );
85 loader->gloader = NULL; 93 loader->gloader = NULL;
(...skipping 11 matching lines...) Expand all
97 FT_Int32 load_flags, 105 FT_Int32 load_flags,
98 FT_UInt depth ) 106 FT_UInt depth )
99 { 107 {
100 FT_Error error; 108 FT_Error error;
101 FT_Face face = loader->face; 109 FT_Face face = loader->face;
102 FT_GlyphLoader gloader = loader->gloader; 110 FT_GlyphLoader gloader = loader->gloader;
103 AF_ScriptMetrics metrics = loader->metrics; 111 AF_ScriptMetrics metrics = loader->metrics;
104 AF_GlyphHints hints = &loader->hints; 112 AF_GlyphHints hints = &loader->hints;
105 FT_GlyphSlot slot = face->glyph; 113 FT_GlyphSlot slot = face->glyph;
106 FT_Slot_Internal internal = slot->internal; 114 FT_Slot_Internal internal = slot->internal;
115 FT_Int32 flags;
107 116
108 117
109 error = FT_Load_Glyph( face, glyph_index, load_flags ); 118 flags = load_flags | FT_LOAD_LINEAR_DESIGN;
119 error = FT_Load_Glyph( face, glyph_index, flags );
110 if ( error ) 120 if ( error )
111 goto Exit; 121 goto Exit;
112 122
113 loader->transformed = internal->glyph_transformed; 123 loader->transformed = internal->glyph_transformed;
114 if ( loader->transformed ) 124 if ( loader->transformed )
115 { 125 {
116 FT_Matrix inverse; 126 FT_Matrix inverse;
117 127
118 128
119 loader->trans_matrix = internal->glyph_matrix; 129 loader->trans_matrix = internal->glyph_matrix;
120 loader->trans_delta = internal->glyph_delta; 130 loader->trans_delta = internal->glyph_delta;
121 131
122 inverse = loader->trans_matrix; 132 inverse = loader->trans_matrix;
123 FT_Matrix_Invert( &inverse ); 133 FT_Matrix_Invert( &inverse );
124 FT_Vector_Transform( &loader->trans_delta, &inverse ); 134 FT_Vector_Transform( &loader->trans_delta, &inverse );
125 } 135 }
126 136
127 /* set linear metrics */
128 slot->linearHoriAdvance = slot->metrics.horiAdvance;
129 slot->linearVertAdvance = slot->metrics.vertAdvance;
130
131 switch ( slot->format ) 137 switch ( slot->format )
132 { 138 {
133 case FT_GLYPH_FORMAT_OUTLINE: 139 case FT_GLYPH_FORMAT_OUTLINE:
134 /* translate the loaded glyph when an internal transform is needed */ 140 /* translate the loaded glyph when an internal transform is needed */
135 if ( loader->transformed ) 141 if ( loader->transformed )
136 FT_Outline_Translate( &slot->outline, 142 FT_Outline_Translate( &slot->outline,
137 loader->trans_delta.x, 143 loader->trans_delta.x,
138 loader->trans_delta.y ); 144 loader->trans_delta.y );
139 145
140 /* copy the outline points in the loader's current */ 146 /* copy the outline points in the loader's current */
141 /* extra points which is used to keep original glyph coordinates */ 147 /* extra points which are used to keep original glyph coordinates */
142 error = FT_GLYPHLOADER_CHECK_POINTS( gloader, 148 error = FT_GLYPHLOADER_CHECK_POINTS( gloader,
143 slot->outline.n_points + 4, 149 slot->outline.n_points + 4,
144 slot->outline.n_contours ); 150 slot->outline.n_contours );
145 if ( error ) 151 if ( error )
146 goto Exit; 152 goto Exit;
147 153
148 FT_ARRAY_COPY( gloader->current.outline.points, 154 FT_ARRAY_COPY( gloader->current.outline.points,
149 slot->outline.points, 155 slot->outline.points,
150 slot->outline.n_points ); 156 slot->outline.n_points );
151 157
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 { 342 {
337 FT_Int k = subglyph->arg1; 343 FT_Int k = subglyph->arg1;
338 FT_UInt l = subglyph->arg2; 344 FT_UInt l = subglyph->arg2;
339 FT_Vector* p1; 345 FT_Vector* p1;
340 FT_Vector* p2; 346 FT_Vector* p2;
341 347
342 348
343 if ( start_point + k >= num_base_points || 349 if ( start_point + k >= num_base_points ||
344 l >= (FT_UInt)num_new_points ) 350 l >= (FT_UInt)num_new_points )
345 { 351 {
346 error = AF_Err_Invalid_Composite; 352 error = FT_THROW( Invalid_Composite );
347 goto Exit; 353 goto Exit;
348 } 354 }
349 355
350 l += num_base_points; 356 l += num_base_points;
351 357
352 /* for now, only use the current point coordinates; */ 358 /* for now, only use the current point coordinates; */
353 /* we may consider another approach in the near future */ 359 /* we eventually may consider another approach */
354 p1 = gloader->base.outline.points + start_point + k; 360 p1 = gloader->base.outline.points + start_point + k;
355 p2 = gloader->base.outline.points + start_point + l; 361 p2 = gloader->base.outline.points + start_point + l;
356 362
357 x = p1->x - p2->x; 363 x = p1->x - p2->x;
358 y = p1->y - p2->y; 364 y = p1->y - p2->y;
359 } 365 }
360 else 366 else
361 { 367 {
362 x = FT_MulFix( subglyph->arg1, hints->x_scale ) + hints->x_delta; 368 x = FT_MulFix( subglyph->arg1, hints->x_scale ) + hints->x_delta;
363 y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta; 369 y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta;
(...skipping 10 matching lines...) Expand all
374 dummy.n_points = (short)num_new_points; 380 dummy.n_points = (short)num_new_points;
375 381
376 FT_Outline_Translate( &dummy, x, y ); 382 FT_Outline_Translate( &dummy, x, y );
377 } 383 }
378 } 384 }
379 } 385 }
380 break; 386 break;
381 387
382 default: 388 default:
383 /* we don't support other formats (yet?) */ 389 /* we don't support other formats (yet?) */
384 error = AF_Err_Unimplemented_Feature; 390 error = FT_THROW( Unimplemented_Feature );
385 } 391 }
386 392
387 Hint_Metrics: 393 Hint_Metrics:
388 if ( depth == 0 ) 394 if ( depth == 0 )
389 { 395 {
390 FT_BBox bbox; 396 FT_BBox bbox;
391 FT_Vector vvector; 397 FT_Vector vvector;
392 398
393 399
394 vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX; 400 vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 483 }
478 484
479 Exit: 485 Exit:
480 return error; 486 return error;
481 } 487 }
482 488
483 489
484 /* Load a glyph. */ 490 /* Load a glyph. */
485 491
486 FT_LOCAL_DEF( FT_Error ) 492 FT_LOCAL_DEF( FT_Error )
487 af_loader_load_glyph( AF_Loader loader, 493 af_loader_load_glyph( AF_Module module,
488 FT_Face face, 494 FT_Face face,
489 FT_UInt gindex, 495 FT_UInt gindex,
490 FT_Int32 load_flags ) 496 FT_Int32 load_flags )
491 { 497 {
492 FT_Error error; 498 FT_Error error;
493 FT_Size size = face->size; 499 FT_Size size = face->size;
500 AF_Loader loader = module->loader;
494 AF_ScalerRec scaler; 501 AF_ScalerRec scaler;
495 502
496 503
497 if ( !size ) 504 if ( !size )
498 return AF_Err_Invalid_Argument; 505 return FT_THROW( Invalid_Argument );
499 506
500 FT_ZERO( &scaler ); 507 FT_ZERO( &scaler );
501 508
502 scaler.face = face; 509 scaler.face = face;
503 scaler.x_scale = size->metrics.x_scale; 510 scaler.x_scale = size->metrics.x_scale;
504 scaler.x_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */ 511 scaler.x_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
505 scaler.y_scale = size->metrics.y_scale; 512 scaler.y_scale = size->metrics.y_scale;
506 scaler.y_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */ 513 scaler.y_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
507 514
508 scaler.render_mode = FT_LOAD_TARGET_MODE( load_flags ); 515 scaler.render_mode = FT_LOAD_TARGET_MODE( load_flags );
509 scaler.flags = 0; /* XXX: fix this */ 516 scaler.flags = 0; /* XXX: fix this */
510 517
511 error = af_loader_reset( loader, face ); 518 error = af_loader_reset( module, face );
512 if ( !error ) 519 if ( !error )
513 { 520 {
514 AF_ScriptMetrics metrics; 521 AF_ScriptMetrics metrics;
515 FT_UInt options = 0; 522 FT_UInt options = 0;
516 523
517 524
518 #ifdef FT_OPTION_AUTOFIT2 525 #ifdef FT_OPTION_AUTOFIT2
519 /* XXX: undocumented hook to activate the latin2 hinter */ 526 /* XXX: undocumented hook to activate the latin2 hinter */
520 if ( load_flags & ( 1UL << 20 ) ) 527 if ( load_flags & ( 1UL << 20 ) )
521 options = 2; 528 options = 2;
(...skipping 23 matching lines...) Expand all
545 552
546 error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 ); 553 error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 );
547 } 554 }
548 } 555 }
549 Exit: 556 Exit:
550 return error; 557 return error;
551 } 558 }
552 559
553 560
554 /* END */ 561 /* END */
OLDNEW
« no previous file with comments | « src/autofit/afloader.h ('k') | src/autofit/afmodule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698