0
|
1 |
/*
|
|
2 |
* CDDL HEADER START
|
|
3 |
*
|
|
4 |
* The contents of this file are subject to the terms of the
|
|
5 |
* Common Development and Distribution License (the "License").
|
|
6 |
* You may not use this file except in compliance with the License.
|
|
7 |
*
|
|
8 |
* You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
|
|
9 |
* or http://www.opensolaris.org/os/licensing.
|
|
10 |
* See the License for the specific language governing permissions
|
|
11 |
* and limitations under the License.
|
|
12 |
*
|
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each
|
|
14 |
* file and include the License file at src/OPENSOLARIS.LICENSE.
|
|
15 |
* If applicable, add the following below this CDDL HEADER, with the
|
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
18 |
*
|
|
19 |
* CDDL HEADER END
|
|
20 |
*/
|
|
21 |
/*
|
|
22 |
* Copyright (c) 1999 by Sun Microsystems, Inc.
|
|
23 |
* All rights reserved.
|
|
24 |
*/
|
|
25 |
/*
|
|
26 |
* Copyright (C) 1994 X Consortium
|
|
27 |
*
|
|
28 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
29 |
* of this software and associated documentation files (the "Software"), to
|
|
30 |
* deal in the Software without restriction, including without limitation the
|
|
31 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
32 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
33 |
* furnished to do so, subject to the following conditions:
|
|
34 |
*
|
|
35 |
* The above copyright notice and this permission notice shall be included in
|
|
36 |
* all copies or substantial portions of the Software.
|
|
37 |
*
|
|
38 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
39 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
40 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
41 |
* X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
42 |
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
|
43 |
* TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
44 |
*
|
|
45 |
* Except as contained in this notice, the name of the X Consortium shall not
|
|
46 |
* be used in advertising or otherwise to promote the sale, use or other deal-
|
|
47 |
* ings in this Software without prior written authorization from the X Consor-
|
|
48 |
* tium.
|
|
49 |
*
|
|
50 |
* X Window System is a trademark of X Consortium, Inc.
|
|
51 |
*/
|
|
52 |
#pragma ident "@(#)pcf.c 1.3 00/02/02 SMI"
|
|
53 |
#include <stdio.h>
|
294
|
54 |
#include <fcntl.h>
|
|
55 |
#include <unistd.h>
|
|
56 |
#include <string.h>
|
0
|
57 |
#include <X11/Xmd.h>
|
|
58 |
#include <assert.h>
|
|
59 |
#include <errno.h>
|
|
60 |
#include "general_header.h"
|
|
61 |
#include "print_preprocess.h"
|
|
62 |
#include "pcf_private.h"
|
|
63 |
#include "pcf.h"
|
|
64 |
#define pcfGetINT8(file, format) (position++, FontFileGetc(file))
|
|
65 |
#define FileDes(f) ((int) (f)->private)
|
|
66 |
|
|
67 |
extern print_info *print_info_st;
|
|
68 |
|
|
69 |
static void dump_Fmetrics(pcffont_t *);
|
|
70 |
static code_int getcode(CompressedFile *);
|
|
71 |
static int BufFileClose(BufFilePtr,int);
|
|
72 |
static int get_font_property(FontPtr, char *, ulong_t *);
|
|
73 |
static BufFilePtr BufFileCreate ( char *, int (*)(), int (*)(),int (*)() );
|
|
74 |
static int BufCompressedClose(BufFilePtr, int);
|
|
75 |
static int BufCompressedSkip(BufFilePtr, int);
|
|
76 |
static int BufCompressedFill(BufFilePtr);
|
|
77 |
static BufFilePtr BufFilePushCompressed(BufFilePtr);
|
|
78 |
static FontFilePtr FontFileOpen(char *);
|
|
79 |
static void FontFileClose (FontFilePtr);
|
|
80 |
static int pcfGetLSB32(FontFilePtr);
|
|
81 |
static PCFTablePtr pcfReadTOC(FontFilePtr,int*);
|
|
82 |
static Bool pcfGetProperties(FontInfoPtr,FontFilePtr, PCFTablePtr, int);
|
|
83 |
static void pcfGetCompressedMetric(FontFilePtr,CARD32, xCharInfo*);
|
|
84 |
static Bool pcfSeekToType(FontFilePtr, PCFTablePtr, int, CARD32, CARD32*, CARD32*);
|
|
85 |
static int pcfGetINT16(FontFilePtr, CARD32);
|
|
86 |
static int pcfGetINT32(FontFilePtr, CARD32);
|
|
87 |
static Bool pcfGetAccel(FontInfoPtr, FontFilePtr, PCFTablePtr, int, CARD32);
|
|
88 |
static void pcfGetMetric(FontFilePtr, CARD32, xCharInfo *);
|
|
89 |
static int pcfReadFont(FontPtr, FontFilePtr, int, int, int, int);
|
|
90 |
static char *NameForAtom(Atom);
|
|
91 |
static BufFilePtr BufFileOpenRead(int);
|
|
92 |
static int BufFileRawFill(BufFilePtr);
|
|
93 |
static int BufFileRawSkip(BufFilePtr, int);
|
|
94 |
static int BufFileRawClose (BufFilePtr, int);
|
|
95 |
static int bitmapGetGlyphs(FontPtr, unsigned long, unsigned char *, FontEncoding , unsigned long * , CharInfoPtr *);
|
|
96 |
static int bitmapGetMetrics(FontPtr, unsigned long, unsigned char *, FontEncoding, unsigned long *, xCharInfo **);
|
|
97 |
static void pcfUnloadFont(FontPtr);
|
|
98 |
static int handle_cuferr(int , ucs4_t *, int *);
|
|
99 |
static int handle_illegalchar(ucs4_t *, int *);
|
|
100 |
static int handle_nonidentchar(ucs4_t *, int *);
|
|
101 |
static int handle_nobitmap(ucs4_t *, pcffont_t *, pcf_charmet_t *, pcf_bm_t **) ;
|
|
102 |
static int handle_nongraphchar(ucs4_t *, int *);
|
|
103 |
static pcf_bm_t * xpcf_getcbm(int , pcffont_t *, pcf_charmet_t *);
|
|
104 |
static void BitOrderInvert(unsigned char *, int);
|
|
105 |
static Bool pcfHasType ( PCFTablePtr, int, CARD32);
|
|
106 |
static void TwoByteSwap(unsigned char *, int);
|
|
107 |
static void FourByteSwap(unsigned char *, int);
|
|
108 |
static int RepadBitmap(char *, char *, unsigned int, unsigned int, int, int);
|
|
109 |
static Atom MakeAtom(char *, unsigned, int );
|
|
110 |
static Bool ResizeReverseMap ();
|
|
111 |
static NameEqual (char *, char *,int );
|
|
112 |
static Hash(char *, int);
|
|
113 |
static ResizeHashTable();
|
|
114 |
static void put_PSbitmap(ucs4_t , pcf_bm_t *, pcf_charmet_t *, pcf_SCcharmet_t *);
|
294
|
115 |
static int gzcatfile(char *);
|
0
|
116 |
void init_putPS(void);
|
|
117 |
unsigned long * Xrealloc(unsigned long *, int);
|
|
118 |
unsigned long * Xalloc(int);
|
|
119 |
int BufFileRead (BufFilePtr, char *, int);
|
|
120 |
void pcf_postscript(ucs4_t c, pcf_bm_t *, pcf_charmet_t *, pcf_SCcharmet_t *);
|
|
121 |
int pres_pcfbm(ucs4_t *, pcffont_t *, pcf_bm_t **, pcf_charmet_t *, pcf_SCcharmet_t *, int);
|
|
122 |
|
|
123 |
double SPACINGwidth = -1;
|
|
124 |
ucs4_t SPACINGchar = (ucs4_t) 0x20;
|
|
125 |
ucs4_t REFERENCEchar = (ucs4_t) 0x20;
|
|
126 |
|
|
127 |
extern pcffont_t *pcf_fonts;
|
|
128 |
extern pcffont_t *CurrentFont;
|
|
129 |
static int position;
|
|
130 |
static CharInfoRec nonExistantChar;
|
|
131 |
static AtomListPtr *hashTable;
|
|
132 |
static int hashMask;
|
|
133 |
static int hashSize, hashUsed;
|
|
134 |
static int hashMask;
|
|
135 |
static int rehash;
|
|
136 |
|
|
137 |
/*
|
|
138 |
static ucs4_t pcf_bmap[4][UCS4_MAXVAL/sizeof(ucs4_t)];
|
|
139 |
static int dictcnt = 0;
|
|
140 |
*/
|
|
141 |
|
|
142 |
static unsigned char _reverse_byte[0x100] = {
|
|
143 |
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
|
144 |
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
|
145 |
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
|
146 |
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
|
147 |
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
|
148 |
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
|
149 |
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
|
150 |
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
|
151 |
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
|
152 |
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
|
153 |
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
|
154 |
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
|
155 |
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
|
156 |
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
|
157 |
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
|
158 |
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
|
159 |
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
|
160 |
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
|
161 |
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
|
162 |
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
|
163 |
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
|
164 |
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
|
165 |
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
|
166 |
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
|
167 |
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
|
168 |
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
|
169 |
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
|
170 |
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
|
171 |
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
|
172 |
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
|
173 |
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
|
174 |
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
|
175 |
};
|
|
176 |
|
|
177 |
static void
|
|
178 |
put_PSbitmap(ucs4_t code, pcf_bm_t *bitmap,
|
|
179 |
pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *Smetrics)
|
|
180 |
{
|
|
181 |
int j;
|
|
182 |
int k;
|
|
183 |
|
|
184 |
if (bitmap == NULL)
|
|
185 |
return;
|
|
186 |
|
|
187 |
fprintf(stdout,"/C%x { GR %.2f %.2f S %d %d T [%d 0 0 -%d 0 %d]\n\t{<",
|
|
188 |
code,
|
|
189 |
Smetrics->widthBits, Smetrics->height,
|
|
190 |
Cmetrics->widthBits, Cmetrics->height,
|
|
191 |
Cmetrics->widthBits, Cmetrics->height,
|
|
192 |
Cmetrics->ascent);
|
|
193 |
|
|
194 |
k = Cmetrics->widthBytes * Cmetrics->height;
|
|
195 |
|
|
196 |
#ifdef SDEBUG
|
|
197 |
fprintf(stderr, "%d is -------Cmetrics->widthBytes for :C%x \n", Cmetrics->widthBytes, code);
|
|
198 |
fprintf(stderr, "%d is -------Cmetrics->height for :C%x \n", Cmetrics->height, code);
|
|
199 |
fprintf(stderr, "%d is ------ no. of glyph elems for:C%x \n", k, code);
|
|
200 |
#endif
|
|
201 |
for (j = 0; j < k; j++)
|
|
202 |
fprintf(stdout,"%.2x", bitmap[j]);
|
|
203 |
|
|
204 |
fprintf(stdout,">} IG } def\n");
|
|
205 |
fprintf(stdout,"C%x\n", code);
|
|
206 |
|
|
207 |
/*
|
|
208 |
dictcnt++;
|
|
209 |
*/
|
|
210 |
}
|
|
211 |
|
|
212 |
pcf_SCcharmet_t *
|
|
213 |
get_SCmetrics(ucs4_t val)
|
|
214 |
{
|
|
215 |
int ndx;
|
|
216 |
ucs4_t v;
|
|
217 |
pcf_bm_t *bm;
|
|
218 |
pcf_charmet_t cm;
|
|
219 |
static pcf_SCcharmet_t sm;
|
|
220 |
|
|
221 |
/* map ucs4 val to a 'pcf_fonts' array index */
|
|
222 |
|
|
223 |
v = val;
|
|
224 |
|
|
225 |
if ((ndx = presform_fontndx(val)) == XU_UCS4UNDEF) {
|
|
226 |
return NULL;
|
|
227 |
} else if ((pcf_ret <= -1 ) || ( pres_pcfbm(&v, &pcf_fonts[ndx], &bm, &cm, &sm, 1) < 0)) {
|
|
228 |
return NULL;
|
|
229 |
} else if (v != val) { /* return NULL if val got mapped to */
|
|
230 |
/* another character */
|
|
231 |
return NULL;
|
|
232 |
} else {
|
|
233 |
return &sm;
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
void
|
|
238 |
init_putPS(void)
|
|
239 |
{
|
|
240 |
pcf_SCcharmet_t *sm;
|
|
241 |
|
|
242 |
if ((sm = get_SCmetrics(REFERENCEchar)) \
|
|
243 |
|| (sm = get_SCmetrics(SPACINGchar))) {
|
|
244 |
SPACINGwidth = sm->origin_xoff;
|
|
245 |
} else SPACINGwidth = (float)SPACE_WIDTH_PER_PTSZ * current_pt_sz;
|
|
246 |
}
|
|
247 |
void
|
|
248 |
pcf_postscript(ucs4_t c, pcf_bm_t *pcfbm,
|
|
249 |
pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *scCmetrics)
|
|
250 |
{
|
|
251 |
|
|
252 |
|
|
253 |
put_PSbitmap(c, pcfbm, Cmetrics, scCmetrics);
|
|
254 |
|
|
255 |
}
|
|
256 |
int
|
|
257 |
load_pcf_font(pcffont_t *font)
|
|
258 |
{
|
|
259 |
FontRec fr;
|
|
260 |
FontInfoPtr fi;
|
|
261 |
FontFilePtr ff;
|
|
262 |
ulong_t value;
|
|
263 |
|
|
264 |
if ((ff = FontFileOpen(font->file)) == NULL)
|
|
265 |
return -1;
|
|
266 |
|
|
267 |
|
|
268 |
if (pcfReadFont(&fr, ff, MSBFirst, MSBFirst, 1, 1) != Successful)
|
|
269 |
return -1;
|
|
270 |
fi = &(fr.info);
|
|
271 |
|
|
272 |
font->Fmetrics.ascent = fi->fontAscent;
|
|
273 |
font->Fmetrics.descent = fi->fontDescent;
|
|
274 |
font->Fmetrics.linespace = fi->fontAscent + fi->fontDescent;
|
|
275 |
font->Fmetrics.firstchar = (fi->firstRow * 256) + fi->firstCol;
|
|
276 |
font->Fmetrics.lastchar = (fi->lastRow * 256) + fi->lastCol;
|
|
277 |
font->Fmetrics.lastCol = fi->lastCol;
|
|
278 |
font->Fmetrics.firstCol = fi->firstCol;
|
|
279 |
|
|
280 |
font->bitmaps = ((BitmapFontPtr)(fr.fontPrivate))->encoding;
|
|
281 |
|
|
282 |
if (get_font_property(&fr, "POINT_SIZE", &value) == -1)
|
|
283 |
return -1;
|
|
284 |
font->Fmetrics.ptsz = (int) value;
|
|
285 |
|
|
286 |
if (get_font_property(&fr, "RESOLUTION_X", &value) == -1)
|
|
287 |
return -1;
|
|
288 |
font->Fmetrics.Xres = (int) value;
|
|
289 |
|
|
290 |
if (get_font_property(&fr, "RESOLUTION_Y", &value) == -1)
|
|
291 |
return -1;
|
|
292 |
font->Fmetrics.Yres = (int) value;
|
|
293 |
|
|
294 |
#ifdef SDEBUG
|
|
295 |
fprintf(stderr,"Fmetrics: ascent:%d, descent:%d, linespace:%d, "
|
|
296 |
"ptsz:%d, Xres:%d, Yres:%d\n", font->Fmetrics.ascent, font->Fmetrics.descent,
|
|
297 |
(&(font->Fmetrics))->linespace, (&(font->Fmetrics))->ptsz, (&(font->Fmetrics))->Xres, (&(font->Fmetrics))->Yres);
|
|
298 |
#endif
|
|
299 |
|
|
300 |
debug(dump_Fmetrics(&(font->Fmetrics)));
|
|
301 |
|
|
302 |
FontFileClose(ff);
|
|
303 |
return 0;
|
|
304 |
}
|
|
305 |
|
|
306 |
void
|
|
307 |
scaling_factors(pcffont_t *font, double ptsz, int Xres, int Yres)
|
|
308 |
{
|
|
309 |
font->Yscale = ((ptsz * (double)Yres)
|
|
310 |
/ ((double)font->Fmetrics.ptsz * (double)font->Fmetrics.Xres));
|
|
311 |
|
|
312 |
font->Xscale = ((((double)Xres * (double)font->Fmetrics.Yres)
|
|
313 |
/ ((double)Yres * (double)font->Fmetrics.Xres))
|
|
314 |
* (font->Yscale));
|
|
315 |
#if 0
|
|
316 |
if (xsflag == OPTARG_SET)
|
|
317 |
font->Xscale = xs_argval;
|
|
318 |
else if (xsflag == OPTARG_ADD)
|
|
319 |
font->Xscale += xs_argval;
|
|
320 |
else if (xsflag == OPTARG_SUB) /* for clarity, we subract a positive */
|
|
321 |
font->Xscale -= xs_argval; /* rather than add a negative. */
|
|
322 |
|
|
323 |
if (ysflag == OPTARG_SET)
|
|
324 |
font->Yscale = ys_argval;
|
|
325 |
else if (ysflag == OPTARG_ADD)
|
|
326 |
font->Yscale += ys_argval;
|
|
327 |
else if (ysflag == OPTARG_SUB)
|
|
328 |
font->Yscale -= ys_argval;
|
|
329 |
#endif
|
|
330 |
#ifdef SDEBUG
|
|
331 |
fprintf(stderr,"%f -- font->Yscale\n %f -- font->Xscale\n", font->Yscale, font->Xscale);
|
|
332 |
#endif
|
|
333 |
}
|
|
334 |
|
|
335 |
void
|
|
336 |
scale_Fmetrics(pcffont_t *font) {
|
|
337 |
font->scFmetrics.ascent = font->Fmetrics.ascent * font->Yscale;
|
|
338 |
font->scFmetrics.descent = font->Fmetrics.descent * font->Yscale;
|
|
339 |
font->scFmetrics.linespace = font->Fmetrics.linespace * font->Yscale;
|
|
340 |
|
|
341 |
#ifdef SDEBUG
|
|
342 |
fprintf(stderr,"%f font->scFmetrics.ascent\n \
|
|
343 |
%f font->scFmetrics.descent\n\
|
|
344 |
%f font->scFmetrics.linespace\n", font->scFmetrics.ascent, font->scFmetrics.descent, font->scFmetrics.linespace);
|
|
345 |
#endif
|
|
346 |
|
|
347 |
}
|
|
348 |
|
|
349 |
void
|
|
350 |
scale_Cmetrics(pcf_charmet_t *Cm, pcf_SCcharmet_t *Sm)
|
|
351 |
{
|
|
352 |
Sm->width = Cm->width * CurrentFont->Xscale;
|
|
353 |
Sm->height = Cm->height * CurrentFont->Yscale;
|
|
354 |
Sm->widthBits = Cm->widthBits * CurrentFont->Xscale;
|
|
355 |
Sm->ascent = Cm->ascent * CurrentFont->Yscale;
|
|
356 |
Sm->descent = Cm->descent * CurrentFont->Yscale;
|
|
357 |
Sm->origin_xoff = Cm->origin_xoff * CurrentFont->Xscale;
|
|
358 |
|
|
359 |
#ifdef SDEBUG
|
|
360 |
fprintf(stderr, "%f is CurrentFont->Xscale\n", CurrentFont->Xscale);
|
|
361 |
fprintf(stderr, "%f is CurrentFont->Yscale\n", CurrentFont->Yscale);
|
|
362 |
fprintf(stderr, "%d is Cm->widthBits\n", Cm->widthBits);
|
|
363 |
fprintf(stderr, "%d is Cm->height\n", Cm->height);
|
|
364 |
fprintf(stderr, "%f is Sm->widthBits\n", Sm->widthBits);
|
|
365 |
fprintf(stderr, "%f is Sm->height\n", Sm->height);
|
|
366 |
#endif
|
|
367 |
|
|
368 |
/*
|
|
369 |
debug(dump_scCmetrics(Sm));
|
|
370 |
*/
|
|
371 |
}
|
|
372 |
int
|
|
373 |
pres_pcfbm(ucs4_t *val, pcffont_t *font, pcf_bm_t **bitmap,
|
|
374 |
pcf_charmet_t *Cmetrics, pcf_SCcharmet_t *scCmetrics, int dontcache)
|
|
375 |
{
|
|
376 |
int fv;
|
|
377 |
ucs4_t v;
|
|
378 |
#if SDEBUG
|
|
379 |
fprintf(stderr, "0x%08x -- ucs4val \n", *val);
|
|
380 |
#endif
|
|
381 |
|
|
382 |
v = *val;
|
|
383 |
if (is_motion_char(v)) {
|
|
384 |
*bitmap = NULL;
|
|
385 |
return XU_MOTION_CHAR;
|
|
386 |
}
|
|
387 |
|
|
388 |
if (non_graphic_char(v)) {
|
|
389 |
int ndx;
|
|
390 |
if ((fv = handle_nongraphchar(&v, &ndx)) == XU_IGNORE) {
|
|
391 |
return XU_IGNORE;
|
|
392 |
} else {
|
|
393 |
font = &pcf_fonts[ndx];
|
|
394 |
CurrentFont = font;
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
if ((fv = font->cuf(v)) < 0) {
|
|
399 |
int ndx;
|
|
400 |
if ((fv = handle_cuferr(fv, &v, &ndx)) == XU_IGNORE) {
|
|
401 |
return XU_IGNORE;
|
|
402 |
} else {
|
|
403 |
font = &pcf_fonts[ndx];
|
|
404 |
CurrentFont = font;
|
|
405 |
}
|
|
406 |
}
|
|
407 |
|
|
408 |
if ((*bitmap = (pcf_bm_t *)xpcf_getcbm(fv, font, Cmetrics)) == NULL) {
|
|
409 |
if (handle_nobitmap(&v, font, Cmetrics, bitmap) == XU_IGNORE)
|
|
410 |
return XU_IGNORE;
|
|
411 |
}
|
|
412 |
#if SDEBUG
|
|
413 |
fprintf(stderr, "0x%02x -- **bitmap \n", (unsigned char)**bitmap);
|
|
414 |
#endif
|
|
415 |
*val = v;
|
|
416 |
scale_Cmetrics(Cmetrics, scCmetrics);
|
|
417 |
return(1);
|
|
418 |
}
|
|
419 |
|
|
420 |
#ifdef DEBUG
|
|
421 |
|
|
422 |
static void
|
|
423 |
dump_Cmetrics(pcf_charmet_t *cm)
|
|
424 |
{
|
|
425 |
dprintf2("cmetrics: ascent:%d, descent:%d, ", cm->ascent, cm->descent);
|
|
426 |
|
|
427 |
dprintf3("width:%d, height:%d, widthBytes:%d, ",
|
|
428 |
cm->width, cm->height, cm->widthBytes);
|
|
429 |
|
|
430 |
dprintf3("LSB:%d,RSB: %d, xoff:%d\n ",
|
|
431 |
cm->LSBearing, cm->RSBearing, cm->origin_xoff);
|
|
432 |
}
|
|
433 |
static void
|
|
434 |
dump_Fmetrics(pcffont_t *fm)
|
|
435 |
{
|
|
436 |
dprintf6("Fmetrics: ascent:%d, descent:%d, linespace:%d, "
|
|
437 |
"ptsz:%d, Xres:%d, Yres:%d\n", fm->ascent, fm->descent,
|
|
438 |
fm->linespace, fm->ptsz, fm->Xres, fm->Yres);
|
|
439 |
}
|
|
440 |
#endif
|
|
441 |
|
|
442 |
unsigned long *
|
|
443 |
Xrealloc (n,m)
|
|
444 |
unsigned long *n;
|
|
445 |
{
|
|
446 |
if (!n)
|
|
447 |
return (unsigned long *) malloc (m);
|
|
448 |
else
|
|
449 |
return (unsigned long *) realloc ((char *) n, m);
|
|
450 |
}
|
|
451 |
unsigned long *
|
|
452 |
Xalloc (m)
|
|
453 |
{
|
|
454 |
return (unsigned long *) malloc (m);
|
|
455 |
}
|
|
456 |
|
|
457 |
/*
|
|
458 |
* Invert byte order within each 16-bits of an array.
|
|
459 |
*/
|
|
460 |
void
|
|
461 |
TwoByteSwap(buf, nbytes)
|
|
462 |
unsigned char *buf;
|
|
463 |
int nbytes;
|
|
464 |
{
|
|
465 |
register unsigned char c;
|
|
466 |
|
|
467 |
for (; nbytes > 0; nbytes -= 2, buf += 2)
|
|
468 |
{
|
|
469 |
c = buf[0];
|
|
470 |
buf[0] = buf[1];
|
|
471 |
buf[1] = c;
|
|
472 |
}
|
|
473 |
}
|
|
474 |
/*
|
|
475 |
* Invert byte order within each 32-bits of an array.
|
|
476 |
*/
|
|
477 |
static void
|
|
478 |
FourByteSwap(buf, nbytes)
|
|
479 |
unsigned char *buf;
|
|
480 |
int nbytes;
|
|
481 |
{
|
|
482 |
register unsigned char c;
|
|
483 |
|
|
484 |
for (; nbytes > 0; nbytes -= 4, buf += 4)
|
|
485 |
{
|
|
486 |
c = buf[0];
|
|
487 |
buf[0] = buf[3];
|
|
488 |
buf[3] = c;
|
|
489 |
c = buf[1];
|
|
490 |
buf[1] = buf[2];
|
|
491 |
buf[2] = c;
|
|
492 |
}
|
|
493 |
}
|
|
494 |
static int
|
|
495 |
handle_nongraphchar(ucs4_t *val, int *ndx)
|
|
496 |
{
|
|
497 |
return XU_IGNORE;
|
|
498 |
}
|
|
499 |
|
|
500 |
static Bool
|
|
501 |
pcfHasType (tables, ntables, type)
|
|
502 |
PCFTablePtr tables;
|
|
503 |
int ntables;
|
|
504 |
CARD32 type;
|
|
505 |
{
|
|
506 |
int i;
|
|
507 |
|
|
508 |
for (i = 0; i < ntables; i++)
|
|
509 |
if (tables[i].type == type)
|
|
510 |
return TRUE;
|
|
511 |
return FALSE;
|
|
512 |
}
|
|
513 |
/*
|
|
514 |
* Invert bit order within each BYTE of an array.
|
|
515 |
*/
|
|
516 |
static void
|
|
517 |
BitOrderInvert(buf, nbytes)
|
|
518 |
unsigned char *buf;
|
|
519 |
int nbytes;
|
|
520 |
{
|
|
521 |
register unsigned char *rev = _reverse_byte;
|
|
522 |
|
|
523 |
for (; --nbytes >= 0; buf++)
|
|
524 |
*buf = rev[*buf];
|
|
525 |
}
|
|
526 |
|
|
527 |
static pcf_bm_t *
|
|
528 |
xpcf_getcbm(int code, pcffont_t *font, pcf_charmet_t *Cmetrics)
|
|
529 |
{
|
|
530 |
int j;
|
|
531 |
CharInfoPtr ci;
|
|
532 |
|
|
533 |
assert(font->loaded);
|
|
534 |
/*
|
|
535 |
* For the default no glyph character to appear in
|
|
536 |
* output stream
|
|
537 |
*/
|
|
538 |
onemoretime:
|
|
539 |
if (code < font->Fmetrics.firstchar || code > font->Fmetrics.lastchar)
|
|
540 |
return NULL;
|
|
541 |
|
|
542 |
j = (code - (((code - font->Fmetrics.firstchar) / 256)
|
|
543 |
* (font->Fmetrics.firstCol + (255 - font->Fmetrics.lastCol))))
|
|
544 |
- font->Fmetrics.firstchar;
|
|
545 |
#ifdef SDEBUG
|
|
546 |
fprintf(stderr, "%d is -- codewidth of C%x\n", wcwidth(code), code);
|
|
547 |
fprintf(stderr, "%d is -- j value C%x\n", wcwidth(code), code);
|
|
548 |
#endif
|
|
549 |
assert(j >= 0);
|
|
550 |
if (font->bitmaps[j] == NULL)
|
|
551 |
{
|
|
552 |
/*
|
|
553 |
* code added to replace the codepoints with
|
|
554 |
* no-glyph code
|
|
555 |
*/
|
|
556 |
|
|
557 |
if (wcwidth(code) == -1)
|
|
558 |
{
|
|
559 |
code = 0;
|
|
560 |
goto onemoretime;
|
|
561 |
}
|
|
562 |
return NULL;
|
|
563 |
}
|
|
564 |
|
|
565 |
ci = font->bitmaps[j];
|
|
566 |
Cmetrics->width = GLYPHWIDTHPIXELS(ci);
|
|
567 |
Cmetrics->height = GLYPHHEIGHTPIXELS(ci);
|
|
568 |
Cmetrics->widthBytes = GLYPHWIDTHBYTES(ci);
|
|
569 |
Cmetrics->widthBits = GLYPHWIDTHBYTES(ci) * NBPB;
|
|
570 |
Cmetrics->ascent = ci->metrics.ascent;
|
|
571 |
Cmetrics->descent = ci->metrics.descent;
|
|
572 |
Cmetrics->LSBearing = ci->metrics.leftSideBearing;
|
|
573 |
Cmetrics->RSBearing = ci->metrics.rightSideBearing;
|
|
574 |
Cmetrics->origin_xoff = ci->metrics.characterWidth;
|
|
575 |
|
|
576 |
#ifdef SDEBUG
|
|
577 |
fprintf(stderr, "%d is -- Cmetrics->widthBytes of C%x\n", Cmetrics->widthBytes, code);
|
|
578 |
fprintf(stderr, "%d is -- Cmetrics->height value of C%x\n", Cmetrics->height, code);
|
|
579 |
#endif
|
|
580 |
|
|
581 |
#if 0
|
|
582 |
if (cwflag) {
|
|
583 |
if (cwflag == OPTARG_ADD)
|
|
584 |
Cmetrics->origin_xoff += cw_argval;
|
|
585 |
else if (cwflag == OPTARG_SUB)
|
|
586 |
Cmetrics->origin_xoff -= cw_argval;
|
|
587 |
else if (cwflag == OPTARG_SET)
|
|
588 |
Cmetrics->origin_xoff = cw_argval;
|
|
589 |
}
|
|
590 |
#endif
|
|
591 |
|
|
592 |
debug(dump_Cmetrics(Cmetrics));
|
|
593 |
|
|
594 |
return (pcf_bm_t*) ci->bits;
|
|
595 |
}
|
|
596 |
|
|
597 |
/*
|
|
598 |
* Repad a bitmap
|
|
599 |
*/
|
|
600 |
|
|
601 |
static int
|
|
602 |
RepadBitmap (pSrc, pDst, srcPad, dstPad, width, height)
|
|
603 |
char *pSrc, *pDst;
|
|
604 |
unsigned srcPad, dstPad;
|
|
605 |
int width, height;
|
|
606 |
{
|
|
607 |
int srcWidthBytes,dstWidthBytes;
|
|
608 |
int row,col;
|
|
609 |
char *pTmpSrc,*pTmpDst;
|
|
610 |
|
|
611 |
switch (srcPad) {
|
|
612 |
case 1:
|
|
613 |
srcWidthBytes = (width+7)>>3;
|
|
614 |
break;
|
|
615 |
case 2:
|
|
616 |
srcWidthBytes = ((width+15)>>4)<<1;
|
|
617 |
break;
|
|
618 |
case 4:
|
|
619 |
srcWidthBytes = ((width+31)>>5)<<2;
|
|
620 |
break;
|
|
621 |
case 8:
|
|
622 |
srcWidthBytes = ((width+63)>>6)<<3;
|
|
623 |
break;
|
|
624 |
default:
|
|
625 |
return 0;
|
|
626 |
}
|
|
627 |
switch (dstPad) {
|
|
628 |
case 1:
|
|
629 |
dstWidthBytes = (width+7)>>3;
|
|
630 |
break;
|
|
631 |
case 2:
|
|
632 |
dstWidthBytes = ((width+15)>>4)<<1;
|
|
633 |
break;
|
|
634 |
case 4:
|
|
635 |
dstWidthBytes = ((width+31)>>5)<<2;
|
|
636 |
break;
|
|
637 |
case 8:
|
|
638 |
dstWidthBytes = ((width+63)>>6)<<3;
|
|
639 |
break;
|
|
640 |
default:
|
|
641 |
return 0;
|
|
642 |
}
|
|
643 |
|
|
644 |
width = srcWidthBytes;
|
|
645 |
if (width > dstWidthBytes)
|
|
646 |
width = dstWidthBytes;
|
|
647 |
pTmpSrc= pSrc;
|
|
648 |
pTmpDst= pDst;
|
|
649 |
for (row = 0; row < height; row++)
|
|
650 |
{
|
|
651 |
for (col = 0; col < width; col++)
|
|
652 |
*pTmpDst++ = *pTmpSrc++;
|
|
653 |
while (col < dstWidthBytes)
|
|
654 |
{
|
|
655 |
*pTmpDst++ = '\0';
|
|
656 |
col++;
|
|
657 |
}
|
|
658 |
pTmpSrc += srcWidthBytes - width;
|
|
659 |
}
|
|
660 |
return dstWidthBytes * height;
|
|
661 |
}
|
|
662 |
static int
|
|
663 |
handle_cuferr(int err, ucs4_t *v, int *ndx)
|
|
664 |
{
|
|
665 |
|
|
666 |
if (err == CUF_ILCH) {
|
|
667 |
return handle_illegalchar(v, ndx);
|
|
668 |
} else if (err == CUF_NICH) {
|
|
669 |
return handle_nonidentchar(v, ndx);
|
|
670 |
} else {
|
|
671 |
err_exit( catgets(cat_fd, ERR_SET, 35, "%s: internal error: "
|
|
672 |
"unable to get pcf glyph for 0x%08x\n"
|
|
673 |
"file name:%s , line number:%d\n"), progname,
|
|
674 |
*v, __FILE__, __LINE__ );
|
|
675 |
}
|
|
676 |
}
|
|
677 |
|
|
678 |
static int
|
|
679 |
handle_illegalchar(ucs4_t *val, int *ndx)
|
|
680 |
{
|
|
681 |
return XU_IGNORE;
|
|
682 |
}
|
|
683 |
|
|
684 |
static int
|
|
685 |
handle_nonidentchar(ucs4_t *val, int *ndx)
|
|
686 |
{
|
|
687 |
return XU_IGNORE;
|
|
688 |
}
|
|
689 |
|
|
690 |
static int
|
|
691 |
handle_nobitmap(ucs4_t *val, pcffont_t *font, pcf_charmet_t *Cm, pcf_bm_t **bitmap) {
|
|
692 |
int fv;
|
|
693 |
/* Becasue NOBITMAPREPL is hard coded for FALLBACK_FONT */
|
|
694 |
if(strstr(font->file, FALLBACK_FONT)==NULL)
|
|
695 |
return XU_IGNORE;
|
|
696 |
*val = NOBITMAPREPL;
|
|
697 |
if ((fv = font->cuf(*val)) < 0) return XU_IGNORE;
|
|
698 |
if ((*bitmap = xpcf_getcbm(fv, font, Cm)) == NULL) return XU_IGNORE;
|
|
699 |
return(1);
|
|
700 |
}
|
|
701 |
|
|
702 |
|
|
703 |
static int
|
|
704 |
BufFileRawFill (f)
|
|
705 |
BufFilePtr f;
|
|
706 |
{
|
|
707 |
int left;
|
|
708 |
|
|
709 |
left = read (FileDes(f), f->buffer, BUFFILESIZE);
|
|
710 |
if (left <= 0) {
|
|
711 |
f->left = 0;
|
|
712 |
return BUFFILEEOF;
|
|
713 |
}
|
|
714 |
f->left = left - 1;
|
|
715 |
f->bufp = f->buffer + 1;
|
|
716 |
return f->buffer[0];
|
|
717 |
}
|
|
718 |
|
|
719 |
static int
|
|
720 |
BufFileRawSkip (f, count)
|
|
721 |
BufFilePtr f;
|
|
722 |
int count;
|
|
723 |
{
|
|
724 |
int curoff;
|
|
725 |
int fileoff;
|
|
726 |
int todo;
|
|
727 |
|
|
728 |
curoff = f->bufp - f->buffer;
|
|
729 |
fileoff = curoff + f->left;
|
|
730 |
if (curoff + count <= fileoff) {
|
|
731 |
f->bufp += count;
|
|
732 |
f->left -= count;
|
|
733 |
} else {
|
|
734 |
todo = count - (fileoff - curoff);
|
|
735 |
if (lseek (FileDes(f), todo, 1) == -1) {
|
|
736 |
if (errno != ESPIPE)
|
|
737 |
return BUFFILEEOF;
|
|
738 |
while (todo) {
|
|
739 |
curoff = BUFFILESIZE;
|
|
740 |
if (curoff > todo)
|
|
741 |
curoff = todo;
|
|
742 |
fileoff = read (FileDes(f), f->buffer, curoff);
|
|
743 |
if (fileoff <= 0)
|
|
744 |
return BUFFILEEOF;
|
|
745 |
todo -= fileoff;
|
|
746 |
}
|
|
747 |
}
|
|
748 |
f->left = 0;
|
|
749 |
}
|
|
750 |
return count;
|
|
751 |
}
|
|
752 |
|
|
753 |
static int
|
|
754 |
BufFileRawClose (f, doClose)
|
|
755 |
BufFilePtr f;
|
|
756 |
{
|
|
757 |
if (doClose)
|
|
758 |
close (FileDes (f));
|
|
759 |
return 1;
|
|
760 |
}
|
|
761 |
|
|
762 |
static
|
|
763 |
NameEqual (a, b, l)
|
|
764 |
char *a, *b;
|
|
765 |
{
|
|
766 |
while (l--)
|
|
767 |
if (*a++ != *b++)
|
|
768 |
return FALSE;
|
|
769 |
return TRUE;
|
|
770 |
}
|
|
771 |
static BufFilePtr
|
|
772 |
BufFileOpenRead(fd)
|
|
773 |
int fd;
|
|
774 |
{
|
|
775 |
return BufFileCreate ((char *) fd, BufFileRawFill, BufFileRawSkip, BufFileRawClose);
|
|
776 |
}
|
|
777 |
|
|
778 |
static AtomListPtr *reverseMap;
|
|
779 |
static int reverseMapSize;
|
|
780 |
static Atom lastAtom;
|
|
781 |
|
|
782 |
static Bool ResizeReverseMap ()
|
|
783 |
{
|
|
784 |
if (reverseMapSize == 0)
|
|
785 |
reverseMapSize = 1000;
|
|
786 |
else
|
|
787 |
reverseMapSize *= 2;
|
|
788 |
reverseMap = (AtomListPtr *) Xrealloc ((ulong_t *)reverseMap, reverseMapSize * sizeof (AtomListPtr));
|
|
789 |
if (!reverseMap)
|
|
790 |
return FALSE;
|
|
791 |
else
|
|
792 |
return TRUE;
|
|
793 |
}
|
|
794 |
|
|
795 |
static char *
|
|
796 |
NameForAtom(atom)
|
|
797 |
Atom atom;
|
|
798 |
{
|
|
799 |
if (atom != None && atom <= lastAtom)
|
|
800 |
return reverseMap[atom]->name;
|
|
801 |
return 0;
|
|
802 |
}
|
|
803 |
/*****************************************************************
|
|
804 |
* TAG( getcode )
|
|
805 |
*
|
|
806 |
* Read one code from the standard input. If BUFFILEEOF, return -1.
|
|
807 |
* Inputs:
|
|
808 |
* stdin
|
|
809 |
* Outputs:
|
|
810 |
* code or -1 is returned.
|
|
811 |
*/
|
|
812 |
|
|
813 |
static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
|
|
814 |
|
|
815 |
static code_int
|
|
816 |
getcode(file)
|
|
817 |
CompressedFile *file;
|
|
818 |
{
|
|
819 |
register code_int code;
|
|
820 |
register int r_off, bits;
|
|
821 |
register char_type *bp = file->buf;
|
|
822 |
register BufFilePtr raw;
|
|
823 |
|
|
824 |
if ( file->clear_flg > 0 || file->offset >= file->size ||
|
|
825 |
file->free_ent > file->maxcode )
|
|
826 |
{
|
|
827 |
/*
|
|
828 |
* If the next entry will be too big for the current code
|
|
829 |
* size, then we must increase the size. This implies reading
|
|
830 |
* a new buffer full, too.
|
|
831 |
*/
|
|
832 |
if ( file->free_ent > file->maxcode ) {
|
|
833 |
file->n_bits++;
|
|
834 |
if ( file->n_bits == file->maxbits )
|
|
835 |
file->maxcode = file->maxmaxcode; /* won't get any bigger now */
|
|
836 |
else
|
|
837 |
file->maxcode = MAXCODE(file->n_bits);
|
|
838 |
}
|
|
839 |
if ( file->clear_flg > 0) {
|
|
840 |
file->maxcode = MAXCODE (file->n_bits = INIT_BITS);
|
|
841 |
file->clear_flg = 0;
|
|
842 |
}
|
|
843 |
bits = file->n_bits;
|
|
844 |
raw = file->file;
|
|
845 |
while (bits > 0 && (code = BufFileGet (raw)) != BUFFILEEOF)
|
|
846 |
{
|
|
847 |
*bp++ = code;
|
|
848 |
--bits;
|
|
849 |
}
|
|
850 |
bp = file->buf;
|
|
851 |
if (bits == file->n_bits)
|
|
852 |
return -1; /* end of file */
|
|
853 |
file->size = file->n_bits - bits;
|
|
854 |
file->offset = 0;
|
|
855 |
/* Round size down to integral number of codes */
|
|
856 |
file->size = (file->size << 3) - (file->n_bits - 1);
|
|
857 |
}
|
|
858 |
r_off = file->offset;
|
|
859 |
bits = file->n_bits;
|
|
860 |
/*
|
|
861 |
* Get to the first byte.
|
|
862 |
*/
|
|
863 |
bp += (r_off >> 3);
|
|
864 |
r_off &= 7;
|
|
865 |
/* Get first part (low order bits) */
|
|
866 |
#ifdef NO_UCHAR
|
|
867 |
code = ((*bp++ >> r_off) & rmask[8 - r_off]) & 0xff;
|
|
868 |
#else
|
|
869 |
code = (*bp++ >> r_off);
|
|
870 |
#endif /* NO_UCHAR */
|
|
871 |
bits -= (8 - r_off);
|
|
872 |
r_off = 8 - r_off; /* now, offset into code word */
|
|
873 |
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
|
|
874 |
if ( bits >= 8 ) {
|
|
875 |
#ifdef NO_UCHAR
|
|
876 |
code |= (*bp++ & 0xff) << r_off;
|
|
877 |
#else
|
|
878 |
code |= *bp++ << r_off;
|
|
879 |
#endif /* NO_UCHAR */
|
|
880 |
r_off += 8;
|
|
881 |
bits -= 8;
|
|
882 |
}
|
|
883 |
/* high order bits. */
|
|
884 |
if (rmask[bits])
|
|
885 |
code |= (*bp & rmask[bits]) << r_off;
|
|
886 |
file->offset += file->n_bits;
|
|
887 |
|
|
888 |
return code;
|
|
889 |
}
|
|
890 |
int
|
|
891 |
BufFileClose (f, doClose)
|
|
892 |
BufFilePtr f;
|
|
893 |
{
|
|
894 |
(void) (*f->close) (f, doClose);
|
|
895 |
xfree (f);
|
|
896 |
}
|
|
897 |
|
|
898 |
|
|
899 |
static int
|
|
900 |
get_font_property(FontPtr Fp, char *name, ulong_t *value)
|
|
901 |
{
|
|
902 |
int j;
|
|
903 |
int n;
|
|
904 |
char *prop_name;
|
|
905 |
|
|
906 |
n = Fp->info.nprops;
|
|
907 |
|
|
908 |
for (j = 0; j < n; j++) {
|
|
909 |
if (!(prop_name = NameForAtom(Fp->info.props[j].name)))
|
|
910 |
continue;
|
|
911 |
if (eq(name, prop_name)) {
|
|
912 |
*value = (ulong_t) Fp->info.props[j].value;
|
|
913 |
return 0;
|
|
914 |
}
|
|
915 |
}
|
|
916 |
|
|
917 |
return -1;
|
|
918 |
}
|
|
919 |
|
|
920 |
|
|
921 |
static BufFilePtr
|
|
922 |
BufFileCreate (private, io, skip, close)
|
|
923 |
char *private;
|
|
924 |
int (*io)();
|
|
925 |
int (*skip)();
|
|
926 |
int (*close)();
|
|
927 |
{
|
|
928 |
BufFilePtr f;
|
|
929 |
|
|
930 |
f = (BufFilePtr) xalloc (sizeof *f);
|
|
931 |
if (!f)
|
|
932 |
return 0;
|
|
933 |
f->private = private;
|
|
934 |
f->bufp = f->buffer;
|
|
935 |
f->left = 0;
|
|
936 |
f->io = io;
|
|
937 |
f->skip = skip;
|
|
938 |
f->close = close;
|
|
939 |
return f;
|
|
940 |
}
|
|
941 |
|
|
942 |
int hsize_table[] = {
|
|
943 |
5003, /* 12 bits - 80% occupancy */
|
|
944 |
9001, /* 13 bits - 91% occupancy */
|
|
945 |
18013, /* 14 bits - 91% occupancy */
|
|
946 |
35023, /* 15 bits - 94% occupancy */
|
|
947 |
69001 /* 16 bits - 95% occupancy */
|
|
948 |
};
|
|
949 |
|
|
950 |
static int BufCompressedFill(), BufCompressedSkip(), BufCompressedClose();
|
|
951 |
|
|
952 |
static int
|
|
953 |
BufCompressedClose (f, doClose)
|
|
954 |
BufFilePtr f;
|
|
955 |
{
|
|
956 |
CompressedFile *file;
|
|
957 |
BufFilePtr raw;
|
|
958 |
|
|
959 |
file = (CompressedFile *) f->private;
|
|
960 |
raw = file->file;
|
|
961 |
xfree (file);
|
|
962 |
BufFileClose (raw, doClose);
|
|
963 |
return 1;
|
|
964 |
}
|
|
965 |
|
|
966 |
static int
|
|
967 |
BufCompressedSkip (f, bytes)
|
|
968 |
BufFilePtr f;
|
|
969 |
int bytes;
|
|
970 |
{
|
|
971 |
int c;
|
|
972 |
while (bytes--) {
|
|
973 |
if (BufFileGet(f) == BUFFILEEOF)
|
|
974 |
return BUFFILEEOF;
|
|
975 |
}
|
|
976 |
return 0;
|
|
977 |
}
|
|
978 |
|
|
979 |
static int
|
|
980 |
BufCompressedFill (f)
|
|
981 |
BufFilePtr f;
|
|
982 |
{
|
|
983 |
CompressedFile *file;
|
|
984 |
register char_type *stackp, *de_stack;
|
|
985 |
register char_type finchar;
|
|
986 |
register code_int code, oldcode, incode;
|
|
987 |
BufChar *buf, *bufend;
|
|
988 |
|
|
989 |
file = (CompressedFile *) f->private;
|
|
990 |
|
|
991 |
buf = f->buffer;
|
|
992 |
bufend = buf + BUFFILESIZE;
|
|
993 |
stackp = file->stackp;
|
|
994 |
de_stack = file->de_stack;
|
|
995 |
finchar = file->finchar;
|
|
996 |
oldcode = file->oldcode;
|
|
997 |
while (buf < bufend) {
|
|
998 |
while (stackp > de_stack && buf < bufend)
|
|
999 |
*buf++ = *--stackp;
|
|
1000 |
|
|
1001 |
if (buf == bufend)
|
|
1002 |
break;
|
|
1003 |
|
|
1004 |
if (oldcode == -1)
|
|
1005 |
break;
|
|
1006 |
|
|
1007 |
code = getcode (file);
|
|
1008 |
if (code == -1)
|
|
1009 |
break;
|
|
1010 |
|
|
1011 |
if ( (code == CLEAR) && file->block_compress ) {
|
|
1012 |
for ( code = 255; code >= 0; code-- )
|
|
1013 |
file->tab_prefix[code] = 0;
|
|
1014 |
file->clear_flg = 1;
|
|
1015 |
file->free_ent = FIRST - 1;
|
|
1016 |
if ( (code = getcode (file)) == -1 ) /* O, untimely death! */
|
|
1017 |
break;
|
|
1018 |
}
|
|
1019 |
incode = code;
|
|
1020 |
/*
|
|
1021 |
* Special case for KwKwK string.
|
|
1022 |
*/
|
|
1023 |
if ( code >= file->free_ent ) {
|
|
1024 |
*stackp++ = finchar;
|
|
1025 |
code = oldcode;
|
|
1026 |
}
|
|
1027 |
|
|
1028 |
/*
|
|
1029 |
* Generate output characters in reverse order
|
|
1030 |
*/
|
|
1031 |
while ( code >= 256 )
|
|
1032 |
{
|
|
1033 |
*stackp++ = file->tab_suffix[code];
|
|
1034 |
code = file->tab_prefix[code];
|
|
1035 |
}
|
|
1036 |
finchar = file->tab_suffix[code];
|
|
1037 |
*stackp++ = finchar;
|
|
1038 |
|
|
1039 |
/*
|
|
1040 |
* Generate the new entry.
|
|
1041 |
*/
|
|
1042 |
if ( (code=file->free_ent) < file->maxmaxcode ) {
|
|
1043 |
file->tab_prefix[code] = (unsigned short)oldcode;
|
|
1044 |
file->tab_suffix[code] = finchar;
|
|
1045 |
file->free_ent = code+1;
|
|
1046 |
}
|
|
1047 |
/*
|
|
1048 |
* Remember previous code.
|
|
1049 |
*/
|
|
1050 |
oldcode = incode;
|
|
1051 |
}
|
|
1052 |
file->oldcode = oldcode;
|
|
1053 |
file->stackp = stackp;
|
|
1054 |
file->finchar = finchar;
|
|
1055 |
if (buf == f->buffer) {
|
|
1056 |
f->left = 0;
|
|
1057 |
return BUFFILEEOF;
|
|
1058 |
}
|
|
1059 |
f->bufp = f->buffer + 1;
|
|
1060 |
f->left = (buf - f->buffer) - 1;
|
|
1061 |
return f->buffer[0];
|
|
1062 |
}
|
|
1063 |
|
|
1064 |
BufFilePtr
|
|
1065 |
BufFilePushCompressed (f)
|
|
1066 |
BufFilePtr f;
|
|
1067 |
{
|
|
1068 |
int code;
|
|
1069 |
int maxbits;
|
|
1070 |
int hsize;
|
|
1071 |
CompressedFile *file;
|
|
1072 |
int extra;
|
|
1073 |
|
|
1074 |
if ((BufFileGet(f) != (magic_header[0] & 0xFF)) ||
|
|
1075 |
(BufFileGet(f) != (magic_header[1] & 0xFF)))
|
|
1076 |
{
|
|
1077 |
return 0;
|
|
1078 |
}
|
|
1079 |
code = BufFileGet (f);
|
|
1080 |
maxbits = code & BIT_MASK;
|
|
1081 |
if (maxbits > BITS || maxbits < 12)
|
|
1082 |
return 0;
|
|
1083 |
hsize = hsize_table[maxbits - 12];
|
|
1084 |
extra = (1 << maxbits) * sizeof (char_type) +
|
|
1085 |
hsize * sizeof (unsigned short);
|
|
1086 |
file = (CompressedFile *) xalloc (sizeof (CompressedFile) + extra);
|
|
1087 |
if (!file)
|
|
1088 |
return 0;
|
|
1089 |
file->file = f;
|
|
1090 |
file->maxbits = maxbits;
|
|
1091 |
file->block_compress = code & BLOCK_MASK;
|
|
1092 |
file->maxmaxcode = 1 << file->maxbits;
|
|
1093 |
file->tab_suffix = (char_type *) &file[1];
|
|
1094 |
file->tab_prefix = (unsigned short *) (file->tab_suffix + file->maxmaxcode);
|
|
1095 |
/*
|
|
1096 |
* As above, initialize the first 256 entries in the table.
|
|
1097 |
*/
|
|
1098 |
file->maxcode = MAXCODE(file->n_bits = INIT_BITS);
|
|
1099 |
for ( code = 255; code >= 0; code-- ) {
|
|
1100 |
file->tab_prefix[code] = 0;
|
|
1101 |
file->tab_suffix[code] = (char_type) code;
|
|
1102 |
}
|
|
1103 |
file->free_ent = ((file->block_compress) ? FIRST : 256 );
|
|
1104 |
file->clear_flg = 0;
|
|
1105 |
file->offset = 0;
|
|
1106 |
file->size = 0;
|
|
1107 |
file->stackp = file->de_stack;
|
|
1108 |
file->finchar = file->oldcode = getcode (file);
|
|
1109 |
if (file->oldcode != -1)
|
|
1110 |
*file->stackp++ = file->finchar;
|
|
1111 |
return BufFileCreate ((char *) file,
|
|
1112 |
BufCompressedFill,
|
|
1113 |
BufCompressedSkip,
|
|
1114 |
BufCompressedClose);
|
|
1115 |
}
|
|
1116 |
|
294
|
1117 |
static
|
|
1118 |
int gzcatfile(char *name) {
|
|
1119 |
int fd[2];
|
|
1120 |
|
|
1121 |
if (pipe (fd) < 0)
|
|
1122 |
return -1;
|
|
1123 |
|
|
1124 |
switch (fork ())
|
|
1125 |
{
|
|
1126 |
case -1:
|
|
1127 |
return -1;
|
|
1128 |
case 0:
|
|
1129 |
close (fd[0]);
|
|
1130 |
close (1);
|
|
1131 |
if (dup (fd[1]) != 1)
|
|
1132 |
return -1;
|
|
1133 |
close (fd[1]);
|
|
1134 |
execlp ("gzcat", "gzcat", name, 0);
|
|
1135 |
return -1;
|
|
1136 |
default:
|
|
1137 |
close (fd[1]);
|
|
1138 |
break;
|
|
1139 |
}
|
|
1140 |
return fd[0];
|
|
1141 |
}
|
0
|
1142 |
|
|
1143 |
static FontFilePtr
|
|
1144 |
FontFileOpen (char *name) {
|
|
1145 |
int fd;
|
|
1146 |
int len;
|
|
1147 |
BufFilePtr raw, cooked;
|
|
1148 |
|
294
|
1149 |
len = strlen (name);
|
|
1150 |
|
|
1151 |
/*
|
|
1152 |
* A little hack for .gz file support.
|
|
1153 |
* We gzcat the file and will treat the
|
|
1154 |
* resultant fd as a regular file's.
|
|
1155 |
*/
|
|
1156 |
|
|
1157 |
if (len > 3 && !strcmp (name + len - 3, ".gz"))
|
|
1158 |
fd = gzcatfile (name);
|
|
1159 |
else
|
|
1160 |
fd = open (name, 0);
|
|
1161 |
|
0
|
1162 |
if (fd < 0)
|
|
1163 |
return 0;
|
|
1164 |
raw = BufFileOpenRead (fd);
|
|
1165 |
if (!raw)
|
|
1166 |
{
|
|
1167 |
close (fd);
|
|
1168 |
return 0;
|
|
1169 |
}
|
|
1170 |
if (len > 2 && !strcmp (name + len - 2, ".Z")) {
|
|
1171 |
cooked = BufFilePushCompressed (raw);
|
|
1172 |
if (!cooked) {
|
|
1173 |
BufFileClose (raw, TRUE);
|
|
1174 |
return 0;
|
|
1175 |
}
|
|
1176 |
raw = cooked;
|
|
1177 |
}
|
|
1178 |
return (FontFilePtr) raw;
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
static void FontFileClose (FontFilePtr f)
|
|
1182 |
{
|
|
1183 |
BufFileClose ((BufFilePtr) f, TRUE);
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
static int
|
|
1187 |
pcfGetLSB32(file)
|
|
1188 |
FontFilePtr file;
|
|
1189 |
{
|
|
1190 |
int c;
|
|
1191 |
|
|
1192 |
c = FontFileGetc(file);
|
|
1193 |
c |= FontFileGetc(file) << 8;
|
|
1194 |
c |= FontFileGetc(file) << 16;
|
|
1195 |
c |= FontFileGetc(file) << 24;
|
|
1196 |
position += 4;
|
|
1197 |
return c;
|
|
1198 |
}
|
|
1199 |
|
|
1200 |
static PCFTablePtr
|
|
1201 |
pcfReadTOC(file, countp)
|
|
1202 |
FontFilePtr file;
|
|
1203 |
int *countp;
|
|
1204 |
{
|
|
1205 |
CARD32 version;
|
|
1206 |
PCFTablePtr tables;
|
|
1207 |
int count;
|
|
1208 |
int i;
|
|
1209 |
|
|
1210 |
position = 0;
|
|
1211 |
version = pcfGetLSB32(file);
|
|
1212 |
if (version != PCF_FILE_VERSION)
|
|
1213 |
return (PCFTablePtr) NULL;
|
|
1214 |
count = pcfGetLSB32(file);
|
|
1215 |
tables = (PCFTablePtr) xalloc(count * sizeof(PCFTableRec));
|
|
1216 |
if (!tables)
|
|
1217 |
return (PCFTablePtr) NULL;
|
|
1218 |
for (i = 0; i < count; i++) {
|
|
1219 |
tables[i].type = pcfGetLSB32(file);
|
|
1220 |
tables[i].format = pcfGetLSB32(file);
|
|
1221 |
tables[i].size = pcfGetLSB32(file);
|
|
1222 |
tables[i].offset = pcfGetLSB32(file);
|
|
1223 |
}
|
|
1224 |
*countp = count;
|
|
1225 |
return tables;
|
|
1226 |
}
|
|
1227 |
|
|
1228 |
|
|
1229 |
static
|
|
1230 |
ResizeHashTable ()
|
|
1231 |
{
|
|
1232 |
int newHashSize;
|
|
1233 |
int newHashMask;
|
|
1234 |
AtomListPtr *newHashTable;
|
|
1235 |
int i;
|
|
1236 |
int h;
|
|
1237 |
int newRehash;
|
|
1238 |
int r;
|
|
1239 |
|
|
1240 |
if (hashSize == 0)
|
|
1241 |
newHashSize = 1024;
|
|
1242 |
else
|
|
1243 |
newHashSize = hashSize * 2;
|
|
1244 |
newHashTable = (AtomListPtr *) xalloc (newHashSize * sizeof (AtomListPtr));
|
|
1245 |
if (!newHashTable)
|
|
1246 |
return FALSE;
|
|
1247 |
bzero ((char *) newHashTable, newHashSize * sizeof (AtomListPtr));
|
|
1248 |
newHashMask = newHashSize - 1;
|
|
1249 |
newRehash = (newHashMask - 2);
|
|
1250 |
for (i = 0; i < hashSize; i++)
|
|
1251 |
{
|
|
1252 |
if (hashTable[i])
|
|
1253 |
{
|
|
1254 |
h = (hashTable[i]->hash) & newHashMask;
|
|
1255 |
if (newHashTable[h])
|
|
1256 |
{
|
|
1257 |
r = hashTable[i]->hash % newRehash | 1;
|
|
1258 |
do {
|
|
1259 |
h += r;
|
|
1260 |
if (h >= newHashSize)
|
|
1261 |
h -= newHashSize;
|
|
1262 |
} while (newHashTable[h]);
|
|
1263 |
}
|
|
1264 |
newHashTable[h] = hashTable[i];
|
|
1265 |
}
|
|
1266 |
}
|
|
1267 |
xfree (hashTable);
|
|
1268 |
hashTable = newHashTable;
|
|
1269 |
hashSize = newHashSize;
|
|
1270 |
hashMask = newHashMask;
|
|
1271 |
rehash = newRehash;
|
|
1272 |
return TRUE;
|
|
1273 |
}
|
|
1274 |
|
|
1275 |
static
|
|
1276 |
Hash(string, len)
|
|
1277 |
char *string;
|
|
1278 |
{
|
|
1279 |
int h;
|
|
1280 |
|
|
1281 |
h = 0;
|
|
1282 |
while (len--)
|
|
1283 |
h = (h << 3) ^ *string++;
|
|
1284 |
if (h < 0)
|
|
1285 |
return -h;
|
|
1286 |
return h;
|
|
1287 |
}
|
|
1288 |
static Atom
|
|
1289 |
MakeAtom(string, len, makeit)
|
|
1290 |
char *string;
|
|
1291 |
unsigned len;
|
|
1292 |
int makeit;
|
|
1293 |
{
|
|
1294 |
AtomListPtr a;
|
|
1295 |
int hash;
|
|
1296 |
int h;
|
|
1297 |
int r;
|
|
1298 |
|
|
1299 |
hash = Hash (string, len);
|
|
1300 |
if (hashTable)
|
|
1301 |
{
|
|
1302 |
h = hash & hashMask;
|
|
1303 |
if (hashTable[h])
|
|
1304 |
{
|
|
1305 |
if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
|
|
1306 |
NameEqual (hashTable[h]->name, string, len))
|
|
1307 |
{
|
|
1308 |
return hashTable[h]->atom;
|
|
1309 |
}
|
|
1310 |
r = (hash % rehash) | 1;
|
|
1311 |
for (;;)
|
|
1312 |
{
|
|
1313 |
h += r;
|
|
1314 |
if (h >= hashSize)
|
|
1315 |
h -= hashSize;
|
|
1316 |
if (!hashTable[h])
|
|
1317 |
break;
|
|
1318 |
if (hashTable[h]->hash == hash && hashTable[h]->len == len &&
|
|
1319 |
NameEqual (hashTable[h]->name, string, len))
|
|
1320 |
{
|
|
1321 |
return hashTable[h]->atom;
|
|
1322 |
}
|
|
1323 |
}
|
|
1324 |
}
|
|
1325 |
}
|
|
1326 |
if (!makeit)
|
|
1327 |
return None;
|
|
1328 |
a = (AtomListPtr) xalloc (sizeof (AtomListRec) + len + 1);
|
|
1329 |
a->name = (char *) (a + 1);
|
|
1330 |
a->len = len;
|
|
1331 |
strncpy (a->name, string, len);
|
|
1332 |
a->name[len] = '\0';
|
|
1333 |
a->atom = ++lastAtom;
|
|
1334 |
a->hash = hash;
|
|
1335 |
if (hashUsed >= hashSize / 2)
|
|
1336 |
{
|
|
1337 |
ResizeHashTable ();
|
|
1338 |
h = hash & hashMask;
|
|
1339 |
if (hashTable[h])
|
|
1340 |
{
|
|
1341 |
r = (hash % rehash) | 1;
|
|
1342 |
do {
|
|
1343 |
h += r;
|
|
1344 |
if (h >= hashSize)
|
|
1345 |
h -= hashSize;
|
|
1346 |
} while (hashTable[h]);
|
|
1347 |
}
|
|
1348 |
}
|
|
1349 |
hashTable[h] = a;
|
|
1350 |
hashUsed++;
|
|
1351 |
if (reverseMapSize <= a->atom)
|
|
1352 |
ResizeReverseMap();
|
|
1353 |
reverseMap[a->atom] = a;
|
|
1354 |
return a->atom;
|
|
1355 |
}
|
|
1356 |
|
|
1357 |
BufFileRead (f, b, n)
|
|
1358 |
BufFilePtr f;
|
|
1359 |
char *b;
|
|
1360 |
int n;
|
|
1361 |
{
|
|
1362 |
int c, cnt;
|
|
1363 |
cnt = n;
|
|
1364 |
while (cnt--) {
|
|
1365 |
c = BufFileGet (f);
|
|
1366 |
if (c == BUFFILEEOF)
|
|
1367 |
break;
|
|
1368 |
*b++ = c;
|
|
1369 |
}
|
|
1370 |
return n - cnt - 1;
|
|
1371 |
}
|
|
1372 |
static Bool
|
|
1373 |
pcfGetProperties(pFontInfo, file, tables, ntables)
|
|
1374 |
FontInfoPtr pFontInfo;
|
|
1375 |
FontFilePtr file;
|
|
1376 |
PCFTablePtr tables;
|
|
1377 |
int ntables;
|
|
1378 |
{
|
|
1379 |
FontPropPtr props = 0;
|
|
1380 |
int nprops;
|
|
1381 |
char *isStringProp = 0;
|
|
1382 |
CARD32 format;
|
|
1383 |
int i;
|
|
1384 |
/* changed by suresh 07/12/99 from int to CARD 32*/
|
|
1385 |
CARD32 size;
|
|
1386 |
int string_size;
|
|
1387 |
char *strings;
|
|
1388 |
|
|
1389 |
/* font properties */
|
|
1390 |
|
|
1391 |
if (!pcfSeekToType(file, tables, ntables, PCF_PROPERTIES, &format, &size))
|
|
1392 |
goto Bail;
|
|
1393 |
format = pcfGetLSB32(file);
|
|
1394 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1395 |
goto Bail;
|
|
1396 |
nprops = pcfGetINT32(file, format);
|
|
1397 |
props = (FontPropPtr) xalloc(nprops * sizeof(FontPropRec));
|
|
1398 |
if (!props)
|
|
1399 |
goto Bail;
|
|
1400 |
isStringProp = (char *) xalloc(nprops * sizeof(char));
|
|
1401 |
if (!isStringProp)
|
|
1402 |
goto Bail;
|
|
1403 |
for (i = 0; i < nprops; i++) {
|
|
1404 |
props[i].name = pcfGetINT32(file, format);
|
|
1405 |
isStringProp[i] = pcfGetINT8(file, format);
|
|
1406 |
props[i].value = pcfGetINT32(file, format);
|
|
1407 |
}
|
|
1408 |
/* pad the property array */
|
|
1409 |
/*
|
|
1410 |
* clever here - nprops is the same as the number of odd-units read, as
|
|
1411 |
* only isStringProp are odd length
|
|
1412 |
*/
|
|
1413 |
if (nprops & 3)
|
|
1414 |
{
|
|
1415 |
i = 4 - (nprops & 3);
|
|
1416 |
FontFileSkip(file, i);
|
|
1417 |
position += i;
|
|
1418 |
}
|
|
1419 |
string_size = pcfGetINT32(file, format);
|
|
1420 |
strings = (char *) xalloc(string_size);
|
|
1421 |
if (!strings) {
|
|
1422 |
goto Bail;
|
|
1423 |
}
|
|
1424 |
FontFileRead(file, strings, string_size);
|
|
1425 |
position += string_size;
|
|
1426 |
for (i = 0; i < nprops; i++) {
|
|
1427 |
props[i].name = MakeAtom(strings + props[i].name,
|
|
1428 |
strlen(strings + props[i].name), TRUE);
|
|
1429 |
if (isStringProp[i]) {
|
|
1430 |
props[i].value = MakeAtom(strings + props[i].value,
|
|
1431 |
strlen(strings + props[i].value), TRUE);
|
|
1432 |
}
|
|
1433 |
}
|
|
1434 |
xfree(strings);
|
|
1435 |
pFontInfo->isStringProp = isStringProp;
|
|
1436 |
pFontInfo->props = props;
|
|
1437 |
pFontInfo->nprops = nprops;
|
|
1438 |
return TRUE;
|
|
1439 |
Bail:
|
|
1440 |
xfree(isStringProp);
|
|
1441 |
xfree(props);
|
|
1442 |
return FALSE;
|
|
1443 |
}
|
|
1444 |
|
|
1445 |
static void
|
|
1446 |
pcfGetCompressedMetric(file, format, metric)
|
|
1447 |
FontFilePtr file;
|
|
1448 |
CARD32 format;
|
|
1449 |
xCharInfo *metric;
|
|
1450 |
{
|
|
1451 |
metric->leftSideBearing = pcfGetINT8(file, format) - 0x80;
|
|
1452 |
metric->rightSideBearing = pcfGetINT8(file, format) - 0x80;
|
|
1453 |
metric->characterWidth = pcfGetINT8(file, format) - 0x80;
|
|
1454 |
metric->ascent = pcfGetINT8(file, format) - 0x80;
|
|
1455 |
metric->descent = pcfGetINT8(file, format) - 0x80;
|
|
1456 |
metric->attributes = 0;
|
|
1457 |
}
|
|
1458 |
|
|
1459 |
static Bool
|
|
1460 |
pcfSeekToType(file, tables, ntables, type, formatp, sizep)
|
|
1461 |
FontFilePtr file;
|
|
1462 |
PCFTablePtr tables;
|
|
1463 |
int ntables;
|
|
1464 |
CARD32 type;
|
|
1465 |
CARD32 *formatp;
|
|
1466 |
CARD32 *sizep;
|
|
1467 |
{
|
|
1468 |
int i;
|
|
1469 |
|
|
1470 |
for (i = 0; i < ntables; i++)
|
|
1471 |
if (tables[i].type == type) {
|
|
1472 |
if (position > tables[i].offset)
|
|
1473 |
return FALSE;
|
|
1474 |
if (!FontFileSkip(file, tables[i].offset - position))
|
|
1475 |
return FALSE;
|
|
1476 |
position = tables[i].offset;
|
|
1477 |
*sizep = tables[i].size;
|
|
1478 |
*formatp = tables[i].format;
|
|
1479 |
return TRUE;
|
|
1480 |
}
|
|
1481 |
return FALSE;
|
|
1482 |
}
|
|
1483 |
|
|
1484 |
static int
|
|
1485 |
pcfGetINT32(file, format)
|
|
1486 |
FontFilePtr file;
|
|
1487 |
CARD32 format;
|
|
1488 |
{
|
|
1489 |
int c;
|
|
1490 |
|
|
1491 |
if (PCF_BYTE_ORDER(format) == MSBFirst) {
|
|
1492 |
c = FontFileGetc(file) << 24;
|
|
1493 |
c |= FontFileGetc(file) << 16;
|
|
1494 |
c |= FontFileGetc(file) << 8;
|
|
1495 |
c |= FontFileGetc(file);
|
|
1496 |
} else {
|
|
1497 |
c = FontFileGetc(file);
|
|
1498 |
c |= FontFileGetc(file) << 8;
|
|
1499 |
c |= FontFileGetc(file) << 16;
|
|
1500 |
c |= FontFileGetc(file) << 24;
|
|
1501 |
}
|
|
1502 |
position += 4;
|
|
1503 |
return c;
|
|
1504 |
}
|
|
1505 |
static int
|
|
1506 |
pcfGetINT16(file, format)
|
|
1507 |
FontFilePtr file;
|
|
1508 |
CARD32 format;
|
|
1509 |
{
|
|
1510 |
int c;
|
|
1511 |
|
|
1512 |
if (PCF_BYTE_ORDER(format) == MSBFirst) {
|
|
1513 |
c = FontFileGetc(file) << 8;
|
|
1514 |
c |= FontFileGetc(file);
|
|
1515 |
} else {
|
|
1516 |
c = FontFileGetc(file);
|
|
1517 |
c |= FontFileGetc(file) << 8;
|
|
1518 |
}
|
|
1519 |
position += 2;
|
|
1520 |
return c;
|
|
1521 |
}
|
|
1522 |
|
|
1523 |
/*
|
|
1524 |
* pcfReadAccel
|
|
1525 |
*
|
|
1526 |
* Fill in the accelerator information from the font file; used
|
|
1527 |
* to read both BDF_ACCELERATORS and old style ACCELERATORS
|
|
1528 |
*/
|
|
1529 |
|
|
1530 |
static Bool
|
|
1531 |
pcfGetAccel(pFontInfo, file, tables, ntables, type)
|
|
1532 |
FontInfoPtr pFontInfo;
|
|
1533 |
FontFilePtr file;
|
|
1534 |
PCFTablePtr tables;
|
|
1535 |
int ntables;
|
|
1536 |
CARD32 type;
|
|
1537 |
{
|
|
1538 |
CARD32 format;
|
|
1539 |
/* changed by suresh 07/12/99 from int to CARD 32*/
|
|
1540 |
CARD32 size;
|
|
1541 |
|
|
1542 |
if (!pcfSeekToType(file, tables, ntables, type, &format, &size))
|
|
1543 |
goto Bail;
|
|
1544 |
format = pcfGetLSB32(file);
|
|
1545 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
|
|
1546 |
!PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS))
|
|
1547 |
{
|
|
1548 |
goto Bail;
|
|
1549 |
}
|
|
1550 |
pFontInfo->noOverlap = pcfGetINT8(file, format);
|
|
1551 |
pFontInfo->constantMetrics = pcfGetINT8(file, format);
|
|
1552 |
pFontInfo->terminalFont = pcfGetINT8(file, format);
|
|
1553 |
pFontInfo->constantWidth = pcfGetINT8(file, format);
|
|
1554 |
pFontInfo->inkInside = pcfGetINT8(file, format);
|
|
1555 |
pFontInfo->inkMetrics = pcfGetINT8(file, format);
|
|
1556 |
pFontInfo->drawDirection = pcfGetINT8(file, format);
|
|
1557 |
pFontInfo->anamorphic = FALSE;
|
|
1558 |
/* natural alignment */ pcfGetINT8(file, format);
|
|
1559 |
pFontInfo->fontAscent = pcfGetINT32(file, format);
|
|
1560 |
pFontInfo->fontDescent = pcfGetINT32(file, format);
|
|
1561 |
pFontInfo->maxOverlap = pcfGetINT32(file, format);
|
|
1562 |
pcfGetMetric(file, format, &pFontInfo->minbounds);
|
|
1563 |
pcfGetMetric(file, format, &pFontInfo->maxbounds);
|
|
1564 |
if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {
|
|
1565 |
pcfGetMetric(file, format, &pFontInfo->ink_minbounds);
|
|
1566 |
pcfGetMetric(file, format, &pFontInfo->ink_maxbounds);
|
|
1567 |
} else {
|
|
1568 |
pFontInfo->ink_minbounds = pFontInfo->minbounds;
|
|
1569 |
pFontInfo->ink_maxbounds = pFontInfo->maxbounds;
|
|
1570 |
}
|
|
1571 |
return TRUE;
|
|
1572 |
Bail:
|
|
1573 |
return FALSE;
|
|
1574 |
}
|
|
1575 |
|
|
1576 |
static void
|
|
1577 |
pcfGetMetric(file, format, metric)
|
|
1578 |
FontFilePtr file;
|
|
1579 |
CARD32 format;
|
|
1580 |
xCharInfo *metric;
|
|
1581 |
{
|
|
1582 |
metric->leftSideBearing = pcfGetINT16(file, format);
|
|
1583 |
metric->rightSideBearing = pcfGetINT16(file, format);
|
|
1584 |
metric->characterWidth = pcfGetINT16(file, format);
|
|
1585 |
metric->ascent = pcfGetINT16(file, format);
|
|
1586 |
metric->descent = pcfGetINT16(file, format);
|
|
1587 |
metric->attributes = pcfGetINT16(file, format);
|
|
1588 |
}
|
|
1589 |
|
|
1590 |
int
|
|
1591 |
bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
|
|
1592 |
FontPtr pFont;
|
|
1593 |
unsigned long count;
|
|
1594 |
unsigned char *chars;
|
|
1595 |
FontEncoding charEncoding;
|
|
1596 |
unsigned long *glyphCount; /* RETURN */
|
|
1597 |
CharInfoPtr *glyphs; /* RETURN */
|
|
1598 |
{
|
|
1599 |
BitmapFontPtr bitmapFont;
|
|
1600 |
unsigned int firstCol;
|
|
1601 |
register unsigned int numCols;
|
|
1602 |
unsigned int firstRow;
|
|
1603 |
unsigned int numRows;
|
|
1604 |
CharInfoPtr *glyphsBase;
|
|
1605 |
register unsigned int c;
|
|
1606 |
register CharInfoPtr pci;
|
|
1607 |
unsigned int r;
|
|
1608 |
CharInfoPtr *encoding;
|
|
1609 |
CharInfoPtr pDefault;
|
|
1610 |
|
|
1611 |
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
|
|
1612 |
encoding = bitmapFont->encoding;
|
|
1613 |
pDefault = bitmapFont->pDefault;
|
|
1614 |
firstCol = pFont->info.firstCol;
|
|
1615 |
numCols = pFont->info.lastCol - firstCol + 1;
|
|
1616 |
glyphsBase = glyphs;
|
|
1617 |
switch (charEncoding) {
|
|
1618 |
|
|
1619 |
case Linear8Bit:
|
|
1620 |
case TwoD8Bit:
|
|
1621 |
if (pFont->info.firstRow > 0)
|
|
1622 |
break;
|
|
1623 |
if (pFont->info.allExist && pDefault) {
|
|
1624 |
while (count--) {
|
|
1625 |
c = (*chars++) - firstCol;
|
|
1626 |
if (c < numCols)
|
|
1627 |
*glyphs++ = encoding[c];
|
|
1628 |
else
|
|
1629 |
*glyphs++ = pDefault;
|
|
1630 |
}
|
|
1631 |
} else {
|
|
1632 |
while (count--) {
|
|
1633 |
c = (*chars++) - firstCol;
|
|
1634 |
if (c < numCols && (pci = encoding[c]))
|
|
1635 |
*glyphs++ = pci;
|
|
1636 |
else if (pDefault)
|
|
1637 |
*glyphs++ = pDefault;
|
|
1638 |
}
|
|
1639 |
}
|
|
1640 |
break;
|
|
1641 |
case Linear16Bit:
|
|
1642 |
if (pFont->info.allExist && pDefault) {
|
|
1643 |
while (count--) {
|
|
1644 |
c = *chars++ << 8;
|
|
1645 |
c = (c | *chars++) - firstCol;
|
|
1646 |
if (c < numCols)
|
|
1647 |
*glyphs++ = encoding[c];
|
|
1648 |
else
|
|
1649 |
*glyphs++ = pDefault;
|
|
1650 |
}
|
|
1651 |
} else {
|
|
1652 |
while (count--) {
|
|
1653 |
c = *chars++ << 8;
|
|
1654 |
c = (c | *chars++) - firstCol;
|
|
1655 |
if (c < numCols && (pci = encoding[c]))
|
|
1656 |
*glyphs++ = pci;
|
|
1657 |
else if (pDefault)
|
|
1658 |
*glyphs++ = pDefault;
|
|
1659 |
}
|
|
1660 |
}
|
|
1661 |
break;
|
|
1662 |
|
|
1663 |
case TwoD16Bit:
|
|
1664 |
firstRow = pFont->info.firstRow;
|
|
1665 |
numRows = pFont->info.lastRow - firstRow + 1;
|
|
1666 |
while (count--) {
|
|
1667 |
r = (*chars++) - firstRow;
|
|
1668 |
c = (*chars++) - firstCol;
|
|
1669 |
if (r < numRows && c < numCols &&
|
|
1670 |
(pci = encoding[r * numCols + c]))
|
|
1671 |
*glyphs++ = pci;
|
|
1672 |
else if (pDefault)
|
|
1673 |
*glyphs++ = pDefault;
|
|
1674 |
}
|
|
1675 |
break;
|
|
1676 |
}
|
|
1677 |
*glyphCount = glyphs - glyphsBase;
|
|
1678 |
return Successful;
|
|
1679 |
}
|
|
1680 |
|
|
1681 |
|
|
1682 |
int
|
|
1683 |
bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
|
|
1684 |
FontPtr pFont;
|
|
1685 |
unsigned long count;
|
|
1686 |
unsigned char *chars;
|
|
1687 |
FontEncoding charEncoding;
|
|
1688 |
unsigned long *glyphCount; /* RETURN */
|
|
1689 |
xCharInfo **glyphs; /* RETURN */
|
|
1690 |
{
|
|
1691 |
int ret;
|
|
1692 |
xCharInfo *ink_metrics;
|
|
1693 |
CharInfoPtr metrics;
|
|
1694 |
BitmapFontPtr bitmapFont;
|
|
1695 |
CharInfoPtr oldDefault;
|
|
1696 |
int i;
|
|
1697 |
|
|
1698 |
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
|
|
1699 |
oldDefault = bitmapFont->pDefault;
|
|
1700 |
bitmapFont->pDefault = &nonExistantChar;
|
|
1701 |
ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
|
|
1702 |
if (ret == Successful) {
|
|
1703 |
if (bitmapFont->ink_metrics) {
|
|
1704 |
metrics = bitmapFont->metrics;
|
|
1705 |
ink_metrics = bitmapFont->ink_metrics;
|
|
1706 |
for (i = 0; i < *glyphCount; i++) {
|
|
1707 |
if (glyphs[i] != (xCharInfo *) & nonExistantChar)
|
|
1708 |
glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
|
|
1709 |
}
|
|
1710 |
}
|
|
1711 |
}
|
|
1712 |
bitmapFont->pDefault = oldDefault;
|
|
1713 |
return ret;
|
|
1714 |
}
|
|
1715 |
|
|
1716 |
void
|
|
1717 |
pcfUnloadFont(pFont)
|
|
1718 |
FontPtr pFont;
|
|
1719 |
{
|
|
1720 |
BitmapFontPtr bitmapFont;
|
|
1721 |
|
|
1722 |
bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
|
|
1723 |
xfree(bitmapFont->ink_metrics);
|
|
1724 |
xfree(bitmapFont->encoding);
|
|
1725 |
xfree(bitmapFont->bitmaps);
|
|
1726 |
xfree(bitmapFont->metrics);
|
|
1727 |
xfree(pFont->info.isStringProp);
|
|
1728 |
xfree(pFont->info.props);
|
|
1729 |
xfree(bitmapFont);
|
|
1730 |
xfree(pFont);
|
|
1731 |
}
|
|
1732 |
static int
|
|
1733 |
pcfReadFont(pFont, file, bit, byte, glyph, scan)
|
|
1734 |
FontPtr pFont;
|
|
1735 |
FontFilePtr file;
|
|
1736 |
int bit,
|
|
1737 |
byte,
|
|
1738 |
glyph,
|
|
1739 |
scan;
|
|
1740 |
{
|
|
1741 |
CARD32 format;
|
|
1742 |
CARD32 size;
|
|
1743 |
BitmapFontPtr bitmapFont = 0;
|
|
1744 |
int i;
|
|
1745 |
PCFTablePtr tables = 0;
|
|
1746 |
int ntables;
|
|
1747 |
int nmetrics;
|
|
1748 |
int nbitmaps;
|
|
1749 |
int sizebitmaps;
|
|
1750 |
int nink_metrics;
|
|
1751 |
CharInfoPtr metrics = 0;
|
|
1752 |
xCharInfo *ink_metrics = 0;
|
|
1753 |
char *bitmaps = 0;
|
|
1754 |
CharInfoPtr *encoding = 0;
|
|
1755 |
int nencoding;
|
|
1756 |
int encodingOffset;
|
|
1757 |
CARD32 bitmapSizes[GLYPHPADOPTIONS];
|
|
1758 |
CARD32 *offsets = 0;
|
|
1759 |
Bool hasBDFAccelerators;
|
|
1760 |
|
|
1761 |
pFont->info.props = 0;
|
|
1762 |
if (!(tables = pcfReadTOC(file, &ntables)))
|
|
1763 |
goto Bail;
|
|
1764 |
|
|
1765 |
/* properties */
|
|
1766 |
|
|
1767 |
if (!pcfGetProperties(&pFont->info, file, tables, ntables))
|
|
1768 |
goto Bail;
|
|
1769 |
|
|
1770 |
/* Use the old accelerators if no BDF accelerators are in the file */
|
|
1771 |
|
|
1772 |
hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);
|
|
1773 |
if (!hasBDFAccelerators)
|
|
1774 |
if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_ACCELERATORS))
|
|
1775 |
goto Bail;
|
|
1776 |
|
|
1777 |
/* metrics */
|
|
1778 |
|
|
1779 |
if (!pcfSeekToType(file, tables, ntables, PCF_METRICS, &format, &size)) {
|
|
1780 |
goto Bail;
|
|
1781 |
}
|
|
1782 |
format = pcfGetLSB32(file);
|
|
1783 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
|
|
1784 |
!PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
|
|
1785 |
goto Bail;
|
|
1786 |
}
|
|
1787 |
if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1788 |
nmetrics = pcfGetINT32(file, format);
|
|
1789 |
else
|
|
1790 |
nmetrics = pcfGetINT16(file, format);
|
|
1791 |
metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));
|
|
1792 |
if (!metrics) {
|
|
1793 |
goto Bail;
|
|
1794 |
}
|
|
1795 |
for (i = 0; i < nmetrics; i++)
|
|
1796 |
if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1797 |
pcfGetMetric(file, format, &(metrics + i)->metrics);
|
|
1798 |
else
|
|
1799 |
pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);
|
|
1800 |
|
|
1801 |
/* bitmaps */
|
|
1802 |
|
|
1803 |
if (!pcfSeekToType(file, tables, ntables, PCF_BITMAPS, &format, &size))
|
|
1804 |
goto Bail;
|
|
1805 |
format = pcfGetLSB32(file);
|
|
1806 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1807 |
goto Bail;
|
|
1808 |
|
|
1809 |
nbitmaps = pcfGetINT32(file, format);
|
|
1810 |
if (nbitmaps != nmetrics)
|
|
1811 |
goto Bail;
|
|
1812 |
|
|
1813 |
offsets = (CARD32 *) xalloc(nbitmaps * sizeof(CARD32));
|
|
1814 |
if (!offsets)
|
|
1815 |
goto Bail;
|
|
1816 |
|
|
1817 |
for (i = 0; i < nbitmaps; i++)
|
|
1818 |
offsets[i] = pcfGetINT32(file, format);
|
|
1819 |
|
|
1820 |
for (i = 0; i < GLYPHPADOPTIONS; i++)
|
|
1821 |
bitmapSizes[i] = pcfGetINT32(file, format);
|
|
1822 |
sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX(format)];
|
|
1823 |
bitmaps = (char *) xalloc(sizebitmaps);
|
|
1824 |
if (!bitmaps)
|
|
1825 |
goto Bail;
|
|
1826 |
FontFileRead(file, bitmaps, sizebitmaps);
|
|
1827 |
position += sizebitmaps;
|
|
1828 |
|
|
1829 |
if (PCF_BIT_ORDER(format) != bit)
|
|
1830 |
BitOrderInvert((unsigned char*)bitmaps, sizebitmaps);
|
|
1831 |
if ((PCF_BYTE_ORDER(format) == PCF_BIT_ORDER(format)) != (bit == byte)) {
|
|
1832 |
switch (bit == byte ? PCF_SCAN_UNIT(format) : scan) {
|
|
1833 |
case 1:
|
|
1834 |
break;
|
|
1835 |
case 2:
|
|
1836 |
TwoByteSwap((unsigned char*)bitmaps, sizebitmaps);
|
|
1837 |
break;
|
|
1838 |
case 4:
|
|
1839 |
FourByteSwap((unsigned char*)bitmaps, sizebitmaps);
|
|
1840 |
break;
|
|
1841 |
}
|
|
1842 |
}
|
|
1843 |
if (PCF_GLYPH_PAD(format) != glyph) {
|
|
1844 |
char *padbitmaps;
|
|
1845 |
int sizepadbitmaps;
|
|
1846 |
int old,
|
|
1847 |
new;
|
|
1848 |
xCharInfo *metric;
|
|
1849 |
|
|
1850 |
sizepadbitmaps = bitmapSizes[PCF_SIZE_TO_INDEX(glyph)];
|
|
1851 |
padbitmaps = (char *) xalloc(sizepadbitmaps);
|
|
1852 |
if (!padbitmaps) {
|
|
1853 |
goto Bail;
|
|
1854 |
}
|
|
1855 |
new = 0;
|
|
1856 |
for (i = 0; i < nbitmaps; i++) {
|
|
1857 |
old = offsets[i];
|
|
1858 |
metric = &metrics[i].metrics;
|
|
1859 |
offsets[i] = new;
|
|
1860 |
new += RepadBitmap(bitmaps + old, padbitmaps + new,
|
|
1861 |
PCF_GLYPH_PAD(format), glyph,
|
|
1862 |
metric->rightSideBearing - metric->leftSideBearing,
|
|
1863 |
metric->ascent + metric->descent);
|
|
1864 |
}
|
|
1865 |
xfree(bitmaps);
|
|
1866 |
bitmaps = padbitmaps;
|
|
1867 |
}
|
|
1868 |
for (i = 0; i < nbitmaps; i++)
|
|
1869 |
metrics[i].bits = bitmaps + offsets[i];
|
|
1870 |
|
|
1871 |
xfree(offsets);
|
|
1872 |
|
|
1873 |
/* ink metrics ? */
|
|
1874 |
|
|
1875 |
ink_metrics = NULL;
|
|
1876 |
if (pcfSeekToType(file, tables, ntables, PCF_INK_METRICS, &format, &size)) {
|
|
1877 |
format = pcfGetLSB32(file);
|
|
1878 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&
|
|
1879 |
!PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {
|
|
1880 |
goto Bail;
|
|
1881 |
}
|
|
1882 |
if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1883 |
nink_metrics = pcfGetINT32(file, format);
|
|
1884 |
else
|
|
1885 |
nink_metrics = pcfGetINT16(file, format);
|
|
1886 |
if (nink_metrics != nmetrics)
|
|
1887 |
goto Bail;
|
|
1888 |
ink_metrics = (xCharInfo *) xalloc(nink_metrics * sizeof(xCharInfo));
|
|
1889 |
if (!ink_metrics)
|
|
1890 |
goto Bail;
|
|
1891 |
for (i = 0; i < nink_metrics; i++)
|
|
1892 |
if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1893 |
pcfGetMetric(file, format, ink_metrics + i);
|
|
1894 |
else
|
|
1895 |
pcfGetCompressedMetric(file, format, ink_metrics + i);
|
|
1896 |
}
|
|
1897 |
|
|
1898 |
/* encoding */
|
|
1899 |
|
|
1900 |
if (!pcfSeekToType(file, tables, ntables, PCF_BDF_ENCODINGS, &format, &size))
|
|
1901 |
goto Bail;
|
|
1902 |
format = pcfGetLSB32(file);
|
|
1903 |
if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))
|
|
1904 |
goto Bail;
|
|
1905 |
|
|
1906 |
pFont->info.firstCol = pcfGetINT16(file, format);
|
|
1907 |
pFont->info.lastCol = pcfGetINT16(file, format);
|
|
1908 |
pFont->info.firstRow = pcfGetINT16(file, format);
|
|
1909 |
pFont->info.lastRow = pcfGetINT16(file, format);
|
|
1910 |
pFont->info.defaultCh = pcfGetINT16(file, format);
|
|
1911 |
|
|
1912 |
nencoding = (pFont->info.lastCol - pFont->info.firstCol + 1) *
|
|
1913 |
(pFont->info.lastRow - pFont->info.firstRow + 1);
|
|
1914 |
|
|
1915 |
encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));
|
|
1916 |
if (!encoding)
|
|
1917 |
goto Bail;
|
|
1918 |
|
|
1919 |
pFont->info.allExist = TRUE;
|
|
1920 |
for (i = 0; i < nencoding; i++) {
|
|
1921 |
encodingOffset = pcfGetINT16(file, format);
|
|
1922 |
if (encodingOffset == 0xFFFF) {
|
|
1923 |
pFont->info.allExist = FALSE;
|
|
1924 |
encoding[i] = 0;
|
|
1925 |
} else
|
|
1926 |
encoding[i] = metrics + encodingOffset;
|
|
1927 |
}
|
|
1928 |
|
|
1929 |
/* BDF style accelerators (i.e. bounds based on encoded glyphs) */
|
|
1930 |
|
|
1931 |
if (hasBDFAccelerators)
|
|
1932 |
if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_BDF_ACCELERATORS))
|
|
1933 |
goto Bail;
|
|
1934 |
|
|
1935 |
bitmapFont = (BitmapFontPtr) xalloc(sizeof *bitmapFont);
|
|
1936 |
if (!bitmapFont)
|
|
1937 |
goto Bail;
|
|
1938 |
|
|
1939 |
bitmapFont->version_num = PCF_FILE_VERSION;
|
|
1940 |
bitmapFont->num_chars = nmetrics;
|
|
1941 |
bitmapFont->num_tables = ntables;
|
|
1942 |
bitmapFont->metrics = metrics;
|
|
1943 |
bitmapFont->ink_metrics = ink_metrics;
|
|
1944 |
bitmapFont->bitmaps = bitmaps;
|
|
1945 |
bitmapFont->encoding = encoding;
|
|
1946 |
bitmapFont->pDefault = (CharInfoPtr) 0;
|
|
1947 |
if (pFont->info.defaultCh != (unsigned short) NO_SUCH_CHAR) {
|
|
1948 |
int r,
|
|
1949 |
c,
|
|
1950 |
cols;
|
|
1951 |
|
|
1952 |
r = pFont->info.defaultCh >> 8;
|
|
1953 |
c = pFont->info.defaultCh & 0xFF;
|
|
1954 |
if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&
|
|
1955 |
pFont->info.firstCol <= c && c <= pFont->info.lastCol) {
|
|
1956 |
cols = pFont->info.lastCol - pFont->info.firstCol + 1;
|
|
1957 |
r = r - pFont->info.firstRow;
|
|
1958 |
c = c - pFont->info.firstCol;
|
|
1959 |
bitmapFont->pDefault = encoding[r * cols + c];
|
|
1960 |
}
|
|
1961 |
}
|
|
1962 |
bitmapFont->bitmapExtra = (BitmapExtraPtr) 0;
|
|
1963 |
pFont->fontPrivate = (pointer) bitmapFont;
|
|
1964 |
pFont->get_glyphs = bitmapGetGlyphs;
|
|
1965 |
pFont->get_metrics = bitmapGetMetrics;
|
|
1966 |
pFont->unload_font = pcfUnloadFont;
|
|
1967 |
pFont->bit = bit;
|
|
1968 |
pFont->byte = byte;
|
|
1969 |
pFont->glyph = glyph;
|
|
1970 |
pFont->scan = scan;
|
|
1971 |
xfree(tables);
|
|
1972 |
return Successful;
|
|
1973 |
Bail:
|
|
1974 |
xfree(ink_metrics);
|
|
1975 |
xfree(encoding);
|
|
1976 |
xfree(bitmaps);
|
|
1977 |
xfree(offsets);
|
|
1978 |
xfree(metrics);
|
|
1979 |
xfree(pFont->info.props);
|
|
1980 |
pFont->info.props = 0;
|
|
1981 |
xfree(bitmapFont);
|
|
1982 |
xfree(tables);
|
|
1983 |
return AllocError;
|
|
1984 |
}
|