30
30
/* Author: Katherine A. Hitchcock IBM Almaden Research Laboratory */
31
/* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
33
* The contents of this file are subject to the CID Font Code Public Licence
34
* Version 1.0 (the "License"). You may not use this file except in compliance
35
* with the Licence. You may obtain a copy of the License at Silicon Graphics,
36
* Inc., attn: Legal Services, 2011 N. Shoreline Blvd., Mountain View, CA
37
* 94043 or at http://www.sgi.com/software/opensource/cid/license.html.
39
* Software distributed under the License is distributed on an "AS IS" basis.
40
* ALL WARRANTIES ARE DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED
41
* WARRANTIES OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR PURPOSE OR OF
42
* NON-INFRINGEMENT. See the License for the specific language governing
43
* rights and limitations under the License.
45
* The Original Software is CID font code that was developed by Silicon
48
31
/* $XFree86: xc/lib/font/Type1/fontfcn.c,v 1.10 2001/04/05 17:42:27 dawes Exp $ */
50
33
#ifdef HAVE_CONFIG_H
51
34
#include <config.h>
77
53
struct blues_struct *bluesP, int *modeP );
80
extern struct xobject *CIDChar ( char *env, XYspace S,
81
psobj *charstrP, psobj *subrsP,
83
struct blues_struct *bluesP, int *modeP );
84
static boolean initCIDFont( int cnt );
87
56
/***================================================================***/
136
if (!(vm_init(cnt))) return(FALSE);
137
vm_base = vm_next_byte();
138
strcpy(CurCIDFontName, ""); /* initialize to none */
139
strcpy(CurCMapName, ""); /* initialize to none */
140
/* cause a font data reset on the next Type 1 font */
141
strcpy(CurFontName, ""); /* initialize to none */
142
CIDFontP = &TheCurrentCIDFont;
143
CMapP = &TheCurrentCMap;
144
CIDFontP->vm_start = vm_next_byte();
145
CIDFontP->spacerangecnt = 0;
146
CIDFontP->notdefrangecnt = 0;
147
CIDFontP->cidrangecnt = 0;
148
CIDFontP->spacerangeP = NULL;
149
CIDFontP->notdefrangeP = NULL;
150
CIDFontP->cidrangeP = NULL;
151
CIDFontP->CIDFontFileName.len = 0;
152
CIDFontP->CIDFontFileName.data.valueP = CurCIDFontName;
153
CMapP->CMapFileName.len = 0;
154
CMapP->CMapFileName.data.valueP = CurCMapName;
155
CMapP->firstRow = 0xFFFF;
156
CMapP->firstCol = 0xFFFF;
162
/***================================================================***/
164
initCIDType1Font(void)
166
strcpy(CurFontName, ""); /* initialize to none */
167
FontP = &FDArrayP[FDArrayIndex];
168
FontP->vm_start = vm_next_byte();
169
FontP->FontFileName.len = 0;
170
FontP->FontFileName.data.valueP = CurFontName;
171
FontP->Subrs.len = 0;
172
FontP->Subrs.data.stringP = NULL;
173
FontP->CharStringsP = NULL;
174
FontP->Private = NULL;
175
FontP->fontInfoP = NULL;
176
FontP->BluesP = NULL;
186
96
vm_base = vm_next_byte();
187
97
if (!(Init_BuiltInEncoding())) return(FALSE);
188
98
strcpy(CurFontName, ""); /* iniitialize to none */
190
/* cause a font data reset on the next CID-keyed font */
191
strcpy(CurCIDFontName, ""); /* initialize to none */
193
99
FontP = &TheCurrentFont;
194
100
FontP->vm_start = vm_next_byte();
195
101
FontP->FontFileName.len = 0;
199
105
/***================================================================***/
202
resetCIDFont(char *cidfontname, char *cmapfile)
205
vm_next = CIDFontP->vm_start;
206
vm_free = vm_size - ( vm_next - vm_base);
207
CIDFontP->spacerangecnt = 0;
208
CIDFontP->notdefrangecnt = 0;
209
CIDFontP->cidrangecnt = 0;
210
CIDFontP->spacerangeP = NULL;
211
CIDFontP->notdefrangeP = NULL;
212
CIDFontP->cidrangeP = NULL;
213
CIDFontP->CIDfontInfoP = NULL;
214
/* This will load the font into the FontP */
215
strcpy(CurCIDFontName,cidfontname);
216
strcpy(CurCMapName,cmapfile);
217
CIDFontP->CIDFontFileName.len = strlen(CurCIDFontName);
218
CIDFontP->CIDFontFileName.data.valueP = CurCIDFontName;
219
CMapP->CMapFileName.len = strlen(CurCMapName);
220
CMapP->CMapFileName.data.valueP = CurCMapName;
221
CMapP->firstRow = 0xFFFF;
222
CMapP->firstCol = 0xFFFF;
228
resetCIDType1Font(void)
231
vm_next = FontP->vm_start;
232
vm_free = vm_size - ( vm_next - vm_base);
233
FontP->Subrs.len = 0;
234
FontP->Subrs.data.stringP = NULL;
235
FontP->CharStringsP = NULL;
236
FontP->Private = NULL;
237
FontP->fontInfoP = NULL;
238
FontP->BluesP = NULL;
239
/* This will load the font into the FontP */
240
FontP->FontFileName.len = strlen(CurFontName);
241
FontP->FontFileName.data.valueP = CurFontName;
246
107
resetFont(char *env)
265
/***================================================================***/
267
readCIDFont(char *cidfontname, char *cmapfile)
271
/* restore the virtual memory and eliminate old font */
272
resetCIDFont(cidfontname, cmapfile);
273
/* This will load the font into the FontP */
274
rcode = scan_cidfont(CIDFontP, CMapP);
275
if (rcode == SCAN_OUT_OF_MEMORY) {
276
/* free the memory and start again */
277
if (!(initCIDFont(vm_size * 2))) {
278
/* we are really out of memory */
279
return(SCAN_OUT_OF_MEMORY);
281
resetCIDFont(cidfontname, cmapfile);
282
rcode = scan_cidfont(CIDFontP, CMapP);
283
/* only double the memory twice, then report error */
284
if (rcode == SCAN_OUT_OF_MEMORY) {
285
/* free the memory and start again */
286
if (!(initCIDFont(vm_size * 2))) {
287
/* we are really out of memory */
288
return(SCAN_OUT_OF_MEMORY);
290
resetCIDFont(cidfontname, cmapfile);
291
rcode = scan_cidfont(CIDFontP, CMapP);
298
readCIDType1Font(void)
304
/* This will load the font into the FontP */
305
rcode = scan_cidtype1font(FontP);
311
126
readFont(char *env)
317
132
/* This will load the font into the FontP */
318
133
rcode = scan_font(FontP);
319
134
if (rcode == SCAN_OUT_OF_MEMORY) {
320
/* free the memory and start again */
322
/* xfree(vm_base); */
326
135
if (!(initFont(vm_size * 2))) {
327
136
/* we are really out of memory */
328
137
return(SCAN_OUT_OF_MEMORY);
331
140
rcode = scan_font(FontP);
333
/* only double the memory twice, then report error */
334
if (rcode == SCAN_OUT_OF_MEMORY) {
335
/* free the memory and start again */
337
if (!(initFont(vm_size * 2))) {
338
/* we are really out of memory */
339
return(SCAN_OUT_OF_MEMORY);
342
rcode = scan_font(FontP);
345
141
/* only double the memory once, then report error */
393
188
return(charpath);
397
/***================================================================***/
398
/* CIDfontfcnA(cidfontname, cmapfile, mode) */
400
/* 1) initialize the font - global indicates it has been done */
401
/* 2) load the font */
402
/***================================================================***/
404
CIDfontfcnA(char *cidfontname, char *cmapfile, int *mode)
409
if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
411
if (!(initCIDFont(VM_SIZE))) {
412
/* we are really out of memory */
413
*mode = SCAN_OUT_OF_MEMORY;
419
/* if the cidfontname is null, then use font already loaded */
421
/* if not the same font name */
422
if (cidinit || (cidfontname && strcmp(cidfontname,CurCIDFontName) != 0) ||
423
(cmapfile && strcmp(cmapfile,CurCMapName) != 0)) {
424
/* restore the virtual memory and eliminate old font, read new one */
425
rcode = readCIDFont(cidfontname, cmapfile);
427
strcpy(CurCIDFontName, ""); /* no CIDFont loaded */
428
strcpy(CurCMapName, ""); /* no CMap loaded */
437
/***================================================================***/
438
/* CIDType1fontfcnA(mode) */
440
/* 1) initialize the font - global indicates it has been done */
441
/* 2) load the font */
442
/***================================================================***/
444
CIDType1fontfcnA(int *mode)
448
if (!(initCIDType1Font())) {
449
/* we are really out of memory */
450
*mode = SCAN_OUT_OF_MEMORY;
454
if ((rcode = readCIDType1Font()) != 0) {
455
strcpy(CurFontName, ""); /* no font loaded */
464
192
/***================================================================***/
465
193
/* fontfcnA(env, mode) */
509
/***================================================================***/
510
/* CIDQueryFontLib(cidfontname,cmapfile,infoName,infoValue,rcodeP) */
512
/* cidfontname is a pointer to a string that contains the fontname. */
514
/* 1) initialize the font - global indicates it has been done */
515
/* 2) load the font */
516
/* 3) use the font to call getInfo for that value. */
517
/***================================================================***/
520
CIDQueryFontLib(char *cidfontname, char *cmapfile, char *infoName,
521
pointer infoValue, /* parameter returned here */
529
/* Has the CIDFontP initialized? If not, then */
532
if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
534
if (!(initCIDFont(VM_SIZE))) {
540
/* if the file name is null, then use font already loaded */
541
/* if the not same font name, reset and load next font */
542
if (cidinit || (cidfontname && strcmp(cidfontname,CurCIDFontName) != 0) ||
543
(cmapfile && strcmp(cmapfile,CurCMapName) != 0)) {
544
/* restore the virtual memory and eliminate old font */
545
rc = readCIDFont(cidfontname, cmapfile);
547
strcpy(CurCIDFontName, ""); /* no font loaded */
548
strcpy(CurCMapName, ""); /* no font loaded */
553
dictP = CIDFontP->CIDfontInfoP;
554
objFormatName(&nameObj,strlen(infoName),infoName);
555
N = SearchDictName(dictP,&nameObj);
559
switch (dictP[N].value.type) {
561
valueP = dictP[N].value.data.arrayP;
562
/* Just double check valueP. H.J. */
563
if (valueP == NULL) break;
564
if (strcmp(infoName,"FontMatrix") == 0) {
565
/* 6 elments, return them as floats */
567
if (valueP->type == OBJ_INTEGER )
568
((float *)infoValue)[i] = valueP->data.integer;
570
((float *)infoValue)[i] = valueP->data.real;
574
if (strcmp(infoName,"FontBBox") == 0) {
575
/* 4 elments for Bounding Box. all integers */
577
((int *)infoValue)[i] = valueP->data.integer;
583
*((int *)infoValue) = dictP[N].value.data.integer;
586
*((float *)infoValue) = dictP[N].value.data.real;
590
*((char **)infoValue) = dictP[N].value.data.valueP;
602
232
/***================================================================***/
603
233
/* QueryFontLib(env, infoName,infoValue,rcodeP) */
687
317
else *rcodeP = 1;
692
CIDfontfcnC(struct XYspace *S, psobj *theStringP,
693
psobj *SubrsArrayP, struct blues_struct *BluesP,
694
int *lenP, int *mode)
696
struct xobject *charpath; /* the path for this character */
698
charpath = (struct xobject *)CIDChar((char *)FontP,S,theStringP,
699
SubrsArrayP,NULL,BluesP,mode);
700
/* if Type1Char reported an error, then return */
701
if ( *mode == FF_PARSE_ERROR) return(NULL);
702
/* fill with winding rule unless path was requested */
703
if (*mode != FF_PATH) {
704
charpath = (struct xobject *)Interior((struct segment *)charpath,
705
WINDINGRULE+CONTINUITY);