~ubuntu-branches/ubuntu/trusty/libxfont/trusty-updates

« back to all changes in this revision

Viewing changes to src/Type1/fontfcn.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2007-02-16 14:32:57 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070216143257-r24zgvh3taklylv9
Tags: 1:1.2.7-1
* New upstream release.
* Add XS-Vcs-Git header to debian/control, and drop obsolete CVS information.
* Install the upstream ChangeLog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 * SOFTWARE.
29
29
 */
30
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
31
/* $XFree86: xc/lib/font/Type1/fontfcn.c,v 1.10 2001/04/05 17:42:27 dawes Exp $ */
49
32
 
50
33
#ifdef HAVE_CONFIG_H
51
34
#include <config.h>
52
35
#endif
53
 
#ifdef BUILDCID
54
 
#define XFONT_CID 1
55
 
#endif
56
36
 
57
37
#ifndef FONTMODULE
58
38
#include <stdio.h>
64
44
#endif
65
45
#include "t1imager.h"
66
46
#include "util.h"
67
 
#if XFONT_CID
68
 
#include "range.h"
69
 
#include <X11/Xdefs.h>
70
 
#endif
71
47
#include <X11/fonts/fntfilst.h>
72
48
#include "fontfcn.h"
73
49
 
76
52
                                   psobj *osubrsP, 
77
53
                                   struct blues_struct *bluesP, int *modeP );
78
54
 
79
 
#if XFONT_CID
80
 
extern struct xobject *CIDChar ( char *env, XYspace S, 
81
 
                                 psobj *charstrP, psobj *subrsP, 
82
 
                                 psobj *osubrsP, 
83
 
                                 struct blues_struct *bluesP, int *modeP );
84
 
static boolean initCIDFont( int cnt );
85
 
#endif
86
55
 
87
56
/***================================================================***/
88
57
/*   GLOBALS                                                          */
92
61
char *vm_base = NULL;
93
62
psfont *FontP = NULL;
94
63
psfont TheCurrentFont;
95
 
#if XFONT_CID
96
 
char CurCIDFontName[CID_PATH_MAX];
97
 
char CurCMapName[CID_PATH_MAX];
98
 
cidfont *CIDFontP = NULL;
99
 
cmapres *CMapP = NULL;
100
 
cidfont TheCurrentCIDFont;
101
 
cmapres TheCurrentCMap;
102
 
psfont *FDArrayP = NULL;
103
 
int FDArrayIndex = 0;
104
 
#endif
105
 
 
 
64
 
106
65
/***================================================================***/
107
66
/*   SearchDict - look for  name                                      */
108
67
/*              - compare for match on len and string                 */
129
88
  return(0);
130
89
}
131
90
 
132
 
#if XFONT_CID
133
 
static boolean 
134
 
initCIDFont(int cnt)
135
 
{
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;
157
 
  CMapP->lastRow = 0;
158
 
  CMapP->lastCol = 0;
159
 
  return(TRUE);
160
 
}
161
 
 
162
 
/***================================================================***/
163
 
boolean 
164
 
initCIDType1Font(void)
165
 
{
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;
177
 
  return(TRUE);
178
 
}
179
 
#endif
180
 
 
181
91
boolean 
182
92
initFont(int cnt)
183
93
{
186
96
  vm_base = vm_next_byte();
187
97
  if (!(Init_BuiltInEncoding())) return(FALSE);
188
98
  strcpy(CurFontName, "");    /* iniitialize to none */
189
 
#if XFONT_CID
190
 
  /* cause a font data reset on the next CID-keyed font */
191
 
  strcpy(CurCIDFontName, "");    /* initialize to none */
192
 
#endif
193
99
  FontP = &TheCurrentFont;
194
100
  FontP->vm_start = vm_next_byte();
195
101
  FontP->FontFileName.len = 0;
197
103
  return(TRUE);
198
104
}
199
105
/***================================================================***/
200
 
#if XFONT_CID
201
 
static void 
202
 
resetCIDFont(char *cidfontname, char *cmapfile)
203
 
{
204
 
 
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;
223
 
  CMapP->lastRow = 0;
224
 
  CMapP->lastCol = 0;
225
 
}
226
 
 
227
 
static void 
228
 
resetCIDType1Font(void)
229
 
{
230
 
 
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;
242
 
}
243
 
#endif
244
 
 
245
106
static void 
246
107
resetFont(char *env)
247
108
{
261
122
 
262
123
}
263
124
 
264
 
#if XFONT_CID
265
 
