diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /dviware/dvi2pcl |
Initial commit
Diffstat (limited to 'dviware/dvi2pcl')
62 files changed, 6178 insertions, 0 deletions
diff --git a/dviware/dvi2pcl/Makefile b/dviware/dvi2pcl/Makefile new file mode 100644 index 0000000000..6c375aa673 --- /dev/null +++ b/dviware/dvi2pcl/Makefile @@ -0,0 +1,176 @@ +#$Log: Makefile,v $ +# Revision 0.8 92/11/23 19:48:02 19:48:02 bt (Bo Thide') +# Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support +# +# Revision 0.7 92/11/13 02:43:26 02:43:26 bt (Bo Thide') +# More bug fixes and improvements. Support for PaintJet XL +# +# Revision 0.6 92/11/10 21:47:36 21:47:36 bt (Bo Thide') +# Bug fixes. Added -R option. Better font handling. +# +# Revision 0.5 92/11/09 16:25:10 16:25:10 bt (Bo Thide') +# Rewrite of dospecial.c. Extended \special support +# +# Revision 0.4 92/11/08 02:45:12 02:45:12 bt (Bo Thide') +# Changed to portable bit manipulations. Replaced strrstr for non-POSIX +# compliant C. Fixed numerous bugs. Added support for more \special's. +# +# Revision 0.3 92/08/24 12:43:17 12:43:17 bt (Bo Thide') +# Fixed 8 bit (dc font) support. +# + +CC = cc + +CCOPTS = +ESlit +OS +O3 + +CFLAGS = $(CCOPTS) -DTIMING #-DDEBUG #-DDEBUG2 -G + + +DEST = /usr/local/bin + +EDITOR = vi + +EXTHDRS = + +HDRS = dvi.h globals.h macros.h paths.h pcl.h pk.h + +INSTALL = cp + +LD = $(CC) + +LDFLAGS = -s +O3 -Wl,-a,archive + +LIBS = -lm + +MAKEFILE = Makefile + + +OBJS = betweenpages.o \ + cachefonts.o \ + checkfont.o \ + definefont.o \ + diagnostics.o \ + dim_to_dots.o \ + doallpages.o \ + doodevpages.o \ + dopage.o \ + dospecial.o \ + downloadchar.o \ + downloadfont.o \ + drawchar.o \ + drawrule.o \ + firstpar.o \ + getcount.o \ + getoptions.o \ + initialize.o \ + loadpkfile.o \ + loadtfmfile.o \ + main.o \ + makepkdir.o \ + openpkfile.o \ + opentfmfile.o \ + permfonts.o \ + pkcharinfo.o \ + pknum.o \ + pktopxl.o \ + postamble.o \ + preamble.o \ + prescanpage.o \ + printbop.o \ + printfont.o \ + rotatechar.o \ + rulepixels.o \ + scanbop.o \ + skipfontdef.o \ + skipnextpage.o \ + skippages.o \ + sortfonts.o \ + storechar.o \ + storefont.o + +PRINT = cpr + +PROGRAMS = dvi2pcl + +SRCS = betweenpages.c \ + cachefonts.c \ + checkfont.c \ + definefont.c \ + diagnostics.c \ + dim_to_dots.c \ + doallpages.c \ + doodevpages.c \ + dopage.c \ + dospecial.c \ + downloadchar.c \ + downloadfont.c \ + drawchar.c \ + drawrule.c \ + firstpar.c \ + getcount.c \ + getoptions.c \ + initialize.c \ + loadpkfile.c \ + loadtfmfile.c \ + main.c \ + makepkdir.c \ + openpkfile.c \ + opentfmfile.c \ + permfonts.c \ + pkcharinfo.c \ + pknum.c \ + pktopxl.c \ + postamble.c \ + preamble.c \ + prescanpage.c \ + printbop.c \ + printfont.c \ + rotatechar.c \ + rulepixels.c \ + scanbop.c \ + skipfontdef.c \ + skipnextpage.c \ + skippages.c \ + sortfonts.c \ + storechar.c \ + storefont.c + +SHELL = /bin/sh + +TAR = tar cvf /tmp/dvi2pcl_0.3.tar + +TEXLIB = /usr/local/lib/tex + +all: $(PROGRAMS) + +dvi2pcl: $(OBJS) + $(LD) $(OBJS) $(CFLAGS) $(LDFLAGS) $(LIBS) -o dvi2pcl + +clean:; @rm -f $(OBJS) $(PROGRAMS) core + +clobber:; @rm -f $(OBJS) $(PROGRAM) core tags + +depend:; @mkmf -f $(MAKEFILE) ROOT=$(ROOT) + +echo:; @echo $(HDRS) $(SRCS) + +edit:; @$(EDITOR) $(HDRS) $(SRCS) + +index:; @ctags -wx $(HDRS) $(SRCS) + +install: $(PROGRAMS) + @echo Installing $(PROGRAMS) in $(DEST) + @-strip $(PROGRAMS) + $(INSTALL) $(PROGRAMS) $(DEST) + cp reslj.fnt $(TEXLIB) + +print:; @$(PRINT) $(HDRS) $(SRCS) + +tar:; @$(TAR) Makefile README TODO $(HDRS) $(SRCS) tags + +tags: $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS) + +update: $(DEST)/$(PROGRAM) + +$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS) + @$(MAKE) -f $(MAKEFILE) ROOT=$(ROOT) DEST=$(DEST) install diff --git a/dviware/dvi2pcl/README b/dviware/dvi2pcl/README new file mode 100644 index 0000000000..9eb043ef5a --- /dev/null +++ b/dviware/dvi2pcl/README @@ -0,0 +1,92 @@ +$Log: README,v $ +# Revision 0.8 92/11/23 19:46:34 19:46:34 bt (Bo Thide') +# Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support +# +# Revision 0.7 92/11/13 02:41:14 02:41:14 bt (Bo Thide') +# More bug fixes and improvements. Support for PaintJet XL +# +# Revision 0.6 92/11/10 21:47:34 21:47:34 bt (Bo Thide') +# Bug fixes. Added -R option. Better font handling. +# +# Revision 0.5 92/11/09 16:25:21 16:25:21 bt (Bo Thide') +# Rewrite of dospecial.c. Extended \special support +# +# Revision 0.4 92/11/08 02:45:13 02:45:13 bt (Bo Thide') +# Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. +# +# Revision 0.3 92/08/24 12:45:21 12:45:21 bt (Bo Thide') +# Fixed 8 bit (dc font) support. +# +# Revision 0.2 92/08/23 17:28:52 17:28:52 bt (Bo Thide') +# Source cleaned up. Changed certain function calls. Removed globals. +# + +This driver, called 'dvi2pcl', is able to download fonts both +dynamically and permanently. There is a file called +'/usr/local/lib/tex/reslj.fnt' which contains information about which +fonts are permanently downloaded in the laser printer before 'dvi2pcl' +is used for the first time. + +The format of the font info file reslj.fnt is as follows: + +fontname size fontnumber orientation [ROM] +MEMORY freemem + +For example: + +cmr6 300 1 P +cmr8 300 2 P +cmr10 300 3 P +cmr11 300 4 P +cmr12 300 5 P +cmbx12 300 6 P +cmti10 300 7 P +cmti12 300 8 P +cmsy6 300 9 P +cmsy8 300 10 P +cmsy10 300 11 P +cmsy12 300 12 P +cmmi6 300 13 P +cmmi8 300 14 P +cmmi10 300 15 P +cmmi12 300 16 P +MEM 2367054 + +The above file would indicate that 'cmrs' at a size of 300 dpi is +downloaded permanently in the portrait modes with font ID number 1 in +the laser printer. + +If you plan not to use the pre-downloading feature (at this stage this is +strongly recommended!), change the 'reslj.fnt' file to the single line: + +MEM2560000 + +A copy of this file is included in this package. Move it to +/usr/local/lib/tex. Of course, the fonts that are not in ROM, yet +mentioned in the file, must be downloaded before any TeX jobs are run. +The pk_crereslj command will create a file called +'/usr/local/lib/tex/initlj.fnt' which contains the quick commands to +download the fonts mentioned in '.../reslj.fnt'. These programs must be +run every time the 'reslj.fnt' file is modified, and at installation. +The created 'initlj.fnt' file must be sent over the queue before any TeX +jobs, and again after every laser printer power cycle or crash. + +The files from which the font information is loaded are given in 'paths.h': + +#define fontpath "/usr/local/lib/tex/fonts/pk300" +#define tfmpath "/usr/local/lib/tex/fonts/tfm/" +#define defaultpk "/usr/local/lib/tex/fonts/pk300/10pt/cmr10.300pk" +#define defaulttfm "/usr/local/lib/tex/fonts/tfm/cmr10.tfm" +#define respath "/usr/local/lib/tex/reslj.fnt" +#define initpath "/usr/local/lib/tex/initlj.fnt" + +For more info, read the man page (dvi2pcl.1). + + Uppsala 8 November, 1992 + +--- + ^ Bo Thide'-------------------------------------------------------------- + |I| Swedish Institute of Space Physics, S-755 91 Uppsala, Sweden + |R| Phone: (+46) 18-303671. Fax: (+46) 18-403100. IP: 130.238.30.23 + /|F|\ INTERNET: bt@irfu.se UUCP: ...!mcvax!sunic!irfu!bt + ~~U~~ ----------------------------------------------------------------sm5dfw- diff --git a/dviware/dvi2pcl/TODO b/dviware/dvi2pcl/TODO new file mode 100644 index 0000000000..3ae6de25f8 --- /dev/null +++ b/dviware/dvi2pcl/TODO @@ -0,0 +1,120 @@ +$Log: TODO,v $ +# Revision 0.8 92/11/23 19:46:35 19:46:35 bt (Bo Thide') +# Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support +# +# Revision 0.7 92/11/13 02:41:15 02:41:15 bt (Bo Thide') +# More bug fixes and improvements. Support for PaintJet XL +# +# Revision 0.6 92/11/10 21:47:35 21:47:35 bt (Bo Thide') +# Bug fixes. Added -R option. Better font handling. +# +# Revision 0.4 92/11/08 02:45:37 02:45:37 bt (Bo Thide') +# Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. +# +# Revision 0.3 92/08/24 12:43:17 12:43:17 bt (Bo Thide') +# Fixed 8 bit (dc font) support. +# + + +3. Move all unnecessary global variables from 'globals.h'. Introduce + more clever .dvi and .pcl page data structures. + +Some of this has been fixed. The beta release will use structs. + + +5. Rewrite dopage() into something less hairy (and maybe faster?). + With the present coding technique (v.0.1) 'dvi2pcl' uses about 23 + ms per page on an HP9000/720. 'dvips' uses about 45 ms per page + and 'dvi' about 85 ms/page under the same conditions (identical + 100-page LaTeX document .dvi input file, no fonts preloaded)! + +Not done yet. + + +6. See if pktopxl() can be replaced by read_PK_char() from 'xdvi'. If + pknum() has to be used, try to improve it. + +A couple of non-obvious bugs were fixed but otherwise it's essentially +unchanged. + + +7. Add support for more '\special's, including HPGL/2 and pbm + graphics/rasters (including EPS by using pbmplus commands) and for + alternative '\special' syntax, taken from other dvi drivers. Maybe + use lex and yacc? + +The code has been rewritten and support for more \special's has been added. +Suggestions, please!! + + +8. Currently, 'dvi2pcl' supports PCL commands understood by LaserJet+. + According to the LaserJet+ Technical Reference Manual this is PCL4. + Add support for PCL3 and 5. See if .dvi commands can be mapped to + PCL macros (which might be preloaded). Try to implement compression + (see 'pclcomp'), also the adaptive compression, currently supported + only by LaserJetIIIP. Also, add support for PCL printers that + cannot(?) download fonts (low-end PaintJet and DeskJets). See if + drawchar() can be modifed to do this. PaintJet XL can handle + font downloading, but requires 180dpi fonts. Resample the 300dpi + fonts to 180dpi ones as is done in 'xdvi'. + +Partially done. Printing to PaintJet XL now works! However, the PJXL +does not have support for drawing solid rectangels (rules). Special +code has to be added for the PJXL case. + + +9. Add support for reading from an input pipe, if possible. The only + radical solution would be to rewrite 'virtex' so it puts the + postamble info up front. Use the nice and clean 'commontex' C code + for this--not the original web and web-to-C code. It's hopeless! + Then, shmem can be used for real fast processing! + +Has to wait until a later release. + + +10. Add support for virtual fonts as in 'xdvi'. See if it's possible to + utilize the PCL5 scalable fonts. + +Has to wait until a later release. + + +11. Change the starting page option '-s' to something more clever, + +Has to wait until a later release. + + +13. Try various mallopt's to speed up the malloc's. + +Has to wait until a later release. + + +14. Try better optimization on HP Snakes (feedback-directed positioning + -- 'ld -I' and 'ld -P' -- and cc #pragma's). + +Has to wait until a later release. + + + +16. Add a Motif GUI by using Wcl. + +Has to wait until a later release. Do people really want this? + + +17. Add support for alternative font paths. + +Not addressed yet. + + +18. Fix memory leaks (free malloc'ed data)! + +Partially fixed. + + +Uppsala, November 23, 1992 + + + ^ Bo Thide'-------------------------------------------------------------- + |I| Swedish Institute of Space Physics, S-755 91 Uppsala, Sweden + |R| Phone: (+46) 18-303671. Fax: (+46) 18-403100. IP: 130.238.30.23 + /|F|\ INTERNET: bt@irfu.se UUCP: ...!mcvax!sunic!irfu!bt + ~~U~~ ----------------------------------------------------------------sm5dfw- diff --git a/dviware/dvi2pcl/betweenpages.c b/dviware/dvi2pcl/betweenpages.c new file mode 100644 index 0000000000..846b384ded --- /dev/null +++ b/dviware/dvi2pcl/betweenpages.c @@ -0,0 +1,70 @@ +/* $Log: betweenpages.c,v $ + * Revision 0.8 92/11/23 19:46:36 19:46:36 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:20 02:41:20 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:37 21:47:37 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:23 16:25:23 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:38 02:45:38 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:32 12:45:32 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:54 17:28:54 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * Process the .dvi file between the occurrence of an 'eop' and the next 'bop' + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: betweenpages.c,v 0.8 92/11/23 19:46:36 bt Exp $"; + +extern void postamble(); +extern int valvalerror(); +extern void scanbop(); + +betweenpages(dvifile, prescan) +FILE *dvifile; +bool prescan; +{ + int k; + + do + { + k = (int)getubyte(dvifile); + if((k >= DVI_FNT_DEF1) && (k <=DVI_FNT_DEF4)) { + firstpar(dvifile, k); + skipfontdef(dvifile); + k = DVI_NOP; + } + } while(k == DVI_NOP); + + if(k == DVI_POST) { + inpostamble = TRUE; + if(prescan) + postamble(dvifile); + return(FALSE); + } + + if(k != DVI_BOP) + valvalerror("Bad .dvi file: byte %d is %d, not DVI_BOP\n", + ftell(dvifile) - 1 , k); + scanbop(dvifile); + return(TRUE); +} diff --git a/dviware/dvi2pcl/cachefonts.c b/dviware/dvi2pcl/cachefonts.c new file mode 100644 index 0000000000..930f3e73bc --- /dev/null +++ b/dviware/dvi2pcl/cachefonts.c @@ -0,0 +1,104 @@ +/* $Log: cachefonts.c,v $ + * Revision 0.8 92/11/23 19:46:37 19:46:37 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:21 02:41:21 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:37 21:47:37 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:24 16:25:24 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:39 02:45:39 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX + * compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:32 12:45:32 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:54 17:28:54 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * This is the procedure with caching font responsibility. On entrance to + * this procedure, all the font usage information will have been loaded into + * 'use_count' entries for each font. 'cachefonts' first checks which of the + * fonts, used in the .dvi file, are permanently downloaded by calling + * 'permfonts' which in turn returns the number of permanent downloaded fonts. + * The remaining fonts are ordered in 'fontlist' in respect to their usage by + * calling 'sortfonts' which in turn returns the number of remaining fonts + * used in the document. These fonts will be downloaded in order of their + * usage, those most heavily used comes first and with just the characters + * used from these fonts. The downloading process continues so long the + * printer's memory will allow more and the actual number of downloaded fonts + * doesn't exceed MAXDOWN. If there are fonts which can't be download + * anymore, their character's pixel patterns together with a small font and + * character overhead are stored dynamically in memory. + */ + +#include <stdio.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: cachefonts.c,v 0.8 92/11/23 19:46:37 bt Exp $"; + +void cachefonts(bitfile, resfile, maxdown, device) +FILE *bitfile; +FILE *resfile; +short maxdown; +short device; +{ + int f; + int n; + int actfontsdown; + int permfontsdown; + int fontnum; + int fontlist[MAXFONTS]; + + /* Find all permanent downloaded fonts for dvifile in progress */ + actfontsdown = permfontsdown = permfonts(resfile); + + /* Sort additional fonts in respect to their usage */ + fontnum = sortfonts(fontlist); + + /* Decide for downloading or storage of fonts and chars and do it */ + for(n = 0 ; n < fontnum ; n++) { + f = fontlist[n]; + font = fontptr[f]; + cbase = font->chr; + loadpkfile(); + makepkdir(); + convtfm = (double)font->scaled_size/(double)FIX ; + convpxl = (double)font->design_size/65536.0* + (double)font->dir_size/(double)SCALE; + +#ifdef DEBUG +fprintf(stderr,"cachefonts: font->scaled_size = %d\n", font->scaled_size); +fprintf(stderr,"cachefonts: font->design_size = %d\n", font->design_size); +fprintf(stderr,"cachefonts: font->dir_size = %d\n", font->dir_size); +fprintf(stderr,"cachefonts: convtfm = %g, convpxl = %g\n", convtfm, convpxl); +#endif /* DEBUG */ + + + if(actfontsdown >= maxdown || + (printer.mem-printermem_used) < MINPRINTERMEM) + storefont(bitfile, f); + else { + printermem_used += downloadfont(bitfile, + permfontsdown, device); + actfontsdown++; + } + + } + + if(landscape) + (void)fputs(PCL4_LANDSCAPE,bitfile); + if(manualfeed) + (void)fputs(PCL4_MANUAL_FEED,bitfile); +} diff --git a/dviware/dvi2pcl/checkfont.c b/dviware/dvi2pcl/checkfont.c new file mode 100644 index 0000000000..59f2f3d05e --- /dev/null +++ b/dviware/dvi2pcl/checkfont.c @@ -0,0 +1,80 @@ +/* $Log: checkfont.c,v $ + * Revision 0.8 92/11/23 19:46:37 19:46:37 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:21 02:41:21 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:38 21:47:38 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:24 16:25:24 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:40 02:45:40 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:33 12:45:33 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:54 17:28:54 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: checkfont.c,v 0.8 92/11/23 19:46:37 bt Exp $"; + +/* + * Check that all font definitions found in the postamble agree with all the + * font definitions found during prescan. For any disagreement a warning will + * be printed. Those fonts which are not detected during the prescan phase + * will be defined now + */ +checkfont(dvifile,f) +FILE *dvifile; +int f; +{ + int i; + int a, l; + fontfmt *font; + char *p; + char buffer[TERMLINELENGTH]; + + if(f >= MAXFONTS) + fprintf(stderr,"Warning: Only font definitions 0..255 are valid.\n"); + else if(!(font = fontptr[f])) + definefont(dvifile, f); + else + { + if(getsquad(dvifile) != font->checksum) + fprintf(stderr,"Warning: Pre-post disagreement in checksum for font # %d !\n",f); + if(getsquad(dvifile) != font->scaled_size) + fprintf(stderr,"Warning: Pre-post disagreement in scaled_size for font # %d !\n", + f); + if(getsquad(dvifile) != font->design_size) + fprintf(stderr,"Warning: Pre-post disagreement in design_size for font # %d !\n", + f); + a = (int)getubyte(dvifile); + l = (int)getubyte(dvifile); + for(i = 0; i < a ; i++) + buffer[i] = getubyte(dvifile); + buffer[a] = '\0'; + p = names + font->name; + if(strcmp(p,buffer)) + fprintf(stderr,"Warning: Pre-post disagreement in path_name for font # %d !\n", + f); + for(i = 0; i < l ; i++) + buffer[i] = getubyte(dvifile); + buffer[l] = '\0'; + p = names + font->name + a + 1; + if(strcmp(p,buffer)) + fprintf(stderr,"Warning: Pre-post disagreement in font_name for font # %d !\n", + f); + } +} diff --git a/dviware/dvi2pcl/definefont.c b/dviware/dvi2pcl/definefont.c new file mode 100644 index 0000000000..b06d4a4239 --- /dev/null +++ b/dviware/dvi2pcl/definefont.c @@ -0,0 +1,109 @@ +/* $Log: definefont.c,v $ + * Revision 0.8 92/11/23 19:46:38 19:46:38 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:22 02:41:22 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:38 21:47:38 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:25 16:25:25 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:40 02:45:40 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:18 12:43:18 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * This subroutine does the necessary things when a 'FNT_DEF' command is + * being processed. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: definefont.c,v 0.8 92/11/23 19:46:38 bt Exp $"; + +void definefont(dvifile, f) +FILE *dvifile; +int f; +{ + static int knownsize[] = {1,90,130,150,180,210,240,270,300,329,360, + 394,432,473,518,568,622,681,746,818,896,981, + 1075,1178,1290,1413,1548,1858,2035,2229,2442, + 2675,10000}; + int k; + int a,l; /* Font definition parameters */ + fontfmt *safefont; + charfmt *u; + int *known; + int idealmag; + double s; + + if(!inpostamble) + { + if(f >= MAXFONTS) + valerror("Max number of allowed fonts is %3d\n", + MAXFONTS); + if(fontptr[f] != 0) + valerror("Font number %d already defined\n", f); + safefont = font; + font = (fontfmt *)malloc(sizeof(*font)); + fontptr[f] = font; + font->checksum = getsquad(dvifile); + font->scaled_size = getsquad(dvifile); + font->design_size = getsquad(dvifile); + a = (int)getubyte(dvifile); + l = (int)getubyte(dvifile); + if((nextnamesfree-names+a+l+2) > NAMESIZE) + valerror("Capacity exceeded (name size=%d)\n",NAMESIZE); + font->name = nextnamesfree - names; + if(verbose) + fprintf(stderr,"Font %d: ", f); + + for(k=0; k<a; k++) + *nextnamesfree++ = getubyte(dvifile); + *nextnamesfree++ = '\0'; + + for(k=0; k<l; k++) + *nextnamesfree++ = getubyte(dvifile); + *nextnamesfree++ = '\0'; + + u = font->chr; + for(k=0; k<=255; k++) { + u->use_count = 0; + u++; + } + + font->space = font->design_size / 6; + font->down = -3; + if(verbose) + printfont(); + idealmag = round((double)font->scaled_size/(double)font->design_size*magnification*RESOLUTION*0.001); + if((idealmag < 10) || (idealmag > 9999)) + valerror("Font dpi size %d unrealistic\n", idealmag); + known = knownsize; + while(*known < idealmag) known++; + if(((double) *known/idealmag) > ((double)idealmag/(*(known-1)))) + known--; + s = (double) *known/idealmag; + if((s > 1.02) || (s < 0.98)) + fprintf(stderr,"Warning: Size %d does not exist; substituting %d.\n", + idealmag, *known); + font->dir_size = *known; + font = safefont; + + } +} diff --git a/dviware/dvi2pcl/diagnostics.c b/dviware/dvi2pcl/diagnostics.c new file mode 100644 index 0000000000..454dc9159b --- /dev/null +++ b/dviware/dvi2pcl/diagnostics.c @@ -0,0 +1,74 @@ +/* $Log: diagnostics.c,v $ + * Revision 0.8 92/11/23 19:46:39 19:46:39 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:23 02:41:23 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:39 21:47:39 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:26 16:25:26 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:41 02:45:41 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:18 12:43:18 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" + +static char rcsid[] = "$Header: diagnostics.c,v 0.8 92/11/23 19:46:39 bt Exp $"; + +/* + * This procedure is included for debugging and monitoring purposes. It prints + * out memory usage if the debug option was chosen. It also creates a font + * usage file 'filname.usg' that contains the font->use_count table for each + * font, used in the document. + */ +void diagnostics(usgfile) +FILE *usgfile; +{ + int i,j; + int n; + char *p; + + fprintf(usgfile,"Font use count table:\n"); + n = 0; + for(i = 0 ; i < MAXFONTS ; i++) + if(font = fontptr[i]) { + n++; + p = names + font->name; + if(*p) + fprintf(usgfile,"%s:\n",p); + while(*p++); + fprintf(usgfile,"%s\n",p); + cbase = font->chr; + for(j = 0 ; j < 256 ; j++) + if((cbase+j)->use_count) + fprintf(usgfile,"%3d %ld\n", j, (cbase+j)->use_count); + } + fprintf(usgfile,"Number of pages processed: %d\n", actualpagecount); + fprintf(usgfile,"Name string pool usage: %d out of %d bytes\n", + nextnamesfree - names, NAMESIZE); + fprintf(usgfile,"Font description information: %d bytes\n" , 1564*n); + fprintf(usgfile,"Printer memory used for fonts: %ld out of %ld bytes\n", + printermem_used, printer.mem); + fclose(usgfile); + + fprintf(stderr,"Number of pages processed: %d\n", actualpagecount); + fprintf(stderr,"Name string pool usage: %d out of %d bytes\n", + nextnamesfree - names, NAMESIZE); + fprintf(stderr,"Font description information: %d bytes\n" , 1564*n); + fprintf(stderr,"Printer memory used for fonts: %ld out of %ld bytes\n", + printermem_used, printer.mem); +} diff --git a/dviware/dvi2pcl/dim_to_dots.c b/dviware/dvi2pcl/dim_to_dots.c new file mode 100644 index 0000000000..8fda24b1a9 --- /dev/null +++ b/dviware/dvi2pcl/dim_to_dots.c @@ -0,0 +1,74 @@ +/* $Log: dim_to_dots.c,v $ + * Revision 0.8 92/11/23 19:46:39 19:46:39 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:23 02:41:23 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:40 21:47:40 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:26 16:25:26 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:42 02:45:42 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:34 12:45:34 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: dim_to_dots.c,v 0.8 92/11/23 19:46:39 bt Exp $"; + +/* + * This routine converts a string which contains a floating number terminated + * by a dimension into the proper number of dots for resolution dots/inch. + */ +long dim_to_dots(data, resolution) +char *data; +short resolution; +{ + double val; + long ival; + char valstr[16]; + char dim; + char dimstr[4]; + + strcpy(valstr, data); + sscanf(valstr,"%lf %c",&val,&dim); + + switch(dim) + { + case 'i': + ival = round(resolution*val); + break; + case 'c': + ival = round((resolution*val)/2.54); + break; + case 'm': + ival = round((resolution*val)/25.4); + break; + case 'p': + ival = round((resolution*val)/72.27); + break; + case 'd': + ival = round(val); + break; + default: + sscanf(data,"%*f%3s",dimstr); + fprintf(stderr,"Unknown dimension '%3s' in options or \\special\n",dimstr); + ival = resolution; + break; + } + return(ival); +} diff --git a/dviware/dvi2pcl/doallpages.c b/dviware/dvi2pcl/doallpages.c new file mode 100644 index 0000000000..637edbf0f9 --- /dev/null +++ b/dviware/dvi2pcl/doallpages.c @@ -0,0 +1,69 @@ +/* $Log: doallpages.c,v $ + * Revision 0.8 92/11/23 19:46:40 19:46:40 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:24 02:41:24 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:40 21:47:40 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:27 16:25:27 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:42 02:45:42 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:35 12:45:35 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "macros.h" +#include "globals.h" + +static char rcsid[] = "$Header: doallpages.c,v 0.8 92/11/23 19:46:40 bt Exp $"; + +/* + * This routine processes all pages in the default 'single-sided' mode. + * Processing is done in reversal order from higher to lower page numbers. + * This way output to the old LaserJet+ will be in natural order. + * This behavior can be controlled via the 'reverse' flag. + */ +void doallpages(bitfile, dvifile, pcllevel, reverse, resolution, device) +FILE *bitfile; +FILE *dvifile; +short pcllevel; +bool reverse; +short resolution; +short device; +{ + long backpage; + + if(inpostamble) + backpage = lastpage + 1; + else + backpage = prevpage + 1; + maxpages = actualpagecount; + + if (!reverse) + fseek(dvifile, firstpage, 0); + + while(maxpages-- > 0) { + if (reverse) + fseek(dvifile, backpage , 0); + scanbop(dvifile); + backpage = prevpage + 1; + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, resolution, device); + if (!reverse) + getubyte(dvifile); + } + fprintf(stderr,"\n"); +} diff --git a/dviware/dvi2pcl/doodevpages.c b/dviware/dvi2pcl/doodevpages.c new file mode 100644 index 0000000000..240e0bb298 --- /dev/null +++ b/dviware/dvi2pcl/doodevpages.c @@ -0,0 +1,194 @@ +/* $Log: doodevpages.c,v $ + * Revision 0.8 92/11/23 19:46:40 19:46:40 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:24 02:41:24 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:41 21:47:41 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:27 16:25:27 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:43 02:45:43 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:35 12:45:35 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine processes all pages in the 'two-sided' mode. + * Reverse is true for LaserJet+, but false for LaserJet II. + * + * If reverse is true, all even pages are output first in reverse order, + * then the odd pages are output in reverse order. + * + * Example: + * First even pages are output: 6 4 2 (2 on top, printed side upwards). + * Then you turn the stack of paper (6 on top, printed side downwards) and + * feed in 6 4 2, and 5 3 1 are printed on the other side. + * 1 is now on top of the stack, printed side upwards. + * + * If reverse is false, all odd pages are output first in normal order, + * then the even pages are output in reverse order. + * + * Example: + * First odd pages are output: 1 3 5 (5 on top of stack, printed side + * downwards). Then you take the stack of paper and + * feed in 5 3 1 (5 on top, printed side downwards), and 6 4 2 are printed on + * the other side. 1 is now on top of the stack, printed side upwards. + */ + +#include <stdio.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: doodevpages.c,v 0.8 92/11/23 19:46:40 bt Exp $"; + +void doodevpages(bitfile, dvifile, pcllevel, reverse, resolution, device) +FILE *bitfile; +FILE *dvifile; +short pcllevel; +bool reverse; +short resolution; +short device; +{ + long backpage, startpage; + short is_odd = actualpagecount % 2; + + if(inpostamble) + backpage = lastpage + 1; + else + backpage = prevpage + 1; + maxpages = actualpagecount; + + if (reverse) + { /* Start with even pages. */ + + /* Eject an empty paper if odd number of pages */ + if (is_odd) fputs(PCL4_EJECT_PAGE,bitfile); + + startpage = backpage; + h_offset = e_offset; + + while(maxpages--) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + backpage = prevpage + 1; + if (! is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, resolution, + device); + } + if(maxpages > 0) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + if (is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, + resolution, device); + } + backpage = prevpage + 1; + maxpages--; + } + } + + /* then do the odd pages */ + fprintf(stderr,"Reload paper cassette with output package\n"); + fputs(PCL4_MANUAL_FEED,bitfile); + + h_offset = o_offset; + maxpages = actualpagecount; + backpage = startpage; + while (maxpages-- > 0) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + backpage = prevpage + 1; + if (is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, resolution, + device); + } + if(maxpages > 0) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + if (! is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, + resolution, device); + } + backpage = prevpage + 1; + maxpages--; + } + } + } + else + { + /* Do odd pages first */ + h_offset = o_offset; + maxpages = actualpagecount; + fseek(dvifile , firstpage-1 , 0); + while(maxpages-- > 0) + { + if(betweenpages(dvifile, PRESCAN_OFF)) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, resolution, + device); + maxpages--; + skipnextpage(dvifile); + } + } + /* Then do the even pages */ + fprintf(stderr,"Reload paper cassette with output package\n"); + fputs(PCL4_MANUAL_FEED,bitfile); + + h_offset = e_offset; + maxpages = actualpagecount; + if (is_odd) fputs(PCL4_EJECT_PAGE,bitfile); /* Odd number of pages */ + + while(maxpages--) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + backpage = prevpage + 1; + if (! is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, resolution, + device); + } + if(maxpages > 0) + { + fseek(dvifile , backpage , 0); + scanbop(dvifile); + if (is_odd) + { + printbop(startvals, count); + dopage(bitfile, dvifile, pcllevel, + resolution, device); + } + backpage = prevpage + 1; + maxpages--; + } + } + } + + fprintf(stderr,"\n"); +} diff --git a/dviware/dvi2pcl/dopage.c b/dviware/dvi2pcl/dopage.c new file mode 100644 index 0000000000..ce269cc50c --- /dev/null +++ b/dviware/dvi2pcl/dopage.c @@ -0,0 +1,318 @@ +/* $Log: dopage.c,v $ + * Revision 0.8 92/11/23 19:46:41 19:46:41 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:25 02:41:25 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:41 21:47:41 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:28 16:25:28 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:44 02:45:44 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:36 12:45:36 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:55 17:28:55 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * This is the main printer dependent output routine, which is organized as + * a function with side effects. The subroutine is organized as a typical + * interpreter, with a multiway branch of the command code followed by 'goto' + * statements leading to branches that finish up the activities common to + * different commands. dopage() aborts `dvi2pcl' if something unusual happens. + * + * The definition of dvi files refer to six registers, (h,v,w,x,y,z), which + * hold integer values in dvi units. In practice, we also need registers hh + * and vv, the pixel analogs of h and v, since it is not always true that + * hh = pixel_round(h) or vv = pixel_round(v). + * The stack of (h,w,w,x,y,z) values is represented by eight arrays called + * hstack,...,zstack, hhstack and vvstack. + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" +#include "pcl.h" + +static char rcsid[] = "$Header: dopage.c,v 0.8 92/11/23 19:46:41 bt Exp $"; + +dopage(bitfile, dvifile, pcllevel, resolution, device) +FILE *bitfile; +FILE *dvifile; +short pcllevel; +short resolution; +short device; +{ + unsigned char o; + int k; + int hhh, vvv; + bool badchar; + long hh, vv; + long p, q; + long hstack[STACKSIZE], vstack[STACKSIZE], wstack[STACKSIZE]; + long xstack[STACKSIZE], ystack[STACKSIZE], zstack[STACKSIZE]; + int hhstack[STACKSIZE], vvstack[STACKSIZE]; + charfmt *c; + + h_posed = v_posed = FALSE; + s = hh = vv = h = v = w = x = y = z = 0; + font = NULL; + while (TRUE) { + o = getubyte(dvifile); + if(o >= DVI_SET1) + p = firstpar(dvifile, o); +#ifdef DEBUG + fprintf(stderr,"\ndopage: o = %d, p = %ld, hh = %ld", o, p, hh); +#endif + if(o < DVI_SET1) { + c = drawchar(bitfile, o, hh, vv, resolution, device); + q = c->tfm_width; + hh += c->pxl_width; + goto move_right; + } else + switch(o) { + case DVI_SET1: + case DVI_SET2: + case DVI_SET3: + case DVI_SET4: + c = drawchar(bitfile, p, hh, vv, resolution, + device); + q = c->tfm_width; + hh += c->pxl_width; + goto move_right; + break; + case DVI_PUT1: + case DVI_PUT2: + case DVI_PUT3: + case DVI_PUT4: + drawchar(bitfile, p, hh, vv, resolution, + device); + goto done; + break; + case DVI_SET_RULE: + q = (long)getsquad(dvifile); + drawrule(bitfile, rulepixels(p, conv), + rulepixels(q, conv), hh, vv); + hh += rulepixels(q, conv); + goto move_right; + break; + case DVI_PUT_RULE: + q = (long)getsquad(dvifile); + drawrule(bitfile, rulepixels(p, conv), + rulepixels(q, conv), hh, vv); + goto done; + break; + case DVI_NOP: + goto done; + break; + case DVI_BOP: + fprintf(stderr,"\n'DVI_BOP' occurred before 'DVI_EOP'"); + goto endfalse; + break; + case DVI_EOP: + if(maxpages) + putc('\014',bitfile); /* Formfeed */ + if(s) + fprintf(stderr,"\nStack not empty at end of page"); + return (TRUE); + break; + case DVI_PUSH: + if(s == maxssofar) { + maxssofar++; + if(s == maxs) + fprintf(stderr,"\nDeeper than claimed in postamble"); + if(s == STACKSIZE) { + fprintf(stderr,"\nStack capacity exceeded"); + goto endfalse; + } + } + hstack[s] = h; + vstack[s] = v; + wstack[s] = w; + xstack[s] = x; + ystack[s] = y; + zstack[s] = z; + hhstack[s] = hh; + vvstack[s] = vv; + s++; + goto done; + break; + case DVI_POP: + if(s) { + s--; + if(hh != hhstack[s]) h_posed = FALSE; + if(vv != vvstack[s]) v_posed = FALSE; + h = hstack[s]; + v = vstack[s]; + w = wstack[s]; + x = xstack[s]; + y = ystack[s]; + z = zstack[s]; + hh = hhstack[s]; + vv = vvstack[s]; + } + else + fprintf(stderr,"\nIllegal at level zero"); + goto done; + break; + case DVI_RIGHT1: + case DVI_RIGHT2: + case DVI_RIGHT3: + case DVI_RIGHT4: + goto out_space; + break; + case DVI_W0: + case DVI_W1: + case DVI_W2: + case DVI_W3: + case DVI_W4: + w = p; + goto out_space; + break; + case DVI_X0: + case DVI_X1: + case DVI_X2: + case DVI_X3: + case DVI_X4: + x = p; + goto out_space; + break; + case DVI_DOWN1: + case DVI_DOWN2: + case DVI_DOWN3: + case DVI_DOWN4: + goto move_down; + break; + case DVI_Y0: + case DVI_Y1: + case DVI_Y2: + case DVI_Y3: + case DVI_Y4: + y = p; + goto move_down; + break; + case DVI_Z0: + case DVI_Z1: + case DVI_Z2: + case DVI_Z3: + case DVI_Z4: + z = p; + goto move_down; + break; + case DVI_FNT_DEF1: + case DVI_FNT_DEF2: + case DVI_FNT_DEF3: + case DVI_FNT_DEF4: + skipfontdef(dvifile); + goto done; + break; + case DVI_XXX1: + case DVI_XXX2: + case DVI_XXX3: + case DVI_XXX4: + badchar = FALSE; + if((long)nextnamesfree - (long)names + p > NAMESIZE ) + prerror("Out of string space during special\n"); + for(k = 0 ; k < (int)p ; k++) { + q = (long)getubyte(dvifile); + if((q < ' ') || (q > '~')) + badchar = TRUE; + *(nextnamesfree + k) = (char)q; + } + *(nextnamesfree + p) = 0; + if(badchar) + fprintf(stderr,"\nNon-ASCII character in xxx command"); + dospecial(bitfile, PRESCAN_OFF, pcllevel, hh, + vv, resolution); + goto done; + break; + case DVI_PRE: + fprintf(stderr,"\nPreamble command within a page"); + goto endfalse; + break; + case DVI_POST: + case DVI_POSTPOST: + fprintf(stderr,"\nPostamble command within a page"); + goto endfalse; + break; + case DVI_UNDEF0: + case DVI_UNDEF1: + case DVI_UNDEF2: + case DVI_UNDEF3: + case DVI_UNDEF4: + case DVI_UNDEF5: + fprintf(stderr,"\nUndefined DVI command %d.",o); + goto done; + break; + default: + font = fontptr[p]; + gfont = gfontptr[p]; + if(font->down > 0) + fprintf(bitfile, PCL4_SELECT_FONT, font->down); + goto done; + break; + } + +out_space: + if((font == NULL) || (p >= font->space) || (p <= -4*font->space)) + hh = round(conv*(h+p)); + else + hh += round(conv*p); + q = p; + h_posed = FALSE; +move_right: + hhh = round(conv*(h+q)); + if(abs(hhh - hh) > MAXDRIFT) { + h_posed = FALSE; + hh = hhh > hh ? hhh - MAXDRIFT : hhh + MAXDRIFT; + } + h += q; + if((long)abs(h) > maxhsofar) { + if(((long)abs(h) > maxh + 99) && verbose) { + fprintf(stderr,"\n|h| > %d\n", maxh); + maxh = (long)abs(h); + } + maxhsofar = (long)abs(h); + } + goto done; + +move_down: + if((font == NULL) || ((long)abs(p) >= 5*font->space)) + vv = round(conv*(v+p)); + else + vv += round(conv*p); + v_posed = FALSE; + if((v > 0) && (p > 0) && (v > INFINITY-p)) + fprintf(stderr,"Arithmetic overflow. Parameter changed from %d to %d.", p, p=INFINITY-v); + if((v < 0) && (p < 0) && (-v > INFINITY+p)) + fprintf(stderr,"\ndopage: Arithmetic overflow. Parameter changed from %d to %d.", p, p = -(INFINITY+v)); + vvv = round(conv*(v+p)); + if(abs(vvv - vv) > MAXDRIFT) + vv = vvv > vv ? vvv - MAXDRIFT : vvv + MAXDRIFT; + v += p; + if((long)abs(v) > maxvsofar) { + if(((long)abs(v) > maxv + 99) && verbose) { + fprintf(stderr,"\n|v| > %d.",maxv); + maxv = (long)abs(v); + } + maxvsofar = (long)abs(v); + } + goto done; + +done: + ; + } +endfalse: + prerror("\n! Bad .pcl file: page ended unexpectedly !\n"); +} diff --git a/dviware/dvi2pcl/dospecial.c b/dviware/dvi2pcl/dospecial.c new file mode 100644 index 0000000000..5312760b57 --- /dev/null +++ b/dviware/dvi2pcl/dospecial.c @@ -0,0 +1,462 @@ +/* $Log: dospecial.c,v $ + * Revision 0.8 92/11/23 19:46:42 19:46:42 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:26 02:41:26 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:42 21:47:42 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:29 16:25:29 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:45 02:45:45 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:37 12:45:37 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:56 17:28:56 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * This procedure will handle any special commands that might appear. + * The following variants are handled: + * + * \special{command} + * \special{command(parameters)} + * \special{command=parameters} + * \special{command parameters} + * \special{command:parameters} + * + * The string contained in the special command is in the name array starting at + * 'nextnamesfree' and ending with a '\0'. Also, the 'prescan' boolean should + * be checked to see if this is the first or second time that this string was + * encountered. + * + * Copyright 1992 Bo Thide', Uppsala, Sweden <bt@irfu.se>. + */ + +#define S_LANDSCAPE 0 /* Original \special "landscape" */ +#define S_INCLUDE 1 /* Original \special "include()" */ +#define S_GRAFIX 2 /* Original \special "grafix()" */ +#define S_MOVE 3 /* Original \special "move()" */ +#define S_ESCAPESEQ 4 /* dvi \special "escapeseq ..." */ +#define S_RASTERFILE 5 /* dvi \special "rasterfile ..." */ +#define S_RAWSTRING 6 /* dvi \special "rawstring ..." */ +#define S_ORIENTATION 7 /* Gustaf Neumann's \special "orientation" */ +#define S_FILE 8 /* Gustaf Neumann's \special "file" */ +#define S_PS 9 /* PostScript \special's "ps:" */ +#define S_EM 10 /* 'emtex' \special's "em:" */ +#define S_PCL 11 /* PCL \special's "pcl:" */ +#define S_HPGL 12 /* PCL5 \special's "hpgl:" */ +#define S_PJXL 13 /* PaintJet XL \special "rawstring ..." */ +#define SPECIALS 14 /* Number of \special's supported */ +#define GRAFLIST 7 /* Number of graphics resolutions supported */ +#define COLORLIST 8 /* Number of PaintJet XL text colors */ + +#include <ctype.h> +#include <stdio.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: dospecial.c,v 0.8 92/11/23 19:46:42 bt Exp $"; + +void dospecial(bitfile, prescan, pcllevel, hh, vv, resolution) +FILE *bitfile; +bool prescan; +short pcllevel; +long hh, vv; +short resolution; +{ + + /* The \special arguemnt keywords and their assocated delimiters */ + static char *spclargv[SPECIALS][2] = { + "landscape", "", + "include", "(", + "grafix", "(", + "move", "(", + "escapeseq", " ", + "rasterfile", " ", + "rawstring", " ", + "orientation", "=", + "file", "=", + "ps", ":", + "em", ":", + "pcl", ":", + "hpgl", ":", + "pjxl", ":" + }; + static char *graflist[] = {"600","300","180","150","100","90","75"}; + static char *colorlist[] = {"black","red","green","yellow","blue", + "magenta","cyan","white"}; + char *bufptr; + char *delimptr; /* Pointer to the argument delimiter */ + char *iptr, *jptr; /* Generic pointers */ + char c; + char drawrow[8]; + char curname[NAMELENGTH]; /* Current name of generic file */ + bool relative; + short angle=0; + short planes=1; + int i, j, k, l; + int pxl_rows, row_bytes; + int gflag; + int ic; + long hoffset, voffset; + FILE *genfile; /* Generic file pointer */ + + bufptr = nextnamesfree; + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: nextnamesfree = '%s'\n", nextnamesfree); +fprintf(stderr,"dospecial: prescan = '%d'\n", prescan); +fprintf(stderr,"dospecial: pcllevel = '%d'\n", pcllevel); +#endif /* DEBUG */ + + /* Process as long as the 'nextnamesfree' is not empty */ + while(*bufptr){ + while(isspace(*bufptr)) /* Skip over all leading white space */ + bufptr++; + if(*bufptr){ /* Process only if it was not all white space */ + iptr = jptr = bufptr; + while(isalpha(*jptr)) /* Move to the end of the first alpha string */ + jptr++; + + /* See if the first alpha string is an OK keyword */ + k = 0; + while(strncmp(bufptr,spclargv[k][0],strlen(spclargv[k][0]))) + k++; /* If the keyword is correct k points to it */ + + /* Locate the correct delimiter associated with the keyword */ + while(*jptr && (*jptr != *spclargv[k][1])) + jptr++; + delimptr = jptr; + + /* + * Bail out if no correct keyword (k >= SPECIALS) + * or no correct delimiter (*jptr == NULL) was found + */ + if(prescan && ((k >= SPECIALS) || !*jptr)) { + fprintf(stderr,"\ndospecial: \\special command not understood: %s\n", + nextnamesfree); + return; + } + /* + * Here we know that the keyword is OK and that delimptr points to + * the correct delimiter associated with that keyword. + */ + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: delimptr = '%s'\n", delimptr); +#endif /* DEBUG */ + + /* Move bufptr to point to the delimiter, after the first alpha string */ + bufptr = delimptr; + + /* Make sure the delimiter '(' has a matching ')' */ + if(*delimptr == '(') { + bufptr++; + while((*bufptr != ')') && *bufptr) + bufptr++; + if(*bufptr == '\0') + fprintf(stderr,"\ndospecial: Expected ) after parameter in \\special{%s}.\n", nextnamesfree); + else + bufptr++; + } + else { /* Handle the other delimiters */ + bufptr++; + while(*bufptr) + bufptr++; + } + /* Now bufptr points to the end of the nextnamesfree string */ + + + /* Move jptr to point to after the (one byte) delimiter */ + jptr = delimptr + 1; + + /* Parse the rest of the string for keyword entry spclargv[k][0] */ + switch (k) { + + case S_LANDSCAPE: /* Landscape mode */ + if(prescan) + landscape = TRUE; + break; + + case S_INCLUDE: /* include(filename) */ + if(!prescan) { + iptr = curname; + while((*jptr != ' ') && (*jptr != ')') && *jptr) + *iptr++ = *jptr++; + *iptr = '\0'; + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: S_INCLUDE curname = %s\n", curname); +#endif /* DEBUG */ + + if((genfile = fopen(curname,"r")) == NULL) { + fprintf(stderr,"Cannot open the \\special{include()} file %s for input.\n", curname); + exit(-1); + } + /* Make the cursor position current and push it */ + /* + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + */ + while((ic = getc(genfile)) != EOF) + putc(ic, bitfile); + fclose(genfile); + /* + fputs(PCL4_POP, bitfile); + */ + } + break; + + case S_MOVE: /* move(h=..dim v=..dim) */ + if(!prescan) { + hoffset = voffset = 0L; + relative = TRUE; + while(*jptr != ')'){ + while(*jptr == ' ') + jptr++; + if(!(c = *jptr++)); + if(*jptr == '=') jptr++; + switch(c) + { + case 'h': + hoffset = dim_to_dots(jptr, resolution); + break; + case 'v': + voffset = dim_to_dots(jptr, resolution); + break; + case 'a': + relative = FALSE; + break; + case 'r': + relative = TRUE; + break; + default: + fprintf(stderr,"\ndospecial: Invalid parameter in \\special{move}\n"); + break; + } + while((*jptr != ' ') && (*jptr != ')') && *jptr) + jptr++; + } + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: S_MOVE relative = %d, hoffset = %ld, voffset = %ld\n", relative, hoffset, voffset); +#endif /* DEBUG */ + + if(relative) { + if(hoffset) + fprintf(bitfile, PCL4_MOVE_HREL, hoffset); + if(voffset) + fprintf(bitfile, PCL4_MOVE_VREL, voffset); + } + else { + if(hoffset) + fprintf(bitfile, PCL4_MOVE_H_POSITION, hoffset); + if(voffset) + fprintf(bitfile, PCL4_MOVE_V_POSITION, voffset); + } + } + break; + + case S_GRAFIX: /* grafix(filename [resolution]) */ + if(!prescan) { + iptr = curname; + while((*jptr != ' ') && (*jptr != ')') && *jptr) + *iptr++ = *jptr++; + *iptr = '\0'; + if((genfile = fopen(curname,"r")) == NULL) { + fprintf(stderr,"Cannot open the \\special{grafix()} input file %s for input.\n", curname); + exit(-1); + } + while(*jptr == ' ') jptr++; + delimptr = jptr; + while((*jptr != ' ') && (*jptr != ')') && *jptr) + jptr++; + if(jptr != delimptr) + { + *jptr = '\0'; + l = 0; + while(l < GRAFLIST) + if(!strcmp(delimptr, graflist[l])) + break; + else l++; + } + else l = 2; + if(l == GRAFLIST) + { + fprintf(stderr,"\ndospecial: Invalid resolution in \\special{grafix}: %s.\n", delimptr); + l = 2; + } + if(l) + fprintf(bitfile, PCL4_GRAPHRES, graflist[l]); + /* Make the cursor position current and push it */ + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + fputs(PCL4_START_RASTER, bitfile); + pxl_rows = (getc(genfile) << 8); + pxl_rows = pxl_rows + getc(genfile); + gflag = getc(genfile); + if(!gflag) + sprintf(drawrow, PCL4_DRAWROW, row_bytes = getc(genfile)); + for(i = 0 ; i < pxl_rows ; i++) { + if(gflag) + fprintf(bitfile, PCL4_DRAWROW, row_bytes = getc(genfile)); + else + fputs(drawrow, bitfile); + for(j = 0 ; j < row_bytes ; j++) + putc(getc(genfile), bitfile); + } + fclose(genfile); + fputs(PCL4_END_RASTER, bitfile); + if(l) + fprintf(bitfile, PCL4_GRAPHRES, graflist[0]); + fputs(PCL4_POP, bitfile); + } + break; + + case S_ORIENTATION: /* PCL5 print orientation/direction */ + if(!prescan) { + if(pcllevel < 5) + fprintf(stderr,"\ndospecial: Changing print direction via \\special not supported at PCL level %d.\n Only at PCL level 5 (option -5).", pcllevel); + else { + + angle = (short)atoi(jptr); + if(angle==1) + angle=90; + else if(angle==2) + angle=180; + else if(angle==3) + angle=270; + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: S_ORIENTATION angle = %d\n", angle); +#endif /* DEBUG */ + + /* Make the cursor position current */ + /* + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + */ + fprintf(bitfile, PCL5_PRINT_DIRECTION, angle); + } + } + break; + + case S_FILE: /* Input file */ + if(!prescan) { + iptr = curname; + while((*jptr != ' ') && *jptr) + *iptr++ = *jptr++; + *iptr = '\0'; + if((genfile = fopen(curname,"r")) == NULL) { + fprintf(stderr,"Cannot open the \\special{input=} file %s for input.\n", curname); + exit(-1); + } + /* Make the cursor position current and push it */ + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + while((ic = getc(genfile)) != EOF) + putc(ic, bitfile); + fclose(genfile); + fputs(PCL4_POP, bitfile); + } + break; + + case S_PCL: /* PCL code */ + case S_PS: /* PostScript code */ + if(!prescan) { + /* Make the cursor position current and push it */ + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + while(*jptr) + putc(*jptr++, bitfile); + fputs(PCL4_POP, bitfile); + } + break; + + case S_HPGL: /* PCL5 HP-GL/2 code */ + if(!prescan) { + if(pcllevel < 5) + fprintf(stderr,"\ndospecial: Using HP-GL/2 commands in \\special not supported at PCL level %d.\n Only at PCL level 5 or higher (option -5).", pcllevel); + else { + /* Make the cursor position current and push it */ + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + /* Enter HP-GL/2 mode. Pen to previous PCL pen position */ + fputs(PCL5_HPGLMODE_PCLPEN, bitfile); + while(*jptr) + putc(*jptr++, bitfile); + /* Enter PCL mode. Pen to previous PCL pen position */ + fputs(PCL5_PCLMODE_PCLPEN, bitfile); + fputs(PCL4_POP, bitfile); + } + } + break; + + case S_RASTERFILE: /* rasterfile ...*/ + if(!prescan) { + iptr = curname; + while((*jptr != ' ') && *jptr) + *iptr++ = *jptr++; + *iptr = '\0'; + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: S_RASTERFILE curname = %s\n", curname); +#endif /* DEBUG */ + + if((genfile = fopen(curname,"r")) == NULL){ + fprintf(stderr,"Cannot open the \\special{rasterfile} file %s for input.\n", curname); + exit(-1); + } + /* Make the cursor position current and push it */ + fprintf(bitfile, PCL4_MOVE_POSITION, hh+h_offset, vv+v_offset); + fputs(PCL4_PUSH, bitfile); + while((ic = getc(genfile)) != EOF) + putc(ic, bitfile); + fclose(genfile); + fputs(PCL4_POP, bitfile); + } + break; + + case S_PJXL: + if(!prescan) { + +#ifdef DEBUG +fprintf(stderr,"\ndospecial: S_PJXL jptr = %s\n", jptr); +#endif /* DEBUG */ + + l = 0; + while(l < GRAFLIST) { + if(!strcmp(jptr, colorlist[l])) + break; + else + l++; + } + if(l == GRAFLIST) { + fprintf(stderr,"\ndospecial: Invalid color in \\special{pjxl:}: %s.\n", jptr); + l = 0; + } + fprintf(bitfile, PJXL_TEXT_COLOR, l); + } + break; + + case S_ESCAPESEQ: + case S_RAWSTRING: + case S_EM: + if(prescan) { + fprintf(stderr,"\ndospecial: \\special command not implemented: %s\n", + nextnamesfree); + } + break; + } + } + } +} diff --git a/dviware/dvi2pcl/downloadchar.c b/dviware/dvi2pcl/downloadchar.c new file mode 100644 index 0000000000..a3f6dc9b0e --- /dev/null +++ b/dviware/dvi2pcl/downloadchar.c @@ -0,0 +1,149 @@ +/* $Log: downloadchar.c,v $ + * Revision 0.8 92/11/23 19:46:43 19:46:43 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:27 02:41:27 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:43 21:47:43 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:30 16:25:30 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:45 02:45:45 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:38 12:45:38 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:56 17:28:56 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * Download character 'c', assuming that the corresponding font file is in + * .pk format. Therefore, 'pktopxl(c)' is called which converts the pk-coded + * character into the corresponding byte aligned pixel pattern, stored in + * 'pxlbuffer'. 'pktopxl(c)' also determines the global variables + * c_width, c_height, c_hoffset, c_voffset. + * + * For landscape mode the pixel pattern then will be rotated and stored at + * the end of the character pixel pattern at 'endofchardata' in pxlbuffer. + * The appropriate pixel pattern then is downloaded, i.e is put in bitfile, + * if possible, including the corresponding character descriptor for the + * printer. For those characters which don't fit into the printer's maximum + * character cell (use_count < 0) raster information is stored in *gfont + * and memory space is allocated to store the corresponding pixel pattern. + * Stored characters are drawn in graphics mode by 'drawchar(c)'. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: downloadchar.c,v 0.8 92/11/23 19:46:43 bt Exp $"; + + +int downloadchar(bitfile, c, device) +FILE *bitfile; +int c; +short device; +{ + int i; + charfmt *u; + int length; + int width_bytes; + int width, height; + byte *p; + + pktopxl(c); + + /* Determine the char descriptor values */ + cd.format = 4; + cd.continuation = 0; + cd.size = 14; + cd.class = 1; + cd.reserved = 0; + if(landscape){ + p = (byte *)rotatechar(); + width = c_height; + height = c_width; + cd.orientation = '\1'; + cd.left_offset = -c_voffset; + cd.top_offset = height - c_hoffset - 1; + } + else{ + width = c_width; + height = c_height; + cd.orientation = '\0'; + cd.left_offset = -c_hoffset; + cd.top_offset = c_voffset; + p = pxlbuffer; + } + width_bytes = (width + 7) / 8; + length = height*width_bytes; + + /* This is for empty characters */ + if(!length) { + length = 1; + if(!width) + width=1; + if(!height) { + height = 1; + cd.top_offset = 1; + } + } + + u = cbase + c; + cd.char_width = (ushort)width; + cd.char_height = (ushort)height; + cd.delta_x = (short)(4*u->pxl_width); /* In quarterdots! */ + if(device == DEV_LJPLUS) { + if(c <= 32) + c += 160; + } + +#ifdef DEBUG2 +fprintf(stderr,"downloadchar: cd.format = %d\n", cd.format); +fprintf(stderr,"downloadchar: cd.continuation = %d\n", cd.continuation); +fprintf(stderr,"downloadchar: cd.size = %d\n", cd.size); +fprintf(stderr,"downloadchar: cd.class = %d\n", cd.class); +fprintf(stderr,"downloadchar: cd.orientation = %d\n", cd.orientation); +fprintf(stderr,"downloadchar: cd.reserved = %d\n", cd.reserved); +fprintf(stderr,"downloadchar: cd.left_offset = %d\n", cd.left_offset); +fprintf(stderr,"downloadchar: cd.top_offset = %d\n", cd.top_offset); +fprintf(stderr,"downloadchar: cd.char_width = %d\n", cd.char_width); +fprintf(stderr,"downloadchar: cd.char_height = %d\n", cd.char_height); +fprintf(stderr,"downloadchar: cd.delta_x = %d\n", cd.delta_x); +#endif /* DEBUG2 */ + + /* Send character ID escape sequence to printer */ + fprintf(bitfile, PCL4_CHAR_ID, c, length + (int)cd.size + 2); + + /* + * Download each char descriptor value individually to avoid + * possible struct alignment problems. + */ + fwrite((void *)&cd.format, sizeof(cd.format), 1, bitfile); + fwrite((void *)&cd.continuation, sizeof(cd.continuation), 1, bitfile); + fwrite((void *)&cd.size, sizeof(cd.size), 1, bitfile); + fwrite((void *)&cd.class, sizeof(cd.class), 1, bitfile); + fwrite((void *)&cd.orientation, sizeof(cd.orientation), 1, bitfile); + fwrite((void *)&cd.reserved, sizeof(cd.reserved), 1, bitfile); + fwrite((void *)&cd.left_offset, sizeof(cd.left_offset), 1, bitfile); + fwrite((void *)&cd.top_offset, sizeof(cd.top_offset), 1, bitfile); + fwrite((void *)&cd.char_width, sizeof(cd.char_width), 1, bitfile); + fwrite((void *)&cd.char_height, sizeof(cd.char_height), 1, bitfile); + fwrite((void *)&cd.delta_x, sizeof(cd.delta_x), 1, bitfile); + + /* Now download pixel pattern for c */ + for(i = 0 ; i < length ; i++) + putc(*p++, bitfile); + + return(height*((width + 7)/8) + (int)cd.size + 2); +} diff --git a/dviware/dvi2pcl/downloadfont.c b/dviware/dvi2pcl/downloadfont.c new file mode 100644 index 0000000000..9715c4cdeb --- /dev/null +++ b/dviware/dvi2pcl/downloadfont.c @@ -0,0 +1,191 @@ +/* $Log: downloadfont.c,v $ + * Revision 0.8 92/11/23 19:46:43 19:46:43 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:27 02:41:27 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:44 21:47:44 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:31 16:25:31 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:46 02:45:46 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:38 12:45:38 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:56 17:28:56 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <math.h> +#include <stdio.h> +#include "globals.h" +#include "macros.h" +#include "pcl.h" + +static char rcsid[] = "$Header: downloadfont.c,v 0.8 92/11/23 19:46:43 bt Exp $"; + +/* Download a font to the printer */ +long downloadfont(bitfile, permfontsdown, device) +FILE *bitfile; +int permfontsdown; +short device; +{ + int i; + int depth; + int max_depth; + int max_width; + int max_offset; + long memreq; + double fh4; + + max_depth = max_width = max_offset = 0; + memreq = 4; + + /* Specify font ID = nextfontdown and download each character */ + fprintf(bitfile, PCL4_FONT_ID, font->down=nextfontdown--, fd.size); + + if(verbose) + fprintf(stderr,"Downloading %d...\n",font->down); + + for(i = font->bc ; i <= font->ec ; i++) + if((cbase + i)->use_count) { + pkcharinfo(i); + if(c_voffset > max_offset) max_offset = c_voffset; + if((depth = c_height-c_voffset) > max_depth) + max_depth = depth; + if(c_width > max_width) max_width = c_width; + } + + + /* Determine the font descriptor values */ + fd.size = 64; + fd.descriptor = 0; + if(device == DEV_LJPLUS) + fd.font_type = 1; + else + fd.font_type = 2; + fd.style_MSB = 0; + fd.reserved = 0; + fd.baseline = (ushort)max_offset; + fd.cell_width = (ushort)(max_width?max_width:1); + fd.cell_height = (ushort)(max_depth?max_offset+max_depth:max_offset+1); + fd.orientation = (ubyte)(landscape ? 1 : 0); + fd.spacing = 1; + fd.symbol_set = (ushort)(DYNAMICFONTBASE-nextfontdown-permfontsdown)<<5; + fd.pitch = fd.cell_width << 2; + fh4 = 4.0*font->height; /* Temp variable */ + fd.height = (ushort)fh4; + pkcharinfo('x'); /* Get global values for 'x' */ + fd.x_height = (ushort)c_height; /* c_height is for 'x' here! */ + fd.width_type = 0; + fd.style_LSB = 0; + fd.stroke_weight = 0; + fd.typeface_LSB = 0; + fd.typeface_MSB = 0; + fd.serif_style = 128; /* Serif */ + fd.quality = 0; + fd.placement = 0; + fd.underl_dist = (byte)-max_depth; + fd.underl_height = 0; + fd.text_height = fd.cell_height << 2; + fd.text_width = fd.cell_width << 2; + fd.first_code = 1; + fd.last_code = 255; + fd.pitch_ext = 0; + fd.height_ext = (ushort)(1024*(fh4 - fd.height)); + fd.cap_height = 0; + fd.font_number = 0; + strcpy(fd.font_name,"-TeX dvi font-"); + +#ifdef DEBUG2 +fprintf(stderr,"downloadfont: fd.size = %d\n", fd.size); +fprintf(stderr,"downloadfont: fd.descriptor = %d\n", fd.descriptor); +fprintf(stderr,"downloadfont: fd.font_type = %d\n", fd.font_type); +fprintf(stderr,"downloadfont: fd.style_MSB = %d\n", fd.style_MSB); +fprintf(stderr,"downloadfont: fd.reserved = %d\n", fd.reserved); +fprintf(stderr,"downloadfont: fd.baseline = %d\n", fd.baseline); +fprintf(stderr,"downloadfont: fd.cell_width = %d\n", fd.cell_width); +fprintf(stderr,"downloadfont: fd.cell_height = %d\n", fd.cell_height); +fprintf(stderr,"downloadfont: fd.orientation = %d\n", fd.orientation); +fprintf(stderr,"downloadfont: fd.spacing = %d\n", fd.spacing); +fprintf(stderr,"downloadfont: fd.symbol_set = %d\n", fd.symbol_set); +fprintf(stderr,"downloadfont: fd.pitch = %d\n", fd.pitch); +fprintf(stderr,"downloadfont: fd.height = %d\n", fd.height); +fprintf(stderr,"downloadfont: fd.x_height = %d\n", fd.x_height); +fprintf(stderr,"downloadfont: fd.width_type = %d\n", fd.width_type); +fprintf(stderr,"downloadfont: fd.style_LSB = %d\n", fd.style_LSB); +fprintf(stderr,"downloadfont: fd.stroke_weight = %d\n", fd.stroke_weight); +fprintf(stderr,"downloadfont: fd.typeface_LSB = %d\n", fd.typeface_LSB); +fprintf(stderr,"downloadfont: fd.typeface_MSB = %d\n", fd.typeface_MSB); +fprintf(stderr,"downloadfont: fd.serif_style = %d\n", fd.serif_style); +fprintf(stderr,"downloadfont: fd.quality = %d\n", fd.quality); +fprintf(stderr,"downloadfont: fd.placement = %d\n", fd.placement); +fprintf(stderr,"downloadfont: fd.underl_dist = %d\n", fd.underl_dist); +fprintf(stderr,"downloadfont: fd.underl_height = %d\n", fd.underl_height); +fprintf(stderr,"downloadfont: fd.text_height = %d\n", fd.text_height); +fprintf(stderr,"downloadfont: fd.text_width = %d\n", fd.text_width); +fprintf(stderr,"downloadfont: fd.first_code = %d\n", fd.first_code); +fprintf(stderr,"downloadfont: fd.last_code = %d\n", fd.last_code); +fprintf(stderr,"downloadfont: fd.pitch_ext = %d\n", fd.pitch_ext); +fprintf(stderr,"downloadfont: fd.height_ext = %d\n", fd.height_ext); +fprintf(stderr,"downloadfont: fd.cap_height = %d\n", fd.cap_height); +fprintf(stderr,"downloadfont: fd.font_number = %d\n", fd.font_number); +fprintf(stderr,"downloadfont: fd.font_name = %s\n", fd.font_name); +#endif /* DEBUG2 */ + + /* Send font descriptor escape sequence to printer */ + fprintf(bitfile, PCL4_FONT_DESCR, fd.size); + + /* + * Download each font descriptor value individually to avoid + * possible struct alignment problems. + */ + fwrite((void *)&fd.size, sizeof(fd.size), 1, bitfile); + fwrite((void *)&fd.descriptor, sizeof(fd.descriptor), 1, bitfile); + fwrite((void *)&fd.font_type, sizeof(fd.font_type), 1, bitfile); + fwrite((void *)&fd.style_MSB, sizeof(fd.style_MSB), 1, bitfile); + fwrite((void *)&fd.reserved, sizeof(fd.reserved), 1, bitfile); + fwrite((void *)&fd.baseline, sizeof(fd.baseline), 1, bitfile); + fwrite((void *)&fd.cell_width, sizeof(fd.cell_width), 1, bitfile); + fwrite((void *)&fd.cell_height, sizeof(fd.cell_height), 1, bitfile); + fwrite((void *)&fd.orientation, sizeof(fd.orientation), 1, bitfile); + fwrite((void *)&fd.spacing, sizeof(fd.spacing), 1, bitfile); + fwrite((void *)&fd.symbol_set, sizeof(fd.symbol_set), 1, bitfile); + fwrite((void *)&fd.pitch, sizeof(fd.pitch), 1, bitfile); + fwrite((void *)&fd.height, sizeof(fd.height), 1, bitfile); + fwrite((void *)&fd.x_height, sizeof(fd.x_height), 1, bitfile); + fwrite((void *)&fd.width_type, sizeof(fd.width_type), 1, bitfile); + fwrite((void *)&fd.style_LSB, sizeof(fd.style_LSB), 1, bitfile); + fwrite((void *)&fd.stroke_weight, sizeof(fd.stroke_weight), 1, bitfile); + fwrite((void *)&fd.typeface_LSB, sizeof(fd.typeface_LSB), 1, bitfile); + fwrite((void *)&fd.typeface_MSB, sizeof(fd.typeface_MSB), 1, bitfile); + fwrite((void *)&fd.serif_style, sizeof(fd.serif_style), 1, bitfile); + fwrite((void *)&fd.quality, sizeof(fd.quality), 1, bitfile); + fwrite((void *)&fd.placement, sizeof(fd.placement), 1, bitfile); + fwrite((void *)&fd.underl_dist, sizeof(fd.underl_dist), 1, bitfile); + fwrite((void *)&fd.underl_height, sizeof(fd.underl_height), 1, bitfile); + fwrite((void *)&fd.text_height, sizeof(fd.text_height), 1, bitfile); + fwrite((void *)&fd.text_width, sizeof(fd.text_width), 1, bitfile); + fwrite((void *)&fd.first_code, sizeof(fd.first_code), 1, bitfile); + fwrite((void *)&fd.last_code, sizeof(fd.last_code), 1, bitfile); + fwrite((void *)&fd.pitch_ext, sizeof(fd.pitch_ext), 1, bitfile); + fwrite((void *)&fd.height_ext, sizeof(fd.height_ext), 1, bitfile); + fwrite((void *)&fd.cap_height, sizeof(fd.cap_height), 1, bitfile); + fwrite((void *)&fd.font_number, sizeof(fd.font_number), 1, bitfile); + fwrite((void *)fd.font_name, sizeof(fd.font_name), 1, bitfile); + + /* Download each character of curfont which occurs in the .dvi file */ + for(i = font->bc ; i <= font->ec ; i++) + if((cbase + i)->use_count) + memreq += downloadchar(bitfile, i, device); + fprintf(bitfile, PCL4_MAKE_FONT_TEMP); /* Make the font temporary */ + return(memreq); +} diff --git a/dviware/dvi2pcl/drawchar.c b/dviware/dvi2pcl/drawchar.c new file mode 100644 index 0000000000..3821e9b5bb --- /dev/null +++ b/dviware/dvi2pcl/drawchar.c @@ -0,0 +1,101 @@ +/* $Log: drawchar.c,v $ + * Revision 0.8 92/11/23 19:46:44 19:46:44 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:28 02:41:28 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:44 21:47:44 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:31 16:25:31 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:47 02:45:47 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:19 12:43:19 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:56 17:28:56 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: drawchar.c,v 0.8 92/11/23 19:46:44 bt Exp $"; + +/* + * On entrance to this routine, the character to be drawn will be in 'c', the + * font in use is pointed by the pointer '*font'. The external name by which + * the font is known in 'font->down'. The routine is also responsible for + * setting the printer to the correct location on the page ('hh' and 'vv') + */ +charfmt *drawchar(bitfile, c, hh, vv, resolution, device) +FILE *bitfile; +int c; +long hh, vv; +short resolution; +short device; +{ + int i,j; + int pxl_bytes; + charfmt *u; + gcharfmt *g; + byte *p; + char drawrow[8]; + +#ifdef DEBUG + fprintf(stderr,"\ndrawchar: hh = %ld, vv = %ld,\n",hh, vv); +#endif + if(!h_posed && !v_posed) { + fprintf(bitfile, PCL4_MOVE_POSITION, hh + h_offset, vv + v_offset); + h_posed = v_posed = TRUE; + } + else if(!h_posed) { + fprintf(bitfile, PCL4_MOVE_H_POSITION, hh + h_offset); + h_posed = TRUE; + } + else if(!v_posed) { + fprintf(bitfile, PCL4_MOVE_V_POSITION, vv + v_offset); + v_posed = TRUE; + } + u = font->chr + c; + if(u->use_count > 0) { + /* Print downloaded character */ + if(device == DEV_LJPLUS) { + putc(c > 32 ? c : c + 160, bitfile); + } else + if(c > 27) + putc(c, bitfile); + else + if(c==0 || c > 6 && c < 16 || c==27) + fprintf(bitfile, PCL4_TRANSP_MODE, c); + else + putc(c , bitfile); + } else { + /* Draw graphic raster pattern of character */ + g = &(*gfont)[c]; + p = g->pxl_pattern; + fputs(PCL4_PUSH, bitfile); + fprintf(bitfile, PCL4_MOVE_REL, g->x_offset, g->y_offset); + fprintf(bitfile, PCL4_RESOLUTION, resolution); + fputs(PCL4_START_RASTER, bitfile); + pxl_bytes = g->pxl_bytes; + sprintf(drawrow, PCL4_DRAWROW, pxl_bytes); + for(i = 0 ; i < g->pxl_rows ; i++) { + fputs(drawrow, bitfile); + for(j = 0 ; j < pxl_bytes ; j++) + putc(*p++, bitfile); + } + fputs(PCL4_END_RASTER, bitfile); + fputs(PCL4_POP, bitfile); + fprintf(bitfile, PCL4_MOVE_HREL, u->pxl_width); + } + return (u); +} diff --git a/dviware/dvi2pcl/drawrule.c b/dviware/dvi2pcl/drawrule.c new file mode 100644 index 0000000000..fb430c06f9 --- /dev/null +++ b/dviware/dvi2pcl/drawrule.c @@ -0,0 +1,53 @@ +/* $Log: drawrule.c,v $ + * Revision 0.8 92/11/23 19:46:45 19:46:45 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:29 02:41:29 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:45 21:47:45 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:32 16:25:32 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:48 02:45:48 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:39 12:45:39 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:56 17:28:56 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "pcl.h" + +static char rcsid[] = "$Header: drawrule.c,v 0.8 92/11/23 19:46:45 bt Exp $"; + +/* + * This procedure draws a rule (a solid black rectangle) of a pixels + * in height and b pixels in width. Positioning is again essential. + * The LaserJet+ makes this very easy. + */ +void drawrule(bitfile, a, b, hh, vv) +FILE *bitfile; +long a, b, hh, vv; +{ + +#ifdef DEBUG + fprintf(stderr,"\ndrawrule: a = %ld, b = %ld\n", a, b); +#endif /* DEBUG */ + + fprintf(bitfile, PCL4_MOVE_V_POSITION, vv + v_offset - a + 1 ); + v_posed = FALSE; + if(!h_posed) + fprintf(bitfile, PCL4_MOVE_H_POSITION, hh + h_offset); + h_posed = FALSE; + fprintf(bitfile, PCL4_DRAWRULE, a, b); +} diff --git a/dviware/dvi2pcl/dvi.h b/dviware/dvi2pcl/dvi.h new file mode 100644 index 0000000000..0baddcdf40 --- /dev/null +++ b/dviware/dvi2pcl/dvi.h @@ -0,0 +1,101 @@ +/* $Log: dvi.h,v $ + * Revision 0.8 92/11/23 19:47:02 19:47:02 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:16 02:41:16 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:43 21:48:43 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:49 16:25:49 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:06 02:46:06 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:24 12:45:24 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:53 17:28:53 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:46 23:58:46 bt (Bo Thide') + * First Release. + * */ + +#ifndef _DVI2PCL_DVI_INCLUDED +#define _DVI2PCL_DVI_INCLUDED + +/* Define dvi commands */ +#define DVI_SET_CHAR0 0 /* Typeset char 0 and move right */ +#define DVI_SET_CHAR127 127 /* Typeset char 127 and move right */ +#define DVI_SET1 128 /* Typeset a char and move right */ +#define DVI_SET2 129 +#define DVI_SET3 130 +#define DVI_SET4 131 +#define DVI_SET_RULE 132 /* Typeset a rule and move right */ +#define DVI_PUT1 133 /* Typeset a char */ +#define DVI_PUT2 134 +#define DVI_PUT3 135 +#define DVI_PUT4 136 +#define DVI_PUT_RULE 137 /* Typeset a rule */ +#define DVI_NOP 138 /* No operation */ +#define DVI_BOP 139 /* Beginning of page */ +#define DVI_EOP 140 /* End of page */ +#define DVI_PUSH 141 /* Save current DVI position */ +#define DVI_POP 142 /* Restore last DVI postition */ +#define DVI_RIGHT1 143 /* Move right */ +#define DVI_RIGHT2 144 +#define DVI_RIGHT3 145 +#define DVI_RIGHT4 146 +#define DVI_W0 147 /* Move right by w */ +#define DVI_W1 148 /* Move right and set w */ +#define DVI_W2 149 +#define DVI_W3 150 +#define DVI_W4 151 +#define DVI_X0 152 /* Move right by x */ +#define DVI_X1 153 /* Move right and set x */ +#define DVI_X2 154 +#define DVI_X3 155 +#define DVI_X4 156 +#define DVI_DOWN1 157 /* Move down */ +#define DVI_DOWN2 158 +#define DVI_DOWN3 159 +#define DVI_DOWN4 160 +#define DVI_Y0 161 /* Move down by y */ +#define DVI_Y1 162 /* Move down and set y */ +#define DVI_Y2 163 +#define DVI_Y3 164 +#define DVI_Y4 165 +#define DVI_Z0 166 /* Move down by z */ +#define DVI_Z1 167 /* Move down and set z */ +#define DVI_Z2 168 +#define DVI_Z3 169 +#define DVI_Z4 170 +#define DVI_FNT_NUM_0 171 /* Current font = 0 */ +#define DVI_TRAILER 223 +#define DVI_FNT_NUM_63 234 /* Current font = 63 */ +#define DVI_FNT1 235 /* Set current font */ +#define DVI_FNT2 236 +#define DVI_FNT3 237 +#define DVI_FNT4 238 +#define DVI_XXX1 239 +#define DVI_XXX2 240 /* Extensions to DVI primitives */ +#define DVI_XXX3 241 +#define DVI_XXX4 242 +#define DVI_FNT_DEF1 243 /* Define the meaning of a font # */ +#define DVI_FNT_DEF2 244 +#define DVI_FNT_DEF3 245 +#define DVI_FNT_DEF4 246 +#define DVI_PRE 247 /* Beginning of preamble */ +#define DVI_POST 248 /* Beginning of postamble */ +#define DVI_POSTPOST 249 /* End of postamble */ +#define DVI_UNDEF0 250 +#define DVI_UNDEF1 251 +#define DVI_UNDEF2 252 +#define DVI_UNDEF3 253 +#define DVI_UNDEF4 254 +#define DVI_UNDEF5 255 + +#endif /* _DVI2PCL_DVI_INCLUDED */ diff --git a/dviware/dvi2pcl/dvi2pcl.1 b/dviware/dvi2pcl/dvi2pcl.1 new file mode 100644 index 0000000000..8e46b3e276 --- /dev/null +++ b/dviware/dvi2pcl/dvi2pcl.1 @@ -0,0 +1,235 @@ +.TH DVI2PCL 1 "" "" +.UC 4 +.SH NAME +dvi2pcl \- translate TeX DVI code to HP PCL printer code. +.SH SYNOPSIS +\fBdvi2pcl\fR [-12345lmrtv] [-c \fInnn\fR] [-d \fIdevice\fR] [-f \fInnn\fR] +[-o \fIoutfile\fR] +.br [-p \fInnn\fR] [-R \fIPCLresolution\fR] [-s \fInnn\fR] +[-x \fIfffdim\fR] [-X \fIfffdim\fR] [-y \fIfffdim\fR] +\fIfile\fR[\fB.dvi\fR] +.PP +.SH DESCRIPTION +\fIdvi2pcl\fR reads the TeX device independent file \fIfile\fB.dvi\fR +created by \fItex(1)\fR or \fIlatex(1)\fR, translates the device +independent (DVI) code to Printer Command Language (PCL) code, and sends +the output to standard output or, if the \fB-o\fR option is used, to the +file \fIoutfile\fR. If \fIfile\fR[\fB.dvi\fR] is not specified, +\fIdvi2pcl\fR reads from standard input. +.PP +.SH OPTIONS +.PD 0 +.TP 12 +.BI - n +Produces code for HP Printer Command Language (PCL) level \fIn\fR = +1, 2, 3, 4, or 5. Default = 4. + +.TP +.BI -c \ nnn +Prints \fInnn\fR < 100 copies. Note that the copies will not be +collated. Thus, a two page document with a request for ten copies will be +printed as ten copies of page one followed by ten copies of page two. + +.TP +.BI -d \ device +Produce optimized \fB.pcl\fR code for the PCL printer \fIdevice\fR. +Rudimentary support is included for the following \fIdevice\fRs: +\fBlj+\fR (HP LaserJet+), \fBlj2\fR (HP LaserJet II), \fBlj2d\fR (HP +LaserJet IID),\fBlj2p\fR (HP LaserJet IIP),\fBlj3si\fR (HP LaserJet +IIISi), \fBlj3p\fR (HP LaserJet IIIP),\fBpj\fR (HP PaintJet), and +\fBpjxl\fR (HP PaintJet XL). In fact, only \fBlj+\fR has any effect. This +flag overcomes certain hardware limitations (missing transparency mode) +in the LaserJet+. It is the user's responsibility to add the \fB-f\fR +flag to limit the number of soft fonts for the particular printer used. + +.TP +.BI -f \ nnn +Maximum number of soft fonts that can be downloaded. This option can be used +to overcome printer limitations. If the maximum number of downloadable +fonts is \fInnn\fR, all remaining fonts will be drawn in raster graphics +mode, restricted only by the printer memory. Avoid this option in +general for the whole document, since raster graphics drawing can be +very time consuming. Instead, use this option just for the special +pages on which this restriction will be relevant and print them +seperately by using the \fB-s \fInnn\fR and \fB-p\ 1\fR option. + +.TP +.B -l +Print the whole document in landscape mode (with the text running +parallel to the longest side of the page.) + +.TP +.B -m +Manual page feed. + +.TP +.BI -o \ outfile +Send the output to the output file \fIoutfile\fR. If \fB-o\fR is not +specified, the output will be sent to standard output. + +.TP +.BI -p \ nnn +Set the maximum number \fInnn\fR of pages to be printed. + +.TP +.BI -r +Toggle the sense of page output order (reverse/no reverse). + +.TP +.BI -R \ nnn +Set the PCL printer resolution to \fInnn\fR. + +.TP +.BI -s \ nnn +Select a starting page. Here \fInnn\fR can be a number, or, if the parameter is +enclosed in quotes, a splat. There can be up to ten fields, each one +corresponding to one of the count values in TeX. The first is normally the +page number. + +.TP +.BI -t +Select twosided printing. First, all even pages are printed with a +left offset chosen by the \fB-x\fR option. The output stack of paper +with the even pages occur in natural order, \fIi.e.\fR, the last even +page is on the top of the stack or it is a blank sheet if the last page +of the document has an odd number. There are two ways to print the odd +pages: (1) After the first pass, the printer is switched to `Manual +Feed' mode, so odd pages can be printed by feeding the sheets, with the +even pages printed on them, into the printer. (2) Flip the stack of +paper back into the paper cassette (with the printed side of paper +facing up and the top at the end of the cassette that enters the printer +first). Take the printer off line, press the `Manual Feed' switch to +exit the manual feed mode and put the printer on line again. After this +procedure the printer starts immediately, printing the odd pages from +the cassette. The final output is in natural order, \fIi.e.\fR, the +first page is facing up and is on the top of the output stack. The left +offset of the odd pages is determined by the \fB-X\fR option. + +.TP +.B -v +Enable verbose mode. + +.TP +.BI -x \ fffdim +Set the horizontal [left] offset for odd sides. \fIfff\fR can be any float +format and the allowed dimensions are: \fBi\fR[\fBn\fR] for inches, +\fBc\fR[\fBm\fR] for centimeter, \fBm\fR[\fBm\fR] for millimeter, +\fBp\fR[\fBt\fR] for points, and \fBd\fR[\fBot\fR] for dots. No space +may occur between \fIfff\fR and \fIdim\fR. + +.TP +.BI -X \ fffdim +Set the horizontal [left] offset for even sides. + +.TP +.BI -y \ fffdim +Set the vertical [top] offset. + +.SH TeX \\\\special COMMANDS +.PP +The following \fB\\special\fR commands are supported: +.PD +.TP +.BI file=\fIfile\fR +Directly include \fIfile\fR into the bit file. Tries to emulate the +command with the same name in Gustaf Neumann's \fIdvi2xx\fR driver. +Full path name required. + +.TP +.BI grafix(\fIrasterfile\ [resolution]\fB) +Include a graphics pixel file at the current location into the bit file. +The first argument \fIrasterfile\fR (required) is the external file +name. Arguments are separated by spaces. The \fIresolution\fR can be any of +600, 300, 180, 150, 90, and 75 dpi. The default resolution is 300 dpi. +The raster file must have the following format: +.br +short = number of pixel rows +.br +byte = flag (0 or 1) +.br +byte = number of pixel bytes per row if flag is 0 followed by the pixel +byte stream. If flag is 1, the next byte gives the length for the first +row, followed by the pixel bytes for the first row. The next byte then +is interpreted as the length of the second row followed by the pixel +bytes for the second row and so on. This restricts the max row length +to 255 bytes, but for the default resolution this is actually 13.6 +inches and still 6.8 inches for full resolution. + +.TP +.BI hpgl:\fIstring\fR +Produce vector graphics by inserting the HP/GL-2 command string +\fIstring\fR into the bit file. Terminate with a `;'. Works only for +PCL5 or higher. + +.TP +.BI include(\fIfile\fB) +Directly include \fIfile\fR into the bit file. Full path name required. + +.TP +.BI landscape +The result will be the same as produced by the \fB-l\fR option, but the +request for this mode is made already in the \fB.tex\fR file instead +by the driver option. No arguments. + +.TP +.BI move(\fIarguments\fB) +Move the current printer cursor position. Allowed \fIarguments\fR are +\fBh\fR[\fB=\fR]\fIfffdim\fR, \fBv\fR[\fB=\fR]\fIfffdim\fR, +\fBr\fR[\fBel\fR], and \fBa\fR[\fBbs\fR]. No space may occur between +\fBh\fR, \fBv\fR and \fB=\fR, or between \fB=\fR and \fIfff or \fBh\fR, +\fBv\fR and \fIfff\fR as between \fIfff\fR and \fIdim\fR. Allowed +dimensions are the same as for the offset options. Positioning is done +relative (\fBrel\fR) to the current cursor or absolute (\fBabs\fR) to +the upper left page corner. + +.TP +.BI orientation=\fInnn +Change the print direction of an arbitrary part of a page. The +following values \fInnn\fR are supported: \fB0\fR to rotate 0 +degrees, \fB1\fR or \fB90\fR to rotate 90 degrees, \fB2\fR or \fB180\fR +to rotate 180 degrees, \fB3\fR or \fB270\fR to rotate 270 degrees. +Tries to emulate the command with the same name in Gustaf Neumann's +\fIdvi2xx\fR driver. Works only for PCL5 or higher. + +.TP +.BI pcl:\fIstring\fR +Directly include the PCL string \fIstring\fR into the bit file. + +.TP +.BI pjxl:\fIcolor\fR +Set the color of the printed text to \fIcolor\fR where \fIcolor\fR is any of +\fBblack\fR, \fBred\fR, \fBgreen\fR, \fByellow\fR, \fBblue\fR, \fBmagenta\fR, +\fBcyan\fR or \fBwhite\fR. Requires color printer (PaintJet XL or compatible). + +.TP +.BI ps:\fIstring\fR +Directly include the raw PostScript string \fIstring\fR (including PS language +enable and disable commands) into the bit file. Requires PostScript support +in the printer. + +.TP +.BI rasterfile\ \fIstring\fR +Directly include the PCL string \fIstring\fR into the bit file. Tries to +emulate the command with the same name in Parag Patel's \fBdvi\fR. +.SH AUTHOR +.PP +\fIdvi2pcl\fR was written by Bo Thid\o'e\(aa' (bt@irfu.se) and is based on +\fIpkdvilj\fR written by Helmut Kopka (hk@linhp.gwdg.de). +.SH HARDWARE DEPENDENCIES +.PP +\fIdvi2pcl\fR generates specific bit raster code for HP PCL printers. It has +been tested on HP LaserJet printers and compatibles. +.SH FILES +.PP +/usr/local/bin/dvi2pcl +.br +/usr/local/lib/tex/reslj.fnt +.SH SEE ALSO +/usr/local/bin/[la]tex +.PP +.SH CAVEATS +.PP +This is an alpha version! +.SH WARNINGS AND BUGS +.PP +Bugs are expected to be present. Comments to bt@irfu.se. diff --git a/dviware/dvi2pcl/firstpar.c b/dviware/dvi2pcl/firstpar.c new file mode 100644 index 0000000000..2c2c79adf6 --- /dev/null +++ b/dviware/dvi2pcl/firstpar.c @@ -0,0 +1,136 @@ +/* $Log: firstpar.c,v $ + * Revision 0.8 92/11/23 19:46:45 19:46:45 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:29 02:41:29 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:45 21:47:45 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:32 16:25:32 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:48 02:45:48 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:40 12:45:40 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:57 17:28:57 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: firstpar.c,v 0.8 92/11/23 19:46:45 bt Exp $"; + +/* + * This routine computes the first parameter of each dvi opcode. + */ +long firstpar(dvifile, k) +FILE *dvifile; +int k; +{ + switch (k) + { + case DVI_SET1: + case DVI_PUT1: + case DVI_FNT1: + case DVI_XXX1: + case DVI_FNT_DEF1: + return((long)getubyte(dvifile)); + break; + case DVI_SET2: + case DVI_PUT2: + case DVI_FNT2: + case DVI_XXX2: + case DVI_FNT_DEF2: + return((long)getupair(dvifile)); + break; + case DVI_SET3: + case DVI_PUT3: + case DVI_FNT3: + case DVI_XXX3: + case DVI_FNT_DEF3: + return((long)getutrio(dvifile)); + break; + case DVI_RIGHT1: + case DVI_W1: + case DVI_X1: + case DVI_DOWN1: + case DVI_Y1: + case DVI_Z1: + return((long)getsbyte(dvifile)); + break; + case DVI_RIGHT2: + case DVI_W2: + case DVI_X2: + case DVI_DOWN2: + case DVI_Y2: + case DVI_Z2: + return((long)getspair(dvifile)); + break; + case DVI_RIGHT3: + case DVI_W3: + case DVI_X3: + case DVI_DOWN3: + case DVI_Y3: + case DVI_Z3: + return((long)getstrio(dvifile)); + break; + case DVI_SET4: + case DVI_SET_RULE: + case DVI_PUT4: + case DVI_PUT_RULE: + case DVI_RIGHT4: + case DVI_W4: + case DVI_X4: + case DVI_DOWN4: + case DVI_Y4: + case DVI_Z4: + case DVI_FNT4: + case DVI_XXX4: + case DVI_FNT_DEF4: + return((long)getsquad(dvifile)); + break; + case DVI_NOP: + case DVI_BOP: + case DVI_EOP: + case DVI_PUSH: + case DVI_POP: + case DVI_PRE: + case DVI_POST: + case DVI_POSTPOST: + case DVI_UNDEF0: + case DVI_UNDEF1: + case DVI_UNDEF2: + case DVI_UNDEF3: + case DVI_UNDEF4: + case DVI_UNDEF5: + return(0); + break; + case DVI_W0: + return(w); + break; + case DVI_X0: + return(x); + break; + case DVI_Y0: + return(y); + break; + case DVI_Z0: + return(z); + break; + default: + if((k >= DVI_FNT_NUM_0) && (k <= DVI_FNT_NUM_63)) + return((long)(k - DVI_FNT_NUM_0)); + break; + } +} diff --git a/dviware/dvi2pcl/freebug b/dviware/dvi2pcl/freebug new file mode 100644 index 0000000000..2bed2e1dcb --- /dev/null +++ b/dviware/dvi2pcl/freebug @@ -0,0 +1,20 @@ +I have just discovered a bug in 'dvi2pcl', version 0.8. The bug was introduced +as the result of a "quick and dirty" addition of free() in cachefonts.c +where I added, without enough testing, the following lines: + + /* Release malloc'ed memory */ + for(n = fontnum-1 ; n >= 0 ; n--) { + f = fontlist[n]; + free(fontptr[f]); + } + +Please remove them again or you may run into severe problems! I will try +better next time... (blush). + +Bo +-- + ^ Bo Thide'----------------------------------------------Science Director + |I| Swedish Institute of Space Physics, S-755 91 Uppsala, Sweden + |R| Phone: (+46) 18-303671. Fax: (+46) 18-403100. IP: 130.238.30.23 + /|F|\ INTERNET: bt@irfu.se UUCP: ...!mcvax!sunic!irfu!bt + ~~U~~ ----------------------------------------------------------------sm5dfw- diff --git a/dviware/dvi2pcl/getcount.c b/dviware/dvi2pcl/getcount.c new file mode 100644 index 0000000000..a817c7a3d3 --- /dev/null +++ b/dviware/dvi2pcl/getcount.c @@ -0,0 +1,49 @@ +/* $Log: getcount.c,v $ + * Revision 0.8 92/11/23 19:46:46 19:46:46 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:30 02:41:30 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:46 21:47:46 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:34 16:25:34 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:49 02:45:49 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:41 12:45:41 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:57 17:28:57 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include "globals.h" + +static char rcsid[] = "$Header: getcount.c,v 0.8 92/11/23 19:46:46 bt Exp $"; + +/* + * Converts string to integer and returns the integer while p is updated to + * the first non digit charcter in string *p + */ +getcount(p) +char *p; +{ + int negative; + int x; + if(*p == '-') + { + negative = TRUE; + p++; + } + else negative = FALSE; + x = 0; + while((*p >= '0') && (*p <= '9')) x = 10*x + *p++ - '0'; + return(negative ? -x : x); +} diff --git a/dviware/dvi2pcl/getoptions.c b/dviware/dvi2pcl/getoptions.c new file mode 100644 index 0000000000..8bc8e5f86a --- /dev/null +++ b/dviware/dvi2pcl/getoptions.c @@ -0,0 +1,242 @@ +/* $Log: getoptions.c,v $ + * Revision 0.8 92/11/23 19:46:46 19:46:46 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:30 02:41:30 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:47 21:47:47 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:34 16:25:34 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:50 02:45:50 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:41 12:45:41 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:57 17:28:57 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include "globals.h" + +static char rcsid[] = "$Header: getoptions.c,v 0.8 92/11/23 19:46:46 bt Exp $"; + +/* + * Put the selected options into global variables +*/ + +getoptions(argc, argv, envp, bitname, dviname, usgname, + pcllevel, numcopies, device, maxdown, outreverse, resolution, twosided) +int argc; +char **argv; +char **envp; +char bitname[]; +char dviname[]; +char usgname[]; +short *pcllevel; +short *numcopies; +short *device; +short *maxdown; +bool *outreverse; +short *resolution; +short *twosided; +{ + char buffer[1024]; + char *bufptr; + char *strptr; + int k; + int c, errflag=0; + extern char *optarg; + extern int optind; + + strcpy(bitname,""); + verbose = FALSE; + + while ((c = getopt(argc, argv, "12345c:d:f:lmo:p:rR:s:tvx:X:y:?")) != EOF) + + switch (c) { + case '1': /* PCL level 1 */ + case '2': /* PCL level 2 */ + case '3': /* PCL level 3 */ + case '4': /* PCL level 4 */ + case '5': /* PCL level 5 */ + *pcllevel = -(short)atoi(argv[optind-1]); + break; + case 'c': /* Number of copies of each page */ + if((*numcopies = (short)atoi(optarg)) <= 0) + *numcopies = 1; + break; + case 'd': /* Specify output device */ + if(strcmp(optarg,"lj+") == 0) + *device = DEV_LJPLUS; + else if (strcmp(optarg,"lj2") == 0) + *device = DEV_LJ2; + else if (strcmp(optarg,"lj2d") == 0) + *device = DEV_LJ2D; + else if (strcmp(optarg,"lj2p") == 0) + *device = DEV_LJ2P; + else if (strcmp(optarg,"lj3si") == 0){ + *device = DEV_LJ3SI; + *pcllevel = 5; + } + else if (strcmp(optarg,"lj3p") == 0){ + *device = DEV_LJ3P; + *pcllevel = 5; + } + else if (strcmp(optarg,"pj") == 0) + *device = DEV_PJ; + else if (strcmp(optarg,"pjxl") == 0) + *device = DEV_PJXL; + break; + case 'f': /* Max number of downloadable fonts */ + + if((*maxdown = (short)atoi(optarg)) < 0) + *maxdown = 32; + break; + case 'l': /* Landscape mode flag */ + landscape = TRUE; + break; + case 'm': /* Manual feed flag */ + manualfeed = TRUE; + break; + case 'o': /* Output file name */ + strcpy(bitname, optarg); + break; + case 'p': /* Max number of output pages */ + if((maxpages = atoi(optarg)) <= 0) + maxpages = MAXPAGES; + break; + case 'r': /* Reverse output order flag */ + *outreverse *= *outreverse; + break; + case 'R': /* Set PCL resolution */ + *resolution = (short)atoi(optarg); + break; + case 's': /* Start page */ + startvals = 0; + startthere[0] = FALSE; + strcpy(buffer,optarg); + bufptr = buffer; + k = 0; + do { + if(*bufptr == '*') { + startthere[k] = FALSE; + bufptr++; + } + else { + startthere[k] = TRUE; + startcount[k] = (long)getcount(bufptr); + } + + if((k<9) && (*bufptr == '.')) { + k++; + bufptr++; + } + else + if((*bufptr==' ')||(*bufptr=='\0')) + startvals = k; + else { + startvals = 0; + k = 0; + } + } while(startvals != k); + break; + case 't': /* Two-sided mode flag */ + *twosided = TRUE; + break; + case 'v': /* Verbose mode flag */ + verbose = TRUE; + break; + case 'x': /* Left offset for odd sides */ + h_offset = dim_to_dots(optarg, resolution); + break; + case 'X': /* Left offset for even sides */ + r_offset = dim_to_dots(optarg, resolution); + break; + case 'y': /* Vertical top offset */ + v_offset = dim_to_dots(optarg, resolution); + break; + case '?': + errflag++; + break; + default: + break; + } + + if (errflag) { + fprintf(stderr, "\nUsage: %s [-12345lmrt] [-c <copies>] [-f <fonts>] [-o <outfile>]\n [-p <pages>] [-R resolution] [-s <startpage>] [-x <offset>]\n [-X <offset>] [-y <offset>] [<infile>]\n", argv[0]); + exit(2); + } + + /* + * Allow for input file names of type + * xx.dvi, xx.yy.dvi, xx, or xx.yy + * Append ".dvi" if it's not already there. + * + * Get the .dvi file name from the input line + */ + strcpy(dviname, argv[optind]); + if((strstr(dviname, DVIFILE_SUFFIX)) == NULL) + strcat(dviname, DVIFILE_SUFFIX); + + /* + * Allow for output file names of type; + * xx.pcl, xx.yy.pcl, xx, or xx.yy + * Append ".pcl" if it's not already there. + * + * The .dvi file name was input via the -o option. + if((strstr(bitname, BITFILE_SUFFIX)) == NULL) + strcat(bitname, BITFILE_SUFFIX); + */ + + if(verbose) { + strcpy(usgname, dviname); + strcat(usgname, USGFILE_SUFFIX); + } + + if(*twosided) { + if(!startvals && !(startcount[0] % 2)) { + if(startthere[0]) + startcount[0]--; + else { + startthere[0] = TRUE; + startcount[0] = 1; + } + } + if(maxpages % 2) + maxpages++; + o_offset = h_offset; + e_offset = r_offset; + } + + if(verbose) { + fprintf(stderr,"Options selected:\n"); + fprintf(stderr,"Starting page: "); + for(k=0; k<=startvals; k++) { + if(startthere[k]) + fprintf(stderr,"%d",startcount[k]); + else + fprintf(stderr,"*"); + if(k<startvals) + fprintf(stderr,"."); + else + fprintf(stderr,"\n"); + } + fprintf(stderr,"Maximum numbers of pages: %d\n",maxpages); + fprintf(stderr,"Number of copies: %d\n",*numcopies); + if(*twosided) + fprintf(stderr,"Two-sided printing\n"); + if(manualfeed) + fprintf(stderr,"Feed pages maually\n"); + } +} diff --git a/dviware/dvi2pcl/globals.h b/dviware/dvi2pcl/globals.h new file mode 100644 index 0000000000..b6b8bc0a01 --- /dev/null +++ b/dviware/dvi2pcl/globals.h @@ -0,0 +1,272 @@ +/* $Log: globals.h,v $ + * Revision 0.8 92/11/23 19:47:02 19:47:02 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:17 02:41:17 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:43 21:48:43 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:50 16:25:50 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:06 02:46:06 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:17 12:43:17 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:53 17:28:53 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * + */ + +#ifndef _DVI2PCL_GLOBALS_INCLUDED +#define _DVI2PCL_GLOBALS_INCLUDED + +#define BANNER "TeX Dvi to HP Print Command Language translator dvi2pcl 0.7.\n" +#define BITFILE_SUFFIX ".pcl" /* Bit file suffix */ +#define BLACKBYTE '\377' +#define DEV_LJPLUS 0 +#define DEV_LJ2 1 +#define DEV_LJ2D 2 +#define DEV_LJ2P 3 +#define DEV_LJ3SI 4 +#define DEV_LJ3P 5 +#define DEV_PJ 10 +#define DEV_PJXL 11 +#define DVIFILE_SUFFIX ".dvi" /* Dvi file suffix */ +#define DYNAMICFONTBASE 256 /* Start value for internal font #'s */ +#define FALSE 0 +#define FIX (1 << 20) +#define FMASK 7 +#define FONTPATH "/%dpt/%s.%d" /* Where to look for fonts */ +#define HOFFSET 200 +#define INFINITY 0x7FFFFFFF +#define MAXCHEIGHT 128 /* Max character height for printer */ +#define MAXCWIDTH 128 /* Max character width for printer */ +#define MAXDOWN 128 /* Max number of downloadable fonts */ +#define MAXDRIFT 2 /* Max dots rounding error */ +#define MAXFONTS 256 /* Max # of fonts to be used */ +#define MAXPAGES 1000 /* Max # of pages of the document */ +#define MAXPKSIZE 65536 /* Max .pk buffer size */ +#define MAXPXLSIZE 65536 /* Max .pxl buffer size */ +#define MINPRINTERMEM 122880 /* 120 KByte */ +#define NAMELENGTH 255 /* Max length of file names */ +#define NAMESIZE 4096 /* Max texbtuffer size for names */ +#define NULL 0 +#define PCLLEVEL 4 /* Default PCL level (old LaserJets) */ +#define PRESCAN_OFF 0 /* Not in the prescan cycle */ +#define PRESCAN_ON 1 /* In the prescan cycle */ +#define RESOLUTION 300 +#define SCALE 75780587.52 /* 72.27*2**20 */ +#define STACKSIZE 100 +#define TERMLINELENGTH 80 +#define TRUE 1 +#define USGFILE_SUFFIX ".usg" /* Usage (log) file suffix */ +#define VOFFSET 150 +#define WHITEBYTE '\0' + + +/* Global type definitions */ + +typedef char byte; +typedef unsigned char ubyte; +typedef unsigned char bool; + +#ifdef TRUE +#include <sys/types.h> +#else +typedef unsigned short ushort; +typedef unsigned int uint; +#endif /* TRUE */ + +/* PCL font descriptor */ +typedef struct { + ushort size; + ubyte descriptor; + ubyte font_type; + ubyte style_MSB; + byte reserved; + ushort baseline; + ushort cell_width; + ushort cell_height; + ubyte orientation; + bool spacing; + ushort symbol_set; + ushort pitch; + ushort height; + ushort x_height; + byte width_type; + ubyte style_LSB; + byte stroke_weight; + ubyte typeface_LSB; + ubyte typeface_MSB; + ubyte serif_style; + ubyte quality; + byte placement; + byte underl_dist; + ubyte underl_height; + ushort text_height; + ushort text_width; + ushort first_code; + ushort last_code; + ubyte pitch_ext; + ubyte height_ext; + ushort cap_height; + uint font_number; + char font_name[16]; + } fdfmt; + +/* PCL character descriptor */ +typedef struct { + ubyte format; + bool continuation; + ubyte size; + ubyte class; + ubyte orientation; + byte reserved; + short left_offset; + short top_offset; + ushort char_width; + ushort char_height; + short delta_x; + } cdfmt; + +/* Internal character information */ +typedef struct { + short pk_char; + long pxl_width; + long tfm_width; + long use_count; + } charfmt; + +/* Internal font information */ +typedef struct { + long checksum; + long scaled_size; + long design_size; + long space; + short dir_size; + double height; + short down; + short name; + short bc; + short ec; + charfmt chr[256]; + } fontfmt; + +/* Internal graphic char information */ +typedef struct { + short pxl_bytes; + short pxl_rows; + long x_offset; + long y_offset; + byte *pxl_pattern; + } gcharfmt; + +typedef gcharfmt (*gfontfmt)[256]; /* Internal graphic font information */ + +/* Header part of .tfm files */ +typedef struct { + short lf; + short lh; + short bc; + short ec; + short nw; + short nh; + short nd; + short ni; + short nl; + short nk; + short ne; + short np; + long cs; + long ds; + } tfmfmt; + +/* Printer name and capabilities */ +typedef struct { + long mem; + char name[16]; + char lang[8]; + } prtfmt; + +/* Global variables in alphabetical order */ +int actualpagecount; +cdfmt cd; /* character descriptor */ +charfmt *cbase; +double conv; +double convpxl; +double convtfm; +long count[10]; +int c_black; +int c_flag; +int c_height; +int c_hoffset; +int c_nib; +int c_voffset; +int c_width; +long denominator; +charfmt *drawchar(); +int dyn_f; +byte *endofchardata; +int e_offset; +fdfmt fd; /* font descriptor */ +long firstpage; +long firstpar(); +fontfmt *font; +int fontpathlen; +fontfmt *fontptr[MAXFONTS]; +gfontfmt gfont; +gfontfmt gfontptr[MAXFONTS]; +bool inpostamble; +long h_offset; +bool h_posed; +int landscape; +long lastpage; +long magnification; +int manualfeed; +long maxh; +int maxs; +long maxv; +long maxhsofar; +int maxssofar; +long maxvsofar; +int maxpages; +int max_depth; +int max_width; +int max_offset; +char names[NAMESIZE]; +int nextfontdown; +char *nextnamesfree; +long numerator; +int o_offset; +short outreverse; +byte *pkbase; +long pkbuffer[MAXPKSIZE]; +byte *pkcharinfo(); +char pkfixname[NAMELENGTH]; +char pkname[NAMELENGTH]; +byte *pk_ptr; +long power[8]; +long prevpage; +prtfmt printer; +long printermem_used; +byte pxlbuffer[MAXPXLSIZE]; +int r_offset; +int s; +long startcount[10]; +int startthere[10]; +int startvals; +long v_offset; +bool v_posed; +bool verbose; + +long h, v, w, x, y, z; + +#endif /* _DVI2PCL_GLOBALS_INCLUDED */ diff --git a/dviware/dvi2pcl/hiscatlogo.pcl b/dviware/dvi2pcl/hiscatlogo.pcl Binary files differnew file mode 100644 index 0000000000..8486c97bf0 --- /dev/null +++ b/dviware/dvi2pcl/hiscatlogo.pcl diff --git a/dviware/dvi2pcl/hpgl.tex b/dviware/dvi2pcl/hpgl.tex new file mode 100644 index 0000000000..9a3d62fe34 --- /dev/null +++ b/dviware/dvi2pcl/hpgl.tex @@ -0,0 +1,8 @@ +\documentstyle[]{article} +\pagestyle{empty} + +\begin{document} +dvi2pcl +\special{hpgl:DF;SP1;PW0.05;SC0,2400,0,3300,1;PU0,0;PD100,1500;FT10,11;CF3; +SD1,21,2,1,4,180,5,1,6,0,7,4101;DT!;LBdvi2pcl!;} +\end{document} diff --git a/dviware/dvi2pcl/initialize.c b/dviware/dvi2pcl/initialize.c new file mode 100644 index 0000000000..bb65c62c87 --- /dev/null +++ b/dviware/dvi2pcl/initialize.c @@ -0,0 +1,143 @@ +/* $Log: initialize.c,v $ + * Revision 0.8 92/11/23 19:46:47 19:46:47 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:31 02:41:31 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:47 21:47:47 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:35 16:25:35 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:50 02:45:50 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:42 12:45:42 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:57 17:28:57 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "paths.h" + +static char rcsid[] = "$Header: initialize.c,v 0.8 92/11/23 19:46:47 bt Exp $"; + +/* + * Get all variables initialized + */ + +initialize() +{ + int i,j; + int linelength=80; + char *cols; + + if(verbose) + fprintf(stderr,BANNER); + for(i=0; i<MAXFONTS; i++) { + fontptr[i] = NULL; + gfontptr[i] = NULL; + } + pkbase = (byte *)pkbuffer; +#ifdef DEBUG + fprintf(stderr,"initialize: pkbase = %d\n", &pkbase); +#endif /* DEBUG */ + nextnamesfree = names + 1; + verbose = FALSE; + maxpages = MAXPAGES; + startvals = 0; + startthere[0] = FALSE; + inpostamble = FALSE; + maxv = INFINITY - 99; + maxh = INFINITY - 99; + maxs = STACKSIZE + 1; + maxvsofar = 0; + maxhsofar = 0; + maxssofar = 0; + h_posed = FALSE; + v_posed = FALSE; + h_offset = HOFFSET; + r_offset = HOFFSET; + v_offset = VOFFSET; + + lastpage = -1; + prevpage = -1; + actualpagecount = 0; + nextfontdown = DYNAMICFONTBASE; + printermem_used = 0; + landscape = FALSE; + manualfeed = FALSE; + + /* Initialize font descriptor data */ + fd.size = 64; + fd.descriptor = 0; + fd.font_type = 2; + fd.style_MSB = 0; + fd.reserved = 0; + fd.baseline = 0; + fd.cell_width = 1; + fd.cell_height = 1; + fd.orientation = 0; + fd.spacing = 1; + fd.symbol_set = 2048; /* Largest allowed value + 1 */ + fd.pitch = 1; + fd.height = 1; + fd.x_height = 0; + fd.width_type = 0; + fd.style_LSB = 0; + fd.stroke_weight = 0; + fd.typeface_LSB = 0; + fd.typeface_MSB = 0; + fd.serif_style = 128; /* Serif */ + fd.quality = 0; + fd.placement = 0; + fd.underl_dist = 0; + fd.underl_height = 0; + fd.text_height = 0; + fd.text_width = 0; + fd.first_code = 1; + fd.last_code = 255; + fd.pitch_ext = 0; + fd.height_ext = 0; + fd.cap_height = 0; + fd.font_number = 0; + strcpy(fd.font_name,"-TeX dvi font-"); + + /* Initialize character descriptor data */ + cd.format = 4; + cd.continuation = 0; + cd.size = 14; + cd.class = 1; + cd.orientation = 0; + cd.reserved = 0; + cd.left_offset = 0; + cd.top_offset = 0; + cd.char_width = 0; + cd.char_height = 0; + cd.delta_x = 0; + + j = 1; + for(i=0 ; i<8; i++) + { + power[i] = (long)j; + j <<= 1; + } + + /* Take a stab at line length (SYSVish) */ + if ((cols = (char *)getenv("COLUMNS")) != NULL){ + sscanf(cols, " %d", &linelength); + if(linelength > 500) linelength = 500; + if(linelength < 20) linelength = 20; + } + + strcpy(pkfixname,fontpath); + fontpathlen = strlen(pkfixname); +} diff --git a/dviware/dvi2pcl/loadpkfile.c b/dviware/dvi2pcl/loadpkfile.c new file mode 100644 index 0000000000..269569b4c7 --- /dev/null +++ b/dviware/dvi2pcl/loadpkfile.c @@ -0,0 +1,69 @@ +/* $Log: loadpkfile.c,v $ + * Revision 0.8 92/11/23 19:46:48 19:46:48 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:32 02:41:32 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:48 21:47:48 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:36 16:25:36 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:52 02:45:52 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:43 12:45:43 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:57 17:28:57 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* + * Here is a procedure that reads the .pk file into 'pkbuffer'. Other than + * insuring that the initial two bytes are 247 and 89 (the pk_pre command, + * followed by the current .pk format identifier), it does no format checks. + * If the corresponding .pk file doesn't fit into pkbuffer, 'dvi2pcl' will be + * aborted. In this case MAXPKSIZE has to be increased by an appropriate + * amount and 'dvi2pcl' has to be recompiled. At this state the choosen value + * of MAXPKSIZE will serve all existing .pk files but for future .pk font + * files this might happen. + */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" +#include "pk.h" + +static char rcsid[] = "$Header: loadpkfile.c,v 0.8 92/11/23 19:46:48 bt Exp $"; + +extern FILE *openpkfile(); + +void loadpkfile() +{ + FILE *pkfile; + long *pkptr; + byte *p; + + pkfile = openpkfile(); + pkptr = pkbuffer; + p = (byte *) pkptr; + if(verbose) + fprintf(stderr,"Trying to load %s\n",pkname); + *pkptr++ = (long)getw(pkfile); + if((getpubyte(p) != PK_PRE) || (getpubyte(p) != PK_ID)) + fprintf(stderr,".pk file corrupt -- not loaded\n"); + else { + while((*pkptr++ = (long)getw(pkfile)) != EOF) { + if(pkptr - pkbuffer >= MAXPKSIZE) + prerror("Memory size exceeded when loading .pk file\n"); + } + font->down = -2; + } + fclose(pkfile); +} diff --git a/dviware/dvi2pcl/loadtfmfile.c b/dviware/dvi2pcl/loadtfmfile.c new file mode 100644 index 0000000000..d4329177ab --- /dev/null +++ b/dviware/dvi2pcl/loadtfmfile.c @@ -0,0 +1,93 @@ +/* $Log: loadtfmfile.c,v $ + * Revision 0.8 92/11/23 19:46:48 19:46:48 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:33 02:41:33 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:49 21:47:49 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:37 16:25:37 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:52 02:45:52 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:20 12:43:20 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:58 17:28:58 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: loadtfmfile.c,v 0.8 92/11/23 19:46:48 bt Exp $"; + + +/* + * This procedure will extract information from the tfm file which is + * necessary to know abut printer resident fonts. + */ +loadtfmfile() +{ + byte *w_index; + char tfmbuf[2048]; + char tfmname[NAMELENGTH]; + int i; + int *width; + long *t; + long *tfmbase; + double x, z; + double pxlconv; + charfmt *c; + tfmfmt *tfm; + FILE *tfmfile; + extern FILE *opentfmfile(); + + tfm = (tfmfmt *) tfmbuf; + tfmbase = (long *) tfmbuf; + t = tfmbase; + tfmfile = opentfmfile(tfmname); + if(verbose) + fprintf(stderr,"loadtfmfile: Trying to load %s\n",tfmname); + while(!feof(tfmfile)) + *t++ = (long)getw(tfmfile); + fclose(tfmfile); + if(font->checksum != tfm->cs) + fprintf(stderr,"loadtfmfile: Checksum mismatch between\n%s and the .dvi file\n", tfmname); + z = (double)font->scaled_size/(double)FIX; + pxlconv = (double)(font->design_size * font->dir_size)/(65536.0*SCALE); + width = (int *)(tfmbase + tfm->lh + tfm->ec - tfm->bc + 7); + w_index = tfmbuf + 4 * (tfm->lh + 6); + c = font->chr; +#ifdef DEBUG2 + fprintf(stderr,"loadtfmfile: pxlconv=%g,tfm->bc=%d,tfm->ec=%d,tfm->lh = %d\n",pxlconv,tfm->bc,tfm->ec,tfm->lh); +#endif + for(i = 0 ; i < tfm->bc ; i++) { + c->tfm_width = 0; + c->pxl_width = 0; + c++; + } + for(i = tfm->bc; i <= tfm->ec; i++) { + x = *(width + *w_index); + c->tfm_width = x*z; + c->pxl_width = round(x*pxlconv); + c++; + w_index += 4; +#ifdef DEBUG2 + fprintf(stderr,"loadtfmfile: pxlconv=%d,tfm->bc=%d,tfm->ec=%d,c->pxl_width = %d\n",pxlconv,tfm->bc,tfm->ec,c->pxl_width); +#endif + } + for(i = tfm->ec + 1 ; i <= 255; i++) { + c->tfm_width = 0; + c->pxl_width = 0; + c++; + } +} diff --git a/dviware/dvi2pcl/macros.h b/dviware/dvi2pcl/macros.h new file mode 100644 index 0000000000..2dc47421e9 --- /dev/null +++ b/dviware/dvi2pcl/macros.h @@ -0,0 +1,64 @@ +/* $Log: macros.h,v $ + * Revision 0.8 92/11/23 19:47:03 19:47:03 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:18 02:41:18 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:44 21:48:44 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:50 16:25:50 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:07 02:46:07 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:29 12:45:29 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:53 17:28:53 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +/* Use the "," operator to ensure proper evaluation order */ +/* Help to fix bugs from Joel M. Hoffman <joel@wam.umd.edu> */ + +#ifndef _DVI2PCL_MACROS_INCLUDED +#define _DVI2PCL_MACROS_INCLUDED + +long _i; +/* Get unsigned one-, two-, three-, or four-byte values from a file "f" */ +#define getubyte(f) (unsigned char)getc(f) +#define getupair(f) (_i=getubyte(f),_i<<=8,_i|=getubyte(f)) +#define getutrio(f) (getupair(f),_i<<=8,_i|=getubyte(f)) + +/* Get signed one-, two-, three-, or four-byte values from a file "f" */ +#define getsbyte(f) (char)getc(f) +#define getspair(f) (_i=getsbyte(f),_i<<=8,_i|=getubyte(f)) +#define getstrio(f) (getspair(f),_i<<=8,_i|=getubyte(f)) +#define getsquad(f) (getstrio(f),_i<<=8,_i|=getubyte(f)) + +/* Get unsigned one-, two-, three-, or four-byte values from a pointer "p" */ +#define getpubyte(p) ((unsigned char)*p++) +#define getpupair(p) (_i=getpubyte(p),_i<<=8,_i|=getpubyte(p)) +#define getputrio(p) (getpupair(p),_i<<=8,_i|=getpubyte(p)) +#define getpuquad(p) (getputrio(p),_i<<=8,_i|=getpubyte(p)) + +/* Get signed one-, two-, three-, or four-byte values from a pointer "p" */ +#define getpsbyte(p) ((char)*p++) +#define getpspair(p) (_i=getpsbyte(p),_i<<=8,_i|getpubyte(p)) +#define getpstrio(p) (getpupair(p),_i<<=8,_i|getpubyte(p)) +#define getpsquad(p) (getputrio(p),_i<<=8,_i|getpubyte(p)) + +double _f; +#define round(f) (long)((_f = (f)) < 0.0 ? _f - 0.5 : _f + 0.5) + +/* +#define rulepixels(x) (!(_a = round(convdot * x)) ? 1 : _a) +*/ + +#endif /* _DVI2PCL_MACROS_INCLUDED */ diff --git a/dviware/dvi2pcl/main.c b/dviware/dvi2pcl/main.c new file mode 100644 index 0000000000..d77b4d322f --- /dev/null +++ b/dviware/dvi2pcl/main.c @@ -0,0 +1,214 @@ +/* $Log: main.c,v $ + * Revision 0.8 92/11/23 19:46:49 19:46:49 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:34 02:41:34 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:50 21:47:50 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:37 16:25:37 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:53 02:45:53 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:44 12:45:44 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:58 17:28:58 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#pragma COPYRIGHT "Bo Thide' and Helmut Kopka, 1992" +#include <stdio.h> +#include <string.h> +#include "globals.h" +#include "paths.h" +#include "pcl.h" + +static char rcsid[] = "$Header: main.c,v 0.8 92/11/23 19:46:49 bt Exp $"; + +static char fatal_error[] = "This was a fatal error.\n"; +static char copyright[] = "Copyright (c) Bo Thide' and Helmut Kopka, 1992."; + +#ifdef TIMING +#include <sys/timeb.h> +#endif /* TIMING */ + +main(argc, argv, envp) +int argc; +char **argv; +char **envp; +{ + char bitname[NAMELENGTH]; + char curname[NAMELENGTH]; + char dviname[NAMELENGTH]; + char usgname[NAMELENGTH]; + bool outreverse=TRUE; + short device=DEV_LJPLUS; + short maxdown=MAXDOWN; + short numcopies=1; + short pcllevel=PCLLEVEL; + short resolution=RESOLUTION; + short twosided=FALSE; + long startloc=0; + FILE *bitfile; + FILE *dvifile; + FILE *resfile; + FILE *usgfile; + +#ifdef TIMING + struct timeb timebuffer; + double start_time, time; + + ftime(&timebuffer); + start_time = (double)((timebuffer.time) + (timebuffer.millitm)/1000.0); +#endif /* TIMING */ + + /* Get things started properly */ + initialize(); + + /* Process all dvi2pcl options and construct the filenames. */ + getoptions(argc, argv, envp, bitname, dviname, usgname, + &pcllevel, &numcopies, &device, &maxdown, &outreverse, + &resolution, &twosided); + + /* + * Open the output bitfile or, if bitname is an empty string, stdout. + */ + if(strcmp(bitname, "") == 0) { + bitfile = stdout; + } + else { + if((bitfile = fopen(bitname,"w")) == NULL) { + fprintf(stderr,"Cannot open the bit file %s for output.\n", bitname); + exit(-1); + } + } + + /* + * Open the input dvifile or stdin. + */ + if(strcmp(dviname, DVIFILE_SUFFIX) == 0) { + dvifile = stdin; + } + else { + if((dvifile = fopen(dviname,"r")) == NULL) { + fprintf(stderr,"Cannot open the dvi file %s for input.\n", dviname); + exit(-1); + } + } + + /* + * Open the input resident font info file + */ + strcpy(curname, respath); + if((resfile = fopen(curname,"r")) == NULL) { + fprintf(stderr,"Cannot open the resident font file %s for input.\n", curname); + exit(-1); + } + + /* Prescan the input file. */ + preamble(dvifile, resolution); + startloc = skippages(bitfile, dvifile, pcllevel, resolution); + if(!inpostamble){ + /* If not in postamble, prescan the file up to maxpages */ + while(maxpages-- > 0){ + /* Prescan up to maxpages or postamble */ + prescanpage(bitfile, dvifile, pcllevel, resolution); + if(inpostamble){ + postamble(dvifile); + break; /* font_def agreement */ + } + if(!betweenpages(dvifile, PRESCAN_ON)) + break; + } + } + + /* Initialize the printer */ + fprintf(bitfile, PCL4_INIT_PRINTER); + fprintf(bitfile, PCL4_COPIES, numcopies); + fprintf(bitfile, PCL4_RESOLUTION, resolution); + fprintf(bitfile, PCL5_PRINT_DIRECTION, 0); + + /* Download the defined fonts */ + cachefonts(bitfile, resfile, maxdown, device); + + /* Now do the main work */ + if(twosided) + doodevpages(bitfile, dvifile, pcllevel, outreverse, + resolution, device); + else + doallpages(bitfile, dvifile, pcllevel, outreverse, + resolution, device); + fprintf(bitfile, PCL4_CLEAN_PRINTER); + +#ifdef TIMING + ftime(&timebuffer); + time = ((timebuffer.time) + (timebuffer.millitm)/1000.0) + -start_time; + fprintf(stderr,"Time of complete run: %.3lf sec, %.3lf sec/page (%.2lf ppm)\n", + time, time/actualpagecount, (double)(actualpagecount*60)/time); +#endif /* TIMING */ + + + if(verbose){ + fprintf(stderr,"%s done.\n",argv[0]); + if((usgfile = fopen(usgname,"w")) == NULL) { + fprintf(stderr,"Cannot open the output file %s\n", usgname); + exit(-1); + } + diagnostics(usgfile); + } + + exit(0); +} + +/* + * Error and die routines. + * Print error messages and exits. + */ + +prerror(s) +char *s; +{ + fprintf(stderr,s); + fprintf(stderr,fatal_error); + fflush(stderr); + exit(-1); +} + +void sterror(s, st) +char *s; +char *st; +{ + fprintf(stderr,s, st); + fprintf(stderr,fatal_error); + fflush(stderr); + exit(-1); +} + +valerror(s,v) +char *s; +int v; +{ + fprintf(stderr,s,v); + fprintf(stderr,fatal_error); + fflush(stderr); + exit(-1); +} + +valvalerror(s,u,v) +char *s; +int u,v; +{ + fprintf(stderr,s,u,v); + fprintf(stderr,fatal_error); + fflush(stderr); + exit(-1); +} diff --git a/dviware/dvi2pcl/makepkdir.c b/dviware/dvi2pcl/makepkdir.c new file mode 100644 index 0000000000..fd0eec0214 --- /dev/null +++ b/dviware/dvi2pcl/makepkdir.c @@ -0,0 +1,120 @@ +/* $Log: makepkdir.c,v $ + * Revision 0.8 92/11/23 19:46:50 19:46:50 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:34 02:41:34 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:50 21:47:50 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:38 16:25:38 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:54 02:45:54 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:20 12:43:20 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:58 17:28:58 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * The coding scheme for the different characters in .pk files in general are + * not stored in ascending order of the ascii value of the character. Access + * to an individual character would need a lot of searching within the + * pk buffer. So it is wise, to make a directory for all of the characters + * in the .pk font which holds a pointer to the flag byte for each of the + * characters when the pkfont is loaded the first time. These pointers are + * relative to 'pkbase' and stored into '(cbase + c)->pk_char' of the + * corresponding 'font'. + */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" +#include "pk.h" + +static char rcsid[] = "$Header: makepkdir.c,v 0.8 92/11/23 19:46:50 bt Exp $"; + +makepkdir() +{ + int flag, i; + byte *p, *pc; + int format; + long ds, hppp, vppp, pkchksum; + unsigned cc, pl; + + for(i=0 ; i<256 ; i++) + (cbase + i)->pk_char = 0; + p = pkbase + *(pkbase + 2) + 3; + ds = getpuquad(p); + pkchksum = getpuquad(p); +#ifdef DEBUG2 + fprintf(stderr,"makepkdir: p-pkbase=%d, ds=%d, pkchksum=%d\n", p-pkbase, ds, pkchksum); +#endif /* DEBUG2 */ + if(font->checksum != pkchksum) + fprintf(stderr,"makepkdir: Checksum mismatch between\n%s and the .dvi file\n", pkname); + hppp = getpuquad(p); + vppp = getpuquad(p); /* points now to first pk charcter */ + + font->height = (double)ds/(double)vppp; +#ifdef DEBUG2 + fprintf(stderr,"makepkdir: ds = %d, hppp = %d, vppp = %d, font->height = %g\n", ds, hppp, vppp, font->height); +#endif /* DEBUG2 */ + + while((flag = getpubyte(p)) != PK_POST) { + if(flag < PK_CMD) { + pc = p - 1; + format = flag & FMASK; + if(format < 4) { + pl = getpubyte(p); + cc = getpubyte(p); + p += (format*256 + pl); + } + else if(format < 7) { + pl = getpupair(p); + cc = getpubyte(p); + p += ((format-4)*65536L + pl); + } + else { + pl = getpuquad(p); + cc = getpuquad(p); + p += pl; + } + if(cc < 256) (cbase + cc)->pk_char = pc - pkbase; + } + else { + switch(flag) { + case PK_XXX1: + pl = getpubyte(p); + break; + case PK_XXX2: + pl = getpupair(p); + break; + case PK_XXX3: + pl = getputrio(p); + break; + case PK_XXX4: + pl = getpuquad(p); + break; + case PK_YYY: + pl = 4; + break; + case PK_PRE: + fprintf(stderr,"PK_PRE command in the .pk font file %s\n", pkname); + exit(-1); + break; + default: + pl = 0; + break; + } + p += pl; + } + } +} diff --git a/dviware/dvi2pcl/openpkfile.c b/dviware/dvi2pcl/openpkfile.c new file mode 100644 index 0000000000..b3a6c9dfc4 --- /dev/null +++ b/dviware/dvi2pcl/openpkfile.c @@ -0,0 +1,91 @@ +/* $Log: openpkfile.c,v $ + * Revision 0.8 92/11/23 19:46:50 19:46:50 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:35 02:41:35 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:47:51 21:47:51 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:38 16:25:38 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:54 02:45:54 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:45 12:45:45 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:58 17:28:58 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include <string.h> +#include "globals.h" +#include "paths.h" + +static char rcsid[] = "$Header: openpkfile.c,v 0.8 92/11/23 19:46:50 bt Exp $"; + +FILE *openpkfile() +{ + FILE *fileptr; + char *fptr, *nptr, *pptr; + char *pt_chrs = "0123456789", *pt_ptr; + int pt_value; + + nptr = &names[font->name]; + fptr = pkname; + pptr = fontpath; + + if(*nptr) + while(*nptr) + *fptr++ = *nptr++; + else + while(*pptr) + *fptr++ = *pptr++; + nptr++; + + /* Find the pt size from the font name string */ + pt_ptr = strpbrk(nptr, pt_chrs); + sscanf(pt_ptr, "%d", &pt_value); + + /* Look for the pk fonts in pk300/10pt/cmr10.300pk etc.*/ + sprintf(fptr,"/%dpt/%s.%dpk", pt_value, nptr, font->dir_size); + + /* Try to open pk font file */ + if((fileptr = fopen(pkname,"r")) != NULL) + return fileptr; + + /* Look for the pk fonts in pk300/cmr10.300pk etc.*/ + sprintf(fptr,"/%s.%dpk", nptr, font->dir_size); + if((fileptr = fopen(pkname,"r")) != NULL) + return fileptr; + + fprintf(stderr,"Cannot find pk font file %s\n",pkname); + + /* Try to substitute at base resolution */ + font->dir_size = pt_value = RESOLUTION; + + sprintf(fptr, "/%dpt/%s.%dpk", pt_value,nptr, font->dir_size); + if((fileptr = fopen(pkname,"r")) != NULL){ + fprintf(stderr,"Substituting %s at %d points\n", nptr,pt_value); + return fileptr; + } + + sprintf(fptr, "/%s.%dpk",nptr,font->dir_size); + if((fileptr = fopen(pkname,"r")) != NULL){ + fprintf(stderr,"Substituting %s at %d points\n", nptr,pt_value); + return fileptr; + } + + fprintf(stderr,"Substituting cmr10 at ten points . . .\n"); + if ((fileptr = fopen(defaultpk,"r")) != NULL) + return 0; + fprintf(stderr, "Killed in openpkfile()\n"); + exit(-1); +} diff --git a/dviware/dvi2pcl/opentfmfile.c b/dviware/dvi2pcl/opentfmfile.c new file mode 100644 index 0000000000..3835ed528d --- /dev/null +++ b/dviware/dvi2pcl/opentfmfile.c @@ -0,0 +1,57 @@ +/* $Log: opentfmfile.c,v $ + * Revision 0.8 92/11/23 19:46:51 19:46:51 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:35 02:41:35 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:33 21:48:33 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:39 16:25:39 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:55 02:45:55 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:46 12:45:46 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:58 17:28:58 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" +#include "paths.h" + +static char rcsid[] = "$Header: opentfmfile.c,v 0.8 92/11/23 19:46:51 bt Exp $"; + +FILE *opentfmfile(tfmname) +char tfmname[]; +{ + FILE *fileptr; + char *fptr,*nptr,*pptr; + + nptr = &names[font->name]; + fptr = tfmname; + pptr = tfmpath; + if(*nptr) + while(*nptr) + *fptr++ = *nptr++; + else + while(*pptr) + *fptr++ = *pptr++; + nptr++; + sprintf(fptr,"%s.tfm",nptr); + if((fileptr = fopen(tfmname,"r")) == NULL) { + fprintf(stderr,"Cannot open the input .tfm file %s\n",tfmname); + fclose(fileptr); + fprintf(stderr,"Substituting the default %s\n", defaulttfm); + fileptr = fopen(defaulttfm,"r"); + } + return(fileptr); +} diff --git a/dviware/dvi2pcl/paths.h b/dviware/dvi2pcl/paths.h new file mode 100644 index 0000000000..2c1f2b3aae --- /dev/null +++ b/dviware/dvi2pcl/paths.h @@ -0,0 +1,41 @@ +/* $Log: paths.h,v $ + * Revision 0.8 92/11/23 19:47:04 19:47:04 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:18 02:41:18 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:44 21:48:44 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:51 16:25:51 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:07 02:46:07 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:29 12:45:29 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:53 17:28:53 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#ifndef _DVI2PCL_PATHS_INCLUDED +#define _DVI2PCL_PATHS_INCLUDED + +#define fontpath "/usr/local/lib/tex/fonts/pk300" +#define tfmpath "/usr/local/lib/tex/fonts/tfm/" +#define defaultpk "/usr/local/lib/tex/fonts/pk300/10pt/cmr10.300pk" +#define defaulttfm "/usr/local/lib/tex/fonts/tfm/cmr10.tfm" +#define respath "/usr/local/lib/tex/reslj.fnt" +#define initpath "/usr/local/lib/tex/initlj.fnt" +/* +#define respath "/tmp/reslj.fnt" +#define initpath "/tmp/initlj.fnt" +*/ + +#endif /* _DVI2PCL_MACROS_INCLUDED */ diff --git a/dviware/dvi2pcl/pcl.h b/dviware/dvi2pcl/pcl.h new file mode 100644 index 0000000000..b21a1677d6 --- /dev/null +++ b/dviware/dvi2pcl/pcl.h @@ -0,0 +1,182 @@ +/* $Log: pcl.h,v $ + * Revision 0.8 92/11/23 19:47:04 19:47:04 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:19 02:41:19 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:45 21:48:45 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:52 16:25:52 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:08 02:46:08 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:30 12:45:30 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:54 17:28:54 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#ifndef _DVI2PCL_PCL_INCLUDED +#define _DVI2PCL_PCL_INCLUDED + +/* + * HP LaserJet+/II printer commands (PCL4) + */ + +/* Specify char and download it */ +#define PCL4_CHAR_ID "\033*c%dE\033(s%dW" + +/* Reset the printer and define line termination */ +#define PCL4_CLEAN_PRINTER "\033E\033&k2G" + +/* Set the number of copies of the page(s) printed */ +#define PCL4_COPIES "\033&l%dX" + +/* Set rule a*b and draw it in solid black */ +#define PCL4_DRAWRULE "\033*c%db%da0P" + +/* Draw one row of pixels */ +#define PCL4_DRAWROW "\033*b%dW" + +/* Eject one page */ +#define PCL4_EJECT_PAGE " \f" + +/* End raster graphic mode */ +#define PCL4_END_RASTER "\033*rB" + +/* Download font descriptor (fd) */ +#define PCL4_FONT_DESCR "\033)s%dW" + +/* Specify font ID */ +#define PCL4_FONT_ID "\033*c%dD" + +/* Set graphic resolution */ +#define PCL4_GRAPHRES "\033*t%sR" + +/* Printer initialization (reset, presentation mode) */ +#define PCL4_INIT_PRINTER "\033E\033*o1Q" + +/* Select landscape mode */ +#define PCL4_LANDSCAPE "\033&l1O" + +/* Make font temporary (last ID) */ +#define PCL4_MAKE_FONT_TEMP "\033*c4F" + +/* Feed from manual feed slot */ +#define PCL4_MANUAL_FEED "\033&l2H" + +/* Move cursor h and v dots */ +#define PCL4_MOVE_POSITION "\033*p%ldx%ldY" + +/* Move cursor h dots */ +#define PCL4_MOVE_H_POSITION "\033*p%ldX" + +/* Move cursor v dots */ +#define PCL4_MOVE_V_POSITION "\033*p%ldY" + +/* Move cursor h and v dots relative */ +#define PCL4_MOVE_REL "\033*p%+ldx%+ldY" + +/* Move cursor h dots horzontally relative */ +#define PCL4_MOVE_HREL "\033*p%+ldX" + +/* Move cursor v dots vertically relative */ +#define PCL4_MOVE_VREL "\033*p%+ldY" + +/* Select portrait mode */ +#define PCL4_PORTRAIT "\033&l0O" + +/* Push cursor position onto stack */ +#define PCL4_PUSH "\033&f0S" + +/* Pop cursor position from stack */ +#define PCL4_POP "\033&f1S" + +/* Printer resolution in dpi */ +#define PCL4_RESOLUTION "\033*t%dR" + +/* Select font identifier */ +#define PCL4_SELECT_FONT "\033(%dX" + +/* Start raster graphics mode */ +#define PCL4_START_RASTER "\033*r1A" + +/* Switch to transparent mode */ +#define PCL4_TRANSP_MODE "\033&p1X%c" + + +/* + * Generic PCL5 commands + */ + +/* Set compresson mode: 0=Unencoded, 1=Run-length, 2=TIFF, 3=Delta Row */ +#define PCL5_COMPRESSION_MODE "\033*b%dM" + +/* HP-GL/2 horizontal plot size (inches) */ +#define PCL5_HPGL_HOR_PLOTSIZE "\033*c%dK" + +/* HP-GL/2 vertical plot size (inches) */ +#define PCL5_HPGL_VERT_PLOTSIZE "\033*c%dL" + +/* Enter HP-GL/2 mode. Pen to previous HP-GL/2 pen position */ +#define PCL5_HPGLMODE_HPGLPEN "\033%%0B" + +/* Enter HP-GL/2 mode. Pen to previous PCL pen position */ +#define PCL5_HPGLMODE_PCLPEN "\033%%1B" + +/* Enter PCL mode. Pen to previous PCL pen position */ +#define PCL5_PCLMODE_PCLPEN "\033%%0A" + +/* Enter PCL mode. Pen to previous HP-GL/2 pen position */ +#define PCL5_PCLMODE_HPGLPEN "\033%%1A" + +/* Set picture frame anchor point (PCL cursor position) */ +#define PCL5_PICTURE_ANCHOR "\033*c0T" + +/* Picture frame, horizontal size */ +#define PCL5_PICTURE_FRAME_HOR "\033*c%dX" + +/* Picture frame, vertical size */ +#define PCL5_PICTURE_FRAME_VERT "\033*c%dY" + +/* Select 0, 90, 180, or 270 degrees print direction */ +#define PCL5_PRINT_DIRECTION "\033&a%dP" + +/* Select reverse landscape mode */ +#define PCL5_REV_LANDSCAPE "\033&l3O" + +/* Select reverse portrait mode */ +#define PCL5_REV_PORTRAIT "\033&l2O" + + +/* + * HP PaintJet XL specific commands (PCL4) + */ + +/* Define the number of color planes to be used */ +#define PJXL_COLOR_PLANES "\033*r%dU" + +/* Draw one row of pixels in one of the color planes */ +#define PJXL_DRAWROW_PLANE "\033*b%dV" + +/* Assign red color */ +#define PJXL_SET_RED "\033*v%dA" + +/* Assign green color */ +#define PJXL_SET_GREEN "\033*v%dB" + +/* Assign blue color */ +#define PJXL_SET_BLUE "\033*v%dC" + +/* Set the text color */ +#define PJXL_TEXT_COLOR "\033&v%dS" + +#endif /* _DVI2PCL_MACROS_INCLUDED */ diff --git a/dviware/dvi2pcl/permfonts.c b/dviware/dvi2pcl/permfonts.c new file mode 100644 index 0000000000..b8da639c4c --- /dev/null +++ b/dviware/dvi2pcl/permfonts.c @@ -0,0 +1,50 @@ + +/* + * Determines how many fonts are permanently downloaded and which of them + * correspond to the fonts, used in the .dvi file. Those are marked in their + * font->down by the identifier fdown. All font information for a permanent + * downloaded font is taken from its .tfm file by calling `loadtfmfile'. + */ + +#include <stdio.h> +#include "globals.h" + +int permfonts(resfile) +FILE *resfile; +{ + char buffer[TERMLINELENGTH]; + char orient[2]; + char resname[NAMELENGTH]; + char *fontname; + int act_fonts_down = 0; + int f; + int fdown; + int fsize; + + while(fscanf(resfile,"%s %d %d %s", buffer, &fsize, &fdown, orient) != EOF) + if(buffer[0] == 'M') + printer.mem = fsize; + else + { + while(getc(resfile) >= ' '); + if((orient[0] == 'L' && landscape) + || (orient[0] == 'P' && !landscape)) { + for (f=0; f<MAXFONTS; f++) + if(font = fontptr[f]) { + if(font->dir_size == fsize) { + fontname = names + font->name; + if(!*fontname) { + fontname++; + if(!strcmp(fontname,buffer)) { + font->down = fdown; + loadtfmfile(); + } + } + } + } + act_fonts_down++; + } + } + (void)fclose(resfile); + return(act_fonts_down); +} diff --git a/dviware/dvi2pcl/pjxl.sty b/dviware/dvi2pcl/pjxl.sty new file mode 100644 index 0000000000..d76a77a8cc --- /dev/null +++ b/dviware/dvi2pcl/pjxl.sty @@ -0,0 +1,19 @@ +% +% pjxl.sty +% +% LaTeX style file for PaintJet XL color support +% Copyright (c) 1992, Bo Thid\'e, bt@irfu.se, Uppsala, Sweden +% +% You may copy this file and use it as long as you don't try to make money +% off it, or pretend that you wrote it. +% +% This file is provided "as is". + +\def\black{\special{pjxl:black}} +\def\red{\special{pjxl:red}} +\def\green{\special{pjxl:green}} +\def\yellow{\special{pjxl:yellow}} +\def\blue{\special{pjxl:blue}} +\def\magenta{\special{pjxl:magenta}} +\def\cyan{\special{pjxl:cyan}} +\def\white{\special{pjxl:white}} diff --git a/dviware/dvi2pcl/pk.h b/dviware/dvi2pcl/pk.h new file mode 100644 index 0000000000..10bfe8f8f6 --- /dev/null +++ b/dviware/dvi2pcl/pk.h @@ -0,0 +1,44 @@ +/* $Log: pk.h,v $ + * Revision 0.8 92/11/23 19:47:05 19:47:05 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:19 02:41:19 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:46 21:48:46 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:52 16:25:52 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:09 02:46:09 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:31 12:45:31 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:54 17:28:54 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:47 23:58:47 bt (Bo Thide') + * First Release. + * */ + +#ifndef _DVI2PCL_PK_INCLUDED +#define _DVI2PCL_PK_INCLUDED + +/* Define PK commands*/ +#define PK_ID 89 +#define PK_CHAR 239 +#define PK_XXX1 240 +#define PK_XXX2 241 +#define PK_XXX3 242 +#define PK_XXX4 243 +#define PK_YYY 244 +#define PK_POST 245 +#define PK_NO_OP 246 +#define PK_PRE 247 +#define PK_UNDEF 248 +#define PK_CMD 240 + +#endif /* _DVI2PCL_PK_INCLUDED */ diff --git a/dviware/dvi2pcl/pkcharinfo.c b/dviware/dvi2pcl/pkcharinfo.c new file mode 100644 index 0000000000..83b5782ab1 --- /dev/null +++ b/dviware/dvi2pcl/pkcharinfo.c @@ -0,0 +1,95 @@ +/* $Log: pkcharinfo.c,v $ + * Revision 0.8 92/11/23 19:46:52 19:46:52 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:36 02:41:36 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:34 21:48:34 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:40 16:25:40 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:56 02:45:56 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:47 12:45:47 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:59 17:28:59 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine determines the global variables + * c_flag, dyn_f, c_width, c_height, c_hoffset, c_voffset + * for the character c. (cbase + c)->pk_char points to its flag byte relative + * to pkbase. It returns a pointer, which points to the first run count of + * the character in progress. + */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" + +byte *pkcharinfo(c) +int c; +{ + int format; + byte *p; + charfmt *u; + long tfm; + + u = cbase + c; + if(u->pk_char == 0) { + c_flag = dyn_f = c_width = c_height = c_hoffset = c_voffset = 0; + if(verbose) + fprintf(stderr, "Character %d does not exist in this font\n",c); + return(NULL); + } + p = pkbase + u->pk_char; + c_flag = getpubyte(p); + dyn_f = c_flag >> 4; + format = c_flag & FMASK; + + if(format < 4) { + p += 2; + tfm = getputrio(p); + p++; + c_width = getpubyte(p); + c_height = getpubyte(p); + c_hoffset = getpsbyte(p); + c_voffset = getpsbyte(p); + } + else if(format < 7) { + p += 3; + tfm = getputrio(p); + p += 2; + c_width = getpupair(p); + c_height = getpupair(p); + c_hoffset = getpspair(p); + c_voffset = getpspair(p); + } + else { + p += 8; + tfm = getpuquad(p); + p += 8; + c_width = getpuquad(p); + c_height = getpuquad(p); + c_hoffset = getpsquad(p); + c_voffset = getpsquad(p); + } + u->tfm_width = round(tfm*convtfm); + u->pxl_width = round(tfm*convpxl); + +#ifdef DEBUG +fprintf(stderr,"pkcharinfo: tfm = %ld, convtfm = %g, convpxl = %g\n", + tfm, convtfm, convpxl); +#endif /* DEBUG */ + + return(p); +} diff --git a/dviware/dvi2pcl/pknum.c b/dviware/dvi2pcl/pknum.c new file mode 100644 index 0000000000..0813516df5 --- /dev/null +++ b/dviware/dvi2pcl/pknum.c @@ -0,0 +1,79 @@ +/* $Log: pknum.c,v $ + * Revision 0.8 92/11/23 19:46:52 19:46:52 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:37 02:41:37 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:34 21:48:34 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:40 16:25:40 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:56 02:45:56 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:47 12:45:47 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:59 17:28:59 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine provides the final algorithm for decoding the run counts, + * assuming a procedure (macro) 'getnib()' is available to get the next + * nibble from the 'pkbuffer'. It returns the next run_count as an integer, + * and if the row needs to be repeated it returns additionally the repeat + * value to the global variable 'repeat_count'. Since a repeat count can + * occur only once within a row, namely after the first transition within a + * row, it is the responsibility of the calling procedure to repeat such a + * row and to reset 'repeat_count' to zero, before calling the next run count + * for the next row. The global variable 'c_black' changes from 0 to -1 and + * back to 0 each time 'pknum' is called, indicating a run count for + * black pixels by 'c_black = -1' or for white pixels by 'c_black = 0', resp. + * Note that this routine is recursive, but since a repeat count can never + * directly follow another repeat count, it can only be recursive to one level + */ + +#include "globals.h" +#include "macros.h" + +#define getnib() ((c_nib = ~c_nib) ? (*pk_ptr & 0xf0) >> 4 : *pk_ptr++ & 0xf) + +static char rcsid[] = "$Header: pknum.c,v 0.8 92/11/23 19:46:52 bt Exp $"; + +pknum() +{ + int i,j; + extern int repeat_count; + + c_black = ~c_black; + if(!(i = getnib())) { + do + i++; + while(!(j = getnib())); + while(i--) + j = (j << 4) | getnib(); + return(j - 15 + ((13 - dyn_f)<<4) + dyn_f); + } + else if(i <= dyn_f) + return(i); + else if(i < 14) + return(((i - dyn_f - 1)<<4) + getnib() + dyn_f + 1); + else { + if(repeat_count) + prerror("Extra repeat count\n"); + if(i == 14) + repeat_count = pknum(); + else { + repeat_count = 1; + c_black = ~c_black; + } + return(pknum()); + } +} diff --git a/dviware/dvi2pcl/pktopxl.c b/dviware/dvi2pcl/pktopxl.c new file mode 100644 index 0000000000..bd8da962b7 --- /dev/null +++ b/dviware/dvi2pcl/pktopxl.c @@ -0,0 +1,164 @@ +/* $Log: pktopxl.c,v $ + * Revision 0.8 92/11/23 19:46:53 19:46:53 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:38 02:41:38 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:35 21:48:35 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:42 16:25:42 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:58 02:45:58 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:48 12:45:48 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:59 17:28:59 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +int repeat_count; + +#include <stdio.h> +#include "globals.h" + +static char rcsid[] = "$Header: pktopxl.c,v 0.8 92/11/23 19:46:53 bt Exp $"; + +/* + * This routine converts a character coded in PK format into the appropriate + * byte aligned pixel pattern. After calling 'pkcharinfo(c)', besides the + * global variables 'dyn_f, c_flag, c_width, c_height, c_hoffset and c_voffset' + * a pointer to the first run count is returned and stored in the global var + * 'pk_ptr'. The produced pixel pattern is stored in the global array + * 'pxl_buffer', and the global pointer 'endofchardata' points to the next free + * byte in 'pxlbuffer'. + *---------------------------------------------------------------------------- + * 'pktopxl' has two main branches: for those characters which are coded into + * run-repeat counts, indicated by a value of dyn_f < 14, the first branch is + * taken, while for bit mapped characters, indicated by dyn_f == 14, the + * second branch is taken. + */ +pktopxl(c) +int c; +{ + static byte c_pad[]={'\0','\200','\300','\340','\360','\370','\374','\376'}; + byte *pxl, *row="", *p; + byte pxl_byte; + int pad_bits, pad_comp; + int pad_mask; + int width_bytes; + int nrows,length; + int l, m=0, n=0; + int run_count; + + pk_ptr = pkcharinfo(c); + nrows = c_height; + width_bytes = (c_width + 7) / 8; + pad_bits = c_width % 8; + pad_mask = c_pad[pad_bits]; + pxl = pxlbuffer; + + if(dyn_f<14){ + /* Convert run/repeat counts to byte aligned pixels */ + run_count = repeat_count = 0; + c_nib = 0; + c_black = (c_flag & 0x8) ? 0 : ~0; + while(nrows) { + if(repeat_count) { + while(repeat_count) { + repeat_count--; + m = width_bytes; + while(m--) + *pxl++ = *row++; + nrows--; + } + } + else { + if(!run_count) + run_count = pknum(); + if(run_count >= c_width) + while(run_count >= c_width) { + run_count -= c_width; + m = pad_bits ? width_bytes : width_bytes + 1; + while(--m) + *pxl++ = c_black ? BLACKBYTE : WHITEBYTE; + if(pad_bits) + *pxl++ = c_black ? pad_mask : WHITEBYTE; + nrows--; + } + else { + row = pxl; + m = pad_bits ? width_bytes : width_bytes + 1; + while(--m) { + if(run_count < 8) { + pxl_byte = c_black ? c_pad[run_count] : ~c_pad[run_count]; + while((run_count += pknum()) < 8) + if(c_black) + pxl_byte &= c_pad[run_count]; + else + pxl_byte |= ~c_pad[run_count]; + *pxl++ = pxl_byte; + } + else + *pxl++ = c_black ? BLACKBYTE : WHITEBYTE; + run_count -= 8; + } + if(pad_bits) { + if(run_count < pad_bits) { + pxl_byte = c_black ? c_pad[run_count] : ~c_pad[run_count]; + while((run_count += pknum()) < pad_bits) + if(c_black) + pxl_byte &= c_pad[run_count]; + else + pxl_byte |= ~c_pad[run_count]; + *pxl++ = pxl_byte & pad_mask; + } + else + *pxl++ = c_black ? pad_mask : WHITEBYTE; + } + nrows--; + run_count -= pad_bits; + } + } + } + } + else { + /* Convert bit mapped character into byte aligned pixel */ + p = pk_ptr; + pad_comp = 8 - pad_bits; + if(pad_bits) { + m=0; + while(nrows--) { + l = width_bytes; + while(--l) + *pxl++ = m ? (*p++) << m | (*p >> n) & ~c_pad[n] : *p++; + if(m) + *pxl++ = m <= pad_comp ? (*p << m) & pad_mask : + (*p++) << m | *p >> n & ~c_pad[n] & pad_mask; + else + *pxl++ = *p & pad_mask; + m = (m + c_width) % 8; + if(!m) + p++; + else + n = 8 - m; + } + } + else { + length = width_bytes*c_height; + if(!length) + *pxl++ = 0; /* special case for empty char */ + while(length--) + *pxl++ = *p++; + } + } + endofchardata = pxl; +} + diff --git a/dviware/dvi2pcl/postamble.c b/dviware/dvi2pcl/postamble.c new file mode 100644 index 0000000000..d056a1b5f8 --- /dev/null +++ b/dviware/dvi2pcl/postamble.c @@ -0,0 +1,69 @@ +/* $Log: postamble.c,v $ + * Revision 0.8 92/11/23 19:46:54 19:46:54 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:38 02:41:38 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:36 21:48:36 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:42 16:25:42 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:58 02:45:58 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:49 12:45:49 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:28:59 17:28:59 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * Process the postamble. It sets the pointer to the final bop + * in the dvi file and checks agreement with the corresponding values from + * the preamble. + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: postamble.c,v 0.8 92/11/23 19:46:54 bt Exp $"; + +void postamble(dvifile) +FILE *dvifile; +{ + int c, t; + long p; + + lastpage = (long)getsquad(dvifile); + if(numerator != (long)getsquad(dvifile)) + fprintf(stderr,"Warning: Pre-post disagreement in numerator\n"); + if(denominator != (long)getsquad(dvifile)) + fprintf(stderr,"Warning: Pre-post disagreement in denominator\n"); + if(magnification != (long)getsquad(dvifile)) + fprintf(stderr,"Warning: Pre-post disagreement in magnification\n"); + + maxv = (long)getsquad(dvifile); + maxh = (long)getsquad(dvifile); + maxs = (int)getspair(dvifile); + t = (int)getspair(dvifile); + + while(TRUE) + { + while((c = (int)getubyte(dvifile)) == DVI_NOP); + if((c >= DVI_FNT_DEF1) && (c <= DVI_FNT_DEF2)) + { + p = firstpar(dvifile, c); + checkfont(dvifile, p); + } + if(c == DVI_POSTPOST) break; + } +} diff --git a/dviware/dvi2pcl/posting b/dviware/dvi2pcl/posting new file mode 100644 index 0000000000..9dd884f199 --- /dev/null +++ b/dviware/dvi2pcl/posting @@ -0,0 +1,75 @@ + +Version 0.8 of the DVI to HP PCL printer driver 'dvi2pcl' is now available +for anonymous ftp from + +Name: hybrid.irfu.se +Address: 130.238.30.23 + +This release fixes a bug wich showed up for largish jobs (> 50 pages) +with many soft fonts downloaded so that, in addition, graphics raster +fonts were being used. If a pcl string was read via \special and that +string changed the printer resolution, the graphics raster glyphs were +printed with the latter, incorrect resolution. + +Binary downloading of font and char descriptors is now done explicitly +value by value in order to avoid any struct alignment problems. This +should improve portability to different architectures and may solve the +problems reported by some users running SGI and PC/386 with non-gcc +compilers. + +Note that the '-o' option has changed. The file extent '.pcl' is no +longer attached to the output bitfile name. This is to simplify +printing to the bit bucket ('-o /dev/null') for testing purposes. Also, +since 'dvi2plc' can write directly to standard output, there is usually +no need to save the bitfile but rather one should pipe the output +directly to the printer spooler ('dvi2pcl <file>.dvi | lp -or +-d<dest>'). + +Version 0.8 adds support for color text for PaintJet printers via the +command: + + \special{pjxl:<color>} + +where <color> is either 'black', 'red', 'green', 'yellow', 'blue', +'magenta', 'cyan', or 'white'. With the new 'pjxl.sty' style file, text +color may be changed by using shorthand commands: '\black', '\red', +'\green', etc. + +For PaintJet printers, 'dvi2pcl' only works acceptably with downloaded +soft fonts (not raster graphics ones) so printing on the PaintJet, which +cannot handle soft font downloading, or on the PaintJet XL with raster +fonts, does not work yet. The number of fonts downloaded to the PaintJet +XL must not exceed 28 (= the hardware limit). Ordinary raster graphics +pictures are printed OK. Rules are not printed on PaintJet XL since +the PJXL has no hardware support for this. + +Version 0.8 adds rudimentary support for device selection via the '-d' +option ('-j' obsoleted, for compatibility with the 'lp' spooler). +Printers supported via '-d' are: "lj+" (HP LaserJet+), "lj2" (HP +LaserJet II), "lj2d" (HP LaserJet IID),"lj2p" (HP LaserJet IIP),"lj3si" +(HP LaserJet IIISi), "lj3p" (HP LaserJet IIIP),"pj" (HP PaintJet), and +"pjxl" (HP PaintJet XL). In fact, only "lj+" has any effect. This flag +overcomes certain hardware limitations (missing transparency mode) in +the LaserJet+. It is the user's responsibility to add the '-f <nnn>' +flag to limit the number of soft fonts for the particular printer used. + +The man page has been updated to reflect changes and corrections ('-d', +'-o', '-r', and '-R' options; '\special' command 'pjxl:') + +This release is the last alpha release. The next release, v0.9 will be +the first beta release and will have the (now quite ugly) code cleaned +up and shortened considerably. New functionality (support for +PostScript graphics in PCL via ghostscript, virtual fonts, and permanent +font downloading for faster printing) is planned for v0.9. + +Please report successes and problems for your specific hardware/compiler +combination. + +Uppsala 23 Nov 1992 + +--- + ^ Bo Thide'-------------------------------------------------------------- + |I| Swedish Institute of Space Physics, S-755 91 Uppsala, Sweden + |R| Phone: (+46) 18-303671. Fax: (+46) 18-403100. IP: 130.238.30.23 + /|F|\ INTERNET: bt@irfu.se UUCP: ...!mcvax!sunic!irfu!bt + ~~U~~ ----------------------------------------------------------------sm5dfw- diff --git a/dviware/dvi2pcl/preamble.c b/dviware/dvi2pcl/preamble.c new file mode 100644 index 0000000000..7872af1927 --- /dev/null +++ b/dviware/dvi2pcl/preamble.c @@ -0,0 +1,74 @@ +/* $Log: preamble.c,v $ + * Revision 0.8 92/11/23 19:46:54 19:46:54 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:39 02:41:39 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:37 21:48:37 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:43 16:25:43 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:45:59 02:45:59 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:49 12:45:49 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine processes the preamble and determines the global variables + * 'conv' and 'magnification'. It exits if a fatal error is found in the + * preamble. + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: preamble.c,v 0.8 92/11/23 19:46:54 bt Exp $"; + +preamble(dvifile, resolution) +FILE *dvifile; +short resolution; +{ + ubyte p; + + if(getubyte(dvifile) != DVI_PRE) + sterror("Bad %s file: First byte is not start of preamble\n", + DVIFILE_SUFFIX); + if(getubyte(dvifile) != 2) + fprintf(stderr,"Identifier in byte 1 should be '2'"); + numerator = (long)getsquad(dvifile); + denominator = (long)getsquad(dvifile); + +#ifdef DEBUG + fprintf (stderr,"preamble: numerator=%d, denominator=%d\n",numerator,denominator); +#endif /* DEBUG */ + + if(numerator <= 0) + valerror("Bad .dvi file: Numerator is %d\n" , numerator); + if(denominator <= 0 ) + valerror("Bad .dvi file: Denominator is %d\n" , denominator); + magnification = (long)getsquad(dvifile); + conv = ((double)numerator/254000.0)*(double)resolution*(double)magnification/((double)denominator*1000.0) ; + +#ifdef DEBUG + fprintf (stderr,"preamble: magnification=%d, conv=%g\n",magnification,conv); +#endif /* DEBUG */ + + p = getubyte(dvifile); + +#ifdef DEBUG2 + fprintf (stderr,"preamble: p = %d\n",p); +#endif /* DEBUG2 */ +} diff --git a/dviware/dvi2pcl/prescanpage.c b/dviware/dvi2pcl/prescanpage.c new file mode 100644 index 0000000000..72cd90f105 --- /dev/null +++ b/dviware/dvi2pcl/prescanpage.c @@ -0,0 +1,153 @@ +/* $Log: prescanpage.c,v $ + * Revision 0.8 92/11/23 19:46:55 19:46:55 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:40 02:41:40 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:37 21:48:37 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:43 16:25:43 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:00 02:46:00 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:21 12:43:21 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine will scan a page from 'bop' to 'eop', maintaining information + * about font usage. It also catches errors like illegal font numbers or + * characters. Finally, it also counts the number of pages actually processed, + * so if the file is scanned backwards, it will end correctly. + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: prescanpage.c,v 0.8 92/11/23 19:46:55 bt Exp $"; + +prescanpage(bitfile, dvifile, pcllevel, resolution) +FILE *bitfile; +FILE *dvifile; +short pcllevel, resolution; +{ + bool badchar; + int k; + int q; + int font_num; + int font_used[MAXFONTS]; + long p; + long hh=0L; /* Pixel analog of DVI unit h */ + long vv=0L; /* Pixel analog of DVI unit v */ + + actualpagecount++; + + for(k = 0 ; k < MAXFONTS ; k++) + font_used[k] = FALSE; + font_num = 0; + + while (TRUE){ + if((k = (int)getubyte(dvifile)) < DVI_SET1) + (cbase + k)->use_count++; + else { + p = firstpar(dvifile, k); + +#ifdef DEBUG2 + fprintf(stderr,"\nprescanpage: p = %d,k = %d", p, k); +#endif /* DEBUG2 */ + + switch (k) { + case DVI_BOP: + scanbop(dvifile); + break; + case DVI_EOP: + goto end; + break; + case DVI_SET1: + case DVI_SET2: + case DVI_SET3: + case DVI_SET4: + case DVI_PUT1: + case DVI_PUT2: + case DVI_PUT3: + case DVI_PUT4: + if(p > 255) + prerror("Char > 255 encountered\n"); + else + (cbase + p)->use_count++; + break; + case DVI_SET_RULE: + case DVI_PUT_RULE: + getsquad(dvifile); + break; + case DVI_FNT_DEF1: + case DVI_FNT_DEF2: + case DVI_FNT_DEF3: + case DVI_FNT_DEF4: + definefont(dvifile, p); + break; + case DVI_XXX1: + case DVI_XXX2: + case DVI_XXX3: + case DVI_XXX4: + badchar = FALSE; + if(p + nextnamesfree - names > NAMESIZE) + prerror("Out of string space during special\n"); + for (k=0; k<(int)p; k++) + { + q = (int)getubyte(dvifile); + if((q < ' ') || (q > '~')) + badchar = TRUE; + *(nextnamesfree + k) = q; + } + *(nextnamesfree + p) = '\0'; + if(badchar) + fprintf(stderr,"non-ASCII character in DVI_XXX command\n"); + dospecial(bitfile, PRESCAN_ON, pcllevel, hh, vv, resolution); + break; + case DVI_POST: + inpostamble = TRUE; + goto end; + break; + default: + if((k >= DVI_FNT_NUM_0) && (k <= DVI_FNT4)) + { + if(p > MAXFONTS) + valerror("Max number of allowed fonts is %3d\n", MAXFONTS); + else { + font = fontptr[p]; + if(font == NULL) + prerror("Undefined font\n"); + else { + cbase = font->chr; + if(!font_used[p]) { + font_used[p] = TRUE; + font_num++; + } + } + } + } + break; + } + } + } +end: + if(font_num > 16) + { + fprintf(stderr,"Warning: "); + printbop(startvals, count); + fprintf(stderr,"prescanpage: %d [>16] fonts on page\n",font_num); + } +} diff --git a/dviware/dvi2pcl/printbop.c b/dviware/dvi2pcl/printbop.c new file mode 100644 index 0000000000..2f9524ad9a --- /dev/null +++ b/dviware/dvi2pcl/printbop.c @@ -0,0 +1,43 @@ +/* $Log: printbop.c,v $ + * Revision 0.8 92/11/23 19:46:56 19:46:56 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:40 02:41:40 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:38 21:48:38 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:44 16:25:44 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:00 02:46:00 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:50 12:45:50 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> + +static char rcsid[] = "$Header: printbop.c,v 0.8 92/11/23 19:46:56 bt Exp $"; + +/* Simply outputs the page number in progress */ +printbop(startvals, count) +int startvals; +int count[]; +{ + int k; + + for(k = 0 ; k <= startvals ; k++) + { + fprintf(stderr,"Page: %3d\010\010\010\010\010\010\010\010\010",count[k]); + fflush(stderr); + } +} diff --git a/dviware/dvi2pcl/printfont.c b/dviware/dvi2pcl/printfont.c new file mode 100644 index 0000000000..8a093e70eb --- /dev/null +++ b/dviware/dvi2pcl/printfont.c @@ -0,0 +1,46 @@ +/* $Log: printfont.c,v $ + * Revision 0.8 92/11/23 19:46:56 19:46:56 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:41 02:41:41 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:38 21:48:38 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:45 16:25:45 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:01 02:46:01 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:51 12:45:51 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "globals.h" + +static char rcsid[] = "$Header: printfont.c,v 0.8 92/11/23 19:46:56 bt Exp $"; + +/* Simply outputs the name of a given font */ +printfont() +{ + char *p; + if(!font->name) + fprintf(stderr,"UNDEFINED!\n"); + else + { + p = names + font->name; + if(*p) + fprintf(stderr,"%s:",p); + while(*p++); + fprintf(stderr,"%s\n",p); + } +} diff --git a/dviware/dvi2pcl/reslj.fnt b/dviware/dvi2pcl/reslj.fnt new file mode 100644 index 0000000000..585428356f --- /dev/null +++ b/dviware/dvi2pcl/reslj.fnt @@ -0,0 +1 @@ +MEM 100000 diff --git a/dviware/dvi2pcl/rotate.tex b/dviware/dvi2pcl/rotate.tex new file mode 100644 index 0000000000..c5be569e44 --- /dev/null +++ b/dviware/dvi2pcl/rotate.tex @@ -0,0 +1,16 @@ +\documentstyle[12pt]{article} + +\Large +\begin{document} + +\special{landscape}% +\special{orientation=90}% +Hello +\special{orientation=180}% +Hello +\special{orientation=270}% +Hello +\special{orientation=0}% +Hello + +\end{document} diff --git a/dviware/dvi2pcl/rotatechar.c b/dviware/dvi2pcl/rotatechar.c new file mode 100644 index 0000000000..3b57191e78 --- /dev/null +++ b/dviware/dvi2pcl/rotatechar.c @@ -0,0 +1,51 @@ + +/* + * Rotate the pixel pattern, stored in pxlbuffer by 90 degrees for landscape + * printout mode. The rotated pixel pattern starts at the end of the + * original pixel pattern in pxlbuffer. The pointer to the begin of the + * rotated pattern is returned by rotatechar() + */ + +#include "globals.h" + +byte *rotatechar() +{ + int lbit, tbit; + int width, height, bytes, length; + int mask; + byte *pp, *lp, *tp; + register int i,j; + + width = c_height; + height = c_width; + bytes = (height + 7) / 8; + length = height*((width + 7)/8); + if(endofchardata - pxlbuffer + length >= MAXPXLSIZE) + prerror("Out of memory while rotating character\n"); + lp = endofchardata; + for(i = 0 ; i < length ; i++) + *lp++ = 0; + lp = endofchardata - 1; + tp = pxlbuffer - 1; + tbit = 7 - (height -1) % 8; + for(i = 0 ; i < height; i++) { + if(tbit == 8) { + tbit = 0; + tp--; + } + pp = tp + bytes; + mask = power[tbit++]; + lp++; + lbit = 8; + for(j = 0 ; j < width ; j++) { + if(!lbit--) { + lbit = 7; + lp++; + } + if(*pp & mask) + *lp |= power[lbit]; + pp += bytes; + } + } + return(endofchardata); +} diff --git a/dviware/dvi2pcl/rulepixels.c b/dviware/dvi2pcl/rulepixels.c new file mode 100644 index 0000000000..20fbb755cc --- /dev/null +++ b/dviware/dvi2pcl/rulepixels.c @@ -0,0 +1,53 @@ +/* $Log: rulepixels.c,v $ + * Revision 0.8 92/11/23 19:46:57 19:46:57 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:41 02:41:41 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:39 21:48:39 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:45 16:25:45 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:02 02:46:02 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:52 12:45:52 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine computes the number of pixels in the height or width of a rule + */ + +#include <math.h> +#include <stdio.h> +#include "macros.h" + +static char rcsid[] = "$Header: rulepixels.c,v 0.8 92/11/23 19:46:57 bt Exp $"; + +long rulepixels(x, conv) +long x; +double conv; +{ + long n; + double y; + + y = conv * (double)x; + n = (long)ceil(y); + +#ifdef DEBUG +fprintf(stderr, "rulepixels: x = %ld, y = %g, conv = %g, n = %d\n", x, y, conv, n); +#endif /* DEBUG */ + + return(n); + +} diff --git a/dviware/dvi2pcl/sample.tex b/dviware/dvi2pcl/sample.tex new file mode 100644 index 0000000000..82f1d89150 --- /dev/null +++ b/dviware/dvi2pcl/sample.tex @@ -0,0 +1,33 @@ +\documentstyle[pjxl,hiscatrep]{report} + +\pagestyle{empty} + +\topmargin-8mm +\oddsidemargin-9mm +\textwidth95mm +\textheight130mm +\begin{document} + +{\bf Hello World!} + +\medskip +{\small\sf This is \TeX\ printout on the HP PaintJet XL.} + +{\small\em Graphics can be included \dots} + +\special{move(h-42mm v6mm r)} +\special{include(hiscatlogo.pcl)} +\vspace{32mm} +%{\GAro \hiscat{}} +{\em \dots and color text too!} + +\small\red{}Now \green colors \yellow can \blue be \magenta changed \cyan +at \black any \red time\black! + +\cyan\small Here's math:\normalsize +$$ +\vec A\approx\mu_0\int\!d^3x'\, +\vec {\red{}J^{\rm NL}}(\vec x')\cyan{}e^{-ik\vec n\cdot\vec x'} +$$ +\black\tiny The driver used is the 'dvi2pcl' dvi-to-pcl translator. +\end{document} diff --git a/dviware/dvi2pcl/scanbop.c b/dviware/dvi2pcl/scanbop.c new file mode 100644 index 0000000000..398b9f15f4 --- /dev/null +++ b/dviware/dvi2pcl/scanbop.c @@ -0,0 +1,46 @@ +/* $Log: scanbop.c,v $ + * Revision 0.8 92/11/23 19:46:58 19:46:58 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:42 02:41:42 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:40 21:48:40 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:46 16:25:46 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:02 02:46:02 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:52 12:45:52 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:00 17:29:00 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine simply scans the 10 counts after the occurrence of a bop + * command. In addition it determines the 'lastpage' and 'prevpage' pointers. + */ + +#include <stdio.h> +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: scanbop.c,v 0.8 92/11/23 19:46:58 bt Exp $"; + +void scanbop(dvifile) +FILE *dvifile; +{ + int k; + lastpage = ftell(dvifile); + for(k = 0; k <= 9 ; k++) + count[k] = (long)getsquad(dvifile); + prevpage = (long)getsquad(dvifile); +} diff --git a/dviware/dvi2pcl/skipfontdef.c b/dviware/dvi2pcl/skipfontdef.c new file mode 100644 index 0000000000..ae38c362be --- /dev/null +++ b/dviware/dvi2pcl/skipfontdef.c @@ -0,0 +1,47 @@ +/* $Log: skipfontdef.c,v $ + * Revision 0.8 92/11/23 19:46:58 19:46:58 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:42 02:41:42 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:40 21:48:40 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:47 16:25:47 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:03 02:46:03 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:53 12:45:53 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:01 17:29:01 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "macros.h" + +static char rcsid[] = "$Header: skipfontdef.c,v 0.8 92/11/23 19:46:58 bt Exp $"; + +/* + * We need a routine to skip over a font definition. This is very simple, just + * requires skipping over the parameters. + */ +void skipfontdef(dvifile) +FILE *dvifile; +{ + int skip; + + getsquad(dvifile); + getsquad(dvifile); + getsquad(dvifile); + skip = (int)getubyte(dvifile); + skip += (int)getubyte(dvifile); + fseek(dvifile, skip, 1); +} diff --git a/dviware/dvi2pcl/skipnextpage.c b/dviware/dvi2pcl/skipnextpage.c new file mode 100644 index 0000000000..3cbfe3faf5 --- /dev/null +++ b/dviware/dvi2pcl/skipnextpage.c @@ -0,0 +1,81 @@ +/* $Log: skipnextpage.c,v $ + * Revision 0.8 92/11/23 19:46:59 19:46:59 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:43 02:41:43 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:41 21:48:41 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:47 16:25:47 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:04 02:46:04 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:54 12:45:54 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:01 17:29:01 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: skipnextpage.c,v 0.8 92/11/23 19:46:59 bt Exp $"; + +/* + * This routine is used to pass over the next odd page during the first path + * for the 'twosided' option in which the even pages are produced. + */ +skipnextpage(dvifile) +FILE *dvifile; +{ + int k; + long p; + + while (TRUE) + { + if((k = (int)getubyte(dvifile)) >= DVI_SET1) { + p = firstpar(dvifile, k); + switch(k) { + case DVI_BOP: + scanbop(dvifile); + break; + case DVI_EOP: + return(TRUE); + break; + case DVI_SET_RULE: + case DVI_PUT_RULE: + getsquad(dvifile); + break; + case DVI_FNT_DEF1: + case DVI_FNT_DEF2: + case DVI_FNT_DEF3: + case DVI_FNT_DEF4: + skipfontdef(dvifile); + break; + case DVI_XXX1: + case DVI_XXX2: + case DVI_XXX3: + case DVI_XXX4: + while (p-- > 0) + getubyte(dvifile); + break; + case DVI_POST: + inpostamble = TRUE; + return(FALSE); + break; + default: + break; + } + } + } +} diff --git a/dviware/dvi2pcl/skippages.c b/dviware/dvi2pcl/skippages.c new file mode 100644 index 0000000000..dd6db636f8 --- /dev/null +++ b/dviware/dvi2pcl/skippages.c @@ -0,0 +1,110 @@ +/* $Log: skippages.c,v $ + * Revision 0.8 92/11/23 19:47:00 19:47:00 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:44 02:41:44 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:41 21:48:41 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:48 16:25:48 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:04 02:46:04 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:45:54 12:45:54 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:01 17:29:01 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +/* + * This routine is used to pass over pages that are not being translated. It + * is assumed to begin just after the preamble has been read, or just after a + * DVI_BOP has been processed. It continues until either finding a DVI_BOP that + * matches the desired starting page specification, or until running into the + * postamble. + */ + +#include <stdio.h> +#include "dvi.h" +#include "globals.h" +#include "macros.h" + +static char rcsid[] = "$Header: skippages.c,v 0.8 92/11/23 19:47:00 bt Exp $"; + +long skippages(bitfile, dvifile, pcllevel, resolution) +FILE *bitfile; +FILE *dvifile; +short pcllevel; +short resolution; +{ + int i, k, q; + bool badchar; + bool match; + long p; + long hh=0L; /* Pixel analog of DVI unit h */ + long vv=0L; /* Pixel analog of DVI unit v */ + long startloc=0; + + while (TRUE) { + if((k = (int)getubyte(dvifile)) >= DVI_SET1) { + p = firstpar(dvifile, k); + switch(k) { + case DVI_BOP: + scanbop(dvifile); + match = TRUE; + for(i = 0 ; i <= startvals ; i++) + if(startthere[i] && (startcount[i] != count[i])) + match = FALSE; + if(match) { + startloc = lastpage - 1; + goto end; + } + break; + case DVI_SET_RULE: + case DVI_PUT_RULE: + getsquad(dvifile); + break; + case DVI_FNT_DEF1: + case DVI_FNT_DEF2: + case DVI_FNT_DEF3: + case DVI_FNT_DEF4: + definefont(dvifile, p); + break; + case DVI_XXX1: + case DVI_XXX2: + case DVI_XXX3: + case DVI_XXX4: + badchar = FALSE; + if(p + nextnamesfree - names > NAMESIZE) + prerror("Out of string space during special\n"); + for (k=0; k<(int)p; k++) { + q = (int)getubyte(dvifile); + if((q < ' ') || (q > '~')) + badchar = TRUE; + *(nextnamesfree + k) = q; + } + *(nextnamesfree + p) = 0; + if(badchar) + fprintf(stderr,"Non-ASCII character in DVI_XX command\n"); + dospecial(bitfile, PRESCAN_ON, pcllevel, hh, vv, resolution); + break; + case DVI_POST: + inpostamble = TRUE; + goto end; + break; + default: + break; + } + } + } +end: + return(startloc); +} diff --git a/dviware/dvi2pcl/sortfonts.c b/dviware/dvi2pcl/sortfonts.c new file mode 100644 index 0000000000..5843842f26 --- /dev/null +++ b/dviware/dvi2pcl/sortfonts.c @@ -0,0 +1,79 @@ +/* + * Sorts order of fonts used in the dvi-file and not stored permanently in + * the printers memory in respect to font usage. Therefore a rating value + * is calculated for each font from their character usage in the document. + * The fonts are ordered in `fontlist' in order of their rating value + * `usage'. The function returns the number of different fonts used, but + * not stored permanently. As a side effect, for each font the first and + * last character, used in the document ist stored in font->bc and font->ec + * resp., to avoid unnecessary searching later on. + */ + +#include "globals.h" + +int sortfonts(fontlist) +int fontlist[]; +{ + int f; + int i; + int t; + int store_all; + int fontnum = 0; + long total; + long different; + long tt; + long usage[MAXFONTS]; + charfmt *u; + charfmt *cbase; + + /* Determine rating value for each font used but not perm loaded */ + for (f = 0 ; f < MAXFONTS ; f++) + if ((font = fontptr[f]) && (font->down < 0)) { + cbase = font->chr; + total = different = 0; + font->bc = 256; + font->ec = -1; + for(i = 0 ; i < 256 ; i++) + if((cbase + i)->use_count) + { + font->bc = i; + break; + } /* First char used */ + for(i = 255 ; i >= font->bc ; i--) + if((cbase + i)->use_count) { + font->ec = i; + break; + } /* Last char used */ + for(i = font->bc ; i <= font->ec ; i++) { + u = cbase + i; + if(u->use_count) { + different++; + total += u->use_count; + } /* Different used chars */ + } /* and total usage */ + + fontlist[fontnum] = f; + + /* Calculate rating */ + if(different) + usage[fontnum++] = + (256*(total - different))/different; + else + usage[fontnum++] = 0; + } + + /* Now sort used fonts in order of the usage rating values */ + for(f = fontnum - 1 ; f > 0 ; f--) + for(i = 0 ; i < f ; i++) + if(usage[i] < usage[f]) { + tt = usage[i]; + usage[i] = usage[f]; + usage[f] = tt; + t = fontlist[i]; + fontlist[i] = fontlist[f]; + fontlist[f] = t; + } + + /* Return the number of different fonts not permanently loaded */ + return(fontnum); +} diff --git a/dviware/dvi2pcl/storechar.c b/dviware/dvi2pcl/storechar.c new file mode 100644 index 0000000000..ce6ea1841e --- /dev/null +++ b/dviware/dvi2pcl/storechar.c @@ -0,0 +1,44 @@ +/* + * Does similar things as down_character, but instead of putting + * the character's pixel pattern in the bitfile it is stored in dynamicaly + * allocated memory, used for drawing the character in graphic mode. In + * graphic mode the meaning for x_offset and y_offset is different from + * downloaded characters and the pixel pattern is stripped off from pending + * zero bytes in each row. + */ + +#include "globals.h" + +void storechar(c) +int c; +{ + byte *q, *p; + int i; + int width; + int height; + long length; + gcharfmt *g; + + pktopxl(c); + g = &(*gfont)[c]; + if(landscape) { + p = (byte *)rotatechar(); + g->pxl_bytes = width = (c_height + 7)/8; + g->pxl_rows = height = c_width; + g->x_offset = height - c_hoffset - 1; + g->y_offset = -c_voffset; + } + else { + p = (byte *) pxlbuffer; + g->pxl_bytes = width = (c_width + 7)/8; + g->pxl_rows = height = c_height; + g->x_offset = -c_hoffset; + g->y_offset = -c_voffset; + } + + length = height*width; + g->pxl_pattern = (byte *)malloc(length); + q = g->pxl_pattern; + for(i = 0 ; i < length ; i ++) + *q++ = *p++; +} diff --git a/dviware/dvi2pcl/storefont.c b/dviware/dvi2pcl/storefont.c new file mode 100644 index 0000000000..1c0832074a --- /dev/null +++ b/dviware/dvi2pcl/storefont.c @@ -0,0 +1,55 @@ +/* $Log: storefont.c,v $ + * Revision 0.8 92/11/23 19:47:01 19:47:01 bt (Bo Thide') + * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support + * + * Revision 0.7 92/11/13 02:41:44 02:41:44 bt (Bo Thide') + * More bug fixes and improvements. Support for PaintJet XL + * + * Revision 0.6 92/11/10 21:48:42 21:48:42 bt (Bo Thide') + * Bug fixes. Added -R option. Better font handling. + * + * Revision 0.5 92/11/09 16:25:48 16:25:48 bt (Bo Thide') + * Rewrite of dospecial.c. Extended \special support + * + * Revision 0.4 92/11/08 02:46:05 02:46:05 bt (Bo Thide') + * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's. + * + * Revision 0.3 92/08/24 12:43:22 12:43:22 bt (Bo Thide') + * Fixed 8 bit (dc font) support. + * + * Revision 0.2 92/08/23 17:29:01 17:29:01 bt (Bo Thide') + * Source cleaned up. Changed certain function calls. Removed globals. + * + * Revision 0.1 92/08/22 23:58:48 23:58:48 bt (Bo Thide') + * First Release. + * */ + +#include <stdio.h> +#include <stdlib.h> +#include "globals.h" + +static char rcsid[] = "$Header: storefont.c,v 0.8 92/11/23 19:47:01 bt Exp $"; + +/* + * Allocate memory for gfont structure and store font in memory + */ +storefont(bitfile, f) +FILE *bitfile; +int f; +{ + int i; + charfmt *u; + + if(verbose) + fprintf(stderr,"Font %d will be stored in memory\n", f); + gfont = (gfontfmt)malloc(sizeof(*gfont)); + gfontptr[f] = gfont; + for(i = font->bc ; i <= font->ec ; i++) { + u = cbase + i; + if(u->use_count) { + if(u->use_count > 0) + u->use_count = -u->use_count; + storechar(i); + } + } +} diff --git a/dviware/dvi2pcl/supportmatrix b/dviware/dvi2pcl/supportmatrix new file mode 100644 index 0000000000..d55ac24e21 --- /dev/null +++ b/dviware/dvi2pcl/supportmatrix @@ -0,0 +1,15 @@ + +In the following "support matrix" an 'X' means that 'dvi2pcl' has been +successfully tested on that particular software/hardware combination. + +---------------------------------------------------------------------------- + | Printer +System Compiler | lj+ lj2 lj2d lj2p lj3si lj3p pj pjxl lj2clone +---------------------------------------------------------------------------- +HP9000/300 cc | X X X X X X X +HP9000/400 cc | X X X X X X X +HP9000/700 cc | X X X X X X X +HP9000/700 gcc 2.2.2| X X X X X X X +PC/ISC2.2.1 gcc 2.2.1| X +PC/Linux gcc | X +---------------------------------------------------------------------------- diff --git a/dviware/dvi2pcl/tags b/dviware/dvi2pcl/tags new file mode 100644 index 0000000000..24a6aceae7 --- /dev/null +++ b/dviware/dvi2pcl/tags @@ -0,0 +1,63 @@ +Mmain main.c /^main(argc, argv, envp)$/ +betweenpages betweenpages.c /^betweenpages(dvifile, prescan)$/ +cachefonts cachefonts.c /^void cachefonts(bitfile, resfile, maxdown, device)/ +checkfont checkfont.c /^checkfont(dvifile,f)$/ +definefont definefont.c /^void definefont(dvifile, f)$/ +diagnostics diagnostics.c /^void diagnostics(usgfile)$/ +dim_to_dots dim_to_dots.c /^long dim_to_dots(data, resolution)$/ +doallpages doallpages.c /^void doallpages(bitfile, dvifile, pcllevel, revers/ +doodevpages doodevpages.c /^void doodevpages(bitfile, dvifile, pcllevel, rever/ +dopage dopage.c /^dopage(bitfile, dvifile, pcllevel, resolution, dev/ +dospecial dospecial.c /^void dospecial(bitfile, prescan, pcllevel, hh, vv,/ +downloadchar downloadchar.c /^int downloadchar(bitfile, c, device)$/ +downloadfont downloadfont.c /^long downloadfont(bitfile, permfontsdown, device)$/ +drawchar drawchar.c /^charfmt *drawchar(bitfile, c, hh, vv, resolution, / +drawrule drawrule.c /^void drawrule(bitfile, a, b, hh, vv)$/ +firstpar firstpar.c /^long firstpar(dvifile, k)$/ +getcount getcount.c /^getcount(p)$/ +getnib pknum.c /^#define getnib() ((c_nib = ~c_nib) ? (*pk_ptr & 0x/ +getoptions getoptions.c /^getoptions(argc, argv, envp, bitname, dviname, usg/ +getpsbyte macros.h /^#define getpsbyte(p) ((char)*p++)$/ +getpspair macros.h /^#define getpspair(p) (_i=getpsbyte(p),_i<<=8,_i|ge/ +getpsquad macros.h /^#define getpsquad(p) (getputrio(p),_i<<=8,_i|getpu/ +getpstrio macros.h /^#define getpstrio(p) (getpupair(p),_i<<=8,_i|getpu/ +getpubyte macros.h /^#define getpubyte(p) ((unsigned char)*p++)$/ +getpupair macros.h /^#define getpupair(p) (_i=getpubyte(p),_i<<=8,_i|=g/ +getpuquad macros.h /^#define getpuquad(p) (getputrio(p),_i<<=8,_i|=getp/ +getputrio macros.h /^#define getputrio(p) (getpupair(p),_i<<=8,_i|=getp/ +getsbyte macros.h /^#define getsbyte(f) (char)getc(f)$/ +getspair macros.h /^#define getspair(f) (_i=getsbyte(f),_i<<=8,_i|=get/ +getsquad macros.h /^#define getsquad(f) (getstrio(f),_i<<=8,_i|=getuby/ +getstrio macros.h /^#define getstrio(f) (getspair(f),_i<<=8,_i|=getuby/ +getubyte macros.h /^#define getubyte(f) (unsigned char)getc(f)$/ +getupair macros.h /^#define getupair(f) (_i=getubyte(f),_i<<=8,_i|=get/ +getutrio macros.h /^#define getutrio(f) (getupair(f),_i<<=8,_i|=getuby/ +initialize initialize.c /^initialize()$/ +loadpkfile loadpkfile.c /^void loadpkfile()$/ +loadtfmfile loadtfmfile.c /^loadtfmfile()$/ +makepkdir makepkdir.c /^makepkdir()$/ +openpkfile openpkfile.c /^FILE *openpkfile()$/ +opentfmfile opentfmfile.c /^FILE *opentfmfile(tfmname)$/ +permfonts permfonts.c /^int permfonts(resfile)$/ +pkcharinfo pkcharinfo.c /^byte *pkcharinfo(c)$/ +pknum pknum.c /^pknum()$/ +pktopxl pktopxl.c /^pktopxl(c)$/ +postamble postamble.c /^void postamble(dvifile)$/ +preamble preamble.c /^preamble(dvifile, resolution)$/ +prerror main.c /^prerror(s)$/ +prescanpage prescanpage.c /^prescanpage(bitfile, dvifile, pcllevel, resolution/ +printbop printbop.c /^printbop(startvals, count)$/ +printfont printfont.c /^printfont()$/ +rotatechar rotatechar.c /^byte *rotatechar()$/ +round macros.h /^#define round(f) (long)((_f = (f)) < 0.0 ? _f - 0./ +rulepixels rulepixels.c /^long rulepixels(x, conv)$/ +scanbop scanbop.c /^void scanbop(dvifile)$/ +skipfontdef skipfontdef.c /^void skipfontdef(dvifile)$/ +skipnextpage skipnextpage.c /^skipnextpage(dvifile)$/ +skippages skippages.c /^long skippages(bitfile, dvifile, pcllevel, resolut/ +sortfonts sortfonts.c /^int sortfonts(fontlist)$/ +sterror main.c /^void sterror(s, st)$/ +storechar storechar.c /^void storechar(c)$/ +storefont storefont.c /^storefont(bitfile, f)$/ +valerror main.c /^valerror(s,v)$/ +valvalerror main.c /^valvalerror(s,u,v)$/ |