1
/* $Xorg: spfile.c,v 1.4 2001/02/09 02:04:00 xorgcvs Exp $ */
3
* Copyright 1990, 1991 Network Computing Devices;
4
* Portions Copyright 1987 by Digital Equipment Corporation
6
* Permission to use, copy, modify, distribute, and sell this software and
7
* its documentation for any purpose is hereby granted without fee, provided
8
* that the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the names of Network Computing Devices or Digital
11
* not be used in advertising or publicity pertaining to distribution of
12
* the software without specific, written prior permission.
14
* NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
15
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
* AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL
17
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
* Author: Dave Lemke, Network Computing Devices Inc
27
Copyright 1987, 1998 The Open Group
29
Permission to use, copy, modify, distribute, and sell this software and its
30
documentation for any purpose is hereby granted without fee, provided that
31
the above copyright notice appear in all copies and that both that
32
copyright notice and this permission notice appear in supporting
35
The above copyright notice and this permission notice shall be included
36
in all copies or substantial portions of the Software.
38
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
42
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
43
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44
OTHER DEALINGS IN THE SOFTWARE.
46
Except as contained in this notice, the name of The Open Group shall
47
not be used in advertising or otherwise to promote the sale, use or
48
other dealings in this Software without prior written authorization
52
/* $XFree86: xc/lib/font/Speedo/spfile.c,v 1.14 2001/12/14 19:56:41 dawes Exp $ */
59
#include "xf86_ansic.h"
63
#include "bics-unicode.h"
65
SpeedoFontPtr sp_fp_cur = (SpeedoFontPtr) 0;
85
}; /* Sample Font decryption key */
98
}; /* Retail Font decryption key */
100
#endif /* EXTRAFONTS */
103
static ufix8 xkey[] =
114
}; /* Sample Font decryption key */
117
static ufix8 mkey[] =
128
}; /* Font decryption key */
137
tmp = (tmp << 8) + *ptr;
147
tmp = (tmp << 8) + *ptr++;
148
tmp = (tmp << 8) + *ptr++;
149
tmp = (tmp << 8) + *ptr;
154
* loads the specified char's data
157
sp_load_char_data(fix31 file_offset, fix15 num, fix15 cb_offset)
159
SpeedoMasterFontPtr master = sp_fp_cur->master;
161
if (fseek(master->fp, (long) file_offset, (int) 0)) {
162
SpeedoErr("can't seek to char\n");
164
if ((num + cb_offset) > master->mincharsize) {
165
SpeedoErr("char buf overflow\n");
167
if (fread((master->c_buffer + cb_offset), sizeof(ufix8), num,
168
master->fp) != num) {
169
SpeedoErr("can't get char data\n");
171
master->char_data.org = (ufix8 *) master->c_buffer + cb_offset;
172
master->char_data.no_bytes = num;
174
return &master->char_data;
177
struct speedo_encoding {
183
/* Takes care of caching encodings already referenced */
185
find_encoding(const char *fontname, const char *filename,
186
int **enc, int *enc_size)
188
static struct speedo_encoding *known_encodings=0;
189
static int number_known_encodings=0;
190
static int known_encodings_size=0;
196
struct speedo_encoding *temp;
202
encoding_name = FontEncFromXLFD(fontname, strlen(fontname));
204
encoding_name="iso8859-1";
207
/* We don't go through the font library if asked for Latin-1 */
208
iso8859_1 = iso8859_1 || !strcmp(encoding_name, "iso8859-1");
210
for(i=0; i<number_known_encodings; i++) {
211
if(!strcmp(encoding_name, known_encodings[i].name)) {
212
*enc=known_encodings[i].enc;
213
*enc_size=known_encodings[i].enc_size;
218
/* it hasn't been cached yet, need to compute it */
220
/* ensure we've got enough storage first */
222
if(known_encodings==0) {
224
(struct speedo_encoding*)xalloc(2*sizeof(struct speedo_encoding)))
227
number_known_encodings=0;
228
known_encodings_size=2;
231
if(number_known_encodings >= known_encodings_size) {
233
(struct speedo_encoding*)xrealloc(known_encodings,
234
2*sizeof(struct speedo_encoding)*
235
known_encodings_size))==0)
237
known_encodings=temp;
238
known_encodings_size*=2;
243
mapping = FontEncMapFind(encoding_name,
244
FONT_ENCODING_UNICODE, -1, -1,
247
#define SPEEDO_RECODE(c) \
249
unicode_to_bics(FontEncRecode(c, mapping)): \
252
if((new_name = (char*)xalloc(strlen(encoding_name)))==0)
254
strcpy(new_name, encoding_name);
256
/* For now, we limit ourselves to 256 glyphs */
258
for(i=0; i < (mapping?mapping->encoding->size:256) && i < 256; i++)
259
if(SPEEDO_RECODE(i)>=0)
261
new_enc = (int*)xalloc(2*size*sizeof(int));
266
for(i=j=0; i < (mapping?mapping->encoding->size:256) && i < 256; i++)
267
if((k = SPEEDO_RECODE(i))>=0) {
272
known_encodings[number_known_encodings].name = new_name;
273
known_encodings[number_known_encodings].enc = new_enc;
274
known_encodings[number_known_encodings].enc_size = size;
275
number_known_encodings++;
284
sp_open_master(const char *fontname, const char *filename,
285
SpeedoMasterFontPtr *master)
287
SpeedoMasterFontPtr spmf;
298
spmf = (SpeedoMasterFontPtr) xalloc(sizeof(SpeedoMasterFontRec));
301
bzero(spmf, sizeof(SpeedoMasterFontRec));
303
spmf->f_buffer = NULL;
304
spmf->c_buffer = NULL;
307
spmf->fname = (char *) xalloc(strlen(filename) + 1);
310
fp = fopen(filename, "r");
315
strcpy(spmf->fname, filename);
317
spmf->state |= MasterFileOpen;
319
if (fread(tmp, sizeof(ufix8), 16, fp) != 16) {
323
minbufsize = (ufix32) read_4b(tmp + FH_FBFSZ);
324
f_buffer = (ufix8 *) xalloc(minbufsize);
329
spmf->f_buffer = f_buffer;
331
fseek(fp, (ufix32) 0, 0);
333
/* read in the font */
334
if (fread(f_buffer, sizeof(ufix8), (ufix16) minbufsize, fp) != minbufsize) {
338
spmf->copyright = (char *) (f_buffer + FH_CPYRT);
339
spmf->mincharsize = mincharsize = read_2b(f_buffer + FH_CBFSZ);
341
c_buffer = (ufix8 *) xalloc(mincharsize);
346
spmf->c_buffer = c_buffer;
348
spmf->font.org = spmf->f_buffer;
349
spmf->font.no_bytes = minbufsize;
351
cust_no = sp_get_cust_no(spmf->font);
353
/* XXX add custom encryption stuff here */
356
if (cust_no == SCUS0) {
358
} else if (cust_no == RCUS0) {
364
if (cust_no == XCUS0) {
369
if (cust_no == CUS0) {
372
SpeedoErr("Non - standard encryption for \"%s\"\n", filename);
379
spmf->first_char_id = read_2b(f_buffer + FH_FCHRF);
380
spmf->num_chars = read_2b(f_buffer + FH_NCHRL);
387
{ /* choose the proper encoding */
390
f = strrchr(filename, '/');
393
if (strncmp(f, "bx113", 5) == 0) {
394
spmf->enc = adobe_map;
395
spmf->enc_size = adobe_map_size;
402
if((ret=find_encoding(fontname, filename, &spmf->enc, &spmf->enc_size))
406
spmf->first_char_id = spmf->enc[0];
407
/* size of extents array */
408
spmf->max_id = spmf->enc[(spmf->enc_size - 1) * 2];
409
spmf->num_chars = spmf->enc_size;
416
*master = (SpeedoMasterFontPtr) 0;
417
sp_close_master_font(spmf);
422
sp_close_master_font(SpeedoMasterFontPtr spmf)
426
if (spmf->state & MasterFileOpen)
429
spmf->entry->u.scalable.extra->private = NULL;
431
xfree(spmf->f_buffer);
432
xfree(spmf->c_buffer);
437
sp_close_master_file(SpeedoMasterFontPtr spmf)
439
(void) fclose(spmf->fp);
440
spmf->state &= ~MasterFileOpen;
445
* reset the encryption key, and make sure the file is opened
448
sp_reset_master(SpeedoMasterFontPtr spmf)
450
sp_set_key(spmf->key);
451
if (!(spmf->state & MasterFileOpen)) {
452
spmf->fp = fopen(spmf->fname, "r");
453
/* XXX -- what to do if we can't open the file? */
454
spmf->state |= MasterFileOpen;
456
fseek(spmf->fp, 0, 0);