1
/* $Xorg: fontfcn.c,v 1.4 2000/08/17 19:46:30 cpqbld Exp $ */
2
/* Copyright International Business Machines,Corp. 1991
5
* License to use, copy, modify, and distribute this software
6
* and its documentation for any purpose and without fee is
7
* hereby granted, provided that the above copyright notice
8
* appear in all copies and that both that copyright notice and
9
* this permission notice appear in supporting documentation,
10
* and that the name of IBM not be used in advertising or
11
* publicity pertaining to distribution of the software without
12
* specific, written prior permission.
14
* IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
15
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
16
* LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
18
* THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
19
* PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
20
* OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
21
* THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
22
* THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
23
* NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
24
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
25
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
26
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
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
/* $XFree86: xc/lib/font/Type1/fontfcn.c,v 1.11 2001/11/23 19:21:31 dawes Exp $ */
54
#include "Xmd.h" /* For INT32 declaration */
55
#include "Xdefs.h" /* For Bool */
56
#include "xf86_ansic.h"
67
extern struct segment *Type1Char ( char *env, XYspace S,
68
psobj *charstrP, psobj *subrsP,
70
struct blues_struct *bluesP, int *modeP );
73
extern struct xobject *CIDChar ( char *env, XYspace S,
74
psobj *charstrP, psobj *subrsP,
76
struct blues_struct *bluesP, int *modeP );
77
static boolean initCIDFont( int cnt );
80
/***================================================================***/
82
/***================================================================***/
83
char CurFontName[120];
87
psfont TheCurrentFont;
89
char CurCIDFontName[CID_PATH_MAX];
90
char CurCMapName[CID_PATH_MAX];
91
cidfont *CIDFontP = NULL;
92
cmapres *CMapP = NULL;
93
cidfont TheCurrentCIDFont;
94
cmapres TheCurrentCMap;
95
psfont *FDArrayP = NULL;
99
/***================================================================***/
100
/* SearchDict - look for name */
101
/* - compare for match on len and string */
102
/* return 0 - not found. */
103
/* return n - nth element in dictionary. */
104
/***================================================================***/
106
SearchDictName(psdict *dictP, psobj *keyP)
111
n = dictP[0].key.len;
112
for (i=1;i<=n;i++) { /* scan the intire dictionary */
114
(dictP[i].key.len == keyP->len )
116
(strncmp(dictP[i].key.data.valueP,
129
if (!(vm_init(cnt))) return(FALSE);
130
vm_base = vm_next_byte();
131
strcpy(CurCIDFontName, ""); /* initialize to none */
132
strcpy(CurCMapName, ""); /* initialize to none */
133
/* cause a font data reset on the next Type 1 font */
134
strcpy(CurFontName, ""); /* initialize to none */
135
CIDFontP = &TheCurrentCIDFont;
136
CMapP = &TheCurrentCMap;
137
CIDFontP->vm_start = vm_next_byte();
138
CIDFontP->spacerangecnt = 0;
139
CIDFontP->notdefrangecnt = 0;
140
CIDFontP->cidrangecnt = 0;
141
CIDFontP->spacerangeP = NULL;
142
CIDFontP->notdefrangeP = NULL;
143
CIDFontP->cidrangeP = NULL;
144
CIDFontP->CIDFontFileName.len = 0;
145
CIDFontP->CIDFontFileName.data.valueP = CurCIDFontName;
146
CMapP->CMapFileName.len = 0;
147
CMapP->CMapFileName.data.valueP = CurCMapName;
148
CMapP->firstRow = 0xFFFF;
149
CMapP->firstCol = 0xFFFF;
155
/***================================================================***/
157
initCIDType1Font(void)
159
strcpy(CurFontName, ""); /* initialize to none */
160
FontP = &FDArrayP[FDArrayIndex];
161
FontP->vm_start = vm_next_byte();
162
FontP->FontFileName.len = 0;
163
FontP->FontFileName.data.valueP = CurFontName;
164
FontP->Subrs.len = 0;
165
FontP->Subrs.data.stringP = NULL;
166
FontP->CharStringsP = NULL;
167
FontP->Private = NULL;
168
FontP->fontInfoP = NULL;
169
FontP->BluesP = NULL;
178
if (!(vm_init(cnt))) return(FALSE);
179
vm_base = vm_next_byte();
180
if (!(Init_BuiltInEncoding())) return(FALSE);
181
strcpy(CurFontName, ""); /* iniitialize to none */
183
/* cause a font data reset on the next CID-keyed font */
184
strcpy(CurCIDFontName, ""); /* initialize to none */
186
FontP = &TheCurrentFont;
187
FontP->vm_start = vm_next_byte();
188
FontP->FontFileName.len = 0;
189
FontP->FontFileName.data.valueP = CurFontName;
192
/***================================================================***/
195
resetCIDFont(char *cidfontname, char *cmapfile)
198
vm_next = CIDFontP->vm_start;
199
vm_free = vm_size - ( vm_next - vm_base);
200
CIDFontP->spacerangecnt = 0;
201
CIDFontP->notdefrangecnt = 0;
202
CIDFontP->cidrangecnt = 0;
203
CIDFontP->spacerangeP = NULL;
204
CIDFontP->notdefrangeP = NULL;
205
CIDFontP->cidrangeP = NULL;
206
CIDFontP->CIDfontInfoP = NULL;
207
/* This will load the font into the FontP */
208
strcpy(CurCIDFontName,cidfontname);
209
strcpy(CurCMapName,cmapfile);
210
CIDFontP->CIDFontFileName.len = strlen(CurCIDFontName);
211
CIDFontP->CIDFontFileName.data.valueP = CurCIDFontName;
212
CMapP->CMapFileName.len = strlen(CurCMapName);
213
CMapP->CMapFileName.data.valueP = CurCMapName;
214
CMapP->firstRow = 0xFFFF;
215
CMapP->firstCol = 0xFFFF;
221
resetCIDType1Font(void)
224
vm_next = FontP->vm_start;
225
vm_free = vm_size - ( vm_next - vm_base);
226
FontP->Subrs.len = 0;
227
FontP->Subrs.data.stringP = NULL;
228
FontP->CharStringsP = NULL;
229
FontP->Private = NULL;
230
FontP->fontInfoP = NULL;
231
FontP->BluesP = NULL;
232
/* This will load the font into the FontP */
233
FontP->FontFileName.len = strlen(CurFontName);
234
FontP->FontFileName.data.valueP = CurFontName;
242
vm_next = FontP->vm_start;
243
vm_free = vm_size - ( vm_next - vm_base);
244
FontP->Subrs.len = 0;
245
FontP->Subrs.data.stringP = NULL;
246
FontP->CharStringsP = NULL;
247
FontP->Private = NULL;
248
FontP->fontInfoP = NULL;
249
FontP->BluesP = NULL;
250
/* This will load the font into the FontP */
251
strcpy(CurFontName,env);
252
FontP->FontFileName.len = strlen(CurFontName);
253
FontP->FontFileName.data.valueP = CurFontName;
258
/***================================================================***/
260
readCIDFont(char *cidfontname, char *cmapfile)
264
/* restore the virtual memory and eliminate old font */
265
resetCIDFont(cidfontname, cmapfile);
266
/* This will load the font into the FontP */
267
rcode = scan_cidfont(CIDFontP, CMapP);
268
if (rcode == SCAN_OUT_OF_MEMORY) {
269
/* free the memory and start again */
270
if (!(initCIDFont(vm_size * 2))) {
271
/* we are really out of memory */
272
return(SCAN_OUT_OF_MEMORY);
274
resetCIDFont(cidfontname, cmapfile);
275
rcode = scan_cidfont(CIDFontP, CMapP);
276
/* only double the memory twice, then report error */
277
if (rcode == SCAN_OUT_OF_MEMORY) {
278
/* free the memory and start again */
279
if (!(initCIDFont(vm_size * 2))) {
280
/* we are really out of memory */
281
return(SCAN_OUT_OF_MEMORY);
283
resetCIDFont(cidfontname, cmapfile);
284
rcode = scan_cidfont(CIDFontP, CMapP);
291
readCIDType1Font(void)
297
/* This will load the font into the FontP */
298
rcode = scan_cidtype1font(FontP);
308
/* restore the virtual memory and eliminate old font */
310
/* This will load the font into the FontP */
311
rcode = scan_font(FontP);
312
if (rcode == SCAN_OUT_OF_MEMORY) {
313
/* free the memory and start again */
315
/* xfree(vm_base); */
319
if (!(initFont(vm_size * 2))) {
320
/* we are really out of memory */
321
return(SCAN_OUT_OF_MEMORY);
324
rcode = scan_font(FontP);
326
/* only double the memory twice, then report error */
327
if (rcode == SCAN_OUT_OF_MEMORY) {
328
/* free the memory and start again */
330
if (!(initFont(vm_size * 2))) {
331
/* we are really out of memory */
332
return(SCAN_OUT_OF_MEMORY);
335
rcode = scan_font(FontP);
338
/* only double the memory once, then report error */
343
/***================================================================***/
345
fontfcnB(struct XYspace *S, unsigned char *code, int *lenP, int *mode)
347
psobj *charnameP; /* points to psobj that is name of character*/
349
psdict *CharStringsDictP; /* dictionary with char strings */
350
psobj CodeName; /* used to store the translation of the name*/
354
struct xobject *charpath; /* the path for this character */
356
charnameP = &CodeName;
357
charnameP->len = *lenP;
358
charnameP->data.stringP = code;
360
CharStringsDictP = FontP->CharStringsP;
362
/* search the chars string for this charname as key */
363
N = SearchDictName(CharStringsDictP,charnameP);
365
*mode = FF_PARSE_ERROR;
368
/* ok, the nth item is the psobj that is the string for this char */
369
theStringP = &(CharStringsDictP[N].value);
371
/* get the dictionary pointers to the Subrs */
373
SubrsArrayP = &(FontP->Subrs);
374
/* scale the Adobe fonts to 1 unit high */
375
/* call the type 1 routine to rasterize the character */
376
charpath = (struct xobject *)Type1Char((char *)FontP,S,theStringP,
378
FontP->BluesP , mode);
379
/* if Type1Char reported an error, then return */
380
if ( *mode == FF_PARSE_ERROR) return(NULL);
381
/* fill with winding rule unless path was requested */
382
if (*mode != FF_PATH) {
383
charpath = (struct xobject *)Interior((struct segment *)charpath,
384
WINDINGRULE+CONTINUITY);
390
/***================================================================***/
391
/* CIDfontfcnA(cidfontname, cmapfile, mode) */
393
/* 1) initialize the font - global indicates it has been done */
394
/* 2) load the font */
395
/***================================================================***/
397
CIDfontfcnA(char *cidfontname, char *cmapfile, int *mode)
402
if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
404
if (!(initCIDFont(VM_SIZE))) {
405
/* we are really out of memory */
406
*mode = SCAN_OUT_OF_MEMORY;
412
/* if the cidfontname is null, then use font already loaded */
414
/* if not the same font name */
415
if (cidinit || (cidfontname && strcmp(cidfontname,CurCIDFontName) != 0) ||
416
(cmapfile && strcmp(cmapfile,CurCMapName) != 0)) {
417
/* restore the virtual memory and eliminate old font, read new one */
418
rcode = readCIDFont(cidfontname, cmapfile);
420
strcpy(CurCIDFontName, ""); /* no CIDFont loaded */
421
strcpy(CurCMapName, ""); /* no CMap loaded */
430
/***================================================================***/
431
/* CIDType1fontfcnA(mode) */
433
/* 1) initialize the font - global indicates it has been done */
434
/* 2) load the font */
435
/***================================================================***/
437
CIDType1fontfcnA(int *mode)
441
if (!(initCIDType1Font())) {
442
/* we are really out of memory */
443
*mode = SCAN_OUT_OF_MEMORY;
447
if ((rcode = readCIDType1Font()) != 0) {
448
strcpy(CurFontName, ""); /* no font loaded */
457
/***================================================================***/
458
/* fontfcnA(env, mode) */
460
/* env is a pointer to a string that contains the fontname. */
462
/* 1) initialize the font - global indicates it has been done */
463
/* 2) load the font */
464
/***================================================================***/
466
fontfcnA(char *env, int *mode)
470
/* Has the FontP initialized? If not, then */
473
if (FontP == NULL || strcmp(CurFontName, "") == 0) {
478
if (!(initFont(VM_SIZE))) {
479
/* we are really out of memory */
480
*mode = SCAN_OUT_OF_MEMORY;
485
/* if the env is null, then use font already loaded */
487
/* if the not same font name */
488
if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
489
/* restore the virtual memory and eliminate old font, read new one */
492
strcpy(CurFontName, ""); /* no font loaded */
502
/***================================================================***/
503
/* CIDQueryFontLib(cidfontname,cmapfile,infoName,infoValue,rcodeP) */
505
/* cidfontname is a pointer to a string that contains the fontname. */
507
/* 1) initialize the font - global indicates it has been done */
508
/* 2) load the font */
509
/* 3) use the font to call getInfo for that value. */
510
/***================================================================***/
513
CIDQueryFontLib(char *cidfontname, char *cmapfile, char *infoName,
514
pointer infoValue, /* parameter returned here */
522
/* Has the CIDFontP initialized? If not, then */
525
if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
527
if (!(initCIDFont(VM_SIZE))) {
533
/* if the file name is null, then use font already loaded */
534
/* if the not same font name, reset and load next font */
535
if (cidinit || (cidfontname && strcmp(cidfontname,CurCIDFontName) != 0) ||
536
(cmapfile && strcmp(cmapfile,CurCMapName) != 0)) {
537
/* restore the virtual memory and eliminate old font */
538
rc = readCIDFont(cidfontname, cmapfile);
540
strcpy(CurCIDFontName, ""); /* no font loaded */
541
strcpy(CurCMapName, ""); /* no font loaded */
546
dictP = CIDFontP->CIDfontInfoP;
547
objFormatName(&nameObj,strlen(infoName),infoName);
548
N = SearchDictName(dictP,&nameObj);
552
switch (dictP[N].value.type) {
554
valueP = dictP[N].value.data.arrayP;
555
/* Just double check valueP. H.J. */
556
if (valueP == NULL) break;
557
if (strcmp(infoName,"FontMatrix") == 0) {
558
/* 6 elments, return them as floats */
560
if (valueP->type == OBJ_INTEGER )
561
((float *)infoValue)[i] = valueP->data.integer;
563
((float *)infoValue)[i] = valueP->data.real;
567
if (strcmp(infoName,"FontBBox") == 0) {
568
/* 4 elments for Bounding Box. all integers */
570
((int *)infoValue)[i] = valueP->data.integer;
576
*((int *)infoValue) = dictP[N].value.data.integer;
579
*((float *)infoValue) = dictP[N].value.data.real;
583
*((char **)infoValue) = dictP[N].value.data.valueP;
595
/***================================================================***/
596
/* QueryFontLib(env, infoName,infoValue,rcodeP) */
598
/* env is a pointer to a string that contains the fontname. */
600
/* 1) initialize the font - global indicates it has been done */
601
/* 2) load the font */
602
/* 3) use the font to call getInfo for that value. */
603
/***================================================================***/
606
QueryFontLib(char *env, char *infoName,
607
pointer infoValue, /* parameter returned here */
615
/* Has the FontP initialized? If not, then */
619
if (!(initFont(VM_SIZE))) {
624
/* if the env is null, then use font already loaded */
625
/* if the not same font name, reset and load next font */
626
if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
627
/* restore the virtual memory and eliminate old font */
630
strcpy(CurFontName, ""); /* no font loaded */
635
dictP = FontP->fontInfoP;
636
objFormatName(&nameObj,strlen(infoName),infoName);
637
N = SearchDictName(dictP,&nameObj);
641
switch (dictP[N].value.type) {
643
valueP = dictP[N].value.data.arrayP;
644
/* Just double check valueP. H.J. */
645
if (valueP == NULL) break;
646
if (strcmp(infoName,"FontMatrix") == 0) {
647
/* 6 elments, return them as floats */
649
if (valueP->type == OBJ_INTEGER )
650
((float *)infoValue)[i] = valueP->data.integer;
652
((float *)infoValue)[i] = valueP->data.real;
656
if (strcmp(infoName,"FontBBox") == 0) {
657
/* 4 elments for Bounding Box. all integers */
659
((int *)infoValue)[i] = valueP->data.integer;
665
*((int *)infoValue) = dictP[N].value.data.integer;
668
*((float *)infoValue) = dictP[N].value.data.real;
672
*((char **)infoValue) = dictP[N].value.data.valueP;
685
CIDfontfcnC(struct XYspace *S, psobj *theStringP,
686
psobj *SubrsArrayP, struct blues_struct *BluesP,
687
int *lenP, int *mode)
689
struct xobject *charpath; /* the path for this character */
691
charpath = (struct xobject *)CIDChar((char *)FontP,S,theStringP,
692
SubrsArrayP,NULL,BluesP,mode);
693
/* if Type1Char reported an error, then return */
694
if ( *mode == FF_PARSE_ERROR) return(NULL);
695
/* fill with winding rule unless path was requested */
696
if (*mode != FF_PATH) {
697
charpath = (struct xobject *)Interior((struct segment *)charpath,
698
WINDINGRULE+CONTINUITY);