~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/font/Type1/fontfcn.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: fontfcn.c,v 1.4 2000/08/17 19:46:30 cpqbld Exp $ */
 
2
/* Copyright International Business Machines,Corp. 1991
 
3
 * All Rights Reserved
 
4
 *
 
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.
 
13
 *
 
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
 
28
 * SOFTWARE.
 
29
 */
 
30
/* Author: Katherine A. Hitchcock    IBM Almaden Research Laboratory */
 
31
/* Copyright (c) 1994-1999 Silicon Graphics, Inc. All Rights Reserved.
 
32
 *
 
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.
 
38
 *
 
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.
 
44
 *
 
45
 * The Original Software is CID font code that was developed by Silicon
 
46
 * Graphics, Inc.
 
47
 */
 
48
/* $XFree86: xc/lib/font/Type1/fontfcn.c,v 1.11 2001/11/23 19:21:31 dawes Exp $ */
 
49
 
 
50
#ifndef FONTMODULE
 
51
#include <stdio.h>
 
52
#include <string.h>
 
53
#else
 
54
#include "Xmd.h"        /* For INT32 declaration */
 
55
#include "Xdefs.h"      /* For Bool */
 
56
#include "xf86_ansic.h"
 
57
#endif
 
58
#include "t1imager.h"
 
59
#include "util.h"
 
60
#ifdef BUILDCID
 
61
#include "range.h"
 
62
#include "Xdefs.h"
 
63
#endif
 
64
#include "fntfilst.h"
 
65
#include "fontfcn.h"
 
66
 
 
67
extern struct segment *Type1Char ( char *env, XYspace S, 
 
68
                                   psobj *charstrP, psobj *subrsP, 
 
69
                                   psobj *osubrsP, 
 
70
                                   struct blues_struct *bluesP, int *modeP );
 
71
 
 
72
#ifdef BUILDCID
 
73
extern struct xobject *CIDChar ( char *env, XYspace S, 
 
74
                                 psobj *charstrP, psobj *subrsP, 
 
75
                                 psobj *osubrsP, 
 
76
                                 struct blues_struct *bluesP, int *modeP );
 
77
static boolean initCIDFont( int cnt );
 
78
#endif
 
79
 
 
80
/***================================================================***/
 
81
/*   GLOBALS                                                          */
 
82
/***================================================================***/
 
83
char CurFontName[120];
 
84
char *CurFontEnv;
 
85
char *vm_base = NULL;
 
86
psfont *FontP = NULL;
 
87
psfont TheCurrentFont;
 
88
#ifdef BUILDCID
 
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;
 
96
int FDArrayIndex = 0;
 
97
#endif
 
98
 
 
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
/***================================================================***/
 
105
int 
 
106
SearchDictName(psdict *dictP, psobj *keyP)
 
107
{
 
108
  int i,n;
 
109
 
 
110
 
 
111
  n =  dictP[0].key.len;
 
112
  for (i=1;i<=n;i++) {          /* scan the intire dictionary */
 
113
    if (
 
114
        (dictP[i].key.len  == keyP->len )
 
115
        &&
 
116
        (strncmp(dictP[i].key.data.valueP,
 
117
                 keyP->data.valueP,
 
118
                 keyP->len) == 0
 
119
        )
 
120
       ) return(i);
 
121
  }
 
122
  return(0);
 
123
}
 
124
 
 
125
#ifdef BUILDCID
 
126
static boolean 
 
127
initCIDFont(int cnt)
 
128
{
 
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;
 
150
  CMapP->lastRow = 0;
 
151
  CMapP->lastCol = 0;
 
152
  return(TRUE);
 
153
}
 
154
 
 
155
/***================================================================***/
 
156
boolean 
 
157
initCIDType1Font(void)
 
158
{
 
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;
 
170
  return(TRUE);
 
171
}
 
172
#endif
 
173
 
 
174
boolean 
 
