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