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 psinitclip
[] =
167 static char pseoclip
[] =
170 static char psrectclip
[] =
171 "%d %d %d %d rectclip\n";
173 static char psrectclip2
[] =
176 static char pshatch
[] =
179 static char psrotate
[] = /* ang */
182 static char psarrayget
[] =
185 static char psarrayput
[] =
188 static char psarraydef
[] =
189 "/%s %d array def\n";
191 char *PSDRV_ANSIVector
[256] = {
192 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x00 */
193 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
194 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x10 */
195 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
196 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
197 "dollar", "percent", "ampersand", "quotesingle",
198 "parenleft", "parenright", "asterisk", "plus",
199 "comma", "hyphen", "period", "slash",
200 "zero", "one", "two", "three", /* 0x30 */
201 "four", "five", "six", "seven",
202 "eight", "nine", "colon", "semicolon",
203 "less", "equal", "greater", "question",
204 "at", "A", "B", "C", /* 0x40 */
208 "P", "Q", "R", "S", /* 0x50 */
210 "X", "Y", "Z", "bracketleft",
211 "backslash", "bracketright", "asciicircum", "underscore",
212 "grave", "a", "b", "c", /* 0x60 */
216 "p", "q", "r", "s", /* 0x70 */
218 "x", "y", "z", "braceleft",
219 "bar", "braceright", "asciitilde", NULL
,
220 NULL
, NULL
, NULL
, NULL
, /* 0x80 */
221 NULL
, NULL
, NULL
, NULL
,
222 NULL
, NULL
, NULL
, NULL
,
223 NULL
, NULL
, NULL
, NULL
,
224 NULL
, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
225 "quotedblright","bullet", "endash", "emdash",
226 NULL
, NULL
, NULL
, NULL
,
227 NULL
, NULL
, NULL
, NULL
,
228 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
229 "currency", "yen", "brokenbar", "section",
230 "dieresis", "copyright", "ordfeminine", "guillemotleft",
231 "logicalnot", "hyphen", "registered", "macron",
232 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
233 "acute", "mu", "paragraph", "periodcentered",
234 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
235 "onequarter", "onehalf", "threequarters","questiondown",
236 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
237 "Adieresis", "Aring", "AE", "Ccedilla",
238 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
239 "Igrave", "Iacute", "Icircumflex", "Idieresis",
240 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
241 "Ocircumflex", "Otilde", "Odieresis", "multiply",
242 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
243 "Udieresis", "Yacute", "Thorn", "germandbls",
244 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
245 "adieresis", "aring", "ae", "ccedilla",
246 "egrave", "eacute", "ecircumflex", "edieresis",
247 "igrave", "iacute", "icircumflex", "idieresis",
248 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
249 "ocircumflex", "otilde", "odieresis", "divide",
250 "oslash", "ugrave", "uacute", "ucircumflex",
251 "udieresis", "yacute", "thorn", "ydieresis"
255 char psreencodefont
[] = /* newfontname basefontname*/
256 "/%s /%s reencodefont\n";
259 int PSDRV_WriteSpool(DC
*dc
, LPSTR lpData
, WORD cch
)
261 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
263 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
264 if( !PSDRV_StartPage(dc
) )
267 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
271 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
275 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
276 strlen(feature
) + strlen(value
));
279 sprintf(buf
, psbeginfeature
, feature
, value
);
280 WriteSpool16( hJob
, buf
, strlen(buf
) );
282 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
284 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
286 HeapFree( PSDRV_Heap
, 0, buf
);
292 INT
PSDRV_WriteHeader( DC
*dc
, LPCSTR title
)
294 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
295 char *buf
, *orient
, vectbuf
[256];
300 TRACE("'%s'\n", title
);
302 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
303 strlen(title
) + 30 );
305 WARN("HeapAlloc failed\n");
309 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
310 /* BBox co-ords are in default user co-ord system so urx < ury even in
312 urx
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
313 ury
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
314 orient
= "Landscape";
316 urx
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
317 ury
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
321 /* FIXME should do something better with BBox */
323 sprintf(buf
, psheader
, title
, 0, 0, urx
, ury
, orient
);
325 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
327 WARN("WriteSpool error\n");
328 HeapFree( PSDRV_Heap
, 0, buf
);
331 HeapFree( PSDRV_Heap
, 0, buf
);
333 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
334 WriteSpool16( physDev
->job
.hJob
, psvectorstart
, strlen(psvectorstart
) );
336 for(i
= 0; i
< 256; i
+= 8) {
338 for(j
= 0; j
< 8; j
++) {
339 strcat(vectbuf
, "/");
340 if(PSDRV_ANSIVector
[i
+j
]) {
341 strcat(vectbuf
, PSDRV_ANSIVector
[i
+j
]);
342 strcat(vectbuf
, " ");
344 strcat(vectbuf
, ".notdef ");
347 strcat(vectbuf
, "\n");
348 WriteSpool16( physDev
->job
.hJob
, vectbuf
, strlen(vectbuf
) );
351 WriteSpool16( physDev
->job
.hJob
, psvectorend
, strlen(psvectorend
) );
352 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
353 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
356 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
358 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
359 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
360 if(slot
->InvocationString
) {
361 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
362 slot
->InvocationString
);
368 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
369 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
370 if(page
->InvocationString
) {
371 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
372 page
->InvocationString
);
378 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
385 INT
PSDRV_WriteFooter( DC
*dc
)
387 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
390 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
392 WARN("HeapAlloc failed\n");
396 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
398 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
400 WARN("WriteSpool error\n");
401 HeapFree( PSDRV_Heap
, 0, buf
);
404 HeapFree( PSDRV_Heap
, 0, buf
);
410 INT
PSDRV_WriteEndPage( DC
*dc
)
412 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
414 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
415 sizeof(psendpage
)-1 ) {
416 WARN("WriteSpool error\n");
425 INT
PSDRV_WriteNewPage( DC
*dc
)
427 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
430 signed int xtrans
, ytrans
, rotation
;
432 sprintf(name
, "%d", physDev
->job
.PageNo
);
434 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
436 WARN("HeapAlloc failed\n");
440 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
441 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
442 xtrans
= dc
->w
.devCaps
->vertRes
;
443 ytrans
= dc
->w
.devCaps
->horzRes
;
451 ytrans
= dc
->w
.devCaps
->vertRes
;
455 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
456 dc
->w
.devCaps
->logPixelsX
, dc
->w
.devCaps
->logPixelsY
,
457 xtrans
, ytrans
, rotation
);
459 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
461 WARN("WriteSpool error\n");
462 HeapFree( PSDRV_Heap
, 0, buf
);
465 HeapFree( PSDRV_Heap
, 0, buf
);
470 BOOL
PSDRV_WriteMoveTo(DC
*dc
, INT x
, INT y
)
474 sprintf(buf
, psmoveto
, x
, y
);
475 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
478 BOOL
PSDRV_WriteLineTo(DC
*dc
, INT x
, INT y
)
482 sprintf(buf
, pslineto
, x
, y
);
483 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
487 BOOL
PSDRV_WriteStroke(DC
*dc
)
489 return PSDRV_WriteSpool(dc
, psstroke
, sizeof(psstroke
)-1);
494 BOOL
PSDRV_WriteRectangle(DC
*dc
, INT x
, INT y
, INT width
,
499 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
500 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
503 BOOL
PSDRV_WriteRRectangle(DC
*dc
, INT x
, INT y
, INT width
,
508 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
509 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
512 BOOL
PSDRV_WriteArc(DC
*dc
, INT x
, INT y
, INT w
, INT h
, double ang1
,
517 /* Make angles -ve and swap order because we're working with an upside
519 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
520 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
523 static char encodingext
[] = "-ANSI";
525 BOOL
PSDRV_WriteSetFont(DC
*dc
, BOOL UseANSI
)
527 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
530 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
531 sizeof(pssetfont
) + strlen(physDev
->font
.afm
->FontName
) + 40);
534 WARN("HeapAlloc failed\n");
538 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
539 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
542 WARN("HeapAlloc failed\n");
543 HeapFree(PSDRV_Heap
, 0, buf
);
548 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
550 strcpy(newbuf
, physDev
->font
.afm
->FontName
);
552 sprintf(buf
, pssetfont
, newbuf
,
553 physDev
->font
.size
, -physDev
->font
.size
,
554 -physDev
->font
.escapement
);
556 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
557 HeapFree(PSDRV_Heap
, 0, buf
);
561 BOOL
PSDRV_WriteSetColor(DC
*dc
, PSCOLOR
*color
)
563 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
566 PSDRV_CopyColor(&physDev
->inkColor
, color
);
567 switch(color
->type
) {
569 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
571 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
574 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
575 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
578 ERR("Unkonwn colour type %d\n", color
->type
);
585 BOOL
PSDRV_WriteSetPen(DC
*dc
)
587 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
590 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
591 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
593 if(physDev
->pen
.dash
) {
594 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
595 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
601 BOOL
PSDRV_WriteReencodeFont(DC
*dc
)
603 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
606 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
607 sizeof(psreencodefont
) + 2 * strlen(physDev
->font
.afm
->FontName
)
608 + sizeof(encodingext
));
611 WARN("HeapAlloc failed\n");
615 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
616 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
619 WARN("HeapAlloc failed\n");
620 HeapFree(PSDRV_Heap
, 0, buf
);
624 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
625 sprintf(buf
, psreencodefont
, newbuf
, physDev
->font
.afm
->FontName
);
627 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
629 HeapFree(PSDRV_Heap
, 0, newbuf
);
630 HeapFree(PSDRV_Heap
, 0, buf
);
634 BOOL
PSDRV_WriteShow(DC
*dc
, char *str
, INT count
)
637 INT buflen
= count
+ 10, i
, done
;
639 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, buflen
);
641 for(i
= done
= 0; i
< count
; i
++) {
642 if(!isprint(str
[i
])) {
643 if(done
+ 4 >= buflen
)
644 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
645 sprintf(buf
+ done
, "\\%03o", (int)(unsigned char)str
[i
] );
647 } else if(str
[i
] == '\\' || str
[i
] == '(' || str
[i
] == ')' ) {
648 if(done
+ 2 >= buflen
)
649 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
651 buf
[done
++] = str
[i
];
653 if(done
+ 1 >= buflen
)
654 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
655 buf
[done
++] = str
[i
];
660 buf1
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psshow
) + done
);
662 sprintf(buf1
, psshow
, buf
);
664 PSDRV_WriteSpool(dc
, buf1
, strlen(buf1
));
665 HeapFree(PSDRV_Heap
, 0, buf
);
666 HeapFree(PSDRV_Heap
, 0, buf1
);
671 BOOL
PSDRV_WriteFill(DC
*dc
)
673 return PSDRV_WriteSpool(dc
, psfill
, sizeof(psfill
)-1);
676 BOOL
PSDRV_WriteEOFill(DC
*dc
)
678 return PSDRV_WriteSpool(dc
, pseofill
, sizeof(pseofill
)-1);
681 BOOL
PSDRV_WriteGSave(DC
*dc
)
683 return PSDRV_WriteSpool(dc
, psgsave
, sizeof(psgsave
)-1);
686 BOOL
PSDRV_WriteGRestore(DC
*dc
)
688 return PSDRV_WriteSpool(dc
, psgrestore
, sizeof(psgrestore
)-1);
691 BOOL
PSDRV_WriteNewPath(DC
*dc
)
693 return PSDRV_WriteSpool(dc
, psnewpath
, sizeof(psnewpath
)-1);
696 BOOL
PSDRV_WriteClosePath(DC
*dc
)
698 return PSDRV_WriteSpool(dc
, psclosepath
, sizeof(psclosepath
)-1);
701 BOOL
PSDRV_WriteClip(DC
*dc
)
703 return PSDRV_WriteSpool(dc
, psclip
, sizeof(psclip
)-1);
706 BOOL
PSDRV_WriteEOClip(DC
*dc
)
708 return PSDRV_WriteSpool(dc
, pseoclip
, sizeof(pseoclip
)-1);
711 BOOL
PSDRV_WriteInitClip(DC
*dc
)
713 return PSDRV_WriteSpool(dc
, psinitclip
, sizeof(psinitclip
)-1);
716 BOOL
PSDRV_WriteHatch(DC
*dc
)
718 return PSDRV_WriteSpool(dc
, pshatch
, sizeof(pshatch
)-1);
721 BOOL
PSDRV_WriteRotate(DC
*dc
, float ang
)
725 sprintf(buf
, psrotate
, ang
);
726 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
729 BOOL
PSDRV_WriteIndexColorSpaceBegin(DC
*dc
, int size
)
732 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
733 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
736 BOOL
PSDRV_WriteIndexColorSpaceEnd(DC
*dc
)
738 char buf
[] = ">\n] setcolorspace\n";
739 return PSDRV_WriteSpool(dc
, buf
, sizeof(buf
) - 1);
742 BOOL
PSDRV_WriteRGB(DC
*dc
, COLORREF
*map
, int number
)
744 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
748 for(i
= 0; i
< number
; i
++) {
749 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
750 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
751 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
754 PSDRV_WriteSpool(dc
, buf
, number
* 7);
755 HeapFree(PSDRV_Heap
, 0, buf
);
760 BOOL
PSDRV_WriteImageDict(DC
*dc
, WORD depth
, INT xDst
, INT yDst
,
761 INT widthDst
, INT heightDst
, INT widthSrc
,
762 INT heightSrc
, char *bits
)
764 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
765 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
766 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
768 char decode1
[] = " /Decode [0 %d]\n";
769 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
771 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
772 char endbits
[] = " /DataSource <%s>\n>> image\n";
774 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
776 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
777 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
779 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
783 sprintf(buf
, decode1
, 255);
787 sprintf(buf
, decode1
, 15);
791 sprintf(buf
, decode1
, 1);
795 strcpy(buf
, decode3
);
799 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
802 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
804 sprintf(buf
, endbits
, bits
);
805 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
808 HeapFree(PSDRV_Heap
, 0, buf
);
813 BOOL
PSDRV_WriteBytes(DC
*dc
, const BYTE
*bytes
, int number
)
815 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
821 for(i
= 0; i
< number
; i
++) {
822 sprintf(ptr
, "%02x%c", bytes
[i
],
823 ((i
& 0xf) == 0xf) || (i
== number
- 1) ? '\n' : ' ');
826 PSDRV_WriteSpool(dc
, buf
, number
* 3);
828 HeapFree(PSDRV_Heap
, 0, buf
);
832 BOOL
PSDRV_WriteDIBits16(DC
*dc
, const WORD
*words
, int number
)
834 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
840 for(i
= 0; i
< number
; i
++) {
843 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
845 r
= words
[i
] >> 10 & 0x1f;
847 g
= words
[i
] >> 5 & 0x1f;
851 sprintf(ptr
, "%02x%02x%02x%c", r
, g
, b
,
852 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
855 PSDRV_WriteSpool(dc
, buf
, number
* 7);
857 HeapFree(PSDRV_Heap
, 0, buf
);
861 BOOL
PSDRV_WriteDIBits24(DC
*dc
, const BYTE
*bits
, int number
)
863 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
869 for(i
= 0; i
< number
; i
++) {
870 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
872 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
875 PSDRV_WriteSpool(dc
, buf
, number
* 7);
877 HeapFree(PSDRV_Heap
, 0, buf
);
881 BOOL
PSDRV_WriteDIBits32(DC
*dc
, const BYTE
*bits
, int number
)
883 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
889 for(i
= 0; i
< number
; i
++) {
890 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
892 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
895 PSDRV_WriteSpool(dc
, buf
, number
* 7);
897 HeapFree(PSDRV_Heap
, 0, buf
);
901 BOOL
PSDRV_WriteArrayGet(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
)
905 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
906 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
909 BOOL
PSDRV_WriteArrayPut(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
913 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
914 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
917 BOOL
PSDRV_WriteArrayDef(DC
*dc
, CHAR
*pszArrayName
, INT nSize
)
921 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
922 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
925 BOOL
PSDRV_WriteRectClip(DC
*dc
, INT x
, INT y
, INT w
, INT h
)
929 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
930 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
933 BOOL
PSDRV_WriteRectClip2(DC
*dc
, CHAR
*pszArrayName
)
937 sprintf(buf
, psrectclip2
, pszArrayName
);
938 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
941 BOOL
PSDRV_WritePatternDict(DC
*dc
, BITMAP
*bm
, BYTE
*bits
)
943 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
944 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
946 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
951 w
= bm
->bmWidth
& ~0x7;
952 h
= bm
->bmHeight
& ~0x7;
954 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
955 sprintf(buf
, start
, w
, h
, w
, h
);
956 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
957 PSDRV_WriteIndexColorSpaceBegin(dc
, 1);
958 map
[0] = dc
->w
.textColor
;
959 map
[1] = dc
->w
.backgroundColor
;
960 PSDRV_WriteRGB(dc
, map
, 2);
961 PSDRV_WriteIndexColorSpaceEnd(dc
);
963 for(y
= h
-1; y
>= 0; y
--) {
964 for(x
= 0; x
< w
/8; x
++) {
965 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
969 PSDRV_WriteImageDict(dc
, 1, 0, 0, 8, 8, 8, 8, buf
);
970 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
971 HeapFree(PSDRV_Heap
, 0, buf
);