/***================================================================***/
266
 
int 
267
 
readCIDFont(char *cidfontname, char *cmapfile)
268
 
{
269
 
  int rcode;
270
 
 
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);
280
 
    }
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);
289
 
      }
290
 
      resetCIDFont(cidfontname, cmapfile);
291
 
      rcode = scan_cidfont(CIDFontP, CMapP);
292
 
    }
293
 
  }
294
 
  return(rcode);
295
 
}
296
 
 
297
 
int 
298
 
readCIDType1Font(void)
299
 
{
300
 
  int rcode;
301
 
 
302
 
  resetCIDType1Font();
303
 
 
304
 
  /* This will load the font into the FontP */
305
 
  rcode = scan_cidtype1font(FontP);
306
 
  return(rcode);
307
 
}
308
 
#endif
309
 
 
310
125
int 
311
126
readFont(char *env)
312
127
{
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 */
321
 
#if XFONT_CID
322
 
    /* xfree(vm_base); */
323
 
#else
324
 
    xfree(vm_base);
325
 
#endif
326
135
    if (!(initFont(vm_size * 2))) {
327
136
      /* we are really out of memory */
328
137
      return(SCAN_OUT_OF_MEMORY);
329
138
      }
330
139
    resetFont(env);
331
140
    rcode = scan_font(FontP);
332
 
#if XFONT_CID
333
 
    /* only double the memory twice, then report error */
334
 
    if (rcode == SCAN_OUT_OF_MEMORY) {
335
 
      /* free the memory and start again */
336
 
      /* xfree(vm_base) */
337
 
      if (!(initFont(vm_size * 2))) {
338
 
        /* we are really out of memory */
339
 
        return(SCAN_OUT_OF_MEMORY);
340
 
      }
341
 
      resetFont(env);
342
 
      rcode = scan_font(FontP);
343
 
    }
344
 
#else
345
141
    /* only double the memory once, then report error */
346
 
#endif
347
142
  }
348
143
  return(rcode);
349
144
}
393
188
  return(charpath);
394
189
}
395
190
 
396
 
#if XFONT_CID
397
 
/***================================================================***/
398
 
/*   CIDfontfcnA(cidfontname, cmapfile, mode)                         */
399
 
/*                                                                    */
400
 
/*     1) initialize the font     - global indicates it has been done */
401
 
/*     2) load the font                                               */
402
 
/***================================================================***/
403
 
Bool 
404
 
CIDfontfcnA(char *cidfontname, char *cmapfile, int *mode)
405
 
{
406
 
  int rcode, cidinit;
407
 
 
408
 
  cidinit = 0;
409
 
  if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
410
 
    InitImager();
411
 
    if (!(initCIDFont(VM_SIZE))) {
412
 
      /* we are really out of memory */
413
 
      *mode = SCAN_OUT_OF_MEMORY;
414
 
      return(FALSE);
415
 
    }
416
 
    cidinit = 1;
417
 
  }
418
 
 
419
 
  /* if the cidfontname is null, then use font already loaded */
420
 
 
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);
426
 
    if (rcode != 0 ) {
427
 
      strcpy(CurCIDFontName, "");    /* no CIDFont loaded */
428
 
      strcpy(CurCMapName, "");    /* no CMap loaded */
429
 
      *mode = rcode;
430
 
      return(FALSE);
431
 
    }
432
 
  }
433
 
  return(TRUE);
434
 
 
435
 
}
436
 
 
437
 
/***================================================================***/
438
 
/*   CIDType1fontfcnA(mode)                                           */
439
 
/*                                                                    */
440
 
/*     1) initialize the font     - global indicates it has been done */
441
 
/*     2) load the font                                               */
442
 
/***================================================================***/
443
 
Bool 
444
 
CIDType1fontfcnA(int *mode)
445
 
{
446
 
  int rcode;
447
 
 
448
 
  if (!(initCIDType1Font())) {
449
 
    /* we are really out of memory */
450
 
    *mode = SCAN_OUT_OF_MEMORY;
451
 
    return(FALSE);
452
 
  }
453
 
 
454
 
  if ((rcode = readCIDType1Font()) != 0) {
455
 
    strcpy(CurFontName, "");    /* no font loaded */
456
 
    *mode = rcode;
457
 
    return(FALSE);
458
 
  }
459
 
  return(TRUE);
460
 
 
461
 
}
462
 
#endif
463
191
 
464
192
/***================================================================***/
465
193
/*   fontfcnA(env, mode)                                              */
476
204
 
