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