This is tfmload.c in view mode; [Download] [Up]
/*
* tfmload.c of dvisw software package.
*
* Loads a tfm file. It marks the characters as undefined.
*/
#include "structures.h"
#include <kpathsea/tex-file.h>
#include <string.h>
/*
* These are the external routines it calls:
*/
extern void error() ;
extern FILE *search() ;
extern integer scalewidth() ;
extern void newraster() ;
extern void TPSdf(), TPSdfe(), TPSdc(), TPSbop(), TPSeop(), texflush() ;
/*
* Here are the external variables we use:
*/
extern halfword *left, *right, *top ;
extern TeXfontdesctype *TeXfonts[] ;
extern real conv ;
extern int curid ;
extern char lastfile[] ;
/*
* Our static variables:
*/
static FILE *tfmfile ;
/*
* Tries to open a tfm file. Returns true if found.
*/
Boolean tfmopen(tft)
TeXfontdesctype *tft ;
{
register char *d, *n ;
n = tft->name ;
if (*n==0) {
n++ ;
d = tfmpath ;
} else {
d = n ;
while (*n) n++ ;
}
sprintf(lastfile, "%s.tfm", n) ;
tfmfile = search(d, lastfile) ;
if (tfmfile == 0) {
error(" couldn't find tfm file; substituting cmr10") ;
tfmfile = search(tfmpath, "cmr10.tfm") ;
}
return (tfmfile != NULL) ;
}
shalfword tfmbyte () {
return(getc(tfmfile)) ;
}
halfword tfm16 () {
register halfword a ;
a = tfmbyte () ;
return ( a * 256 + tfmbyte () ) ;
}
integer tfm32 () {
register integer a ;
a = tfm16 () ;
return ( (a << 16) + tfm16 () ) ;
}
void tfmload(tft, define)
register TeXfontdesctype *tft ;
int define ;
{
register chardesctype *cdp ;
register shalfword i ;
register integer li ;
register fontdesctype *curfnt ;
integer scaledsize ;
shalfword nw, nh, nd, hd ;
shalfword bc, ec ;
integer scaled[400] ;
halfword chardat[256] ;
shalfword pixel[400] ;
int height, width, yoff ;
int *black ;
int bk ;
bk = ~0 ;
black = &bk ;
curfnt = tft->loaded ;
if (!tfmopen(tft))
error("! could not open tfm file") ;
/*
* Next, we read the font data from the tfm file, and store it in
* our own arrays.
*/
li = tfm16() ; hd = tfm16() ;
bc = tfm16() ; ec = tfm16() ;
nw = tfm16() ; nh = tfm16() ; nd = tfm16() ;
li = tfm32() ; li = tfm32() ; li = tfm16() ;
scaledsize = tfm32() ;
/* if (scaledsize-tft->checksum > 6 || -6 > scaledsize-tft->checksum) {
error("bad checksum in tfm file") ;
} */
li = tfm32() >> 4 ;
if (li > tft->designsize + 2 || li < tft->designsize - 2)
error("bad design size in tfm file") ;
for (i=2; i<hd; i++)
li = tfm32() ;
for (i=bc; i<=ec; i++) {
chardat[i] = tfm16() ;
li = tfm16() ;
}
scaledsize = tft->scaledsize ;
for (i=0; i<nw+nh+nd; i++) {
scaled[i] = tfm32() ;
if (scaled[i] >= 0)
pixel[i] = (conv * scalewidth(scaled[i], scaledsize) + 0.5) ;
else
pixel[i] = -(conv * scalewidth(-scaled[i], scaledsize) + 0.5) ;
}
fclose(tfmfile) ;
if (define) {
curfnt->id = curid++ ;
#ifdef POPRESTORE
TPSeop() ;
#endif
TPSdf(curfnt->id) ;
}
for (i=0, cdp = curfnt->chardesc; i<256; i++, cdp++) {
if (i>=bc && i<=ec) {
cdp = curfnt->chardesc + i ;
cdp->TFMwidth = scaled[chardat[i]>>8] ;
cdp->pixelwidth = pixel[chardat[i]>>8] ;
width = cdp->pixelwidth ;
yoff = pixel[((chardat[i]&240)>>4)+nw] ;
height = pixel[(chardat[i]&15)+nw+nh] + yoff ;
if (width <= 0)
width = 1 ;
if (height <= 0)
height = 1 ;
if (define)
TPSdc(black, 2, width, height, 0, height - yoff - 1, cdp->pixelwidth, i) ;
}
}
if (define) {
TPSdfe() ;
#ifdef POPRESTORE
TPSbop() ;
#else
texflush() ;
#endif
}
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.