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