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