1: /******************************************************************************
   2:  *  font - 	manages the fonts and their associated descriptor files for
   3:  *		processing ditroff commands into interpress
   4:  *
   5:  *
   6:  *	William LeFebvre (Xerox Corp)
   7:  *	with modifications by John Mellor-Crummey (Xerox Corp)
   8:  *
   9:  * 	Copyright (c) 1984,1985 Xerox Corp.
  10:  *
  11:  * HISTORY
  12:  * 15-Jan-86  lee at Xerox, WRC
  13:  *	Fixed NULL pointer de-reference.
  14:  *
  15:  *
  16:  ******************************************************************************/
  17: 
  18: #include <stdio.h>
  19: #include <sys/types.h>
  20: #include <sys/file.h>
  21: #include <sys/stat.h>
  22: 
  23: 
  24: #include "deviceinfo.h" /* typesetter characteristics */
  25: #include "defs.h"   /* constant and macro definitions */
  26: #include "externs.h"    /* declarations for global variables */
  27: 
  28: 
  29: /*-----------------------------------------------------------------------------
  30:  *	readDeviceInitInfo	read the device descriptor and font
  31:  *				initialization info into tables in memory
  32:  *				from a typesetter descriptor file created using
  33:  *				by makedev
  34:  *---------------------------------------------------------------------------*/
  35: readDeviceInitInfo()
  36: {
  37:     int devicefd,entries,fontno;
  38:     char deviceFilename[80],*buffer,*ptr;
  39: 
  40:     /* read in device descriptor , fonts character and width info */
  41: 
  42:     /* form descriptor file name */
  43:     (void) sprintf(deviceFilename, "%s/dev%s/DESC.out", fontdirectory, devicename);
  44: 
  45:     if ((devicefd = open(deviceFilename,O_RDONLY,0)) < 0)
  46:         reportError(QUIT, "can't open file %s for device characteristics (%s)",
  47:             deviceFilename, sys_errlist[errno]);
  48: 
  49:     /* read in device characteristics */
  50:     (void) read(devicefd, &device, sizeof(struct device_entry));
  51: 
  52:     /* allocate space to read in the rest of
  53: 	 * the tables in the descriptor file
  54: 	 */
  55:     buffer = malloc(device.font_size);
  56:     (void) read(devicefd, buffer, device.font_size);
  57: 
  58:     /* set up global pointers to tables */
  59:     pointsizeTab = (short *) buffer;
  60:     specCharTab = (short *) pointsizeTab + device.num_sizes + 1;
  61:     specCharStrTab = (char *) (specCharTab + device.spec_char_num);
  62: 
  63:     /* walk through the rest of the fonts */
  64:     ptr = specCharStrTab + device.spec_name_len;
  65:     for (fontno = 1; fontno <= device.num_fonts; fontno++)
  66:     {
  67:         fontPtr[fontno] = (struct font_entry *) ptr;
  68:         entries = (unsigned char)(*ptr) & 255;  /* get width entries */
  69:         if (specFontPos == 0 && fontPtr[fontno]->special_flag == 1)
  70:             specFontPos = fontno;   /* position of 1st special font */
  71:         ptr += sizeof(struct font_entry);   /* that's what's on the beginning */
  72:         charWidthTab[fontno] = (unsigned char *) ptr;
  73:         /* ignore kerning info */
  74:         ptr += entries * 2;
  75:         charCodeTab[fontno] =  ptr;
  76:         ptr += entries;
  77:         fontIndexTab[fontno] = (unsigned char *) ptr;
  78:         ptr += device.spec_char_num + 128 - 32;
  79:         setFontPosition(fontno, fontPtr[fontno]->font_name, fontPtr[fontno]->font_number);
  80:     }
  81:     fontPtr[0] = (struct font_entry *) malloc(3*255 + device.spec_char_num + (128-32) + sizeof (struct font_entry));
  82:     charWidthTab[0] = (unsigned char *) fontPtr[0] + sizeof (struct font_entry);
  83:     fontPtr[0]->num_char_wid = 255;
  84:     (void) close(devicefd);
  85: }
  86: 
  87: /*-----------------------------------------------------------------------------
  88:  *	loadFont	load the descriptor and tables for a font into position
  89:  *			n in the font table
  90:  *---------------------------------------------------------------------------*/
  91: loadFont(fontno, fname)
  92: int fontno;
  93: char *fname;
  94: {
  95:     int fontsfd, entries;
  96:     int num_widths;
  97:     char fontfilename[60];
  98: 
  99:     if (fontno < 0 || fontno > MAX_NUM_FONTS)
 100:         reportError(QUIT, "load fail for font %s, index out of bounds %d",fname,fontno);
 101:     if (strcmp(fname, fontPtr[fontno]->font_name) == 0) return; /* already loaded */
 102: 
 103:     (void) sprintf(fontfilename, "%s/dev%s/%s.out", fontdirectory, devicename, fname);
 104:     if ((fontsfd = open(fontfilename,O_RDONLY,0)) < 0)
 105:         reportError(QUIT, "can't open font file %s (%s)",fontfilename, sys_errlist[errno]);
 106:     /* record the current length of this font table */
 107:     entries = (unsigned char)(fontPtr[fontno]->num_char_wid) & 255;
 108: 
 109:     /* read in the new font */
 110:     (void) read(fontsfd, fontPtr[fontno], 3*entries + device.spec_char_num+128-32 + sizeof(struct font_entry));
 111:     (void) close(fontsfd);
 112: 
 113:     if (((unsigned char)(fontPtr[fontno]->num_char_wid) & 255) > entries)
 114:         reportError(QUIT, "Font %s too big for position %d\n", fname, fontno);
 115: 
 116:     num_widths = (unsigned char)(fontPtr[fontno]->num_char_wid) & 255; /* width of new font tables */
 117:     charWidthTab[fontno] = (unsigned char *) fontPtr[fontno] + sizeof(struct font_entry);
 118:     charCodeTab[fontno] = (char *) charWidthTab[fontno] + 2 * num_widths;
 119:     fontIndexTab[fontno] = (unsigned char *) charWidthTab[fontno] + 3 * num_widths;
 120: 
 121:     setFontPosition(fontno, fontPtr[fontno]->font_name, fontPtr[fontno]->font_number);
 122: 
 123:     /* restore to old value to allow use of the maximum space later */
 124:     fontPtr[fontno]->num_char_wid = entries;
 125: }
 126: 
 127: 
 128: /*-----------------------------------------------------------------------------
 129:  *	setFontPosition		set up a font with troff name *name in the
 130:  *				position given by index of the current fonts
 131:  *				table
 132:  *---------------------------------------------------------------------------*/
 133: setFontPosition(index, name, iname)
 134: int index;          /* index into fontPtr */
 135: char *name;         /* troff name */
 136: char *iname;            /* internal name */
 137: 
 138: {
 139:     int  cnt;
 140:     char **trp;
 141:     register struct ifont *ifp;
 142: 
 143:     if (dbg) printf("setFontPosition(%d, %s, %s)\n", index, name, iname);
 144: 
 145:     /* do nothing if it is the same font */
 146:     if (currfonts[index] != NULL  && strcmp(name, currfonts[index]->name) == 0)
 147:     {
 148:     if (dbg) printf("trivial case -- no action taken\n");
 149:     return;
 150:     }
 151: 
 152:     /* place any old and used font on the inactive list if not already there */
 153:     ifp = currfonts[index];
 154:     if (ifp != NULL && ifp->frames != NULL && ifp->next == NULL)
 155:     {
 156:     if (dbg) printf("placing old font (%s) on inactive list\n", ifp->name);
 157:     ifp->next = inactfonts;
 158:     inactfonts = ifp;
 159:     }
 160: 
 161:     /* try to find the new font on the inactive list */
 162:     if (dbg) printf("checking inactive list: ");
 163:     for (ifp = inactfonts; ifp != NULL; ifp = ifp->next)
 164:     {
 165:     if (dbg) printf("%s  ", ifp->name);
 166:     if (strcmp(ifp->name, name) == 0)
 167:         break;
 168:     }
 169: 
 170:     if (ifp != NULL)
 171:     {
 172:     if (dbg) printf("\ngot it!\n");
 173:     /* it was on the inactive list -- pull it back */
 174:     currfonts[index] = ifp;
 175:     }
 176:     else
 177:     {
 178:     /* brand new font */
 179:     if (dbg) printf("\nnot there ... making new font\ninterpress equiv: ");
 180:     currfonts[index] = ifp = (struct ifont *)malloc(sizeof(struct ifont));
 181:     strcpy(ifp->name, name);
 182:     ifp->frames = NULL;
 183:     ifp->extab  = NULL;
 184:     ifp->next   = NULL;
 185: 
 186:     /* map the troff name to an interpress name */
 187:     for (cnt = 0, trp = trname; cnt < mapcnt; cnt++, trp++)
 188:     {
 189:         if (dbg) printf("%s  ", *trp);
 190:         if (strcmp(*trp, name) == 0)
 191:         break;
 192:     }
 193:     if (cnt == mapcnt)
 194:     {
 195:         reportError(CONTINUE, "no interpress equivalent for troff font %s",
 196:             name);
 197:         currfonts[index]->uname = ipname[0];        /* punt */
 198:     }
 199:     else
 200:     {
 201:         if (dbg) printf("\ngot it ... using %s\n", ipname[cnt]);
 202:         currfonts[index]->uname = ipname[cnt];
 203:     }
 204:     }
 205: }

Defined functions

loadFont defined in line 91; used 1 times
setFontPosition defined in line 133; used 2 times
Last modified: 1986-01-15
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1331
Valid CSS Valid XHTML 1.0 Strict