w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ps.c
Go to the documentation of this file.
1 /*
2  * DEVICE dependent, font independent
3  */
4 
5 #include "defs.h"
6 #include "emit.h"
7 #include "global.h"
8 #include "ps.h"
9 
10 /* define for "optimal" relative postioning, rather
11  than absolute. Relative can reduce size of postcript
12  output 20% (and reduce print time by almost as much */
13 #define USERELPOS 1
14 
16 
17 int ordinal = 0; /* page's position in the page sequence */
19 
20 int hconv, vconv; /* converts DVI units to pixels */
21 int ps_h = 0; /* current h on device */
22 int ps_v = 0; /* current v on device */
23 int *ps_move;
24 
25 extern int num, den;
26 
27 #define Letter 0
28 #define Legal 1
29 #define Tabloid 2
30 #define B4 3
31 #define B5 4
32 #define A5 5
33 #define A4 6
34 #define A3 7
35 #define Envelope 8
36 
37 struct {
38  char *size; /* paper size */
39  char *command; /* paper command */
40  int width; /* paper width */
41  int height; /* paper height */
42 } paperinfo[] = {
43  {"Letter", "letter", 612, 792},
44  {"Legal", "legal", 612, 1008},
45  {"Tabloid", "tabloid", 792, 1224},
46  {"B4", "b4", 709, 1001},
47  {"B5", "b5", 499, 709},
48  {"A5", "a5", 420, 595},
49  {"A4", "a4", 595, 842},
50  {"A3", "a3", 842, 1191},
51  {"Letter", "envelope", 612, 792}
52  };
53 
54 #ifndef PAPERTYPE
55 #define PAPERTYPE Letter
56 #endif
57 #ifndef LARGEAREA
58 #define LARGEAREA TRUE
59 #endif
60 
65 
67 char option;
68 char *c;
69 {
70  switch (option) {
71  case 'o':
72  if (!ChkOpt(c))
73  Fatal("%s is an invalid option\n", c);
74  break;
75  }
76 }
77 
78 /*-->ChkOpt*/ /* check a user supplied option for validity */
79 #define ISOPT(s) (strcmp(str,s)==0)
80 
82 char *str;
83 {
84  if (ISOPT("landscape")) {
85  landscape = TRUE;
86  return TRUE;
87  } else if (ISOPT("manualfeed")) {
88  manualfeed = TRUE;
89  return TRUE;
90  } else if (ISOPT("large")) {
91  large = TRUE;
92  return TRUE;
93  } else if (ISOPT("small")) {
94  large = FALSE;
95  return TRUE;
96  } else if (ISOPT("letter")) {
97  paper = Letter;
98  return TRUE;
99  } else if (ISOPT("note")) {
100  paper = Letter;
101  large = FALSE;
102  return TRUE;
103  } else if (ISOPT("legal")) {
104  paper = Legal;
105  return TRUE;
106  } else if (ISOPT("tabloid")) {
107  paper = Tabloid;
108  return TRUE;
109  } else if (ISOPT("a3")) {
110  paper = A3;
111  return TRUE;
112  } else if (ISOPT("a4")) {
113  paper = A4;
114  return TRUE;
115  } else if (ISOPT("a5")) {
116  paper = A5;
117  return TRUE;
118  } else if (ISOPT("b4")) {
119  paper = B4;
120  return TRUE;
121  } else if (ISOPT("b5")) {
122  paper = B5;
123  return TRUE;
124  } else if (ISOPT("letterlandscape")) {
125  paper = Letter;
126  landscape = TRUE;
127  return TRUE;
128  } else if (ISOPT("notelandscape")) {
129  paper = Letter;
130  large = FALSE;
131  landscape = TRUE;
132  return TRUE;
133  } else if (ISOPT("legallandscape")) {
134  paper = Legal;
135  landscape = TRUE;
136  return TRUE;
137  } else if (ISOPT("tabloidlandscape")) {
138  paper = Tabloid;
139  landscape = TRUE;
140  return TRUE;
141  } else if (ISOPT("a3landscape")) {
142  paper = A3;
143  landscape = TRUE;
144  return TRUE;
145  } else if (ISOPT("a4landscape")) {
146  paper = A4;
147  landscape = TRUE;
148  return TRUE;
149  } else if (ISOPT("a5landscape")) {
150  paper = A5;
151  landscape = TRUE;
152  return TRUE;
153  } else if (ISOPT("b4landscape")) {
154  paper = B4;
155  landscape = TRUE;
156  return TRUE;
157  } else if (ISOPT("b5landscape")) {
158  paper = B5;
159  landscape = TRUE;
160  return TRUE;
161  } else if (ISOPT("envelope")) {
162  paper = Envelope;
163  manualfeed = TRUE;
164  landscape = TRUE;
165  return TRUE;
166  }
167 
168  return FALSE;
169 }
170 
172 {
173  initcolor();
174 }
175 
177 {
178  if (epsf && ordinal > 1) {
179  Warning("We cannot make it EPSF.");
180  epsf = FALSE;
181  }
182  if (!epsf)
183  EMIT(outfp, "%%!PS-Adobe-3.0\n");
184  else
185  EMIT(outfp, "%%!PS-Adobe-3.0 EPSF-3.0\n");
186  EMIT(outfp, "%%%%Creator: %s\n", G_progname);
187  EMIT(outfp, "%%%%Title: %s\n", dvifilename);
188  if (!epsf)
189  EMIT(outfp, "%%%%Pages: %d\n", ordinal);
190  EMIT(outfp, "%%%%BoundingBox: 0 0 %d %d\n",
192  /*EMIT(outfp, "%%%%DocumentPaperSizes: %s\n", paperinfo[paper].size);*/
193  if (!epsf)
194  EMIT(outfp, "%%%%Orientation: %s\n",
195  (landscape?"Landscape":"Portrait"));
196  EMIT(outfp, "%%%%EndComments\n");
197  /* include file given in fontdesc */
198  do_include();
200  EMIT(outfp, "%%%%EndProlog\n");
201 }
202 
204 {
209 #ifdef DEBUG
210  if (Debug) {
211  (void)fprintf(stderr, "hconv = %d\n", hconv);
212  (void)fprintf(stderr, "vconv = %d\n", vconv);
213  }
214 #endif
215  ordinal = 0;
216 
217  EMIT(outfp, "%%%%BeginSetup\n");
218  if (!epsf)
219  EMIT(outfp, "%%%%Feature: *ManualFeed %s\n",
220  (manualfeed?"True":"False"));
221  EMIT(outfp, "%%%%Feature: *Resolution %d\n", resolution);
222  EMIT(outfp, "TeXDict begin\n");
223  if (!epsf) {
224  EMIT(outfp, "%%%%PaperSize: %s\n", paperinfo[paper].size);
225  if (manualfeed)
226  EMIT(outfp, "@manualfeed\n");
227  if (landscape)
228  EMIT(outfp, "@landscape\n");
229  EMIT(outfp, "@%s\n", (large?"large":"small"));
230  EMIT(outfp, "@%s\n", paperinfo[paper].command);
231  if (ncopies > 1)
232  EMIT(outfp, "%d COPIES\n", ncopies);
233  } else
234  EMIT(outfp, "@%ssize\n", paperinfo[paper].command);
235 }
236 
238 {
239  if (useifont())
240  ifont_setup();
241  /* setup file given in fontdesc */
242  do_setup();
243  EMIT(outfp, "%d %.3f START\n", resolution, (float)mag/1000);
244  EMIT(outfp, "%%%%EndSetup\n");
245 }
246 
248 {
249  end_string();
250  EMIT(outfp,"%%%%Trailer\n");
251  EMIT(outfp,"end\n");
252  EMIT(outfp,"userdict /end-hook known{end-hook}if\n");
253  EMIT(outfp,"%%%%EOF\n");
254 }
255 
256 #define DF_ALWAYS 0
257 #define DF_SPEC 1
258 #define DF_PSMOD 2
259 #define DF_PSIFONT 3
260 #define DF_COLOR 4
261 
263 char *kind;
264 {
265  if (STREQ(kind, "special"))
266  return DF_SPEC;
267  else if (STREQ(kind, "psmod"))
268  return DF_PSMOD;
269  else if (STREQ(kind, "psifont"))
270  return DF_PSIFONT;
271  else if (STREQ(kind, "color"))
272  return DF_COLOR;
273  else
274  return DF_ALWAYS;
275 }
276 
278 {
279  extern __BOOLEAN__ usesspecial;
280  extern __BOOLEAN__ usespsmod;
281  extern __BOOLEAN__ usescolor;
282 
283  if (kind == DF_SPEC)
284  return usesspecial;
285  else if (kind == DF_PSMOD)
286  return usespsmod;
287  else if (kind == DF_PSIFONT)
288  return useifont();
289  else if (kind == DF_COLOR)
290  return usescolor;
291  return 0;
292 }
293 
294 
295 /*
296  * each ps font is assigned a unique numbler
297  */
298 static DEV_FONT ps_curf; /* current font on device */
299 static char psfnamebuf[256];
300 static int devicefont = 0;
301 
302 char *
304 int psf;
305 {
306  (void)sprintf(psfnamebuf, "f%d", (unsigned int)psf);
307  return psfnamebuf;
308 }
309 
311 {
312  return devicefont++;
313 }
314 
316 {
317  ps_h = ps_v = 0;
318  dev_initfont();
319 }
320 
322 int count;
323 {
324  extern int pagenum ;
325 
326  ++ordinal;
327  pagenum = count;
328  bopcolor(FALSE);
329 }
330 
332 int count;
333 {
334  end_string();
335  EMITC('\n');
336  if (!epsf)
337  EMIT(outfp, "%%%%Page: %d %d\n", count, ++ordinal);
338  EMIT(outfp, "BP\n");
339  bopcolor(TRUE);
340 }
341 
343 {
344  end_string();
345  EMIT(outfp, "EP\n");
346 }
347 
348 float
350 struct font_entry *fe;
351 {
352  return (((float)fe->s/(float)fe->d)
353 #ifdef USEGLOBALMAG
354  * ((float)mag/1000.0)
355 #endif
356  );
357 }
358 
360 {
362  return 0;
363 }
364 
366 int psf;
367 {
368  if (ps_curf != psf) {
369  end_string();
370  EMIT(outfp, "%s SF\n", psfname(psf));
371  ps_curf = psf;
372  }
373 }
374 
375 dev_setposn(x, y) /* output a positioning command */
376 int x, y;
377 {
378  int rx;
379 #ifdef USERELPOS
380  if (y == ps_v) { /* use relative movement if just moving horizontally */
381  if (x != ps_h) {
382  if ((rx=pixround(x-ps_h,hconv)) != 0) {
383  end_string();
384  EMITN(rx);
385  EMITS("r ");
386  ps_h += rx*hconv;
387  }
388  }
389  } else {
390 #endif
391  end_string();
392  EMITN(rx=pixround(x,hconv));
393  EMITN(pixround(y,vconv)); /* ry */
394  EMITS("p ");
395  ps_h = rx*hconv; /* must know where device "really" is horizontally, for rel. posning. */
396  ps_v = y; /* but we always use direct positioning for vertical movement */
397 #ifdef USERELPOS
398  }
399 #endif
400 }
401 
402 dev_setposn_abs(x, y) /* output a positioning command */
403 int x, y;
404 {
405  int rx;
406 
407  end_string();
408  EMITN(rx=pixround(x,hconv));
409  EMITN(pixround(y,vconv)); /* ry */
410  EMITS("p ");
411  ps_h = rx*hconv; /* must know where device "really" is horizontally, for rel. posning. */
412  ps_v = y; /* but we always use direct positioning for vertical movement */
413 }
414 
416 int a, b;
417 {
418  end_string();
419  EMITN(pixround(b,hconv)); /* width */
420  EMITN(pixround(a,vconv)); /* height */
421  EMITS("ru\n");
422 }
423 
424 char *endscom = "s";
425 char *endvscom = "rs";
426 char *endstrcom;
427 
429 int d;
430 {
431  end_string();
432  if (d == HOR) {
433  ps_move = &ps_h;
434  endstrcom = endscom;
435  } else if (d == VER) {
436  ps_move = &ps_v;
438  } else
439  Fatal("direction %d not supported", d);
440 }
441 
444 
446 {
447  if (!instring) {
448  instring = TRUE;
449  EMITC('(');
450  }
451 }
452 
454 {
455  if (!instring) {
456  instring = TRUE;
457  vertstring = TRUE;
458  EMITC('(');
459  }
460 }
461 
463 {
464  if (instring) {
465  instring = FALSE;
466  if (vertstring) {
467  EMITS(")s\n");
468  vertstring = FALSE;
469  } else
470  EMIT(outfp, ")%s\n", endstrcom);
471  }
472  return 0;
473 }
474 
475 /*-->DoConv*/
476 /*********************************************************************/
477 /******************************** DoConv ***************************/
478 /*********************************************************************/
479 /*
480  1 sp = (num/den)*10^(-5) cm
481  (num = 254*10^5, den = 7227*2^16)
482  1 inch = 254*10^(-2) cm
483  Therefore, 1 sp = conv pixel-unit
484  return-value sp = 1 pixel-unit
485 */
486 
487 int DoConv(num, den, mag, convResolution)
488 int num, den, mag, convResolution;
489 {
490  float conv;
491  conv = ((float)num/(float)den) *
492 #ifdef USEGLOBALMAG
493  ((float) mag/1000.0) *
494 #endif
495  ((float)convResolution/254000.0);
496  return (int)(1.0 / conv + 0.5);
497 }
498 
499 int
500 pixround(x, conv) /* return rounded number of pixels */
501 int x; /* in DVI units */
502 int conv; /* conversion factor */
503 {
504  return (int)((x + (conv >> 1)) / conv);
505 }
FILE * outfp
Definition: aftopl.c:22
#define count(a)
Definition: aptex-macros.h:781
#define mag
Definition: aptex-macros.h:802
#define b
Definition: jpegint.h:372
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
void Warning(const char *sb1, const char *sb2)
Definition: detex.c:4677
#define DEV_NULLFONT
Definition: defs.h:180
#define USEGLOBALMAG
Definition: defs.h:123
#define HOR
Definition: defs.h:230
#define STREQ(s, t)
Definition: defs.h:149
#define VER
Definition: defs.h:231
#define Debug
Definition: defs.h:89
char * G_progname
Definition: dvi2.c:77
int ncopies
Definition: dvi2.c:68
char dvifilename[1024]
Definition: dvi2.c:62
void Fatal()
int __BOOLEAN__
Definition: defs.h:174
do_include()
Definition: fontdesc.c:854
do_setup()
Definition: fontdesc.c:859
__BOOLEAN__ usescolor
Definition: psspecial.c:49
dev_outbangspecials()
Definition: psspecial.c:232
__BOOLEAN__ usesspecial
Definition: psspecial.c:48
static double conv
Definition: dvicore.c:53
#define EMIT
Definition: emit.h:2
#define EMITC(c)
Definition: emit.h:13
#define EMITN(n)
Definition: emit.h:8
#define EMITS(s)
Definition: emit.h:4
static void
Definition: fpif.c:118
#define c(n)
Definition: gpos-common.c:150
#define a(n)
Definition: gpos-common.c:148
#define d(n)
Definition: gpos-common.c:151
int kind
Definition: image.c:8980
JCOPY_OPTION option
Definition: transupp.h:131
kerning y
Definition: ttdriver.c:212
#define fprintf
Definition: mendex.h:64
#define sprintf
Definition: snprintf.c:44
float x
Definition: cordic.py:15
integer resolution
Definition: pbmtopk.c:45
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld endif[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if
__BOOLEAN__ usespsmod
Definition: psbi.c:12
integer pagenum
Definition: pscolor.c:30
void bopcolor(outtops)
Definition: pscolor.c:207
void initcolor()
Definition: pscolor.c:92
ifont_setup()
Definition: psifont.c:146
useifont()
Definition: psifont.c:141
#define str(s)
Definition: sh6.c:399
Definition: defs.h:190
int d
Definition: defs.h:192
int s
Definition: defs.h:192
Definition: getopt.h:95
Definition: paper.c:25
#define B4
Definition: ps.c:30
int large
Definition: ps.c:62
dev_init()
Definition: ps.c:171
int den
Definition: ps.c:25
#define DF_SPEC
Definition: ps.c:257
begin_string()
Definition: ps.c:445
#define ISOPT(s)
Definition: ps.c:79
dev_setposn_abs(int x, int y)
Definition: ps.c:402
int pixround(int x, int conv)
Definition: ps.c:500
int width
Definition: ps.c:40
__BOOLEAN__ instring
Definition: ps.c:442
#define PAPERTYPE
Definition: ps.c:55
dev_prebop(int count)
Definition: ps.c:321
static DEV_FONT ps_curf
Definition: ps.c:298
dev_prologue()
Definition: ps.c:176
int * ps_move
Definition: ps.c:23
__BOOLEAN__ landscape
Definition: ps.c:64
int ps_v
Definition: ps.c:22
#define DF_PSMOD
Definition: ps.c:258
#define Letter
Definition: ps.c:27
#define DF_PSIFONT
Definition: ps.c:259
__BOOLEAN__ epsf
Definition: ps.c:18
#define A3
Definition: ps.c:34
int vconv
Definition: ps.c:20
char * size
Definition: ps.c:38
dev_eop()
Definition: ps.c:342
dev_setup()
Definition: ps.c:203
#define DF_COLOR
Definition: ps.c:260
struct @98 paperinfo[]
__BOOLEAN__ manualfeed
Definition: ps.c:63
#define A5
Definition: ps.c:32
static int devicefont
Definition: ps.c:300
int ordinal
Definition: ps.c:17
dev_arg(char option, char *c)
Definition: ps.c:66
begin_string_v()
Definition: ps.c:453
dev_bop(int count)
Definition: ps.c:331
dev_endsetup()
Definition: ps.c:237
int hconv
Definition: ps.c:20
int DoConv(int num, int den, int mag, int convResolution)
Definition: ps.c:487
#define DF_ALWAYS
Definition: ps.c:256
ChkOpt(char *str)
Definition: ps.c:81
__BOOLEAN__ vertstring
Definition: ps.c:443
#define Envelope
Definition: ps.c:35
int num
Definition: dvi2.c:50
char * psfname(int psf)
Definition: ps.c:303
dev_devfileif(int kind)
Definition: ps.c:277
int ps_h
Definition: ps.c:21
float dev_fontmag(struct font_entry *fe)
Definition: ps.c:349
int hconvresolution
Definition: ps.c:15
dev_devfilekind(char *kind)
Definition: ps.c:262
dev_dir(int d)
Definition: ps.c:428
#define Legal
Definition: ps.c:28
dev_setrule(int a, int b)
Definition: ps.c:415
#define A4
Definition: ps.c:33
dev_finish()
Definition: ps.c:247
dev_setfont(int psf)
Definition: ps.c:365
char * endstrcom
Definition: ps.c:426
end_string(void)
Definition: ps.c:462
#define B5
Definition: ps.c:31
char * endvscom
Definition: ps.c:425
static char psfnamebuf[256]
Definition: ps.c:299
int vconvresolution
Definition: ps.c:15
#define Tabloid
Definition: ps.c:29
dev_newdevfont()
Definition: ps.c:310
int height
Definition: ps.c:41
char * command
Definition: ps.c:39
char * endscom
Definition: ps.c:424
dev_initfont(void)
Definition: ps.c:359
#define LARGEAREA
Definition: ps.c:58
dev_setposn(int x, int y)
Definition: ps.c:375
dev_initpage()
Definition: ps.c:315