175
initFont(int cnt)
 
176
{
 
177
 
 
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 */
 
182
#ifdef BUILDCID
 
183
  /* cause a font data reset on the next CID-keyed font */
 
184
  strcpy(CurCIDFontName, "");    /* initialize to none */
 
185
#endif
 
186
  FontP = &TheCurrentFont;
 
187
  FontP->vm_start = vm_next_byte();
 
188
  FontP->FontFileName.len = 0;
 
189
  FontP->FontFileName.data.valueP = CurFontName;
 
190
  return(TRUE);
 
191
}
 
192
/***================================================================***/
 
193
#ifdef BUILDCID
 
194
static void 
 
195
resetCIDFont(char *cidfontname, char *cmapfile)
 
196
{
 
197
 
 
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;
 
216
  CMapP->lastRow = 0;
 
217
  CMapP->lastCol = 0;
 
218
}
 
219
 
 
220
static void 
 
221
resetCIDType1Font(void)
 
222
{
 
223
 
 
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;
 
235
}
 
236
#endif
 
237
 
 
238
static void 
 
239
resetFont(char *env)
 
240
{
 
241
 
 
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;
 
254
 
 
255
}
 
256
 
 
257
#ifdef BUILDCID
 
258
/***================================================================***/
 
259
int 
 
260
readCIDFont(char *cidfontname, char *cmapfile)
 
261
{
 
262
  int rcode;
 
263
 
 
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);
 
273
    }
 
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);
 
282
      }
 
283
      resetCIDFont(cidfontname, cmapfile);
 
284
      rcode = scan_cidfont(CIDFontP, CMapP);
 
285
    }
 
286
  }
 
287
  return(rcode);
 
288
}
 
289
 
 
290
int 
 
291
readCIDType1Font(void)
 
292
{
 
293
  int rcode;
 
294
 
 
295
  resetCIDType1Font();
 
296
 
 
297
  /* This will load the font into the FontP */
 
298
  rcode = scan_cidtype1font(FontP);
 
299
  return(rcode);
 
300
}
 
301
#endif
 
302
 
 
303
int 
 
304
readFont(char *env)
 
305
{
 
306
  int rcode;
 
307
 
 
308
  /* restore the virtual memory and eliminate old font */
 
309
  resetFont(env);
 
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 */
 
314
#ifdef BUILDCID
 
315
    /* xfree(vm_base); */
 
316
#else
 
317
    xfree(vm_base);
 
318
#endif
 
319
    if (!(initFont(vm_size * 2))) {
 
320
      /* we are really out of memory */
 
321
      return(SCAN_OUT_OF_MEMORY);
 
322
      }
 
323
    resetFont(env);
 
324
    rcode = scan_font(FontP);
 
325
#ifdef BUILDCID
 
326
    /* only double the memory twice, then report error */
 
327
    if (rcode == SCAN_OUT_OF_MEMORY) {
 
328
      /* free the memory and start again */
 
329
      /* xfree(vm_base) */
 
330
      if (!(initFont(vm_size * 2))) {
 
331
        /* we are really out of memory */
 
332
        return(SCAN_OUT_OF_MEMORY);
 
333
      }
 
334
      resetFont(env);
 
335
      rcode = scan_font(FontP);
 
336
    }
 
337
#else
 
338
    /* only double the memory once, then report error */
 
339
#endif
 
340
  }
 
341
  return(rcode);
 
342
}
 
343
/***================================================================***/
 
344
struct xobject *
 
345
fontfcnB(struct XYspace *S, unsigned char *code, int *lenP, int *mode)
 
