2 * Copyright (C) 2012, The AROS Development Team. All rights reserved.
3 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
5 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
9 #include <aros/debug.h>
10 #include <aros/printertag.h>
12 #include <clib/alib_protos.h>
13 #include <devices/printer.h>
14 #include <devices/prtgfx.h>
15 #include <prefs/printergfx.h>
16 #include <prefs/printertxt.h>
17 #include <exec/rawfmt.h>
19 #include <proto/exec.h>
20 #include <proto/graphics.h>
22 #define PS_NOSCALING TRUE /* Do all scaling in PostScript, not in printer.device */
23 #define PS_RGB TRUE /* RGB or CMYK printing */
26 /* Support binary compatability with AOS */
28 #undef RAWFMTFUNC_STRING
29 #define RAWFMTFUNC_STRING (VOID (*)())"\x16\xC0\x4E\x75"
32 static LONG
ps_Init(struct PrinterData
*pd
);
33 static VOID
ps_Expunge(VOID
);
34 static LONG
ps_Open(union printerIO
*ior
);
35 static VOID
ps_Close(union printerIO
*ior
);
37 static LONG
ps_Render(SIPTR ct
, LONG x
, LONG y
, LONG status
);
38 static LONG
ps_ConvFunc(UBYTE
*buf
, UBYTE c
, LONG crlf_flag
);
39 static LONG
ps_DoPreferences(union printerIO
*ior
, LONG command
);
40 static VOID
ps_CallErrHook(union printerIO
*ior
, struct Hook
*hook
);
41 static LONG
ps_DoSpecial(UWORD
*command
, UBYTE output_buffer
[],
42 BYTE
*current_line_position
,
43 BYTE
*current_line_spacing
,
44 BYTE
*crlf_flag
, UBYTE params
[]);
46 static CONST_STRPTR PED_Commands
[] = {
47 "\377", /* 0 aRIS (reset) */
48 "\377\377", /* 1 aRIN (initialize) */
49 ") aSHOW aIND (", /* 2 aIND (linefeed) */
50 ") aSHOW aNEL (", /* 3 aNEL (CR/LF) */
51 "\377", /* 4 aRI (reverse LF) */
52 ") aSHOW aSGR0 (", /* 5 aSGR0 (Courier) */
53 ") aSHOW aSGR3 (", /* 6 aSGR3 (italics) */
54 ") aSHOW aSGR23 (", /* 7 aSGR23 (no italics) */
55 ") aSHOW aSGR4 (", /* 8 aSGR4 (underline) */
56 ") aSHOW aSGR24 (", /* 9 aSGR24 (no underline) */
57 ") aSHOW aSGR1 (", /* 10 aSGR1 (boldface) */
58 ") aSHOW aSGR22 (", /* 11 aSGR22 (no boldface) */
59 "\377", /* 12 aSFC (set text color) */
60 "\377", /* 13 aSBC (set background color) */
61 ") aSHOW aSHORP0 (", /* 14 aSHORP0 (normal pitch) */
62 ") aSHOW aSHORP2 (", /* 15 aSHORP2 (elite) */
63 ") aSHOW aSHORP1 (", /* 16 aSHORP1 (no elite) */
64 ") aSHOW aSHORP4 (", /* 17 aSHORP4 (condensed) */
65 ") aSHOW aSHORP3 (", /* 18 aSHORP3 (no condensed) */
66 ") aSHOW aSHORP6 (", /* 19 aSHORP6 (enlarge) */
67 ") aSHOW aSHORP5 (", /* 20 aSHORT5 (no enlarge) */
68 ") aSHOW aDEN6 (", /* 21 aDEN6 (shadow) */
69 ") aSHOW aDEN5 (", /* 22 aDEN5 (no shadow) */
70 ") aSHOW aDEN4 (", /* 23 aDEN4 (double strike) */
71 ") aSHOW aDEN3 (", /* 24 aDEN3 (no double strike) */
72 ") aSHOW aDEN2 (", /* 25 aDEN2 (NLQ) */
73 ") aSHOW aDEN1 (", /* 26 aDEN1 (no NLQ) */
74 ") aSHOW aSUS2 (", /* 27 aSUS2 (superscript) */
75 ") aSHOW aSUS1 (", /* 28 aSUS1 (no superscript) */
76 ") aSHOW aSUS4 (", /* 29 aSUS4 (subscript) */
77 ") aSHOW aSUS3 (", /* 30 aSUS3 (no subscript) */
78 ") aSHOW aSUS0 (", /* 31 aSUS0 (normal) */
79 ") aSHOW aPLU (", /* 32 aPLU (partial line up) */
80 ") aSHOW aPLD (", /* 33 aPLD (partial line down) */
81 ") aSHOW aFNT0 (", /* 34 aFNT0 (Courier) */
82 ") aSHOW aFNT1 (", /* 35 aFNT1 (Helvetica) */
83 ") aSHOW aFNT2 (", /* 36 aFNT2 (Font 2) */
84 ") aSHOW aFNT3 (", /* 37 aFNT3 (Font 3) */
85 ") aSHOW aFNT4 (", /* 38 aFNT4 (Font 4) */
86 ") aSHOW aFNT5 (", /* 39 aFNT5 (Font 5) */
87 ") aSHOW aFNT6 (", /* 40 aFNT6 (Font 6) */
88 ") aSHOW aFNT7 (", /* 41 aFNT7 (Font 7) */
89 ") aSHOW aFNT8 (", /* 42 aFNT8 (Font 8) */
90 ") aSHOW aFNT9 (", /* 43 aFNT9 (Font 9) */
91 ") aSHOW aFNT10 (", /* 44 aFNT10 (Font 10) */
92 ") aSHOW aPROP2 (", /* 45 aPROP2 (proportional) */
93 ") aSHOW aPROP1 (", /* 46 aPROP1 (no proportional) */
94 ") aSHOW aPROP0 (", /* 47 aPROP0 (default proportion) */
95 "\377", /* 48 aTSS (set proportional offset) */
96 ") aSHOW aJFY5 (", /* 49 aJFY5 (left justify) */
97 ") aSHOW aJFY7 (", /* 50 aJFY7 (right justify) */
98 ") aSHOW aJFY6 (", /* 51 aJFY6 (full justify) */
99 ") aSHOW aJFY0 (", /* 52 aJFY0 (no justify) */
100 ") aSHOW aJFY3 (", /* 53 aJFY3 (letter space) */
101 ") aSHOW aJFY1 (", /* 54 aJFY1 (word fill) */
102 ") aSHOW aVERP0 (", /* 55 aVERP0 (1/8" line spacing) */
103 ") aSHOW aVERP1 (", /* 56 aVERP1 (1/6" line spacing) */
104 "\377", /* 57 aSLPP (form length) */
105 "\377", /* 58 aPERF (skip n perfs) */
106 "\377", /* 59 aPERF0 (no skip perfs) */
107 "\377", /* 60 aLMS (left margin) */
108 "\377", /* 61 aRMS (right margin) */
109 "\377", /* 62 aTMS (top margin) */
110 "\377", /* 63 aBMS (bot margin) */
111 "\377", /* 64 aSTBM (top & bottom margin) */
112 "\377", /* 65 aSLRM (left & right margin) */
113 "\377", /* 66 aCAM (no margins) */
114 "\377", /* 67 aHTS (horizontal tabs) */
115 "\377", /* 68 aVTS (vertical tabs) */
116 "\377", /* 69 aTBC0 (clear horizontal tab) */
117 "\377", /* 70 aTBC3 (clear all horiz. tabs) */
118 "\377", /* 71 aTBC1 (clear vertical tab) */
119 "\377", /* 72 aTBC4 (clear all vertical tabs) */
120 "\377", /* 73 aTBCALL (clear all tabs) */
121 "\377", /* 74 aTBSALL (default tabs) */
122 "\377", /* 75 aEXTEND (extended chars) */
123 "\377", /* 76 aRAW (next N chars are literal) */
126 static CONST_STRPTR PED_8BitChars
[] = {
226 static struct TagItem PED_TagList
[] = {
227 { PRTA_8BitGuns
, TRUE
}, /* 0 */
228 { PRTA_FloydDithering
, TRUE
}, /* 1 */
229 { PRTA_MixBWColor
, TRUE
}, /* 2 */
230 { PRTA_LeftBorder
, 0 }, /* 3 */
231 { PRTA_TopBorder
, 0 }, /* 4 */
232 { PRTA_NoScaling
, PS_NOSCALING
},
236 AROS_PRINTER_TAG(PED
, 44, 0,
237 .ped_PrinterName
= "PostScript",
239 .ped_Expunge
= ps_Expunge
,
241 .ped_Close
= ps_Close
,
243 /* Settings for a 'graphics only' printer */
244 .ped_PrinterClass
= PPC_COLORGFX
| PPCF_EXTENDED
,
245 .ped_MaxColumns
= 0, /* Set during render */
246 .ped_ColorClass
= (PS_RGB
? PCC_BGR
: PCC_YMCB
),
247 .ped_NumCharSets
= 2,
248 .ped_NumRows
= 1, /* minimum pixels/row in gfx mode */
249 .ped_MaxXDots
= 0, /* Set during render */
250 .ped_MaxYDots
= 0, /* Set during render */
251 .ped_XDotsInch
= 0, /* Set during render */
252 .ped_YDotsInch
= 0, /* Set during render */
253 .ped_Commands
= (STRPTR
*)PED_Commands
, /* No ANSI commands */
254 .ped_DoSpecial
= ps_DoSpecial
,
255 .ped_Render
= ps_Render
,
256 .ped_TimeoutSecs
= 1000, /* For print-to-file timeouts */
257 .ped_8BitChars
= (STRPTR
*)PED_8BitChars
,
259 .ped_ConvFunc
= ps_ConvFunc
,
260 .ped_TagList
= &PED_TagList
[0],
261 .ped_DoPreferences
= ps_DoPreferences
,
262 .ped_CallErrHook
= ps_CallErrHook
,
265 struct PrinterData
*PD
;
266 static LONG ps_PageID
;
267 static BOOL ps_HeaderSent
;
268 static CONST_STRPTR ps_PaperSize
;
269 static LONG ps_PrintBufLen
;
270 static LONG ps_SpacingLPI
;
271 static LONG ps_FontCPI
;
272 static UWORD ps_PrintShade
;
274 struct ExecBase
*SysBase
;
276 static LONG
ps_Init(struct PrinterData
*pd
)
278 SysBase
= pd
->pd_Device
.dd_ExecBase
;
280 D(bug("ps_Init: pd=%p\n", pd
));
285 static VOID
ps_Expunge(VOID
)
287 D(bug("ps_Expunge\n"));
297 .buff
= &ps_PState
.buff_a
[0]
300 #define PFLUSH() do { \
301 PD->pd_PWrite(ps_PState.buff, ps_PState.len); \
302 if (ps_PState.buff == &ps_PState.buff_a[0]) \
303 ps_PState.buff = &ps_PState.buff_b[0]; \
305 ps_PState.buff = &ps_PState.buff_a[0]; \
310 static AROS_UFH2(void, ps_PPutC
,
311 AROS_UFHA(UBYTE
, c
, D0
),
312 AROS_UFHA(APTR
, dummy
, A3
))
316 /* Ignore the trailing 0 that RawDoFmt() tacks on the end */
320 ps_PState
.buff
[ps_PState
.len
++]=c
;
321 if (ps_PState
.len
>= 16)
327 static inline void ps_PWrite(const char *fmt
, ...)
329 AROS_SLOWSTACKFORMAT_PRE(fmt
);
330 RawDoFmt(fmt
, AROS_SLOWSTACKFORMAT_ARG(fmt
), (VOID_FUNC
)ps_PPutC
, NULL
);
331 AROS_SLOWSTACKFORMAT_POST(fmt
);
336 #define STRING_FUNC (VOID (*)())"\x16\xC0\x4E\x75"
338 #define STRING_FUNC RAWFMTFUNC_STRING
341 static inline void ps_VWrite(char *buf
, const char *fmt
, ...)
343 AROS_SLOWSTACKFORMAT_PRE(fmt
);
344 RawDoFmt(fmt
, AROS_SLOWSTACKFORMAT_ARG(fmt
), STRING_FUNC
, buf
);
345 AROS_SLOWSTACKFORMAT_POST(fmt
);
348 CONST TEXT ps_PageHeader
[] =
349 "%s\n" /* Optional formfeed */
350 "%%%%Page: %ld %ld\n"
351 "%%%%BeginPageSetup\n"
352 "%%%%PageOrientation: %s\n"
353 "%%%%PageMedia: %s\n"
354 "%%%%PageBoundingBox: %ld %ld %ld %ld\n"
359 static void ps_VSendPage(char *buff
, BOOL formfeed
)
361 ps_VWrite(buff
, ps_PageHeader
, formfeed
? ") aSHOW aFF" : "",
362 ps_PageID
, ps_PageID
,
364 PD
->pd_Preferences
.PrintAspect
? "Landscape" : "Portrait",
369 PED
->ped_MaxXDots
* 72 / PED
->ped_XDotsInch
,
370 PED
->ped_MaxYDots
* 72 / PED
->ped_YDotsInch
376 static void ps_SendPage(BOOL formfeed
)
378 ps_PWrite(ps_PageHeader
, formfeed
? ") aSHOW aFF" : "",
379 ps_PageID
, ps_PageID
,
381 PD
->pd_Preferences
.PrintAspect
? "Landscape" : "Portrait",
386 PED
->ped_MaxXDots
* 72 / PED
->ped_XDotsInch
,
387 PED
->ped_MaxYDots
* 72 / PED
->ped_YDotsInch
393 static void ps_SendHeader(void)
395 const TEXT header
[] =
397 "%%%%Creator: AROS PostScript %ld.%ld (printer.device)\n"
398 "%%%%BoundingBox: %ld %ld %ld %ld\n"
399 "%%%%DocumentData: Clean7Bit\n"
400 "%%%%LanguageLevel: 2\n"
401 "%%%%DocumentMedia: %s %ld %ld 0 () ()\n"
404 /* (ypixels * 72 / ydpi) - (72 / 4) [1/4 inch] */
405 "/Page_Top %ld 72 mul %ld div 72 4 div sub def\n"
406 /* 12 * left-margin-chars */
407 "/Page_Left 12 %ld mul def\n"
408 "/aFB { gsave Font_CPI setFont Page_Left Page_Top moveto } bind def\n"
409 "/aFF { grestore showpage } bind def\n"
411 " /aImage_H exch def /aImage_W exch def\n"
412 " aImage_W aImage_H 1\n"
413 " [ aImage_W 0 0 aImage_H neg 0 aImage_H ]\n"
414 " { currentfile aImage_W 7 add 8 div cvi string readhexstring pop} bind\n"
417 "/aImageGreyscale {\n"
418 " /aImage_H exch def /aImage_W exch def\n"
419 " aImage_W aImage_H 8\n"
420 " [ aImage_W 0 0 aImage_H neg 0 aImage_H ]\n"
421 " { currentfile aImage_W string readhexstring pop} bind\n"
424 "/aImageColorRGB {\n"
425 " /aImage_H exch def /aImage_W exch def\n"
426 " aImage_W aImage_H 8\n"
427 " [ aImage_W 0 0 aImage_H neg 0 aImage_H ]\n"
428 " { currentfile aImage_W 3 mul string readhexstring pop} bind %% RGB\n"
429 " false 3 colorimage %% Single-pass \n"
431 "/aImageColorCMYK {\n"
432 " /aImage_H exch def /aImage_W exch def\n"
433 " aImage_W aImage_H 8\n"
434 " [ aImage_W 0 0 aImage_H -1 mul 0 aImage_H ]\n"
435 " { currentfile aImage_W 4 mul string readhexstring pop} bind %% CMYK\n"
436 " false 4 colorimage %%\n"
439 "/setFont { Font_Name findfont 1200 Font_CPI div scalefont setfont } bind def\n"
440 "/Spacing { 72 Spacing_LPI div } bind def\n"
444 " Font_B { /Helvetica-BoldOblique } { /Courier-Oblique } ifelse\n"
446 " Font_B { /Helvetica-Bold } { /Courier } ifelse\n"
450 " Font_B { /Courier-BoldOblique } { /Courier-Oblique } ifelse\n"
452 " Font_B { /Courier-Bold } { /Courier } ifelse\n"
456 "/Font_CPIDefault %ld def\n"
457 "/Spacing_LPIDefault %ld def\n"
458 "/Font_CPI Font_CPIDefault def\n"
459 "/Font_P false def\n"
460 "/Font_U false def\n"
461 "/Font_B false def\n"
462 "/Font_I false def\n"
463 "/Font_Bg [ 1 1 1 ] def\n"
464 "/Font_Fg [ 0 0 0 ] def\n"
465 "/Spacing_LPI Spacing_LPIDefault def\n"
467 " gsave Font_Bg aload pop setrgbcolor \n"
468 " 0 -2 rmoveto dup stringwidth pop dup 0 rlineto\n"
469 " 0 Spacing 2 sub rlineto neg 0 rlineto closepath fill\n"
471 " Font_U { gsave 0 -2 rmoveto dup stringwidth rlineto 0.3 setlinewidth stroke grestore } if\n"
472 " Font_Fg aload pop setrgbcolor\n"
475 "/aNEL { currentpoint exch pop Page_Left exch Spacing sub dup 0 lt { pop pop aFF aFB } { moveto } ifelse } bind def\n"
476 "/aIND { currentpoint exch pop Page_Left exch moveto } bind def\n"
477 "/aSGR0 { /Font_Fg [ 0 0 0 ] def /Font_Bg [ 1 1 1 ] def /Font_U false def /Font_B false def /Font_I false def Font_CPI setFont } bind def\n"
478 "/aSGR3 { /Font_I true def setFont } bind def\n"
479 "/aSGR23 { /Font_I false def setFont } bind def\n"
480 "/aSGR4 { /Font_U true def setFont } bind def\n"
481 "/aSGR24 { /Font_U false def setFont } bind def\n"
482 "/aSGR1 { /Font_B true def setFont } bind def\n"
483 "/aSGR22 { /Font_B false def setFont } bind def\n"
484 "/aColor { [ [ 0 0 0 ] [ 1 0 0 ] [ 0 1 0] [ 1 1 0] [ 0 0 1] [ 0.3 0.3 0.3] [0 1 1] [0.7 0.7 0.7] [ 0 0 0 ] [ 0 0 0 ] ] exch get } bind def\n"
485 "/aSFC { aColor /Font_Fg exch def } bind def\n"
486 "/aSBC { aColor /Font_Bg exch def } bind def\n"
487 "/aSHORP0 { /Font_CPI Font_CPIDefault def setFont } bind def\n"
488 "/aSHORP1 { /Font_CPI Font_CPIDefault def setFont } bind def\n"
489 "/aSHORP2 { /Font_CPI 120 def setFont } bind def\n"
490 "/aSHORP3 { /Font_CPI Font_CPIDefault def setFont } bind def\n"
491 "/aSHORP4 { /Font_CPI 171 def setFont } bind def\n"
492 "/aSHORP5 { /Font_CPI Font_CPIDefault def setFont } bind def\n"
493 "/aSHORP6 { /Font_CPI 100 def setFont } bind def\n"
494 "/aDEN6 { } bind def\n"
495 "/aDEN5 { } bind def\n"
496 "/aDEN4 { } bind def\n"
497 "/aDEN3 { } bind def\n"
498 "/aDEN2 { } bind def\n"
499 "/aDEN1 { } bind def\n"
500 "/aSUS2 { } bind def\n"
501 "/aSUS1 { } bind def\n"
502 "/aSUS4 { } bind def\n"
503 "/aSUS3 { } bind def\n"
504 "/aSUS0 { } bind def\n"
505 "/aPLU { } bind def\n"
506 "/aPLD { } bind def\n"
507 "/aFNT0 { } bind def\n"
508 "/aFNT1 { } bind def\n"
509 "/aFNT2 { } bind def\n"
510 "/aFNT3 { } bind def\n"
511 "/aFNT4 { } bind def\n"
512 "/aFNT5 { } bind def\n"
513 "/aFNT6 { } bind def\n"
514 "/aFNT7 { } bind def\n"
515 "/aFNT8 { } bind def\n"
516 "/aFNT9 { } bind def\n"
517 "/aFNT10 { } bind def\n"
518 "/aPROP2 { /Font_P true def } bind def\n"
519 "/aPROP1 { /Font_P false def } bind def\n"
520 "/aPROP0 { /Font_P false def } bind def\n"
521 "/aJFY5 { } bind def\n"
522 "/aJFY7 { } bind def\n"
523 "/aJFY6 { } bind def\n"
524 "/aJFY0 { } bind def\n"
525 "/aJFY3 { } bind def\n"
526 "/aJFY1 { } bind def\n"
527 "/aVERP0 { /Spacing_LPI 8 def } bind def\n"
528 "/aVERP1 { /Spacing_LPI 6 def } bind def\n"
532 if (!ps_HeaderSent
) {
538 PED
->ped_MaxXDots
* 72 / PED
->ped_XDotsInch
,
539 PED
->ped_MaxYDots
* 72 / PED
->ped_YDotsInch
,
542 PED
->ped_MaxXDots
* 72 / PED
->ped_XDotsInch
,
543 PED
->ped_MaxYDots
* 72 / PED
->ped_YDotsInch
,
544 /* Margin - assuming average font width is 1/2 its height*/
545 PED
->ped_MaxYDots
, PED
->ped_YDotsInch
,
546 PD
->pd_Preferences
.PrintLeftMargin
,
551 ps_HeaderSent
= TRUE
;
556 static LONG
ps_Open(union printerIO
*ior
)
558 D(bug("ps_Open: ior=%p\n", ior
));
560 ps_HeaderSent
= FALSE
;
565 static VOID
ps_Close(union printerIO
*ior
)
568 ps_PWrite(") aSHOW aFF\n"
572 D(bug("ps_Close: ior=%p\n", ior
));
575 VOID
color_get(struct ColorMap
*cm
,
581 UWORD hibits
= ((UWORD
*)cm
->ColorTable
)[index
];
583 ULONG red8
= (hibits
& 0x0f00) >> 4;
584 ULONG green8
= (hibits
& 0x00f0);
585 ULONG blue8
= (hibits
& 0x000f) << 4;
587 if (cm
->Type
> COLORMAP_TYPE_V1_2
) {
588 UWORD lobits
= ((UWORD
*)cm
->LowColorBits
)[index
];
590 red8
|= (lobits
& 0x0f00) >> 8;
591 green8
|= (lobits
& 0x00f0) >> 4;
592 blue8
|= (lobits
& 0x000f);
600 static LONG
ps_RenderInit(struct IODRPReq
*io
, LONG width
, LONG height
)
602 D(bug("ps_RenderInit: Dump raster %ldx%ld pixels, io_RastPort=%p\n", width
, height
, io
->io_RastPort
));
603 D(bug("\t@%ldx%ld (%ldx%ld) => @%ldx%ld\n",
604 io
->io_SrcX
, io
->io_SrcY
, io
->io_SrcWidth
,
605 io
->io_SrcHeight
, io
->io_DestCols
, io
->io_DestRows
));
612 ps_PrintShade
= PD
->pd_Preferences
.PrintShade
;
613 ps_PrintBufLen
= PS_NOSCALING
? io
->io_SrcWidth
: width
;
614 PD
->pd_PrintBuf
= AllocMem(ps_PrintBufLen
* 8 + 1, MEMF_ANY
);
615 if (PD
->pd_PrintBuf
== NULL
)
616 return PDERR_BUFFERMEMORY
;
618 if (PD
->pd_Preferences
.PrintFlags
& PGFF_CENTER_IMAGE
) {
619 alignOffsetX
= (PED
->ped_MaxXDots
- width
) / 2;
620 alignOffsetY
= (PED
->ped_MaxYDots
- height
) / 2;
623 alignOffsetY
= PED
->ped_MaxYDots
- height
;
626 /* Leave text printing mode */
627 ps_PWrite(") aSHOW grestore gsave\n");
629 /* Move grapics location to (in dots):
637 /* Move text location to (in points):
639 * texty = y * 72 / dpiY - Spacing
641 ps_PWrite("Page_Left %ld 72 mul %ld div Spacing sub moveto\n",
642 y
, PED
->ped_YDotsInch
);
644 /* Save the graphics context - we don't want the scaling & translation
645 * when we return to text context later
647 ps_PWrite("gsave\n");
648 ps_PWrite("%ld %ld div %ld %ld div translate\n",
649 x
* 72, PED
->ped_XDotsInch
,
650 y
* 72, PED
->ped_YDotsInch
);
651 ps_PWrite("%ld %ld div %ld %ld div scale\n", width
* 72, PED
->ped_XDotsInch
, height
* 72, PED
->ped_YDotsInch
);
654 width
= io
->io_SrcWidth
;
655 height
= io
->io_SrcHeight
;
658 ps_PWrite("%ld %ld ", width
, height
);
660 switch (ps_PrintShade
) {
662 ps_PWrite("aImageBW\n");
664 case SHADE_GREYSCALE
:
665 ps_PWrite("aImageGreyscale\n");
669 ps_PWrite("aImageColorRGB\n");
671 ps_PWrite("aImageColorCMYK\n");
679 static UBYTE
tohex(UBYTE val
)
682 return (val
< 10) ? ('0' + val
) : ('a' + val
- 10);
685 static LONG
ps_RenderTransfer(struct PrtInfo
*pi
, LONG cindex
, LONG y
)
687 UBYTE
*ptr
= PD
->pd_PrintBuf
;
688 union colorEntry
*src
= pi
->pi_ColorInt
;
690 int const rgb
[3] = { PCMRED
, PCMGREEN
, PCMBLUE
};
691 int const cmyk
[4] = { PCMCYAN
, PCMMAGENTA
, PCMYELLOW
, PCMBLACK
};
693 UBYTE threshold
= (PD
->pd_Preferences
.PrintThreshold
& 0xf) * 0x11;
695 for (x
= 0; x
< ps_PrintBufLen
; x
++, src
++) {
698 switch (ps_PrintShade
) {
702 color
|= (src
->colorByte
[PCMWHITE
] >= threshold
) ? 1 : 0;
704 color
|= ((255 - src
->colorByte
[PCMBLACK
]) >= threshold
) ? 1 : 0;
706 *(ptr
++) = tohex(color
>>4);
707 *(ptr
++) = tohex(color
>>0);
710 case SHADE_GREYSCALE
:
712 color
= src
->colorByte
[PCMWHITE
];
714 color
= 255 - src
->colorByte
[PCMBLACK
];
715 *(ptr
++) = tohex(color
>>4);
716 *(ptr
++) = tohex(color
>>0);
720 /* Single-pass RGB */
721 for (i
= 0; i
< 3; i
++) {
722 color
= src
->colorByte
[rgb
[i
]];
723 *(ptr
++) = tohex(color
>>4);
724 *(ptr
++) = tohex(color
>>0);
728 for (i
= 0; i
< 4; i
++) {
729 color
= src
->colorByte
[cmyk
[i
]];
730 *(ptr
++) = tohex(color
>>4);
731 *(ptr
++) = tohex(color
>>0);
737 if (ps_PrintShade
== SHADE_BW
&& ((x
& 7) != 0)) {
738 for (; (x
& 7) != 0; x
++) {
741 *(ptr
++) = tohex(color
>>4);
742 *(ptr
++) = tohex(color
>>0);
750 static LONG
ps_RenderFlush(LONG rows
)
754 switch (ps_PrintShade
) {
756 len
= (ps_PrintBufLen
+ 7) / 8;
758 case SHADE_GREYSCALE
:
759 len
= ps_PrintBufLen
;
763 len
= ps_PrintBufLen
* 3;
765 len
= ps_PrintBufLen
* 4;
769 PD
->pd_PWrite(PD
->pd_PrintBuf
, len
* 2 + 1);
774 static LONG
ps_RenderClear(void)
776 memset(PD
->pd_PrintBuf
, '0', ps_PrintBufLen
* 8);
780 static LONG
ps_RenderPreInit(struct IODRPReq
*io
, LONG flags
)
786 switch (flags
& SPECIAL_DENSITYMASK
) {
787 case SPECIAL_DENSITY1
:
791 case SPECIAL_DENSITY2
:
795 case SPECIAL_DENSITY3
:
799 case SPECIAL_DENSITY4
:
803 case SPECIAL_DENSITY5
:
807 case SPECIAL_DENSITY6
:
811 case SPECIAL_DENSITY7
:
820 switch (PD
->pd_Preferences
.PrintPitch
) {
821 case PP_ELITE
: ps_FontCPI
= 120; break;
822 case PP_FINE
: ps_FontCPI
= 171; break;
823 case PP_PICA
: ps_FontCPI
= 100; break;
825 return PDERR_BADDIMENSION
;
828 switch (PD
->pd_Preferences
.PrintSpacing
) {
829 case PS_SIX_LPI
: ps_SpacingLPI
= 6; break;
830 case PS_EIGHT_LPI
: ps_SpacingLPI
= 8; break;
832 return PDERR_BADDIMENSION
;
835 switch (PD
->pd_Preferences
.PaperSize
) {
836 /* PaperSize (in units of 0.0001 meters) */
837 case US_LETTER
: ps_PaperSize
= "Letter"; break; /* 8.5"x11" */
838 case US_LEGAL
: ps_PaperSize
= "Legal"; break; /* 8.5"x14" */
839 case N_TRACTOR
: ps_PaperSize
= "80-Col"; break; /* 9.5"x11" */
840 case W_TRACTOR
: ps_PaperSize
= "132-Col"; break; /* 14.86"x11" */
842 case EURO_A0
: ps_PaperSize
= "A0"; break; /* A0: 841 x 1189 */
843 case EURO_A1
: ps_PaperSize
= "A1"; break; /* A1: 594 x 841 */
844 case EURO_A2
: ps_PaperSize
= "A2"; break; /* A2: 420 x 594 */
845 case EURO_A3
: ps_PaperSize
= "A3"; break; /* A3: 297 x 420 */
846 case EURO_A4
: ps_PaperSize
= "A4"; break; /* A4: 210 x 297 */
847 case EURO_A5
: ps_PaperSize
= "A5"; break; /* A5: 148 x 210 */
848 case EURO_A6
: ps_PaperSize
= "A6"; break; /* A6: 105 x 148 */
849 case EURO_A7
: ps_PaperSize
= "A7"; break; /* A7: 74 x 105 */
850 case EURO_A8
: ps_PaperSize
= "A8"; break; /* A8: 52 x 74 */
851 case CUSTOM
: ps_PaperSize
= "Custom"; break;
852 default: return PDERR_BADDIMENSION
;
855 /* Set up for the page size */
856 switch (PD
->pd_Preferences
.PaperSize
) {
857 /* PaperSize (in units of 0.0001 meters) */
858 case US_LETTER
: width
= 2159; height
= 2794; break; /* 8.5"x11" */
859 case US_LEGAL
: width
= 2159; height
= 3556; break; /* 8.5"x14" */
860 case N_TRACTOR
: width
= 2413; height
= 2794; break; /* 9.5"x11" */
861 case W_TRACTOR
: width
= 3774; height
= 2794; break; /* 14.86"x11" */
863 case EURO_A0
: width
= 8410; height
= 11890; break; /* A0: 841 x 1189 */
864 case EURO_A1
: width
= 5940; height
= 8410; break; /* A1: 594 x 841 */
865 case EURO_A2
: width
= 4200; height
= 5940; break; /* A2: 420 x 594 */
866 case EURO_A3
: width
= 2970; height
= 4200; break; /* A3: 297 x 420 */
867 case EURO_A4
: width
= 2100; height
= 2970; break; /* A4: 210 x 297 */
868 case EURO_A5
: width
= 1480; height
= 2100; break; /* A5: 148 x 210 */
869 case EURO_A6
: width
= 1050; height
= 1480; break; /* A6: 105 x 148 */
870 case EURO_A7
: width
= 740; height
= 1050; break; /* A7: 74 x 105 */
871 case EURO_A8
: width
= 520; height
= 740; break; /* A8: 52 x 74 */
872 case CUSTOM
: width
= PD
->pd_Preferences
.PrintMaxWidth
* 254 / 10;
873 height
= PD
->pd_Preferences
.PrintMaxHeight
* 254 / 10;
875 default: return PDERR_CANCEL
;
878 PED
->ped_MaxColumns
= width
* ps_FontCPI
/ 2540;
879 PED
->ped_XDotsInch
= dpiX
;
880 PED
->ped_YDotsInch
= dpiY
;
881 PED
->ped_MaxXDots
= width
* dpiX
/ 254;
882 PED
->ped_MaxYDots
= height
* dpiY
/ 254;
883 D(bug("MaxColumns=%d, dpiX=%d, dpiY=%d, MaxXDots=%d, MaxYDots=%d (%d x %d in)\n",
884 PED
->ped_MaxColumns
, PED
->ped_XDotsInch
, PED
->ped_YDotsInch
,
885 PED
->ped_MaxXDots
, PED
->ped_MaxYDots
,
886 PED
->ped_MaxXDots
/ dpiX
, PED
->ped_MaxYDots
/ dpiY
));
891 static LONG
ps_RenderClose(SIPTR error
, ULONG flags
)
893 if (ps_PrintBufLen
) {
894 /* Restore to text context - the text location
895 * has already been moved to after the raster
897 ps_PWrite("grestore (\n");
898 FreeMem(PD
->pd_PrintBuf
, ps_PrintBufLen
* 8 + 1);
899 PD
->pd_PrintBuf
=NULL
;
904 if (!(flags
& SPECIAL_NOFORMFEED
))
911 static LONG
ps_Render(SIPTR ct
, LONG x
, LONG y
, LONG status
)
913 LONG err
= PDERR_NOERR
;
917 D(bug("PRS_INIT: ct=%p, x=%d, y=%d\n", ct
, x
, y
));
918 err
= ps_RenderInit((struct IODRPReq
*)ct
, x
, y
);
921 D(bug("PRS_TRANSFER: ct=%p, x=%d, y=%d\n", ct
, x
, y
));
922 err
= ps_RenderTransfer((struct PrtInfo
*)ct
, x
, y
);
925 D(bug("PRS_FLUSH: ct=%p, x=%d, y=%d\n", ct
, x
, y
));
926 err
= ps_RenderFlush(y
);
929 D(bug("PRS_CLEAR: ct=%p, x=%d, y=%d\n", ct
, x
, y
));
930 err
= ps_RenderClear();
933 D(bug("PRS_CLOSE: ct=%p, x=0x%0x, y=%d\n", ct
, x
, y
));
934 err
= ps_RenderClose(ct
, x
);
937 D(bug("PRS_PREINIT: ct=%p, x=0x%0x, y=%d\n", ct
, x
, y
));
938 err
= ps_RenderPreInit((struct IODRPReq
*)ct
, x
);
941 D(bug("PRS_CONVERT: ct=%p, x=0x%0x, y=%d\n", ct
, x
, y
));
945 D(bug("PRS_CORRECT: ct=%p, x=0x%0x, y=%d\n", ct
, x
, y
));
949 D(bug("PRS_xxxx(%d): ct=%p, x=0x%0x, y=%d\n", status
, ct
, x
, y
));
958 * > 0 = processed, add N chars
959 * 0 = not handled by DoSpecial
960 * -1 = Unsupported command
961 * -2 = Processed, but no additional chars in the buffer
963 static LONG
ps_DoSpecial(UWORD
*command
, UBYTE output_buffer
[],
964 BYTE
*current_line_position
,
965 BYTE
*current_line_spacing
,
966 BYTE
*crlf_flag
, UBYTE params
[])
969 D(bug("ps_DoSpecial: command=0x%04x, output_buffer=%p, current_line_position=%d, current_line_spacing=%d, crlf_flag=%d, params=%s\n",
970 *command
, output_buffer
, *current_line_position
, *current_line_spacing
, *crlf_flag
, params
));
978 PD
->pd_PWaitEnabled
= '\375';
982 ps_VWrite(output_buffer
, ") aSHOW %ld aSFC (\n", params
[0] % 10);
983 ret
= strlen(output_buffer
);
986 ps_VWrite(output_buffer
, ") aSHOW %ld aSBC (\n", params
[0] % 10);
987 ret
= strlen(output_buffer
);
997 static LONG
ps_ConvFunc(UBYTE
*buf
, UBYTE c
, LONG crlf_flag
)
999 D(bug("ps_ConvFunc: %p '%c' %d\n", buf
, c
, crlf_flag
));
1001 if (c
== '\014') { /* Formfeed */
1002 ps_VSendPage(buf
, TRUE
);
1006 if (c
< 0x1f || c
> 0x7f)
1009 if (c
== '(' || c
== ')' || c
== '\\') {
1016 if (c
>= ' ' && c
< 127) {
1023 *(buf
++) = ((c
>> 6) & 7) + '0';
1024 *(buf
++) = ((c
>> 3) & 7) + '0';
1025 *(buf
++) = ((c
>> 0) & 7) + '0';
1030 static LONG
ps_DoPreferences(union printerIO
*ior
, LONG command
)
1032 D(bug("ps_DoPreferences: ior=%p, command=%d\n"));
1036 static VOID
ps_CallErrHook(union printerIO
*ior
, struct Hook
*hook
)
1038 D(bug("ps_CallErrHook: ior=%p, hook=%p\n", ior
, hook
));