misc/libfreetype/src/bdf/bdflib.c
author Medo <smaxein@googlemail.com>
Fri, 08 Jun 2012 19:52:24 +0200
changeset 7177 bf6cf4dd847a
parent 5172 88f2e05288ba
permissions -rw-r--r--
Implemented public API for letting the engine render maps
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
 * Copyright 2000 Computing Research Labs, New Mexico State University
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
 * Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
 *   Francesco Zappa Nardelli
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
 *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
 * Permission is hereby granted, free of charge, to any person obtaining a
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
 * copy of this software and associated documentation files (the "Software"),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
 * to deal in the Software without restriction, including without limitation
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
 * and/or sell copies of the Software, and to permit persons to whom the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
 * Software is furnished to do so, subject to the following conditions:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
 *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
 * The above copyright notice and this permission notice shall be included in
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
 * all copies or substantial portions of the Software.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
 *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
 * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
 * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
  /*************************************************************************/
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
  /*  This file is based on bdf.c,v 1.22 2000/03/16 20:08:50               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*  taken from Mark Leisher's xmbdfed package                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
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 <ft2build.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
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#include FT_INTERNAL_OBJECTS_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#include "bdf.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#include "bdferror.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
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
  /* 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
    48
  /* 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
    49
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
#define FT_COMPONENT  trace_bdflib
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
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
  /*************************************************************************/
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
  /* Default BDF font options.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
  /*                                                                       */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  static const bdf_options_t  _bdf_opts =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    1,                /* Correct metrics.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    1,                /* Preserve unencoded glyphs.     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    0,                /* Preserve comments.             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    BDF_PROPORTIONAL  /* Default spacing.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
  /* Builtin BDF font properties.                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
  /* List of most properties that might appear in a font.  Doesn't include */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
  /* the RAW_* and AXIS_* properties in X11R6 polymorphic fonts.           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
  static const bdf_property_t  _bdf_properties[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
    { (char *)"ADD_STYLE_NAME",          BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    { (char *)"AVERAGE_WIDTH",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    { (char *)"AVG_CAPITAL_WIDTH",       BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    { (char *)"AVG_LOWERCASE_WIDTH",     BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
    { (char *)"CAP_HEIGHT",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    { (char *)"CHARSET_COLLECTIONS",     BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    { (char *)"CHARSET_ENCODING",        BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    { (char *)"CHARSET_REGISTRY",        BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
    { (char *)"COMMENT",                 BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    { (char *)"COPYRIGHT",               BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    { (char *)"DEFAULT_CHAR",            BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    { (char *)"DESTINATION",             BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    { (char *)"DEVICE_FONT_NAME",        BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    { (char *)"END_SPACE",               BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    { (char *)"FACE_NAME",               BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    { (char *)"FAMILY_NAME",             BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
    { (char *)"FIGURE_WIDTH",            BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
    { (char *)"FONT",                    BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
    { (char *)"FONTNAME_REGISTRY",       BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    { (char *)"FONT_ASCENT",             BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    { (char *)"FONT_DESCENT",            BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    { (char *)"FOUNDRY",                 BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
    { (char *)"FULL_NAME",               BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
    { (char *)"ITALIC_ANGLE",            BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    { (char *)"MAX_SPACE",               BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
    { (char *)"MIN_SPACE",               BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
    { (char *)"NORM_SPACE",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    { (char *)"NOTICE",                  BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    { (char *)"PIXEL_SIZE",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
    { (char *)"POINT_SIZE",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
    { (char *)"QUAD_WIDTH",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
    { (char *)"RAW_ASCENT",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    { (char *)"RAW_AVERAGE_WIDTH",       BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    { (char *)"RAW_AVG_CAPITAL_WIDTH",   BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    { (char *)"RAW_AVG_LOWERCASE_WIDTH", BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    { (char *)"RAW_CAP_HEIGHT",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    { (char *)"RAW_DESCENT",             BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    { (char *)"RAW_END_SPACE",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    { (char *)"RAW_FIGURE_WIDTH",        BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    { (char *)"RAW_MAX_SPACE",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    { (char *)"RAW_MIN_SPACE",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    { (char *)"RAW_NORM_SPACE",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    { (char *)"RAW_PIXEL_SIZE",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    { (char *)"RAW_POINT_SIZE",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    { (char *)"RAW_PIXELSIZE",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    { (char *)"RAW_POINTSIZE",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    { (char *)"RAW_QUAD_WIDTH",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    { (char *)"RAW_SMALL_CAP_SIZE",      BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    { (char *)"RAW_STRIKEOUT_ASCENT",    BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    { (char *)"RAW_STRIKEOUT_DESCENT",   BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    { (char *)"RAW_SUBSCRIPT_SIZE",      BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    { (char *)"RAW_SUBSCRIPT_X",         BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    { (char *)"RAW_SUBSCRIPT_Y",         BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    { (char *)"RAW_SUPERSCRIPT_SIZE",    BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    { (char *)"RAW_SUPERSCRIPT_X",       BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    { (char *)"RAW_SUPERSCRIPT_Y",       BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    { (char *)"RAW_UNDERLINE_POSITION",  BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    { (char *)"RAW_UNDERLINE_THICKNESS", BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    { (char *)"RAW_X_HEIGHT",            BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    { (char *)"RELATIVE_SETWIDTH",       BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    { (char *)"RELATIVE_WEIGHT",         BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    { (char *)"RESOLUTION",              BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    { (char *)"RESOLUTION_X",            BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    { (char *)"RESOLUTION_Y",            BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
    { (char *)"SETWIDTH_NAME",           BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
    { (char *)"SLANT",                   BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    { (char *)"SMALL_CAP_SIZE",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
    { (char *)"SPACING",                 BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    { (char *)"STRIKEOUT_ASCENT",        BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    { (char *)"STRIKEOUT_DESCENT",       BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    { (char *)"SUBSCRIPT_SIZE",          BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    { (char *)"SUBSCRIPT_X",             BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    { (char *)"SUBSCRIPT_Y",             BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    { (char *)"SUPERSCRIPT_SIZE",        BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    { (char *)"SUPERSCRIPT_X",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    { (char *)"SUPERSCRIPT_Y",           BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    { (char *)"UNDERLINE_POSITION",      BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    { (char *)"UNDERLINE_THICKNESS",     BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    { (char *)"WEIGHT",                  BDF_CARDINAL, 1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    { (char *)"WEIGHT_NAME",             BDF_ATOM,     1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    { (char *)"X_HEIGHT",                BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    { (char *)"_MULE_BASELINE_OFFSET",   BDF_INTEGER,  1, { 0 } },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    { (char *)"_MULE_RELATIVE_COMPOSE",  BDF_INTEGER,  1, { 0 } },
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
  static const unsigned long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
  _num_bdf_properties = sizeof ( _bdf_properties ) /
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
                        sizeof ( _bdf_properties[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
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
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  /* Hash table utilities for the properties.                              */
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
  /* XXX: Replace this with FreeType's hash functions */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
