1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | #ifdef HAVE_CONFIG_H1 |
32 | #include <config.h> |
33 | #endif |
34 | |
35 | #include <X11/fonts/fntfilst.h> |
36 | #include <X11/fonts/bitmap.h> |
37 | #include <X11/fonts/fontutil.h> |
38 | #if XFONT_BDFFORMAT1 |
39 | #include <X11/fonts/bdfint.h> |
40 | #endif |
41 | #if XFONT_PCFFORMAT1 |
42 | #include <X11/fonts/pcf.h> |
43 | #endif |
44 | #if XFONT_SNFFORMAT |
45 | #include "snfstr.h" |
46 | #endif |
47 | |
48 | #if XFONT_PCFFORMAT1 || XFONT_SNFFORMAT || XFONT_BDFFORMAT1 |
49 | typedef struct _BitmapFileFunctions { |
50 | int (*ReadFont) (FontPtr , FontFilePtr , |
51 | int , int , |
52 | int , int ); |
53 | int (*ReadInfo) ( FontInfoPtr , |
54 | FontFilePtr ); |
55 | } BitmapFileFunctionsRec, *BitmapFileFunctionsPtr; |
56 | |
57 | static int BitmapGetRenderIndex(FontRendererPtr renderer); |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | static BitmapFileFunctionsRec readers[] = { |
65 | #if XFONT_PCFFORMAT1 |
66 | { pcfReadFont, pcfReadFontInfo} , |
67 | { pcfReadFont, pcfReadFontInfo} , |
68 | # ifdef X_GZIP_FONT_COMPRESSION1 |
69 | { pcfReadFont, pcfReadFontInfo} , |
70 | # endif |
71 | # ifdef X_BZIP2_FONT_COMPRESSION |
72 | { pcfReadFont, pcfReadFontInfo} , |
73 | # endif |
74 | #endif |
75 | #if XFONT_SNFFORMAT |
76 | { snfReadFont, snfReadFontInfo}, |
77 | { snfReadFont, snfReadFontInfo}, |
78 | # ifdef X_GZIP_FONT_COMPRESSION1 |
79 | { snfReadFont, snfReadFontInfo} , |
80 | # endif |
81 | # ifdef X_BZIP2_FONT_COMPRESSION |
82 | { snfReadFont, snfReadFontInfo} , |
83 | # endif |
84 | #endif |
85 | #if XFONT_BDFFORMAT1 |
86 | { bdfReadFont, bdfReadFontInfo} , |
87 | { bdfReadFont, bdfReadFontInfo} , |
88 | # ifdef X_GZIP_FONT_COMPRESSION1 |
89 | { bdfReadFont, bdfReadFontInfo} , |
90 | # endif |
91 | # ifdef X_BZIP2_FONT_COMPRESSION |
92 | { bdfReadFont, bdfReadFontInfo} , |
93 | # endif |
94 | #endif |
95 | }; |
96 | |
97 | |
98 | #define CAPABILITIES(0x1 | 0x2) (CAP_MATRIX0x1 | CAP_CHARSUBSETTING0x2) |
99 | |
100 | static int |
101 | BitmapOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags, |
102 | FontEntryPtr entry, char *fileName, |
103 | fsBitmapFormat format, fsBitmapFormatMask fmask, |
104 | FontPtr non_cachable_font) |
105 | { |
106 | FontFilePtr file; |
107 | FontPtr pFont; |
108 | int i; |
109 | int ret; |
110 | int bit, |
111 | byte, |
112 | glyph, |
113 | scan, |
114 | image; |
115 | |
116 | i = BitmapGetRenderIndex(entry->u.bitmap.renderer); |
117 | file = FontFileOpen (fileName); |
118 | if (!file) |
119 | return BadFontName83; |
120 | if (!(pFont = CreateFontRec())) { |
121 | fprintf(stderr__stderrp, "Error: Couldn't allocate pFont (%ld)\n", |
122 | (unsigned long)sizeof(FontRec)); |
123 | FontFileClose (file); |
124 | return AllocError80; |
125 | } |
126 | |
127 | FontDefaultFormat(&bit, &byte, &glyph, &scan); |
128 | |
129 | ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image); |
| Value stored to 'ret' is never read |
130 | |
131 | |
132 | pFont->refcnt = 0; |
133 | |
134 | ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan); |
135 | |
136 | FontFileClose (file); |
137 | if (ret != Successful85) { |
138 | free(pFont); |
139 | } else { |
140 | *ppFont = pFont; |
141 | } |
142 | return ret; |
143 | } |
144 | |
145 | static int |
146 | BitmapGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo, |
147 | FontEntryPtr entry, char *fileName) |
148 | { |
149 | FontFilePtr file; |
150 | int i; |
151 | int ret; |
152 | FontRendererPtr renderer; |
153 | |
154 | renderer = FontFileMatchRenderer (fileName); |
155 | if (!renderer) |
156 | return BadFontName83; |
157 | i = BitmapGetRenderIndex(renderer); |
158 | file = FontFileOpen (fileName); |
159 | if (!file) |
160 | return BadFontName83; |
161 | ret = (*readers[i].ReadInfo) (pFontInfo, file); |
162 | FontFileClose (file); |
163 | return ret; |
164 | } |
165 | |
166 | static FontRendererRec renderers[] = { |
167 | #if XFONT_PCFFORMAT1 |
168 | { ".pcf", 4, BitmapOpenBitmap, BitmapOpenScalable, |
169 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
170 | CAPABILITIES(0x1 | 0x2) }, |
171 | { ".pcf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, |
172 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
173 | CAPABILITIES(0x1 | 0x2) }, |
174 | # ifdef X_GZIP_FONT_COMPRESSION1 |
175 | { ".pcf.gz", 7, |
176 | BitmapOpenBitmap, BitmapOpenScalable, |
177 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
178 | CAPABILITIES(0x1 | 0x2) }, |
179 | # endif |
180 | # ifdef X_BZIP2_FONT_COMPRESSION |
181 | { ".pcf.bz2", 8, |
182 | BitmapOpenBitmap, BitmapOpenScalable, |
183 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
184 | CAPABILITIES(0x1 | 0x2) }, |
185 | # endif |
186 | #endif |
187 | #if XFONT_SNFFORMAT |
188 | { ".snf", 4, BitmapOpenBitmap, BitmapOpenScalable, |
189 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
190 | CAPABILITIES(0x1 | 0x2) }, |
191 | { ".snf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, |
192 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
193 | CAPABILITIES(0x1 | 0x2) }, |
194 | # ifdef X_GZIP_FONT_COMPRESSION1 |
195 | { ".snf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable, |
196 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
197 | CAPABILITIES(0x1 | 0x2) }, |
198 | # endif |
199 | # ifdef X_BZIP2_FONT_COMPRESSION |
200 | { ".snf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable, |
201 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
202 | CAPABILITIES(0x1 | 0x2) }, |
203 | # endif |
204 | #endif |
205 | #if XFONT_BDFFORMAT1 |
206 | { ".bdf", 4, BitmapOpenBitmap, BitmapOpenScalable, |
207 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
208 | CAPABILITIES(0x1 | 0x2) }, |
209 | { ".bdf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, |
210 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
211 | CAPABILITIES(0x1 | 0x2) }, |
212 | # ifdef X_GZIP_FONT_COMPRESSION1 |
213 | { ".bdf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable, |
214 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
215 | CAPABILITIES(0x1 | 0x2) }, |
216 | # endif |
217 | # ifdef X_BZIP2_FONT_COMPRESSION |
218 | { ".bdf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable, |
219 | BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, |
220 | CAPABILITIES(0x1 | 0x2) }, |
221 | # endif |
222 | #endif |
223 | }; |
224 | |
225 | #define numRenderers(sizeof renderers / sizeof renderers[0]) (sizeof renderers / sizeof renderers[0]) |
226 | |
227 | void |
228 | BitmapRegisterFontFileFunctions (void) |
229 | { |
230 | int i; |
231 | |
232 | for (i = 0; i < numRenderers(sizeof renderers / sizeof renderers[0]); i++) |
233 | FontFileRegisterRenderer (&renderers[i]); |
234 | } |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | static int |
242 | BitmapGetRenderIndex(FontRendererPtr renderer) |
243 | { |
244 | return renderer - renderers; |
245 | } |
246 | |
247 | #else |
248 | void |
249 | BitmapRegisterFontFileFunctions (void) |
250 | { |
251 | |
252 | } |
253 | #endif /* XFONT_PCFFORMAT || XFONT_SNFFORMAT || XFONT_BDFFORMAT */ |