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