346
{
 
347
  psobj *charnameP; /* points to psobj that is name of character*/
 
348
  int   N;
 
349
  psdict *CharStringsDictP; /* dictionary with char strings     */
 
350
  psobj   CodeName;   /* used to store the translation of the name*/
 
351
  psobj  *SubrsArrayP;
 
352
  psobj  *theStringP;
 
353
 
 
354
  struct xobject *charpath;   /* the path for this character              */
 
355
 
 
356
  charnameP = &CodeName;
 
357
  charnameP->len = *lenP;
 
358
  charnameP->data.stringP = code;
 
359
 
 
360
  CharStringsDictP =  FontP->CharStringsP;
 
361
 
 
362
  /* search the chars string for this charname as key */
 
363
  N = SearchDictName(CharStringsDictP,charnameP);
 
364
  if (N<=0) {
 
365
    *mode = FF_PARSE_ERROR;
 
366
    return(NULL);
 
367
  }
 
368
  /* ok, the nth item is the psobj that is the string for this char */
 
369
  theStringP = &(CharStringsDictP[N].value);
 
370
 
 
371
  /* get the dictionary pointers to the Subrs  */
 
372
 
 
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,
 
377
                                         SubrsArrayP,NULL,
 
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);
 
385
  }
 
386
  return(charpath);
 
387
}
 
388
 
 
389
#ifdef BUILDCID
 
390
/***================================================================***/
 
391
/*   CIDfontfcnA(cidfontname, cmapfile, mode)                         */
 
392
/*                                                                    */
 
393
/*     1) initialize the font     - global indicates it has been done */
 
394
/*     2) load the font                                               */
 
395
/***================================================================***/
 
396
Bool 
 
397
CIDfontfcnA(char *cidfontname, char *cmapfile, int *mode)
 
398
{
 
399
  int rcode, cidinit;
 
400
 
 
401
  cidinit = 0;
 
402
  if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
 
403
    InitImager();
 
404
    if (!(initCIDFont(VM_SIZE))) {
 
405
      /* we are really out of memory */
 
406
      *mode = SCAN_OUT_OF_MEMORY;
 
407
      return(FALSE);
 
408
    }
 
409
    cidinit = 1;
 
410
  }
 
411
 
 
412
  /* if the cidfontname is null, then use font already loaded */
 
413
 
 
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);
 
419
    if (rcode != 0 ) {
 
420
      strcpy(CurCIDFontName, "");    /* no CIDFont loaded */
 
421
      strcpy(CurCMapName, "");    /* no CMap loaded */
 
422
      *mode = rcode;
 
423
      return(FALSE);
 
424
    }
 
425
  }
 
426
  return(TRUE);
 
427
 
 
428
}
 
429
 
 
430
/***================================================================***/
 
431
/*   CIDType1fontfcnA(mode)                                           */
 
432
/*                                                                    */
 
433
/*     1) initialize the font     - global indicates it has been done */
 
434
/*     2) load the font                                               */
 
435
/***================================================================***/
 
436
Bool 
 
437
CIDType1fontfcnA(int *mode)
 
438
{
 
439
  int rcode;
 
440
 
 
441
  if (!(initCIDType1Font())) {
 
442
    /* we are really out of memory */
 
443
    *mode = SCAN_OUT_OF_MEMORY;
 
444
    return(FALSE);
 
445
  }
 
446
 
 
447
  if ((rcode = readCIDType1Font()) != 0) {
 
448
    strcpy(CurFontName, "");    /* no font loaded */
 
449
    *mode = rcode;
 
450
    return(FALSE);
 
451
  }
 
452
  return(TRUE);
 
453
 
 
454
}
 
455
#endif
 
456
 
 
457
/***================================================================***/
 
458
/*   fontfcnA(env, mode)                                              */
 
459
/*                                                                    */
 
460
/*          env is a pointer to a string that contains the fontname.  */
 
461
/*                                                                    */
 
462
/*     1) initialize the font     - global indicates it has been done */
 
463
/*     2) load the font                                               */
 
464
/***================================================================***/
 
465
Bool 
 
466
fontfcnA(char *env, int *mode)
 
