ttgload.c revision d5c1b27d58c4308745338cb0f3f710d6c1549982
1/***************************************************************************/
2/*                                                                         */
3/*  ttgload.c                                                              */
4/*                                                                         */
5/*    TrueType Glyph Loader (body).                                        */
6/*                                                                         */
7/*  Copyright 1996-2000 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_INTERNAL_SFNT_H
24#include FT_TRUETYPE_TAGS_H
25#include FT_OUTLINE_H
26
27#include FT_SOURCE_FILE( truetype, ttgload.h )
28
29
30  /*************************************************************************/
31  /*                                                                       */
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  */
34  /* messages during execution.                                            */
35  /*                                                                       */
36#undef  FT_COMPONENT
37#define FT_COMPONENT  trace_ttgload
38
39
40  /*************************************************************************/
41  /*                                                                       */
42  /* Composite font flags.                                                 */
43  /*                                                                       */
44#define ARGS_ARE_WORDS       0x001
45#define ARGS_ARE_XY_VALUES   0x002
46#define ROUND_XY_TO_GRID     0x004
47#define WE_HAVE_A_SCALE      0x008
48/* reserved                  0x010 */
49#define MORE_COMPONENTS      0x020
50#define WE_HAVE_AN_XY_SCALE  0x040
51#define WE_HAVE_A_2X2        0x080
52#define WE_HAVE_INSTR        0x100
53#define USE_MY_METRICS       0x200
54
55
56
57  /*************************************************************************/
58  /*                                                                       */
59  /* <Function>                                                            */
60  /*    TT_Get_Metrics                                                     */
61  /*                                                                       */
62  /* <Description>                                                         */
63  /*    Returns the horizontal or vertical metrics in font units for a     */
64  /*    given glyph.  The metrics are the left side bearing (resp. top     */
65  /*    side bearing) and advance width (resp. advance height).            */
66  /*                                                                       */
67  /* <Input>                                                               */
68  /*    header  :: A pointer to either the horizontal or vertical metrics  */
69  /*               structure.                                              */
70  /*                                                                       */
71  /*    index   :: The glyph index.                                        */
72  /*                                                                       */
73  /* <Output>                                                              */
74  /*    bearing :: The bearing, either left side or top side.              */
75  /*                                                                       */
76  /*    advance :: The advance width resp. advance height.                 */
77  /*                                                                       */
78  /* <Note>                                                                */
79  /*    This function will much probably move to another component in the  */
80  /*    near future, but I haven't decided which yet.                      */
81  /*                                                                       */
82  FT_LOCAL_DEF
83  void  TT_Get_Metrics( TT_HoriHeader*  header,
84                        FT_UInt         index,
85                        FT_Short*       bearing,
86                        FT_UShort*      advance )
87  {
88    TT_LongMetrics*  longs_m;
89    FT_UShort        k = header->number_Of_HMetrics;
90
91
92    if ( index < (FT_UInt)k )
93    {
94      longs_m  = (TT_LongMetrics*)header->long_metrics + index;
95      *bearing = longs_m->bearing;
96      *advance = longs_m->advance;
97    }
98    else
99    {
100      *bearing = ((TT_ShortMetrics*)header->short_metrics)[index - k];
101      *advance = ((TT_LongMetrics*)header->long_metrics)[k - 1].advance;
102    }
103  }
104
105
106  /*************************************************************************/
107  /*                                                                       */
108  /* Returns the horizontal metrics in font units for a given glyph.  If   */
109  /* `check' is true, take care of monospaced fonts by returning the       */
110  /* advance width maximum.                                                */
111  /*                                                                       */
112  static
113  void Get_HMetrics( TT_Face     face,
114                     FT_UInt     index,
115                     FT_Bool     check,
116                     FT_Short*   lsb,
117                     FT_UShort*  aw )
118  {
119    TT_Get_Metrics( &face->horizontal, index, lsb, aw );
120
121    if ( check && face->postscript.isFixedPitch )
122      *aw = face->horizontal.advance_Width_Max;
123  }
124
125
126  /*************************************************************************/
127  /*                                                                       */
128  /*    Returns the advance width table for a given pixel size if it is    */
129  /*    found in the font's `hdmx' table (if any).                         */
130  /*                                                                       */
131  static
132  FT_Byte*  Get_Advance_Widths( TT_Face    face,
133                                FT_UShort  ppem )
134  {
135    FT_UShort  n;
136
137    for ( n = 0; n < face->hdmx.num_records; n++ )
138      if ( face->hdmx.records[n].ppem == ppem )
139        return face->hdmx.records[n].widths;
140
141    return NULL;
142  }
143
144
145#define cur_to_org( n, zone ) \
146          MEM_Copy( (zone)->org, (zone)->cur, n * sizeof ( FT_Vector ) )
147
148#define org_to_cur( n, zone ) \
149          MEM_Copy( (zone)->cur, (zone)->org, n * sizeof ( FT_Vector ) )
150
151
152  /*************************************************************************/
153  /*                                                                       */
154  /*    Translates an array of coordinates.                                */
155  /*                                                                       */
156  static
157  void  translate_array( FT_UInt     n,
158                         FT_Vector*  coords,
159                         FT_Pos      delta_x,
160                         FT_Pos      delta_y )
161  {
162    FT_UInt  k;
163
164
165    if ( delta_x )
166      for ( k = 0; k < n; k++ )
167        coords[k].x += delta_x;
168
169    if ( delta_y )
170      for ( k = 0; k < n; k++ )
171        coords[k].y += delta_y;
172  }
173
174
175  static
176  void  tt_prepare_zone( TT_GlyphZone*  zone,
177                         FT_GlyphLoad*  load,
178                         FT_UInt        start_point,
179                         FT_UInt        start_contour )
180  {
181    zone->n_points   = load->outline.n_points - start_point;
182    zone->n_contours = load->outline.n_contours - start_contour;
183    zone->org        = load->extra_points + start_point;
184    zone->cur        = load->outline.points + start_point;
185    zone->tags       = (FT_Byte*)load->outline.tags + start_point;
186    zone->contours   = (FT_UShort*)load->outline.contours + start_contour;
187  }
188
189
190#undef  IS_HINTED
191#define IS_HINTED( flags )  ( ( flags & FT_LOAD_NO_HINTING ) == 0 )
192
193
194  /*************************************************************************/
195  /*                                                                       */
196  /*  The following functions are used by default with TrueType fonts.     */
197  /*  However, they can be replaced by alternatives if we need to support  */
198  /*  TrueType-compressed formats (like MicroType) in the future.          */
199  /*                                                                       */
200  /*************************************************************************/
201
202  FT_CALLBACK_DEF
203  FT_Error  TT_Access_Glyph_Frame( TT_Loader*  loader,
204                                   FT_UInt     glyph_index,
205                                   FT_ULong    offset,
206                                   FT_UInt     byte_count )
207  {
208    FT_Error   error;
209    FT_Stream  stream = loader->stream;
210
211    /* for non-debug mode */
212    FT_UNUSED( glyph_index );
213
214
215    FT_TRACE5(( "Glyph %ld\n", glyph_index ));
216
217    /* the following line sets the `error' variable through macros! */
218    if ( FILE_Seek( offset ) || ACCESS_Frame( byte_count ) )
219      return error;
220
221    return TT_Err_Ok;
222  }
223
224
225  FT_CALLBACK_DEF
226  void  TT_Forget_Glyph_Frame( TT_Loader*  loader )
227  {
228    FT_Stream  stream = loader->stream;
229
230
231    FORGET_Frame();
232  }
233
234
235  FT_CALLBACK_DEF
236  FT_Error  TT_Load_Glyph_Header( TT_Loader*  loader )
237  {
238    FT_Stream   stream = loader->stream;
239
240
241    loader->n_contours = GET_Short();
242
243    loader->bbox.xMin = GET_Short();
244    loader->bbox.yMin = GET_Short();
245    loader->bbox.xMax = GET_Short();
246    loader->bbox.yMax = GET_Short();
247
248    FT_TRACE5(( "  # of contours: %d\n", loader->n_contours ));
249    FT_TRACE5(( "  xMin: %4d  xMax: %4d\n", loader->bbox.xMin,
250                                            loader->bbox.xMax ));
251    FT_TRACE5(( "  yMin: %4d  yMax: %4d\n", loader->bbox.yMin,
252                                            loader->bbox.yMax ));
253
254    return FT_Err_Ok;
255  }
256
257
258  FT_CALLBACK_DEF
259  FT_Error  TT_Load_Simple_Glyph( TT_Loader*  load )
260  {
261    FT_Error         error;
262    FT_Stream        stream     = load->stream;
263    FT_GlyphLoader*  gloader    = load->gloader;
264    FT_Int           n_contours = load->n_contours;
265    FT_Outline*      outline;
266    TT_Face          face    = (TT_Face)load->face;
267    TT_GlyphSlot     slot    = (TT_GlyphSlot)load->glyph;
268    FT_UShort        n_ins;
269    FT_Int           n, n_points;
270
271
272    /* reading the contours endpoints & number of points */
273    {
274      short*  cur   = gloader->current.outline.contours;
275      short*  limit = cur + n_contours;
276
277
278      for ( ; cur < limit; cur++ )
279        cur[0] = GET_UShort();
280
281      n_points = 0;
282      if ( n_contours > 0 )
283        n_points = cur[-1] + 1;
284
285      error = FT_GlyphLoader_Check_Points( gloader, n_points + 2, 0 );
286      if ( error )
287        goto Fail;
288
289      outline = &gloader->current.outline;
290    }
291
292    /* reading the bytecode instructions */
293    slot->control_len  = 0;
294    slot->control_data = 0;
295
296    n_ins = GET_UShort();
297
298    FT_TRACE5(( "  Instructions size: %d\n", n_ins ));
299
300    if ( n_ins > face->max_profile.maxSizeOfInstructions )
301    {
302      FT_TRACE0(( "ERROR: Too many instructions!\n" ));
303      error = TT_Err_Too_Many_Ins;
304      goto Fail;
305    }
306
307    if ( stream->cursor + n_ins > stream->limit )
308    {
309      FT_TRACE0(( "ERROR: Instruction count mismatch!\n" ));
310      error = TT_Err_Too_Many_Ins;
311      goto Fail;
312    }
313
314#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
315
316    if ( ( load->load_flags                        &
317         ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) ) == 0 &&
318           load->instructions )
319    {
320      slot->control_len  = n_ins;
321      slot->control_data = load->instructions;
322
323      MEM_Copy( load->instructions, stream->cursor, n_ins );
324    }
325
326#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
327
328    stream->cursor += n_ins;
329
330    /* reading the point tags */
331
332    {
333      FT_Byte*  flag  = (FT_Byte*)outline->tags;
334      FT_Byte*  limit = flag + n_points;
335      FT_Byte   c, count;
336
337
338      for ( ; flag < limit; flag++ )
339      {
340        *flag = c = GET_Byte();
341        if ( c & 8 )
342        {
343          for ( count = GET_Byte(); count > 0; count-- )
344            *++flag = c;
345        }
346      }
347    }
348
349    /* reading the X coordinates */
350
351    {
352      FT_Vector*  vec   = outline->points;
353      FT_Vector*  limit = vec + n_points;
354      FT_Byte*    flag  = (FT_Byte*)outline->tags;
355      FT_Pos      x     = 0;
356
357
358      for ( ; vec < limit; vec++, flag++ )
359      {
360        FT_Pos  y = 0;
361
362
363        if ( *flag & 2 )
364        {
365          y = GET_Byte();
366          if ( ( *flag & 16 ) == 0 )
367            y = -y;
368        }
369        else if ( ( *flag & 16 ) == 0 )
370          y = GET_Short();
371
372        x     += y;
373        vec->x = x;
374      }
375    }
376
377    /* reading the Y coordinates */
378
379    {
380      FT_Vector*  vec   = gloader->current.outline.points;
381      FT_Vector*  limit = vec + n_points;
382      FT_Byte*    flag  = (FT_Byte*)outline->tags;
383      FT_Pos      x     = 0;
384
385
386      for ( ; vec < limit; vec++, flag++ )
387      {
388        FT_Pos  y = 0;
389
390
391        if ( *flag & 4 )
392        {
393          y = GET_Byte();
394          if ( ( *flag & 32 ) == 0 )
395            y = -y;
396        }
397        else if ( ( *flag & 32 ) == 0 )
398          y = GET_Short();
399
400        x     += y;
401        vec->y = x;
402      }
403    }
404
405    /* clear the touch tags */
406    for ( n = 0; n < n_points; n++ )
407      outline->tags[n] &= FT_Curve_Tag_On;
408
409    outline->n_points   = n_points;
410    outline->n_contours = n_contours;
411
412  Fail:
413    return error;
414  }
415
416
417  FT_CALLBACK_DEF
418  FT_Error  TT_Load_Composite_Glyph( TT_Loader*  loader )
419  {
420    FT_Error         error;
421    FT_Stream        stream  = loader->stream;
422    FT_GlyphLoader*  gloader = loader->gloader;
423    FT_SubGlyph*     subglyph;
424    FT_UInt          num_subglyphs;
425
426
427    num_subglyphs = 0;
428
429    do
430    {
431      FT_Fixed  xx, xy, yy, yx;
432
433
434      /* check that we can load a new subglyph */
435      error = FT_GlyphLoader_Check_Subglyphs( gloader, num_subglyphs + 1 );
436      if ( error )
437        goto Fail;
438
439      subglyph = gloader->current.subglyphs + num_subglyphs;
440
441      subglyph->arg1 = subglyph->arg2 = 0;
442
443      subglyph->flags = GET_UShort();
444      subglyph->index = GET_UShort();
445
446      /* read arguments */
447      if ( subglyph->flags & ARGS_ARE_WORDS )
448      {
449        subglyph->arg1 = GET_Short();
450        subglyph->arg2 = GET_Short();
451      }
452      else
453      {
454        subglyph->arg1 = GET_Char();
455        subglyph->arg2 = GET_Char();
456      }
457
458      /* read transform */
459      xx = yy = 0x10000L;
460      xy = yx = 0;
461
462      if ( subglyph->flags & WE_HAVE_A_SCALE )
463      {
464        xx = (FT_Fixed)GET_Short() << 2;
465        yy = xx;
466      }
467      else if ( subglyph->flags & WE_HAVE_AN_XY_SCALE )
468      {
469        xx = (FT_Fixed)GET_Short() << 2;
470        yy = (FT_Fixed)GET_Short() << 2;
471      }
472      else if ( subglyph->flags & WE_HAVE_A_2X2 )
473      {
474        xx = (FT_Fixed)GET_Short() << 2;
475        xy = (FT_Fixed)GET_Short() << 2;
476        yx = (FT_Fixed)GET_Short() << 2;
477        yy = (FT_Fixed)GET_Short() << 2;
478      }
479
480      subglyph->transform.xx = xx;
481      subglyph->transform.xy = xy;
482      subglyph->transform.yx = yx;
483      subglyph->transform.yy = yy;
484
485      num_subglyphs++;
486
487    } while ( subglyph->flags & MORE_COMPONENTS );
488
489    gloader->current.num_subglyphs = num_subglyphs;
490
491#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
492    {
493      /* we must undo the ACCESS_Frame in order to point to the */
494      /* composite instructions, if we find some.               */
495      /* we will process them later...                          */
496      /*                                                        */
497      loader->ins_pos = FILE_Pos() + stream->cursor - stream->limit;
498    }
499#endif
500
501  Fail:
502    return error;
503  }
504
505
506  FT_LOCAL_DEF
507  void  TT_Init_Glyph_Loading( TT_Face  face )
508  {
509    face->access_glyph_frame   = TT_Access_Glyph_Frame;
510    face->read_glyph_header    = TT_Load_Glyph_Header;
511    face->read_simple_glyph    = TT_Load_Simple_Glyph;
512    face->read_composite_glyph = TT_Load_Composite_Glyph;
513    face->forget_glyph_frame   = TT_Forget_Glyph_Frame;
514  }
515
516
517  /*************************************************************************/
518  /*                                                                       */
519  /* <Function>                                                            */
520  /*    TT_Process_Simple_Glyph                                            */
521  /*                                                                       */
522  /* <Description>                                                         */
523  /*    Once a simple glyph has been loaded, it needs to be processed.     */
524  /*    Usually, this means scaling and hinting through bytecode           */
525  /*    interpretation.                                                    */
526  /*                                                                       */
527  static
528  FT_Error  TT_Process_Simple_Glyph( TT_Loader*  load,
529                                     FT_Bool     debug )
530  {
531    FT_GlyphLoader*  gloader  = load->gloader;
532    FT_Outline*      outline  = &gloader->current.outline;
533    FT_UInt          n_points = outline->n_points;
534    FT_UInt          n_ins;
535    TT_GlyphZone*    zone     = &load->zone;
536    FT_Error         error    = FT_Err_Ok;
537
538    FT_UNUSED( debug );  /* used by truetype interpreter only */
539
540
541    n_ins = load->glyph->control_len;
542
543    /* add shadow points */
544
545    /* Now add the two shadow points at n and n + 1.    */
546    /* We need the left side bearing and advance width. */
547
548    {
549      FT_Vector*  pp1;
550      FT_Vector*  pp2;
551
552
553      /* pp1 = xMin - lsb */
554      pp1    = outline->points + n_points;
555      pp1->x = load->bbox.xMin - load->left_bearing;
556      pp1->y = 0;
557
558      /* pp2 = pp1 + aw */
559      pp2    = pp1 + 1;
560      pp2->x = pp1->x + load->advance;
561      pp2->y = 0;
562
563      outline->tags[n_points    ] = 0;
564      outline->tags[n_points + 1] = 0;
565    }
566
567    /* Note that we return two more points that are not */
568    /* part of the glyph outline.                       */
569
570    n_points += 2;
571
572    /* set up zone for hinting */
573    tt_prepare_zone( zone, &gloader->current, 0, 0 );
574
575    /* eventually scale the glyph */
576    if ( !( load->load_flags & FT_LOAD_NO_SCALE ) )
577    {
578      FT_Vector*  vec     = zone->cur;
579      FT_Vector*  limit   = vec + n_points;
580      FT_Fixed    x_scale = load->size->metrics.x_scale;
581      FT_Fixed    y_scale = load->size->metrics.y_scale;
582
583
584      /* first scale the glyph points */
585      for ( ; vec < limit; vec++ )
586      {
587        vec->x = FT_MulFix( vec->x, x_scale );
588        vec->y = FT_MulFix( vec->y, y_scale );
589      }
590    }
591
592    cur_to_org( n_points, zone );
593
594    /* eventually hint the glyph */
595    if ( IS_HINTED( load->load_flags ) )
596    {
597      FT_Pos  x = zone->org[n_points-2].x;
598
599
600      x = ( ( x + 32 ) & -64 ) - x;
601      translate_array( n_points, zone->org, x, 0 );
602
603      org_to_cur( n_points, zone );
604
605      zone->cur[n_points - 1].x = ( zone->cur[n_points - 1].x + 32 ) & -64;
606
607#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
608
609      /* now consider hinting */
610      if ( n_ins > 0 )
611      {
612        error = TT_Set_CodeRange( load->exec, tt_coderange_glyph,
613                                  load->exec->glyphIns, n_ins );
614        if ( error )
615          goto Exit;
616
617        load->exec->is_composite     = FALSE;
618        load->exec->pedantic_hinting = (FT_Bool)( load->load_flags &
619                                                  FT_LOAD_PEDANTIC );
620        load->exec->pts              = *zone;
621        load->exec->pts.n_points    += 2;
622
623        error = TT_Run_Context( load->exec, debug );
624        if ( error && load->exec->pedantic_hinting )
625          goto Exit;
626
627        error = FT_Err_Ok;  /* ignore bytecode errors in non-pedantic mode */
628      }
629
630#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
631
632    }
633
634    /* save glyph phantom points */
635    if ( !load->preserve_pps )
636    {
637      load->pp1 = zone->cur[n_points - 2];
638      load->pp2 = zone->cur[n_points - 1];
639    }
640
641#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
642  Exit:
643#endif
644    return error;
645  }
646
647
648  /*************************************************************************/
649  /*                                                                       */
650  /* <Function>                                                            */
651  /*    load_truetype_glyph                                                */
652  /*                                                                       */
653  /* <Description>                                                         */
654  /*    Loads a given truetype glyph.  Handles composites and uses a       */
655  /*    TT_Loader object.                                                  */
656  /*                                                                       */
657  static
658  FT_Error  load_truetype_glyph( TT_Loader*  loader,
659                                 FT_UInt     glyph_index )
660  {
661
662#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
663    FT_Stream        stream = loader->stream;
664#endif
665
666    FT_Error         error;
667    TT_Face          face   = (TT_Face)loader->face;
668    FT_ULong         offset;
669    FT_Int           contours_count;
670    FT_UInt          index, num_points, num_contours, count;
671    FT_Fixed         x_scale, y_scale;
672    FT_ULong         ins_offset;
673    FT_GlyphLoader*  gloader = loader->gloader;
674    FT_Bool          opened_frame = 0;
675
676
677    /* check glyph index */
678    index = glyph_index;
679    if ( index >= (FT_UInt)face->root.num_glyphs )
680    {
681      error = TT_Err_Invalid_Glyph_Index;
682      goto Exit;
683    }
684
685    loader->glyph_index = glyph_index;
686    num_contours = 0;
687    num_points   = 0;
688    ins_offset   = 0;
689
690    x_scale = 0x10000L;
691    y_scale = 0x10000L;
692    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
693    {
694      x_scale = loader->size->metrics.x_scale;
695      y_scale = loader->size->metrics.y_scale;
696    }
697
698    /* get horizontal metrics */
699    {
700      FT_Short   left_bearing;
701      FT_UShort  advance_width;
702
703
704      Get_HMetrics( face, index,
705                    (FT_Bool)!(loader->load_flags &
706                                FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH),
707                    &left_bearing,
708                    &advance_width );
709
710      loader->left_bearing = left_bearing;
711      loader->advance      = advance_width;
712    }
713
714    offset = face->glyph_locations[index];
715    count  = 0;
716
717    if ( index < (FT_UInt)face->num_locations - 1 )
718       count = face->glyph_locations[index + 1] - offset;
719
720    if ( count == 0 )
721    {
722      /* as described by Frederic Loyer, these are spaces, and */
723      /* not the unknown glyph.                                */
724      loader->bbox.xMin = 0;
725      loader->bbox.xMax = 0;
726      loader->bbox.yMin = 0;
727      loader->bbox.yMax = 0;
728
729      loader->pp1.x = 0;
730      loader->pp2.x = loader->advance;
731
732      if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
733        loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
734
735#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
736
737      if ( loader->exec )
738        loader->exec->glyphSize = 0;
739
740#endif
741
742      error = FT_Err_Ok;
743      goto Exit;
744    }
745
746    offset = loader->glyf_offset + offset;
747
748    /* access glyph frame */
749    error = face->access_glyph_frame( loader, glyph_index, offset, count );
750    if ( error )
751      goto Exit;
752
753    opened_frame = 1;
754
755    /* read first glyph header */
756    error = face->read_glyph_header( loader );
757    if ( error )
758      goto Fail;
759
760    contours_count = loader->n_contours;
761
762    count -= 10;
763
764    loader->pp1.x = loader->bbox.xMin - loader->left_bearing;
765    loader->pp1.y = 0;
766    loader->pp2.x = loader->pp1.x + loader->advance;
767    loader->pp2.y = 0;
768
769    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
770    {
771      loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );
772      loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );
773    }
774
775    /***********************************************************************/
776    /***********************************************************************/
777    /***********************************************************************/
778
779    /* if it is a simple glyph, load it */
780
781    if ( contours_count >= 0 )
782    {
783      /* check that we can add the contours to the glyph */
784      error = FT_GlyphLoader_Check_Points( gloader, 0, contours_count );
785      if ( error )
786        goto Fail;
787
788      error = face->read_simple_glyph( loader );
789      if ( error )
790        goto Fail;
791
792#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
793
794      {
795        TT_Size size = (TT_Size)loader->size;
796
797
798        error = TT_Process_Simple_Glyph( loader,
799                                         (FT_Bool)( size && size->debug ) );
800      }
801
802#else
803
804      error = TT_Process_Simple_Glyph( loader, 0 );
805
806#endif
807
808      if ( error )
809        goto Fail;
810
811      FT_GlyphLoader_Add( gloader );
812
813      /* Note: We could have put the simple loader source there */
814      /*       but the code is fat enough already :-)           */
815    }
816
817    /***********************************************************************/
818    /***********************************************************************/
819    /***********************************************************************/
820
821    /* otherwise, load a composite! */
822    else
823    {
824      TT_GlyphSlot  glyph = (TT_GlyphSlot)loader->glyph;
825      FT_UInt       start_point, start_contour;
826      FT_ULong      ins_pos;  /* position of composite instructions, if any */
827
828
829      /* for each subglyph, read composite header */
830      start_point   = gloader->base.outline.n_points;
831      start_contour = gloader->base.outline.n_contours;
832
833      error = face->read_composite_glyph( loader );
834      if ( error )
835        goto Fail;
836
837      ins_pos = loader->ins_pos;
838      face->forget_glyph_frame( loader );
839      opened_frame = 0;
840
841      /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */
842      /* `as is' in the glyph slot (the client application will be     */
843      /* responsible for interpreting this data)...                    */
844      /*                                                               */
845      if ( loader->load_flags & FT_LOAD_NO_RECURSE )
846      {
847        /* set up remaining glyph fields */
848        FT_GlyphLoader_Add( gloader );
849
850        glyph->num_subglyphs  = gloader->base.num_subglyphs;
851        glyph->format         = ft_glyph_format_composite;
852        glyph->subglyphs      = gloader->base.subglyphs;
853
854        goto Exit;
855      }
856
857      /*********************************************************************/
858      /*********************************************************************/
859      /*********************************************************************/
860
861      /* Now, read each subglyph independently. */
862      {
863        FT_Int        n, num_base_points, num_new_points;
864        FT_SubGlyph*  subglyph = 0;
865
866        FT_UInt num_subglyphs  = gloader->current.num_subglyphs;
867        FT_UInt num_base_subgs = gloader->base.num_subglyphs;
868
869
870        FT_GlyphLoader_Add( gloader );
871
872        for ( n = 0; n < (FT_Int)num_subglyphs; n++ )
873        {
874          FT_Vector  pp1, pp2;
875          FT_Pos     x, y;
876
877
878          /* Each time we call load_truetype_glyph in this loop, the   */
879          /* value of `gloader.base.subglyphs' can change due to table */
880          /* reallocations.  We thus need to recompute the subglyph    */
881          /* pointer on each iteration.                                */
882          subglyph = gloader->base.subglyphs + num_base_subgs + n;
883
884          pp1 = loader->pp1;
885          pp2 = loader->pp2;
886
887          num_base_points = gloader->base.outline.n_points;
888
889          error = load_truetype_glyph( loader, subglyph->index );
890          if ( error )
891            goto Fail;
892
893          subglyph = gloader->base.subglyphs + num_base_subgs + n;
894
895          if ( subglyph->flags & USE_MY_METRICS )
896          {
897            pp1 = loader->pp1;
898            pp2 = loader->pp2;
899          }
900          else
901          {
902            loader->pp1 = pp1;
903            loader->pp2 = pp2;
904          }
905
906          num_points = gloader->base.outline.n_points;
907
908          num_new_points = num_points - num_base_points;
909
910          /* now perform the transform required for this subglyph */
911
912          if ( subglyph->flags & ( WE_HAVE_A_SCALE     |
913                                   WE_HAVE_AN_XY_SCALE |
914                                   WE_HAVE_A_2X2       ) )
915          {
916            FT_Vector*  cur   = gloader->base.outline.points +
917                                  num_base_points;
918            FT_Vector*  org   = gloader->base.extra_points +
919                                  num_base_points;
920            FT_Vector*  limit = cur + num_new_points;
921
922
923            for ( ; cur < limit; cur++, org++ )
924            {
925              FT_Vector_Transform( cur, &subglyph->transform );
926              FT_Vector_Transform( org, &subglyph->transform );
927            }
928          }
929
930          /* apply offset */
931
932          if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) )
933          {
934            FT_UInt     k = subglyph->arg1;
935            FT_UInt     l = subglyph->arg2;
936            FT_Vector*  p1;
937            FT_Vector*  p2;
938
939
940            if ( start_point + k >= (FT_UInt)num_base_points ||
941                               l >= (FT_UInt)num_new_points  )
942            {
943              error = TT_Err_Invalid_Composite;
944              goto Fail;
945            }
946
947            l += num_base_points;
948
949            p1 = gloader->base.outline.points + start_point + k;
950            p2 = gloader->base.outline.points + start_point + l;
951
952            x = p1->x - p2->x;
953            y = p1->y - p2->y;
954          }
955          else
956          {
957            x = subglyph->arg1;
958            y = subglyph->arg2;
959
960            if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
961            {
962              x = FT_MulFix( x, x_scale );
963              y = FT_MulFix( y, y_scale );
964
965              if ( subglyph->flags & ROUND_XY_TO_GRID )
966              {
967                x = ( x + 32 ) & -64;
968                y = ( y + 32 ) & -64;
969              }
970            }
971          }
972
973          translate_array( num_new_points, loader->zone.cur, x, y );
974          cur_to_org( num_new_points, &loader->zone );
975        }
976
977        /*******************************************************************/
978        /*******************************************************************/
979        /*******************************************************************/
980
981        /* we have finished loading all sub-glyphs; now, look for */
982        /* instructions for this composite!                       */
983
984#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
985
986        if ( num_subglyphs > 0               &&
987             loader->exec                    &&
988             ins_pos         > 0             &&
989             subglyph->flags & WE_HAVE_INSTR )
990        {
991          FT_UShort       n_ins;
992          TT_ExecContext  exec = loader->exec;
993          TT_GlyphZone*   pts;
994          FT_Vector*      pp1;
995
996
997          /* read size of instructions */
998          if ( FILE_Seek( ins_pos ) ||
999               READ_UShort( n_ins ) )
1000            goto Fail;
1001          FT_TRACE5(( "  Instructions size = %d\n", n_ins ));
1002
1003          /* in some fonts? */
1004          if ( n_ins == 0xFFFF )
1005            n_ins = 0;
1006
1007          /* check it */
1008          if ( n_ins > face->max_profile.maxSizeOfInstructions )
1009          {
1010            FT_TRACE0(( "Too many instructions (%d) in composite glyph %ld\n",
1011                        n_ins, subglyph->index ));
1012            return TT_Err_Too_Many_Ins;
1013          }
1014
1015          /* read the instructions */
1016          if ( FILE_Read( exec->glyphIns, n_ins ) )
1017            goto Fail;
1018
1019          glyph->control_data = exec->glyphIns;
1020          glyph->control_len  = n_ins;
1021
1022          error = TT_Set_CodeRange( exec,
1023                                    tt_coderange_glyph,
1024                                    exec->glyphIns,
1025                                    n_ins );
1026          if ( error )
1027            goto Fail;
1028
1029          /* prepare the execution context */
1030          tt_prepare_zone( &exec->pts, &gloader->base,
1031                           start_point, start_contour );
1032          pts = &exec->pts;
1033
1034          pts->n_points   = num_points + 2;
1035          pts->n_contours = gloader->base.outline.n_contours;
1036
1037          /* add phantom points */
1038          pp1    = pts->cur + num_points;
1039          pp1[0] = loader->pp1;
1040          pp1[1] = loader->pp2;
1041
1042          pts->tags[num_points    ] = 0;
1043          pts->tags[num_points + 1] = 0;
1044
1045          /* if hinting, round the phantom points */
1046          if ( IS_HINTED( loader->load_flags ) )
1047          {
1048            pp1[0].x = ( ( loader->pp1.x + 32 ) & -64 );
1049            pp1[1].x = ( ( loader->pp2.x + 32 ) & -64 );
1050          }
1051
1052          {
1053            FT_UInt  k;
1054
1055
1056            for ( k = 0; k < num_points; k++ )
1057              pts->tags[k] &= FT_Curve_Tag_On;
1058          }
1059
1060          cur_to_org( num_points + 2, pts );
1061
1062          /* now consider hinting */
1063          if ( IS_HINTED( loader->load_flags ) && n_ins > 0 )
1064          {
1065            exec->is_composite     = TRUE;
1066            exec->pedantic_hinting =
1067              (FT_Bool)( loader->load_flags & FT_LOAD_PEDANTIC );
1068
1069            error = TT_Run_Context( exec, ((TT_Size)loader->size)->debug );
1070            if ( error && exec->pedantic_hinting )
1071              goto Fail;
1072          }
1073
1074          /* save glyph origin and advance points */
1075          loader->pp1 = pp1[0];
1076          loader->pp2 = pp1[1];
1077        }
1078
1079#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
1080
1081      }
1082      /* end of composite loading */
1083    }
1084
1085    /***********************************************************************/
1086    /***********************************************************************/
1087    /***********************************************************************/
1088
1089  Fail:
1090    if ( opened_frame )
1091      face->forget_glyph_frame( loader );
1092
1093  Exit:
1094    return error;
1095  }
1096
1097
1098  static
1099  void  compute_glyph_metrics( TT_Loader*  loader,
1100                               FT_UInt     glyph_index )
1101  {
1102    FT_BBox       bbox;
1103    TT_Face       face = (TT_Face)loader->face;
1104    FT_Fixed      x_scale, y_scale;
1105    TT_GlyphSlot  glyph = loader->glyph;
1106    TT_Size       size = (TT_Size)loader->size;
1107
1108
1109    x_scale = 0x10000L;
1110    y_scale = 0x10000L;
1111    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )
1112    {
1113      x_scale = size->root.metrics.x_scale;
1114      y_scale = size->root.metrics.y_scale;
1115    }
1116
1117    if ( glyph->format != ft_glyph_format_composite )
1118    {
1119      glyph->outline.flags &= ~ft_outline_single_pass;
1120
1121      /* copy outline to our glyph slot */
1122      FT_GlyphLoader_Copy_Points( glyph->internal->loader, loader->gloader );
1123      glyph->outline = glyph->internal->loader->base.outline;
1124
1125      /* translate array so that (0,0) is the glyph's origin */
1126      FT_Outline_Translate( &glyph->outline, -loader->pp1.x, 0 );
1127
1128      FT_Outline_Get_CBox( &glyph->outline, &bbox );
1129
1130      if ( IS_HINTED( loader->load_flags ) )
1131      {
1132        /* grid-fit the bounding box */
1133        bbox.xMin &= -64;
1134        bbox.yMin &= -64;
1135        bbox.xMax  = ( bbox.xMax + 63 ) & -64;
1136        bbox.yMax  = ( bbox.yMax + 63 ) & -64;
1137      }
1138    }
1139    else
1140      bbox = loader->bbox;
1141
1142    /* get the device-independent horizontal advance.  It is scaled later */
1143    /* by the base layer.                                                 */
1144    {
1145      FT_Pos  advance = loader->advance;
1146
1147
1148      /* the flag FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH was introduced to */
1149      /* correctly support DynaLab fonts, which have an incorrect       */
1150      /* `advance_Width_Max' field!  It is used, to my knowledge,       */
1151      /* exclusively in the X-TrueType font server.                     */
1152      /*                                                                */
1153      if ( face->postscript.isFixedPitch                                    &&
1154           ( loader->load_flags & FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH ) == 0 )
1155        advance = face->horizontal.advance_Width_Max;
1156
1157      /* we need to return the advance in font units in linearHoriAdvance, */
1158      /* it will be scaled later by the base layer.                        */
1159      glyph->linearHoriAdvance = advance;
1160    }
1161
1162    glyph->metrics.horiBearingX = bbox.xMin;
1163    glyph->metrics.horiBearingY = bbox.yMax;
1164    glyph->metrics.horiAdvance  = loader->pp2.x - loader->pp1.x;
1165
1166    /* Now take care of vertical metrics.  In the case where there is    */
1167    /* no vertical information within the font (relatively common), make */
1168    /* up some metrics by `hand'...                                      */
1169
1170    {
1171      FT_Short   top_bearing;    /* vertical top side bearing (EM units) */
1172      FT_UShort  advance_height; /* vertical advance height   (EM units) */
1173
1174      FT_Pos  left;     /* scaled vertical left side bearing         */
1175      FT_Pos  Top;      /* scaled original vertical top side bearing */
1176      FT_Pos  top;      /* scaled vertical top side bearing          */
1177      FT_Pos  advance;  /* scaled vertical advance height            */
1178
1179
1180      /* Get the unscaled `tsb' and `ah' */
1181      if ( face->vertical_info                   &&
1182           face->vertical.number_Of_VMetrics > 0 )
1183      {
1184        /* Don't assume that both the vertical header and vertical */
1185        /* metrics are present in the same font :-)                */
1186
1187        TT_Get_Metrics( (TT_HoriHeader*)&face->vertical,
1188                        glyph_index,
1189                        &top_bearing,
1190                        &advance_height );
1191      }
1192      else
1193      {
1194        /* Make up the distances from the horizontal header.   */
1195
1196        /* NOTE: The OS/2 values are the only `portable' ones, */
1197        /*       which is why we use them, if there is an OS/2 */
1198        /*       table in the font.  Otherwise, we use the     */
1199        /*       values defined in the horizontal header.      */
1200        /*                                                     */
1201        /* NOTE2: The sTypoDescender is negative, which is why */
1202        /*        we compute the baseline-to-baseline distance */
1203        /*        here with:                                   */
1204        /*             ascender - descender + linegap          */
1205        /*                                                     */
1206        if ( face->os2.version != 0xFFFF )
1207        {
1208          top_bearing    = face->os2.sTypoLineGap / 2;
1209          advance_height = (FT_UShort)( face->os2.sTypoAscender -
1210                                        face->os2.sTypoDescender +
1211                                        face->os2.sTypoLineGap );
1212        }
1213        else
1214        {
1215          top_bearing    = face->horizontal.Line_Gap / 2;
1216          advance_height = (FT_UShort)( face->horizontal.Ascender  +
1217                                        face->horizontal.Descender +
1218                                        face->horizontal.Line_Gap );
1219        }
1220      }
1221
1222      /* We must adjust the top_bearing value from the bounding box given */
1223      /* in the glyph header to te bounding box calculated with           */
1224      /* FT_Get_Outline_CBox().                                           */
1225
1226      /* scale the metrics */
1227      if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )
1228      {
1229        Top     = FT_MulFix( top_bearing, y_scale );
1230        top     = FT_MulFix( top_bearing + loader->bbox.yMax, y_scale )
1231                    - bbox.yMax;
1232        advance = FT_MulFix( advance_height, y_scale );
1233      }
1234      else
1235      {
1236        Top     = top_bearing;
1237        top     = top_bearing + loader->bbox.yMax - bbox.yMax;
1238        advance = advance_height;
1239      }
1240
1241      /* set the advance height in design units.  It is scaled later by */
1242      /* the base layer.                                                */
1243      glyph->linearVertAdvance = advance_height;
1244
1245      /* XXX: for now, we have no better algorithm for the lsb, but it */
1246      /*      should work fine.                                        */
1247      /*                                                               */
1248      left = ( bbox.xMin - bbox.xMax ) / 2;
1249
1250      /* grid-fit them if necessary */
1251      if ( IS_HINTED( loader->load_flags ) )
1252      {
1253        left   &= -64;
1254        top     = ( top + 63     ) & -64;
1255        advance = ( advance + 32 ) & -64;
1256      }
1257
1258      glyph->metrics.vertBearingX = left;
1259      glyph->metrics.vertBearingY = top;
1260      glyph->metrics.vertAdvance  = advance;
1261    }
1262
1263    /* adjust advance width to the value contained in the hdmx table */
1264    if ( !face->postscript.isFixedPitch && size &&
1265         IS_HINTED( loader->load_flags )        )
1266    {
1267      FT_Byte* widths = Get_Advance_Widths( face,
1268                                            size->root.metrics.x_ppem );
1269
1270
1271      if ( widths )
1272        glyph->metrics.horiAdvance = widths[glyph_index] << 6;
1273    }
1274
1275    /* set glyph dimensions */
1276    glyph->metrics.width  = bbox.xMax - bbox.xMin;
1277    glyph->metrics.height = bbox.yMax - bbox.yMin;
1278  }
1279
1280
1281  /*************************************************************************/
1282  /*                                                                       */
1283  /* <Function>                                                            */
1284  /*    TT_Load_Glyph                                                      */
1285  /*                                                                       */
1286  /* <Description>                                                         */
1287  /*    A function used to load a single glyph within a given glyph slot,  */
1288  /*    for a given size.                                                  */
1289  /*                                                                       */
1290  /* <Input>                                                               */
1291  /*    glyph       :: A handle to a target slot object where the glyph    */
1292  /*                   will be loaded.                                     */
1293  /*                                                                       */
1294  /*    size        :: A handle to the source face size at which the glyph */
1295  /*                   must be scaled/loaded.                              */
1296  /*                                                                       */
1297  /*    glyph_index :: The index of the glyph in the font file.            */
1298  /*                                                                       */
1299  /*    load_flags  :: A flag indicating what to load for this glyph.  The */
1300  /*                   FT_LOAD_XXX constants can be used to control the    */
1301  /*                   glyph loading process (e.g., whether the outline    */
1302  /*                   should be scaled, whether to load bitmaps or not,   */
1303  /*                   whether to hint the outline, etc).                  */
1304  /*                                                                       */
1305  /* <Return>                                                              */
1306  /*    FreeType error code.  0 means success.                             */
1307  /*                                                                       */
1308  FT_LOCAL_DEF
1309  FT_Error  TT_Load_Glyph( TT_Size       size,
1310                           TT_GlyphSlot  glyph,
1311                           FT_UShort     glyph_index,
1312                           FT_UInt       load_flags )
1313  {
1314    SFNT_Interface*  sfnt;
1315    TT_Face          face;
1316    FT_Stream        stream;
1317    FT_Memory        memory;
1318    FT_Error         error;
1319    TT_Loader        loader;
1320
1321
1322    face   = (TT_Face)glyph->face;
1323    sfnt   = (SFNT_Interface*)face->sfnt;
1324    stream = face->root.stream;
1325    memory = face->root.memory;
1326    error  = 0;
1327
1328    if ( !size || ( load_flags & FT_LOAD_NO_SCALE )   ||
1329                  ( load_flags & FT_LOAD_NO_RECURSE ) )
1330    {
1331      size        = NULL;
1332      load_flags |= FT_LOAD_NO_SCALE   |
1333                    FT_LOAD_NO_HINTING |
1334                    FT_LOAD_NO_BITMAP;
1335    }
1336
1337    glyph->num_subglyphs = 0;
1338
1339#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
1340
1341    /* try to load embedded bitmap if any              */
1342    /*                                                 */
1343    /* XXX: The convention should be emphasized in     */
1344    /*      the documents because it can be confusing. */
1345    if ( size                                    &&
1346         size->strike_index != 0xFFFF            &&
1347         sfnt->load_sbits                        &&
1348         ( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
1349
1350    {
1351      TT_SBit_Metrics  metrics;
1352
1353
1354      error = sfnt->load_sbit_image( face,
1355                                     size->strike_index,
1356                                     glyph_index,
1357                                     load_flags,
1358                                     stream,
1359                                     &glyph->bitmap,
1360                                     &metrics );
1361      if ( !error )
1362      {
1363        glyph->outline.n_points   = 0;
1364        glyph->outline.n_contours = 0;
1365
1366        glyph->metrics.width  = (FT_Pos)metrics.width  << 6;
1367        glyph->metrics.height = (FT_Pos)metrics.height << 6;
1368
1369        glyph->metrics.horiBearingX = (FT_Pos)metrics.horiBearingX << 6;
1370        glyph->metrics.horiBearingY = (FT_Pos)metrics.horiBearingY << 6;
1371        glyph->metrics.horiAdvance  = (FT_Pos)metrics.horiAdvance  << 6;
1372
1373        glyph->metrics.vertBearingX = (FT_Pos)metrics.vertBearingX << 6;
1374        glyph->metrics.vertBearingY = (FT_Pos)metrics.vertBearingY << 6;
1375        glyph->metrics.vertAdvance  = (FT_Pos)metrics.vertAdvance  << 6;
1376
1377        glyph->format = ft_glyph_format_bitmap;
1378        if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
1379        {
1380          glyph->bitmap_left = metrics.vertBearingX;
1381          glyph->bitmap_top  = metrics.vertBearingY;
1382        }
1383        else
1384        {
1385          glyph->bitmap_left = metrics.horiBearingX;
1386          glyph->bitmap_top  = metrics.horiBearingY;
1387        }
1388        return error;
1389      }
1390    }
1391
1392#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */
1393
1394    /* seek to the beginning of the glyph table.  For Type 42 fonts      */
1395    /* the table might be accessed from a Postscript stream or something */
1396    /* else...                                                           */
1397
1398    error = face->goto_table( face, TTAG_glyf, stream, 0 );
1399    if ( error )
1400    {
1401      FT_ERROR(( "TT_Load_Glyph: could not access glyph table\n" ));
1402      goto Exit;
1403    }
1404
1405    MEM_Set( &loader, 0, sizeof ( loader ) );
1406
1407    /* update the glyph zone bounds */
1408    {
1409      FT_GlyphLoader*  gloader = FT_FACE_DRIVER(face)->glyph_loader;
1410
1411
1412      loader.gloader = gloader;
1413
1414      FT_GlyphLoader_Rewind( gloader );
1415
1416      tt_prepare_zone( &loader.zone, &gloader->base, 0, 0 );
1417      tt_prepare_zone( &loader.base, &gloader->base, 0, 0 );
1418    }
1419
1420#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
1421
1422    if ( size )
1423    {
1424      /* query new execution context */
1425      loader.exec = size->debug ? size->context : TT_New_Context( face );
1426      if ( !loader.exec )
1427        return TT_Err_Could_Not_Find_Context;
1428
1429      TT_Load_Context( loader.exec, face, size );
1430      loader.instructions = loader.exec->glyphIns;
1431
1432      /* load default graphics state - if needed */
1433      if ( size->GS.instruct_control & 2 )
1434        loader.exec->GS = tt_default_graphics_state;
1435    }
1436
1437#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
1438
1439    /* clear all outline flags, except the `owner' one */
1440    glyph->outline.flags = 0;
1441
1442    if ( size && size->root.metrics.y_ppem < 24 )
1443      glyph->outline.flags |= ft_outline_high_precision;
1444
1445    /* let's initialize the rest of our loader now */
1446
1447    loader.load_flags    = load_flags;
1448
1449    loader.face   = (FT_Face)face;
1450    loader.size   = (FT_Size)size;
1451    loader.glyph  = (FT_GlyphSlot)glyph;
1452    loader.stream = stream;
1453
1454    loader.glyf_offset  = FILE_Pos();
1455
1456#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
1457
1458    /* if the cvt program has disabled hinting, the argument */
1459    /* is ignored.                                           */
1460    if ( size && ( size->GS.instruct_control & 1 ) )
1461      loader.load_flags |= FT_LOAD_NO_HINTING;
1462
1463#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
1464
1465    /* Main loading loop */
1466    glyph->format        = ft_glyph_format_outline;
1467    glyph->num_subglyphs = 0;
1468    error = load_truetype_glyph( &loader, glyph_index );
1469    if ( !error )
1470      compute_glyph_metrics( &loader, glyph_index );
1471
1472#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
1473
1474    if ( !size || !size->debug )
1475      TT_Done_Context( loader.exec );
1476
1477#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
1478
1479  Exit:
1480    return error;
1481  }
1482
1483
1484/* END */
1485