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