1 /************************************************************************
2 Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
6 Permission to use, copy, modify, and distribute this software and its
7 documentation for any purpose and without fee is hereby granted,
8 provided that the above copyright notice appear in all copies and that
9 both that copyright notice and this permission notice appear in
10 supporting documentation, and that the name of Digital not be
11 used in advertising or publicity pertaining to distribution of the
12 software without specific, written prior permission.
14 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 ************************************************************************/
26 Copyright 1994, 1998 The Open Group
28 Permission to use, copy, modify, distribute, and sell this software and its
29 documentation for any purpose is hereby granted without fee, provided that
30 the above copyright notice appear in all copies and that both that
31 copyright notice and this permission notice appear in supporting
34 The above copyright notice and this permission notice shall be included
35 in all copies or substantial portions of the Software.
37 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
38 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
41 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
42 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43 OTHER DEALINGS IN THE SOFTWARE.
45 Except as contained in this notice, the name of The Open Group shall
46 not be used in advertising or otherwise to promote the sale, use or
47 other dealings in this Software without prior written authorization
60 #include <X11/fonts/fntfilst.h>
61 #include <X11/fonts/fontstruct.h>
62 /* use bitmap structure */
63 #include <X11/fonts/bitmap.h>
64 #include <X11/fonts/bdfint.h>
68 /***====================================================================***/
71 bdfError(const char* message, ...)
75 va_start (args, message);
76 fprintf(stderr, "BDF Error on line %d: ", bdfFileLineNum);
77 vfprintf(stderr, message, args);
81 /***====================================================================***/
84 bdfWarning(const char *message, ...)
88 va_start (args, message);
89 fprintf(stderr, "BDF Warning on line %d: ", bdfFileLineNum);
90 vfprintf(stderr, message, args);
95 * read the next (non-comment) line and keep a count for error messages.
96 * Returns buf, or NULL if EOF.
100 bdfGetLine(FontFilePtr file, unsigned char *buf, int len)
107 while ((c = FontFileGetc(file)) != FontFileEOF) {
114 if (b - buf >= (len - 1))
119 if (c == FontFileEOF)
121 if (b != buf && !bdfIsPrefix(buf, "COMMENT"))
127 /***====================================================================***/
130 bdfForceMakeAtom(const char *str, int *size)
132 register int len = strlen(str);
137 the_atom = MakeAtom(str, len, TRUE);
138 if (the_atom == None)
139 bdfError("Atom allocation failed\n");
143 /***====================================================================***/
146 * Handle quoted strings.
150 bdfGetPropertyValue(char *s)
157 /* strip leading white space */
158 while (*s && (*s == ' ' || *s == '\t'))
161 return bdfForceMakeAtom(s, NULL);
165 /* no white space in value */
166 for (pp = s; *pp; pp++)
167 if (*pp == ' ' || *pp == '\t' || *pp == '\015' || *pp == '\n') {
171 return bdfForceMakeAtom(s, NULL);
173 /* quoted string: strip outer quotes and undouble inner quotes */
175 pp = p = malloc((unsigned) strlen(s) + 1);
177 bdfError("Couldn't allocate property value string (%d)\n",
178 (int) strlen(s) + 1);
183 if (*(s + 1) != '"') {
185 atom = bdfForceMakeAtom(pp, NULL);
195 bdfError("unterminated quoted string property: %s\n", orig_s);
199 /***====================================================================***/
202 * return TRUE if string is a valid integer
205 bdfIsInteger(char *str)
210 if (!(isdigit(c) || c == '-' || c == '+'))
220 /***====================================================================***/
223 * make a byte from the first two hex characters in glyph picture
227 bdfHexByte(unsigned char *s)
233 for (i = 2; i; i--) {
235 if ((c >= '0') && (c <= '9'))
236 b = (b << 4) + (c - '0');
237 else if ((c >= 'A') && (c <= 'F'))
238 b = (b << 4) + 10 + (c - 'A');
239 else if ((c >= 'a') && (c <= 'f'))
240 b = (b << 4) + 10 + (c - 'a');
242 bdfError("bad hex char '%c'", c);
247 /***====================================================================***/
250 * check for known special property values
253 static const char *SpecialAtoms[] = {
255 #define BDF_FONT_ASCENT 0
257 #define BDF_FONT_DESCENT 1
259 #define BDF_DEFAULT_CHAR 2
261 #define BDF_POINT_SIZE 3
263 #define BDF_RESOLUTION 4
265 #define BDF_X_HEIGHT 5
269 #define BDF_QUAD_WIDTH 7
273 #define BDF_RESOLUTION_X 9
275 #define BDF_RESOLUTION_Y 10
280 bdfSpecialProperty(FontPtr pFont, FontPropPtr prop,
281 char isString, bdfFileState *bdfState)
283 const char **special;
286 name = NameForAtom(prop->name);
287 for (special = SpecialAtoms; *special; special++)
288 if (!strcmp(name, *special))
291 switch (special - SpecialAtoms) {
292 case BDF_FONT_ASCENT:
294 pFont->info.fontAscent = prop->value;
295 bdfState->haveFontAscent = TRUE;
298 case BDF_FONT_DESCENT:
300 pFont->info.fontDescent = prop->value;
301 bdfState->haveFontDescent = TRUE;
304 case BDF_DEFAULT_CHAR:
306 pFont->info.defaultCh = prop->value;
307 bdfState->haveDefaultCh = TRUE;
311 bdfState->pointSizeProp = prop;
314 bdfState->resolutionProp = prop;
317 bdfState->xHeightProp = prop;
320 bdfState->weightProp = prop;
323 bdfState->quadWidthProp = prop;
326 bdfState->fontProp = prop;
328 case BDF_RESOLUTION_X:
329 bdfState->resolutionXProp = prop;
331 case BDF_RESOLUTION_Y:
332 bdfState->resolutionYProp = prop;