misc/libfreetype/src/sfnt/ttpost.c
author koda
Wed, 19 Dec 2012 18:17:23 +0100
changeset 8312 9e8781faabab
parent 5172 88f2e05288ba
permissions -rw-r--r--
can compile engine as library on linux but not run the executable (automatically), most likely breaking other platforms (wrt engine-as-library)
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
/*  ttpost.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
/*    Postcript name table processing for TrueType and OpenType fonts      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*    (body).                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  Copyright 1996-2001, 2002, 2003, 2006, 2007, 2008, 2009, 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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
  /* The post table is not completely loaded by the core engine.  This     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
  /* file loads the missing PS glyph names and implements an API to access */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
  /* them.                                                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
#include FT_TRUETYPE_TAGS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#include "ttpost.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#include "sferrors.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
  /* 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
    40
  /* 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
    41
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
#define FT_COMPONENT  trace_ttpost
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
  /* If this configuration macro is defined, we rely on the `PSNames' */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
  /* module to grab the glyph names.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
#define MAC_NAME( x )  ( (FT_String*)psnames->macintosh_name( x ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
#else /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
   /* Otherwise, we ignore the `PSNames' module, and provide our own  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
   /* table of Mac names.  Thus, it is possible to build a version of */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
   /* FreeType without the Type 1 driver & PSNames module.            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
#define MAC_NAME( x )  ( (FT_String*)tt_post_default_names[x] )
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
  /* the 258 default Mac PS glyph names */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
  static const FT_String* const  tt_post_default_names[258] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    /*   0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    ".notdef", ".null", "CR", "space", "exclam",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    "quotedbl", "numbersign", "dollar", "percent", "ampersand",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    /*  10 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    "quotesingle", "parenleft", "parenright", "asterisk", "plus",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    "comma", "hyphen", "period", "slash", "zero",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    /*  20 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    "one", "two", "three", "four", "five",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    "six", "seven", "eight", "nine", "colon",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    /*  30 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    "semicolon", "less", "equal", "greater", "question",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    "at", "A", "B", "C", "D",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    /*  40 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    "E", "F", "G", "H", "I",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    "J", "K", "L", "M", "N",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    /*  50 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    "O", "P", "Q", "R", "S",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    "T", "U", "V", "W", "X",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    /*  60 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    "Y", "Z", "bracketleft", "backslash", "bracketright",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    "asciicircum", "underscore", "grave", "a", "b",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    /*  70 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    "c", "d", "e", "f", "g",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    "h", "i", "j", "k", "l",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    /*  80 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    "m", "n", "o", "p", "q",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    "r", "s", "t", "u", "v",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    /*  90 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    "w", "x", "y", "z", "braceleft",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    "bar", "braceright", "asciitilde", "Adieresis", "Aring",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    /* 100 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    "Ccedilla", "Eacute", "Ntilde", "Odieresis", "Udieresis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    "aacute", "agrave", "acircumflex", "adieresis", "atilde",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    /* 110 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    "aring", "ccedilla", "eacute", "egrave", "ecircumflex",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    "edieresis", "iacute", "igrave", "icircumflex", "idieresis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    /* 120 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    "ntilde", "oacute", "ograve", "ocircumflex", "odieresis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    "otilde", "uacute", "ugrave", "ucircumflex", "udieresis",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    /* 130 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    "dagger", "degree", "cent", "sterling", "section",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    "bullet", "paragraph", "germandbls", "registered", "copyright",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    /* 140 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    "trademark", "acute", "dieresis", "notequal", "AE",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    "Oslash", "infinity", "plusminus", "lessequal", "greaterequal",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    /* 150 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    "yen", "mu", "partialdiff", "summation", "product",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    "pi", "integral", "ordfeminine", "ordmasculine", "Omega",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    /* 160 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    "ae", "oslash", "questiondown", "exclamdown", "logicalnot",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    "radical", "florin", "approxequal", "Delta", "guillemotleft",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    /* 170 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    "guillemotright", "ellipsis", "nbspace", "Agrave", "Atilde",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    "Otilde", "OE", "oe", "endash", "emdash",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    /* 180 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    "quotedblleft", "quotedblright", "quoteleft", "quoteright", "divide",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    "lozenge", "ydieresis", "Ydieresis", "fraction", "currency",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    /* 190 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    "guilsinglleft", "guilsinglright", "fi", "fl", "daggerdbl",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    "periodcentered", "quotesinglbase", "quotedblbase", "perthousand", "Acircumflex",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    /* 200 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    "Ecircumflex", "Aacute", "Edieresis", "Egrave", "Iacute",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    "Icircumflex", "Idieresis", "Igrave", "Oacute", "Ocircumflex",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    /* 210 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    "apple", "Ograve", "Uacute", "Ucircumflex", "Ugrave",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    "dotlessi", "circumflex", "tilde", "macron", "breve",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    /* 220 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    "dotaccent", "ring", "cedilla", "hungarumlaut", "ogonek",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    "caron", "Lslash", "lslash", "Scaron", "scaron",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    /* 230 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    "Zcaron", "zcaron", "brokenbar", "Eth", "eth",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    "Yacute", "yacute", "Thorn", "thorn", "minus",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    /* 240 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    "multiply", "onesuperior", "twosuperior", "threesuperior", "onehalf",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    "onequarter", "threequarters", "franc", "Gbreve", "gbreve",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    /* 250 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    "Idot", "Scedilla", "scedilla", "Cacute", "cacute",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    "Ccaron", "ccaron", "dmacron",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
#endif /* FT_CONFIG_OPTION_POSTSCRIPT_NAMES */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
  load_format_20( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
                  FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
                  FT_Long    post_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    FT_Memory   memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    FT_Error    error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    FT_Int      num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    FT_UShort   num_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    FT_UShort*  glyph_indices = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    FT_Char**   name_strings  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
    if ( FT_READ_USHORT( num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
    /* UNDOCUMENTED!  The number of glyphs in this table can be smaller */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
    /* than the value in the maxp table (cf. cyberbit.ttf).             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    /* There already exist fonts which have more than 32768 glyph names */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
    /* in this table, so the test for this threshold has been dropped.  */
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
    if ( num_glyphs > face->max_profile.numGlyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    /* load the indices */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
      FT_Int  n;
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
      if ( FT_NEW_ARRAY ( glyph_indices, num_glyphs ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
           FT_FRAME_ENTER( num_glyphs * 2L )          )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
      for ( n = 0; n < num_glyphs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
        glyph_indices[n] = FT_GET_USHORT();
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
      FT_FRAME_EXIT();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    /* compute number of names stored in table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      FT_Int  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
      num_names = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      for ( n = 0; n < num_glyphs; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
        FT_Int  idx;
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
        idx = glyph_indices[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
        if ( idx >= 258 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
          idx -= 257;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
          if ( idx > num_names )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
            num_names = (FT_UShort)idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
        }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
    /* now load the name strings */
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
      FT_UShort  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      if ( FT_NEW_ARRAY( name_strings, num_names ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
        goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      for ( n = 0; n < num_names; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
        FT_UInt  len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
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
        if ( FT_STREAM_POS() >= post_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
          FT_TRACE6(( "load_format_20: %d byte left in post table\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
                      post_limit - FT_STREAM_POS() ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
          if ( FT_READ_BYTE( len ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
            goto Fail1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
        if ( (FT_Int)len > post_limit                   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
             FT_STREAM_POS() > post_limit - (FT_Int)len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
          FT_ERROR(( "load_format_20:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
                     " exceeding string length (%d),"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
                     " truncating at end of post table (%d byte left)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
                     len, post_limit - FT_STREAM_POS() ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
          len = FT_MAX( 0, post_limit - FT_STREAM_POS() );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
        if ( FT_NEW_ARRAY( name_strings[n], len + 1 ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
             FT_STREAM_READ( name_strings[n], len   ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
          goto Fail1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
        name_strings[n][len] = '\0';
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
      if ( n < num_names )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
        FT_ERROR(( "load_format_20:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
                   " all entries in post table are already parsed,"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
                   " using NULL names for gid %d - %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
                    n, num_names - 1 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
        for ( ; n < num_names; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
          if ( FT_NEW_ARRAY( name_strings[n], 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
            goto Fail1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
            name_strings[n][0] = '\0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
    }
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
    /* all right, set table fields and exit successfully */
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
      TT_Post_20  table = &face->postscript_names.names.format_20;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
      table->num_glyphs    = (FT_UShort)num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
      table->num_names     = (FT_UShort)num_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
      table->glyph_indices = glyph_indices;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
      table->glyph_names   = name_strings;
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
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
  Fail1:
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
      FT_UShort  n;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      for ( n = 0; n < num_names; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
        FT_FREE( name_strings[n] );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
    FT_FREE( name_strings );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
    FT_FREE( glyph_indices );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
  load_format_25( TT_Face    face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
                  FT_Stream  stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
                  FT_Long    post_limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
    FT_Memory  memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
    FT_Int     num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    FT_Char*   offset_table = 0;
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
    FT_UNUSED( post_limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    /* UNDOCUMENTED!  This value appears only in the Apple TT specs. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    if ( FT_READ_USHORT( num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    /* check the number of glyphs */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
    if ( num_glyphs > face->max_profile.numGlyphs || num_glyphs > 258 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
    if ( FT_NEW_ARRAY( offset_table, num_glyphs )   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
         FT_STREAM_READ( offset_table, num_glyphs ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
      goto Fail;
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
    /* now check the offset table */
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
      FT_Int  n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
      for ( n = 0; n < num_glyphs; n++ )
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
        FT_Long  idx = (FT_Long)n + offset_table[n];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        if ( idx < 0 || idx > num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
          error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    }
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
    /* OK, set table fields and exit successfully */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
      TT_Post_25  table = &face->postscript_names.names.format_25;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
      table->num_glyphs = (FT_UShort)num_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
      table->offsets    = offset_table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    FT_FREE( offset_table );
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  load_post_names( TT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    FT_Stream  stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    FT_Error   error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    FT_Fixed   format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
    FT_ULong   post_len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    FT_Long    post_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    /* get a stream for the face's resource */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
    stream = face->root.stream;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    /* seek to the beginning of the PS names table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
    error = face->goto_table( face, TTAG_post, stream, &post_len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    post_limit = FT_STREAM_POS() + post_len;
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
    format = face->postscript.FormatType;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    /* go to beginning of subtable */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    if ( FT_STREAM_SKIP( 32 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    /* now read postscript table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
    if ( format == 0x00020000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
      error = load_format_20( face, stream, post_limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
    else if ( format == 0x00028000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
      error = load_format_25( face, stream, post_limit );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
      error = SFNT_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
    face->postscript_names.loaded = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
  tt_face_free_ps_names( TT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    FT_Memory      memory = face->root.memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
    TT_Post_Names  names  = &face->postscript_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    FT_Fixed       format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
    if ( names->loaded )
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
      format = face->postscript.FormatType;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      if ( format == 0x00020000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
        TT_Post_20  table = &names->names.format_20;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
        FT_UShort   n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        FT_FREE( table->glyph_indices );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        table->num_glyphs = 0;
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
        for ( n = 0; n < table->num_names; n++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
          FT_FREE( table->glyph_names[n] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
        FT_FREE( table->glyph_names );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
        table->num_names = 0;
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
      else if ( format == 0x00028000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
        TT_Post_25  table = &names->names.format_25;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
        FT_FREE( table->offsets );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
        table->num_glyphs = 0;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    names->loaded = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
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
  /* <Function>                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
  /*    tt_face_get_ps_name                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  /* <Description>                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  /*    Get the PostScript glyph name of a glyph.                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
  /* <Input>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
  /*    face   :: A handle to the parent face.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
  /*    idx    :: The glyph index.                                         */
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
  /* <InOut>                                                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
  /*    PSname :: The address of a string pointer.  Will be NULL in case   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
  /*              of error, otherwise it is a pointer to the glyph name.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
  /*              You must not modify the returned string!                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
  /* <Output>                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
  /*    FreeType error code.  0 means success.                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
  tt_face_get_ps_name( TT_Face      face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
                       FT_UInt      idx,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
                       FT_String**  PSname )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
    FT_Error       error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
    TT_Post_Names  names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    FT_Fixed       format;
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
#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    FT_Service_PsCMaps  psnames;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
#endif
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
    if ( !face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      return SFNT_Err_Invalid_Face_Handle;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    if ( idx >= (FT_UInt)face->max_profile.numGlyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
      return SFNT_Err_Invalid_Glyph_Index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
#ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
    psnames = (FT_Service_PsCMaps)face->psnames;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
    if ( !psnames )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
      return SFNT_Err_Unimplemented_Feature;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
#endif
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
    names = &face->postscript_names;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    /* `.notdef' by default */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    *PSname = MAC_NAME( 0 );
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
    format = face->postscript.FormatType;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    if ( format == 0x00010000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
      if ( idx < 258 )                    /* paranoid checking */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
        *PSname = MAC_NAME( idx );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    else if ( format == 0x00020000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      TT_Post_20  table = &names->names.format_20;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      if ( !names->loaded )
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
        error = load_post_names( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
          goto End;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
      if ( idx < (FT_UInt)table->num_glyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
        FT_UShort  name_index = table->glyph_indices[idx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
        if ( name_index < 258 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
          *PSname = MAC_NAME( name_index );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
          *PSname = (FT_String*)table->glyph_names[name_index - 258];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      }
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
    else if ( format == 0x00028000L )
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
      TT_Post_25  table = &names->names.format_25;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
      if ( !names->loaded )
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
        error = load_post_names( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
          goto End;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
      if ( idx < (FT_UInt)table->num_glyphs )    /* paranoid checking */
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
        idx    += table->offsets[idx];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        *PSname = MAC_NAME( idx );
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
    /* nothing to do for format == 0x00030000L */
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
  End:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    return SFNT_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
/* END */