Debian Codegraph @

texk/dvipsk/fontdef.c

raw
1 /*
2 * Stores the data from a font definition into the global data structures.
3 * A routine skipnop is also included to handle nops and font definitions
4 * between pages.
5 */
6 #include "dvips.h" /* The copyright notice in that file is included too! */
7 #ifdef KPATHSEA
8 #include <kpathsea/magstep.h>
9 #endif
10
11 /*
12 * The external declarations:
13 */
14 #include "protos.h"
15
16 /*
17 * newfontdesc creates a new font descriptor with the given parameters and
18 * returns a pointer to the new object.
19 */
20 fontdesctype*
21 newfontdesc(integer cksum, integer scsize, integer dssize,
22 char *name, char *area)
23 {
24 register fontdesctype *fp;
25
26 fp = (fontdesctype *)mymalloc((integer)sizeof(fontdesctype));
27 fp->chardesc = (chardesctype *)mymalloc(256*(integer)sizeof(chardesctype));
28 fp->maxchars = 256;
29 fp->iswide = 0;
30 fp->psname = 0;
31 fp->loaded = 0;
32 fp->checksum = cksum;
33 fp->scaledsize = scsize;
34 fp->designsize = dssize;
35 fp->thinspace = scsize / 6;
36 fp->scalename = NULL;
37 fp->psflag = 0;
38 fp->codewidth = 1;
39 fp->name = name;
40 #ifdef VMCMS /* IBM: VM/CMS */
41 {
42 int i;
43 for ( i=0; fp->name[i]; i++ )
44 fp->name[i] = ascii2ebcdic[ fp->name[i] ];
45 }
46 #else
47 #ifdef MVSXA /* IBM: MVS/XA */
48 {
49 int i;
50 for ( i=0; fp->name[i]; i++ )
51 fp->name[i] = ascii2ebcdic[ fp->name[i] ];
52 }
53 #endif /* IBM: MVS/XA */
54 #endif /* IBM: VM/CMS */
55 fp->area = area;
56 fp->resfont = NULL;
57 fp->localfonts = NULL;
58 #ifdef KPATHSEA
59 fp->dpi = kpse_magstep_fix ((halfword)(mag*(float)fp->scaledsize*DPI/
60 ((float)fp->designsize*1000.0)+0.5), DPI, NULL);
61 #else
62 fp->dpi = dpicheck((halfword)(mag*fp->scaledsize*DPI/
63 ((float)fp->designsize*1000.0)+0.5));
64 #endif
65 fp->loadeddpi = fp->dpi;
66 #ifdef DEBUG
67 if (dd(D_FONTS))
68 fprintf_str(stderr,"Defining font (%s) %s at %.1fpt\n",
69 area, name, (real)scsize/(alpha*0x100000));
70 #endif /* DEBUG */
71 return fp;
72 }
73 /*
74 * Try to find a font with a given name and approximate scaled size, returning
75 * NULL if unsuccessful. If scname and the font's scalename are both
76 * non-NULL they must match exactly. If both are NULL, scsize and the
77 * font's scaledsize come from the dvi file and should match exactly.
78 * Otherwise there can be some slop due to the inaccuracies of sizes
79 * read from an included psfile.
80 */
81 fontdesctype *
82 matchfont(char *name, char *area, integer scsize, char *scname)
83 {
84 register fontdesctype *fp;
85 register integer smin, smax;
86
87 smin = scsize - fsizetol;
88 smax = scsize + fsizetol;
89 for (fp=fonthead; fp; fp=fp->next)
90 if (smin < fp->scaledsize && fp->scaledsize < smax &&
91 strcmp(name,fp->name)==0 && strcmp(area,fp->area)==0) {
92 if (scname == NULL) {
93 if (fp->scalename!=NULL || scsize==fp->scaledsize)
94 break;
95 } else {
96 if (fp->scalename==NULL || strcmp(scname,fp->scalename)==0)
97 break;
98 }
99 }
100 #ifdef DEBUG
101 if (dd(D_FONTS) && fp)
102 fprintf(stderr,"(Already known.)\n");
103 #endif /* DEBUG */
104 return fp;
105 }
106 /*
107 * fontdef takes a font definition in the dvi file and loads the data
108 * into its data structures.
109 */
110 void
111 fontdef(int siz)
112 {
113 register integer i, j, fn;
114 register fontdesctype *fp;
115 register fontmaptype *cfnt;
116 char *name, *area;
117 integer cksum, scsize, dssize;
118
119 fn = dvibyte();
120 while (siz-- > 1)
121 fn = (fn << 8) + dvibyte();
122 for (cfnt=ffont; cfnt; cfnt = cfnt->next)
123 if (cfnt->fontnum == fn) goto alreadydefined;
124 cfnt = (fontmaptype *)mymalloc((integer)sizeof(fontmaptype));
125 cfnt->next = ffont;
126 ffont = cfnt;
127 cfnt->fontnum = fn;
128 cksum = signedquad();
129 scsize = signedquad();
130 dssize = signedquad();
131 i = dvibyte(); j = dvibyte();
132 if (nextstring + i + j > maxstring)
133 error("! out of string space");
134 area = nextstring;
135 for (; i>0; i--)
136 *nextstring++ = dvibyte();
137 *nextstring++ = 0;
138 name = nextstring;
139 for (; j>0; j--)
140 *nextstring++ = dvibyte();
141 *nextstring++ = 0;
142 fp = matchfont(name, area, scsize, (char *)0);
143 if (fp) {
144 nextstring = name;
145 fp->checksum = cksum;
146 } else {
147 fp = newfontdesc(cksum, scsize, dssize, name, area);
148 fp->next = fonthead;
149 fonthead = fp;
150 }
151 cfnt->desc = fp;
152 return;
153 alreadydefined:
154 /* A DVI file will not define a font twice; but we may be scanning
155 * a font definition twice because a new section has started,
156 * or because of collated copies. */
157 skipover(12);
158 skipover(dvibyte()+dvibyte());
159 }
160
161 /*
162 * The next routine handles nops or font definitions between pages in a
163 * dvi file. Returns the first command that is not a nop or font definition.
164 *
165 * Now handles specials (but ignores them)
166 */
167 int
168 skipnop(void)
169 {
170 register int cmd;
171
172 while (1) {
173 switch(cmd=dvibyte()) {
174 case 138: break;
175 case 239: skipover((int)dvibyte()); break; /* xxx1 */
176 case 240: skipover((int)twobytes()); break; /* xxx2 */
177 case 241: skipover((int)threebytes()); break; /* xxx3 */
178 case 242: skipover((int)signedquad()); break; /* xxx4 */
179 case 243: case 244: case 245: case 246: fontdef(cmd-242); break;
180 default: return cmd;
181 }
182 }
183 }