w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fontdef.c
Go to the documentation of this file.
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 */
22  char *name, char *area)
23 {
24  register fontdesctype *fp;
25 
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  */
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 }
long cksum
Definition: afm2tfm.c:238
#define mag
Definition: aptex-macros.h:802
#define name
halfword dpicheck(halfword dpi)
Definition: dpicheck.c:62
double real
Definition: dvips.h:66
unsigned short halfword
Definition: dvips.h:68
int strcmp()
Definition: coll.cpp:143
char * maxstring
Definition: dvidvi.c:138
static halfword twobytes(void)
Definition: dvidvi.c:230
char * nextstring
Definition: dvidvi.c:138
static integer signedquad(void)
Definition: dvidvi.c:273
static shalfword dvibyte(void)
Definition: dvidvi.c:222
#define error(a)
Definition: dviinfo.c:48
void skipover(int i)
Definition: dviinput.c:86
integer threebytes(void)
Definition: dviinput.c:41
fontmaptype * ffont
Definition: dvips.c:136
fontdesctype * fonthead
Definition: dvips.c:92
integer fsizetol
Definition: dvips.c:225
struct tft fontmaptype
struct tfd fontdesctype
struct tcd chardesctype
#define fprintf_str
Definition: dvips.h:321
void fontdef(int siz)
Definition: fontdef.c:111
fontdesctype * newfontdesc(integer cksum, integer scsize, integer dssize, char *name, char *area)
Definition: fontdef.c:21
int skipnop(void)
Definition: fontdef.c:168
fontdesctype * matchfont(char *name, char *area, integer scsize, char *scname)
Definition: fontdef.c:82
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define fprintf
Definition: mendex.h:64
#define cmd(arg)
Definition: mitsu.h:44
string fn
Definition: fc-lang.py:335
int integer
Definition: pbmtopk.c:38
#define fp
static enum alpha_handling alpha
Definition: pngtopnm.c:70
float DPI
Definition: mag.c:83
#define mymalloc
Definition: pscolor.c:28
Definition: dvips.h:148
Definition: dvips.h:174
Definition: dvips.h:200
fontdesctype * desc
Definition: dvips.h:202
struct tft * next
Definition: dvips.h:203
integer fontnum
Definition: dvips.h:201
int j
Definition: t4ht.c:1589