misc/libfreetype/src/autofit/afloader.c
author nemo
Sun, 11 Sep 2011 10:46:53 -0400
changeset 5856 ed97138dc414
parent 5172 88f2e05288ba
permissions -rw-r--r--
Should prevent a crasher when drowning while firing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  afloader.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    Auto-fitter glyph loading routines (body).                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 2003-2009, 2011 by                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include "afloader.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "afhints.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "afglobal.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include "aferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /* Initialize glyph loader. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  af_loader_init( AF_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
                  FT_Memory  memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
    FT_ZERO( loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
    af_glyph_hints_init( &loader->hints, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#ifdef FT_DEBUG_AUTOFIT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
    _af_debug_hints = &loader->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
    return FT_GlyphLoader_New( memory, &loader->gloader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /* Reset glyph loader and compute globals if necessary. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  af_loader_reset( AF_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
                   FT_Face    face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_Error  error = AF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    loader->face    = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    loader->globals = (AF_FaceGlobals)face->autohint.data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    FT_GlyphLoader_Rewind( loader->gloader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    if ( loader->globals == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
      error = af_face_globals_new( face, &loader->globals );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
        face->autohint.data =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
          (FT_Pointer)loader->globals;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
        face->autohint.finalizer =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
          (FT_Generic_Finalizer)af_face_globals_free;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /* Finalize glyph loader. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  af_loader_done( AF_Loader  loader )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    af_glyph_hints_done( &loader->hints );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    loader->face    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    loader->globals = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
#ifdef FT_DEBUG_AUTOFIT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    _af_debug_hints = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    FT_GlyphLoader_Done( loader->gloader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    loader->gloader = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  /* Load a single glyph component.  This routine calls itself */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  /* recursively, if necessary, and does the main work of      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  /* `af_loader_load_glyph.'                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
  af_loader_load_g( AF_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
                    AF_Scaler  scaler,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
                    FT_UInt    glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
                    FT_Int32   load_flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
                    FT_UInt    depth )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    FT_Error          error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    FT_Face           face     = loader->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    FT_GlyphLoader    gloader  = loader->gloader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    AF_ScriptMetrics  metrics  = loader->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    AF_GlyphHints     hints    = &loader->hints;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    FT_GlyphSlot      slot     = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    FT_Slot_Internal  internal = slot->internal;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    error = FT_Load_Glyph( face, glyph_index, load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    loader->transformed = internal->glyph_transformed;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    if ( loader->transformed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      FT_Matrix  inverse;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      loader->trans_matrix = internal->glyph_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
      loader->trans_delta  = internal->glyph_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      inverse = loader->trans_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      FT_Matrix_Invert( &inverse );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
      FT_Vector_Transform( &loader->trans_delta, &inverse );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    /* set linear metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    slot->linearHoriAdvance = slot->metrics.horiAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    slot->linearVertAdvance = slot->metrics.vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    switch ( slot->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    case FT_GLYPH_FORMAT_OUTLINE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      /* translate the loaded glyph when an internal transform is needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      if ( loader->transformed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
        FT_Outline_Translate( &slot->outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
                              loader->trans_delta.x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
                              loader->trans_delta.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      /* copy the outline points in the loader's current               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      /* extra points which is used to keep original glyph coordinates */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      error = FT_GLYPHLOADER_CHECK_POINTS( gloader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
                                           slot->outline.n_points + 4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
                                           slot->outline.n_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      FT_ARRAY_COPY( gloader->current.outline.points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
                     slot->outline.points,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
                     slot->outline.n_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
      FT_ARRAY_COPY( gloader->current.outline.contours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
                     slot->outline.contours,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
                     slot->outline.n_contours );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      FT_ARRAY_COPY( gloader->current.outline.tags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
                     slot->outline.tags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
                     slot->outline.n_points );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
      gloader->current.outline.n_points   = slot->outline.n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
      gloader->current.outline.n_contours = slot->outline.n_contours;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      /* compute original horizontal phantom points (and ignore */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      /* vertical ones)                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      loader->pp1.x = hints->x_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      loader->pp1.y = hints->y_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      loader->pp2.x = FT_MulFix( slot->metrics.horiAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
                                 hints->x_scale ) + hints->x_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
      loader->pp2.y = hints->y_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      /* be sure to check for spacing glyphs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      if ( slot->outline.n_points == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
        goto Hint_Metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      /* now load the slot image into the auto-outline and run the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      /* automatic hinting process                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      if ( metrics->clazz->script_hints_apply )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
        metrics->clazz->script_hints_apply( hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
                                            &gloader->current.outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
                                            metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      /* we now need to adjust the metrics according to the change in */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
      /* width/positioning that occurred during the hinting process   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
      if ( scaler->render_mode != FT_RENDER_MODE_LIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
        FT_Pos        old_rsb, old_lsb, new_lsb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
        FT_Pos        pp1x_uh, pp2x_uh;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
        AF_AxisHints  axis  = &hints->axis[AF_DIMENSION_HORZ];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
        AF_Edge       edge1 = axis->edges;         /* leftmost edge  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
        AF_Edge       edge2 = edge1 +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
                              axis->num_edges - 1; /* rightmost edge */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
        if ( axis->num_edges > 1 && AF_HINTS_DO_ADVANCE( hints ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
          old_rsb = loader->pp2.x - edge2->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
          old_lsb = edge1->opos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
          new_lsb = edge1->pos;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
          /* remember unhinted values to later account */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
          /* for rounding errors                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
          pp1x_uh = new_lsb    - old_lsb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
          pp2x_uh = edge2->pos + old_rsb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          /* prefer too much space over too little space */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
          /* for very small sizes                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
          if ( old_lsb < 24 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
            pp1x_uh -= 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
          if ( old_rsb < 24 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
            pp2x_uh += 8;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
          loader->pp1.x = FT_PIX_ROUND( pp1x_uh );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
          loader->pp2.x = FT_PIX_ROUND( pp2x_uh );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
          if ( loader->pp1.x >= new_lsb && old_lsb > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
            loader->pp1.x -= 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
          if ( loader->pp2.x <= edge2->pos && old_rsb > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
            loader->pp2.x += 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
          slot->lsb_delta = loader->pp1.x - pp1x_uh;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
          slot->rsb_delta = loader->pp2.x - pp2x_uh;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
          FT_Pos  pp1x = loader->pp1.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
          FT_Pos  pp2x = loader->pp2.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
          loader->pp1.x = FT_PIX_ROUND( pp1x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
          loader->pp2.x = FT_PIX_ROUND( pp2x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
          slot->lsb_delta = loader->pp1.x - pp1x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
          slot->rsb_delta = loader->pp2.x - pp2x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
        FT_Pos  pp1x = loader->pp1.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
        FT_Pos  pp2x = loader->pp2.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
        loader->pp1.x = FT_PIX_ROUND( pp1x + hints->xmin_delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
        loader->pp2.x = FT_PIX_ROUND( pp2x + hints->xmax_delta );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
        slot->lsb_delta = loader->pp1.x - pp1x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
        slot->rsb_delta = loader->pp2.x - pp2x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      /* good, we simply add the glyph to our loader's base */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      FT_GlyphLoader_Add( gloader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
    case FT_GLYPH_FORMAT_COMPOSITE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
        FT_UInt      nn, num_subglyphs = slot->num_subglyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
        FT_UInt      num_base_subgs, start_point;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
        FT_SubGlyph  subglyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
        start_point = gloader->base.outline.n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
        /* first of all, copy the subglyph descriptors in the glyph loader */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
        error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
        FT_ARRAY_COPY( gloader->current.subglyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                       slot->subglyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
                       num_subglyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        gloader->current.num_subglyphs = num_subglyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        num_base_subgs                 = gloader->base.num_subglyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
        /* now read each subglyph independently */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
        for ( nn = 0; nn < num_subglyphs; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
          FT_Vector  pp1, pp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
          FT_Pos     x, y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
          FT_UInt    num_points, num_new_points, num_base_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
          /* gloader.current.subglyphs can change during glyph loading due */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
          /* to re-allocation -- we must recompute the current subglyph on */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
          /* each iteration                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
          subglyph = gloader->base.subglyphs + num_base_subgs + nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
          pp1 = loader->pp1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
          pp2 = loader->pp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
          num_base_points = gloader->base.outline.n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
          error = af_loader_load_g( loader, scaler, subglyph->index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
                                    load_flags, depth + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
          /* recompute subglyph pointer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
          subglyph = gloader->base.subglyphs + num_base_subgs + nn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
          if ( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
            pp1 = loader->pp1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
            pp2 = loader->pp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
            loader->pp1 = pp1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
            loader->pp2 = pp2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
          num_points     = gloader->base.outline.n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
          num_new_points = num_points - num_base_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
          /* now perform the transformation required for this subglyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
          if ( subglyph->flags & ( FT_SUBGLYPH_FLAG_SCALE    |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
                                   FT_SUBGLYPH_FLAG_XY_SCALE |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
                                   FT_SUBGLYPH_FLAG_2X2      ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
            FT_Vector*  cur   = gloader->base.outline.points +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
                                num_base_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
            FT_Vector*  limit = cur + num_new_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
            for ( ; cur < limit; cur++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
              FT_Vector_Transform( cur, &subglyph->transform );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
          /* apply offset */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
          if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
            FT_Int      k = subglyph->arg1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
            FT_UInt     l = subglyph->arg2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
            FT_Vector*  p1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
            FT_Vector*  p2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
            if ( start_point + k >= num_base_points         ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
                               l >= (FT_UInt)num_new_points )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
              error = AF_Err_Invalid_Composite;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
            l += num_base_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
            /* for now, only use the current point coordinates;    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
            /* we may consider another approach in the near future */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
            p1 = gloader->base.outline.points + start_point + k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
            p2 = gloader->base.outline.points + start_point + l;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
            x = p1->x - p2->x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
            y = p1->y - p2->y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
            x = FT_MulFix( subglyph->arg1, hints->x_scale ) + hints->x_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
            y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
            x = FT_PIX_ROUND( x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
            y = FT_PIX_ROUND( y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
            FT_Outline  dummy = gloader->base.outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
            dummy.points  += num_base_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
            dummy.n_points = (short)num_new_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
            FT_Outline_Translate( &dummy, x, y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      /* we don't support other formats (yet?) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      error = AF_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  Hint_Metrics:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    if ( depth == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      FT_BBox    bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
      FT_Vector  vvector;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      vvector.y = slot->metrics.vertBearingY - slot->metrics.horiBearingY;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      vvector.x = FT_MulFix( vvector.x, metrics->scaler.x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      vvector.y = FT_MulFix( vvector.y, metrics->scaler.y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      /* transform the hinted outline if needed */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
      if ( loader->transformed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        FT_Outline_Transform( &gloader->base.outline, &loader->trans_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
        FT_Vector_Transform( &vvector, &loader->trans_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
      /* we must translate our final outline by -pp1.x and compute */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      /* the new metrics                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      if ( loader->pp1.x )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
        FT_Outline_Translate( &gloader->base.outline, -loader->pp1.x, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      FT_Outline_Get_CBox( &gloader->base.outline, &bbox );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
      bbox.xMin = FT_PIX_FLOOR( bbox.xMin );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
      bbox.yMin = FT_PIX_FLOOR( bbox.yMin );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
      bbox.xMax = FT_PIX_CEIL(  bbox.xMax );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      bbox.yMax = FT_PIX_CEIL(  bbox.yMax );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      slot->metrics.width        = bbox.xMax - bbox.xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      slot->metrics.height       = bbox.yMax - bbox.yMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
      slot->metrics.horiBearingX = bbox.xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      slot->metrics.horiBearingY = bbox.yMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      slot->metrics.vertBearingX = FT_PIX_FLOOR( bbox.xMin + vvector.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      slot->metrics.vertBearingY = FT_PIX_FLOOR( bbox.yMax + vvector.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      /* for mono-width fonts (like Andale, Courier, etc.) we need */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      /* to keep the original rounded advance width; ditto for     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      /* digits if all have the same advance width                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      if ( !FT_IS_FIXED_WIDTH( slot->face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
                                               x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
#else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      if ( FT_IS_FIXED_WIDTH( slot->face )                              ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
           ( af_face_globals_is_digit( loader->globals, glyph_index ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
             metrics->digits_have_same_width                          ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
                                               metrics->scaler.x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        /* Set delta values to 0.  Otherwise code that uses them is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        /* going to ruin the fixed advance width.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        slot->lsb_delta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
        slot->rsb_delta = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
        /* non-spacing glyphs must stay as-is */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        if ( slot->metrics.horiAdvance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
          slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
      slot->metrics.vertAdvance = FT_MulFix( slot->metrics.vertAdvance,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
                                             metrics->scaler.y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
      slot->metrics.horiAdvance = FT_PIX_ROUND( slot->metrics.horiAdvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
      slot->metrics.vertAdvance = FT_PIX_ROUND( slot->metrics.vertAdvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
      /* now copy outline into glyph slot */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
      FT_GlyphLoader_Rewind( internal->loader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
      error = FT_GlyphLoader_CopyPoints( internal->loader, gloader );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      slot->outline = internal->loader->base.outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      slot->format  = FT_GLYPH_FORMAT_OUTLINE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
  /* Load a glyph. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
  af_loader_load_glyph( AF_Loader  loader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
                        FT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
                        FT_UInt    gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
                        FT_UInt32  load_flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    FT_Size       size = face->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    AF_ScalerRec  scaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    if ( !size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      return AF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    FT_ZERO( &scaler );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    scaler.face    = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    scaler.x_scale = size->metrics.x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    scaler.x_delta = 0;  /* XXX: TODO: add support for sub-pixel hinting */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
    scaler.y_scale = size->metrics.y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    scaler.y_delta = 0;  /* XXX: TODO: add support for sub-pixel hinting */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    scaler.render_mode = FT_LOAD_TARGET_MODE( load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
    scaler.flags       = 0;  /* XXX: fix this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    error = af_loader_reset( loader, face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
      AF_ScriptMetrics  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      FT_UInt           options = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
#ifdef FT_OPTION_AUTOFIT2
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
      /* XXX: undocumented hook to activate the latin2 hinter */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
      if ( load_flags & ( 1UL << 20 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
        options = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      error = af_face_globals_get_metrics( loader->globals, gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
                                           options, &metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
        loader->metrics = metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
        if ( metrics->clazz->script_metrics_scale )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
          metrics->clazz->script_metrics_scale( metrics, &scaler );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
          metrics->scaler = scaler;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
        load_flags |=  FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
        load_flags &= ~FT_LOAD_RENDER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
        if ( metrics->clazz->script_hints_init )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
          error = metrics->clazz->script_hints_init( &loader->hints,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
                                                     metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
        error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
/* END */