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