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(char* message, ...)
75 va_start (args, message);
76 fprintf(stderr, "BDF Error on line %d: ", bdfFileLineNum);
77 vfprintf(stderr, message, args);
81 /***====================================================================***/
84 bdfWarning(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(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", strlen(s) + 1);
182 if (*(s + 1) != '"') {
184 atom = bdfForceMakeAtom(pp, NULL);
194 bdfError("unterminated quoted string property: %s\n", (pointer) orig_s);
198 /***====================================================================***/
201 * return TRUE if string is a valid integer
204 bdfIsInteger(char *str)
209 if (!(isdigit(c) || c == '-' || c == '+'))
219 /***====================================================================***/
222 * make a byte from the first two hex characters in glyph picture
226 bdfHexByte(unsigned char *s)
232 for (i = 2; i; i--) {
234 if ((c >= '0') && (c <= '9'))
235 b = (b << 4) + (c - '0');
236 else if ((c >= 'A') && (c <= 'F'))
237 b = (b << 4) + 10 + (c - 'A');
238 else if ((c >= 'a') && (c <= 'f'))
239 b = (b << 4) + 10 + (c - 'a');
241 bdfError("bad hex char '%c'", c);
246 /***====================================================================***/
249 * check for known special property values
252 static char *SpecialAtoms[] = {
254 #define BDF_FONT_ASCENT 0
256 #define BDF_FONT_DESCENT 1
258 #define BDF_DEFAULT_CHAR 2
260 #define BDF_POINT_SIZE 3
262 #define BDF_RESOLUTION 4
264 #define BDF_X_HEIGHT 5
268 #define BDF_QUAD_WIDTH 7
272 #define BDF_RESOLUTION_X 9
274 #define BDF_RESOLUTION_Y 10
279 bdfSpecialProperty(FontPtr pFont, FontPropPtr prop,
280 char isString, bdfFileState *bdfState)
285 name = NameForAtom(prop->name);
286 for (special = SpecialAtoms; *special; special++)
287 if (!strcmp(name, *special))
290 switch (special - SpecialAtoms) {
291 case BDF_FONT_ASCENT:
293 pFont->info.fontAscent = prop->value;
294 bdfState->haveFontAscent = TRUE;
297 case BDF_FONT_DESCENT:
299 pFont->info.fontDescent = prop->value;
300 bdfState->haveFontDescent = TRUE;
303 case BDF_DEFAULT_CHAR:
305 pFont->info.defaultCh = prop->value;
306 bdfState->haveDefaultCh = TRUE;
310 bdfState->pointSizeProp = prop;
313 bdfState->resolutionProp = prop;
316 bdfState->xHeightProp = prop;
319 bdfState->weightProp = prop;
322 bdfState->quadWidthProp = prop;
325 bdfState->fontProp = prop;
327 case BDF_RESOLUTION_X:
328 bdfState->resolutionXProp = prop;
330 case BDF_RESOLUTION_Y:
331 bdfState->resolutionYProp = prop;