1 /* $XConsortium: bdfutils.c,v 1.11 94/04/17 20:17:10 gildea Exp $ */
2 /************************************************************************
3 Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the name of Digital not be
12 used in advertising or publicity pertaining to distribution of the
13 software without specific, written prior permission.
15 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 ************************************************************************/
27 Copyright (c) 1994 X Consortium
29 Permission is hereby granted, free of charge, to any person obtaining
30 a copy of this software and associated documentation files (the
31 "Software"), to deal in the Software without restriction, including
32 without limitation the rights to use, copy, modify, merge, publish,
33 distribute, sublicense, and/or sell copies of the Software, and to
34 permit persons to whom the Software is furnished to do so, subject to
35 the following conditions:
37 The above copyright notice and this permission notice shall be included
38 in all copies or substantial portions of the Software.
40 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
41 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 OTHER DEALINGS IN THE SOFTWARE.
48 Except as contained in this notice, the name of the X Consortium shall
49 not be used in advertising or otherwise to promote the sale, use or
50 other dealings in this Software without prior written authorization
51 from the X Consortium.
59 #include "fontstruct.h"
60 /* use bitmap structure */
66 /***====================================================================***/
70 bdfError(message, a0, a1, a2, a3, a4, a5)
79 fprintf(stderr, "BDF Error on line %d: ", bdfFileLineNum);
80 fprintf(stderr, message, a0, a1, a2, a3, a4, a5);
83 /***====================================================================***/
87 bdfWarning(message, a0, a1, a2, a3, a4, a5)
96 fprintf(stderr, "BDF Warning on line %d: ", bdfFileLineNum);
97 fprintf(stderr, message, a0, a1, a2, a3, a4, a5);
101 * read the next (non-comment) line and keep a count for error messages.
102 * Returns buf, or NULL if EOF.
106 bdfGetLine(file, buf, len)
116 while ((c = FontFileGetc(file)) != FontFileEOF) {
123 if (b - buf >= (len - 1))
128 if (c == FontFileEOF)
130 if (b != buf && !bdfIsPrefix(buf, "COMMENT"))
136 /***====================================================================***/
139 bdfForceMakeAtom(str, size)
143 register int len = strlen(str);
144 extern Atom MakeAtom();
148 return MakeAtom(str, len, TRUE);
151 /***====================================================================***/
154 * Handle quoted strings.
158 bdfGetPropertyValue(s)
166 /* strip leading white space */
167 while (*s && (*s == ' ' || *s == '\t'))
170 return bdfForceMakeAtom(s, NULL);
174 /* no white space in value */
175 for (pp = s; *pp; pp++)
176 if (*pp == ' ' || *pp == '\t' || *pp == '\015' || *pp == '\n') {
180 return bdfForceMakeAtom(s, NULL);
182 /* quoted string: strip outer quotes and undouble inner quotes */
184 pp = p = (char *) xalloc((unsigned) strlen(s) + 1);
187 if (*(s + 1) != '"') {
189 atom = bdfForceMakeAtom(pp, NULL);
199 bdfError("unterminated quoted string property: %s\n", (pointer) orig_s);
203 /***====================================================================***/
206 * return TRUE if string is a valid integer
215 if (!(isdigit(c) || c == '-' || c == '+'))
225 /***====================================================================***/
228 * make a byte from the first two hex characters in glyph picture
239 for (i = 2; i; i--) {
241 if ((c >= '0') && (c <= '9'))
242 b = (b << 4) + (c - '0');
243 else if ((c >= 'A') && (c <= 'F'))
244 b = (b << 4) + 10 + (c - 'A');
245 else if ((c >= 'a') && (c <= 'f'))
246 b = (b << 4) + 10 + (c - 'a');
248 bdfError("bad hex char '%c'", c);
253 /***====================================================================***/
256 * check for known special property values
259 static char *SpecialAtoms[] = {
261 #define BDF_FONT_ASCENT 0
263 #define BDF_FONT_DESCENT 1
265 #define BDF_DEFAULT_CHAR 2
267 #define BDF_POINT_SIZE 3
269 #define BDF_RESOLUTION 4
271 #define BDF_X_HEIGHT 5
275 #define BDF_QUAD_WIDTH 7
279 #define BDF_RESOLUTION_X 9
281 #define BDF_RESOLUTION_Y 10
286 bdfSpecialProperty(pFont, prop, isString, bdfState)
290 bdfFileState *bdfState;
295 name = NameForAtom(prop->name);
296 for (special = SpecialAtoms; *special; special++)
297 if (!strcmp(name, *special))
300 switch (special - SpecialAtoms) {
301 case BDF_FONT_ASCENT:
303 pFont->info.fontAscent = prop->value;
304 bdfState->haveFontAscent = TRUE;
307 case BDF_FONT_DESCENT:
309 pFont->info.fontDescent = prop->value;
310 bdfState->haveFontDescent = TRUE;
313 case BDF_DEFAULT_CHAR:
315 pFont->info.defaultCh = prop->value;
316 bdfState->haveDefaultCh = TRUE;
320 bdfState->pointSizeProp = prop;
323 bdfState->resolutionProp = prop;
326 bdfState->xHeightProp = prop;
329 bdfState->weightProp = prop;
332 bdfState->quadWidthProp = prop;
335 bdfState->fontProp = prop;
337 case BDF_RESOLUTION_X:
338 bdfState->resolutionXProp = prop;
340 case BDF_RESOLUTION_Y:
341 bdfState->resolutionYProp = prop;