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