2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(psdrv
);
17 static char psheader
[] = /* title llx lly urx ury orientation */
19 "%%%%Creator: Wine PostScript Driver\n"
21 "%%%%BoundingBox: %d %d %d %d\n"
22 "%%%%Pages: (atend)\n"
23 "%%%%Orientation: %s\n"
26 static char psbeginprolog
[] =
29 static char psendprolog
[] =
32 static char psvectorstart
[] =
35 static char psvectorend
[] =
38 static char psprolog
[] = /* output ANSIEncoding vector first */
41 " dup length dict begin\n"
42 " {1 index /FID ne {def} {pop pop} ifelse} forall\n"
43 " /Encoding ANSIEncoding def\n"
48 "/tmpmtrx matrix def\n"
51 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
52 " l cvi gap idiv gap mul\n"
54 " r cvi gap idiv gap mul\n"
55 " {t moveto 0 b t sub rlineto}\n"
59 static char psbeginsetup
[] =
62 static char psendsetup
[] =
65 static char psbeginfeature
[] = /* feature, value */
67 "%%%%BeginFeature: %s %s\n";
69 static char psendfeature
[] =
71 "} stopped cleartomark\n";
73 static char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
75 "%%%%BeginPageSetup\n"
77 "72 %d div 72 %d div scale\n"
83 static char psendpage
[] =
87 static char psfooter
[] = /* pages */
92 static char psmoveto
[] = /* x, y */
95 static char pslineto
[] = /* x, y */
98 static char psstroke
[] =
101 static char psrectangle
[] = /* x, y, width, height, -width */
108 static char psrrectangle
[] = /* x, y, width, height, -width */
115 static char psshow
[] = /* string */
118 static char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
121 "%d 10 div matrix rotate\n"
122 "matrix concatmatrix\n"
123 "makefont setfont\n";
125 static char pssetlinewidth
[] = /* width */
128 static char pssetdash
[] = /* dash, offset */
131 static char pssetgray
[] = /* gray */
134 static char pssetrgbcolor
[] = /* r, g, b */
135 "%.2f %.2f %.2f setrgbcolor\n";
137 static char psarc
[] = /* x, y, w, h, ang1, ang2 */
138 "tmpmtrx currentmatrix pop\n"
141 "0 0 0.5 %.1f %.1f arc\n"
142 "tmpmtrx setmatrix\n";
144 static char psgsave
[] =
147 static char psgrestore
[] =
150 static char psfill
[] =
153 static char pseofill
[] =
156 static char psnewpath
[] =
159 static char psclosepath
[] =
162 static char psclip
[] =
165 static char psinitclip
[] =
168 static char pseoclip
[] =
171 static char psrectclip
[] =
172 "%d %d %d %d rectclip\n";
174 static char psrectclip2
[] =
177 static char pshatch
[] =
180 static char psrotate
[] = /* ang */
183 static char psarrayget
[] =
186 static char psarrayput
[] =
189 static char psarraydef
[] =
190 "/%s %d array def\n";
192 char *PSDRV_ANSIVector
[256] = {
193 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x00 */
194 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
195 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x10 */
196 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
197 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
198 "dollar", "percent", "ampersand", "quotesingle",
199 "parenleft", "parenright", "asterisk", "plus",
200 "comma", "hyphen", "period", "slash",
201 "zero", "one", "two", "three", /* 0x30 */
202 "four", "five", "six", "seven",
203 "eight", "nine", "colon", "semicolon",
204 "less", "equal", "greater", "question",
205 "at", "A", "B", "C", /* 0x40 */
209 "P", "Q", "R", "S", /* 0x50 */
211 "X", "Y", "Z", "bracketleft",
212 "backslash", "bracketright", "asciicircum", "underscore",
213 "grave", "a", "b", "c", /* 0x60 */
217 "p", "q", "r", "s", /* 0x70 */
219 "x", "y", "z", "braceleft",
220 "bar", "braceright", "asciitilde", NULL
,
221 NULL
, NULL
, NULL
, NULL
, /* 0x80 */
222 NULL
, NULL
, NULL
, NULL
,
223 NULL
, NULL
, NULL
, NULL
,
224 NULL
, NULL
, NULL
, NULL
,
225 NULL
, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
226 "quotedblright","bullet", "endash", "emdash",
227 NULL
, NULL
, NULL
, NULL
,
228 NULL
, NULL
, NULL
, NULL
,
229 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
230 "currency", "yen", "brokenbar", "section",
231 "dieresis", "copyright", "ordfeminine", "guillemotleft",
232 "logicalnot", "hyphen", "registered", "macron",
233 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
234 "acute", "mu", "paragraph", "periodcentered",
235 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
236 "onequarter", "onehalf", "threequarters","questiondown",
237 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
238 "Adieresis", "Aring", "AE", "Ccedilla",
239 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
240 "Igrave", "Iacute", "Icircumflex", "Idieresis",
241 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
242 "Ocircumflex", "Otilde", "Odieresis", "multiply",
243 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
244 "Udieresis", "Yacute", "Thorn", "germandbls",
245 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
246 "adieresis", "aring", "ae", "ccedilla",
247 "egrave", "eacute", "ecircumflex", "edieresis",
248 "igrave", "iacute", "icircumflex", "idieresis",
249 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
250 "ocircumflex", "otilde", "odieresis", "divide",
251 "oslash", "ugrave", "uacute", "ucircumflex",
252 "udieresis", "yacute", "thorn", "ydieresis"
256 char psreencodefont
[] = /* newfontname basefontname*/
257 "/%s /%s reencodefont\n";
260 int PSDRV_WriteSpool(DC
*dc
, LPSTR lpData
, WORD cch
)
262 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
264 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
265 if( !PSDRV_StartPage(dc
) )
268 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
272 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
276 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
277 strlen(feature
) + strlen(value
));
280 sprintf(buf
, psbeginfeature
, feature
, value
);
281 WriteSpool16( hJob
, buf
, strlen(buf
) );
283 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
285 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
287 HeapFree( PSDRV_Heap
, 0, buf
);
293 INT
PSDRV_WriteHeader( DC
*dc
, LPCSTR title
)
295 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
296 char *buf
, *orient
, vectbuf
[256];
301 TRACE("'%s'\n", title
);
303 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
304 strlen(title
) + 30 );
306 WARN("HeapAlloc failed\n");
310 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
311 /* BBox co-ords are in default user co-ord system so urx < ury even in
313 urx
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
314 ury
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
315 orient
= "Landscape";
317 urx
= (int) (dc
->w
.devCaps
->horzSize
* 72.0 / 25.4);
318 ury
= (int) (dc
->w
.devCaps
->vertSize
* 72.0 / 25.4);
322 /* FIXME should do something better with BBox */
324 sprintf(buf
, psheader
, title
, 0, 0, urx
, ury
, orient
);
326 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
328 WARN("WriteSpool error\n");
329 HeapFree( PSDRV_Heap
, 0, buf
);
332 HeapFree( PSDRV_Heap
, 0, buf
);
334 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
335 WriteSpool16( physDev
->job
.hJob
, psvectorstart
, strlen(psvectorstart
) );
337 for(i
= 0; i
< 256; i
+= 8) {
339 for(j
= 0; j
< 8; j
++) {
340 strcat(vectbuf
, "/");
341 if(PSDRV_ANSIVector
[i
+j
]) {
342 strcat(vectbuf
, PSDRV_ANSIVector
[i
+j
]);
343 strcat(vectbuf
, " ");
345 strcat(vectbuf
, ".notdef ");
348 strcat(vectbuf
, "\n");
349 WriteSpool16( physDev
->job
.hJob
, vectbuf
, strlen(vectbuf
) );
352 WriteSpool16( physDev
->job
.hJob
, psvectorend
, strlen(psvectorend
) );
353 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
354 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
357 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
359 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
360 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
361 if(slot
->InvocationString
) {
362 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
363 slot
->InvocationString
);
369 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
370 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
371 if(page
->InvocationString
) {
372 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
373 page
->InvocationString
);
379 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
386 INT
PSDRV_WriteFooter( DC
*dc
)
388 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
391 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
393 WARN("HeapAlloc failed\n");
397 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
399 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
401 WARN("WriteSpool error\n");
402 HeapFree( PSDRV_Heap
, 0, buf
);
405 HeapFree( PSDRV_Heap
, 0, buf
);
411 INT
PSDRV_WriteEndPage( DC
*dc
)
413 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
415 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
416 sizeof(psendpage
)-1 ) {
417 WARN("WriteSpool error\n");
426 INT
PSDRV_WriteNewPage( DC
*dc
)
428 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
431 signed int xtrans
, ytrans
, rotation
;
433 sprintf(name
, "%d", physDev
->job
.PageNo
);
435 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
437 WARN("HeapAlloc failed\n");
441 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
442 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
443 xtrans
= dc
->w
.devCaps
->vertRes
;
444 ytrans
= dc
->w
.devCaps
->horzRes
;
452 ytrans
= dc
->w
.devCaps
->vertRes
;
456 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
457 dc
->w
.devCaps
->logPixelsX
, dc
->w
.devCaps
->logPixelsY
,
458 xtrans
, ytrans
, rotation
);
460 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
462 WARN("WriteSpool error\n");
463 HeapFree( PSDRV_Heap
, 0, buf
);
466 HeapFree( PSDRV_Heap
, 0, buf
);
471 BOOL
PSDRV_WriteMoveTo(DC
*dc
, INT x
, INT y
)
475 sprintf(buf
, psmoveto
, x
, y
);
476 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
479 BOOL
PSDRV_WriteLineTo(DC
*dc
, INT x
, INT y
)
483 sprintf(buf
, pslineto
, x
, y
);
484 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
488 BOOL
PSDRV_WriteStroke(DC
*dc
)
490 return PSDRV_WriteSpool(dc
, psstroke
, sizeof(psstroke
)-1);
495 BOOL
PSDRV_WriteRectangle(DC
*dc
, INT x
, INT y
, INT width
,
500 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
501 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
504 BOOL
PSDRV_WriteRRectangle(DC
*dc
, INT x
, INT y
, INT width
,
509 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
510 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
513 BOOL
PSDRV_WriteArc(DC
*dc
, INT x
, INT y
, INT w
, INT h
, double ang1
,
518 /* Make angles -ve and swap order because we're working with an upside
520 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
521 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
524 static char encodingext
[] = "-ANSI";
526 BOOL
PSDRV_WriteSetFont(DC
*dc
, BOOL UseANSI
)
528 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
531 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
532 sizeof(pssetfont
) + strlen(physDev
->font
.afm
->FontName
) + 40);
535 WARN("HeapAlloc failed\n");
539 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
540 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
543 WARN("HeapAlloc failed\n");
544 HeapFree(PSDRV_Heap
, 0, buf
);
549 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
551 strcpy(newbuf
, physDev
->font
.afm
->FontName
);
553 sprintf(buf
, pssetfont
, newbuf
,
554 physDev
->font
.size
, -physDev
->font
.size
,
555 -physDev
->font
.escapement
);
557 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
558 HeapFree(PSDRV_Heap
, 0, buf
);
562 BOOL
PSDRV_WriteSetColor(DC
*dc
, PSCOLOR
*color
)
564 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
567 PSDRV_CopyColor(&physDev
->inkColor
, color
);
568 switch(color
->type
) {
570 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
572 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
575 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
576 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
579 ERR("Unkonwn colour type %d\n", color
->type
);
586 BOOL
PSDRV_WriteSetPen(DC
*dc
)
588 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
591 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
592 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
594 if(physDev
->pen
.dash
) {
595 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
596 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
602 BOOL
PSDRV_WriteReencodeFont(DC
*dc
)
604 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
607 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
608 sizeof(psreencodefont
) + 2 * strlen(physDev
->font
.afm
->FontName
)
609 + sizeof(encodingext
));
612 WARN("HeapAlloc failed\n");
616 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
617 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
620 WARN("HeapAlloc failed\n");
621 HeapFree(PSDRV_Heap
, 0, buf
);
625 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
626 sprintf(buf
, psreencodefont
, newbuf
, physDev
->font
.afm
->FontName
);
628 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
630 HeapFree(PSDRV_Heap
, 0, newbuf
);
631 HeapFree(PSDRV_Heap
, 0, buf
);
635 BOOL
PSDRV_WriteShow(DC
*dc
, LPCWSTR str
, INT count
)
638 INT buflen
= count
+ 10, i
, done
;
640 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, buflen
);
642 for(i
= done
= 0; i
< count
; i
++) {
643 char c
= PSDRV_UnicodeToANSI(str
[i
]);
645 if(done
+ 4 >= buflen
)
646 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
647 sprintf(buf
+ done
, "\\%03o", (int)(unsigned char)c
);
649 } else if(c
== '\\' || c
== '(' || c
== ')' ) {
650 if(done
+ 2 >= buflen
)
651 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
655 if(done
+ 1 >= buflen
)
656 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
662 buf1
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psshow
) + done
);
664 sprintf(buf1
, psshow
, buf
);
666 PSDRV_WriteSpool(dc
, buf1
, strlen(buf1
));
667 HeapFree(PSDRV_Heap
, 0, buf
);
668 HeapFree(PSDRV_Heap
, 0, buf1
);
673 BOOL
PSDRV_WriteFill(DC
*dc
)
675 return PSDRV_WriteSpool(dc
, psfill
, sizeof(psfill
)-1);
678 BOOL
PSDRV_WriteEOFill(DC
*dc
)
680 return PSDRV_WriteSpool(dc
, pseofill
, sizeof(pseofill
)-1);
683 BOOL
PSDRV_WriteGSave(DC
*dc
)
685 return PSDRV_WriteSpool(dc
, psgsave
, sizeof(psgsave
)-1);
688 BOOL
PSDRV_WriteGRestore(DC
*dc
)
690 return PSDRV_WriteSpool(dc
, psgrestore
, sizeof(psgrestore
)-1);
693 BOOL
PSDRV_WriteNewPath(DC
*dc
)
695 return PSDRV_WriteSpool(dc
, psnewpath
, sizeof(psnewpath
)-1);
698 BOOL
PSDRV_WriteClosePath(DC
*dc
)
700 return PSDRV_WriteSpool(dc
, psclosepath
, sizeof(psclosepath
)-1);
703 BOOL
PSDRV_WriteClip(DC
*dc
)
705 return PSDRV_WriteSpool(dc
, psclip
, sizeof(psclip
)-1);
708 BOOL
PSDRV_WriteEOClip(DC
*dc
)
710 return PSDRV_WriteSpool(dc
, pseoclip
, sizeof(pseoclip
)-1);
713 BOOL
PSDRV_WriteInitClip(DC
*dc
)
715 return PSDRV_WriteSpool(dc
, psinitclip
, sizeof(psinitclip
)-1);
718 BOOL
PSDRV_WriteHatch(DC
*dc
)
720 return PSDRV_WriteSpool(dc
, pshatch
, sizeof(pshatch
)-1);
723 BOOL
PSDRV_WriteRotate(DC
*dc
, float ang
)
727 sprintf(buf
, psrotate
, ang
);
728 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
731 BOOL
PSDRV_WriteIndexColorSpaceBegin(DC
*dc
, int size
)
734 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
735 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
738 BOOL
PSDRV_WriteIndexColorSpaceEnd(DC
*dc
)
740 char buf
[] = ">\n] setcolorspace\n";
741 return PSDRV_WriteSpool(dc
, buf
, sizeof(buf
) - 1);
744 BOOL
PSDRV_WriteRGB(DC
*dc
, COLORREF
*map
, int number
)
746 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
750 for(i
= 0; i
< number
; i
++) {
751 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
752 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
753 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
756 PSDRV_WriteSpool(dc
, buf
, number
* 7);
757 HeapFree(PSDRV_Heap
, 0, buf
);
762 BOOL
PSDRV_WriteImageDict(DC
*dc
, WORD depth
, INT xDst
, INT yDst
,
763 INT widthDst
, INT heightDst
, INT widthSrc
,
764 INT heightSrc
, char *bits
)
766 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
767 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
768 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
770 char decode1
[] = " /Decode [0 %d]\n";
771 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
773 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
774 char endbits
[] = " /DataSource <%s>\n>> image\n";
776 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
778 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
779 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
781 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
785 sprintf(buf
, decode1
, 255);
789 sprintf(buf
, decode1
, 15);
793 sprintf(buf
, decode1
, 1);
797 strcpy(buf
, decode3
);
801 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
804 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
806 sprintf(buf
, endbits
, bits
);
807 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
810 HeapFree(PSDRV_Heap
, 0, buf
);
815 BOOL
PSDRV_WriteBytes(DC
*dc
, const BYTE
*bytes
, int number
)
817 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
823 for(i
= 0; i
< number
; i
++) {
824 sprintf(ptr
, "%02x%c", bytes
[i
],
825 ((i
& 0xf) == 0xf) || (i
== number
- 1) ? '\n' : ' ');
828 PSDRV_WriteSpool(dc
, buf
, number
* 3);
830 HeapFree(PSDRV_Heap
, 0, buf
);
834 BOOL
PSDRV_WriteDIBits16(DC
*dc
, const WORD
*words
, int number
)
836 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
842 for(i
= 0; i
< number
; i
++) {
845 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
847 r
= words
[i
] >> 10 & 0x1f;
849 g
= words
[i
] >> 5 & 0x1f;
853 sprintf(ptr
, "%02x%02x%02x%c", r
, g
, b
,
854 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
857 PSDRV_WriteSpool(dc
, buf
, number
* 7);
859 HeapFree(PSDRV_Heap
, 0, buf
);
863 BOOL
PSDRV_WriteDIBits24(DC
*dc
, const BYTE
*bits
, int number
)
865 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
871 for(i
= 0; i
< number
; i
++) {
872 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
874 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
877 PSDRV_WriteSpool(dc
, buf
, number
* 7);
879 HeapFree(PSDRV_Heap
, 0, buf
);
883 BOOL
PSDRV_WriteDIBits32(DC
*dc
, const BYTE
*bits
, int number
)
885 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
891 for(i
= 0; i
< number
; i
++) {
892 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
894 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
897 PSDRV_WriteSpool(dc
, buf
, number
* 7);
899 HeapFree(PSDRV_Heap
, 0, buf
);
903 BOOL
PSDRV_WriteArrayGet(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
)
907 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
908 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
911 BOOL
PSDRV_WriteArrayPut(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
915 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
916 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
919 BOOL
PSDRV_WriteArrayDef(DC
*dc
, CHAR
*pszArrayName
, INT nSize
)
923 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
924 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
927 BOOL
PSDRV_WriteRectClip(DC
*dc
, INT x
, INT y
, INT w
, INT h
)
931 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
932 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
935 BOOL
PSDRV_WriteRectClip2(DC
*dc
, CHAR
*pszArrayName
)
939 sprintf(buf
, psrectclip2
, pszArrayName
);
940 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
943 BOOL
PSDRV_WritePatternDict(DC
*dc
, BITMAP
*bm
, BYTE
*bits
)
945 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
946 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
948 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
953 w
= bm
->bmWidth
& ~0x7;
954 h
= bm
->bmHeight
& ~0x7;
956 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
957 sprintf(buf
, start
, w
, h
, w
, h
);
958 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
959 PSDRV_WriteIndexColorSpaceBegin(dc
, 1);
960 map
[0] = dc
->w
.textColor
;
961 map
[1] = dc
->w
.backgroundColor
;
962 PSDRV_WriteRGB(dc
, map
, 2);
963 PSDRV_WriteIndexColorSpaceEnd(dc
);
965 for(y
= h
-1; y
>= 0; y
--) {
966 for(x
= 0; x
< w
/8; x
++) {
967 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
971 PSDRV_WriteImageDict(dc
, 1, 0, 0, 8, 8, 8, 8, buf
);
972 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
973 HeapFree(PSDRV_Heap
, 0, buf
);