2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(psdrv
)
16 static char psheader
[] = /* title llx lly urx ury orientation */
18 "%%%%Creator: Wine PostScript Driver\n"
20 "%%%%BoundingBox: %d %d %d %d\n"
21 "%%%%Pages: (atend)\n"
22 "%%%%Orientation: %s\n"
25 static char psbeginprolog
[] =
28 static char psendprolog
[] =
31 static char psvectorstart
[] =
34 static char psvectorend
[] =
37 static char psprolog
[] = /* output ANSIEncoding vector first */
40 " dup length dict begin\n"
41 " {1 index /FID ne {def} {pop pop} ifelse} forall\n"
42 " /Encoding ANSIEncoding def\n"
47 "/tmpmtrx matrix def\n"
50 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
51 " l cvi gap idiv gap mul\n"
53 " r cvi gap idiv gap mul\n"
54 " {t moveto 0 b t sub rlineto}\n"
58 static char psbeginsetup
[] =
61 static char psendsetup
[] =
64 static char psbeginfeature
[] = /* feature, value */
66 "%%%%BeginFeature: %s %s\n";
68 static char psendfeature
[] =
70 "} stopped cleartomark\n";
72 static char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
74 "%%%%BeginPageSetup\n"
76 "72 %d div 72 %d div scale\n"
82 static char psendpage
[] =
86 static char psfooter
[] = /* pages */
91 static char psmoveto
[] = /* x, y */
94 static char pslineto
[] = /* x, y */
97 static char psstroke
[] =
100 static char psrectangle
[] = /* x, y, width, height, -width */
107 static char psrrectangle
[] = /* x, y, width, height, -width */
114 static char psshow
[] = /* string */
117 static char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
120 "%d 10 div matrix rotate\n"
121 "matrix concatmatrix\n"
122 "makefont setfont\n";
124 static char pssetlinewidth
[] = /* width */
127 static char pssetdash
[] = /* dash, offset */
130 static char pssetgray
[] = /* gray */
133 static char pssetrgbcolor
[] = /* r, g, b */
134 "%.2f %.2f %.2f setrgbcolor\n";
136 static char psarc
[] = /* x, y, w, h, ang1, ang2 */
137 "tmpmtrx currentmatrix pop\n"
140 "0 0 0.5 %.1f %.1f arc\n"
141 "tmpmtrx setmatrix\n";
143 static char psgsave
[] =
146 static char psgrestore
[] =
149 static char psfill
[] =
152 static char pseofill
[] =
155 static char psnewpath
[] =
158 static char psclosepath
[] =
161 static char psclip
[] =
164 static char pseoclip
[] =
167 static char psrectclip
[] =
170 static char pshatch
[] =
173 static char psrotate
[] = /* ang */
176 static char psarrayget
[] =
179 static char psarrayput
[] =
182 static char psarraydef
[] =
183 "/%s %d array def\n";
185 char *PSDRV_ANSIVector
[256] = {
186 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x00 */
187 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
188 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x10 */
189 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
190 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
191 "dollar", "percent", "ampersand", "quotesingle",
192 "parenleft", "parenright", "asterisk", "plus",
193 "comma", "hyphen", "period", "slash",
194 "zero", "one", "two", "three", /* 0x30 */
195 "four", "five", "six", "seven",
196 "eight", "nine", "colon", "semicolon",
197 "less", "equal", "greater", "question",
198 "at", "A", "B", "C", /* 0x40 */
202 "P", "Q", "R", "S", /* 0x50 */
204 "X", "Y", "Z", "bracketleft",
205 "backslash", "bracketright", "asciicircum", "underscore",
206 "grave", "a", "b", "c", /* 0x60 */
210 "p", "q", "r", "s", /* 0x70 */
212 "x", "y", "z", "braceleft",
213 "bar", "braceright", "asciitilde", NULL
,
214 NULL
, NULL
, NULL
, NULL
, /* 0x80 */
215 NULL
, NULL
, NULL
, NULL
,
216 NULL
, NULL
, NULL
, NULL
,
217 NULL
, NULL
, NULL
, NULL
,
218 NULL
, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
219 "quotedblright","bullet", "endash", "emdash",
220 NULL
, NULL
, NULL
, NULL
,
221 NULL
, NULL
, NULL
, NULL
,
222 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
223 "currency", "yen", "brokenbar", "section",
224 "dieresis", "copyright", "ordfeminine", "guillemotleft",
225 "logicalnot", "hyphen", "registered", "macron",
226 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
227 "acute", "mu", "paragraph", "periodcentered",
228 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
229 "onequarter", "onehalf", "threequarters","questiondown",
230 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
231 "Adieresis", "Aring", "AE", "Ccedilla",
232 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
233 "Igrave", "Iacute", "Icircumflex", "Idieresis",
234 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
235 "Ocircumflex", "Otilde", "Odieresis", "multiply",
236 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
237 "Udieresis", "Yacute", "Thorn", "germandbls",
238 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
239 "adieresis", "aring", "ae", "ccedilla",
240 "egrave", "eacute", "ecircumflex", "edieresis",
241 "igrave", "iacute", "icircumflex", "idieresis",
242 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
243 "ocircumflex", "otilde", "odieresis", "divide",
244 "oslash", "ugrave", "uacute", "ucircumflex",
245 "udieresis", "yacute", "thorn", "ydieresis"
249 char psreencodefont
[] = /* newfontname basefontname*/
250 "/%s /%s reencodefont\n";
253 int PSDRV_WriteSpool(DC
*dc
, LPSTR lpData
, WORD cch
)
255 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
257 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
258 if( !PSDRV_StartPage(dc
) )
261 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
265 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
269 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
270 strlen(feature
) + strlen(value
));
273 sprintf(buf
, psbeginfeature
, feature
, value
);
274 WriteSpool16( hJob
, buf
, strlen(buf
) );
276 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
278 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
280 HeapFree( PSDRV_Heap
, 0, buf
);
286 INT
PSDRV_WriteHeader( DC
*dc
, LPCSTR title
)
288 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
289 char *buf
, *orient
, vectbuf
[256];
294 TRACE("'%s'\n", title
);
296 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
297 strlen(title
) + 30 );
299 WARN("HeapAlloc failed\n");
303 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
304 /* BBox co-ords are in default user co-ord system so urx < ury even in
306 urx
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
307 ury
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
308 orient
= "Landscape";
310 urx
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
311 ury
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
315 /* FIXME should do something better with BBox */
317 sprintf(buf
, psheader
, title
, 0, 0, urx
, ury
, orient
);
319 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
321 WARN("WriteSpool error\n");
322 HeapFree( PSDRV_Heap
, 0, buf
);
325 HeapFree( PSDRV_Heap
, 0, buf
);
327 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
328 WriteSpool16( physDev
->job
.hJob
, psvectorstart
, strlen(psvectorstart
) );
330 for(i
= 0; i
< 256; i
+= 8) {
332 for(j
= 0; j
< 8; j
++) {
333 strcat(vectbuf
, "/");
334 if(PSDRV_ANSIVector
[i
+j
]) {
335 strcat(vectbuf
, PSDRV_ANSIVector
[i
+j
]);
336 strcat(vectbuf
, " ");
338 strcat(vectbuf
, ".notdef ");
341 strcat(vectbuf
, "\n");
342 WriteSpool16( physDev
->job
.hJob
, vectbuf
, strlen(vectbuf
) );
345 WriteSpool16( physDev
->job
.hJob
, psvectorend
, strlen(psvectorend
) );
346 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
347 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
350 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
352 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
353 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
354 if(slot
->InvocationString
) {
355 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
356 slot
->InvocationString
);
362 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
363 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
364 if(page
->InvocationString
) {
365 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
366 page
->InvocationString
);
372 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
379 INT
PSDRV_WriteFooter( DC
*dc
)
381 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
384 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
386 WARN("HeapAlloc failed\n");
390 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
392 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
394 WARN("WriteSpool error\n");
395 HeapFree( PSDRV_Heap
, 0, buf
);
398 HeapFree( PSDRV_Heap
, 0, buf
);
404 INT
PSDRV_WriteEndPage( DC
*dc
)
406 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
408 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
409 sizeof(psendpage
)-1 ) {
410 WARN("WriteSpool error\n");
419 INT
PSDRV_WriteNewPage( DC
*dc
)
421 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
424 signed int xtrans
, ytrans
, rotation
;
426 sprintf(name
, "%d", physDev
->job
.PageNo
);
428 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
430 WARN("HeapAlloc failed\n");
434 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
435 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
436 xtrans
= dc
->w
.devCaps
->vertRes
;
437 ytrans
= dc
->w
.devCaps
->horzRes
;
445 ytrans
= dc
->w
.devCaps
->vertRes
;
449 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
450 dc
->w
.devCaps
->logPixelsX
, dc
->w
.devCaps
->logPixelsY
,
451 xtrans
, ytrans
, rotation
);
453 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
455 WARN("WriteSpool error\n");
456 HeapFree( PSDRV_Heap
, 0, buf
);
459 HeapFree( PSDRV_Heap
, 0, buf
);
464 BOOL
PSDRV_WriteMoveTo(DC
*dc
, INT x
, INT y
)
468 sprintf(buf
, psmoveto
, x
, y
);
469 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
472 BOOL
PSDRV_WriteLineTo(DC
*dc
, INT x
, INT y
)
476 sprintf(buf
, pslineto
, x
, y
);
477 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
481 BOOL
PSDRV_WriteStroke(DC
*dc
)
483 return PSDRV_WriteSpool(dc
, psstroke
, sizeof(psstroke
)-1);
488 BOOL
PSDRV_WriteRectangle(DC
*dc
, INT x
, INT y
, INT width
,
493 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
494 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
497 BOOL
PSDRV_WriteRRectangle(DC
*dc
, INT x
, INT y
, INT width
,
502 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
503 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
506 BOOL
PSDRV_WriteArc(DC
*dc
, INT x
, INT y
, INT w
, INT h
, double ang1
,
511 /* Make angles -ve and swap order because we're working with an upside
513 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
514 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
517 static char encodingext
[] = "-ANSI";
519 BOOL
PSDRV_WriteSetFont(DC
*dc
, BOOL UseANSI
)
521 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
524 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
525 sizeof(pssetfont
) + strlen(physDev
->font
.afm
->FontName
) + 40);
528 WARN("HeapAlloc failed\n");
532 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
533 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
536 WARN("HeapAlloc failed\n");
537 HeapFree(PSDRV_Heap
, 0, buf
);
542 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
544 strcpy(newbuf
, physDev
->font
.afm
->FontName
);
546 sprintf(buf
, pssetfont
, newbuf
,
547 physDev
->font
.size
, -physDev
->font
.size
,
548 -physDev
->font
.escapement
);
550 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
551 HeapFree(PSDRV_Heap
, 0, buf
);
555 BOOL
PSDRV_WriteSetColor(DC
*dc
, PSCOLOR
*color
)
557 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
560 PSDRV_CopyColor(&physDev
->inkColor
, color
);
561 switch(color
->type
) {
563 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
565 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
568 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
569 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
572 ERR("Unkonwn colour type %d\n", color
->type
);
579 BOOL
PSDRV_WriteSetPen(DC
*dc
)
581 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
584 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
585 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
587 if(physDev
->pen
.dash
) {
588 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
589 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
595 BOOL
PSDRV_WriteReencodeFont(DC
*dc
)
597 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
600 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
601 sizeof(psreencodefont
) + 2 * strlen(physDev
->font
.afm
->FontName
)
602 + sizeof(encodingext
));
605 WARN("HeapAlloc failed\n");
609 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
610 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
613 WARN("HeapAlloc failed\n");
614 HeapFree(PSDRV_Heap
, 0, buf
);
618 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
619 sprintf(buf
, psreencodefont
, newbuf
, physDev
->font
.afm
->FontName
);
621 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
623 HeapFree(PSDRV_Heap
, 0, newbuf
);
624 HeapFree(PSDRV_Heap
, 0, buf
);
628 BOOL
PSDRV_WriteShow(DC
*dc
, char *str
, INT count
)
631 INT buflen
= count
+ 10, i
, done
;
633 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, buflen
);
635 for(i
= done
= 0; i
< count
; i
++) {
636 if(!isprint(str
[i
])) {
637 if(done
+ 4 >= buflen
)
638 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
639 sprintf(buf
+ done
, "\\%03o", (int)(unsigned char)str
[i
] );
641 } else if(str
[i
] == '\\' || str
[i
] == '(' || str
[i
] == ')' ) {
642 if(done
+ 2 >= buflen
)
643 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
645 buf
[done
++] = str
[i
];
647 if(done
+ 1 >= buflen
)
648 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
649 buf
[done
++] = str
[i
];
654 buf1
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psshow
) + done
);
656 sprintf(buf1
, psshow
, buf
);
658 PSDRV_WriteSpool(dc
, buf1
, strlen(buf1
));
659 HeapFree(PSDRV_Heap
, 0, buf
);
660 HeapFree(PSDRV_Heap
, 0, buf1
);
665 BOOL
PSDRV_WriteFill(DC
*dc
)
667 return PSDRV_WriteSpool(dc
, psfill
, sizeof(psfill
)-1);
670 BOOL
PSDRV_WriteEOFill(DC
*dc
)
672 return PSDRV_WriteSpool(dc
, pseofill
, sizeof(pseofill
)-1);
675 BOOL
PSDRV_WriteGSave(DC
*dc
)
677 return PSDRV_WriteSpool(dc
, psgsave
, sizeof(psgsave
)-1);
680 BOOL
PSDRV_WriteGRestore(DC
*dc
)
682 return PSDRV_WriteSpool(dc
, psgrestore
, sizeof(psgrestore
)-1);
685 BOOL
PSDRV_WriteNewPath(DC
*dc
)
687 return PSDRV_WriteSpool(dc
, psnewpath
, sizeof(psnewpath
)-1);
690 BOOL
PSDRV_WriteClosePath(DC
*dc
)
692 return PSDRV_WriteSpool(dc
, psclosepath
, sizeof(psclosepath
)-1);
695 BOOL
PSDRV_WriteClip(DC
*dc
)
697 return PSDRV_WriteSpool(dc
, psclip
, sizeof(psclip
)-1);
700 BOOL
PSDRV_WriteEOClip(DC
*dc
)
702 return PSDRV_WriteSpool(dc
, pseoclip
, sizeof(pseoclip
)-1);
705 BOOL
PSDRV_WriteHatch(DC
*dc
)
707 return PSDRV_WriteSpool(dc
, pshatch
, sizeof(pshatch
)-1);
710 BOOL
PSDRV_WriteRotate(DC
*dc
, float ang
)
714 sprintf(buf
, psrotate
, ang
);
715 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
718 BOOL
PSDRV_WriteIndexColorSpaceBegin(DC
*dc
, int size
)
721 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
722 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
725 BOOL
PSDRV_WriteIndexColorSpaceEnd(DC
*dc
)
727 char buf
[] = ">\n] setcolorspace\n";
728 return PSDRV_WriteSpool(dc
, buf
, sizeof(buf
) - 1);
731 BOOL
PSDRV_WriteRGB(DC
*dc
, COLORREF
*map
, int number
)
733 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
737 for(i
= 0; i
< number
; i
++) {
738 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
739 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
740 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
743 PSDRV_WriteSpool(dc
, buf
, number
* 7);
744 HeapFree(PSDRV_Heap
, 0, buf
);
749 BOOL
PSDRV_WriteImageDict(DC
*dc
, WORD depth
, INT xDst
, INT yDst
,
750 INT widthDst
, INT heightDst
, INT widthSrc
,
751 INT heightSrc
, char *bits
)
753 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
754 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
755 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
757 char decode1
[] = " /Decode [0 %d]\n";
758 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
760 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
761 char endbits
[] = " /DataSource <%s>\n>> image\n";
763 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
765 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
766 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
768 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
772 sprintf(buf
, decode1
, 255);
776 sprintf(buf
, decode1
, 15);
780 sprintf(buf
, decode1
, 1);
784 strcpy(buf
, decode3
);
788 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
791 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
793 sprintf(buf
, endbits
, bits
);
794 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
797 HeapFree(PSDRV_Heap
, 0, buf
);
802 BOOL
PSDRV_WriteBytes(DC
*dc
, const BYTE
*bytes
, int number
)
804 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
810 for(i
= 0; i
< number
; i
++) {
811 sprintf(ptr
, "%02x%c", bytes
[i
],
812 ((i
& 0xf) == 0xf) || (i
== number
- 1) ? '\n' : ' ');
815 PSDRV_WriteSpool(dc
, buf
, number
* 3);
817 HeapFree(PSDRV_Heap
, 0, buf
);
821 BOOL
PSDRV_WriteDIBits16(DC
*dc
, const WORD
*words
, int number
)
823 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
829 for(i
= 0; i
< number
; i
++) {
832 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
834 r
= words
[i
] >> 10 & 0x1f;
836 g
= words
[i
] >> 5 & 0x1f;
840 sprintf(ptr
, "%02x%02x%02x%c", r
, g
, b
,
841 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
844 PSDRV_WriteSpool(dc
, buf
, number
* 7);
846 HeapFree(PSDRV_Heap
, 0, buf
);
850 BOOL
PSDRV_WriteDIBits24(DC
*dc
, const BYTE
*bits
, int number
)
852 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
858 for(i
= 0; i
< number
; i
++) {
859 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
861 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
864 PSDRV_WriteSpool(dc
, buf
, number
* 7);
866 HeapFree(PSDRV_Heap
, 0, buf
);
870 BOOL
PSDRV_WriteDIBits32(DC
*dc
, const BYTE
*bits
, int number
)
872 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
878 for(i
= 0; i
< number
; i
++) {
879 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
881 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
884 PSDRV_WriteSpool(dc
, buf
, number
* 7);
886 HeapFree(PSDRV_Heap
, 0, buf
);
890 BOOL
PSDRV_WriteArrayGet(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
)
894 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
895 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
898 BOOL
PSDRV_WriteArrayPut(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
902 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
903 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
906 BOOL
PSDRV_WriteArrayDef(DC
*dc
, CHAR
*pszArrayName
, INT nSize
)
910 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
911 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
914 BOOL
PSDRV_WriteRectClip(DC
*dc
, CHAR
*pszArrayName
)
918 sprintf(buf
, psrectclip
, pszArrayName
);
919 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
923 BOOL
PSDRV_WritePatternDict(DC
*dc
, BITMAP
*bm
, BYTE
*bits
)
925 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
926 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
928 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
933 w
= bm
->bmWidth
& ~0x7;
934 h
= bm
->bmHeight
& ~0x7;
936 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
937 sprintf(buf
, start
, w
, h
, w
, h
);
938 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
939 PSDRV_WriteIndexColorSpaceBegin(dc
, 1);
940 map
[0] = dc
->w
.textColor
;
941 map
[1] = dc
->w
.backgroundColor
;
942 PSDRV_WriteRGB(dc
, map
, 2);
943 PSDRV_WriteIndexColorSpaceEnd(dc
);
945 for(y
= h
-1; y
>= 0; y
--) {
946 for(x
= 0; x
< w
/8; x
++) {
947 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
951 PSDRV_WriteImageDict(dc
, 1, 0, 0, 8, 8, 8, 8, buf
);
952 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
953 HeapFree(PSDRV_Heap
, 0, buf
);