misc/libfreetype/src/cff/cffload.c
author nemo
Sun, 25 Sep 2011 15:40:01 -0400
changeset 6028 335eaf56d976
parent 5172 88f2e05288ba
permissions -rw-r--r--
rename to match prior mass hat rename
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
/*  cffload.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
/*    OpenType and CFF data/program tables 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, 2008, 2009,   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*            2010 by                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_OBJECTS_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_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_TYPE1_TABLES_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 "cffload.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include "cffparse.h"
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
#include "cfferrs.h"
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#if 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
  static const FT_UShort  cff_isoadobe_charset[229] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
      0,   1,   2,   3,   4,   5,   6,   7,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
      8,   9,  10,  11,  12,  13,  14,  15,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
     16,  17,  18,  19,  20,  21,  22,  23,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
     24,  25,  26,  27,  28,  29,  30,  31,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
     32,  33,  34,  35,  36,  37,  38,  39,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
     40,  41,  42,  43,  44,  45,  46,  47,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
     48,  49,  50,  51,  52,  53,  54,  55,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
     56,  57,  58,  59,  60,  61,  62,  63,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
     64,  65,  66,  67,  68,  69,  70,  71,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
     72,  73,  74,  75,  76,  77,  78,  79,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
     80,  81,  82,  83,  84,  85,  86,  87,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
     88,  89,  90,  91,  92,  93,  94,  95,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
     96,  97,  98,  99, 100, 101, 102, 103,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    104, 105, 106, 107, 108, 109, 110, 111,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    112, 113, 114, 115, 116, 117, 118, 119,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    120, 121, 122, 123, 124, 125, 126, 127,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    128, 129, 130, 131, 132, 133, 134, 135,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    136, 137, 138, 139, 140, 141, 142, 143,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    144, 145, 146, 147, 148, 149, 150, 151,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
    152, 153, 154, 155, 156, 157, 158, 159,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    160, 161, 162, 163, 164, 165, 166, 167,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    168, 169, 170, 171, 172, 173, 174, 175,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
    176, 177, 178, 179, 180, 181, 182, 183,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    184, 185, 186, 187, 188, 189, 190, 191,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    192, 193, 194, 195, 196, 197, 198, 199,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    200, 201, 202, 203, 204, 205, 206, 207,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    208, 209, 210, 211, 212, 213, 214, 215,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    216, 217, 218, 219, 220, 221, 222, 223,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    224, 225, 226, 227, 228
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  static const FT_UShort  cff_expert_charset[166] =
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
      0,   1, 229, 230, 231, 232, 233, 234,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    235, 236, 237, 238,  13,  14,  15,  99,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    239, 240, 241, 242, 243, 244, 245, 246,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    247, 248,  27,  28, 249, 250, 251, 252,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    253, 254, 255, 256, 257, 258, 259, 260,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    261, 262, 263, 264, 265, 266, 109, 110,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    267, 268, 269, 270, 271, 272, 273, 274,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    275, 276, 277, 278, 279, 280, 281, 282,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    283, 284, 285, 286, 287, 288, 289, 290,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    291, 292, 293, 294, 295, 296, 297, 298,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    299, 300, 301, 302, 303, 304, 305, 306,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    307, 308, 309, 310, 311, 312, 313, 314,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    315, 316, 317, 318, 158, 155, 163, 319,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    320, 321, 322, 323, 324, 325, 326, 150,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    164, 169, 327, 328, 329, 330, 331, 332,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    333, 334, 335, 336, 337, 338, 339, 340,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    341, 342, 343, 344, 345, 346, 347, 348,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    349, 350, 351, 352, 353, 354, 355, 356,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    357, 358, 359, 360, 361, 362, 363, 364,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    365, 366, 367, 368, 369, 370, 371, 372,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    373, 374, 375, 376, 377, 378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
  };
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 const FT_UShort  cff_expertsubset_charset[87] =
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
      0,   1, 231, 232, 235, 236, 237, 238,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
     13,  14,  15,  99, 239, 240, 241, 242,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    243, 244, 245, 246, 247, 248,  27,  28,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    249, 250, 251, 253, 254, 255, 256, 257,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    258, 259, 260, 261, 262, 263, 264, 265,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    266, 109, 110, 267, 268, 269, 270, 272,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    300, 301, 302, 305, 314, 315, 158, 155,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    163, 320, 321, 322, 323, 324, 325, 326,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    150, 164, 169, 327, 328, 329, 330, 331,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    332, 333, 334, 335, 336, 337, 338, 339,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    340, 341, 342, 343, 344, 345, 346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  };
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
  static const FT_UShort  cff_standard_encoding[256] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
      1,   2,   3,   4,   5,   6,   7,   8,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
      9,  10,  11,  12,  13,  14,  15,  16,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
     17,  18,  19,  20,  21,  22,  23,  24,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
     25,  26,  27,  28,  29,  30,  31,  32,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
     33,  34,  35,  36,  37,  38,  39,  40,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
     41,  42,  43,  44,  45,  46,  47,  48,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
     49,  50,  51,  52,  53,  54,  55,  56,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
     57,  58,  59,  60,  61,  62,  63,  64,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
     65,  66,  67,  68,  69,  70,  71,  72,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
     73,  74,  75,  76,  77,  78,  79,  80,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
     81,  82,  83,  84,  85,  86,  87,  88,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
     89,  90,  91,  92,  93,  94,  95,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
      0,  96,  97,  98,  99, 100, 101, 102,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    103, 104, 105, 106, 107, 108, 109, 110,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
      0, 111, 112, 113, 114,   0, 115, 116,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    117, 118, 119, 120, 121, 122,   0, 123,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      0, 124, 125, 126, 127, 128, 129, 130,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    131,   0, 132, 133,   0, 134, 135, 136,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    137,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
      0, 138,   0, 139,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    140, 141, 142, 143,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
      0, 144,   0,   0,   0, 145,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    146, 147, 148, 149,   0,   0,   0,   0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  };
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
  static const FT_UShort  cff_expert_encoding[256] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
      1, 229, 230,   0, 231, 232, 233, 234,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    235, 236, 237, 238,  13,  14,  15,  99,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    239, 240, 241, 242, 243, 244, 245, 246,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    247, 248,  27,  28, 249, 250, 251, 252,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
      0, 253, 254, 255, 256, 257,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
      0, 258,   0,   0, 259, 260, 261, 262,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      0,   0, 263, 264, 265,   0, 266, 109,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    110, 267, 268, 269,   0, 270, 271, 272,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    273, 274, 275, 276, 277, 278, 279, 280,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    281, 282, 283, 284, 285, 286, 287, 288,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    289, 290, 291, 292, 293, 294, 295, 296,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    297, 298, 299, 300, 301, 302, 303,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      0,   0,   0,   0,   0,   0,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
      0, 304, 305, 306,   0,   0, 307, 308,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    309, 310, 311,   0, 312,   0,   0, 312,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
      0,   0, 314, 315,   0,   0, 316, 317,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
    318,   0,   0,   0, 158, 155, 163, 319,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    320, 321, 322, 323, 324, 325,   0,   0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
    326, 150, 164, 169, 327, 328, 329, 330,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
    331, 332, 333, 334, 335, 336, 337, 338,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    339, 340, 341, 342, 343, 344, 345, 346,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    347, 348, 349, 350, 351, 352, 353, 354,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
    355, 356, 357, 358, 359, 360, 361, 362,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    363, 364, 365, 366, 367, 368, 369, 370,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    371, 372, 373, 374, 375, 376, 377, 378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  };
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
#endif /* 1 */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
  FT_LOCAL_DEF( FT_UShort )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  cff_get_standard_encoding( FT_UInt  charcode )
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
    return (FT_UShort)( charcode < 256 ? cff_standard_encoding[charcode]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
                                       : 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
  /*************************************************************************/
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
  /* 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
   194
  /* 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
   195
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
#define FT_COMPONENT  trace_cffload
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
  /* read an offset from the index's stream current position */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
  static FT_ULong
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
  cff_index_read_offset( CFF_Index  idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
                         FT_Error  *errorp )
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
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
    FT_Stream  stream = idx->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
    FT_Byte    tmp[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
    FT_ULong   result = 0;
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
    if ( !FT_STREAM_READ( tmp, idx->off_size ) )
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
      FT_Int  nn;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
      for ( nn = 0; nn < idx->off_size; nn++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
        result = ( result << 8 ) | tmp[nn];
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
    *errorp = error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    return result;
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
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
  cff_index_init( CFF_Index  idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
                  FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
                  FT_Bool    load )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
    FT_UShort  count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
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
    FT_MEM_ZERO( idx, sizeof ( *idx ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
    idx->stream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
    idx->start  = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    if ( !FT_READ_USHORT( count ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
         count > 0                )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
      FT_Byte   offsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
      FT_ULong  size;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
      /* there is at least one element; read the offset size,           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
      /* then access the offset table to compute the index's total size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
      if ( FT_READ_BYTE( offsize ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
        goto Exit;
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
      if ( offsize < 1 || offsize > 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
        error = CFF_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
      idx->count    = count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
      idx->off_size = offsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      size          = (FT_ULong)( count + 1 ) * offsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      idx->data_offset = idx->start + 3 + size;
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
      if ( FT_STREAM_SKIP( size - offsize ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
        goto Exit;
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
      size = cff_index_read_offset( idx, &error );
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
      if ( size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
        error = CFF_Err_Invalid_Table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
      idx->data_size = --size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      if ( load )
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
        /* load the data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        if ( FT_FRAME_EXTRACT( size, idx->bytes ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
          goto Exit;
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
      else
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
        /* skip the data */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
        if ( FT_STREAM_SKIP( size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
          goto Exit;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      FT_FREE( idx->offsets );
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
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  cff_index_done( CFF_Index  idx )
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 ( idx->stream )
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
      FT_Stream  stream = idx->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      FT_Memory  memory = stream->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      if ( idx->bytes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        FT_FRAME_RELEASE( idx->bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
      FT_FREE( idx->offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
      FT_MEM_ZERO( idx, sizeof ( *idx ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
  cff_index_load_offsets( CFF_Index  idx )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    FT_Error   error  = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    FT_Stream  stream = idx->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    if ( idx->count > 0 && idx->offsets == NULL )
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
      FT_Byte    offsize = idx->off_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
      FT_ULong   data_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      FT_Byte*   p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      FT_Byte*   p_end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      FT_ULong*  poff;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      data_size = (FT_ULong)( idx->count + 1 ) * offsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      if ( FT_NEW_ARRAY( idx->offsets, idx->count + 1 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
           FT_STREAM_SEEK( idx->start + 3 )             ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
           FT_FRAME_ENTER( data_size )                  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
        goto Exit;
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
      poff   = idx->offsets;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      p      = (FT_Byte*)stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      p_end  = p + data_size;
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
      switch ( offsize )
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
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
        for ( ; p < p_end; p++, poff++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
          poff[0] = p[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
        for ( ; p < p_end; p += 2, poff++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
          poff[0] = FT_PEEK_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
      case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        for ( ; p < p_end; p += 3, poff++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
          poff[0] = FT_PEEK_OFF3( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
        for ( ; p < p_end; p += 4, poff++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
          poff[0] = FT_PEEK_ULONG( p );
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
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    }
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
      FT_FREE( idx->offsets );
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
    return error;
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
  /* Allocate a table containing pointers to an index's elements. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
  /* The `pool' argument makes this function convert the index    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
  /* entries to C-style strings (this is, NULL-terminated).       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
  cff_index_get_pointers( CFF_Index   idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
                          FT_Byte***  table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
                          FT_Byte**   pool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    FT_Error   error     = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
    FT_Memory  memory    = idx->stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
    FT_Byte**  t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    FT_Byte*   new_bytes = NULL;
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
    *table = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( idx->offsets == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
      error = cff_index_load_offsets( idx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
        goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
    if ( idx->count > 0                                        &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
         !FT_NEW_ARRAY( t, idx->count + 1 )                    &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
         ( !pool || !FT_ALLOC( new_bytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
                               idx->data_size + idx->count ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
      FT_ULong  n, cur_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
      FT_ULong  extra = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
      FT_Byte*  org_bytes = idx->bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
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
      /* at this point, `idx->offsets' can't be NULL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
      cur_offset = idx->offsets[0] - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      /* sanity check */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
      if ( cur_offset >= idx->data_size )
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
        FT_TRACE0(( "cff_index_get_pointers:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
                    " invalid first offset value %d set to zero\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
                    cur_offset ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
        cur_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
      if ( !pool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
        t[0] = org_bytes + cur_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
        t[0] = new_bytes + cur_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
      for ( n = 1; n <= idx->count; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        FT_ULong  next_offset = idx->offsets[n] - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
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
        /* empty slot + two sanity checks for invalid offset tables */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        if ( next_offset == 0                                    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
             next_offset < cur_offset                            ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
             ( next_offset >= idx->data_size && n < idx->count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
          next_offset = cur_offset;
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
        if ( !pool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
          t[n] = org_bytes + next_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
          t[n] = new_bytes + next_offset + extra;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
          if ( next_offset != cur_offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
            FT_MEM_COPY( t[n - 1], org_bytes + cur_offset, t[n] - t[n - 1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
            t[n][0] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
            t[n]   += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
            extra++;
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
        }
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
        cur_offset = next_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
      *table = t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
      if ( pool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
        *pool = new_bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
  cff_index_access_element( CFF_Index  idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
                            FT_UInt    element,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
                            FT_Byte**  pbytes,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
                            FT_ULong*  pbyte_len )
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
    FT_Error  error = CFF_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
    if ( idx && idx->count > element )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
      /* compute start and end offsets */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
      FT_Stream  stream = idx->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
      FT_ULong   off1, off2 = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
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
      /* load offsets from file or the offset table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
      if ( !idx->offsets )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
        FT_ULong  pos = element * idx->off_size;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
        if ( FT_STREAM_SEEK( idx->start + 3 + pos ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
        off1 = cff_index_read_offset( idx, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
        if ( off1 != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
            element++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
            off2 = cff_index_read_offset( idx, &error );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
          while ( off2 == 0 && element < idx->count );
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
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      else   /* use offsets table */
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
        off1 = idx->offsets[element];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
        if ( off1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
          do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
            element++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
            off2 = idx->offsets[element];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
          } while ( off2 == 0 && element < idx->count );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
        }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
      /* XXX: should check off2 does not exceed the end of this entry; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      /*      at present, only truncate off2 at the end of this stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      if ( off2 > stream->size + 1                    ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
           idx->data_offset > stream->size - off2 + 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
        FT_ERROR(( "cff_index_access_element:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
                   " offset to next entry (%d)"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
                   " exceeds the end of stream (%d)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
                   off2, stream->size - idx->data_offset + 1 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
        off2 = stream->size - idx->data_offset + 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
      /* access element */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      if ( off1 && off2 > off1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
        *pbyte_len = off2 - off1;
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
        if ( idx->bytes )
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
          /* this index was completely loaded in memory, that's easy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
          *pbytes = idx->bytes + off1 - 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
        else
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
          /* this index is still on disk/file, access it through a frame */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
          if ( FT_STREAM_SEEK( idx->data_offset + off1 - 1 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
               FT_FRAME_EXTRACT( off2 - off1, *pbytes )      )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
        /* empty index element */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        *pbytes    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
        *pbyte_len = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  cff_index_forget_element( CFF_Index  idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
                            FT_Byte**  pbytes )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    if ( idx->bytes == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
      FT_Stream  stream = idx->stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
      FT_FRAME_RELEASE( *pbytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
  /* get an entry from Name INDEX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
  FT_LOCAL_DEF( FT_String* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
  cff_index_get_name( CFF_Font  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
                      FT_UInt   element )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
    CFF_Index   idx = &font->name_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    FT_Memory   memory = idx->stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    FT_Byte*    bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    FT_ULong    byte_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    FT_String*  name = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
    error = cff_index_access_element( idx, element, &bytes, &byte_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
    if ( !FT_ALLOC( name, byte_len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
      FT_MEM_COPY( name, bytes, byte_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
      name[byte_len] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    cff_index_forget_element( idx, &bytes );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
    return name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
  /* get an entry from String INDEX */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  FT_LOCAL_DEF( FT_String* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
  cff_index_get_string( CFF_Font  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
                        FT_UInt   element )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
    return ( element < font->num_strings )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
             ? (FT_String*)font->strings[element]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
             : NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
  FT_LOCAL_DEF( FT_String* )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
  cff_index_get_sid_string( CFF_Font  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
                            FT_UInt   sid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
    /* value 0xFFFFU indicates a missing dictionary entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    if ( sid == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    /* if it is not a standard string, return it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
    if ( sid > 390 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
      return cff_index_get_string( font, sid - 391 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    /* CID-keyed CFF fonts don't have glyph names */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    if ( !font->psnames )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
      return NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    /* this is a standard string */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    return (FT_String *)font->psnames->adobe_std_strings( sid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
  /***                                                                   ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
  /***   FD Select table support                                         ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
  /***                                                                   ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
  CFF_Done_FD_Select( CFF_FDSelect  fdselect,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
                      FT_Stream     stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
    if ( fdselect->data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
      FT_FRAME_RELEASE( fdselect->data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
    fdselect->data_size   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
    fdselect->format      = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    fdselect->range_count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
  CFF_Load_FD_Select( CFF_FDSelect  fdselect,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
                      FT_UInt       num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
                      FT_Stream     stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
                      FT_ULong      offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    FT_Error  error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    FT_Byte   format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    FT_UInt   num_ranges;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    /* read format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    if ( FT_STREAM_SEEK( offset ) || FT_READ_BYTE( format ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    fdselect->format      = format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    fdselect->cache_count = 0;   /* clear cache */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    switch ( format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    case 0:     /* format 0, that's simple */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
      fdselect->data_size = num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
      goto Load_Data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    case 3:     /* format 3, a tad more complex */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
      if ( FT_READ_USHORT( num_ranges ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
      fdselect->data_size = num_ranges * 3 + 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
    Load_Data:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
      if ( FT_FRAME_EXTRACT( fdselect->data_size, fdselect->data ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
    default:    /* hmm... that's wrong */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
      error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
  FT_LOCAL_DEF( FT_Byte )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
  cff_fd_select_get( CFF_FDSelect  fdselect,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
                     FT_UInt       glyph_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
    FT_Byte  fd = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
    switch ( fdselect->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
      fd = fdselect->data[glyph_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
    case 3:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
      /* first, compare to cache */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
      if ( (FT_UInt)( glyph_index - fdselect->cache_first ) <
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
                        fdselect->cache_count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
        fd = fdselect->cache_fd;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
      /* then, lookup the ranges array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
        FT_Byte*  p       = fdselect->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
        FT_Byte*  p_limit = p + fdselect->data_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
        FT_Byte   fd2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
        FT_UInt   first, limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
        first = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
        do
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
          if ( glyph_index < first )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
          fd2   = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
          limit = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
          if ( glyph_index < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
            fd = fd2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
            /* update cache */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
            fdselect->cache_first = first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
            fdselect->cache_count = limit-first;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
            fdselect->cache_fd    = fd2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
          first = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
        } while ( p < p_limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
      ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    return fd;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
  /***                                                                   ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
  /***   CFF font support                                                ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
  /***                                                                   ***/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
  cff_charset_compute_cids( CFF_Charset  charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
                            FT_UInt      num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
                            FT_Memory    memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
    FT_Error   error   = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    FT_UInt    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
    FT_Long    j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    FT_UShort  max_cid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    if ( charset->max_cid > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    for ( i = 0; i < num_glyphs; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
      if ( charset->sids[i] > max_cid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
        max_cid = charset->sids[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    if ( FT_NEW_ARRAY( charset->cids, (FT_ULong)max_cid + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    /* When multiple GIDs map to the same CID, we choose the lowest */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    /* GID.  This is not described in any spec, but it matches the  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    /* behaviour of recent Acroread versions.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
    for ( j = num_glyphs - 1; j >= 0 ; j-- )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
      charset->cids[charset->sids[j]] = (FT_UShort)j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
    charset->max_cid    = max_cid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
    charset->num_glyphs = num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  FT_LOCAL_DEF( FT_UInt )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
  cff_charset_cid_to_gindex( CFF_Charset  charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
                             FT_UInt      cid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
    FT_UInt  result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
    if ( cid <= charset->max_cid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
      result = charset->cids[cid];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
  cff_charset_free_cids( CFF_Charset  charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
                         FT_Memory    memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
    FT_FREE( charset->cids );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
    charset->max_cid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
  cff_charset_done( CFF_Charset  charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
                    FT_Stream    stream )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
    cff_charset_free_cids( charset, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
    FT_FREE( charset->sids );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
    charset->format = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    charset->offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
  cff_charset_load( CFF_Charset  charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
                    FT_UInt      num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
                    FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
                    FT_ULong     base_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
                    FT_ULong     offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
                    FT_Bool      invert )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    FT_Error   error  = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
    FT_UShort  glyph_sid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
    /* If the the offset is greater than 2, we have to parse the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
    /* charset table.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
    if ( offset > 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
      FT_UInt  j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
      charset->offset = base_offset + offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
      /* Get the format of the table. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
      if ( FT_STREAM_SEEK( charset->offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
           FT_READ_BYTE( charset->format )   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
      /* Allocate memory for sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
      if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
      /* assign the .notdef glyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      charset->sids[0] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
      switch ( charset->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
        if ( num_glyphs > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
          if ( FT_FRAME_ENTER( ( num_glyphs - 1 ) * 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
          for ( j = 1; j < num_glyphs; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
            charset->sids[j] = FT_GET_USHORT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
          FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
          FT_UInt  nleft;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
          FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
          j = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
          while ( j < num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
            /* Read the first glyph sid of the range. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
            if ( FT_READ_USHORT( glyph_sid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
            /* Read the number of glyphs in the range.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
            if ( charset->format == 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
              if ( FT_READ_USHORT( nleft ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
            else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
              if ( FT_READ_BYTE( nleft ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
            /* try to rescue some of the SIDs if `nleft' is too large */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
            if ( glyph_sid > 0xFFFFL - nleft )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
              FT_ERROR(( "cff_charset_load: invalid SID range trimmed"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
                         " nleft=%d -> %d\n", nleft, 0xFFFFL - glyph_sid ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
              nleft = ( FT_UInt )( 0xFFFFL - glyph_sid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
            /* Fill in the range of sids -- `nleft + 1' glyphs. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
            for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
              charset->sids[j] = glyph_sid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
        FT_ERROR(( "cff_charset_load: invalid table format\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
        error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
      /* Parse default tables corresponding to offset == 0, 1, or 2.  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
      /* CFF specification intimates the following:                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
      /*                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
      /* In order to use a predefined charset, the following must be  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
      /* true: The charset constructed for the glyphs in the font's   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
      /* charstrings dictionary must match the predefined charset in  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
      /* the first num_glyphs.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
      charset->offset = offset;  /* record charset type */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
      switch ( (FT_UInt)offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
      case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
        if ( num_glyphs > 229 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
          FT_ERROR(( "cff_charset_load: implicit charset larger than\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
                     "predefined charset (Adobe ISO-Latin)\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
          error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
        /* Allocate memory for sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
        if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
        /* Copy the predefined charset into the allocated memory. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
        FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
        if ( num_glyphs > 166 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
          FT_ERROR(( "cff_charset_load: implicit charset larger than\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
                     "predefined charset (Adobe Expert)\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
          error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
        /* Allocate memory for sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
        if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
        /* Copy the predefined charset into the allocated memory.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
        FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
      case 2:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
        if ( num_glyphs > 87 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
          FT_ERROR(( "cff_charset_load: implicit charset larger than\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
                     "predefined charset (Adobe Expert Subset)\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
          error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
        /* Allocate memory for sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
        if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
        /* Copy the predefined charset into the allocated memory.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
        FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
        error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
    /* we have to invert the `sids' array for subsetted CID-keyed fonts */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
    if ( invert )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
      error = cff_charset_compute_cids( charset, num_glyphs, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    /* Clean up if there was an error. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
      FT_FREE( charset->sids );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
      FT_FREE( charset->cids );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
      charset->format = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
      charset->offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
      charset->sids   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
  cff_encoding_done( CFF_Encoding  encoding )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
    encoding->format = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    encoding->offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
    encoding->count  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
  cff_encoding_load( CFF_Encoding  encoding,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
                     CFF_Charset   charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
                     FT_UInt       num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
                     FT_Stream     stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
                     FT_ULong      base_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
                     FT_ULong      offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
    FT_Error   error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
    FT_UInt    count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
    FT_UInt    j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
    FT_UShort  glyph_sid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
    FT_UInt    glyph_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
    /* Check for charset->sids.  If we do not have this, we fail. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
    if ( !charset->sids )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
      error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
    /* Zero out the code to gid/sid mappings. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
    for ( j = 0; j < 256; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
      encoding->sids [j] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
      encoding->codes[j] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
    /* Note: The encoding table in a CFF font is indexed by glyph index;  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
    /* the first encoded glyph index is 1.  Hence, we read the character  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
    /* code (`glyph_code') at index j and make the assignment:            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
    /*    encoding->codes[glyph_code] = j + 1                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
    /* We also make the assignment:                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
    /*    encoding->sids[glyph_code] = charset->sids[j + 1]               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
    /*                                                                    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
    /* This gives us both a code to GID and a code to SID mapping.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
    if ( offset > 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
      encoding->offset = base_offset + offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
      /* we need to parse the table to determine its size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
      if ( FT_STREAM_SEEK( encoding->offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
           FT_READ_BYTE( encoding->format )   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
           FT_READ_BYTE( count )              )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
      switch ( encoding->format & 0x7F )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
      case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
          FT_Byte*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
          /* By convention, GID 0 is always ".notdef" and is never */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
          /* coded in the font.  Hence, the number of codes found  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
          /* in the table is `count+1'.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
          /*                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
          encoding->count = count + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
          if ( FT_FRAME_ENTER( count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
          p = (FT_Byte*)stream->cursor;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
          for ( j = 1; j <= count; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
            glyph_code = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
            /* Make sure j is not too big. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
            if ( j < num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
              /* Assign code to GID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
              encoding->codes[glyph_code] = (FT_UShort)j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
              /* Assign code to SID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
              encoding->sids[glyph_code] = charset->sids[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
          FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
          FT_UInt  nleft;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
          FT_UInt  i = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
          FT_UInt  k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
          encoding->count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
          /* Parse the Format1 ranges. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
          for ( j = 0;  j < count; j++, i += nleft )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
            /* Read the first glyph code of the range. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
            if ( FT_READ_BYTE( glyph_code ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
            /* Read the number of codes in the range. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
            if ( FT_READ_BYTE( nleft ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
            /* Increment nleft, so we read `nleft + 1' codes/sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
            nleft++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
            /* compute max number of character codes */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
            if ( (FT_UInt)nleft > encoding->count )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
              encoding->count = nleft;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
            /* Fill in the range of codes/sids. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
            for ( k = i; k < nleft + i; k++, glyph_code++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
              /* Make sure k is not too big. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
              if ( k < num_glyphs && glyph_code < 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
                /* Assign code to GID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
                encoding->codes[glyph_code] = (FT_UShort)k;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
                /* Assign code to SID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
                encoding->sids[glyph_code] = charset->sids[k];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
          /* simple check; one never knows what can be found in a font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
          if ( encoding->count > 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
            encoding->count = 256;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
        FT_ERROR(( "cff_encoding_load: invalid table format\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
        error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
      /* Parse supplemental encodings, if any. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
      if ( encoding->format & 0x80 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
        FT_UInt  gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
        /* count supplements */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
        if ( FT_READ_BYTE( count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
        for ( j = 0; j < count; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
          /* Read supplemental glyph code. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
          if ( FT_READ_BYTE( glyph_code ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
          /* Read the SID associated with this glyph code. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
          if ( FT_READ_USHORT( glyph_sid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
          /* Assign code to SID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
          encoding->sids[glyph_code] = glyph_sid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
          /* First, look up GID which has been assigned to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
          /* SID glyph_sid.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
          for ( gindex = 0; gindex < num_glyphs; gindex++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
            if ( charset->sids[gindex] == glyph_sid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
              encoding->codes[glyph_code] = (FT_UShort)gindex;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
      /* We take into account the fact a CFF font can use a predefined */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
      /* encoding without containing all of the glyphs encoded by this */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
      /* encoding (see the note at the end of section 12 in the CFF    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
      /* specification).                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
      switch ( (FT_UInt)offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
      case 0:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
        /* First, copy the code to SID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
        FT_ARRAY_COPY( encoding->sids, cff_standard_encoding, 256 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
        goto Populate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
      case 1:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
        /* First, copy the code to SID mapping. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
        FT_ARRAY_COPY( encoding->sids, cff_expert_encoding, 256 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
      Populate:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
        /* Construct code to GID mapping from code to SID mapping */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
        /* and charset.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
        encoding->count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
        error = cff_charset_compute_cids( charset, num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
                                          stream->memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
        for ( j = 0; j < 256; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
          FT_UInt  sid = encoding->sids[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
          FT_UInt  gid = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
          if ( sid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
            gid = cff_charset_cid_to_gindex( charset, sid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
          if ( gid != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
            encoding->codes[j] = (FT_UShort)gid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
            encoding->count    = j + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
            encoding->codes[j] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
            encoding->sids [j] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
        FT_ERROR(( "cff_encoding_load: invalid table format\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
        error = CFF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
    /* Clean up if there was an error. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
  cff_subfont_load( CFF_SubFont  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
                    CFF_Index    idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
                    FT_UInt      font_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
                    FT_Stream    stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
                    FT_ULong     base_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
                    FT_Library   library )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
    CFF_ParserRec    parser;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
    FT_Byte*         dict = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
    FT_ULong         dict_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
    CFF_FontRecDict  top  = &font->font_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
    CFF_Private      priv = &font->private_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
    cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict, library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
    /* set defaults */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
    FT_MEM_ZERO( top, sizeof ( *top ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
    top->underline_position  = -100L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
    top->underline_thickness = 50L << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
    top->charstring_type     = 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
    top->font_matrix.xx      = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
    top->font_matrix.yy      = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
    top->cid_count           = 8720;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
    /* we use the implementation specific SID value 0xFFFF to indicate */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
    /* missing entries                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
    top->version             = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
    top->notice              = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
    top->copyright           = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
    top->full_name           = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
    top->family_name         = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
    top->weight              = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
    top->embedded_postscript = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
    top->cid_registry        = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
    top->cid_ordering        = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
    top->cid_font_name       = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
    error = cff_index_access_element( idx, font_index, &dict, &dict_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
    if ( !error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
      error = cff_parser_run( &parser, dict, dict + dict_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
    cff_index_forget_element( idx, &dict );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    /* if it is a CID font, we stop there */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
    if ( top->cid_registry != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
    /* parse the private dictionary, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
    if ( top->private_offset && top->private_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
      /* set defaults */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
      FT_MEM_ZERO( priv, sizeof ( *priv ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
      priv->blue_shift       = 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
      priv->blue_fuzz        = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
      priv->lenIV            = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
      priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
      priv->blue_scale       = (FT_Fixed)( 0.039625 * 0x10000L * 1000 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
      cff_parser_init( &parser, CFF_CODE_PRIVATE, priv, library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
      if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
           FT_FRAME_ENTER( font->font_dict.private_size )                 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
      error = cff_parser_run( &parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
                              (FT_Byte*)stream->cursor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
                              (FT_Byte*)stream->limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
      /* ensure that `num_blue_values' is even */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
      priv->num_blue_values &= ~1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    /* read the local subrs, if any */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
    if ( priv->local_subrs_offset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
      if ( FT_STREAM_SEEK( base_offset + top->private_offset +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
                           priv->local_subrs_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
      error = cff_index_init( &font->local_subrs_index, stream, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
      error = cff_index_get_pointers( &font->local_subrs_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
                                      &font->local_subrs, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
  cff_subfont_done( FT_Memory    memory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
                    CFF_SubFont  subfont )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
    if ( subfont )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
      cff_index_done( &subfont->local_subrs_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
      FT_FREE( subfont->local_subrs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
  cff_font_load( FT_Library library,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
                 FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
                 FT_Int     face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
                 CFF_Font   font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
                 FT_Bool    pure_cff )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
    static const FT_Frame_Field  cff_header_fields[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
#undef  FT_STRUCTURE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
#define FT_STRUCTURE  CFF_FontRec
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
      FT_FRAME_START( 4 ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
        FT_FRAME_BYTE( version_major ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
        FT_FRAME_BYTE( version_minor ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
        FT_FRAME_BYTE( header_size ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
        FT_FRAME_BYTE( absolute_offsize ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
      FT_FRAME_END
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
    FT_Memory        memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
    FT_ULong         base_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
    CFF_FontRecDict  dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
    CFF_IndexRec     string_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
    FT_ZERO( font );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
    FT_ZERO( &string_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
    font->stream = stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
    font->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    dict         = &font->top_font.font_dict;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
    base_offset  = FT_STREAM_POS();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    /* read CFF font header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
    if ( FT_STREAM_READ_FIELDS( cff_header_fields, font ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
    /* check format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
    if ( font->version_major   != 1 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
         font->header_size      < 4 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
         font->absolute_offsize > 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
      FT_TRACE2(( "[not a CFF font header]\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
      error = CFF_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
    /* skip the rest of the header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
    if ( FT_STREAM_SKIP( font->header_size - 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
    /* read the name, top dict, string and global subrs index */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
    if ( FT_SET_ERROR( cff_index_init( &font->name_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
                                       stream, 0 ) )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
         FT_SET_ERROR( cff_index_init( &font->font_dict_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
                                       stream, 0 ) )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
         FT_SET_ERROR( cff_index_init( &string_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
                                       stream, 1 ) )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
         FT_SET_ERROR( cff_index_init( &font->global_subrs_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
                                       stream, 1 ) )                  ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
         FT_SET_ERROR( cff_index_get_pointers( &string_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
                                               &font->strings,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
                                               &font->string_pool ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
    font->num_strings = string_index.count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
    /* well, we don't really forget the `disabled' fonts... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
    font->num_faces = font->name_index.count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
    if ( face_index >= (FT_Int)font->num_faces )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
      FT_ERROR(( "cff_font_load: incorrect face index = %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
                 face_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
      error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
    /* in case of a font format check, simply exit now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
    if ( face_index < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
    /* now, parse the top-level font dictionary */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
    error = cff_subfont_load( &font->top_font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
                              &font->font_dict_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
                              face_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
                              stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
                              base_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
                              library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
    if ( FT_STREAM_SEEK( base_offset + dict->charstrings_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
    error = cff_index_init( &font->charstrings_index, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
    /* now, check for a CID font */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
    if ( dict->cid_registry != 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
      CFF_IndexRec  fd_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
      CFF_SubFont   sub;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
      FT_UInt       idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
      /* this is a CID-keyed font, we must now allocate a table of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
      /* sub-fonts, then load each of them separately              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
      if ( FT_STREAM_SEEK( base_offset + dict->cid_fd_array_offset ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
      error = cff_index_init( &fd_index, stream, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
      if ( fd_index.count > CFF_MAX_CID_FONTS )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
        FT_TRACE0(( "cff_font_load: FD array too large in CID font\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
        goto Fail_CID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
      /* allocate & read each font dict independently */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
      font->num_subfonts = fd_index.count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
      if ( FT_NEW_ARRAY( sub, fd_index.count ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
        goto Fail_CID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
      /* set up pointer table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
      for ( idx = 0; idx < fd_index.count; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
        font->subfonts[idx] = sub + idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
      /* now load each subfont independently */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
      for ( idx = 0; idx < fd_index.count; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
        sub = font->subfonts[idx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
        error = cff_subfont_load( sub, &fd_index, idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
                                  stream, base_offset, library );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
          goto Fail_CID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
      /* now load the FD Select array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
      error = CFF_Load_FD_Select( &font->fd_select,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
                                  font->charstrings_index.count,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
                                  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
                                  base_offset + dict->cid_fd_select_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
    Fail_CID:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
      cff_index_done( &fd_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
      font->num_subfonts = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
    /* read the charstrings index now */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
    if ( dict->charstrings_offset == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
      FT_ERROR(( "cff_font_load: no charstrings offset\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
      error = CFF_Err_Unknown_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
    font->num_glyphs = font->charstrings_index.count;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
    error = cff_index_get_pointers( &font->global_subrs_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
                                    &font->global_subrs, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
    /* read the Charset and Encoding tables if available */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
    if ( font->num_glyphs > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
      FT_Bool  invert = FT_BOOL( dict->cid_registry != 0xFFFFU && pure_cff );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
      error = cff_charset_load( &font->charset, font->num_glyphs, stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
                                base_offset, dict->charset_offset, invert );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
      /* CID-keyed CFFs don't have an encoding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
      if ( dict->cid_registry == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
        error = cff_encoding_load( &font->encoding,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
                                   &font->charset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
                                   font->num_glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
                                   stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
                                   base_offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
                                   dict->encoding_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
    /* get the font name (/CIDFontName for CID-keyed fonts, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
    /* /FontName otherwise)                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
    font->font_name = cff_index_get_name( font, face_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
    cff_index_done( &string_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
  cff_font_done( CFF_Font  font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
    FT_Memory  memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
    FT_UInt    idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
    cff_index_done( &font->global_subrs_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
    cff_index_done( &font->font_dict_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
    cff_index_done( &font->name_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
    cff_index_done( &font->charstrings_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
    /* release font dictionaries, but only if working with */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
    /* a CID keyed CFF font                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
    if ( font->num_subfonts > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
      for ( idx = 0; idx < font->num_subfonts; idx++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
        cff_subfont_done( memory, font->subfonts[idx] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
      /* the subfonts array has been allocated as a single block */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
      FT_FREE( font->subfonts[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
    cff_encoding_done( &font->encoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
    cff_charset_done( &font->charset, font->stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
    cff_subfont_done( memory, &font->top_font );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
    CFF_Done_FD_Select( &font->fd_select, font->stream );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
    FT_FREE( font->font_info );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
    FT_FREE( font->font_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
    FT_FREE( font->global_subrs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
    FT_FREE( font->strings );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
    FT_FREE( font->string_pool );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
/* END */