3 Copyright 1991, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * Author: Keith Packard, MIT X Consortium
36 * Translate monolithic #defines to modular definitions
40 #define XFONT_PCFFORMAT 1
44 #define XFONT_SNFFORMAT 1
48 #define XFONT_BDFFORMAT 1
51 #include <X11/fonts/fntfilst.h>
52 #include <X11/fonts/bitmap.h>
53 #include <X11/fonts/fontutil.h>
54 #include <X11/fonts/bdfint.h>
55 #include <X11/fonts/pcf.h>
58 typedef struct _BitmapFileFunctions {
59 int (*ReadFont) (FontPtr /* pFont */, FontFilePtr /* file */,
60 int /* bit */, int /* byte */,
61 int /* glyph */, int /* scan */);
62 int (*ReadInfo) ( FontInfoPtr /* pFontInfo */,
63 FontFilePtr /* file */ );
64 } BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
66 static int BitmapGetRenderIndex(FontRendererPtr renderer);
69 * the readers[] and renderers[] arrays must be in the same order,
70 * and also in the same order as scale[] and find_scale[] in bitscale.c
73 static BitmapFileFunctionsRec readers[] = {
75 { pcfReadFont, pcfReadFontInfo} ,
76 { pcfReadFont, pcfReadFontInfo} ,
77 # ifdef X_GZIP_FONT_COMPRESSION
78 { pcfReadFont, pcfReadFontInfo} ,
80 # ifdef X_BZIP2_FONT_COMPRESSION
81 { pcfReadFont, pcfReadFontInfo} ,
85 { snfReadFont, snfReadFontInfo},
86 { snfReadFont, snfReadFontInfo},
87 # ifdef X_GZIP_FONT_COMPRESSION
88 { snfReadFont, snfReadFontInfo} ,
90 # ifdef X_BZIP2_FONT_COMPRESSION
91 { snfReadFont, snfReadFontInfo} ,
95 { bdfReadFont, bdfReadFontInfo} ,
96 { bdfReadFont, bdfReadFontInfo} ,
97 # ifdef X_GZIP_FONT_COMPRESSION
98 { bdfReadFont, bdfReadFontInfo} ,
100 # ifdef X_BZIP2_FONT_COMPRESSION
101 { bdfReadFont, bdfReadFontInfo} ,
107 #define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
110 BitmapOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags,
111 FontEntryPtr entry, char *fileName,
112 fsBitmapFormat format, fsBitmapFormatMask fmask,
113 FontPtr non_cachable_font) /* We don't do licensing */
125 i = BitmapGetRenderIndex(entry->u.bitmap.renderer);
126 file = FontFileOpen (fileName);
129 if (!(pFont = CreateFontRec())) {
130 fprintf(stderr, "Error: Couldn't allocate pFont (%ld)\n",
131 (unsigned long)sizeof(FontRec));
132 FontFileClose (file);
135 /* set up default values */
136 FontDefaultFormat(&bit, &byte, &glyph, &scan);
137 /* get any changes made from above */
138 ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
140 /* Fill in font record. Data format filled in by reader. */
143 ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
145 FontFileClose (file);
146 if (ret != Successful) {
155 BitmapGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
156 FontEntryPtr entry, char *fileName)
161 FontRendererPtr renderer;
163 renderer = FontFileMatchRenderer (fileName);
166 i = BitmapGetRenderIndex(renderer);
167 file = FontFileOpen (fileName);
170 ret = (*readers[i].ReadInfo) (pFontInfo, file);
171 FontFileClose (file);
175 static FontRendererRec renderers[] = {
177 { ".pcf", 4, BitmapOpenBitmap, BitmapOpenScalable,
178 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
180 { ".pcf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
181 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
183 # ifdef X_GZIP_FONT_COMPRESSION
185 BitmapOpenBitmap, BitmapOpenScalable,
186 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
189 # ifdef X_BZIP2_FONT_COMPRESSION
191 BitmapOpenBitmap, BitmapOpenScalable,
192 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
197 { ".snf", 4, BitmapOpenBitmap, BitmapOpenScalable,
198 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
200 { ".snf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
201 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
203 # ifdef X_GZIP_FONT_COMPRESSION
204 { ".snf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable,
205 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
208 # ifdef X_BZIP2_FONT_COMPRESSION
209 { ".snf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable,
210 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
215 { ".bdf", 4, BitmapOpenBitmap, BitmapOpenScalable,
216 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
218 { ".bdf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
219 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
221 # ifdef X_GZIP_FONT_COMPRESSION
222 { ".bdf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable,
223 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
226 # ifdef X_BZIP2_FONT_COMPRESSION
227 { ".bdf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable,
228 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
234 #define numRenderers (sizeof renderers / sizeof renderers[0])
237 BitmapRegisterFontFileFunctions (void)
241 for (i = 0; i < numRenderers; i++)
242 FontFileRegisterRenderer (&renderers[i]);
246 * compute offset into renderers array - used to find the font reader,
247 * the font info reader, and the bitmap scaling routine. All users
248 * of this routine must be kept in step with the renderer array.
251 BitmapGetRenderIndex(FontRendererPtr renderer)
253 return renderer - renderers;