home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume13 / lj2ps / part09 < prev    next >
Encoding:
Text File  |  1990-07-02  |  48.7 KB  |  1,481 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v13i094: lj2ps (09 of 12), a LaserJet to PostScript Translator
  3. From: lishka@uwslh.slh.wisc.edu (Chris Lishka (relaxing in the Mad-City) )
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 13, Issue 94
  7. Submitted-by: lishka@uwslh.slh.wisc.edu (Chris Lishka (relaxing in the Mad-City) )
  8. Archive-name: lj2ps/part09
  9.  
  10. ---- Cut Here and unpack ----
  11. #!/bin/sh
  12. # This is part 09 of a multipart archive
  13. if touch 2>&1 | fgrep '[-amc]' > /dev/null
  14.  then TOUCH=touch
  15.  else TOUCH=true
  16. fi
  17. # ============= errors.c ==============
  18. if test X"$1" != X"-c" -a -f 'errors.c'; then
  19.     echo "File already exists: skipping 'errors.c'"
  20. else
  21. echo "x - extracting errors.c (Text)"
  22. sed 's/^X//' << 'SHAR_EOF' > errors.c &&
  23. X/* Project:        lj2ps, LaserJet PCL to PostScript translator
  24. X** File:       errors.c
  25. X**
  26. X** Author:       Christopher Lishka
  27. X** Organization:   Wisconsin State Laboratory of Hygiene
  28. X**           Data Processing Dept.
  29. X**
  30. X** Copyright (C) 1990 by Christopher Lishka.
  31. X**
  32. X** This program is free software; you can redistribute it and/or modify
  33. X** it under the terms of the GNU General Public License as published by
  34. X** the Free Software Foundation; either version 1, or (at your option)
  35. X** any later version.
  36. X**
  37. X** This program is distributed in the hope that it will be useful,
  38. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  40. X** GNU General Public License for more details.
  41. X**
  42. X** You should have received a copy of the GNU General Public License
  43. X** along with this program; if not, write to the Free Software
  44. X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  45. X*/
  46. X
  47. Xstatic char * ModuleID = "Module errors: v1.0, production";
  48. X
  49. X#include <stdio.h>
  50. X#include "errors.h"
  51. X#include "lj2ps.h"
  52. X
  53. X
  54. X  /* Functions */
  55. Xextern void  warning();
  56. Xextern void  error();
  57. Xextern void  fatal_error();
  58. Xextern void  internal_error();
  59. X
  60. X
  61. X
  62. X  /* warning() prints a message to stderr about a minor problem.
  63. X  */
  64. Xvoid
  65. Xwarning(message, argument)
  66. X    char *message, *argument;
  67. X{
  68. X
  69. X  if( warnings ){
  70. X    fprintf(stderr, "%s %s (%s): WARNING\n", PROGRAM, VERSION, STATUS);
  71. X    fprintf(stderr, "%s", message);
  72. X    if( argument[0] != '\0' ) fprintf(stderr, " (%s)\n\n", argument);
  73. X    else                      fprintf(stderr, "\n\n");
  74. X  }
  75. X
  76. X} /* warning() */
  77. X
  78. X
  79. X
  80. X  /* error() prints a message to stderr about a major but recoverable problem.
  81. X  */
  82. Xvoid
  83. Xerror(message, argument)
  84. X    char *message, *argument;
  85. X{
  86. X
  87. X  fprintf(stderr, "%s %s (%s): ERROR\n", PROGRAM, VERSION, STATUS);
  88. X  fprintf(stderr, "%s", message);
  89. X  if( argument[0] != '\0' ) fprintf(stderr, " (%s)\n\n", argument);
  90. X  else                      fprintf(stderr, "\n\n");
  91. X
  92. X} /* error() */
  93. X
  94. X
  95. X
  96. X  /* fatal_error() prints a message to stderr about a major and
  97. X  ** unrecoverable problem, then exits gracelessly.
  98. X  */
  99. Xvoid
  100. Xfatal_error(message, argument)
  101. X    char *message, *argument;
  102. X{
  103. X
  104. X  fprintf(stderr, "%s %s (%s): FATAL ERROR\n", PROGRAM, VERSION, STATUS);
  105. X  fprintf(stderr, "%s", message);
  106. X  if( argument[0] != '\0' ) fprintf(stderr, " (%s)\n\n", argument);
  107. X  else                      fprintf(stderr, "\n\n");
  108. X
  109. X  exit(1);
  110. X
  111. X} /* fatal_error() */
  112. X
  113. X
  114. X
  115. X  /* internal_error() reports an inconsistency in the program itself.
  116. X  ** After the error message is reported, the program is killed
  117. X  ** gracelessly.
  118. X  */
  119. Xvoid
  120. Xinternal_error(message, argument)
  121. X    char *message, *argument;
  122. X{
  123. X
  124. X  fprintf(stderr, "%s %s (%s): INTERNAL ERROR\n", PROGRAM, VERSION, STATUS);
  125. X  fprintf(stderr, "%s", message);
  126. X  if( argument[0] != '\0' ) fprintf(stderr, " (%s)\n\n", argument);
  127. X  else                      fprintf(stderr, "\n\n");
  128. X
  129. X  exit(2);
  130. X
  131. X} /* internal_error() */
  132. X
  133. SHAR_EOF
  134. $TOUCH -am 0630160790 errors.c &&
  135. chmod 0644 errors.c ||
  136. echo "restore of errors.c failed"
  137. set `wc -c errors.c`;Wc_c=$1
  138. if test "$Wc_c" != "2950"; then
  139.     echo original size 2950, current size $Wc_c
  140. fi
  141. fi
  142. # ============= errors.h ==============
  143. if test X"$1" != X"-c" -a -f 'errors.h'; then
  144.     echo "File already exists: skipping 'errors.h'"
  145. else
  146. echo "x - extracting errors.h (Text)"
  147. sed 's/^X//' << 'SHAR_EOF' > errors.h &&
  148. X/*
  149. X** Project:        lj2ps
  150. X** File:       errors.h
  151. X**
  152. X** Author:       Christopher Lishka
  153. X** Organization:   Wisconsin State Laboratory of Hygiene
  154. X**           Data Processing Dept.
  155. X**
  156. X** Copyright (C) 1990 by Christopher Lishka.
  157. X**
  158. X** This program is free software; you can redistribute it and/or modify
  159. X** it under the terms of the GNU General Public License as published by
  160. X** the Free Software Foundation; either version 1, or (at your option)
  161. X** any later version.
  162. X**
  163. X** This program is distributed in the hope that it will be useful,
  164. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  165. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  166. X** GNU General Public License for more details.
  167. X**
  168. X** You should have received a copy of the GNU General Public License
  169. X** along with this program; if not, write to the Free Software
  170. X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  171. X*/
  172. X
  173. X  /* Global functions */
  174. Xextern void  warning();        /* Minor problem */
  175. Xextern void  error();        /* Major but recoverable problem */
  176. Xextern void  fatal_error();    /* Major unrecoverable problem */
  177. Xextern void  internal_error();    /* Problem with the programs innards */
  178. SHAR_EOF
  179. $TOUCH -am 0630160790 errors.h &&
  180. chmod 0644 errors.h ||
  181. echo "restore of errors.h failed"
  182. set `wc -c errors.h`;Wc_c=$1
  183. if test "$Wc_c" != "1170"; then
  184.     echo original size 1170, current size $Wc_c
  185. fi
  186. fi
  187. # ============= lj.c ==============
  188. if test X"$1" != X"-c" -a -f 'lj.c'; then
  189.     echo "File already exists: skipping 'lj.c'"
  190. else
  191. echo "x - extracting lj.c (Text)"
  192. sed 's/^X//' << 'SHAR_EOF' > lj.c &&
  193. X/* Project:        lj2ps
  194. X** File:       lj.c
  195. X**
  196. X** Author:       Christopher Lishka
  197. X** Organization:   Wisconsin State Laboratory of Hygiene
  198. X**           Data Processing Dept.
  199. X**
  200. X** Copyright (C) 1990 by Christopher Lishka.
  201. X**
  202. X** This program is free software; you can redistribute it and/or modify
  203. X** it under the terms of the GNU General Public License as published by
  204. X** the Free Software Foundation; either version 1, or (at your option)
  205. X** any later version.
  206. X**
  207. X** This program is distributed in the hope that it will be useful,
  208. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  209. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  210. X** GNU General Public License for more details.
  211. X**
  212. X** You should have received a copy of the GNU General Public License
  213. X** along with this program; if not, write to the Free Software
  214. X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  215. X*/
  216. X
  217. Xstatic char * ModuleID = "Module lj: v1.0, production";
  218. X
  219. X  /* Include files
  220. X  */
  221. X#include <stdio.h>
  222. X#include "lj.h"
  223. X#include "ljcmds.h"
  224. X#include "ljfonts.h"
  225. X#include "scan.h"
  226. X#include "lj2ps.h"
  227. X
  228. X  /* External definitions
  229. X  */
  230. X
  231. X  /* Global variables
  232. X  */
  233. X  /* Front panel variables */
  234. Xint    panel_copies;        /* Front panel: Copies */
  235. Xint    panel_manual_feed;    /* Front panel: Manual Feed */
  236. Xint    panel_font_source;    /* Front panel: Font Source */
  237. Xint    panel_font_number;    /* Front panel: Font Number */
  238. Xint    panel_orientation;    /* Front panel: Font Source, Font Number */
  239. Xint    panel_form;        /* Front panel: Form (i.e. lines/page) */
  240. X  /* Postscript specific variables */
  241. Xdouble ps_scale_x;        /* PS: scale in x direction */
  242. Xdouble ps_scale_y;        /* PS: scale in y direction */
  243. Xdouble ps_offset_x;        /* PS: offset in x direction */
  244. Xdouble ps_offset_y;        /* PS: offset in y direction */
  245. X  /* Job control */
  246. Xint     copies;            /* Number of copies */
  247. X  /* Page control */
  248. Xint     paper_source;        /* Where the paper is coming from */
  249. Xint     orientation;        /* Portrait/landscape          (code)      */
  250. Xpsize   page_size;        /* Type of paper being used   (structure) */
  251. Xdouble  page_height;        /* Height of physical page    (inches)      */
  252. Xdouble  page_width;        /* Width of physical page     (inches)      */
  253. Xdouble  char_height;        /* Char height (~= VMI)          (inches)      */
  254. Xdouble  char_width;        /* Char width  (~= HMI)          (inches)      */
  255. Xdouble  margin_top;        /* Top margin                 (inches)      */
  256. Xint     text_length;        /* Text length              (lines)      */
  257. Xdouble  text_height;        /* Text height                (inches)      */
  258. Xdouble  margin_left;        /* Left margin                (inches)    */
  259. Xdouble  text_width;        /* Text width                 (inches)      */
  260. Xint     perf_skip;        /* 1 if perforation skip is on */
  261. Xint     line_term;        /* Current line termination mode */
  262. X  /* Fonts */
  263. Xljfont  font_p;            /* Primary font */
  264. Xljfont  font_s;            /* Secondary font */
  265. Xint     underline;        /* Underline mode */
  266. X  /* Font management */
  267. Xint     font_ID;        /* Current font ID */
  268. Xint     char_code;        /* Current character code */
  269. X  /* Raster graphics */
  270. Xint     resolution;        /* Current graphics resolution */
  271. Xint     margin_graphics;    /* Graphics left margin, in dots? */
  272. X  /* Rectangular area fill */
  273. Xint     rect_size_h;        /* Horizontal rectangle size */
  274. Xint     rect_size_v;        /* Vertical rectangle size */
  275. Xint     fill_ID;        /* Current area fill ID */
  276. X  /* Macro */
  277. Xint     macro_ID;        /* Current macro ID */
  278. X  /* Troubleshooting commands */
  279. Xint     eol_wrap;        /* End-of-line wrap on/off */
  280. Xint     display_funcs;        /* Display functions on/off */
  281. X  /* Implementation variables */
  282. Xdouble  current_x;        /* Current X position         (inches)      */
  283. Xdouble  current_y;        /* Current Y position         (inches)      */
  284. Xint     current_line;        /* Current line being printed (lines)     */
  285. Xint     current_font;        /* Primary or secondary          (code)      */
  286. Xint     empty_line;        /* Ture if line is empty      (boolean)   */
  287. Xint     empty_text;        /* True if text is empty      (boolean)   */
  288. Xint     empty_page;        /* True if page is empty      (boolean)      */
  289. Xdouble  compress_width;        /* Compression in x axis      (%)         */
  290. Xdouble  compress_height;    /* Compression in y axis      (%)         */
  291. Xdouble  offset_width;        /* Offset of x axis           (inches)    */
  292. Xdouble  offset_height;        /* Offset of y axis           (inches)    */
  293. X
  294. X  /* Global function list
  295. X  */
  296. Xextern void  lj_factory_setup(); /* Reset to factory defaults */
  297. Xextern void  lj_startup();    /* Do before the virtual LJ is ready... */
  298. Xextern void  lj_shutdown();    /* Do after the virtual LJ is shutdown... */
  299. Xextern void  lj_page_begin();    /* Start a new page */
  300. Xextern void  lj_page_end();    /* End the current page */
  301. X/*     macro lj_text_begin();*/ /* Start text */
  302. X/*     macro lj_text_add(); */  /* Add text to buffer */
  303. X/*     macro lj_text_end(); */  /* End text (i.e. flush the buffer) */
  304. X/*     macro lj_cursor_move();*//* Move cursor to a new location */
  305. X/*     macro lj_set_font(); */  /* Use a new font to print the text */
  306. X/*     macro lj_undl_begin();*/    /* Start underlining */
  307. X/*     macro lj_undl_flush();*/    /* Flush the current underline request */
  308. X/*     macro lj_undl_end(); */    /* End underlining */
  309. Xextern void  lj_nl();        /* Print a newline */
  310. Xextern void  lj_reset();    /* Reset the printer to default state */
  311. Xextern int   lj_paper_size();    /* Get the dimensions of paper and envelopes */
  312. X
  313. X  /* Local constants
  314. X  */
  315. X
  316. X  /* Local structures and types
  317. X  */
  318. X
  319. X  /* Local variables
  320. X  */
  321. X  /* Implementation variables */
  322. Xstatic int     new_page;    /* Is the next page a new one? */
  323. Xstatic int     page_number;    /* Which page we are currently printing */
  324. X  /* Tables */
  325. Xpsize   paper_size[] = {    /* Sizes (in inches) for paper and envelopes */
  326. X  { LJ_PS_EXECUTIVE,         7.2500,  10.5000, 57,            /* Paper sizes */
  327. X                             0.2000,   0.2000,  0.1667,  0.3333 }, 
  328. X
  329. X  { LJ_PS_LETTER,            8.5000,  11.0000, 60,
  330. X                             0.2000,   0.2000,  0.1667,  0.3333 },
  331. X
  332. X  { LJ_PS_LEGAL,             8.5000,  14.0000, 78,
  333. X                             0.2000,   0.2000,  0.1667,  0.3333 },
  334. X
  335. X  { LJ_PS_A4,                8.2677,  11.6929, 64,
  336. X                             0.2000,   0.1933,  0.1667,  0.3067 },
  337. X
  338. X  { LJ_PS_MONARCH,           3.8750,   7.5000, 39,         /* Envelope sizes */
  339. X                             0.2000,   0.2000,  0.1667,  0.3333 },
  340. X
  341. X  { LJ_PS_COMMERCIAL10,      4.1250,   9.5000, 51,
  342. X                             0.2000,   0.2000,  0.1667,  0.3333 },
  343. X
  344. X  { LJ_PS_INTERNATIONALDL,   4.3307,   8.6614, 46,
  345. X                             0.2000,   0.1933,  0.1667,  0.3067 },
  346. X
  347. X  { LJ_PS_INTERNATIONALC5,   6.3780,   9.0157, 48,
  348. X                             0.2000,   0.1933,  0.1667,  0.3067 },
  349. X
  350. X  { 0,                       0.0000,   0.0000 }    /* The end must be all 0's */
  351. X};
  352. X
  353. X
  354. X  /* Local macro definitions
  355. X  */
  356. X
  357. X  /* Local function list
  358. X  */
  359. X
  360. X  /* Function bodies
  361. X  */
  362. X
  363. X
  364. Xvoid
  365. Xlj_factory_setup()
  366. X{
  367. X
  368. X  panel_copies = 1;
  369. X  panel_manual_feed = LJ_PS_TRAY_1;
  370. X  panel_form = 60;
  371. X  panel_orientation = LJ_OR_PORTRAIT;
  372. X  panel_font_source = LJ_FS_INTERNAL;
  373. X  panel_font_number = 0;
  374. X
  375. X  ps_scale_x  = 1.0;
  376. X  ps_scale_y  = 1.0;
  377. X  ps_offset_x = 0.0;
  378. X  ps_offset_y = 0.0;
  379. X
  380. X} /* lj_factory_setup() */
  381. X
  382. X
  383. X
  384. Xvoid
  385. Xlj_startup(ofile)
  386. X     FILE *ofile;
  387. X{
  388. X
  389. X    /* Set the default laserjet variables by executing a reset (ljcmd_E) */
  390. X  lj_reset(ofile);  
  391. X
  392. X    /*
  393. X    ** The postscript prologue
  394. X    **
  395. X    ** Postscript naming conventions used here:
  396. X    **
  397. X    **   Note: X = uppercase letter; x = lowercase letter.
  398. X    **
  399. X    **   X, XX, XXX:  Functions
  400. X    **
  401. X    **   x, xx, xxx:  Global variables
  402. X    **
  403. X    **      Xx, Xxx:  Temporary variables
  404. X    */
  405. X
  406. X    /* First write out the comments */
  407. X  fprintf(ofile, "%%!PS-Adobe-1.0\n"); /* The standard header */
  408. X  fprintf(ofile, "%%%%Creator: %s %s (%s)\n",
  409. X      PROGRAM, VERSION, STATUS); /* Identify oneself! */
  410. X  fprintf(ofile, "%%%%Pages: (atend)\n");
  411. X  fprintf(ofile, "%%%%EndComments\n");
  412. X  fprintf(ofile, "\n");
  413. X
  414. X    /* Next, write the prologue code */
  415. X
  416. X    /* Set the number of copies */
  417. X  fprintf(ofile, "/#copies %d def\n", copies);
  418. X
  419. X    /* Use letter size paper (8.5"x11") */
  420. X/*  fputs("letter\n", ofile);*/ /* XXX */
  421. X
  422. X    /* Set manual or automatic feed */
  423. X  if(   (paper_source == LJ_PS_MANUAL)
  424. X     || (paper_source == LJ_PS_MANUAL_ENVELOPE) ){
  425. X    fprintf(ofile, "statusdict begin /manualfeed true def end\n");
  426. X  }
  427. X  else{
  428. X    fprintf(ofile, "statusdict begin /manualfeed false def end\n");
  429. X  }
  430. X
  431. X    /* Define variables for the current font, font size, and font width */
  432. X  fputs("\n", ofile);
  433. X  fprintf(ofile, "/cf /%s def\n", font_p.ps_name);
  434. X  fprintf(ofile, "/cs %.4f def\n", pt2in(font_p.point_size));
  435. X  fprintf(ofile, "/cw %.4f def\n", font_p.width);
  436. X
  437. X    /* Left margin */
  438. X  fputs("\n", ofile);
  439. X  fprintf(ofile, "/ml %.4f def\n", margin_left);
  440. X
  441. X    /* Variables for underlining */
  442. X  fputs("\n", ofile);
  443. X  fputs("/ux 0.0 def\n", ofile); /* X coord of underline beginning */
  444. X  fputs("/uy 0.0 def\n", ofile); /* Y coord of underline beginning */
  445. X
  446. X    /* <String> S ->     % Show the string */
  447. X  fputs("\n/S /show load def\n", ofile);
  448. X
  449. X    /* <X> <Y> ->      % Move to (<X>,<Y>) */
  450. X  fputs("\n/M /moveto load def\n", ofile);
  451. X
  452. X    /* <DeltaX> HRM ->     % Move <DeltaX> horizontally (i.e. relative) */
  453. X  fputs("\n\
  454. X/HRM {\n\
  455. X  0 rmoveto\n\
  456. X} bind def\n\
  457. X", ofile);
  458. X
  459. X    /* <Y> VM ->     % Move to <Y> (i.e. vertical absolute) */
  460. X  fputs("\n\
  461. X/VM {\n\
  462. X  currentpoint pop exch moveto\n\
  463. X} bind def\n\
  464. X", ofile);
  465. X
  466. X    /* Set Right Margin -- uses clippath
  467. X    ** Note: 25 is used as an arbitrary size.  The only requirement of this
  468. X    ** number is that it must be outside the page boundaries
  469. X    */
  470. X  fputs("\n\
  471. X/RM {\n\
  472. X  /Tr exch def\n\
  473. X  currentpoint  initclip\n\
  474. X  newpath\n\
  475. X    0  0 moveto  Tr 0 lineto  Tr 25 lineto  0 25 lineto\n\
  476. X  closepath  clip\n\
  477. X  moveto\n\
  478. X} bind def\n\
  479. X", ofile);
  480. X
  481. X    /* <typeface> <point-size> F ->
  482. X    ** Set the font, given typeface and point size.
  483. X    ** Note that the character-width is derived by having PostScript
  484. X    ** provide the width of the *space* character (which is likely
  485. X    ** the best character to use for a proportional font).
  486. X    */
  487. X  fputs("\n\
  488. X/F {\n\
  489. X  /Tp exch def  /Tf exch def\n\
  490. X  Tf findfont Tp scalefont setfont\n\
  491. X  /cf Tf def  /cs Tp def  /cw ( ) stringwidth pop def\n\
  492. X} bind def\n\
  493. X", ofile);
  494. X
  495. X    /* <typeface> <width> <height> FS ->
  496. X    ** Set the font, given typeface, X scale factor, Y scale factor.
  497. X    ** Note that the character-width is derived by having PostScript
  498. X    ** provide the width of the *space* character (which is likely
  499. X    ** the best character to use for a proportional font).
  500. X    */
  501. X  fputs("\n\
  502. X/FS {\n\
  503. X  /Ty exch def  /Tx exch def  /Tf exch def\n\
  504. X  Tf findfont [Tx 0 0 Ty 0 0] makefont setfont\n\
  505. X  /cf Tf def  /cs Ty def /cw ( ) stringwidth pop def\n\
  506. X} bind def\n\
  507. X", ofile);
  508. X
  509. X    /* US ->     Start a new underline */
  510. X  fputs("\n\
  511. X/US {\n\
  512. X  currentpoint /uy exch def /ux exch def\n\
  513. X} bind def\n\
  514. X", ofile);
  515. X
  516. X    /* UE ->     Finish (i.e. draw!) the current underline
  517. X    **
  518. X    ** Note that this underlining does not yet work across separate lines,
  519. X    ** so US and UE must be called on the same line.  Also, underlining does
  520. X    ** not work backwards, so only use it if going forwards with the
  521. X    ** underlines (yes, I know this is very limited, but tracking page motion
  522. X    ** is a bit hard with underlining).
  523. X    */
  524. X  fputs("\n\
  525. X/UE {\n\
  526. X  /Tcx currentpoint pop def\n\
  527. X  gsave\n\
  528. X    newpath\n\
  529. X    cf findfont cs scalefont dup\n\
  530. X    /FontMatrix get 0 get /Ts exch def /FontInfo get dup\n\
  531. X    /UnderlinePosition get Ts mul /To exch def\n\
  532. X    /UnderlineThickness get Ts mul /Tt exch def\n\
  533. X    ux uy To add moveto  Tcx uy To add lineto\n\
  534. X    Tt setlinewidth stroke\n\
  535. X  grestore\n\
  536. X} bind def\n\
  537. X", ofile);
  538. X
  539. X    /* TAB ->          Tab over to the next tab stop
  540. X    ** For efficiency, this function gets the currentpoint, exch's to
  541. X    ** get the current-x to the top-of-stack, works magic on the
  542. X    ** current-x to figure out the position of the tab stop, exch's
  543. X    ** again to get the arguments in the right sequence for the moveto
  544. X    ** operator, and moves to the tab position.
  545. X    **
  546. X    ** Note that (1.0 + LJ_ERROR) is added to the calculation.  The 1.0
  547. X    ** represents the movement to the next tab-stop.  LJ_ERROR is needed
  548. X    ** insure that the value is within a certain error-margin in its proximity
  549. X    ** to the tab-stop when the "cvi" (i.e. drop the decimal portion) is
  550. X    ** performed.
  551. X    */
  552. X  fprintf(ofile, "\n\
  553. X/TAB {\n\
  554. X  currentpoint exch\n\
  555. X  ml sub cw div %d div %f add cvi %d mul cw mul ml add\n\
  556. X  exch moveto\n\
  557. X} bind def\n\
  558. X",
  559. X      LJ_TAB_WIDTH,
  560. X      (1.0 + LJ_ERROR),
  561. X      LJ_TAB_WIDTH);
  562. X
  563. X    /* Initialization of the position stack would go here, if it was
  564. X    ** implemented! */
  565. X
  566. X    /* Mark the end of the prolog */
  567. X  fprintf(ofile, "\n%%%%EndProlog\n");
  568. X
  569. X    /* Start the first page */
  570. X  new_page = 1;
  571. X  page_number = 0;
  572. X
  573. X} /* lj_startup() */
  574. X
  575. X
  576. X
  577. Xvoid
  578. Xlj_shutdown(ofile)
  579. X     FILE *ofile;
  580. X{
  581. X
  582. X  fprintf(ofile, "\nstatusdict begin /manualfeed false def end\n");
  583. X  fprintf(ofile, "%%%%Trailer\n");
  584. X  fprintf(ofile, "%%%%Pages: %d\n", page_number);
  585. X
  586. X} /* lj_shutdown() */
  587. X
  588. X
  589. X
  590. Xvoid
  591. Xlj_page_begin(ofile)
  592. X     FILE *ofile;
  593. X{
  594. X
  595. X    /* Set starting position */
  596. X  current_x    = margin_left;
  597. X  current_y    = page_height - margin_top - char_height;
  598. X  current_line = 1;
  599. X
  600. X    /* Print the PostScript page header */
  601. X  if( new_page ){
  602. X    page_number++;
  603. X    fprintf(ofile, "\n%%%%Page: ? %d\n", page_number);
  604. X  }
  605. X
  606. X    /* Save the current graphics state */
  607. X  fputs("save\n", ofile);    
  608. X
  609. X    /* Note: the next three pieces of code must be in the following
  610. X    ** order to insure that everything works correctly:
  611. X    **
  612. X    ** (1) Make inches the default measure
  613. X    ** (2) Rotate the the page to landscape, if necessary
  614. X    ** (3) Perform default offsets and page scaling
  615. X    */
  616. X
  617. X    /* Make inches the default measure.  Note that this must be at the
  618. X    ** beginning of every *page* (rather than in the prologue) because
  619. X    ** the PostScript showpage function resets the graphics state.
  620. X    */
  621. X  fprintf(ofile, "72 72 scale\n");
  622. X
  623. X    /* Rotate the page to the proper orientation */
  624. X  if( orientation == LJ_OR_LANDSCAPE ){
  625. X    fprintf(ofile,
  626. X        "90 rotate 0 %.4f translate\n",
  627. X        -page_size.width);
  628. X  }
  629. X
  630. X    /* Make sure everything fits in the printable region */
  631. X  fprintf(ofile, "%.4f %.4f translate  %.4f %.4f scale\n",
  632. X      offset_width,   offset_height,
  633. X      compress_width, compress_height);
  634. X
  635. X    /* Make sure that a current point exists */
  636. X  fputs("0 0 moveto\n", ofile);    
  637. X
  638. X    /* Set the initial font */
  639. X  if( current_font == LJ_FT_PRIMARY )
  640. X    lj_set_font(ofile, font_p);
  641. X  else
  642. X    lj_set_font(ofile, font_s);
  643. X
  644. X    /* Set the left margin */
  645. X  fprintf(ofile, "/ml %.4f def ", margin_left);
  646. X
  647. X    /* Set the right margin */
  648. X  fprintf(ofile, " %.4f RM ", 
  649. X      margin_left + text_width);
  650. X
  651. X    /* Default position */
  652. X  fprintf(ofile,        
  653. X      "%.4f %.4f M\n", current_x, current_y);
  654. X
  655. X  empty_page = 1;
  656. X  lj_undl_mark(ofile);
  657. X  lj_text_begin();
  658. X
  659. X} /* lj_page_begin() */
  660. X
  661. X
  662. X
  663. Xvoid
  664. Xlj_page_end(ofile)
  665. X     FILE *ofile;
  666. X{
  667. X
  668. X  lj_text_end(ofile);
  669. X  lj_undl_flush(ofile);
  670. X  fputs("\nrestore ", ofile);
  671. X  if( empty_page ){
  672. X      /* Clear the page without using erasepage! */
  673. X    fputs("gsave newpath clippath 1 setgray fill grestore\n", ofile);
  674. X    new_page = 0;        /* Still the same physical page */
  675. X  }
  676. X  else{
  677. X    fputs("showpage\n", ofile); /* Print the page */
  678. X    new_page = 1;        /* A new physical page is started */
  679. X  }
  680. X
  681. X} /* lj_page_end() */
  682. X
  683. X
  684. X
  685. Xvoid
  686. Xlj_nl(ofile)
  687. X     FILE *ofile;
  688. X{
  689. X
  690. X  lj_text_end(ofile);
  691. X  lj_undl_flush(ofile);
  692. X
  693. X  current_x  = margin_left;
  694. X  current_y -= char_height;
  695. X  fprintf(ofile, "%% NL\n%.4f %.4f M ", current_x, current_y);
  696. X
  697. X  empty_line = 1;
  698. X  lj_undl_mark(ofile);
  699. X  lj_text_begin();
  700. X
  701. X} /* lj_nl() */
  702. X
  703. X
  704. X
  705. Xvoid
  706. Xlj_reset(ofile)
  707. X     FILE *ofile;
  708. X{
  709. X
  710. X    /* ***** JOB CONTROL **************************************************
  711. X    */
  712. X  copies = panel_copies;    /* Number of copies, from the "front panel" */
  713. X
  714. X    /* ***** FONTS ********************************************************
  715. X    **
  716. X    ** Note: fonts must come before page control because the HMI (i.e.
  717. X    **       char_width) is determined from the font.
  718. X    */
  719. X
  720. X    /* Reset the primary font */
  721. X  if( lj_find_font(panel_font_source, panel_font_number, &font_p) == 1 ){
  722. X    fatal_error("could not find specified font", "");
  723. X  }
  724. X
  725. X    /* Reset the secondary font */
  726. X  if( lj_find_font(panel_font_source, panel_font_number, &font_p) == 1 ){
  727. X    fatal_error("could not find specified font", "");
  728. X  }
  729. X
  730. X    /* Underline, should be off */
  731. X  underline = LJ_UL_OFF;
  732. X
  733. X
  734. X    /* ***** PAGE CONTROL ************************************************
  735. X    */
  736. X
  737. X    /* Paper source, from the "front panel" */
  738. X  paper_source = panel_manual_feed;
  739. X
  740. X    /* Page orientation, from the "front panel" */
  741. X  orientation = panel_orientation;
  742. X
  743. X    /* Determine the physical page size */
  744. X  page_size.code = LJ_PS_LETTER; /* Letter size, by default */
  745. X  if( lj_paper_size(&page_size) ){
  746. X    internal_error("illegal page size", "");
  747. X  }
  748. X
  749. X    /* Page width and height */
  750. X  if( orientation == LJ_OR_PORTRAIT ){
  751. X    page_width = page_size.width;
  752. X    page_height = page_size.height;
  753. X  }
  754. X  else{
  755. X    page_width = page_size.height;
  756. X    page_height = page_size.width;
  757. X  }
  758. X
  759. X    /* Top margin, text height (inches), and text length (lines).
  760. X    ** Char width and height are set here as well due to the
  761. X    ** inter-dependencies.
  762. X    */
  763. X  margin_top  = 0.5;        /* Top and bottom margins are 1/2" */
  764. X  text_height = page_height - margin_top - 0.5;    /* 0.5 is for bottom margin */
  765. X  char_height = text_height / panel_form;
  766. X  char_width  = font_p.width;    /* inches per character */
  767. X  text_length = text_height / char_height;
  768. X
  769. X    /* Left margin + text_width (= page width - right margin) */
  770. X  margin_left = 0.0;
  771. X    /* Initially, the right margin is not set.  To simulate this, the
  772. X    ** text_width is set to be wider than any reasonable page width.
  773. X    */
  774. X  text_width  = 99.00;
  775. X
  776. X    /* Perforation skip */
  777. X  perf_skip = 1;
  778. X
  779. X    /* Line termination: start with normal */
  780. X  line_term = LJ_LT_NORM;
  781. X
  782. X
  783. X    /* ***** FONT MANAGEMENT **********************************************
  784. X    */
  785. X
  786. X    /* Current font ID, for soft fonts */
  787. X  font_ID = 0;
  788. X
  789. X    /* Current character code, for soft fonts */
  790. X  char_code = 0;
  791. X
  792. X
  793. X    /* ***** RASTER GRAPHICS **********************************************
  794. X    */
  795. X
  796. X    /* Graphics resolution, start at 300 dpi */
  797. X  resolution = 75;
  798. X
  799. X    /* Graphics margin, start at 0 */
  800. X  margin_graphics = 0;
  801. X
  802. X
  803. X    /* ***** RECTANGULAR AREA FILL ****************************************
  804. X    */
  805. X
  806. X    /* ID for filling areas (one ID used for both patterns and gray scales) */
  807. X  fill_ID = LJ_FI_RULE;        /* *Black* greyscale! */
  808. X
  809. X    /* Horizontal and vertical graphics area sizes */
  810. X  rect_size_h = 0;
  811. X  rect_size_v = 0;
  812. X
  813. X
  814. X    /* ***** MACRO ********************************************************
  815. X    */
  816. X
  817. X    /* Current macro ID */
  818. X  macro_ID = 0;
  819. X
  820. X
  821. X    /* ***** TROUBLESHOOTING COMMANDS *************************************
  822. X    */
  823. X
  824. X    /* End-of-line wrap: should be off */
  825. X  eol_wrap = 0;
  826. X
  827. X    /* Display functions should be off */
  828. X  display_funcs = 0;
  829. X
  830. X
  831. X    /* ***** IMPLEMENTATION VARIABLES *************************************
  832. X    */
  833. X  current_x = margin_left;
  834. X  current_y = page_height - margin_top - char_height;
  835. X  current_line = 1;
  836. X  current_font = LJ_FT_PRIMARY;
  837. X  empty_line = 1;
  838. X  empty_text = 1;
  839. X  empty_page = 1;
  840. X  compress_width  = ps_scale_x * LJ_DEFAULT_SCALE_X;
  841. X  compress_height = ps_scale_y * LJ_DEFAULT_SCALE_Y;
  842. X  offset_width    = ps_offset_x + LJ_DEFAULT_OFFSET_X;
  843. X  offset_height   = ps_offset_y + LJ_DEFAULT_OFFSET_Y;
  844. X
  845. X} /* lj_reset() */
  846. X
  847. X
  848. X
  849. X  /* lj_paper_size() looks up the dimensions of the paper or envelope
  850. X  ** passed in the code field of the argument.  If the code is legal, then
  851. X  ** the width and height fields are filled and a 0 is returned.  If the
  852. X  ** code does not exist, then the width and height fields are undefined and
  853. X  ** a 1 is returned.
  854. X  */
  855. Xint
  856. Xlj_paper_size(page_size)
  857. X     psize *page_size;
  858. X{
  859. X  int found;
  860. X  int counter;
  861. X  
  862. X  found = 0;
  863. X  for( counter = 0; !found && !(paper_size[counter].code == 0); counter++ ){
  864. X    if( page_size->code == paper_size[counter].code ){
  865. X      found = 1;
  866. X      page_size->width  = paper_size[counter].width;
  867. X      page_size->height = paper_size[counter].height;
  868. X    } /* if(...) */
  869. X  } /* for(...) */
  870. X
  871. X  return( !found );
  872. X} /* lj_paper_size() */
  873. SHAR_EOF
  874. $TOUCH -am 0630160790 lj.c &&
  875. chmod 0644 lj.c ||
  876. echo "restore of lj.c failed"
  877. set `wc -c lj.c`;Wc_c=$1
  878. if test "$Wc_c" != "20389"; then
  879.     echo original size 20389, current size $Wc_c
  880. fi
  881. fi
  882. # ============= lj.h ==============
  883. if test X"$1" != X"-c" -a -f 'lj.h'; then
  884.     echo "File already exists: skipping 'lj.h'"
  885. else
  886. echo "x - extracting lj.h (Text)"
  887. sed 's/^X//' << 'SHAR_EOF' > lj.h &&
  888. X/*
  889. X** Project:        lj2ps
  890. X** File:       lj.h
  891. X**
  892. X** Author:       Christopher Lishka
  893. X** Organization:   Wisconsin State Laboratory of Hygiene
  894. X**           Data Processing Dept.
  895. X**
  896. X** Copyright (C) 1990 by Christopher Lishka.
  897. X**
  898. X** This program is free software; you can redistribute it and/or modify
  899. X** it under the terms of the GNU General Public License as published by
  900. X** the Free Software Foundation; either version 1, or (at your option)
  901. X** any later version.
  902. X**
  903. X** This program is distributed in the hope that it will be useful,
  904. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  905. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  906. X** GNU General Public License for more details.
  907. X**
  908. X** You should have received a copy of the GNU General Public License
  909. X** along with this program; if not, write to the Free Software
  910. X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  911. X*/
  912. X
  913. X#ifndef LJ_H
  914. X#define LJ_H
  915. X
  916. X  /* Global constants
  917. X  */
  918. X  /* Implementation constraints */
  919. X#define LJ_STRING_SIZE  256
  920. X#define LJ_ERROR  0.00001    /* Accuracy of floating point numbers */
  921. X  /* Default scaling constants */
  922. X#define LJ_DEFAULT_SCALE_X   1.0000
  923. X#define LJ_DEFAULT_SCALE_Y   0.99
  924. X  /* Default offset constants */
  925. X#define LJ_DEFAULT_OFFSET_X  0.2500
  926. X#define LJ_DEFAULT_OFFSET_Y  0.0000
  927. X  /* Measurements */
  928. X#define in   1            /* Inches (base unit of measurement) */
  929. X#define dt 300            /* Dots per inch */
  930. X#define dp 720            /* Decipoints */
  931. X#define hi 120            /* Horizontal Index Unit */
  932. X#define vi  48            /* Vertical Index Unit */
  933. X#define pt  72            /* Points */
  934. X  /* Tab stops */
  935. X#define LJ_TAB_WIDTH 8        /* Tabs occur every eight characters */
  936. X  /* Internal codes */
  937. X#define LJ_UL_OFF             100 /* Underline codes */
  938. X#define LJ_UL_ON              101
  939. X#define LJ_UL_FLOAT           102
  940. X#define LJ_FI_RULE            200 /* Fill codes      Rule */
  941. X#define LJ_FI_2               201 /*              2% gray */
  942. X#define LJ_FI_10              202 /*             10% gray */
  943. X#define LJ_FI_15              203 /*             15% gray */
  944. X#define LJ_FI_30              204 /*             30% gray */
  945. X#define LJ_FI_45              205 /*             45% gray */
  946. X#define LJ_FI_70              206 /*             70% gray */
  947. X#define LJ_FI_90              207 /*             90% gray */
  948. X#define LJ_FI_100             208 /*            100% gray */
  949. X#define LJ_FI_LINE_H          209 /*     Horizontal lines */
  950. X#define LJ_FI_LINE_V          210 /*     Vertical lines */
  951. X#define LJ_FI_DIAG_1          211 /*     Diagonals 1 */
  952. X#define LJ_FI_DIAG_2          212 /*     Diagonals 2 */
  953. X#define LJ_FI_GRID_SQ         213 /*     Square grid */
  954. X#define LJ_FI_GRID_DIAG       214 /*     Diagonal grid */
  955. X#define LJ_LT_NORM            301 /* Line termination    normal */
  956. X#define LJ_LT_CR              302 /* cr=cr+lf lf=lf ff=ff */
  957. X#define LJ_LT_LF_FF           303 /* cr=cr lf=cr+lf ff=cr+ff */
  958. X#define LJ_LT_CR_LF_FF        304 /* cr=cr+lf lf=cr+lf ff=cr+ff */
  959. X#define LJ_PS_TRAY_1          301 /* Paper source */
  960. X#define LJ_PS_TRAY_2          302
  961. X#define LJ_PS_MANUAL          303
  962. X#define LJ_PS_MANUAL_ENVELOPE 304
  963. X#define LJ_OR_PORTRAIT        401 /* Orientation */
  964. X#define LJ_OR_LANDSCAPE       402
  965. X#define LJ_SS_0B              501 /* Symbol set: bit vector entries */
  966. X#define LJ_SS_0N              502
  967. X#define LJ_SS_0U              503
  968. X#define LJ_SS_1U              504
  969. X#define LJ_SS_8U              505
  970. X#define LJ_SS_10U             506
  971. X#define LJ_SS_11U             507
  972. X#define LJ_TF_HELV            601 /* Typefaces */
  973. X#define LJ_TF_TIMES           602
  974. X#define LJ_TF_PRES            603
  975. X#define LJ_TF_LP              604
  976. X#define LJ_TF_COUR            605
  977. X#define LJ_SP_PROPORTIONAL    701 /* Spacing */
  978. X#define LJ_SP_FIXED           702
  979. X#define LJ_ST_UPRIGHT         801 /* Font style */
  980. X#define LJ_ST_ITALIC          802
  981. X#define LJ_FT_PRIMARY         901 /* Primary/secondary current font */
  982. X#define LJ_FT_SECONDARY       902
  983. X#define LJ_PS_EXECUTIVE       1001 /* Page size codes */
  984. X#define LJ_PS_LETTER          1002
  985. X#define LJ_PS_LEGAL           1003
  986. X#define LJ_PS_A4              1004
  987. X#define LJ_PS_MONARCH         1005
  988. X#define LJ_PS_COMMERCIAL10    1006
  989. X#define LJ_PS_INTERNATIONALDL 1007
  990. X#define LJ_PS_INTERNATIONALC5 1008
  991. X#define LJ_FS_INTERNAL        1101 /* Font sources */
  992. X#define LJ_FS_LEFT            1102
  993. X#define LJ_FS_RIGHT           1103
  994. X#define LJ_FS_SOFT            1104
  995. X
  996. X  /* Global structure and type definitions
  997. X  */
  998. X
  999. X  /* Data required for a laserjet font */
  1000. Xtypedef struct {
  1001. X    /* Identifier fields */
  1002. X  int     source;        /* Font source: where the font is located */
  1003. X  int     number;        /* Font number */
  1004. X     /* Scaling fields */
  1005. X  int     scale;        /* True if scaling should be performed */
  1006. X  double  scale_x;        /* % to scale in x direction */
  1007. X  double  scale_y;        /* % to scale in y direction */
  1008. X    /* LaserJet font ID fields */
  1009. X  int     symbol_set;        /* The symbol set of the font */
  1010. X  int     spacing;        /* Proportional/fixed */
  1011. X  double  pitch;        /* (Only valid for fixed width fonts!) */
  1012. X  double  point_size;        /* Height of the character */
  1013. X  int     style;        /* Upright/italic */
  1014. X  int     weight;        /* Stroke weight: -3 to +3 */
  1015. X  int     typeface;        /* Which typeface to use */
  1016. X  char    ps_name[LJ_STRING_SIZE]; /* The postscript font used for emulation */
  1017. X  double  width;        /* Width of a character */
  1018. X} ljfont;
  1019. X  /* Data required to determine paper size */
  1020. Xtypedef struct {
  1021. X  int     code;            /* Type of paper: letter, legal, A4, etc. */
  1022. X  double  width;        /* How wide (inches) */
  1023. X  double  height;        /* How high (inches) */
  1024. X  int     default_form;        /* Default value for form variable */
  1025. X  double  unprint_top;        /* Unprintable region - top */
  1026. X  double  unprint_bottom;    /* Unprintable region - bottom */
  1027. X  double  unprint_left;        /* Unprintable region - left */
  1028. X  double  unprint_right;    /* Unprintable region - right */
  1029. X} psize;
  1030. X
  1031. X  /* Global variables
  1032. X  */
  1033. X  /* Front panel variables */
  1034. Xextern int    panel_copies;    /*  Front panel: Copies */
  1035. Xextern int    panel_manual_feed; /* Front panel: Manual Feed */
  1036. Xextern int    panel_font_source; /* Front panel: Font Source */
  1037. Xextern int    panel_font_number; /* Front panel: Font Number */
  1038. Xextern int    panel_orientation; /* Front panel: Font Source, Font Number */
  1039. Xextern int    panel_form;    /*  Front panel: Form (i.e. lpi) */
  1040. X  /* Postscript specific variables */
  1041. Xextern double ps_scale_x;    /* PS: scale in x direction */
  1042. Xextern double ps_scale_y;    /* PS: scale in y direction */
  1043. Xextern double ps_offset_x;    /* PS: offset in x direction */
  1044. Xextern double ps_offset_y;    /* PS: offset in y direction */
  1045. X  /* Job control */
  1046. Xextern int     copies;        /* Number of copies */
  1047. X  /* Page control */
  1048. Xextern int     paper_source;    /* Where the paper is coming from */
  1049. Xextern int     orientation;    /* Portrait/landscape          (code)      */
  1050. Xextern psize   page_size;    /* Type of paper being used   (structure) */
  1051. Xextern double  page_height;    /* Height of physical page    (inches)      */
  1052. Xextern double  page_width;    /* Width of physical page     (inches)      */
  1053. Xextern double  char_height;    /* Char height (~= VMI)          (inches)      */
  1054. Xextern double  char_width;    /* Char width  (~= HMI)          (inches)      */
  1055. Xextern double  margin_top;    /* Top margin                 (inches)      */
  1056. Xextern int     text_length;    /* Text length              (lines)      */
  1057. Xextern double  text_height;    /* Text height                (inches)      */
  1058. Xextern double  margin_left;    /* Left margin                (inches)    */
  1059. Xextern double  text_width;    /* Text width                 (inches)      */
  1060. Xextern int     perf_skip;    /* 1 if perforation skip is on */
  1061. Xextern int     line_term;    /* Current line termination mode */
  1062. X  /* Fonts */
  1063. Xextern ljfont  font_p;        /* Primary font */
  1064. Xextern ljfont  font_s;        /* Secondary font */
  1065. Xextern int     underline;    /* Underline mode */
  1066. X  /* Font management */
  1067. Xextern int     font_ID;        /* Current font ID */
  1068. Xextern int     char_code;    /* Current character code */
  1069. X  /* Raster graphics */
  1070. Xextern int     resolution;    /* Current graphics resolution */
  1071. Xextern int     margin_graphics;    /* Graphics left margin, in dots? */
  1072. X  /* Rectangular area fill */
  1073. Xextern int     rect_size_h;    /* Horizontal rectangle size */
  1074. Xextern int     rect_size_v;    /* Vertical rectangle size */
  1075. Xextern int     fill_ID;        /* Current area fill ID */
  1076. X  /* Macro */
  1077. Xextern int     macro_ID;    /* Current macro ID */
  1078. X  /* Troubleshooting commands */
  1079. Xextern int     eol_wrap;    /* End-of-line wrap on/off */
  1080. Xextern int     display_func;    /* Display functions on/off */
  1081. X  /* Implementation variables */
  1082. Xextern double  current_x;    /* Current X position         (inches)      */
  1083. Xextern double  current_y;    /* Current Y position         (inches)      */
  1084. Xextern int     current_line;    /* Current line being printed (lines)     */
  1085. Xextern int     current_font;    /* Primary or secondary          (code)      */
  1086. Xextern int     empty_line;    /* True if line is empty      (boolean)   */
  1087. Xextern int     empty_text;    /* True if text is empty      (boolean)   */
  1088. Xextern int     empty_page;    /* True if page is empty      (boolean)      */
  1089. Xextern double  compress_width;    /* Compression in x axis      (%)      */
  1090. Xextern double  compress_height;    /* Compression in y axis      (%)      */
  1091. Xextern double  offset_width;    /* Offset of x axis           (inches)    */
  1092. Xextern double  offset_height;    /* Offset of y axis           (inches)    */
  1093. X
  1094. X  /* Global macro definitions
  1095. X  */
  1096. X  /* Conversion macros */
  1097. X#define dt2in(x)  (x/dt)    /* Dots to inches */
  1098. X#define in2dt(x)  (x*dt)    /* Inches to dots */
  1099. X#define dp2in(x)  (x/dp)    /* Decipoints to inches */
  1100. X#define in2dp(x)  (x*dp)    /* Inches to decipoints */
  1101. X#define hi2in(x)  (x/hi)    /* Horizontal index units to inches */
  1102. X#define in2hi(x)  (x*hi)    /* Inches to horizontal index units */
  1103. X#define vi2in(x)  (x/vi)    /* Vertical index units to inches */
  1104. X#define in2vi(x)  (x*vi)    /* Inches to vertical index units */
  1105. X#define pt2in(x)  (x/pt)    /* Points to inches */
  1106. X#define in2pt(x)  (x*pt)    /* Inches to points */
  1107. X#define co2in(x)  (x*char_width) /* Columns to inches */
  1108. X#define in2co(x)  (x/char_width) /* Inches to columns */
  1109. X#define ro2in(x)  (x*char_height) /* Rows to inches */
  1110. X#define in2ro(x)  (x/char_height) /* Inches to rows */
  1111. X  /* Emulation macros */
  1112. X  /* Text buffer macros */
  1113. X#define lj_text_begin()   \
  1114. X  ( empty_text = 1 )
  1115. X#define lj_text_add(F, X) \
  1116. X  ( (empty_text?fprintf((F),"(%s",X):fputs((X),(F))), \
  1117. X   empty_text = 0, empty_line = 0, empty_page = 0 )
  1118. X#define lj_text_end(F) \
  1119. X  ( (!empty_text) \
  1120. X   ? fputs(")S ",F) \
  1121. X   : 0)
  1122. X  /* Cursor positioning macros */
  1123. X#define lj_cursor_abs(F, X, Y) \
  1124. X  (current_x = (X), current_y = (Y), \
  1125. X   fprintf(F, "%.4f %.4f M ", current_x, current_y))
  1126. X#define lj_cursor_hor_abs(F, X) \
  1127. X  (current_x = (X), fprintf(F, "%.4f %.4f M ", current_x, current_y))
  1128. X#define lj_cursor_hor_rel(F, dX) \
  1129. X  (fprintf(F, "%.4f HRM ", (dX)))
  1130. X#define lj_cursor_ver_abs(F, Y) \
  1131. X  (current_y = (Y), fprintf(F, "%.4f VM ", current_y))
  1132. X#define lj_cursor_ver_rel(F, dY) \
  1133. X  (current_y -= (dY), fprintf(F, "%.4f VM ", current_y))
  1134. X  /* Font macros */
  1135. X#define lj_set_font(Z, X) \
  1136. X  ( char_width = (X).width, \
  1137. X   ( (X).scale \
  1138. X   ? fprintf((Z), "/%s %.4f %.4f FS ", (X).ps_name, \
  1139. X         pt2in((X).point_size) * (X).scale_x, \
  1140. X         pt2in((X).point_size) * (X).scale_y) \
  1141. X   : fprintf((Z), "/%s %.4f F ", \
  1142. X         (X).ps_name, \
  1143. X         pt2in((X).point_size)) ) )
  1144. X  /* Underlining macros */
  1145. X#define lj_undl_begin(F)  (underline = LJ_UL_ON,  fputs("US ", (F)))
  1146. X#define lj_undl_mark(F) \
  1147. X  ( (underline == LJ_UL_ON) \
  1148. X   ? (fputs("US ", (F))) \
  1149. X   : 0 )
  1150. X#define lj_undl_flush(F) \
  1151. X  ( (underline == LJ_UL_ON) \
  1152. X   ? (fputs("UE ", (F))) \
  1153. X   : 0 )
  1154. X#define lj_undl_end(F)    (underline = LJ_UL_OFF, fputs("UE ", (F)))
  1155. X  /* Number of copies */
  1156. X#define lj_copies(F, C) \
  1157. X  ( fprintf((F), "/#copies %d def ", (C)) )
  1158. X
  1159. X  /* Global functions
  1160. X  */
  1161. Xextern void  lj_factory_setup(); /* Reset to factory defaults */
  1162. Xextern void  lj_startup();    /* Do before the virtual LJ is ready... */
  1163. Xextern void  lj_shutdown();    /* Do after the virtual LJ is shutdown... */
  1164. Xextern void  lj_page_begin();    /* Start a new page */
  1165. Xextern void  lj_page_end();    /* End the current page */
  1166. X/*     macro lj_text_begin();*/ /* Start text */
  1167. X/*     macro lj_text_add(); */  /* Add text to the buffer */
  1168. X/*     macro lj_text_end(); */  /* End text */
  1169. X/*     macro lj_cursor_abs();*/ /* Absolute X,Y cursor positioning */
  1170. X/*     macro lj_cursor_hor_abs(); */ /* Absolute X cursor positioning */
  1171. X/*     macro lj_cursor_hor_rel(); */ /* Relative X cursor positioning */
  1172. X/*     macro lj_cursor_ver_abs(); */ /* Absolute Y cursor positioning */
  1173. X/*     macro lj_cursor_ver_rel(); */ /* Relative Y cursor positioning */
  1174. X/*     macro lj_set_font(); */  /* Use a new font to print the text */
  1175. X/*     macro lj_undl_begin();*/    /* Start underlining */
  1176. X/*     macro lj_undl_mark();*/  /* Mark the start of a new underline */
  1177. X/*     macro lj_undl_flush();*/    /* Flush the current underline buffer */
  1178. X/*     macro lj_undl_end(); */    /* End underlining */
  1179. X/*     macro lj_copies(); */    /* Set the number of copies */
  1180. Xextern void  lj_nl();        /* Print a newline */
  1181. Xextern void  lj_reset();    /* Reset the printer to default state */
  1182. Xextern int   lj_paper_size();    /* Get the dimensions of paper and envelopes */
  1183. X
  1184. X#endif
  1185. X
  1186. SHAR_EOF
  1187. $TOUCH -am 0630160790 lj.h &&
  1188. chmod 0644 lj.h ||
  1189. echo "restore of lj.h failed"
  1190. set `wc -c lj.h`;Wc_c=$1
  1191. if test "$Wc_c" != "13148"; then
  1192.     echo original size 13148, current size $Wc_c
  1193. fi
  1194. fi
  1195. # ============= lj2ps.c ==============
  1196. if test X"$1" != X"-c" -a -f 'lj2ps.c'; then
  1197.     echo "File already exists: skipping 'lj2ps.c'"
  1198. else
  1199. echo "x - extracting lj2ps.c (Text)"
  1200. sed 's/^X//' << 'SHAR_EOF' > lj2ps.c &&
  1201. X/* Project:        lj2ps
  1202. X** File:       lj2ps.c
  1203. X**
  1204. X** Author:       Christopher Lishka
  1205. X** Organization:   Wisconsin State Laboratory of Hygiene
  1206. X**           Data Processing Dept.
  1207. X**
  1208. X** Copyright (C) 1990 by Christopher Lishka.
  1209. X**
  1210. X** This program is free software; you can redistribute it and/or modify
  1211. X** it under the terms of the GNU General Public License as published by
  1212. X** the Free Software Foundation; either version 1, or (at your option)
  1213. X** any later version.
  1214. X**
  1215. X** This program is distributed in the hope that it will be useful,
  1216. X** but WITHOUT ANY WARRANTY; without even the implied warranty of
  1217. X** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1218. X** GNU General Public License for more details.
  1219. X**
  1220. X** You should have received a copy of the GNU General Public License
  1221. X** along with this program; if not, write to the Free Software
  1222. X** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1223. X*/
  1224. X
  1225. Xstatic char *ModuleID = "Module lj2ps: 1.1, production";
  1226. Xstatic char *RCSid = "$Header: lj2ps.c,v 1.1 90/06/30 15:55:10 lishka Release $";
  1227. X
  1228. X  /* Include files
  1229. X  */
  1230. X#include <stdio.h>
  1231. X#include <math.h>
  1232. X#include "lj2ps.h"
  1233. X#include "lj.h"
  1234. X#include "transform.h"
  1235. X#include "errors.h"
  1236. X
  1237. X  /* External definitions
  1238. X  */
  1239. X
  1240. X  /* Global variables
  1241. X  */
  1242. X#ifdef DEBUG
  1243. Xint    debug;            /* True if debugging is on */
  1244. X#endif
  1245. Xint    warnings;        /* True if warnings are printed */
  1246. X
  1247. X  /* Global function list
  1248. X  */
  1249. Xextern int   main();
  1250. X
  1251. X  /* Local constants
  1252. X  */
  1253. X#define MAX_NAME 256
  1254. X
  1255. X  /* Local structures and types
  1256. X  */
  1257. X
  1258. X  /* Local variables
  1259. X  */
  1260. X
  1261. X  /* Local macro definitions
  1262. X  */
  1263. X#define option(x)    (!(strncmp(x, argv[counter], strlen(x))))
  1264. X#define argument(x)  (&(argv[counter][strlen(x)]))
  1265. X#define file()       (argv[counter][0] != '-')
  1266. X
  1267. X  /* Local function list
  1268. X  */
  1269. Xstatic void  syntax();
  1270. X
  1271. X  /* Function bodies
  1272. X  */
  1273. X
  1274. X  /* syntax() prints the legal syntax of this program to stderr
  1275. X  */
  1276. Xstatic void
  1277. Xsyntax(stream)
  1278. X     FILE *stream;
  1279. X{
  1280. X
  1281. X  fprintf(stream, "%s %s (%s): the correct syntax is\n",
  1282. X      PROGRAM, VERSION, STATUS);
  1283. X  fprintf(stream, "     %s [options] [files]\n", PROGRAM);
  1284. X  fputs("\
  1285. XIf no files are listed, input is taken from stdin.\n\
  1286. XThe following options are recognized (## indicates an argument):\n\
  1287. X\n\
  1288. X    LaserJet II Front Panel Selections:                      Default:\n\
  1289. X        -c##     Number of copies                              1 copy\n\
  1290. X        -mf      Manual feed                                   Automatic feed\n\
  1291. X        -fs##    Font source (left, right, internal, or soft)  Internal\n\
  1292. X        -fn##    Font number                                   Font 0\n\
  1293. X        -fl##    Form length                                   60 lines\n\
  1294. X    Page Orientation:\n\
  1295. X        -p       Portrait mode                                 Portrait mode\n\
  1296. X        -l       Landscape mode                                Portrait mode\n\
  1297. X    Page Scaling and Offsets:\n\
  1298. X        -xs##    Scale the width (x axis)                      1.0\n\
  1299. X        -xo##    Offset of left margin (x axis)                0.0\n\
  1300. X        -ys##    Scale the length (y axis)                     1.0\n\
  1301. X        -yo##    Offset of top margin (y axis)                 0.0\n\
  1302. X    Miscellaneous:\n\
  1303. X        -X       Print this syntax list\n\
  1304. X        -w       Do not print warning messages                 Print warnings\n\
  1305. X", stream);
  1306. X#ifdef DEBUG
  1307. X  fputs("\
  1308. X        -d##     Debug level (0 = off)                         Off (0)\n\
  1309. X", stream);
  1310. X#endif
  1311. X
  1312. X} /* syntax() */
  1313. X
  1314. X
  1315. X  /* main() hands off the work to the appropriate functions, as needed.
  1316. X  */
  1317. Xint
  1318. Xmain(argc, argv)
  1319. X    int argc; char *argv[];
  1320. X{
  1321. X  int   arguments;        /* True while still reading the arguments */
  1322. X  int   counter;        /* Generic counter */
  1323. X  FILE *input_file;        /* Current file being read */
  1324. X  FILE *output_file;        /* The file where stuff should be written */
  1325. X  int   tmp_form;        /* Temporary storage for panel_form */
  1326. X
  1327. X    /* Turn warnings on */
  1328. X  warnings = 1;
  1329. X
  1330. X    /* Only stdout is being written to */
  1331. X  output_file = stdout;
  1332. X
  1333. X    /* Set the "factory defaults" */
  1334. X  lj_factory_setup();        /* Like you just took it out of the box! */
  1335. X
  1336. X    /* Parse the command line */
  1337. X  tmp_form = -1;
  1338. X  arguments = 1;
  1339. X  for( counter = 1; arguments && (counter < argc); counter++ ){
  1340. X
  1341. X    if( option("-X") ){  syntax(stdout); exit(0);  }
  1342. X
  1343. X#ifdef DEBUG
  1344. X      /* -d: debug */
  1345. X    else if( option("-d") ){
  1346. X      warning("debugging mode is on", "");
  1347. X      debug = atoi(argument("-d"));
  1348. X    }
  1349. X#endif
  1350. X
  1351. X      /* -w: turn off warnings */
  1352. X    else if( option("-w") ){  warnings = 0; }
  1353. X
  1354. X      /* -c: number of copies */
  1355. X    else if( option("-c") ){  panel_copies = atoi(argument("-c"));  }
  1356. X
  1357. X      /* -mf: manual feed */
  1358. X    else if( option("-mf") ){ panel_manual_feed = LJ_PS_MANUAL;  }
  1359. X
  1360. X      /* -fs: font source */
  1361. X    else if( option("-fs") ){
  1362. X      if(   (strcmp(argument("-fs"), "L") == 0)
  1363. X     || (strcmp(argument("-fs"), "l") == 0)
  1364. X     || (strcmp(argument("-fs"), "Left") == 0)
  1365. X     || (strcmp(argument("-fs"), "left") == 0)
  1366. X     || (strcmp(argument("-fs"), "LEFT") == 0) ){
  1367. X    panel_font_source = LJ_FS_LEFT;
  1368. X      }
  1369. X      else if(   (strcmp(argument("-fs"), "R") == 0)
  1370. X          || (strcmp(argument("-fs"), "r") == 0)
  1371. X          || (strcmp(argument("-fs"), "Right") == 0)
  1372. X          || (strcmp(argument("-fs"), "right") == 0)
  1373. X          || (strcmp(argument("-fs"), "RIGHT") == 0) ){
  1374. X    panel_font_source = LJ_FS_RIGHT;
  1375. X      }
  1376. X      else if(   (strcmp(argument("-fs"), "I") == 0)
  1377. X          || (strcmp(argument("-fs"), "i") == 0)
  1378. X          || (strcmp(argument("-fs"), "Internal") == 0)
  1379. X          || (strcmp(argument("-fs"), "internal") == 0)
  1380. X          || (strcmp(argument("-fs"), "INTERNAL") == 0) ){
  1381. X    panel_font_source = LJ_FS_INTERNAL;
  1382. X      }
  1383. X      else if(   (strcmp(argument("-fs"), "S") == 0)
  1384. X          || (strcmp(argument("-fs"), "s") == 0)
  1385. X          || (strcmp(argument("-fs"), "Soft") == 0)
  1386. X          || (strcmp(argument("-fs"), "soft") == 0)
  1387. X          || (strcmp(argument("-fs"), "SOFT") == 0) ){
  1388. X    panel_font_source = LJ_FS_SOFT;
  1389. X      }
  1390. X      else{
  1391. X    syntax(stderr);
  1392. X    fatal_error("unrecognized font source", argument("-fs"));
  1393. X      }
  1394. X    } /* if( -fs ) */
  1395. X
  1396. X      /* -fn: font number */
  1397. X    else if( option("-fn") ){ panel_font_number = atoi(argument("-fn")); }
  1398. X
  1399. X      /* -p: portrait mode */
  1400. X    else if( option("-p") ){  panel_orientation = LJ_OR_PORTRAIT;  }
  1401. X
  1402. X      /* -l: landscape mode */
  1403. X    else if( option("-l") ){  panel_orientation = LJ_OR_LANDSCAPE; }
  1404. X
  1405. X      /* -fl: text length (i.e. lines per page) */
  1406. X    else if( option("-fl") ){ tmp_form = atoi(argument("-fl"));    }
  1407. X
  1408. X      /* -xs: scale in the x direction */
  1409. X    else if( option("-xs") ){ ps_scale_x = atof(argument("-xs"));  }
  1410. X
  1411. X      /* -ys: scale in the y direction */
  1412. X    else if( option("-ys") ){ ps_scale_y = atof(argument("-ys"));  }
  1413. X
  1414. X      /* -xo: offset in the x direction */
  1415. X    else if( option("-xo") ){ ps_offset_x = atof(argument("-xo")); }
  1416. X
  1417. X      /* -yo: offset in the y direction */
  1418. X    else if( option("-yo") ){ ps_offset_y = -(atof(argument("-yo"))); }
  1419. X
  1420. X      /* File argument */
  1421. X    else if( file() ){
  1422. X      arguments = 0;
  1423. X      break;
  1424. X    } /* if( file ) */
  1425. X
  1426. X    else{ syntax(stdout); fatal_error("unrecognized option", argv[counter]); }
  1427. X    
  1428. X  } /* for(...) */
  1429. X
  1430. X    /* Adjust the default text length to the orientation */
  1431. X  if( tmp_form > 0 ){
  1432. X    panel_form = tmp_form;
  1433. X  }
  1434. X  else{
  1435. X    if( panel_orientation == LJ_OR_LANDSCAPE ){
  1436. X      panel_form = 45;
  1437. X    }
  1438. X  }
  1439. X
  1440. X    /* Initialize the postscript file */
  1441. X  lj_startup(output_file);
  1442. X  lj_page_begin(output_file);
  1443. X
  1444. X    /* Transform the input */
  1445. X  if( arguments ){
  1446. X    transform(stdin, output_file);
  1447. X  } /* if */
  1448. X  else{
  1449. X    for( ; counter < argc; counter ++ ){
  1450. X      if( (input_file = fopen(argv[counter], "r")) == (FILE *) NULL ){
  1451. X    fatal_error("unable to open input file", argv[counter]);
  1452. X      }
  1453. X      transform(input_file, output_file); /* Transform LJ PCL -> Postscript */
  1454. X      if( fclose(input_file) == EOF ){
  1455. X    internal_error("unable to close input file", argv[counter]);
  1456. X      }
  1457. X    } /* for */
  1458. X  } /* else */
  1459. X
  1460. X    /* Finish up the postscript job */
  1461. X  lj_page_end(output_file);
  1462. X  lj_shutdown(output_file);
  1463. X
  1464. X    /* To shut lint and tcc up! */
  1465. X  return( 0 );
  1466. X
  1467. X} /* main() */
  1468. SHAR_EOF
  1469. $TOUCH -am 0630160790 lj2ps.c &&
  1470. chmod 0644 lj2ps.c ||
  1471. echo "restore of lj2ps.c failed"
  1472. set `wc -c lj2ps.c`;Wc_c=$1
  1473. if test "$Wc_c" != "8092"; then
  1474.     echo original size 8092, current size $Wc_c
  1475. fi
  1476. fi
  1477. echo "End of part 9, continue with part 10"
  1478. exit 0
  1479.  
  1480.