467
{
 
468
  int rc;
 
469
 
 
470
  /* Has the FontP initialized?  If not, then   */
 
471
  /* Initialize  */
 
472
#ifdef BUILDCID
 
473
  if (FontP == NULL || strcmp(CurFontName, "") == 0) {
 
474
#else
 
475
  if (FontP == NULL) {
 
476
#endif
 
477
    InitImager();
 
478
    if (!(initFont(VM_SIZE))) {
 
479
      /* we are really out of memory */
 
480
      *mode = SCAN_OUT_OF_MEMORY;
 
481
      return(FALSE);
 
482
    }
 
483
  }
 
484
 
 
485
  /* if the env is null, then use font already loaded */
 
486
 
 
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 */
 
490
    rc = readFont(env);
 
491
    if (rc != 0 ) {
 
492
      strcpy(CurFontName, "");    /* no font loaded */
 
493
      *mode = rc;
 
494
      return(FALSE);
 
495
    }
 
496
  }
 
497
  return(TRUE);
 
498
 
 
499
}
 
500
 
 
501
#ifdef BUILDCID
 
502
/***================================================================***/
 
503
/*   CIDQueryFontLib(cidfontname,cmapfile,infoName,infoValue,rcodeP)  */
 
504
/*                                                                    */
 
505
/*   cidfontname is a pointer to a string that contains the fontname. */
 
506
/*                                                                    */
 
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
/***================================================================***/
 
511
 
 
512
void 
 
513
CIDQueryFontLib(char *cidfontname, char *cmapfile, char *infoName,
 
514
                pointer infoValue, /* parameter returned here    */
 
515
                int *rcodeP)
 
516
{
 
517
  int rc,N,i,cidinit;
 
518
  psdict *dictP;
 
519
  psobj  nameObj;
 
520
  psobj  *valueP;
 
521
 
 
522
  /* Has the CIDFontP initialized?  If not, then   */
 
523
  /* Initialize  */
 
524
  cidinit = 0;
 
525
  if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
 
526
    InitImager();
 
527
    if (!(initCIDFont(VM_SIZE))) {
 
528
      *rcodeP = 1;
 
529
      return;
 
530
    }
 
531
    cidinit = 1;
 
532
  }
 
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);
 
539
    if (rc != 0 ) {
 
540
      strcpy(CurCIDFontName, "");    /* no font loaded */
 
541
      strcpy(CurCMapName, "");    /* no font loaded */
 
542
      *rcodeP = 1;
 
543
      return;
 
544
    }
 
545
  }
 
546
  dictP = CIDFontP->CIDfontInfoP;
 
547
  objFormatName(&nameObj,strlen(infoName),infoName);
 
548
  N = SearchDictName(dictP,&nameObj);
 
549
  /* if found */
 
550
  if ( N > 0 ) {
 
551
    *rcodeP = 0;
 
552
    switch (dictP[N].value.type) {
 
553
       case OBJ_ARRAY:
 
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      */
 
559
           for (i=0;i<6;i++) {
 
560
             if (valueP->type == OBJ_INTEGER )
 
561
               ((float *)infoValue)[i] = valueP->data.integer;
 
562
             else
 
563
               ((float *)infoValue)[i] = valueP->data.real;
 
564
            valueP++;
 
565
           }
 
566
         }
 
567
         if (strcmp(infoName,"FontBBox") == 0) {
 
568
           /* 4 elments for Bounding Box.  all integers   */
 
569
           for (i=0;i<4;i++) {
 
570
             ((int *)infoValue)[i] = valueP->data.integer;
 
571
             valueP++;
 
572
           }
 
573
         break;
 
574
       case OBJ_INTEGER:
 
575
       case OBJ_BOOLEAN:
 
576
         *((int *)infoValue) = dictP[N].value.data.integer;
 
577
         break;
 
578
       case OBJ_REAL:
 
579
         *((float *)infoValue) = dictP[N].value.data.real;
 
580
         break;
 
581
       case OBJ_NAME:
 
582
       case OBJ_STRING:
 
583
         *((char **)infoValue) =  dictP[N].value.data.valueP;
 
584
         break;
 
585
       default:
 
586
         *rcodeP = 1;
 
587
         break;
 
588
     }
 
589
   }
 