#define INITIAL_HT_SIZE  241
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
  typedef void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  (*hash_free_func)( hashnode  node );
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
  static hashnode*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
  hash_bucket( const char*  key,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
               hashtable*   ht )
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
    const char*    kp  = key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    unsigned long  res = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
    hashnode*      bp  = ht->table, *ndp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    /* Mocklisp hash function. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    while ( *kp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      res = ( res << 5 ) - res + *kp++;
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
    ndp = bp + ( res % ht->size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    while ( *ndp )
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
      kp = (*ndp)->key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      if ( kp[0] == key[0] && ft_strcmp( kp, key ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
      ndp--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      if ( ndp < bp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
        ndp = bp + ( ht->size - 1 );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
    return ndp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
  hash_rehash( hashtable*  ht,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
               FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
    hashnode*  obp = ht->table, *bp, *nbp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    int        i, sz = ht->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    FT_Error   error = BDF_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    ht->size <<= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
    ht->limit  = ht->size / 3;
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
    if ( FT_NEW_ARRAY( ht->table, ht->size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    for ( i = 0, bp = obp; i < sz; i++, bp++ )
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
      if ( *bp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
        nbp = hash_bucket( (*bp)->key, ht );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
        *nbp = *bp;
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
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    FT_FREE( obp );
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
  hash_init( hashtable*  ht,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
             FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
    int       sz = INITIAL_HT_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FT_Error  error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
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
    ht->size  = sz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
    ht->limit = sz / 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    ht->used  = 0;
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( ht->table, sz ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
  hash_free( hashtable*  ht,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
             FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
    if ( ht != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      int        i, sz = ht->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      hashnode*  bp = ht->table;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      for ( i = 0; i < sz; i++, bp++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
        FT_FREE( *bp );
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
      FT_FREE( ht->table );
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
  }
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
  hash_insert( char*       key,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
               size_t      data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
               hashtable*  ht,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
               FT_Memory   memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
    hashnode  nn, *bp = hash_bucket( key, ht );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
    FT_Error  error = BDF_Err_Ok;
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
    nn = *bp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
    if ( !nn )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      if ( FT_NEW( nn ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      *bp = nn;
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
      nn->key  = key;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
      nn->data = data;
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
      if ( ht->used >= ht->limit )
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
        error = hash_rehash( ht, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      ht->used++;
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
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
      nn->data = data;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
    return error;
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
  static hashnode
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
  hash_lookup( const char* key,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
               hashtable*  ht )
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
    hashnode *np = hash_bucket( key, ht );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
    return *np;
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
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
  /*************************************************************************/
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
  /* Utility types and functions.                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
  /*************************************************************************/
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
  /* Function type for parsing lines of a BDF font. */
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
  typedef FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
  (*_bdf_line_func_t)( char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
                       unsigned long  linelen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
                       unsigned long  lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
                       void*          call_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
                       void*          client_data );
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
  /* List structure for splitting lines into fields. */
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
  typedef struct  _bdf_list_t_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
    char**         field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
    unsigned long  size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
    unsigned long  used;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    FT_Memory      memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
  } _bdf_list_t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
  /* Structure used while loading BDF fonts. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
  typedef struct  _bdf_parse_t_
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
    unsigned long   flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
    unsigned long   cnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    unsigned long   row;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
    short           minlb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
    short           maxlb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    short           maxrb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
    short           maxas;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
    short           maxds;
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
    short           rbearing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
    char*           glyph_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
    long            glyph_enc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
    bdf_font_t*     font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
    bdf_options_t*  opts;
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
    unsigned long   have[2048];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
    _bdf_list_t     list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    FT_Memory       memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
  } _bdf_parse_t;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
#define setsbit( m, cc ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
          ( m[(FT_Byte)(cc) >> 3] |= (FT_Byte)( 1 << ( (cc) & 7 ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
#define sbitset( m, cc ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
          ( m[(FT_Byte)(cc) >> 3]  & ( 1 << ( (cc) & 7 ) ) )
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
  _bdf_list_init( _bdf_list_t*  list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
                  FT_Memory     memory )
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
    FT_ZERO( list );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    list->memory = memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
  }
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  _bdf_list_done( _bdf_list_t*  list )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    FT_Memory  memory = list->memory;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    if ( memory )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
      FT_FREE( list->field );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      FT_ZERO( list );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
  _bdf_list_ensure( _bdf_list_t*   list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
                    unsigned long  num_items ) /* same as _bdf_list_t.used */
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
    FT_Error  error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    if ( num_items > list->size )
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
      unsigned long  oldsize = list->size; /* same as _bdf_list_t.size */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      unsigned long  newsize = oldsize + ( oldsize >> 1 ) + 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
      unsigned long  bigsize = (unsigned long)( FT_INT_MAX / sizeof ( char* ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
      FT_Memory      memory  = list->memory;
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
      if ( oldsize == bigsize )
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
        error = BDF_Err_Out_Of_Memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      else if ( newsize < oldsize || newsize > bigsize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
        newsize = bigsize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
      if ( FT_RENEW_ARRAY( list->field, oldsize, newsize ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        goto Exit;
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
      list->size = newsize;
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
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
  _bdf_list_shift( _bdf_list_t*   list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
                   unsigned long  n )
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
    unsigned long  i, u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
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
    if ( list == 0 || list->used == 0 || n == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
    if ( n >= list->used )
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
      list->used = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
    }
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
    for ( u = n, i = 0; u < list->used; i++, u++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      list->field[i] = list->field[u];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
    list->used -= n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
  /* An empty string for empty fields. */
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
  static const char  empty[1] = { 0 };      /* XXX eliminate this */
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
  static char *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
  _bdf_list_join( _bdf_list_t*    list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
                  int             c,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
                  unsigned long  *alen )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    unsigned long  i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    char           *fp, *dp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
    *alen = 0;
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
    if ( list == 0 || list->used == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
    dp = list->field[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    for ( i = j = 0; i < list->used; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
      fp = list->field[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
      while ( *fp )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
        dp[j++] = *fp++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
      if ( i + 1 < list->used )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
        dp[j++] = (char)c;
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
    if ( dp != empty )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
      dp[j] = 0;
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
    *alen = j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    return dp;
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
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
  _bdf_list_split( _bdf_list_t*   list,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
                   char*          separators,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
                   char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
                   unsigned long  linelen )
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
    int       mult, final_empty;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    char      *sp, *ep, *end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
    char      seps[32];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    FT_Error  error = BDF_Err_Ok;
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
    /* Initialize the list. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    list->used = 0;
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
    /* If the line is empty, then simply return. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    if ( linelen == 0 || line[0] == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
    /* In the original code, if the `separators' parameter is NULL or */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    /* empty, the list is split into individual bytes.  We don't need */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    /* this, so an error is signaled.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    if ( separators == 0 || *separators == 0 )
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
      error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    /* Prepare the separator bitmap. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    FT_MEM_ZERO( seps, 32 );
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
    /* If the very last character of the separator string is a plus, then */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    /* set the `mult' flag to indicate that multiple separators should be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    /* collapsed into one.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    for ( mult = 0, sp = separators; sp && *sp; sp++ )
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
      if ( *sp == '+' && *( sp + 1 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
        mult = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
        setsbit( seps, *sp );
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
    /* Break the line up into fields. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    for ( final_empty = 0, sp = ep = line, end = sp + linelen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
          sp < end && *sp; )
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
      /* Collect everything that is not a separator. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
      for ( ; *ep && !sbitset( seps, *ep ); ep++ )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      /* Resize the list if necessary. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
      if ( list->used == list->size )
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
        error = _bdf_list_ensure( list, list->used + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
          goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
      /* Assign the field appropriately. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
      list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty;
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
      sp = ep;
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
      if ( mult )
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
        /* If multiple separators should be collapsed, do it now by */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
        /* setting all the separator characters to 0.               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        for ( ; *ep && sbitset( seps, *ep ); ep++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          *ep = 0;
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
      else if ( *ep != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
        /* Don't collapse multiple separators by making them 0, so just */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
        /* make the one encountered 0.                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
        *ep++ = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
      final_empty = ( ep > sp && *ep == 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
      sp = ep;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    /* Finally, NULL-terminate the list. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
    if ( list->used + final_empty >= list->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      error = _bdf_list_ensure( list, list->used + final_empty + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
    if ( final_empty )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
      list->field[list->used++] = (char*)empty;
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
    list->field[list->used] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
#define NO_SKIP  256  /* this value cannot be stored in a 'char' */
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
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
  _bdf_readstream( FT_Stream         stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
                   _bdf_line_func_t  callback,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
                   void*             client_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
                   unsigned long    *lno )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
    _bdf_line_func_t  cb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
    unsigned long     lineno, buf_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
    int               refill, hold, to_skip;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
    ptrdiff_t         bytes, start, end, cursor, avail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
    char*             buf = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
    FT_Memory         memory = stream->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
    FT_Error          error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
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
    if ( callback == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
      error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
    /* initial size and allocation of the input buffer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
    buf_size = 1024;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
    if ( FT_NEW_ARRAY( buf, buf_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
      goto Exit;
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
    cb      = callback;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    lineno  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
    buf[0]  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    start   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
    end     = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
    avail   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    cursor  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
    refill  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    to_skip = NO_SKIP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    bytes   = 0;        /* make compiler happy */
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
    for (;;)
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
      if ( refill )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
        bytes  = (ptrdiff_t)FT_Stream_TryRead(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
                   stream, (FT_Byte*)buf + cursor,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
                   (FT_ULong)( buf_size - cursor ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
        avail  = cursor + bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
        cursor = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
        refill = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
      end = start;
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
      /* should we skip an optional character like \n or \r? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      if ( start < avail && buf[start] == to_skip )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
        start  += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
        to_skip = NO_SKIP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
      }
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
      /* try to find the end of the line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
      while ( end < avail && buf[end] != '\n' && buf[end] != '\r' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
        end++;
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
      /* if we hit the end of the buffer, try shifting its content */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
      /* or even resizing it                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
      if ( end >= avail )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
        if ( bytes == 0 )  /* last line in file doesn't end in \r or \n */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
          break;           /* ignore it then exit                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
        if ( start == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
          /* this line is definitely too long; try resizing the input */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
          /* buffer a bit to handle it.                               */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
          FT_ULong  new_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
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
          if ( buf_size >= 65536UL )  /* limit ourselves to 64KByte */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
            error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
          }
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
          new_size = buf_size * 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
          if ( FT_RENEW_ARRAY( buf, buf_size, new_size ) )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
          cursor   = buf_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
          buf_size = new_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
        else
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
          bytes = avail - start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
          FT_MEM_COPY( buf, buf + start, bytes );
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
          cursor = bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
          avail -= bytes;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
          start  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
        refill = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
        continue;
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
      /* Temporarily NUL-terminate the line. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
      hold     = buf[end];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
      buf[end] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
      /* XXX: Use encoding independent value for 0x1a */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
      if ( buf[start] != '#' && buf[start] != 0x1a && end > start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
        error = (*cb)( buf + start, end - start, lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
                       (void*)&cb, client_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
        /* Redo if we have encountered CHARS without properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
        if ( error == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
          error = (*cb)( buf + start, end - start, lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
                         (void*)&cb, client_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
      }
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
      lineno  += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
      buf[end] = (char)hold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
      start    = end + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
      if ( hold == '\n' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
        to_skip = '\r';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      else if ( hold == '\r' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
        to_skip = '\n';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
        to_skip = NO_SKIP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    }
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
    *lno = lineno;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
    FT_FREE( buf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
  /* XXX: make this work with EBCDIC also */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
  static const unsigned char  a2i[128] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
    0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
    0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
  };
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
  static const unsigned char  odigits[32] =
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
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
  static const unsigned char  ddigits[32] =
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
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
  static const unsigned char  hdigits[32] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    0x7e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
  };
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
#define isdigok( m, d )  (m[(d) >> 3] & ( 1 << ( (d) & 7 ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
  /* Routine to convert an ASCII string into an unsigned long integer. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
  static unsigned long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
  _bdf_atoul( char*   s,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
              char**  end,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
              int     base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    unsigned long         v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
    const unsigned char*  dmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
    if ( s == 0 || *s == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
    /* Make sure the radix is something recognizable.  Default to 10. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
    switch ( base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
      dmap = odigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
    case 16:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
      base = 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
      dmap = ddigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
    /* Check for the special hex prefix. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
    if ( *s == '0'                                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
         ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
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
      base = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
      s   += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    }
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
    for ( v = 0; isdigok( dmap, *s ); s++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
      v = v * base + a2i[(int)*s];
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
    if ( end != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
      *end = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
    return v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
  /* Routine to convert an ASCII string into an signed long integer. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
  static long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
  _bdf_atol( char*   s,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
             char**  end,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
             int     base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
    long                  v, neg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
    const unsigned char*  dmap;
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
    if ( s == 0 || *s == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
    /* Make sure the radix is something recognizable.  Default to 10. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    switch ( base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
      dmap = odigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    case 16:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
      base = 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
      dmap = ddigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
      break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
    /* Check for a minus sign. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
    neg = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
    if ( *s == '-' )
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
      s++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
      neg = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
    /* Check for the special hex prefix. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
    if ( *s == '0'                                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
         ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
      base = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
      s   += 2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
    for ( v = 0; isdigok( dmap, *s ); s++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
      v = v * base + a2i[(int)*s];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
    if ( end != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
      *end = s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
    return ( !neg ) ? v : -v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
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
  /* Routine to convert an ASCII string into an signed short integer. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
  static short
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
  _bdf_atos( char*   s,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
             char**  end,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
             int     base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
    short                 v, neg;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
    const unsigned char*  dmap;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
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
    if ( s == 0 || *s == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
      return 0;
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
    /* Make sure the radix is something recognizable.  Default to 10. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
    switch ( base )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
    case 8:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
      dmap = odigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
    case 16:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
    default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
      base = 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
      dmap = ddigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
      break;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
    /* Check for a minus. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    neg = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
    if ( *s == '-' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
      s++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
      neg = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
    /* Check for the special hex prefix. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
    if ( *s == '0'                                  &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
         ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
      base = 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
      dmap = hdigits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
      s   += 2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
    for ( v = 0; isdigok( dmap, *s ); s++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
      v = (short)( v * base + a2i[(int)*s] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
    if ( end != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
      *end = s;
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
    return (short)( ( !neg ) ? v : -v );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
  /* Routine to compare two glyphs by encoding so they can be sorted. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
  by_encoding( const void*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
               const void*  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
    bdf_glyph_t  *c1, *c2;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
    c1 = (bdf_glyph_t *)a;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    c2 = (bdf_glyph_t *)b;
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
    if ( c1->encoding < c2->encoding )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
      return -1;
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
    if ( c1->encoding > c2->encoding )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
    return 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
  bdf_create_property( char*        name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
                       int          format,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
                       bdf_font_t*  font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
    size_t           n;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
    bdf_property_t*  p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
    FT_Memory        memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
    FT_Error         error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
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
    /* First check to see if the property has      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
    /* already been added or not.  If it has, then */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
    /* simply ignore it.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
    if ( hash_lookup( name, &(font->proptbl) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
      goto Exit;
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
    if ( FT_RENEW_ARRAY( font->user_props,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
                         font->nuser_props,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
                         font->nuser_props + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
    p = font->user_props + font->nuser_props;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
    FT_ZERO( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
    n = ft_strlen( name ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
    if ( n > FT_ULONG_MAX )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
      return BDF_Err_Invalid_Argument;
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
    if ( FT_NEW_ARRAY( p->name, n ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
    FT_MEM_COPY( (char *)p->name, name, n );
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
    p->format  = format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
    p->builtin = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
    n = _num_bdf_properties + font->nuser_props;
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
    error = hash_insert( p->name, n, &(font->proptbl), memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    font->nuser_props++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
    return error;
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
  FT_LOCAL_DEF( bdf_property_t * )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
  bdf_get_property( char*        name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
                    bdf_font_t*  font )
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
    hashnode  hn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
    size_t    propid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
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
    if ( name == 0 || *name == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
      return 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
    propid = hn->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    if ( propid >= _num_bdf_properties )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
      return font->user_props + ( propid - _num_bdf_properties );
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
    return (bdf_property_t*)_bdf_properties + propid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
  /* BDF font file parsing flags and functions.                            */
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
  /* Parse flags. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
#define _BDF_START      0x0001
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
#define _BDF_FONT_NAME  0x0002
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
#define _BDF_SIZE       0x0004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
#define _BDF_FONT_BBX   0x0008
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
#define _BDF_PROPS      0x0010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
#define _BDF_GLYPHS     0x0020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
#define _BDF_GLYPH      0x0040
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
#define _BDF_ENCODING   0x0080
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
#define _BDF_SWIDTH     0x0100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
#define _BDF_DWIDTH     0x0200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
#define _BDF_BBX        0x0400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
#define _BDF_BITMAP     0x0800
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
#define _BDF_SWIDTH_ADJ  0x1000
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
#define _BDF_GLYPH_BITS ( _BDF_GLYPH    | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
                          _BDF_ENCODING | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
                          _BDF_SWIDTH   | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
                          _BDF_DWIDTH   | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
                          _BDF_BBX      | \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
                          _BDF_BITMAP   )
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
#define _BDF_GLYPH_WIDTH_CHECK   0x40000000UL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
#define _BDF_GLYPH_HEIGHT_CHECK  0x80000000UL
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
  /* Auto correction messages. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
#define ACMSG1   "FONT_ASCENT property missing.  " \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
                 "Added \"FONT_ASCENT %hd\".\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
#define ACMSG2   "FONT_DESCENT property missing.  " \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
                 "Added \"FONT_DESCENT %hd\".\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
#define ACMSG3   "Font width != actual width.  Old: %hd New: %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
#define ACMSG4   "Font left bearing != actual left bearing.  " \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
                 "Old: %hd New: %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
#define ACMSG5   "Font ascent != actual ascent.  Old: %hd New: %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
#define ACMSG6   "Font descent != actual descent.  Old: %hd New: %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
#define ACMSG7   "Font height != actual height. Old: %hd New: %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
#define ACMSG8   "Glyph scalable width (SWIDTH) adjustments made.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
#define ACMSG9   "SWIDTH field missing at line %ld.  Set automatically.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
#define ACMSG10  "DWIDTH field missing at line %ld.  Set to glyph width.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
#define ACMSG11  "SIZE bits per pixel field adjusted to %hd.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
#define ACMSG12  "Duplicate encoding %ld (%s) changed to unencoded.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
#define ACMSG13  "Glyph %ld extra rows removed.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
#define ACMSG14  "Glyph %ld extra columns removed.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
#define ACMSG15  "Incorrect glyph count: %ld indicated but %ld found.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
  /* Error messages. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
#define ERRMSG1  "[line %ld] Missing \"%s\" line.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
#define ERRMSG2  "[line %ld] Font header corrupted or missing fields.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
#define ERRMSG3  "[line %ld] Font glyphs corrupted or missing fields.\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
#define ERRMSG4  "[line %ld] BBX too big.\n"
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
  _bdf_add_comment( bdf_font_t*    font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
                    char*          comment,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
                    unsigned long  len )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    char*      cp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
    FT_Memory  memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
    FT_Error   error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
    if ( FT_RENEW_ARRAY( font->comments,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
                         font->comments_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
                         font->comments_len + len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
      goto Exit;
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
    cp = font->comments + font->comments_len;
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
    FT_MEM_COPY( cp, comment, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
    cp[len] = '\n';
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
    font->comments_len += len + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
  }
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
  /* Set the spacing from the font name if it exists, or set it to the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
  /* default specified in the options.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
  _bdf_set_default_spacing( bdf_font_t*     font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
                            bdf_options_t*  opts )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
    size_t       len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
    char         name[256];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
    _bdf_list_t  list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
    FT_Error     error = BDF_Err_Ok;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
    if ( font == 0 || font->name == 0 || font->name[0] == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
      error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
    memory = font->memory;
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
    _bdf_list_init( &list, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
    font->spacing = opts->font_spacing;
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
    len = ft_strlen( font->name ) + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
    /* Limit ourselves to 256 characters in the font name. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
    if ( len >= 256 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
      error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
    FT_MEM_COPY( name, font->name, len );
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
    error = _bdf_list_split( &list, (char *)"-", name, len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
    if ( list.used == 15 )
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
      switch ( list.field[11][0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
      case 'C':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
      case 'c':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
        font->spacing = BDF_CHARCELL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
      case 'M':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
      case 'm':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
        font->spacing = BDF_MONOWIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
      case 'P':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
      case 'p':
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
        font->spacing = BDF_PROPORTIONAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
    }
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
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
    _bdf_list_done( &list );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
  /* Determine whether the property is an atom or not.  If it is, then */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
  /* clean it up so the double quotes are removed if they exist.       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
  _bdf_is_atom( char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
                unsigned long  linelen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
                char**         name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
                char**         value,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
                bdf_font_t*    font )
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
    int              hold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
    char             *sp, *ep;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
    bdf_property_t*  p;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
    *name = sp = ep = line;
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
    while ( *ep && *ep != ' ' && *ep != '\t' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
      ep++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
    hold = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
    if ( *ep )
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
      hold = *ep;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
      *ep  = 0;
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
    p = bdf_get_property( sp, font );
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
    /* Restore the character that was saved before any return can happen. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
    if ( hold != -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
      *ep = (char)hold;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
    /* If the property exists and is not an atom, just return here. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
    if ( p && p->format != BDF_ATOM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
      return 0;
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
    /* The property is an atom.  Trim all leading and trailing whitespace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
    /* and double quotes for the atom value.                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
    sp = ep;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
    ep = line + linelen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
    /* Trim the leading whitespace if it exists. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
    *sp++ = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
    while ( *sp                           &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
            ( *sp == ' ' || *sp == '\t' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
      sp++;
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
    /* Trim the leading double quote if it exists. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
    if ( *sp == '"' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
      sp++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
    *value = sp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
    /* Trim the trailing whitespace if it exists. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
    while ( ep > sp                                       &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
            ( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
      *--ep = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
    /* Trim the trailing double quote if it exists. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
    if ( ep > sp && *( ep - 1 ) == '"' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
      *--ep = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
    return 1;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
  _bdf_add_property( bdf_font_t*  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
                     char*        name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
                     char*        value )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
    size_t          propid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
    hashnode        hn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
    bdf_property_t  *prop, *fp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
    FT_Memory       memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
    FT_Error        error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
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
    /* First, check to see if the property already exists in the font. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
    if ( ( hn = hash_lookup( name, (hashtable *)font->internal ) ) != 0 )
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
      /* The property already exists in the font, so simply replace */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
      /* the value of the property with the current value.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
      fp = font->props + hn->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
      switch ( fp->format )
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
      case BDF_ATOM:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
        /* Delete the current atom if it exists. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
        FT_FREE( fp->value.atom );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
        if ( value && value[0] != 0 )
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
          if ( FT_STRDUP( fp->value.atom, value ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
      case BDF_INTEGER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
        fp->value.l = _bdf_atol( value, 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
      case BDF_CARDINAL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
        fp->value.ul = _bdf_atoul( value, 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
        ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
      }
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
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
    }
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
    /* See whether this property type exists yet or not. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
    /* If not, create it.                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
    hn = hash_lookup( name, &(font->proptbl) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
    if ( hn == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
      error = bdf_create_property( name, BDF_ATOM, font );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
      hn = hash_lookup( name, &(font->proptbl) );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
    /* Allocate another property if this is overflow. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
    if ( font->props_used == font->props_size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
      if ( font->props_size == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
        if ( FT_NEW_ARRAY( font->props, 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
        if ( FT_RENEW_ARRAY( font->props,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
                             font->props_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
                             font->props_size + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
      fp = font->props + font->props_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
      FT_MEM_ZERO( fp, sizeof ( bdf_property_t ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
      font->props_size++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
    propid = hn->data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    if ( propid >= _num_bdf_properties )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
      prop = font->user_props + ( propid - _num_bdf_properties );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
      prop = (bdf_property_t*)_bdf_properties + propid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
    fp = font->props + font->props_used;
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
    fp->name    = prop->name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
    fp->format  = prop->format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
    fp->builtin = prop->builtin;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
    switch ( prop->format )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
    case BDF_ATOM:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
      fp->value.atom = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
      if ( value != 0 && value[0] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
        if ( FT_STRDUP( fp->value.atom, value ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
      break;
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
    case BDF_INTEGER:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
      fp->value.l = _bdf_atol( value, 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
    case BDF_CARDINAL:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
      fp->value.ul = _bdf_atoul( value, 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
      break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
    /* If the property happens to be a comment, then it doesn't need */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
    /* to be added to the internal hash table.                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    if ( ft_memcmp( name, "COMMENT", 7 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
      /* Add the property to the font property table. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
      error = hash_insert( fp->name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
                           font->props_used,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
                           (hashtable *)font->internal,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
                           memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
    }
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
    font->props_used++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
    /* Some special cases need to be handled here.  The DEFAULT_CHAR       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
    /* property needs to be located if it exists in the property list, the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
    /* FONT_ASCENT and FONT_DESCENT need to be assigned if they are        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
    /* present, and the SPACING property should override the default       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
    /* spacing.                                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
    if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
      font->default_char = fp->value.l;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
    else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
      font->font_ascent = fp->value.l;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
    else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
      font->font_descent = fp->value.l;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
    else if ( ft_memcmp( name, "SPACING", 7 ) == 0 )
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 ( !fp->value.atom )
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
        error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
        goto Exit;
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
      if ( fp->value.atom[0] == 'p' || fp->value.atom[0] == 'P' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
        font->spacing = BDF_PROPORTIONAL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
      else if ( fp->value.atom[0] == 'm' || fp->value.atom[0] == 'M' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
        font->spacing = BDF_MONOWIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
      else if ( fp->value.atom[0] == 'c' || fp->value.atom[0] == 'C' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
        font->spacing = BDF_CHARCELL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
    return error;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
  static const unsigned char nibble_mask[8] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
    0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
  /* Actually parse the glyph info and bitmaps. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
  _bdf_parse_glyphs( char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
                     unsigned long  linelen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
                     unsigned long  lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
                     void*          call_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
                     void*          client_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
    int                c, mask_index;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
    char*              s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
    unsigned char*     bp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
    unsigned long      i, slen, nibbles;
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
    _bdf_parse_t*      p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
    bdf_glyph_t*       glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    bdf_font_t*        font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
    FT_Memory          memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    FT_Error           error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
    FT_UNUSED( call_data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
    FT_UNUSED( lineno );        /* only used in debug mode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
    p = (_bdf_parse_t *)client_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
    font   = p->font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
    memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
    /* Check for a comment. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
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
      linelen -= 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
      s = line + 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
      if ( *s != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
        s++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
        linelen--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
      error = _bdf_add_comment( p->font, s, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
    /* The very first thing expected is the number of glyphs. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
    if ( !( p->flags & _BDF_GLYPHS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
      if ( ft_memcmp( line, "CHARS", 5 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
        FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
        error = BDF_Err_Missing_Chars_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
      p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
      /* Make sure the number of glyphs is non-zero. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
      if ( p->cnt == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
        font->glyphs_size = 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
      /* Limit ourselves to 1,114,112 glyphs in the font (this is the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
      /* number of code points available in Unicode).                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
      if ( p->cnt >= 1114112UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
        error = BDF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
      if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
      p->flags |= _BDF_GLYPHS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
    /* Check for the ENDFONT field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
    if ( ft_memcmp( line, "ENDFONT", 7 ) == 0 )
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
      /* Sort the glyphs by encoding. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
      ft_qsort( (char *)font->glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
                font->glyphs_used,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
                sizeof ( bdf_glyph_t ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
                by_encoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
      p->flags &= ~_BDF_START;
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
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
    /* Check for the ENDCHAR field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
    if ( ft_memcmp( line, "ENDCHAR", 7 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
      p->glyph_enc = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
      p->flags    &= ~_BDF_GLYPH_BITS;
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
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
    /* Check to see whether a glyph is being scanned but should be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
    /* ignored because it is an unencoded glyph.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
    if ( ( p->flags & _BDF_GLYPH )     &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
         p->glyph_enc            == -1 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
         p->opts->keep_unencoded == 0  )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
    /* Check for the STARTCHAR field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
    if ( ft_memcmp( line, "STARTCHAR", 9 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
      /* Set the character name in the parse info first until the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
      /* encoding can be checked for an unencoded character.      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
      FT_FREE( p->glyph_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
      _bdf_list_shift( &p->list, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
      s = _bdf_list_join( &p->list, ' ', &slen );
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
      if ( !s )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
        error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
      }
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
      if ( FT_NEW_ARRAY( p->glyph_name, slen + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
        goto Exit;
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
      FT_MEM_COPY( p->glyph_name, s, slen + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
      p->flags |= _BDF_GLYPH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
      goto Exit;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
    /* Check for the ENCODING field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
    if ( ft_memcmp( line, "ENCODING", 8 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
      if ( !( p->flags & _BDF_GLYPH ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
        /* Missing STARTCHAR field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
        FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "STARTCHAR" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
        error = BDF_Err_Missing_Startchar_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
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
      p->glyph_enc = _bdf_atol( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
      /* Check that the encoding is in the range [0,65536] because        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
      /* otherwise p->have (a bitmap with static size) overflows.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
      if ( (size_t)p->glyph_enc >= sizeof ( p->have ) * 8 )
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 = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
      /* Check to see whether this encoding has already been encountered. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
      /* If it has then change it to unencoded so it gets added if        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
      /* indicated.                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
      if ( p->glyph_enc >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
        if ( _bdf_glyph_modified( p->have, p->glyph_enc ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
          /* Emit a message saying a glyph has been moved to the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
          /* unencoded area.                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
          FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG12,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
                      p->glyph_enc, p->glyph_name ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
          p->glyph_enc = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
          font->modified = 1;
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
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
          _bdf_set_glyph_modified( p->have, p->glyph_enc );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
      if ( p->glyph_enc >= 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
        /* Make sure there are enough glyphs allocated in case the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
        /* number of characters happen to be wrong.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
        if ( font->glyphs_used == font->glyphs_size )
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
          if ( FT_RENEW_ARRAY( font->glyphs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
                               font->glyphs_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
                               font->glyphs_size + 64 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
            goto Exit;
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
          font->glyphs_size += 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
        }
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
        glyph           = font->glyphs + font->glyphs_used++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
        glyph->name     = p->glyph_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
        glyph->encoding = p->glyph_enc;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
        /* Reset the initial glyph info. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
        p->glyph_name = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
        /* Unencoded glyph.  Check to see whether it should */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
        /* be added or not.                                 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
        if ( p->opts->keep_unencoded != 0 )
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
          /* Allocate the next unencoded glyph. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
          if ( font->unencoded_used == font->unencoded_size )
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
            if ( FT_RENEW_ARRAY( font->unencoded ,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
                                 font->unencoded_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
                                 font->unencoded_size + 4 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
            font->unencoded_size += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
          }
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
          glyph           = font->unencoded + font->unencoded_used;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
          glyph->name     = p->glyph_name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
          glyph->encoding = font->unencoded_used++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
          /* Free up the glyph name if the unencoded shouldn't be */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
          /* kept.                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
          FT_FREE( p->glyph_name );
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
        p->glyph_name = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
      /* Clear the flags that might be added when width and height are */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
      /* checked for consistency.                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
      p->flags &= ~( _BDF_GLYPH_WIDTH_CHECK | _BDF_GLYPH_HEIGHT_CHECK );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
      p->flags |= _BDF_ENCODING;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
    /* Point at the glyph being constructed. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
    if ( p->glyph_enc == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
      glyph = font->unencoded + ( font->unencoded_used - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
      glyph = font->glyphs + ( font->glyphs_used - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
    /* Check to see whether a bitmap is being constructed. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
    if ( p->flags & _BDF_BITMAP )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
      /* If there are more rows than are specified in the glyph metrics, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
      /* ignore the remaining lines.                                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
      if ( p->row >= (unsigned long)glyph->bbx.height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
        if ( !( p->flags & _BDF_GLYPH_HEIGHT_CHECK ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
          FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG13, glyph->encoding ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
          p->flags |= _BDF_GLYPH_HEIGHT_CHECK;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
          font->modified = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
      /* Only collect the number of nibbles indicated by the glyph     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
      /* metrics.  If there are more columns, they are simply ignored. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
      nibbles = glyph->bpr << 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
      bp      = glyph->bitmap + p->row * glyph->bpr;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
      for ( i = 0; i < nibbles; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
        c = line[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
        *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
        if ( i + 1 < nibbles && ( i & 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
          *++bp = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
      /* Remove possible garbage at the right. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
      mask_index = ( glyph->bbx.width * p->font->bpp ) & 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
      if ( glyph->bbx.width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
        *bp &= nibble_mask[mask_index];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
      /* If any line has extra columns, indicate they have been removed. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
      if ( ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
           !( p->flags & _BDF_GLYPH_WIDTH_CHECK )                   )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
        FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
        p->flags       |= _BDF_GLYPH_WIDTH_CHECK;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
        font->modified  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
      p->row++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
    /* Expect the SWIDTH (scalable width) field next. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
    if ( ft_memcmp( line, "SWIDTH", 6 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
      if ( !( p->flags & _BDF_ENCODING ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
        /* Missing ENCODING field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
        FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENCODING" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
        error = BDF_Err_Missing_Encoding_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
      glyph->swidth = (unsigned short)_bdf_atoul( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
      p->flags |= _BDF_SWIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
    /* Expect the DWIDTH (scalable width) field next. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
    if ( ft_memcmp( line, "DWIDTH", 6 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
      glyph->dwidth = (unsigned short)_bdf_atoul( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
      if ( !( p->flags & _BDF_SWIDTH ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
        /* Missing SWIDTH field.  Emit an auto correction message and set */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1760
        /* the scalable width from the device width.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1761
        FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG9, lineno ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1762
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1763
        glyph->swidth = (unsigned short)FT_MulDiv(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1764
                          glyph->dwidth, 72000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1765
                          (FT_Long)( font->point_size *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1766
                                     font->resolution_x ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1767
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1769
      p->flags |= _BDF_DWIDTH;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1770
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1771
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1772
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1773
    /* Expect the BBX field next. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1774
    if ( ft_memcmp( line, "BBX", 3 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1775
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1776
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1777
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1778
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1779
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1780
      glyph->bbx.width    = _bdf_atos( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1781
      glyph->bbx.height   = _bdf_atos( p->list.field[2], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1782
      glyph->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1783
      glyph->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1784
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1785
      /* Generate the ascent and descent of the character. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1786
      glyph->bbx.ascent  = (short)( glyph->bbx.height + glyph->bbx.y_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1787
      glyph->bbx.descent = (short)( -glyph->bbx.y_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1788
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1789
      /* Determine the overall font bounding box as the characters are */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1790
      /* loaded so corrections can be done later if indicated.         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1791
      p->maxas    = (short)FT_MAX( glyph->bbx.ascent, p->maxas );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1792
      p->maxds    = (short)FT_MAX( glyph->bbx.descent, p->maxds );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1793
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1794
      p->rbearing = (short)( glyph->bbx.width + glyph->bbx.x_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1795
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1796
      p->maxrb    = (short)FT_MAX( p->rbearing, p->maxrb );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1797
      p->minlb    = (short)FT_MIN( glyph->bbx.x_offset, p->minlb );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1798
      p->maxlb    = (short)FT_MAX( glyph->bbx.x_offset, p->maxlb );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1799
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1800
      if ( !( p->flags & _BDF_DWIDTH ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1801
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1802
        /* Missing DWIDTH field.  Emit an auto correction message and set */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1803
        /* the device width to the glyph width.                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1804
        FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG10, lineno ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1805
        glyph->dwidth = glyph->bbx.width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1806
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1807
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1808
      /* If the BDF_CORRECT_METRICS flag is set, then adjust the SWIDTH */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1809
      /* value if necessary.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1810
      if ( p->opts->correct_metrics != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1811
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1812
        /* Determine the point size of the glyph. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1813
        unsigned short  sw = (unsigned short)FT_MulDiv(
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1814
                               glyph->dwidth, 72000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1815
                               (FT_Long)( font->point_size *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1816
                                          font->resolution_x ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1817
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1819
        if ( sw != glyph->swidth )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1820
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1821
          glyph->swidth = sw;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1823
          if ( p->glyph_enc == -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1824
            _bdf_set_glyph_modified( font->umod,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1825
                                     font->unencoded_used - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1826
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1827
            _bdf_set_glyph_modified( font->nmod, glyph->encoding );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1828
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1829
          p->flags       |= _BDF_SWIDTH_ADJ;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1830
          font->modified  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1831
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1832
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1833
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1834
      p->flags |= _BDF_BBX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1835
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1836
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1837
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1838
    /* And finally, gather up the bitmap. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1839
    if ( ft_memcmp( line, "BITMAP", 6 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1840
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1841
      unsigned long  bitmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1842
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1843
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1844
      if ( !( p->flags & _BDF_BBX ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1845
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1846
        /* Missing BBX field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1847
        FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "BBX" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1848
        error = BDF_Err_Missing_Bbx_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1849
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1850
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1851
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1852
      /* Allocate enough space for the bitmap. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1853
      glyph->bpr   = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1854
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1855
      bitmap_size = glyph->bpr * glyph->bbx.height;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1856
      if ( bitmap_size > 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1857
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1858
        FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG4, lineno ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1859
        error = BDF_Err_Bbx_Too_Big;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1860
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1861
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1862
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1863
        glyph->bytes = (unsigned short)bitmap_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1864
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1865
      if ( FT_NEW_ARRAY( glyph->bitmap, glyph->bytes ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1866
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1868
      p->row    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1869
      p->flags |= _BDF_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1870
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1871
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1872
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1874
    error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1875
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1876
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1877
    if ( error && ( p->flags & _BDF_GLYPH ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1878
      FT_FREE( p->glyph_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1879
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1880
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1881
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1882
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1883
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1884
  /* Load the font properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1885
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1886
  _bdf_parse_properties( char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1887
                         unsigned long  linelen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1888
                         unsigned long  lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1889
                         void*          call_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1890
                         void*          client_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1891
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1892
    unsigned long      vlen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1893
    _bdf_line_func_t*  next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1894
    _bdf_parse_t*      p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1895
    char*              name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1896
    char*              value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1897
    char               nbuf[128];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1898
    FT_Error           error = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1900
    FT_UNUSED( lineno );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1903
    next = (_bdf_line_func_t *)call_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1904
    p    = (_bdf_parse_t *)    client_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1905
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1906
    /* Check for the end of the properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1907
    if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1908
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1909
      /* If the FONT_ASCENT or FONT_DESCENT properties have not been      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1910
      /* encountered yet, then make sure they are added as properties and */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1911
      /* make sure they are set from the font bounding box info.          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1912
      /*                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1913
      /* This is *always* done regardless of the options, because X11     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1914
      /* requires these two fields to compile fonts.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1915
      if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1916
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1917
        p->font->font_ascent = p->font->bbx.ascent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1918
        ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1919
        error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", nbuf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1920
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1921
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1922
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1923
        FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1924
        p->font->modified = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1925
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1927
      if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1928
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1929
        p->font->font_descent = p->font->bbx.descent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1930
        ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1931
        error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", nbuf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1932
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1933
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1934
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1935
        FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1936
        p->font->modified = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1937
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1938
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1939
      p->flags &= ~_BDF_PROPS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1940
      *next     = _bdf_parse_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1942
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1943
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1944
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1945
    /* Ignore the _XFREE86_GLYPH_RANGES properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1946
    if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1947
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1948
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1949
    /* Handle COMMENT fields and properties in a special way to preserve */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1950
    /* the spacing.                                                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1951
    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1952
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1953
      name = value = line;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1954
      value += 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1955
      if ( *value )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1956
        *value++ = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1957
      error = _bdf_add_property( p->font, name, value );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1958
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1959
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1960
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1961
    else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1962
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1963
      error = _bdf_add_property( p->font, name, value );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1964
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1965
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1966
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1967
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1968
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1969
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1970
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1971
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1972
      name = p->list.field[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1973
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1974
      _bdf_list_shift( &p->list, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1975
      value = _bdf_list_join( &p->list, ' ', &vlen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1976
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1977
      error = _bdf_add_property( p->font, name, value );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1978
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1979
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1980
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1981
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1982
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1983
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1984
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1985
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1986
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1987
  /* Load the font header. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1988
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1989
  _bdf_parse_start( char*          line,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1990
                    unsigned long  linelen,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1991
                    unsigned long  lineno,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1992
                    void*          call_data,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1993
                    void*          client_data )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1994
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1995
    unsigned long      slen;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1996
    _bdf_line_func_t*  next;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1997
    _bdf_parse_t*      p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1998
    bdf_font_t*        font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1999
    char               *s;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2001
    FT_Memory          memory = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2002
    FT_Error           error  = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2003
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2004
    FT_UNUSED( lineno );            /* only used in debug mode */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2005
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2006
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2007
    next = (_bdf_line_func_t *)call_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2008
    p    = (_bdf_parse_t *)    client_data;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2009
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2010
    if ( p->font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2011
      memory = p->font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2012
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2013
    /* Check for a comment.  This is done to handle those fonts that have */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2014
    /* comments before the STARTFONT line for some reason.                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2015
    if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2016
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2017
      if ( p->opts->keep_comments != 0 && p->font != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2018
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2019
        linelen -= 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2020
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2021
        s = line + 7;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2022
        if ( *s != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2023
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2024
          s++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2025
          linelen--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2026
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2027
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2028
        error = _bdf_add_comment( p->font, s, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2029
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2030
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2031
        /* here font is not defined! */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2032
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2033
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2034
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2035
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2036
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2037
    if ( !( p->flags & _BDF_START ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2038
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2039
      memory = p->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2040
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2041
      if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2042
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2043
        /* No STARTFONT field is a good indication of a problem. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2044
        error = BDF_Err_Missing_Startfont_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2045
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2046
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2048
      p->flags = _BDF_START;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2049
      font = p->font = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2050
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2051
      if ( FT_NEW( font ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2052
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2053
      p->font = font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2054
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2055
      font->memory = p->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2056
      p->memory    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2057
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2058
      { /* setup */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2059
        size_t           i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2060
        bdf_property_t*  prop;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2061
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2062
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2063
        error = hash_init( &(font->proptbl), memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2064
        if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2065
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2066
        for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2067
              i < _num_bdf_properties; i++, prop++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2068
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2069
          error = hash_insert( prop->name, i,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2070
                               &(font->proptbl), memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2071
          if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2072
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2073
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2074
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2076
      if ( FT_ALLOC( p->font->internal, sizeof ( hashtable ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2077
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2078
      error = hash_init( (hashtable *)p->font->internal,memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2079
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2080
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2081
      p->font->spacing      = p->opts->font_spacing;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2082
      p->font->default_char = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2083
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2084
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2085
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2086
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2087
    /* Check for the start of the properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2088
    if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2089
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2090
      if ( !( p->flags & _BDF_FONT_BBX ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2091
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2092
        /* Missing the FONTBOUNDINGBOX field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2093
        FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2094
        error = BDF_Err_Missing_Fontboundingbox_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2095
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2096
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2098
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2099
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2100
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2101
      /* at this point, `p->font' can't be NULL */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2102
      p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2103
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2104
      if ( FT_NEW_ARRAY( p->font->props, p->cnt ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2105
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2107
      p->flags |= _BDF_PROPS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2108
      *next     = _bdf_parse_properties;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2110
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2111
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2113
    /* Check for the FONTBOUNDINGBOX field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2114
    if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2115
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2116
      if ( !( p->flags & _BDF_SIZE ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2117
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2118
        /* Missing the SIZE field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2119
        FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2120
        error = BDF_Err_Missing_Size_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2121
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2122
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2124
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2125
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2126
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2128
      p->font->bbx.width  = _bdf_atos( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2129
      p->font->bbx.height = _bdf_atos( p->list.field[2], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2130
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2131
      p->font->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2132
      p->font->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2134
      p->font->bbx.ascent  = (short)( p->font->bbx.height +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2135
                                      p->font->bbx.y_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2137
      p->font->bbx.descent = (short)( -p->font->bbx.y_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2139
      p->flags |= _BDF_FONT_BBX;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2141
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2142
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2144
    /* The next thing to check for is the FONT field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2145
    if ( ft_memcmp( line, "FONT", 4 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2146
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2147
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2148
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2149
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2150
      _bdf_list_shift( &p->list, 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2151
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2152
      s = _bdf_list_join( &p->list, ' ', &slen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2154
      if ( !s )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2155
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2156
        error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2157
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2158
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2160
      /* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2161
      FT_FREE( p->font->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2163
      if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2164
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2165
      FT_MEM_COPY( p->font->name, s, slen + 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2167
      /* If the font name is an XLFD name, set the spacing to the one in  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2168
      /* the font name.  If there is no spacing fall back on the default. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2169
      error = _bdf_set_default_spacing( p->font, p->opts );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2170
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2171
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2173
      p->flags |= _BDF_FONT_NAME;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2175
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2176
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2178
    /* Check for the SIZE field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2179
    if ( ft_memcmp( line, "SIZE", 4 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2180
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2181
      if ( !( p->flags & _BDF_FONT_NAME ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2182
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2183
        /* Missing the FONT field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2184
        FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2185
        error = BDF_Err_Missing_Font_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2186
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2187
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2189
      error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2190
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2191
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2193
      p->font->point_size   = _bdf_atoul( p->list.field[1], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2194
      p->font->resolution_x = _bdf_atoul( p->list.field[2], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2195
      p->font->resolution_y = _bdf_atoul( p->list.field[3], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2197
      /* Check for the bits per pixel field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2198
      if ( p->list.used == 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2199
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2200
        unsigned short bitcount, i, shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2202
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2203
        p->font->bpp = (unsigned short)_bdf_atos( p->list.field[4], 0, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2205
        /* Only values 1, 2, 4, 8 are allowed. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2206
        shift = p->font->bpp;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2207
        bitcount = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2208
        for ( i = 0; shift > 0; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2209
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2210
          if ( shift & 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2211
            bitcount = i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2212
          shift >>= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2213
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2214
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2215
        shift = (short)( ( bitcount > 3 ) ? 8 : ( 1 << bitcount ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2216
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2217
        if ( p->font->bpp > shift || p->font->bpp != shift )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2218
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2219
          /* select next higher value */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2220
          p->font->bpp = (unsigned short)( shift << 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2221
          FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2222
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2223
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2224
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2225
        p->font->bpp = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2227
      p->flags |= _BDF_SIZE;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2228
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2229
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2230
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2231
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2232
    /* Check for the CHARS field -- font properties are optional */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2233
    if ( ft_memcmp( line, "CHARS", 5 ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2234
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2235
      char  nbuf[128];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2237
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2238
      if ( !( p->flags & _BDF_FONT_BBX ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2239
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2240
        /* Missing the FONTBOUNDINGBOX field. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2241
        FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2242
        error = BDF_Err_Missing_Fontboundingbox_Field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2243
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2244
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2246
      /* Add the two standard X11 properties which are required */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2247
      /* for compiling fonts.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2248
      p->font->font_ascent = p->font->bbx.ascent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2249
      ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2250
      error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", nbuf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2251
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2252
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2253
      FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2255
      p->font->font_descent = p->font->bbx.descent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2256
      ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2257
      error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", nbuf );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2258
      if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2259
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2260
      FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2262
      p->font->modified = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2264
      *next = _bdf_parse_glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2266
      /* A special return value. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2267
      error = -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2268
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2269
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2270
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2271
    error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2273
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2274
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2275
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2276
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2277
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2278
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2279
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2280
  /* API.                                                                  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2281
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2282
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2284
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2285
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2286
  bdf_load_font( FT_Stream       stream,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2287
                 FT_Memory       extmemory,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2288
                 bdf_options_t*  opts,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2289
                 bdf_font_t*    *font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2290
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2291
    unsigned long  lineno = 0; /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2292
    _bdf_parse_t   *p     = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2294
    FT_Memory      memory = extmemory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2295
    FT_Error       error  = BDF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2296
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2297
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2298
    if ( FT_NEW( p ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2299
      goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2300
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2301
    memory    = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2302
    p->opts   = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2303
    p->minlb  = 32767;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2304
    p->memory = extmemory;  /* only during font creation */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2305
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2306
    _bdf_list_init( &p->list, extmemory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2307
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2308
    error = _bdf_readstream( stream, _bdf_parse_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2309
                             (void *)p, &lineno );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2310
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2311
      goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2312
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2313
    if ( p->font != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2314
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2315
      /* If the font is not proportional, set the font's monowidth */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2316
      /* field to the width of the font bounding box.              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2317
      memory = p->font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2318
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2319
      if ( p->font->spacing != BDF_PROPORTIONAL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2320
        p->font->monowidth = p->font->bbx.width;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2321
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2322
      /* If the number of glyphs loaded is not that of the original count, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2323
      /* indicate the difference.                                          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2324
      if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2325
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2326
        FT_TRACE2(( "bdf_load_font: " ACMSG15, p->cnt,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2327
                    p->font->glyphs_used + p->font->unencoded_used ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2328
        p->font->modified = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2329
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2331
      /* Once the font has been loaded, adjust the overall font metrics if */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2332
      /* necessary.                                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2333
      if ( p->opts->correct_metrics != 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2334
           ( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2335
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2336
        if ( p->maxrb - p->minlb != p->font->bbx.width )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2337
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2338
          FT_TRACE2(( "bdf_load_font: " ACMSG3,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2339
                      p->font->bbx.width, p->maxrb - p->minlb ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2340
          p->font->bbx.width = (unsigned short)( p->maxrb - p->minlb );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2341
          p->font->modified  = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2342
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2343
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2344
        if ( p->font->bbx.x_offset != p->minlb )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2345
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2346
          FT_TRACE2(( "bdf_load_font: " ACMSG4,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2347
                      p->font->bbx.x_offset, p->minlb ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2348
          p->font->bbx.x_offset = p->minlb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2349
          p->font->modified     = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2350
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2352
        if ( p->font->bbx.ascent != p->maxas )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2353
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2354
          FT_TRACE2(( "bdf_load_font: " ACMSG5,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2355
                      p->font->bbx.ascent, p->maxas ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2356
          p->font->bbx.ascent = p->maxas;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2357
          p->font->modified   = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2358
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2360
        if ( p->font->bbx.descent != p->maxds )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2361
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2362
          FT_TRACE2(( "bdf_load_font: " ACMSG6,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2363
                      p->font->bbx.descent, p->maxds ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2364
          p->font->bbx.descent  = p->maxds;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2365
          p->font->bbx.y_offset = (short)( -p->maxds );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2366
          p->font->modified     = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2367
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2368
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2369
        if ( p->maxas + p->maxds != p->font->bbx.height )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2370
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2371
          FT_TRACE2(( "bdf_load_font: " ACMSG7,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2372
                      p->font->bbx.height, p->maxas + p->maxds ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2373
          p->font->bbx.height = (unsigned short)( p->maxas + p->maxds );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2374
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2375
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2376
        if ( p->flags & _BDF_SWIDTH_ADJ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2377
          FT_TRACE2(( "bdf_load_font: " ACMSG8 ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2378
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2379
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2381
    if ( p->flags & _BDF_START )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2382
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2383
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2384
        /* The ENDFONT field was never reached or did not exist. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2385
        if ( !( p->flags & _BDF_GLYPHS ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2386
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2387
          /* Error happened while parsing header. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2388
          FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2389
          error = BDF_Err_Corrupted_Font_Header;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2390
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2391
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2392
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2393
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2394
          /* Error happened when parsing glyphs. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2395
          FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2396
          error = BDF_Err_Corrupted_Font_Glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2397
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2398
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2399
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2400
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2402
    if ( p->font != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2403
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2404
      /* Make sure the comments are NULL terminated if they exist. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2405
      memory = p->font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2406
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2407
      if ( p->font->comments_len > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2408
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2409
        if ( FT_RENEW_ARRAY( p->font->comments,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2410
                             p->font->comments_len,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2411
                             p->font->comments_len + 1 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2412
          goto Fail;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2414
        p->font->comments[p->font->comments_len] = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2415
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2416
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2417
    else if ( error == BDF_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2418
      error = BDF_Err_Invalid_File_Format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2419
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2420
    *font = p->font;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2422
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2423
    if ( p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2424
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2425
      _bdf_list_done( &p->list );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2427
      memory = extmemory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2428
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2429
      FT_FREE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2430
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2432
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2434
  Fail:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2435
    bdf_free_font( p->font );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2437
    memory = extmemory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2438
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2439
    FT_FREE( p->font );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2441
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2442
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2443
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2444
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2445
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2446
  bdf_free_font( bdf_font_t*  font )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2447
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2448
    bdf_property_t*  prop;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2449
    unsigned long    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2450
    bdf_glyph_t*     glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2451
    FT_Memory        memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2452
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2454
    if ( font == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2455
      return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2457
    memory = font->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2458
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2459
    FT_FREE( font->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2460
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2461
    /* Free up the internal hash table of property names. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2462
    if ( font->internal )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2463
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2464
      hash_free( (hashtable *)font->internal, memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2465
      FT_FREE( font->internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2466
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2468
    /* Free up the comment info. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2469
    FT_FREE( font->comments );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2471
    /* Free up the properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2472
    for ( i = 0; i < font->props_size; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2473
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2474
      if ( font->props[i].format == BDF_ATOM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2475
        FT_FREE( font->props[i].value.atom );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2476
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2478
    FT_FREE( font->props );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2479
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2480
    /* Free up the character info. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2481
    for ( i = 0, glyphs = font->glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2482
          i < font->glyphs_used; i++, glyphs++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2483
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2484
      FT_FREE( glyphs->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2485
      FT_FREE( glyphs->bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2486
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2488
    for ( i = 0, glyphs = font->unencoded; i < font->unencoded_used;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2489
          i++, glyphs++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2490
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2491
      FT_FREE( glyphs->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2492
      FT_FREE( glyphs->bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2493
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2495
    FT_FREE( font->glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2496
    FT_FREE( font->unencoded );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2498
    /* Free up the overflow storage if it was used. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2499
    for ( i = 0, glyphs = font->overflow.glyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2500
          i < font->overflow.glyphs_used; i++, glyphs++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2501
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2502
      FT_FREE( glyphs->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2503
      FT_FREE( glyphs->bitmap );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2504
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2505
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2506
    FT_FREE( font->overflow.glyphs );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2507
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2508
    /* bdf_cleanup */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2509
    hash_free( &(font->proptbl), memory );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2511
    /* Free up the user defined properties. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2512
    for ( prop = font->user_props, i = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2513
          i < font->nuser_props; i++, prop++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2514
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2515
      FT_FREE( prop->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2516
      if ( prop->format == BDF_ATOM )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2517
        FT_FREE( prop->value.atom );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2518
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2520
    FT_FREE( font->user_props );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2521
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2522
    /* FREE( font ); */ /* XXX Fixme */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2523
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2524
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2526
  FT_LOCAL_DEF( bdf_property_t * )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2527
  bdf_get_font_property( bdf_font_t*  font,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2528
                         const char*  name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2529
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2530
    hashnode  hn;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2531
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2532
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2533
    if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2534
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2535
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2536
    hn = hash_lookup( name, (hashtable *)font->internal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2538
    return hn ? ( font->props + hn->data ) : 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2539
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2540
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  2542
/* END */