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