home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fonts 1
/
freshfonts1.bin
/
bbs
/
programs
/
amiga
/
pastex13.lha
/
DVIPS
/
dvips5519.lha
/
dvips
/
loadfont.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-04
|
14KB
|
483 lines
/*
* Here's the code to load a PK file into memory.
* Individual bitmaps won't be unpacked until they prove to be needed.
*/
#include "dvips.h" /* The copyright notice in that file is included too! */
/*
* These are the external routines we use.
*/
extern void makefont() ;
extern void error() ;
extern integer scalewidth() ;
extern int tfmload() ;
extern FILE *pksearch() ;
/*
* These are the external variables we use.
*/
#ifdef DEBUG
extern integer debug_flag;
#endif /* DEBUG */
extern long bytesleft ;
extern quarterword *raster ;
extern real conv ;
extern int actualdpi, vactualdpi ;
extern real alpha ;
extern char *pkpath ;
char errbuf[200] ;
int lastresortsizes[40] ;
extern integer fsizetol ;
extern Boolean nosmallchars ;
extern Boolean compressed ;
extern Boolean dopprescan ;
#ifdef FONTLIB
extern Boolean flib ;
extern FILE *flisearch() ;
#endif
/*
* Now we have some routines to get stuff from the PK file.
* Subroutine pkbyte returns the next byte.
*/
FILE *pkfile ;
char name[50] ;
void
badpk(s)
char *s ;
{
(void)sprintf(errbuf,"! Bad PK file %s: %s",name,s) ;
error(errbuf);
}
shalfword
pkbyte()
{
register shalfword i ;
if ((i=getc(pkfile))==EOF)
badpk("unexpected eof") ;
return(i) ;
}
integer
pkquad()
{
register integer i ;
i = pkbyte() ;
if (i > 127)
i -= 256 ;
i = i * 256 + pkbyte() ;
i = i * 256 + pkbyte() ;
i = i * 256 + pkbyte() ;
return(i) ;
}
integer
pktrio()
{
register integer i ;
i = pkbyte() ;
i = i * 256 + pkbyte() ;
i = i * 256 + pkbyte() ;
return(i) ;
}
/*
* pkopen opens the pk file. This is system dependent. We work really
* hard to open some sort of PK file.
*/
#ifdef VMCMS /* IBM: VM/CMS - we let DVIPS EXEC handle this after
the DVIPS MODULE has finished to avoid
complications with system calls. */
int dontmakefont = 0 ;
#else
#ifdef MVSXA /* IBM: MVS/XA - we let system administrator handle this on
MVS/XA since some printers can't get to user
fonts anyway */
int dontmakefont = 1 ;
#else
int dontmakefont = 0 ; /* if makefont fails once we won't try again */
#endif /* IBM: VM/CMS */
#endif
void
lectureuser() {
static int userwarned = 0 ;
if (! userwarned) {
error("Such scaling will generate extremely poor output.") ;
userwarned = 1 ;
}
}
Boolean
pkopen(fd)
register fontdesctype *fd ;
{
register char *d, *n ;
int vdpi ;
d = fd->area ;
n = fd->name ;
if (*d==0)
d = pkpath ;
#ifdef FONTLIB
if (*(fd->area) == 0) {
int del ;
for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
if ((pkfile=flisearch(n, fd->dpi + del)) != (FILE *)NULL )
return(1);
}
}
#endif
{
int del ;
for (del=0; del<=RES_TOLERANCE(fd->dpi); del=del>0?-del:-del+1) {
if (actualdpi == vactualdpi) {
vdpi = 0 ;
} else {
vdpi = (2 * ((long)vactualdpi) * (fd->dpi + del) + actualdpi)
/ (2 * actualdpi) ;
}
#ifdef MVSXA
(void)sprintf(name, "pk%d(%s)", fd->dpi + del, n) ;
#else
#ifdef AMIGA
(void)sprintf(name, "%d/%s.%dpk", fd->dpi + del, n, fd->dpi + del) ;
#else
(void)sprintf(name, "%s.%dpk", n, fd->dpi + del) ;
#endif
#endif
if (0 != (pkfile=pksearch(d, name, READBIN, n, fd->dpi + del, vdpi)))
return(1) ;
}
}
if (d == pkpath) {
if (actualdpi == vactualdpi) {
vdpi = 0 ;
} else {
vdpi = (2 * ((long)vactualdpi) * fd->dpi + actualdpi)
/ (2 * actualdpi) ;
}
#ifdef MVSXA
(void)sprintf(name, "pk%d(%s)", fd->dpi, n) ;
#else
#ifdef AMIGA
(void)sprintf(name, "%d/%s.%dpk", fd->dpi, n, fd->dpi) ;
#else
(void)sprintf(name, "%s.%dpk", n, fd->dpi) ;
#endif
#endif
makefont(n, (int)fd->dpi, DPI) ;
if (dontmakefont == 0 &&
(pkfile = pksearch(d, name, READBIN, n, fd->dpi, vdpi)))
return(1) ;
#ifndef MSDOS
#ifndef AMIGA
dontmakefont = 1 ;
#endif
#endif
}
/*
* If nothing above worked, then we get desparate. We attempt to
* open the stupid font at one of a small set of predefined sizes,
* and then use PostScript scaling to generate the correct size.
*
* We much prefer scaling up to scaling down, since scaling down
* can omit character features, so we try the larger sizes first,
* and then work down.
*/
{
int i, j ;
if (lastresortsizes[0] && fd->dpi < 30000) {
for (i=0; lastresortsizes[i] < fd->dpi; i++) ;
for (j = i-1; j >= 0; j--) {
if (actualdpi == vactualdpi) {
vdpi = 0 ;
} else {
vdpi = (2 * ((long)vactualdpi) * lastresortsizes[j] + actualdpi)
/ (2 * actualdpi) ;
}
#ifdef MVSXA
(void)sprintf(name, "pk%d(%s)", lastresortsizes[j], n) ;
#else
#ifdef AMIGA
(void)sprintf(name, "%d/%s.%dpk", lastresortsizes[j], n, lastresortsizes[j]) ;
#else
(void)sprintf(name, "%s.%dpk", n, lastresortsizes[j]) ;
#endif
#endif
#ifdef FONTLIB
if (0 != (pkfile=flisearch(n,(halfword)lastresortsizes[j]))
|| 0 != (pkfile=pksearch(d, name, READBIN, n,
(halfword)lastresortsizes[j], vdpi))) {
#else
if (0 != (pkfile=pksearch(d, name, READBIN, n,
(halfword)lastresortsizes[j], vdpi))) {
#endif
fd->loadeddpi = lastresortsizes[j] ;
fd->alreadyscaled = 0 ;
(void)sprintf(errbuf,
"Font %s at %d not found; scaling %d instead.",
name, fd->dpi, lastresortsizes[j]) ;
error(errbuf) ;
lectureuser() ;
return 1 ;
}
}
for (j = i; lastresortsizes[j] < 30000; j++) {
if (actualdpi == vactualdpi) {
vdpi = 0 ;
} else {
vdpi = (2 * ((long)vactualdpi) * lastresortsizes[j] + actualdpi)
/ (2 * actualdpi) ;
}
#ifdef AMIGA
(void)sprintf(name, "%d/%s.%dpk", lastresortsizes[j], n, lastresortsizes[j]) ;
#else
(void)sprintf(name, "%s.%dpk", n, lastresortsizes[j]) ;
#endif
#ifdef FONTLIB
if (0 != (pkfile=flisearch(n, (halfword)lastresortsizes[j]))
|| 0 != (pkfile=pksearch(d, name, READBIN, n,
(halfword)lastresortsizes[j], vdpi))) {
#else
if (0 != (pkfile=pksearch(d, name, READBIN, n,
(halfword)lastresortsizes[j], vdpi))) {
#endif
fd->loadeddpi = lastresortsizes[j] ;
fd->alreadyscaled = 0 ;
(void)sprintf(errbuf,
"Font %s at %d not found; scaling %d instead.",
name, fd->dpi, lastresortsizes[j]) ;
error(errbuf) ;
lectureuser() ;
return 1 ;
}
}
}
}
#ifdef MVSXA
(void)sprintf(name, "%s.pk%d", n, fd->dpi) ;
#else
#ifdef AMIGA
(void)sprintf(name, "%d/%s.%dpk", fd->dpi, n, fd->dpi) ;
#else
(void)sprintf(name, "%s.%dpk", n, fd->dpi) ;
#endif
#endif
(void)sprintf(errbuf,
"Font %s%s not found, characters will be left blank.",
fd->area, name) ;
error(errbuf) ;
return(0) ;
}
/*
* Now our loadfont routine. We return an integer indicating the
* highest character code in the font, so we know how much space
* to reserve for the character. (It's returned in the font
* structure, along with everything else.)
*/
void
loadfont(curfnt)
register fontdesctype *curfnt ;
{
register shalfword i ;
register shalfword cmd ;
register integer k ;
register integer length = 0 ;
register shalfword cc = 0 ;
register integer scaledsize = curfnt->scaledsize ;
register