misc/libfreetype/src/cid/cidgload.c
author sheepluva
Wed, 17 Apr 2013 14:57:56 +0200
branch0.9.19
changeset 8902 a94c074fd483
parent 5172 88f2e05288ba
permissions -rw-r--r--
fix for issue #599: "Change graphics size settings to use qspinbox"? somebody ask unC0Rr if that's what he wanted :p
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
/*  cidgload.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
/*    CID-keyed Type1 Glyph Loader (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 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 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 <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "cidload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include "cidgload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_INTERNAL_CALC_H
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
#include "ciderrs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#define FT_COMPONENT  trace_cidgload
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
  FT_CALLBACK_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  cid_load_glyph( T1_Decoder  decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
                  FT_UInt     glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
    CID_Face       face = (CID_Face)decoder->builder.face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
    CID_FaceInfo   cid  = &face->cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_Byte*       p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
    FT_UInt        fd_select;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    FT_Stream      stream       = face->cid_stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    FT_Error       error        = CID_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    FT_Byte*       charstring   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_Memory      memory       = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    FT_ULong       glyph_length = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    PSAux_Service  psaux        = (PSAux_Service)face->psaux;
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
#ifdef FT_CONFIG_OPTION_INCREMENTAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    FT_Incremental_InterfaceRec *inc =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
                                  face->root.internal->incremental_interface;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
#endif
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    FT_TRACE4(( "cid_load_glyph: glyph index %d\n", glyph_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
#ifdef FT_CONFIG_OPTION_INCREMENTAL
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
    /* For incremental fonts get the character data using */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    /* the callback function.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    if ( inc )
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
      FT_Data  glyph_data;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      error = inc->funcs->get_glyph_data( inc->object,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
                                          glyph_index, &glyph_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      p         = (FT_Byte*)glyph_data.pointer;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
      fd_select = (FT_UInt)cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
      if ( glyph_data.length != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
        glyph_length = glyph_data.length - cid->fd_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
        (void)FT_ALLOC( charstring, glyph_length );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
        if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
          ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
                     glyph_length );
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
      inc->funcs->free_glyph_data( inc->object, &glyph_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    /* For ordinary fonts read the CID font dictionary index */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    /* and charstring offset from the CIDMap.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      FT_UInt   entry_len = cid->fd_bytes + cid->gd_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
      FT_ULong  off1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
      if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
                           glyph_index * entry_len )               ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
           FT_FRAME_ENTER( 2 * entry_len )                         )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      p            = (FT_Byte*)stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
      fd_select    = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      off1         = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      p           += cid->fd_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
      FT_FRAME_EXIT();
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
      if ( fd_select >= (FT_UInt)cid->num_dicts )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
        error = CID_Err_Invalid_Offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      if ( glyph_length == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
      if ( FT_ALLOC( charstring, glyph_length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      if ( FT_STREAM_READ_AT( cid->data_offset + off1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
                              charstring, glyph_length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    /* Now set up the subrs array and parse the charstrings. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      CID_FaceDict  dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
      CID_Subrs     cid_subrs = face->subrs + fd_select;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
      FT_Int        cs_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      /* Set up subrs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      decoder->num_subrs = cid_subrs->num_subrs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
      decoder->subrs     = cid_subrs->code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      decoder->subrs_len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
      /* Set up font matrix */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
      dict                 = cid->font_dicts + fd_select;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      decoder->font_matrix = dict->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      decoder->font_offset = dict->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      decoder->lenIV       = dict->private_dict.lenIV;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
      /* Decode the charstring. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
      /* Adjustment for seed bytes. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 );
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
      /* Decrypt only if lenIV >= 0. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
      if ( decoder->lenIV >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
        psaux->t1_decrypt( charstring, glyph_length, 4330 );
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
      error = decoder->funcs.parse_charstrings(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
                decoder, charstring + cs_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
                (FT_Int)glyph_length - cs_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
    FT_FREE( charstring );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
#ifdef FT_CONFIG_OPTION_INCREMENTAL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    /* Incremental fonts can optionally override the metrics. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    if ( !error && inc && inc->funcs->get_glyph_metrics )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
      FT_Incremental_MetricsRec  metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
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
      metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      metrics.bearing_y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      metrics.advance   = FIXED_TO_INT( decoder->builder.advance.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
      metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
      error = inc->funcs->get_glyph_metrics( inc->object,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
                                             glyph_index, FALSE, &metrics );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
      decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
      decoder->builder.advance.x      = INT_TO_FIXED( metrics.advance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
      decoder->builder.advance.y      = INT_TO_FIXED( metrics.advance_v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
#endif /* FT_CONFIG_OPTION_INCREMENTAL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
#if 0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
  /*************************************************************************/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
  /**********                                                      *********/
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
  /**********            COMPUTE THE MAXIMUM ADVANCE WIDTH         *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
  /**********                                                      *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
  /**********    The following code is in charge of computing      *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  /**********    the maximum advance width of the font.  It        *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
  /**********    quickly processes each glyph charstring to        *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
  /**********    extract the value from either a `sbw' or `seac'   *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
  /**********    operator.                                         *********/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  /**********                                                      *********/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  cid_face_compute_max_advance( CID_Face  face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
                                FT_Int*   max_advance )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    T1_DecoderRec  decoder;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    FT_Int         glyph_index;
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
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
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
    *max_advance = 0;
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
    /* Initialize load decoder */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
    error = psaux->t1_decoder_funcs->init( &decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
                                           (FT_Face)face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
                                           0, /* size       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
                                           0, /* glyph slot */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
                                           0, /* glyph names! XXX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
                                           0, /* blend == 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
                                           0, /* hinting == 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
                                           cid_load_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
    /* TODO: initialize decoder.len_buildchar and decoder.buildchar */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    /*       if we ever support CID-keyed multiple master fonts     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
    decoder.builder.metrics_only = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
    decoder.builder.load_points  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
    /* for each glyph, parse the glyph charstring and extract */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    /* the advance width                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    for ( glyph_index = 0; glyph_index < face->root.num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
          glyph_index++ )
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
      /* now get load the unscaled outline */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      error = cid_load_glyph( &decoder, glyph_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
      /* ignore the error if one occurred - skip to next glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    }
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
    *max_advance = FIXED_TO_INT( decoder.builder.advance.x );
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
    psaux->t1_decoder_funcs->done( &decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
    return CID_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
#endif /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
  cid_slot_load_glyph( FT_GlyphSlot  cidglyph,      /* CID_GlyphSlot */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
                       FT_Size       cidsize,       /* CID_Size      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
                       FT_UInt       glyph_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
                       FT_Int32      load_flags )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
    CID_GlyphSlot  glyph = (CID_GlyphSlot)cidglyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
    T1_DecoderRec  decoder;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    CID_Face       face = (CID_Face)cidglyph->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
    FT_Bool        hinting;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
    PSAux_Service  psaux = (PSAux_Service)face->psaux;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
    FT_Matrix      font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
    FT_Vector      font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
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
    if ( glyph_index >= (FT_UInt)face->root.num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      error = CID_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    }
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
    if ( load_flags & FT_LOAD_NO_RECURSE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
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
    glyph->x_scale = cidsize->metrics.x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
    glyph->y_scale = cidsize->metrics.y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
    cidglyph->outline.n_points   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
    cidglyph->outline.n_contours = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    hinting = FT_BOOL( ( load_flags & FT_LOAD_NO_SCALE   ) == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
                       ( load_flags & FT_LOAD_NO_HINTING ) == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    cidglyph->format = FT_GLYPH_FORMAT_OUTLINE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
    error = psaux->t1_decoder_funcs->init( &decoder,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
                                           cidglyph->face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
                                           cidsize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
                                           cidglyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
                                           0, /* glyph names -- XXX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
                                           0, /* blend == 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
                                           hinting,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
                                           FT_LOAD_TARGET_MODE( load_flags ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
                                           cid_load_glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    /* TODO: initialize decoder.len_buildchar and decoder.buildchar */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    /*       if we ever support CID-keyed multiple master fonts     */
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
    /* set up the decoder */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    decoder.builder.no_recurse = FT_BOOL(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
      ( ( load_flags & FT_LOAD_NO_RECURSE ) != 0 ) );
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
    error = cid_load_glyph( &decoder, glyph_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
      goto Exit;
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
    font_matrix = decoder.font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
    font_offset = decoder.font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    /* save new glyph tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    psaux->t1_decoder_funcs->done( &decoder );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    /* now set the metrics -- this is rather simple, as    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    /* the left side bearing is the xMin, and the top side */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    /* bearing the yMax                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
    cidglyph->outline.flags &= FT_OUTLINE_OWNER;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
    cidglyph->outline.flags |= FT_OUTLINE_REVERSE_FILL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
    /* for composite glyphs, return only left side bearing and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    /* advance width                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    if ( load_flags & FT_LOAD_NO_RECURSE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      FT_Slot_Internal  internal = cidglyph->internal;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      cidglyph->metrics.horiBearingX =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
        FIXED_TO_INT( decoder.builder.left_bearing.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
      cidglyph->metrics.horiAdvance =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
        FIXED_TO_INT( decoder.builder.advance.x );
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
      internal->glyph_matrix      = font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
      internal->glyph_delta       = font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
      internal->glyph_transformed = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
      FT_BBox            cbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
      FT_Glyph_Metrics*  metrics = &cidglyph->metrics;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      FT_Vector          advance;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
      /* copy the _unscaled_ advance width */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      metrics->horiAdvance =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
        FIXED_TO_INT( decoder.builder.advance.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      cidglyph->linearHoriAdvance =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
        FIXED_TO_INT( decoder.builder.advance.x );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
      cidglyph->internal->glyph_transformed = 0;
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
      /* make up vertical ones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
      metrics->vertAdvance        = ( face->cid.font_bbox.yMax -
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
                                      face->cid.font_bbox.yMin ) >> 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
      cidglyph->linearVertAdvance = metrics->vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
      cidglyph->format            = FT_GLYPH_FORMAT_OUTLINE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      if ( cidsize->metrics.y_ppem < 24 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
        cidglyph->outline.flags |= FT_OUTLINE_HIGH_PRECISION;
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
      /* apply the font matrix */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
      FT_Outline_Transform( &cidglyph->outline, &font_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
      FT_Outline_Translate( &cidglyph->outline,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
                            font_offset.x,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
                            font_offset.y );
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
      advance.x = metrics->horiAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
      advance.y = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      FT_Vector_Transform( &advance, &font_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
      metrics->horiAdvance = advance.x + font_offset.x;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
      advance.x = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
      advance.y = metrics->vertAdvance;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
      FT_Vector_Transform( &advance, &font_matrix );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      metrics->vertAdvance = advance.y + font_offset.y;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      if ( ( load_flags & FT_LOAD_NO_SCALE ) == 0 )
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
        /* scale the outline and the metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
        FT_Int       n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
        FT_Outline*  cur = decoder.builder.base;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
        FT_Vector*   vec = cur->points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
        FT_Fixed     x_scale = glyph->x_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
        FT_Fixed     y_scale = glyph->y_scale;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
        /* First of all, scale the points */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
        if ( !hinting || !decoder.builder.hints_funcs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
          for ( n = cur->n_points; n > 0; n--, vec++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
            vec->x = FT_MulFix( vec->x, x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
            vec->y = FT_MulFix( vec->y, y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
        /* Then scale the metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
        metrics->horiAdvance = FT_MulFix( metrics->horiAdvance, x_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
        metrics->vertAdvance = FT_MulFix( metrics->vertAdvance, y_scale );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
      /* compute the other metrics */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      FT_Outline_Get_CBox( &cidglyph->outline, &cbox );
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
      metrics->width  = cbox.xMax - cbox.xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
      metrics->height = cbox.yMax - cbox.yMin;
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
      metrics->horiBearingX = cbox.xMin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      metrics->horiBearingY = cbox.yMax;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      if ( load_flags & FT_LOAD_VERTICAL_LAYOUT ) 
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        /* make up vertical ones */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        ft_synthesize_vertical_metrics( metrics,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
                                        metrics->vertAdvance );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
/* END */