1 /* $XConsortium: fontfcn.c,v 1.10 94/02/06 16:07:23 gildea 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 */
39 extern xobject Type1Char();
40 /***================================================================***/
42 /***================================================================***/
43 char CurFontName[120];
47 psfont TheCurrentFont;
50 /***================================================================***/
51 /* SearchDict - look for name */
52 /* - compare for match on len and string */
53 /* return 0 - not found. */
54 /* return n - nth element in dictionary. */
55 /***================================================================***/
56 int SearchDictName(dictP,keyP)
64 for (i=1;i<=n;i++) { /* scan the intire dictionary */
66 (dictP[i].key.len == keyP->len )
68 (strncmp(dictP[i].key.data.valueP,
76 /***================================================================***/
81 if (!(vm_init(cnt))) return(FALSE);
82 vm_base = vm_next_byte();
83 if (!(Init_BuiltInEncoding())) return(FALSE);
84 strcpy(CurFontName, ""); /* iniitialize to none */
85 FontP = &TheCurrentFont;
86 FontP->vm_start = vm_next_byte();
87 FontP->FontFileName.len = 0;
88 FontP->FontFileName.data.valueP = CurFontName;
91 /***================================================================***/
92 static void resetFont(env)
96 vm_next = FontP->vm_start;
97 vm_free = vm_size - ( vm_next - vm_base);
99 FontP->Subrs.data.stringP = NULL;
100 FontP->CharStringsP = NULL;
101 FontP->Private = NULL;
102 FontP->fontInfoP = NULL;
103 FontP->BluesP = NULL;
104 /* This will load the font into the FontP */
105 strcpy(CurFontName,env);
106 FontP->FontFileName.len = strlen(CurFontName);
107 FontP->FontFileName.data.valueP = CurFontName;
110 /***================================================================***/
116 /* restore the virtual memory and eliminate old font */
118 /* This will load the font into the FontP */
119 rcode = scan_font(FontP);
120 if (rcode == SCAN_OUT_OF_MEMORY) {
121 /* free the memory and start again */
123 if (!(initFont(vm_size * 2))) {
124 /* we are really out of memory */
125 return(SCAN_OUT_OF_MEMORY);
128 rcode = scan_font(FontP);
129 /* only double the memory once, then report error */
133 /***================================================================***/
134 xobject fontfcnB(S,code,lenP,mode)
142 psobj *charnameP; /* points to psobj that is name of character*/
144 unsigned char *s; /* used to search the name for '|' */
145 psdict *CharStringsDictP; /* dictionary with char strings */
146 psobj CodeName; /* used to store the translation of the name*/
150 path charpath; /* the path for this character */
152 charnameP = &CodeName;
153 charnameP->len = *lenP;
154 charnameP->data.stringP = code;
156 CharStringsDictP = FontP->CharStringsP;
158 /* search the chars string for this charname as key */
159 N = SearchDictName(CharStringsDictP,charnameP);
161 *mode = FF_PARSE_ERROR;
164 /* ok, the nth item is the psobj that is the string for this char */
165 theStringP = &(CharStringsDictP[N].value);
167 /* get the dictionary pointers to the Subrs */
169 SubrsArrayP = &(FontP->Subrs);
170 /* scale the Adobe fonts to 1 unit high */
171 /* call the type 1 routine to rasterize the character */
172 charpath = Type1Char(FontP,S,theStringP,SubrsArrayP,NULL,
173 FontP->BluesP , mode);
174 /* if Type1Char reported an error, then return */
175 if ( *mode == FF_PARSE_ERROR) return(NULL);
176 /* fill with winding rule unless path was requested */
177 if (*mode != FF_PATH) {
178 charpath = Interior(charpath,WINDINGRULE+CONTINUITY);
182 /***================================================================***/
183 /* fontfcnA(env, mode) */
185 /* env is a pointer to a string that contains the fontname. */
187 /* 1) initialize the font - global indicates it has been done */
188 /* 2) load the font */
189 /***================================================================***/
190 Bool fontfcnA(env,mode)
196 /* Has the FontP initialized? If not, then */
200 if (!(initFont(VM_SIZE))) {
201 /* we are really out of memory */
202 *mode = SCAN_OUT_OF_MEMORY;
207 /* if the env is null, then use font already loaded */
209 /* if the not same font name */
210 if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
211 /* restore the virtual memory and eliminate old font, read new one */
214 strcpy(CurFontName, ""); /* no font loaded */
222 /***================================================================***/
223 /* QueryFontLib(env, infoName,infoValue,rcodeP) */
225 /* env is a pointer to a string that contains the fontname. */
227 /* 1) initialize the font - global indicates it has been done */
228 /* 2) load the font */
229 /* 3) use the font to call getInfo for that value. */
230 /***================================================================***/
232 void QueryFontLib(env,infoName,infoValue,rcodeP)
235 pointer infoValue; /* parameter returned here */
243 /* Has the FontP initialized? If not, then */
247 if (!(initFont(VM_SIZE))) {
252 /* if the env is null, then use font already loaded */
253 /* if the not same font name, reset and load next font */
254 if ( (env) && (strcmp(env,CurFontName) != 0 ) ) {
255 /* restore the virtual memory and eliminate old font */
258 strcpy(CurFontName, ""); /* no font loaded */
263 dictP = FontP->fontInfoP;
264 objFormatName(&nameObj,strlen(infoName),infoName);
265 N = SearchDictName(dictP,&nameObj);
269 switch (dictP[N].value.type) {
271 valueP = dictP[N].value.data.arrayP;
272 /* Just double check valueP. H.J. */
273 if (valueP == NULL) break;
274 if (strcmp(infoName,"FontMatrix") == 0) {
275 /* 6 elments, return them as floats */
277 if (valueP->type == OBJ_INTEGER )
278 ((float *)infoValue)[i] = valueP->data.integer;
280 ((float *)infoValue)[i] = valueP->data.real;
284 if (strcmp(infoName,"FontBBox") == 0) {
285 /* 4 elments for Bounding Box. all integers */
287 ((int *)infoValue)[i] = valueP->data.integer;
293 *((int *)infoValue) = dictP[N].value.data.integer;
296 *((float *)infoValue) = dictP[N].value.data.real;
300 *((char **)infoValue) = dictP[N].value.data.valueP;