1 /* $TOG: spfile.c /main/13 1997/06/09 09:38:27 barstow $ */
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 (c) 1987 X Consortium
29 Permission is hereby granted, free of charge, to any person obtaining
30 a copy of this software and associated documentation files (the
31 "Software"), to deal in the Software without restriction, including
32 without limitation the rights to use, copy, modify, merge, publish,
33 distribute, sublicense, and/or sell copies of the Software, and to
34 permit persons to whom the Software is furnished to do so, subject to
35 the following conditions:
37 The above copyright notice and this permission notice shall be included
38 in all copies or substantial portions of the Software.
40 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
41 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 OTHER DEALINGS IN THE SOFTWARE.
48 Except as contained in this notice, the name of the X Consortium shall
49 not be used in advertising or otherwise to promote the sale, use or
50 other dealings in this Software without prior written authorization
51 from the X Consortium.
60 SpeedoFontPtr sp_fp_cur = (SpeedoFontPtr) 0;
80 }; /* Sample Font decryption key */
93 }; /* Retail Font decryption key */
95 #endif /* EXTRAFONTS */
109 }; /* Sample Font decryption key */
112 static ufix8 mkey[] =
123 }; /* Font decryption key */
133 tmp = (tmp << 8) + *ptr;
144 tmp = (tmp << 8) + *ptr++;
145 tmp = (tmp << 8) + *ptr++;
146 tmp = (tmp << 8) + *ptr;
151 * loads the specified char's data
154 sp_load_char_data(file_offset, num, 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;
178 sp_open_master(filename, master)
180 SpeedoMasterFontPtr *master;
182 SpeedoMasterFontPtr spmf;
193 spmf = (SpeedoMasterFontPtr) xalloc(sizeof(SpeedoMasterFontRec));
196 bzero(spmf, sizeof(SpeedoMasterFontRec));
198 spmf->f_buffer = NULL;
199 spmf->c_buffer = NULL;
202 spmf->fname = (char *) xalloc(strlen(filename) + 1);
205 fp = fopen(filename, "r");
210 strcpy(spmf->fname, filename);
212 spmf->state |= MasterFileOpen;
214 if (fread(tmp, sizeof(ufix8), 16, fp) != 16) {
218 minbufsize = (ufix32) read_4b(tmp + FH_FBFSZ);
219 f_buffer = (ufix8 *) xalloc(minbufsize);
224 spmf->f_buffer = f_buffer;
226 fseek(fp, (ufix32) 0, 0);
228 /* read in the font */
229 if (fread(f_buffer, sizeof(ufix8), (ufix16) minbufsize, fp) != minbufsize) {
233 spmf->copyright = (char *) (f_buffer + FH_CPYRT);
234 spmf->mincharsize = mincharsize = read_2b(f_buffer + FH_CBFSZ);
236 c_buffer = (ufix8 *) xalloc(mincharsize);
241 spmf->c_buffer = c_buffer;
243 spmf->font.org = spmf->f_buffer;
244 spmf->font.no_bytes = minbufsize;
246 cust_no = sp_get_cust_no(spmf->font);
248 /* XXX add custom encryption stuff here */
251 if (cust_no == SCUS0) {
253 } else if (cust_no == RCUS0) {
259 if (cust_no == XCUS0) {
264 if (cust_no == CUS0) {
267 SpeedoErr("Non - standard encryption for \"%s\"\n", filename);
274 spmf->first_char_id = read_2b(f_buffer + FH_FCHRF);
275 spmf->num_chars = read_2b(f_buffer + FH_NCHRL);
278 spmf->enc = sp_bics_map;
279 spmf->enc_size = sp_bics_map_size;
282 { /* choose the proper encoding */
285 f = strrchr(filename, '/');
288 if (strncmp(f, "bx113", 5) == 0) {
289 spmf->enc = adobe_map;
290 spmf->enc_size = adobe_map_size;
296 /* XXX slam back to ISO Latin1 */
297 spmf->first_char_id = spmf->enc[0];
298 /* size of extents array */
299 spmf->max_id = spmf->enc[(spmf->enc_size - 1) * 2];
300 spmf->num_chars = spmf->enc_size;
307 *master = (SpeedoMasterFontPtr) 0;
308 sp_close_master_font(spmf);
313 sp_close_master_font(spmf)
314 SpeedoMasterFontPtr spmf;
318 if (spmf->state & MasterFileOpen)
321 spmf->entry->u.scalable.extra->private = NULL;
323 xfree(spmf->f_buffer);
324 xfree(spmf->c_buffer);
329 sp_close_master_file(spmf)
330 SpeedoMasterFontPtr spmf;
332 (void) fclose(spmf->fp);
333 spmf->state &= ~MasterFileOpen;
338 * reset the encryption key, and make sure the file is opened
341 sp_reset_master(spmf)
342 SpeedoMasterFontPtr spmf;
344 sp_set_key(spmf->key);
345 if (!(spmf->state & MasterFileOpen)) {
346 spmf->fp = fopen(spmf->fname, "r");
347 /* XXX -- what to do if we can't open the file? */
348 spmf->state |= MasterFileOpen;
350 fseek(spmf->fp, 0, 0);