590
  }
 
591
  else *rcodeP = 1;
 
592
}
 
593
#endif
 
594
 
 
595
/***================================================================***/
 
596
/*   QueryFontLib(env, infoName,infoValue,rcodeP)                     */
 
597
/*                                                                    */
 
598
/*          env is a pointer to a string that contains the fontname.  */
 
599
/*                                                                    */
 
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
/***================================================================***/
 
604
 
 
605
void 
 
606
QueryFontLib(char *env, char *infoName,
 
607
             pointer infoValue, /* parameter returned here    */
 
608
             int *rcodeP)
 
609
{
 
610
  int rc,N,i;
 
611
  psdict *dictP;
 
612
  psobj  nameObj;
 
613
  psobj  *valueP;
 
614
 
 
615
  /* Has the FontP initialized?  If not, then   */
 
616
  /* Initialize  */
 
617
  if (FontP == NULL) {
 
618
    InitImager();
 
619
    if (!(initFont(VM_SIZE))) {
 
620
      *rcodeP = 1;
 
621
      return;
 
622
    }
 
623
  }
 
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 */
 
628
    rc = readFont(env);
 
629
    if (rc != 0 ) {
 
630
      strcpy(CurFontName, "");    /* no font loaded */
 
631
      *rcodeP = 1;
 
632
      return;
 
633
    }
 
634
  }
 
635
  dictP = FontP->fontInfoP;
 
636
  objFormatName(&nameObj,strlen(infoName),infoName);
 
637
  N = SearchDictName(dictP,&nameObj);
 
638
  /* if found */
 
639
  if ( N > 0 ) {
 
640
    *rcodeP = 0;
 
641
    switch (dictP[N].value.type) {
 
642
       case OBJ_ARRAY:
 
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      */
 
648
           for (i=0;i<6;i++) {
 
649
             if (valueP->type == OBJ_INTEGER )
 
650
               ((float *)infoValue)[i] = valueP->data.integer;
 
651
             else
 
652
               ((float *)infoValue)[i] = valueP->data.real;
 
653
            valueP++;
 
654
           }
 
655
         }
 
656
         if (strcmp(infoName,"FontBBox") == 0) {
 
657
           /* 4 elments for Bounding Box.  all integers   */
 
658
           for (i=0;i<4;i++) {
 
659
             ((int *)infoValue)[i] = valueP->data.integer;
 
660
             valueP++;
 
661
           }
 
662
         break;
 
663
       case OBJ_INTEGER:
 
664
       case OBJ_BOOLEAN:
 
665
         *((int *)infoValue) = dictP[N].value.data.integer;
 
666
         break;
 
667
       case OBJ_REAL:
 
668
         *((float *)infoValue) = dictP[N].value.data.real;
 
669
         break;
 
670
       case OBJ_NAME:
 
671
       case OBJ_STRING:
 
672
         *((char **)infoValue) =  dictP[N].value.data.valueP;
 
673
         break;
 
674
       default:
 
675
         *rcodeP = 1;
 
676
         break;
 
677
     }
 
678
   }
 
679
  }
 
680
  else *rcodeP = 1;
 
681
}
 
682
 
 
683
#ifdef BUILDCID
 
684
struct xobject *
 
685
CIDfontfcnC(struct XYspace *S, psobj *theStringP, 
 
686
            psobj *SubrsArrayP, struct blues_struct *BluesP,
 
687
            int *lenP, int *mode)
 
688
{
 
689
  struct xobject *charpath;   /* the path for this character              */
 
690
 
 
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);
 
699
  }
 
700
  return(charpath);
 
701
}
 
702
#endif