477
205
  /* Has the FontP initialized?  If not, then   */
478
206
  /* Initialize  */
479
 
#if XFONT_CID
480
 
  if (FontP == NULL || strcmp(CurFontName, "") == 0) {
481
 
#else
482
207
  if (FontP == NULL) {
483
 
#endif
484
208
    InitImager();
485
209
    if (!(initFont(VM_SIZE))) {
486
210
      /* we are really out of memory */
505
229
 
506
230
}
507
231
 
508
 
#if XFONT_CID
509
 
/***================================================================***/
510
 
/*   CIDQueryFontLib(cidfontname,cmapfile,infoName,infoValue,rcodeP)  */
511
 
/*                                                                    */
512
 
/*   cidfontname is a pointer to a string that contains the fontname. */
513
 
/*                                                                    */
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
 
/***================================================================***/
518
 
 
519
 
void 
520
 
CIDQueryFontLib(char *cidfontname, char *cmapfile, char *infoName,
521
 
                pointer infoValue, /* parameter returned here    */
522
 
                int *rcodeP)
523
 
{
524
 
  int rc,N,i,cidinit;
525
 
  psdict *dictP;
526
 
  psobj  nameObj;
527
 
  psobj  *valueP;
528
 
 
529
 
  /* Has the CIDFontP initialized?  If not, then   */
530
 
  /* Initialize  */
531
 
  cidinit = 0;
532
 
  if (CIDFontP == NULL || strcmp(CurCIDFontName, "") == 0) {
533
 
    InitImager();
534
 
    if (!(initCIDFont(VM_SIZE))) {
535
 
      *rcodeP = 1;
536
 
      return;
537
 
    }
538
 
    cidinit = 1;
539
 
  }
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);
546
 
    if (rc != 0 ) {
547
 
      strcpy(CurCIDFontName, "");    /* no font loaded */
548
 
      strcpy(CurCMapName, "");    /* no font loaded */
549
 
      *rcodeP = 1;
550
 
      return;
551
 
    }
552
 
  }
553
 
  dictP = CIDFontP->CIDfontInfoP;
554
 
  objFormatName(&nameObj,strlen(infoName),infoName);
555
 
  N = SearchDictName(dictP,&nameObj);
556
 
  /* if found */
557
 
  if ( N > 0 ) {
558
 
    *rcodeP = 0;
559
 
    switch (dictP[N].value.type) {
560
 
       case OBJ_ARRAY:
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      */
566
 
           for (i=0;i<6;i++) {
567
 
             if (valueP->type == OBJ_INTEGER )
568
 
               ((float *)infoValue)[i] = valueP->data.integer;
569
 
             else
570
 
               ((float *)infoValue)[i] = valueP->data.real;
571
 
            valueP++;
572
 
           }
573
 
         }
574
 
         if (strcmp(infoName,"FontBBox") == 0) {
575
 
           /* 4 elments for Bounding Box.  all integers   */
576
 
           for (i=0;i<4;i++) {
577
 
             ((int *)infoValue)[i] = valueP->data.integer;
578
 
             valueP++;
579
 
           }
580
 
         break;
581
 
       case OBJ_INTEGER:
582
 
       case OBJ_BOOLEAN:
583
 
         *((int *)infoValue) = dictP[N].value.data.integer;
584
 
         break;
585
 
       case OBJ_REAL:
586
 
         *((float *)infoValue) = dictP[N].value.data.real;
587
 
         break;
588
 
       case OBJ_NAME:
589
 
       case OBJ_STRING:
590
 
         *((char **)infoValue) =  dictP[N].value.data.valueP;
591
 
         break;
592
 
       default:
593
 
         *rcodeP = 1;
594
 
         break;
595
 
     }
596
 
   }
597
 
  }
598
 
  else *rcodeP = 1;
599
 
}
600
 
#endif
601
 
 
602
232
/***================================================================***/
603
233
/*   QueryFontLib(env, infoName,infoValue,rcodeP)                     */
604
234
/*                                                                    */
686
316
  }
687
317
  else *rcodeP = 1;
688
318
}
689
 
 
690
 
#if XFONT_CID
691
 
struct xobject *
692
 
CIDfontfcnC(struct XYspace *S, psobj *theStringP, 
693
 
            psobj *SubrsArrayP, struct blues_struct *BluesP,
694
 
            int *lenP, int *mode)
695
 
{
696
 
  struct xobject *charpath;   /* the path for this character              */
697
 
 
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);
706
 
  }
707
 
  return(charpath);
708
 
}
709
 
#endif