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