/* * Copyright 1999 Computing Research Labs, New Mexico State University * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * 13 April 1999 * Mark Leisher */ #include #include #include #include #include #define isdig(cc) ((cc) >= '0' && (cc) <= '9') /* * Macro to test if a bitmap contains a code or not. */ #define hasglyph(code, bitmap) (bitmap[(code) >> 5] & (1 << ((code) & 31))) Bool #ifdef __STDC__ get_ranges(Display *dpy, XFontStruct *font, unsigned long *mincode, unsigned long *maxcode, unsigned long bitmap[]) #else get_ranges(dpy, font, mincode, maxcode, bitmap) Display *dpy; XFontStruct *font; unsigned long *mincode, *maxcode, bitmap[]; #endif { long i, l, r; char *s, *p; XFontProp *xfp; Atom prop; *mincode = ~0; *maxcode = 0; /* * Make an atom from the name so it can be used to locate font properties * quickly. */ prop = XInternAtom(dpy, "_XFREE86_GLYPH_RANGES", False); /* * Clear the first 2048 spots in the `bitmap' array. It is assumed to * have at least 2048 elements available. */ (void) memset((char *) bitmap, 0, sizeof(unsigned long) * 2048); /* * Cycle through the font and locate the properties matching * _XFREE86_GLYPH_RANGES and parse each one of these into the bitmap. */ for (i = 0, xfp = font->properties; i < font->n_properties; i++, xfp++) { if (xfp->name == prop) { p = s = XGetAtomName(dpy, (Atom) xfp->card32); while (*s) { /* * Collect the next code value. */ for (l = r = 0; *s && isdig(*s); s++) l = (l * 10) + (*s - '0'); /* * If the next character is an '_', advance and collect the * end of the specified range. */ if (*s == '_') { s++; for (; *s && isdig(*s); s++) r = (r * 10) + (*s - '0'); } else r = l; /* * Add the range just collected to the bitmap and set the * minimum and maximum codes seen. */ if (l <= r) { if (r > *maxcode) *maxcode = r; if (l < *mincode) *mincode = l; for (; l <= r; l++) bitmap[l >> 5] |= (1 << (l & 31)); } /* * Skip all non-digit characters. */ while (*s && !isdig(*s)) s++; } /* * Free the string returned by the X library. */ XFree(p); } } return (*mincode != ~0) ? True : False; } #ifdef TEST int #ifdef __STDC__ main(int argc, char *argv[]) #else main(argc, argv) int argc; char *argv[]; #endif { Display *d; XFontStruct *f; unsigned long min, max, bitmap[2048]; if (argc < 2) { fprintf(stderr, "Usage: %s xlfdname\n", argv[0]); return 1; } if ((d = XOpenDisplay(0)) == 0) { fprintf(stderr, "%s: unable to open display.\n", argv[0]); return 1; } if ((f = XLoadQueryFont(d, argv[1])) == 0) { XCloseDisplay(d); fprintf(stderr, "%s: unable to load font '%s'.\n", argv[0], argv[1]); return 1; } if (get_ranges(d, f, &min, &max, bitmap) == True) fprintf(stderr, "Font has glyph ranges %ld - %ld\n", min, max); else fprintf(stderr, "Font has no glyph ranges.\n"); XFreeFont(d, f); XCloseDisplay(d); return 0; } #endif /* TEST */