/* -*-C-*- dvije2.c */ /*-->dvije2 (adapted for HP LaserJet II from DVIJEP driver)*/ /**********************************************************************/ /******************************* dvije2 *******************************/ /**********************************************************************/ #include "dvihead.h" /*********************************************************************** ***********************************************************************/ /**********************************************************************/ /************************ Device Definitions ************************/ /**********************************************************************/ /* All output-device-specific definitions go here. This section must be changed when modifying a dvi driver for use on a new device */ #undef HPJETTWO #define HPJETTWO 1 /* conditional compilation flag */ #undef HPJETPLUS #define HPJETPLUS 1 /* but also treat the II like a Plus */ #define VERSION_NO "0.2" /* DVI driver version number */ #define DEVICE_ID "Hewlett-Packard LaserJet II laser printer" /* this string is printed at runtime */ #if OS_PCDOS #define OUTFILE_EXT ".je2" #endif #if OS_TOPS20 #define OUTFILE_EXT ".dvi-je2" #endif #if OS_UNIX #define OUTFILE_EXT ".je2" #endif #if OS_VAXVMS #define OUTFILE_EXT ".dvi-je2" #endif #define BYTE_SIZE 8 /* output file byte size */ #undef STDRES #define STDRES 1 /* to get standard font resolution */ #define MAXLINE 4096 /* maximum input file line size */ /* it is needed only in special() */ #define XDPI 300 /* horizontal dots/inch */ #define XPSIZE 9 /* horizontal paper size in inches */ #define XSIZE (((XDPI*XPSIZE+2*HOST_WORD_SIZE-1)/\ (2*HOST_WORD_SIZE))*(2*HOST_WORD_SIZE)) /* number of horizontal dots; */ /* MUST BE multiple of */ /* 2*HOST_WORD_SIZE */ #define YDPI 300 /* vertical dots/inch */ #define YPSIZE 12 /* vertical paper size in inches */ #define YSIZE (YDPI*YPSIZE) /* number of vertical dots */ #define XORIGIN 30 /* measured pixel coordinates of */ #define YORIGIN -15 /* page origin (should be at (0,0) */ #define FONTNAMESIZE 16 /* in downloaded font descriptor */ /*********************************************************************** Define some useful shorthand macros for all required LaserJet II commands. With the exception of the CREATEFONT and DOWNLOADCHAR macros, which require extra data, NO escape sequences appear anywhere else in the text. The LaserJet II allows coordinates in dots as well as the decipoints supported by the regular LaserJet. Dot coordinates are more convenient, so we use them exclusively. The LaserJet II puts the page origin in the upper- left corner, while we have it in the lower-left corner, so MOVEY adjusts the coordinate accordingly. With 7-bit fonts, only characters 33..127 are printable, and with 8-bit fonts, 33..127 and 160..255 are printable. Since TeX assumes characters 0..127 are available, we remap character numbers in 0..32 to 160..192 and use 8-bit fonts. The macros conceal the remapping. Whenever possible, escape sequences are combined and 0 parameters omitted, in order to compress the output. ***********************************************************************/ /* CREATEFONT must be followed by a 64-byte font header (see readfont) */ #define CREATEFONT (void)fprintf(plotfp,"\033\051s64W") #define DELETEALLFONTS OUTS("\033*cF") #define DELETEFONT(fontnumber) (void)fprintf(plotfp,"\033*c%dd2F",fontnumber) /* DOWNLOADCHAR is not a complete specification---it must be followed by two-byte values of xoff, yoff, width, height, deltax */ #define DOWNLOADCHAR(nbytes) (void)fprintf(plotfp,"\033\050s%dW",(nbytes)+16) /* Map characters (0..32,33..127) to (160..192,33..127) */ #define MAPCHAR(c) (((c) > 32) ? (c) : ((c) + 160)) /* Move absolute to (x,y), page origin in lower left corner */ #define MOVETO(x,y) (void)fprintf(plotfp,"\033*p%dx%dY",(x),YSIZE-(y)) /* Move absolute to (x,current y), page origin in lower left corner */ #define MOVEX(x) (void)fprintf(plotfp,"\033*p%dX",(x)) /* Move absolute to (current x,y), page origin in lower left corner */ #define MOVEY(y) (void)fprintf(plotfp,"\033*p%dY",YSIZE-(y)) /* Output TeX character number with mapping to HP LaserJet II number */ #define OUTCHAR(c) OUTC(MAPCHAR(c)) /* Output a 16-bit binary number in two bytes */ #define OUT16(n) {OUTC((n)>>8); OUTC((n));} /* Eject a page from the printer--this is the last command on each page */ #define PAGEEJECT OUTC('\f') /* Pop current point (push with PUSHCP) */ #define POPCP OUTS("\033&f1S") /* Push current point (pop with POPCP) */ #define PUSHCP OUTS("\033&fS") /* Reset printer at job start. E is global reset which clears everything but permanent fonts, which we do not use. &l0E resets left margin to 0. &a0L resets top margin to 0. Without these, default margins are supplied which lie inside page. Unfortunately, these do not permit negative values, so we have to further correct the origin with (XORIGIN, YORIGIN) defined above; these bias (lmargin, tmargin) set in dviinit(). */ #define RESETPRINTER OUTS("\033E\033&lE\033&aL") /* Move relative by (delx,dely) from current point */ #define RMOVETO(delx,dely) {\ if ((delx) == 0)\ RMOVEY(dely)\ else if ((dely) == 0)\ RMOVEX(delx)\ else\ (void)fprintf(plotfp,"\033*p%c%dx%c%dY",\ ((delx) > 0 ? '+' : '-'),ABS(delx),\ ((dely) < 0 ? '+' : '-'),ABS(dely));\ } /* Move relative to (delx+currentx,currenty), page origin in lower left corner */ #define RMOVEX(delx) {\ if ((delx) > 0)\ (void)fprintf(plotfp,"\033*p+%dX",(delx));\ else if ((delx) < 0)\ (void)fprintf(plotfp,"\033*p%dX",(delx));\ } /* Move relative to (currentx,dely+currenty), page origin in lower left corner */ #define RMOVEY(dely) {\ if ((dely) > 0)\ (void)fprintf(plotfp,"\033*p%dY",-(dely));\ else if ((dely) < 0)\ (void)fprintf(plotfp,"\033*p+%dY",-(dely));\ } /* Round a POSITIVE floating-point value to the nearest integer */ #define ROUND(x) ((int)(x + 0.5)) /* Output a new rule at TeX position (x,y). The device coordinates will be changed on completion. The rule origin is the TeX convention of the lower-left corner, while the LaserJet II uses the upper-left corner. */ #define RULE(x,y,width,height) {\ MOVETO(x,(y)+height);\ (void)fprintf(plotfp,"\033*c%da%dbP",width,height);\ } /* Set rule of same size as previous one at TeX position (x,y). The device coordinates will be changed on completion. */ #define RULE2(x,y) {\ MOVETO(x,(y)+rule_height);\ OUTS("\033*cP");\ } /* Set the current font and character in preparation for a DOWNLOADCHAR */ #define SETCHARCODE(fontnumber,ch) {\ if (fontnumber)\ (void)fprintf(plotfp,"\033*c%dd%dE",fontnumber,MAPCHAR(ch));\ else\ (void)fprintf(plotfp,"\033*cd%dE",MAPCHAR(ch));\ } /* Set the number of copies of the current page (issue just before PAGEEJECT) */ #define SETCOPIES(n) (void)fprintf(plotfp,"\033&l%dX",MAX(1,MIN(n,99))) /* Set the font number in preparation for a CREATEFONT */ #define SETFONTID(fontnumber) (void)fprintf(plotfp,"\033*c%dd4F",(fontnumber)); /* Set the current font number */ #define SETCURRENTFONT(fontnumber) {\ if (fontnumber)\ (void)fprintf(plotfp,"\033\050%dX",(fontnumber));\ else\ OUTS("\033\050X");\ } #include "main.h" #include "abortrun.h" #include "actfact.h" #include "alldone.h" #include "chargf.h" #include "charpk.h" #include "charpxl.h" #include "clrrow.h" /*-->devinit*/ /**********************************************************************/ /****************************** devinit *******************************/ /**********************************************************************/ void devinit(argc,argv) /* initialize device */ int argc; char *argv[]; { RESETPRINTER; /* printer reset */ DELETEALLFONTS; /* delete all downloaded fonts */ font_count = 0; /* no font numbers are assigned yet */ font_switched = TRUE; } /*-->devterm*/ /**********************************************************************/ /****************************** devterm *******************************/ /**********************************************************************/ void devterm() /* terminate device */ { DELETEALLFONTS; /* delete all downloaded fonts */ RESETPRINTER; /* printer reset */ } #include "dvifile.h" #include "dviinit.h" #include "dviterm.h" #if PCC_20 #include "f20open.h" #endif #include "fatal.h" /*-->fillrect*/ /**********************************************************************/ /****************************** fillrect ******************************/ /**********************************************************************/ void fillrect(x,y,width,height) COORDINATE x,y,width,height; /* lower left corner, size */ /*********************************************************************** With the page origin (0,0) at the lower-left corner, draw a filled rectangle at (x,y). For most TeX uses, rules are uncommon, and little optimization is possible. However, for the LaTeX Bezier option, curves are simulated by many small rules (typically 2 x 2) separated by positioning commands. By remembering the size of the last rule set, we can test for the occurrence of repeated rules of the same size, and reduce the output by omitting the rule sizes. The last rule parameters are reset by the begin-page action in prtpage(), so they do not carry across pages. It is not possible to use relative, instead of absolute, moves in these sequences, without stacking rules for the whole page, because each rule is separated in the DVI file by push, pop, and positioning commands, making for an uncertain correspondence between internal (xcp,ycp) pixel page coordinates and external device coordinates. The last string y coordinate, str_ycp, must be reset here to force any later setstring() to reissue new absolute positioning commands. ***********************************************************************/ { str_ycp = -1; /* invalidate string y coordinate */ if ((height != rule_height) || (width != rule_width)) { RULE(x,y,width,height); rule_width = width; /* save current rule parameters */ rule_height = height; } else /* same size rule again */ RULE2(x,y); } #include "findpost.h" #include "fixpos.h" #include "fontfile.h" #include "fontsub.h" #include "getbytes.h" #include "getfntdf.h" #include "getpgtab.h" #include "inch.h" #include "initglob.h" /*-->loadchar*/ /**********************************************************************/ /****************************** loadchar ******************************/ /**********************************************************************/ void loadchar(c) register BYTE c; { void (*charyy)(); /* subterfuge to get around PCC-20 bug */ register struct char_entry *tcharptr; /* temporary char_entry pointer */ COORDINATE nbytes; /* number of bytes per row */ if ((c < FIRSTPXLCHAR) || (LASTPXLCHAR < c)) /* check character range */ return; tcharptr = &(fontptr->ch[c]); if (!VISIBLE(tcharptr)) return; /* do nothing for invisible fonts */ if (fontptr != pfontptr) openfont(fontptr->n); if (fontfp == (FILE *)NULL) /* do nothing if no font file */ return; (void)clearerr(plotfp); tcharptr->isloaded = TRUE; SETCHARCODE(fontptr->font_number,c); /* Number of bytes in bitmap, possibly reduced because of LaserJet II */ /* limits. Large characters really need to be handled as bitmaps */ /* instead of as downloaded characters. */ nbytes = ((tcharptr->wp) + 7) >> 3; /* wp div 8 */ DOWNLOADCHAR(MIN(16,nbytes)*MIN(255,(tcharptr->hp))); /* 4 0 14 1 is fixed sequence */ OUTC(4); /* format of char descriptor = 4 (always) */ OUTC(0); /* continuation = 0 ==> no */ OUTC(14); /* descriptor size = 14 (always) */ OUTC(1); /* format of char data = 1 (always) */ OUTC(0); /* orientation = 0 ==> portrait */ OUTC(0); /* (reserved byte) */ OUT16(MAX(-4200,MIN(-(tcharptr->xoffp),4200))); /* left offset */ OUT16(MAX(-4200,MIN(tcharptr->yoffp,4200))); /* top offset */ OUT16(MIN(4200,tcharptr->wp)); /* character width*/ OUT16(MIN(4200,tcharptr->hp)); /* character height*/ OUT16(ROUND(4.0*(tcharptr->tfmw)*conv)); /* delta x to nearest */ /* 1/4 dot */ /* Bug fix: PCC-20 otherwise jumps to charxx instead of *charxx */ charyy = fontptr->charxx; (void)(*charyy)(c,outrow); /* output rasters */ if (DISKFULL(plotfp)) (void)fatal("loadchar(): Output error -- disk storage probably full"); } #include "movedown.h" #include "moveover.h" #include "moveto.h" /*-->newfont*/ /**********************************************************************/ /****************************** newfont *******************************/ /**********************************************************************/ void newfont() { struct font_entry *tfontptr;/* temporary font_entry pointer */ register BYTE the_char; /* loop index */ INT16 j; /* loop index */ /* parameters of largest cell */ COORDINATE cell_above; /* dots above baseline */ COORDINATE cell_below; /* dots below baseline */ COORDINATE cell_height; /* total height */ COORDINATE cell_left; /* dots left of character cell */ COORDINATE cell_width; /* total width */ COORDINATE cell_baseline; /* in 0..(cell_height-1) */ /******************************************************************* Each LaserJet II font must be assigned a unique number in 0..32767, and only 32 fonts can be active at one time. We keep a table of font pointers for this purpose and store the corresponding table index in font_number. Each time a new font is encountered, we increment font_count and store it in that fonts font_number. TeX produces a unique font number as well, and TeX82 only uses values in the range 0..255. The DVI file supports 32-bit font numbers, so it is better to generate our own, because someday other programs may produce DVI files too. If fonts are freed dynamically, the table entry must be invalidated and a command sent to the printer to delete that font. At present, font freeing happens only in dviterm() at the close of processing of a single DVI file. A subsequent DVI file processed will result in the invocation of devinit() which resets font_count to 0. In order to deal with the limit of 32 active fonts in the LaserJet II, we have two choices. The first and best and most difficult, is to entirely discard the matching of TeX fonts with LaserJet II fonts---new characters would simply be assigned to the next available entry in the current open font. The second choice is less satisfactory---when 32 fonts have been downloaded, we delete the last 16 of them and reset the isloaded flags for all of them. As a guide to how bad this is, we issue a warning message when it happens. An intermediate solution would be to use the character reference counts to find the least-used fonts and delete them. The II also allows deletion of individual characters, so in the first case, we could delete little-used characters to make room in the font tables on the device. <------wp------> ^ ................ | ................ | ................ | ................ | ................ | ................ | ................ hp ................ | ................ | ................ | ................ | .....o.......... <-- character reference point (xcp,ycp) at "o" | ................ ^ | ................ | | ................ |--- (hp - yoffp - 1) | ................ | v +............... v <-- (xcorner,ycorner) at "+" <---> | | xoffp (negative if (xcp,ycp) left of bitmap) The LaserJet II font mechanism requires the declaration of cell height, width, and baseline in the CreateFont command. Experiments show that these must be large enough to incorporate the maximum extent above and below the baseline of any characters in the font. The metric correspondences are as follows: ----- ------------- TeX LaserJet II ----- ------------- xoffp -(left offset) yoffp top offset max(yoffp) + 1 cell baseline max(wp) cell width max(yoffp) + max(hp-yoff,yoff-hp) + 1 cell height *******************************************************************/ for (the_char = FIRSTPXLCHAR; the_char <= LASTPXLCHAR; the_char++) fontptr->ch[the_char].isloaded = FALSE; if (font_count >= MAXFONTS) /* then 32n fonts have been downloaded */ { (void)warning( "newfont(): HP LaserJet II active font storage exceeded.\n\ ---Last 16 downloaded fonts will be deleted, then reloaded on demand.\n\ ---Reprinting of current page may be necessary."); for (j = (INT16)(MAXFONTS>>1); j < (INT16)font_count; ++j) { tfontptr = font_table[j]; DELETEFONT(tfontptr->font_number); for (the_char = 0; the_char < NPXLCHARS; ++the_char) tfontptr->ch[the_char].isloaded = FALSE; font_table[j] = (struct font_entry *)NULL; } font_count = (UNSIGN16)(MAXFONTS>>1); } for (j = 0; j < (INT16)font_count; ++j) if (font_table[j] == fontptr) /* then font already known */ break; if (j >= (INT16)font_count) /* new font */ { fontptr->font_number = font_count; font_table[font_count++] = fontptr; cell_above = 0; cell_baseline = 0; cell_below = 0; cell_height = 0; cell_left = 0; cell_width = 0; for (the_char = FIRSTPXLCHAR; the_char <= LASTPXLCHAR; ++the_char) { cell_above = MAX(cell_above,fontptr->ch[the_char].yoffp); cell_below = MAX(cell_below, ABS(fontptr->ch[the_char].yoffp - fontptr->ch[the_char].hp)); cell_left = MAX(cell_left,-fontptr->ch[the_char].xoffp); cell_width = MAX(cell_width,fontptr->ch[the_char].wp); } cell_baseline = cell_above + 1; cell_height = cell_above + cell_below + 1; if ((cell_width > 4200) || (cell_height > 4200)) { (void)sprintf(message, "newfont(): Some characters in font [%s] exceed\n\ ---HP LaserJet II limit of 4200-dot cell size.\n\ ---Some characters may be truncated or lost",fontptr->name); (void)warning(message); cell_height = MIN(cell_height,4200); cell_width = MIN(cell_width,4200); } if (!IN(-4200,cell_left,4200) || !IN(-4200,cell_above,4200)) { (void)sprintf(message, "newfont(): Some characters in font [%s] exceed\n\ ---HP LaserJet II range of -4200..+4200 for left or top offset.\n\ ---Some characters may be truncated or lost",fontptr->name); (void)warning(message); } if (!IN(0,cell_width,4200)) { (void)sprintf(message, "newfont(): Some characters in font [%s] exceed\n\ ---HP LaserJet II limit of 4200-dot width.\n\ ---Some characters may be truncated or lost",fontptr->name); (void)warning(message); cell_width = MIN(cell_width,4200); } SETFONTID(fontptr->font_number); CREATEFONT; OUTC(0); OUTC(64); /* descriptor length */ /* ignored by LJ II, BUT >>should be 64<< */ OUTC(0); /* reserved */ OUTC(1); /* 8-bit font (for more than 95 characters) */ OUT16(0); /* reserved */ OUT16(cell_baseline); /* baseline position (in 0..cell_height-1))*/ OUT16(cell_width); /* cell width, dots (range 1..4200) */ OUT16(cell_height); /* cell height, dots (range 1..4200) */ OUTC(0); /* orientation = 0 ==> portrait */ OUTC(1); /* spacing = 1 ==> proportional */ OUT16(0); /* symbol set (arbitrary) */ OUT16(2); /* pitch, 1/4-dots (arbitrary in 0..16800) */ OUT16(cell_height); /* font height, 1/4-dots (range 0..10922) */ OUT16(0); /* xHeight, 1/4-dots (ignored by LJ II) */ OUTC(0); /* width type = 0 => normal (ignored) */ OUTC(0); /* style = 0 ==> upright */ OUTC(0); /* stroke weight = 0 ==> normal */ OUTC(0); /* typeface = 0 (lineprinter) */ OUTC(0); /* reserved */ OUTC(0); /* serif style = 0 => sans square (ignored) */ OUT16(0); /* reserved */ OUTC(0); /* underline distance, dots = 0 => baseline */ OUTC(0); /* underline height, dots (ignored) */ OUT16(0); /* text height, 1/4-dots (ignored) */ OUT16(0); /* text width, 1/4-dots (ignored) */ OUT16(0); /* reserved */ OUT16(0); /* reserved */ OUTC(0); /* pitch_extended, 1024ths-dot */ OUTC(0); /* height_extended, 1024ths-dot */ OUT16(0); /* reserved */ OUT16(0); /* reserved */ OUT16(0); /* reserved */ for (j=0; j < FONTNAMESIZE; j++) /* name of soft font */ OUTC(' '); } } #include "nosignex.h" #include "openfont.h" #include "option.h" /*-->outrow*/ /**********************************************************************/ /******************************* outrow *******************************/ /**********************************************************************/ void outrow(c,yoff) /* copy img_row[] into rasters[] if allocated, else no-op */ BYTE c; /* current character value */ UNSIGN16 yoff; /* offset from top row (0,1,...,hp-1) */ { UNSIGN16 bytes_per_row; /* number of raster bytes to copy */ register UNSIGN16 k; /* loop index */ register UNSIGN32 *p; /* pointer into img_row[] */ struct char_entry *tcharptr;/* temporary char_entry pointer */ register BYTE the_byte; /* unpacked raster byte */ if (yoff > 4200) /* LaserJet II cannot handle big characters */ return; tcharptr = &(fontptr->ch[c]);/* assume check for valid c has been done */ bytes_per_row = (UNSIGN16)((tcharptr->wp) + 7) >> 3; /* wp div 8 */ bytes_per_row = MIN(16,bytes_per_row); /* limited to 128 bits/row */ p = img_row; /* we step pointer p along img_row[] */ for (k = bytes_per_row; k > 0; ++p) { the_byte = (BYTE)((*p) >> 24); OUTC(the_byte); if ((--k) <= 0) break; the_byte = (BYTE)((*p) >> 16); OUTC(the_byte); if ((--k) <= 0) break; the_byte = (BYTE)((*p) >> 8); OUTC(the_byte); if ((--k) <= 0) break; the_byte = (BYTE)(*p); OUTC(the_byte); if ((--k) <= 0) break; } } #include "prtpage.h" #include "readfont.h" #include "readgf.h" #include "readpk.h" #include "readpost.h" #include "readpxl.h" #include "rulepxl.h" /*-->setchar*/ /**********************************************************************/ /****************************** setchar *******************************/ /**********************************************************************/ void setchar(c, update_h) register BYTE c; register BOOLEAN update_h; { register struct char_entry *tcharptr; /* temporary char_entry pointer */ /* BIGCHAR() and ONPAGE() are used here and in setstr() */ #define BIGCHAR(t) ((t->wp > (COORDINATE)size_limit) ||\ (t->hp > (COORDINATE)size_limit)) #define ONPAGE(t) (((hh - t->xoffp + t->pxlw) <= XSIZE) \ && (hh >= 0)\ && (vv <= YSIZE)\ && (vv >= 0)) tcharptr = &(fontptr->ch[c]); moveto(hh,YSIZE-vv); if (ONPAGE(tcharptr)) { /* character fits entirely on page */ if (font_switched) { SETCURRENTFONT(fontptr->font_number); font_switched = FALSE; } if (VISIBLE(tcharptr)) { if (BIGCHAR(tcharptr)) { /* we need to send a graphics bitmap at this point */ (void)warning( "newfont(): No code implemented yet for big characters"); } else { if (!tcharptr->isloaded) loadchar(c); if (ycp != str_ycp) { MOVETO(xcp,ycp); str_ycp = ycp; } else MOVEX(xcp); OUTCHAR(c); } } } else if ((debug_code & 32) && !quiet) { /* character is off page -- discard it */ (void)fprintf(stderr, "setchar(): Char %c [10#%3d 8#%03o 16#%02x] off page.", isprint(c) ? c : '?',c,c,c); NEWLINE(stderr); } if (update_h) { h += (INT32)tcharptr->tfmw; hh += (COORDINATE)tcharptr->pxlw; hh = fixpos(hh-lmargin,h,conv) + lmargin; } } #include "setfntnm.h" #include "setrule.h" /*-->setstr*/ /**********************************************************************/ /******************************* setstr *******************************/ /**********************************************************************/ void setstr(c) register BYTE c; { register struct char_entry *tcharptr; /* temporary char_entry pointer */ register BOOLEAN inside; INT32 h0,v0; /* (h,v) at entry */ COORDINATE hh0,vv0; /* (hh,vv) at entry */ COORDINATE hh_last; /* hh before call to fixpos() */ register UNSIGN16 k; /* loop index */ UNSIGN16 nstr; /* number of characters in str[] */ BYTE str[MAXSTR+1]; /* string accumulator */ BOOLEAN truncated; /* off-page string truncation flag */ /******************************************************************* Set a sequence of characters in SETC_000 .. SETC_127 with a minimal number of LaserJet II commands. These sequences tend to occur in long clumps in a DVI file, and setting them together whenever possible substantially decreases the overhead and the size of the output file. A sequence can be set as a single string if * TeX and LaserJet II coordinates of each character agree (may not be true, since device coordinates are in multiples of 1/4 pixel; violation of this requirement can be detected if fixpos() changes hh, or if ycp != str_ycp), AND * each character is in the same font (this will always be true in a sequence from a DVI file), AND * each character fits within the page boundaries, AND * each character definition is already loaded, AND * each character is from a visible font, AND * each character bitmap extent is smaller than the size_limit (which is used to enable discarding large characters after each use in order to conserve virtual memory storage on the output device). Whenever any of these conditions does not hold, any string already output is terminated, and a new one begun. Two output optimizations are implemented here. First, up to MAXSTR (in practice more than enough) characters are collected in str[], and any that require downloading are handled. Then the entire string is set at once, subject to the above limitations. Second, by recording the vertical page coordinate, ycp, in the global variable str_ycp (reset in prtpage() at begin-page processing), it is possible to avoid outputting y coordinates unnecessarily, since a single line of text will generally result in many calls to this function. *******************************************************************/ #define BEGINSTRING {inside = TRUE;\ if (ycp != str_ycp)\ {\ MOVETO(xcp,ycp);\ str_ycp = ycp;\ }\ else\ MOVEX(xcp);} #define ENDSTRING {inside = FALSE;} #define OFF_PAGE (-1) /* off-page coordinate value */ if (font_switched) /* output new font selection */ { SETCURRENTFONT(fontptr->font_number); font_switched = FALSE; } inside = FALSE; truncated = FALSE; hh0 = hh; vv0 = vv; h0 = h; v0 = v; nstr = 0; while ((SETC_000 <= c) && (c <= SETC_127) && (nstr < MAXSTR)) { /* loop over character sequence */ tcharptr = &(fontptr->ch[c]); moveto(hh,YSIZE-vv); if (ONPAGE(tcharptr) && VISIBLE(tcharptr)) { /* character fits entirely on page and is visible */ if ((!tcharptr->isloaded) && (!BIGCHAR(tcharptr))) loadchar(c); } /* update horizontal positions in TFM and pixel units */ h += (INT32)tcharptr->tfmw; hh += (COORDINATE)tcharptr->pxlw; str[nstr++] = c; /* save string character */ c = (BYTE)nosignex(dvifp,(BYTE)1); } /* put back character which terminated the loop */ (void)UNGETC((int)(c),dvifp); hh = hh0; /* restore coordinates at entry */ vv = vv0; h = h0; v = v0; for (k = 0; k < nstr; ++k) { /* loop over character sequence */ c = str[k]; tcharptr = &(fontptr->ch[c]); moveto(hh,YSIZE-vv); if (ONPAGE(tcharptr) && VISIBLE(tcharptr)) { /* character fits entirely on page and is visible */ if (tcharptr->isloaded) /* character already downloaded */ { if (!inside) BEGINSTRING; OUTCHAR(c); } else /* character must be downloaded first */ { if (inside) ENDSTRING; /* finish any open string */ if (BIGCHAR(tcharptr)) { /* Large character to be discarded. */ /* we need to send a graphics bitmap at this point */ (void)warning( "setstr(): No code implemented yet for big characters"); str_ycp = OFF_PAGE; tcharptr->isloaded = FALSE; } } } else /* character does not fit on page -- output */ { /* current string and discard the character */ truncated = TRUE; if (inside) ENDSTRING; } /* update horizontal positions in TFM and pixel units */ h += (INT32)tcharptr->tfmw; hh += (COORDINATE)tcharptr->pxlw; hh_last = hh; hh = fixpos(hh-lmargin,h,conv) + lmargin; if (debug_code & 4) { (void)fprintf(stderr, "[%03o] xcp = %d\tycp = %d\thh = %d\thh_last = %d\n", c,xcp,ycp,hh,hh_last); } /* If fixpos() changed position, we need new string next time */ /* around. Actually, since the LaserJet II stores character */ /* widths in units of 1/4 dot, we could compute coordinates at */ /* four times the precision, but for now, we start a new string */ /* each time we have one or more dots of error. */ if ((hh != hh_last) && inside) ENDSTRING; } if (truncated && (debug_code & 32) && !quiet) { (void)fprintf(stderr,"setstr(): Text ["); for (k = 0; k < nstr; ++k) (void)fprintf(stderr,isprint(str[k]) ? "%c" : "\\%03o",str[k]); (void)fprintf(stderr,"] truncated at page boundaries."); NEWLINE(stderr); } if (inside) /* finish last string */ ENDSTRING; } #include "signex.h" #include "skgfspec.h" #include "skipfont.h" #include "skpkspec.h" #include "special.h" #include "strchr.h" #include "strcm2.h" #include "strid2.h" #include "strrchr.h" #include "tctos.h" #include "usage.h" #include "warning.h" /* -------------------------- End of DVIJE2 -------------------------- */