xref: /inferno-os/libfreetype/ttobjs.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ttobjs.c                                                               */
4 /*                                                                         */
5 /*    Objects manager (body).                                              */
6 /*                                                                         */
7 /*  Copyright 1996-2001, 2002 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_CALC_H
22 #include FT_INTERNAL_STREAM_H
23 #include FT_TRUETYPE_IDS_H
24 #include FT_TRUETYPE_TAGS_H
25 #include FT_INTERNAL_SFNT_H
26 #include FT_INTERNAL_POSTSCRIPT_NAMES_H
27 
28 #include "ttgload.h"
29 #include "ttpload.h"
30 
31 #include "tterrors.h"
32 
33 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
34 #include "ttinterp.h"
35 #endif
36 
37 
38   /*************************************************************************/
39   /*                                                                       */
40   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
41   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
42   /* messages during execution.                                            */
43   /*                                                                       */
44 #undef  FT_COMPONENT
45 #define FT_COMPONENT  trace_ttobjs
46 
47 
48 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
49 
50   /*************************************************************************/
51   /*                                                                       */
52   /*                       GLYPH ZONE FUNCTIONS                            */
53   /*                                                                       */
54   /*************************************************************************/
55 
56 
57   /*************************************************************************/
58   /*                                                                       */
59   /* <Function>                                                            */
60   /*    tt_glyphzone_done                                                  */
61   /*                                                                       */
62   /* <Description>                                                         */
63   /*    Deallocates a glyph zone.                                          */
64   /*                                                                       */
65   /* <Input>                                                               */
66   /*    zone :: A pointer to the target glyph zone.                        */
67   /*                                                                       */
68   FT_LOCAL_DEF( void )
tt_glyphzone_done(TT_GlyphZone zone)69   tt_glyphzone_done( TT_GlyphZone  zone )
70   {
71     FT_Memory  memory = zone->memory;
72 
73 
74     FT_FREE( zone->contours );
75     FT_FREE( zone->tags );
76     FT_FREE( zone->cur );
77     FT_FREE( zone->org );
78 
79     zone->max_points   = zone->n_points   = 0;
80     zone->max_contours = zone->n_contours = 0;
81   }
82 
83 
84   /*************************************************************************/
85   /*                                                                       */
86   /* <Function>                                                            */
87   /*    tt_glyphzone_new                                                   */
88   /*                                                                       */
89   /* <Description>                                                         */
90   /*    Allocates a new glyph zone.                                        */
91   /*                                                                       */
92   /* <Input>                                                               */
93   /*    memory      :: A handle to the current memory object.              */
94   /*                                                                       */
95   /*    maxPoints   :: The capacity of glyph zone in points.               */
96   /*                                                                       */
97   /*    maxContours :: The capacity of glyph zone in contours.             */
98   /*                                                                       */
99   /* <Output>                                                              */
100   /*    zone        :: A pointer to the target glyph zone record.          */
101   /*                                                                       */
102   /* <Return>                                                              */
103   /*    FreeType error code.  0 means success.                             */
104   /*                                                                       */
105   FT_LOCAL_DEF( FT_Error )
tt_glyphzone_new(FT_Memory memory,FT_UShort maxPoints,FT_Short maxContours,TT_GlyphZone zone)106   tt_glyphzone_new( FT_Memory     memory,
107                     FT_UShort     maxPoints,
108                     FT_Short      maxContours,
109                     TT_GlyphZone  zone )
110   {
111     FT_Error  error;
112 
113 
114     if ( maxPoints > 0 )
115       maxPoints += 2;
116 
117     FT_MEM_ZERO( zone, sizeof ( *zone ) );
118     zone->memory = memory;
119 
120     if ( FT_NEW_ARRAY( zone->org,      maxPoints * 2 ) ||
121          FT_NEW_ARRAY( zone->cur,      maxPoints * 2 ) ||
122          FT_NEW_ARRAY( zone->tags,     maxPoints     ) ||
123          FT_NEW_ARRAY( zone->contours, maxContours   ) )
124     {
125       tt_glyphzone_done( zone );
126     }
127 
128     return error;
129   }
130 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
131 
132 
133   /*************************************************************************/
134   /*                                                                       */
135   /* <Function>                                                            */
136   /*    tt_face_init                                                       */
137   /*                                                                       */
138   /* <Description>                                                         */
139   /*    Initializes a given TrueType face object.                          */
140   /*                                                                       */
141   /* <Input>                                                               */
142   /*    stream     :: The source font stream.                              */
143   /*                                                                       */
144   /*    face_index :: The index of the font face in the resource.          */
145   /*                                                                       */
146   /*    num_params :: Number of additional generic parameters.  Ignored.   */
147   /*                                                                       */
148   /*    params     :: Additional generic parameters.  Ignored.             */
149   /*                                                                       */
150   /* <InOut>                                                               */
151   /*    face       :: The newly built face object.                         */
152   /*                                                                       */
153   /* <Return>                                                              */
154   /*    FreeType error code.  0 means success.                             */
155   /*                                                                       */
156   FT_LOCAL_DEF( FT_Error )
tt_face_init(FT_Stream stream,TT_Face face,FT_Int face_index,FT_Int num_params,FT_Parameter * params)157   tt_face_init( FT_Stream      stream,
158                 TT_Face        face,
159                 FT_Int         face_index,
160                 FT_Int         num_params,
161                 FT_Parameter*  params )
162   {
163     FT_Error      error;
164     FT_Library    library;
165     SFNT_Service  sfnt;
166 
167 
168     library = face->root.driver->root.library;
169     sfnt    = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" );
170     if ( !sfnt )
171       goto Bad_Format;
172 
173     /* create input stream from resource */
174     if ( FT_STREAM_SEEK( 0 ) )
175       goto Exit;
176 
177     /* check that we have a valid TrueType file */
178     error = sfnt->init_face( stream, face, face_index, num_params, params );
179     if ( error )
180       goto Exit;
181 
182     /* We must also be able to accept Mac/GX fonts, as well as OT ones */
183     if ( face->format_tag != 0x00010000L &&    /* MS fonts  */
184          face->format_tag != TTAG_true   )     /* Mac fonts */
185     {
186       FT_TRACE2(( "[not a valid TTF font]\n" ));
187       goto Bad_Format;
188     }
189 
190     /* If we are performing a simple font format check, exit immediately */
191     if ( face_index < 0 )
192       return TT_Err_Ok;
193 
194     /* Load font directory */
195     error = sfnt->load_face( stream, face, face_index, num_params, params );
196     if ( error )
197       goto Exit;
198 
199     if ( face->root.face_flags & FT_FACE_FLAG_SCALABLE )
200       {
201 
202 #ifdef FT_CONFIG_OPTION_INCREMENTAL
203 
204         if ( !face->root.internal->incremental_interface )
205           error = tt_face_load_loca( face, stream );
206         if ( !error )
207           error = tt_face_load_cvt      ( face, stream ) ||
208                   tt_face_load_fpgm ( face, stream );
209 
210 #else
211 
212         if ( !error )
213           error = tt_face_load_loca( face, stream ) ||
214                   tt_face_load_cvt      ( face, stream ) ||
215                   tt_face_load_fpgm ( face, stream );
216 
217 #endif
218 
219       }
220 
221     /* initialize standard glyph loading routines */
222     TT_Init_Glyph_Loading( face );
223 
224   Exit:
225     return error;
226 
227   Bad_Format:
228     error = TT_Err_Unknown_File_Format;
229     goto Exit;
230   }
231 
232 
233   /*************************************************************************/
234   /*                                                                       */
235   /* <Function>                                                            */
236   /*    tt_face_done                                                       */
237   /*                                                                       */
238   /* <Description>                                                         */
239   /*    Finalizes a given face object.                                     */
240   /*                                                                       */
241   /* <Input>                                                               */
242   /*    face :: A pointer to the face object to destroy.                   */
243   /*                                                                       */
244   FT_LOCAL_DEF( void )
tt_face_done(TT_Face face)245   tt_face_done( TT_Face  face )
246   {
247     FT_Memory     memory = face->root.memory;
248     FT_Stream     stream = face->root.stream;
249 
250     SFNT_Service  sfnt   = (SFNT_Service)face->sfnt;
251 
252 
253     /* for `extended TrueType formats' (i.e. compressed versions) */
254     if ( face->extra.finalizer )
255       face->extra.finalizer( face->extra.data );
256 
257     if ( sfnt )
258       sfnt->done_face( face );
259 
260     /* freeing the locations table */
261     FT_FREE( face->glyph_locations );
262     face->num_locations = 0;
263 
264     /* freeing the CVT */
265     FT_FREE( face->cvt );
266     face->cvt_size = 0;
267 
268     /* freeing the programs */
269     FT_FRAME_RELEASE( face->font_program );
270     FT_FRAME_RELEASE( face->cvt_program );
271     face->font_program_size = 0;
272     face->cvt_program_size  = 0;
273   }
274 
275 
276   /*************************************************************************/
277   /*                                                                       */
278   /*                           SIZE  FUNCTIONS                             */
279   /*                                                                       */
280   /*************************************************************************/
281 
282 
283   /*************************************************************************/
284   /*                                                                       */
285   /* <Function>                                                            */
286   /*    tt_size_init                                                       */
287   /*                                                                       */
288   /* <Description>                                                         */
289   /*    Initializes a new TrueType size object.                            */
290   /*                                                                       */
291   /* <InOut>                                                               */
292   /*    size :: A handle to the size object.                               */
293   /*                                                                       */
294   /* <Return>                                                              */
295   /*    FreeType error code.  0 means success.                             */
296   /*                                                                       */
297   FT_LOCAL_DEF( FT_Error )
tt_size_init(TT_Size size)298   tt_size_init( TT_Size  size )
299   {
300     FT_Error  error = TT_Err_Ok;
301 
302 
303 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
304 
305     TT_Face    face   = (TT_Face)size->root.face;
306     FT_Memory  memory = face->root.memory;
307     FT_Int     i;
308 
309     TT_ExecContext  exec;
310     FT_UShort       n_twilight;
311     TT_MaxProfile*  maxp = &face->max_profile;
312 
313 
314     size->ttmetrics.valid = FALSE;
315 
316     size->max_function_defs    = maxp->maxFunctionDefs;
317     size->max_instruction_defs = maxp->maxInstructionDefs;
318 
319     size->num_function_defs    = 0;
320     size->num_instruction_defs = 0;
321 
322     size->max_func = 0;
323     size->max_ins  = 0;
324 
325     size->cvt_size     = face->cvt_size;
326     size->storage_size = maxp->maxStorage;
327 
328     /* Set default metrics */
329     {
330       FT_Size_Metrics*  metrics  = &size->root.metrics;
331       TT_Size_Metrics*  metrics2 = &size->ttmetrics;
332 
333 
334       metrics->x_ppem = 0;
335       metrics->y_ppem = 0;
336 
337       metrics2->rotated   = FALSE;
338       metrics2->stretched = FALSE;
339 
340       /* set default compensation (all 0) */
341       for ( i = 0; i < 4; i++ )
342         metrics2->compensations[i] = 0;
343     }
344 
345     /* allocate function defs, instruction defs, cvt, and storage area */
346     if ( FT_NEW_ARRAY( size->function_defs,    size->max_function_defs    ) ||
347          FT_NEW_ARRAY( size->instruction_defs, size->max_instruction_defs ) ||
348          FT_NEW_ARRAY( size->cvt,              size->cvt_size             ) ||
349          FT_NEW_ARRAY( size->storage,          size->storage_size         ) )
350 
351       goto Fail_Memory;
352 
353     /* reserve twilight zone */
354     n_twilight = maxp->maxTwilightPoints;
355     error = tt_glyphzone_new( memory, n_twilight, 0, &size->twilight );
356     if ( error )
357       goto Fail_Memory;
358 
359     size->twilight.n_points = n_twilight;
360 
361     /* set `face->interpreter' according to the debug hook present */
362     {
363       FT_Library  library = face->root.driver->root.library;
364 
365 
366       face->interpreter = (TT_Interpreter)
367                             library->debug_hooks[FT_DEBUG_HOOK_TRUETYPE];
368       if ( !face->interpreter )
369         face->interpreter = (TT_Interpreter)TT_RunIns;
370     }
371 
372     /* Fine, now execute the font program! */
373     exec = size->context;
374     /* size objects used during debugging have their own context */
375     if ( !size->debug )
376       exec = TT_New_Context( face );
377 
378     if ( !exec )
379     {
380       error = TT_Err_Could_Not_Find_Context;
381       goto Fail_Memory;
382     }
383 
384     size->GS = tt_default_graphics_state;
385     TT_Load_Context( exec, face, size );
386 
387     exec->callTop   = 0;
388     exec->top       = 0;
389 
390     exec->period    = 64;
391     exec->phase     = 0;
392     exec->threshold = 0;
393 
394     {
395       FT_Size_Metrics*  metrics    = &exec->metrics;
396       TT_Size_Metrics*  tt_metrics = &exec->tt_metrics;
397 
398 
399       metrics->x_ppem   = 0;
400       metrics->y_ppem   = 0;
401       metrics->x_scale  = 0;
402       metrics->y_scale  = 0;
403 
404       tt_metrics->ppem  = 0;
405       tt_metrics->scale = 0;
406       tt_metrics->ratio = 0x10000L;
407     }
408 
409     exec->instruction_trap = FALSE;
410 
411     exec->cvtSize = size->cvt_size;
412     exec->cvt     = size->cvt;
413 
414     exec->F_dot_P = 0x10000L;
415 
416     /* allow font program execution */
417     TT_Set_CodeRange( exec,
418                       tt_coderange_font,
419                       face->font_program,
420                       face->font_program_size );
421 
422     /* disable CVT and glyph programs coderange */
423     TT_Clear_CodeRange( exec, tt_coderange_cvt );
424     TT_Clear_CodeRange( exec, tt_coderange_glyph );
425 
426     if ( face->font_program_size > 0 )
427     {
428       error = TT_Goto_CodeRange( exec, tt_coderange_font, 0 );
429       if ( !error )
430         error = face->interpreter( exec );
431 
432       if ( error )
433         goto Fail_Exec;
434     }
435     else
436       error = TT_Err_Ok;
437 
438     TT_Save_Context( exec, size );
439 
440     if ( !size->debug )
441       TT_Done_Context( exec );
442 
443 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
444 
445     size->ttmetrics.valid = FALSE;
446     return error;
447 
448 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
449 
450   Fail_Exec:
451     if ( !size->debug )
452       TT_Done_Context( exec );
453 
454   Fail_Memory:
455 
456     tt_size_done( size );
457     return error;
458 
459 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
460 
461   }
462 
463 
464   /*************************************************************************/
465   /*                                                                       */
466   /* <Function>                                                            */
467   /*    tt_size_done                                                       */
468   /*                                                                       */
469   /* <Description>                                                         */
470   /*    The TrueType size object finalizer.                                */
471   /*                                                                       */
472   /* <Input>                                                               */
473   /*    size :: A handle to the target size object.                        */
474   /*                                                                       */
475   FT_LOCAL_DEF( void )
tt_size_done(TT_Size size)476   tt_size_done( TT_Size  size )
477   {
478 
479 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
480 
481     FT_Memory  memory = size->root.face->memory;
482 
483 
484     if ( size->debug )
485     {
486       /* the debug context must be deleted by the debugger itself */
487       size->context = NULL;
488       size->debug   = FALSE;
489     }
490 
491     FT_FREE( size->cvt );
492     size->cvt_size = 0;
493 
494     /* free storage area */
495     FT_FREE( size->storage );
496     size->storage_size = 0;
497 
498     /* twilight zone */
499     tt_glyphzone_done( &size->twilight );
500 
501     FT_FREE( size->function_defs );
502     FT_FREE( size->instruction_defs );
503 
504     size->num_function_defs    = 0;
505     size->max_function_defs    = 0;
506     size->num_instruction_defs = 0;
507     size->max_instruction_defs = 0;
508 
509     size->max_func = 0;
510     size->max_ins  = 0;
511 
512 #endif
513 
514     size->ttmetrics.valid = FALSE;
515   }
516 
517 
518   /*************************************************************************/
519   /*                                                                       */
520   /* <Function>                                                            */
521   /*    Reset_Outline_Size                                                 */
522   /*                                                                       */
523   /* <Description>                                                         */
524   /*    Resets a TrueType outline size when resolutions and character      */
525   /*    dimensions have been changed.                                      */
526   /*                                                                       */
527   /* <Input>                                                               */
528   /*    size :: A handle to the target size object.                        */
529   /*                                                                       */
530   static FT_Error
Reset_Outline_Size(TT_Size size)531   Reset_Outline_Size( TT_Size  size )
532   {
533     TT_Face           face;
534     FT_Error          error = TT_Err_Ok;
535 
536     FT_Size_Metrics*  metrics;
537 
538 
539     if ( size->ttmetrics.valid )
540       return TT_Err_Ok;
541 
542     face = (TT_Face)size->root.face;
543 
544     metrics = &size->root.metrics;
545 
546     if ( metrics->x_ppem < 1 || metrics->y_ppem < 1 )
547       return TT_Err_Invalid_PPem;
548 
549     /* compute new transformation */
550     if ( metrics->x_ppem >= metrics->y_ppem )
551     {
552       size->ttmetrics.scale   = metrics->x_scale;
553       size->ttmetrics.ppem    = metrics->x_ppem;
554       size->ttmetrics.x_ratio = 0x10000L;
555       size->ttmetrics.y_ratio = FT_MulDiv( metrics->y_ppem,
556                                            0x10000L,
557                                            metrics->x_ppem );
558     }
559     else
560     {
561       size->ttmetrics.scale   = metrics->y_scale;
562       size->ttmetrics.ppem    = metrics->y_ppem;
563       size->ttmetrics.x_ratio = FT_MulDiv( metrics->x_ppem,
564                                            0x10000L,
565                                            metrics->y_ppem );
566       size->ttmetrics.y_ratio = 0x10000L;
567     }
568 
569     /* Compute root ascender, descender, test height, and max_advance */
570     metrics->ascender    = ( FT_MulFix( face->root.ascender,
571                                         metrics->y_scale ) + 32 ) & -64;
572     metrics->descender   = ( FT_MulFix( face->root.descender,
573                                         metrics->y_scale ) + 32 ) & -64;
574     metrics->height      = ( FT_MulFix( face->root.height,
575                                         metrics->y_scale ) + 32 ) & -64;
576     metrics->max_advance = ( FT_MulFix( face->root.max_advance_width,
577                                         metrics->x_scale ) + 32 ) & -64;
578 
579 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
580     /* set to `invalid' by default */
581     size->strike_index = 0xFFFFU;
582 #endif
583 
584 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
585 
586     {
587       TT_ExecContext  exec;
588       FT_UInt         i, j;
589 
590 
591       /* Scale the cvt values to the new ppem.          */
592       /* We use by default the y ppem to scale the CVT. */
593       for ( i = 0; i < size->cvt_size; i++ )
594         size->cvt[i] = FT_MulFix( face->cvt[i], size->ttmetrics.scale );
595 
596       /* All twilight points are originally zero */
597       for ( j = 0; j < (FT_UInt)size->twilight.n_points; j++ )
598       {
599         size->twilight.org[j].x = 0;
600         size->twilight.org[j].y = 0;
601         size->twilight.cur[j].x = 0;
602         size->twilight.cur[j].y = 0;
603       }
604 
605       /* clear storage area */
606       for ( i = 0; i < (FT_UInt)size->storage_size; i++ )
607         size->storage[i] = 0;
608 
609       size->GS = tt_default_graphics_state;
610 
611       /* get execution context and run prep program */
612       if ( size->debug )
613         exec = size->context;
614       else
615         exec = TT_New_Context( face );
616       /* debugging instances have their own context */
617 
618       if ( !exec )
619         return TT_Err_Could_Not_Find_Context;
620 
621       TT_Load_Context( exec, face, size );
622 
623       TT_Set_CodeRange( exec,
624                         tt_coderange_cvt,
625                         face->cvt_program,
626                         face->cvt_program_size );
627 
628       TT_Clear_CodeRange( exec, tt_coderange_glyph );
629 
630       exec->instruction_trap = FALSE;
631 
632       exec->top     = 0;
633       exec->callTop = 0;
634 
635       if ( face->cvt_program_size > 0 )
636       {
637         error = TT_Goto_CodeRange( exec, tt_coderange_cvt, 0 );
638         if ( error )
639           goto End;
640 
641         if ( !size->debug )
642           error = face->interpreter( exec );
643       }
644       else
645         error = TT_Err_Ok;
646 
647       size->GS = exec->GS;
648       /* save default graphics state */
649 
650     End:
651       TT_Save_Context( exec, size );
652 
653       if ( !size->debug )
654         TT_Done_Context( exec );
655       /* debugging instances keep their context */
656     }
657 
658 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
659 
660     if ( !error )
661       size->ttmetrics.valid = TRUE;
662 
663     return error;
664   }
665 
666 
667 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
668 
669   /*************************************************************************/
670   /*                                                                       */
671   /* <Function>                                                            */
672   /*    Reset_SBit_Size                                                    */
673   /*                                                                       */
674   /* <Description>                                                         */
675   /*    Resets a TrueType sbit size when resolutions and character         */
676   /*    dimensions have been changed.                                      */
677   /*                                                                       */
678   /* <Input>                                                               */
679   /*    size :: A handle to the target size object.                        */
680   /*                                                                       */
681   static FT_Error
Reset_SBit_Size(TT_Size size)682   Reset_SBit_Size( TT_Size  size )
683   {
684     TT_Face           face;
685     FT_Error          error = TT_Err_Ok;
686 
687     FT_ULong          strike_index;
688     FT_Size_Metrics*  metrics;
689     FT_Size_Metrics*  sbit_metrics;
690     SFNT_Service      sfnt;
691 
692 
693     metrics = &size->root.metrics;
694 
695     if ( size->strike_index != 0xFFFFU )
696       return TT_Err_Ok;
697 
698     face = (TT_Face)size->root.face;
699     sfnt = (SFNT_Service)face->sfnt;
700 
701     sbit_metrics = &size->strike_metrics;
702 
703     error = sfnt->set_sbit_strike(face,
704                                   metrics->x_ppem, metrics->y_ppem,
705                                   &strike_index);
706 
707     if ( !error )
708     {
709       TT_SBit_Strike  strike = face->sbit_strikes + strike_index;
710 
711 
712       sbit_metrics->x_ppem      = metrics->x_ppem;
713       sbit_metrics->y_ppem      = metrics->y_ppem;
714 #if 0
715       /*
716        * sbit_metrics->?_scale
717        * are not used now.
718        */
719       sbit_metrics->x_scale     = 1 << 16;
720       sbit_metrics->y_scale     = 1 << 16;
721 #endif
722 
723       sbit_metrics->ascender    = strike->hori.ascender  << 6;
724       sbit_metrics->descender   = strike->hori.descender << 6;
725 
726       /* XXX: Is this correct? */
727       sbit_metrics->height      = sbit_metrics->ascender -
728                                   sbit_metrics->descender;
729 
730       /* XXX: Is this correct? */
731       sbit_metrics->max_advance = ( strike->hori.min_origin_SB +
732                                     strike->hori.max_width     +
733                                     strike->hori.min_advance_SB ) << 6;
734 
735       size->strike_index = strike_index;
736     }
737     else
738     {
739       size->strike_index = 0xFFFFU;
740 
741       sbit_metrics->x_ppem      = 0;
742       sbit_metrics->y_ppem      = 0;
743       sbit_metrics->ascender    = 0;
744       sbit_metrics->descender   = 0;
745       sbit_metrics->height      = 0;
746       sbit_metrics->max_advance = 0;
747     }
748 
749     return error;
750   }
751 
752 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
753 
754 
755   /*************************************************************************/
756   /*                                                                       */
757   /* <Function>                                                            */
758   /*    tt_size_reset                                                      */
759   /*                                                                       */
760   /* <Description>                                                         */
761   /*    Resets a TrueType size when resolutions and character dimensions   */
762   /*    have been changed.                                                 */
763   /*                                                                       */
764   /* <Input>                                                               */
765   /*    size :: A handle to the target size object.                        */
766   /*                                                                       */
767   FT_LOCAL_DEF( FT_Error )
tt_size_reset(TT_Size size)768   tt_size_reset( TT_Size  size )
769   {
770     FT_Face   face;
771     FT_Error  error = TT_Err_Ok;
772 
773 
774     face = size->root.face;
775 
776     if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
777     {
778       if ( !size->ttmetrics.valid )
779         error = Reset_Outline_Size( size );
780 
781       if ( error )
782         return error;
783     }
784 
785 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
786 
787     if ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES )
788     {
789       if ( size->strike_index == 0xFFFFU )
790         error = Reset_SBit_Size( size );
791 
792       if ( !error && !( face->face_flags & FT_FACE_FLAG_SCALABLE ) )
793         size->root.metrics = size->strike_metrics;
794     }
795 
796 #endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
797 
798     if ( face->face_flags & FT_FACE_FLAG_SCALABLE )
799       return TT_Err_Ok;
800     else
801       return error;
802   }
803 
804 
805   /*************************************************************************/
806   /*                                                                       */
807   /* <Function>                                                            */
808   /*    tt_driver_init                                                     */
809   /*                                                                       */
810   /* <Description>                                                         */
811   /*    Initializes a given TrueType driver object.                        */
812   /*                                                                       */
813   /* <Input>                                                               */
814   /*    driver :: A handle to the target driver object.                    */
815   /*                                                                       */
816   /* <Return>                                                              */
817   /*    FreeType error code.  0 means success.                             */
818   /*                                                                       */
819   FT_LOCAL_DEF( FT_Error )
tt_driver_init(TT_Driver driver)820   tt_driver_init( TT_Driver  driver )
821   {
822     FT_Error  error;
823 
824 
825     /* set `extra' in glyph loader */
826     error = FT_GlyphLoader_CreateExtra( FT_DRIVER( driver )->glyph_loader );
827 
828     return error;
829   }
830 
831 
832   /*************************************************************************/
833   /*                                                                       */
834   /* <Function>                                                            */
835   /*    tt_driver_done                                                     */
836   /*                                                                       */
837   /* <Description>                                                         */
838   /*    Finalizes a given TrueType driver.                                 */
839   /*                                                                       */
840   /* <Input>                                                               */
841   /*    driver :: A handle to the target TrueType driver.                  */
842   /*                                                                       */
843   FT_LOCAL_DEF( void )
tt_driver_done(TT_Driver driver)844   tt_driver_done( TT_Driver  driver )
845   {
846 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
847 
848     /* destroy the execution context */
849     if ( driver->context )
850     {
851       TT_Destroy_Context( driver->context, driver->root.root.memory );
852       driver->context = NULL;
853     }
854 #else
855     FT_UNUSED( driver );
856 #endif
857 
858   }
859 
860 
861 /* END */
862