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 */
116 static char psshow
[] = /* string */
120 static const char psglyphshow
[] = /* glyph name */
123 static char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
126 "%d 10 div matrix rotate\n"
127 "matrix concatmatrix\n"
128 "makefont setfont\n";
130 static char pssetlinewidth
[] = /* width */
133 static char pssetdash
[] = /* dash, offset */
136 static char pssetgray
[] = /* gray */
139 static char pssetrgbcolor
[] = /* r, g, b */
140 "%.2f %.2f %.2f setrgbcolor\n";
142 static char psarc
[] = /* x, y, w, h, ang1, ang2 */
143 "tmpmtrx currentmatrix pop\n"
146 "0 0 0.5 %.1f %.1f arc\n"
147 "tmpmtrx setmatrix\n";
149 static char psgsave
[] =
152 static char psgrestore
[] =
155 static char psfill
[] =
158 static char pseofill
[] =
161 static char psnewpath
[] =
164 static char psclosepath
[] =
167 static char psclip
[] =
170 static char psinitclip
[] =
173 static char pseoclip
[] =
176 static char psrectclip
[] =
177 "%d %d %d %d rectclip\n";
179 static char psrectclip2
[] =
182 static char pshatch
[] =
185 static char psrotate
[] = /* ang */
188 static char psarrayget
[] =
191 static char psarrayput
[] =
194 static char psarraydef
[] =
195 "/%s %d array def\n";
197 char *PSDRV_ANSIVector
[256] = {
198 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x00 */
199 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
200 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 0x10 */
201 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
202 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
203 "dollar", "percent", "ampersand", "quotesingle",
204 "parenleft", "parenright", "asterisk", "plus",
205 "comma", "hyphen", "period", "slash",
206 "zero", "one", "two", "three", /* 0x30 */
207 "four", "five", "six", "seven",
208 "eight", "nine", "colon", "semicolon",
209 "less", "equal", "greater", "question",
210 "at", "A", "B", "C", /* 0x40 */
214 "P", "Q", "R", "S", /* 0x50 */
216 "X", "Y", "Z", "bracketleft",
217 "backslash", "bracketright", "asciicircum", "underscore",
218 "grave", "a", "b", "c", /* 0x60 */
222 "p", "q", "r", "s", /* 0x70 */
224 "x", "y", "z", "braceleft",
225 "bar", "braceright", "asciitilde", NULL
,
226 NULL
, NULL
, NULL
, NULL
, /* 0x80 */
227 NULL
, NULL
, NULL
, NULL
,
228 NULL
, NULL
, NULL
, NULL
,
229 NULL
, NULL
, NULL
, NULL
,
230 NULL
, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
231 "quotedblright","bullet", "endash", "emdash",
232 NULL
, NULL
, NULL
, NULL
,
233 NULL
, NULL
, NULL
, NULL
,
234 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
235 "currency", "yen", "brokenbar", "section",
236 "dieresis", "copyright", "ordfeminine", "guillemotleft",
237 "logicalnot", "hyphen", "registered", "macron",
238 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
239 "acute", "mu", "paragraph", "periodcentered",
240 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
241 "onequarter", "onehalf", "threequarters","questiondown",
242 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
243 "Adieresis", "Aring", "AE", "Ccedilla",
244 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
245 "Igrave", "Iacute", "Icircumflex", "Idieresis",
246 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
247 "Ocircumflex", "Otilde", "Odieresis", "multiply",
248 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
249 "Udieresis", "Yacute", "Thorn", "germandbls",
250 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
251 "adieresis", "aring", "ae", "ccedilla",
252 "egrave", "eacute", "ecircumflex", "edieresis",
253 "igrave", "iacute", "icircumflex", "idieresis",
254 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
255 "ocircumflex", "otilde", "odieresis", "divide",
256 "oslash", "ugrave", "uacute", "ucircumflex",
257 "udieresis", "yacute", "thorn", "ydieresis"
261 char psreencodefont
[] = /* newfontname basefontname*/
262 "/%s /%s reencodefont\n";
265 int PSDRV_WriteSpool(DC
*dc
, LPSTR lpData
, WORD cch
)
267 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
269 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
270 if( !PSDRV_StartPage(dc
) )
273 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
277 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
281 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
282 strlen(feature
) + strlen(value
));
285 sprintf(buf
, psbeginfeature
, feature
, value
);
286 WriteSpool16( hJob
, buf
, strlen(buf
) );
288 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
290 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
292 HeapFree( PSDRV_Heap
, 0, buf
);
298 INT
PSDRV_WriteHeader( DC
*dc
, LPCSTR title
)
300 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
301 char *buf
, *orient
, vectbuf
[256];
304 int llx
, lly
, urx
, ury
, i
, j
;
306 TRACE("'%s'\n", title
);
308 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
309 strlen(title
) + 30 );
311 WARN("HeapAlloc failed\n");
315 /* BBox co-ords are in default user co-ord system so urx < ury even in
317 llx
= physDev
->PageSize
.left
* 72.0 / dc
->devCaps
->logPixelsX
;
318 lly
= physDev
->PageSize
.bottom
* 72.0 / dc
->devCaps
->logPixelsY
;
319 urx
= physDev
->PageSize
.right
* 72.0 / dc
->devCaps
->logPixelsX
;
320 ury
= physDev
->PageSize
.top
* 72.0 / dc
->devCaps
->logPixelsY
;
322 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
323 orient
= "Landscape";
328 /* FIXME should do something better with BBox */
330 sprintf(buf
, psheader
, title
, llx
, lly
, urx
, ury
, orient
);
332 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
334 WARN("WriteSpool error\n");
335 HeapFree( PSDRV_Heap
, 0, buf
);
338 HeapFree( PSDRV_Heap
, 0, buf
);
340 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
341 WriteSpool16( physDev
->job
.hJob
, psvectorstart
, strlen(psvectorstart
) );
343 for(i
= 0; i
< 256; i
+= 8) {
345 for(j
= 0; j
< 8; j
++) {
346 strcat(vectbuf
, "/");
347 if(PSDRV_ANSIVector
[i
+j
]) {
348 strcat(vectbuf
, PSDRV_ANSIVector
[i
+j
]);
349 strcat(vectbuf
, " ");
351 strcat(vectbuf
, ".notdef ");
354 strcat(vectbuf
, "\n");
355 WriteSpool16( physDev
->job
.hJob
, vectbuf
, strlen(vectbuf
) );
358 WriteSpool16( physDev
->job
.hJob
, psvectorend
, strlen(psvectorend
) );
359 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
360 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
363 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
365 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
366 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
367 if(slot
->InvocationString
) {
368 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
369 slot
->InvocationString
);
375 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
376 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
377 if(page
->InvocationString
) {
378 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
379 page
->InvocationString
);
385 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
392 INT
PSDRV_WriteFooter( DC
*dc
)
394 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
397 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
399 WARN("HeapAlloc failed\n");
403 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
405 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
407 WARN("WriteSpool error\n");
408 HeapFree( PSDRV_Heap
, 0, buf
);
411 HeapFree( PSDRV_Heap
, 0, buf
);
417 INT
PSDRV_WriteEndPage( DC
*dc
)
419 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
421 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
422 sizeof(psendpage
)-1 ) {
423 WARN("WriteSpool error\n");
432 INT
PSDRV_WriteNewPage( DC
*dc
)
434 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
437 signed int xtrans
, ytrans
, rotation
;
439 sprintf(name
, "%d", physDev
->job
.PageNo
);
441 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
443 WARN("HeapAlloc failed\n");
447 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
448 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
449 xtrans
= physDev
->PageSize
.right
;
450 ytrans
= physDev
->PageSize
.top
;
453 xtrans
= physDev
->PageSize
.left
;
454 ytrans
= physDev
->PageSize
.bottom
;
458 xtrans
= physDev
->PageSize
.left
;
459 ytrans
= physDev
->PageSize
.top
;
463 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
464 dc
->devCaps
->logPixelsX
, dc
->devCaps
->logPixelsY
,
465 xtrans
, ytrans
, rotation
);
467 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
469 WARN("WriteSpool error\n");
470 HeapFree( PSDRV_Heap
, 0, buf
);
473 HeapFree( PSDRV_Heap
, 0, buf
);
478 BOOL
PSDRV_WriteMoveTo(DC
*dc
, INT x
, INT y
)
482 sprintf(buf
, psmoveto
, x
, y
);
483 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
486 BOOL
PSDRV_WriteLineTo(DC
*dc
, INT x
, INT y
)
490 sprintf(buf
, pslineto
, x
, y
);
491 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
495 BOOL
PSDRV_WriteStroke(DC
*dc
)
497 return PSDRV_WriteSpool(dc
, psstroke
, sizeof(psstroke
)-1);
502 BOOL
PSDRV_WriteRectangle(DC
*dc
, INT x
, INT y
, INT width
,
507 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
508 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
511 BOOL
PSDRV_WriteRRectangle(DC
*dc
, INT x
, INT y
, INT width
,
516 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
517 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
520 BOOL
PSDRV_WriteArc(DC
*dc
, INT x
, INT y
, INT w
, INT h
, double ang1
,
525 /* Make angles -ve and swap order because we're working with an upside
527 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
528 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
531 static char encodingext
[] = "-ANSI";
533 BOOL
PSDRV_WriteSetFont(DC
*dc
, BOOL UseANSI
)
535 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
538 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
539 sizeof(pssetfont
) + strlen(physDev
->font
.afm
->FontName
) + 40);
542 WARN("HeapAlloc failed\n");
546 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
547 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
550 WARN("HeapAlloc failed\n");
551 HeapFree(PSDRV_Heap
, 0, buf
);
556 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
558 strcpy(newbuf
, physDev
->font
.afm
->FontName
);
560 sprintf(buf
, pssetfont
, newbuf
,
561 physDev
->font
.size
, -physDev
->font
.size
,
562 -physDev
->font
.escapement
);
564 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
565 HeapFree(PSDRV_Heap
, 0, buf
);
569 BOOL
PSDRV_WriteSetColor(DC
*dc
, PSCOLOR
*color
)
571 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
574 PSDRV_CopyColor(&physDev
->inkColor
, color
);
575 switch(color
->type
) {
577 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
579 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
582 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
583 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
586 ERR("Unkonwn colour type %d\n", color
->type
);
593 BOOL
PSDRV_WriteSetPen(DC
*dc
)
595 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
598 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
599 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
601 if(physDev
->pen
.dash
) {
602 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
603 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
609 BOOL
PSDRV_WriteReencodeFont(DC
*dc
)
611 PSDRV_PDEVICE
*physDev
= (PSDRV_PDEVICE
*)dc
->physDev
;
614 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
615 sizeof(psreencodefont
) + 2 * strlen(physDev
->font
.afm
->FontName
)
616 + sizeof(encodingext
));
619 WARN("HeapAlloc failed\n");
623 newbuf
= (char *)HeapAlloc( PSDRV_Heap
, 0,
624 strlen(physDev
->font
.afm
->FontName
) + sizeof(encodingext
));
627 WARN("HeapAlloc failed\n");
628 HeapFree(PSDRV_Heap
, 0, buf
);
632 sprintf(newbuf
, "%s%s", physDev
->font
.afm
->FontName
, encodingext
);
633 sprintf(buf
, psreencodefont
, newbuf
, physDev
->font
.afm
->FontName
);
635 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
637 HeapFree(PSDRV_Heap
, 0, newbuf
);
638 HeapFree(PSDRV_Heap
, 0, buf
);
643 BOOL
PSDRV_WriteShow(DC
*dc
, LPCWSTR str
, INT count
)
646 INT buflen
= count
+ 10, i
, done
;
648 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, buflen
);
650 for(i
= done
= 0; i
< count
; i
++) {
651 char c
= PSDRV_UnicodeToANSI(str
[i
]);
653 if(done
+ 4 >= buflen
)
654 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
655 sprintf(buf
+ done
, "\\%03o", (int)(unsigned char)c
);
657 } else if(c
== '\\' || c
== '(' || c
== ')' ) {
658 if(done
+ 2 >= buflen
)
659 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
663 if(done
+ 1 >= buflen
)
664 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, buflen
+= 10 );
670 buf1
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psshow
) + done
);
672 sprintf(buf1
, psshow
, buf
);
674 PSDRV_WriteSpool(dc
, buf1
, strlen(buf1
));
675 HeapFree(PSDRV_Heap
, 0, buf
);
676 HeapFree(PSDRV_Heap
, 0, buf1
);
682 BOOL
PSDRV_WriteShow(DC
*dc
, LPCWSTR str
, INT count
)
687 for (i
= 0; i
< count
; ++i
)
692 name
= PSDRV_UVMetrics(str
[i
],
693 ((PSDRV_PDEVICE
*)dc
->physDev
)->font
.afm
)->N
->sz
;
694 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, name
);
696 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1)
698 WARN("Unusable glyph name '%s' - ignoring\n", name
);
702 PSDRV_WriteSpool(dc
, buf
, l
);
708 BOOL
PSDRV_WriteFill(DC
*dc
)
710 return PSDRV_WriteSpool(dc
, psfill
, sizeof(psfill
)-1);
713 BOOL
PSDRV_WriteEOFill(DC
*dc
)
715 return PSDRV_WriteSpool(dc
, pseofill
, sizeof(pseofill
)-1);
718 BOOL
PSDRV_WriteGSave(DC
*dc
)
720 return PSDRV_WriteSpool(dc
, psgsave
, sizeof(psgsave
)-1);
723 BOOL
PSDRV_WriteGRestore(DC
*dc
)
725 return PSDRV_WriteSpool(dc
, psgrestore
, sizeof(psgrestore
)-1);
728 BOOL
PSDRV_WriteNewPath(DC
*dc
)
730 return PSDRV_WriteSpool(dc
, psnewpath
, sizeof(psnewpath
)-1);
733 BOOL
PSDRV_WriteClosePath(DC
*dc
)
735 return PSDRV_WriteSpool(dc
, psclosepath
, sizeof(psclosepath
)-1);
738 BOOL
PSDRV_WriteClip(DC
*dc
)
740 return PSDRV_WriteSpool(dc
, psclip
, sizeof(psclip
)-1);
743 BOOL
PSDRV_WriteEOClip(DC
*dc
)
745 return PSDRV_WriteSpool(dc
, pseoclip
, sizeof(pseoclip
)-1);
748 BOOL
PSDRV_WriteInitClip(DC
*dc
)
750 return PSDRV_WriteSpool(dc
, psinitclip
, sizeof(psinitclip
)-1);
753 BOOL
PSDRV_WriteHatch(DC
*dc
)
755 return PSDRV_WriteSpool(dc
, pshatch
, sizeof(pshatch
)-1);
758 BOOL
PSDRV_WriteRotate(DC
*dc
, float ang
)
762 sprintf(buf
, psrotate
, ang
);
763 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
766 BOOL
PSDRV_WriteIndexColorSpaceBegin(DC
*dc
, int size
)
769 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
770 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
773 BOOL
PSDRV_WriteIndexColorSpaceEnd(DC
*dc
)
775 char buf
[] = ">\n] setcolorspace\n";
776 return PSDRV_WriteSpool(dc
, buf
, sizeof(buf
) - 1);
779 BOOL
PSDRV_WriteRGB(DC
*dc
, COLORREF
*map
, int number
)
781 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
785 for(i
= 0; i
< number
; i
++) {
786 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
787 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
788 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
791 PSDRV_WriteSpool(dc
, buf
, number
* 7);
792 HeapFree(PSDRV_Heap
, 0, buf
);
797 BOOL
PSDRV_WriteImageDict(DC
*dc
, WORD depth
, INT xDst
, INT yDst
,
798 INT widthDst
, INT heightDst
, INT widthSrc
,
799 INT heightSrc
, char *bits
)
801 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
802 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
803 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
805 char decode1
[] = " /Decode [0 %d]\n";
806 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
808 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
809 char endbits
[] = " /DataSource <%s>\n>> image\n";
811 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
813 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
814 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
816 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
820 sprintf(buf
, decode1
, 255);
824 sprintf(buf
, decode1
, 15);
828 sprintf(buf
, decode1
, 1);
832 strcpy(buf
, decode3
);
836 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
839 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
841 sprintf(buf
, endbits
, bits
);
842 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
845 HeapFree(PSDRV_Heap
, 0, buf
);
850 BOOL
PSDRV_WriteBytes(DC
*dc
, const BYTE
*bytes
, int number
)
852 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
858 for(i
= 0; i
< number
; i
++) {
859 sprintf(ptr
, "%02x%c", bytes
[i
],
860 ((i
& 0xf) == 0xf) || (i
== number
- 1) ? '\n' : ' ');
863 PSDRV_WriteSpool(dc
, buf
, number
* 3);
865 HeapFree(PSDRV_Heap
, 0, buf
);
869 BOOL
PSDRV_WriteDIBits16(DC
*dc
, const WORD
*words
, int number
)
871 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
877 for(i
= 0; i
< number
; i
++) {
880 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
882 r
= words
[i
] >> 10 & 0x1f;
884 g
= words
[i
] >> 5 & 0x1f;
888 sprintf(ptr
, "%02x%02x%02x%c", r
, g
, b
,
889 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
892 PSDRV_WriteSpool(dc
, buf
, number
* 7);
894 HeapFree(PSDRV_Heap
, 0, buf
);
898 BOOL
PSDRV_WriteDIBits24(DC
*dc
, const BYTE
*bits
, int number
)
900 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
906 for(i
= 0; i
< number
; i
++) {
907 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
909 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
912 PSDRV_WriteSpool(dc
, buf
, number
* 7);
914 HeapFree(PSDRV_Heap
, 0, buf
);
918 BOOL
PSDRV_WriteDIBits32(DC
*dc
, const BYTE
*bits
, int number
)
920 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
926 for(i
= 0; i
< number
; i
++) {
927 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
929 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
932 PSDRV_WriteSpool(dc
, buf
, number
* 7);
934 HeapFree(PSDRV_Heap
, 0, buf
);
938 BOOL
PSDRV_WriteArrayGet(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
)
942 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
943 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
946 BOOL
PSDRV_WriteArrayPut(DC
*dc
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
950 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
951 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
954 BOOL
PSDRV_WriteArrayDef(DC
*dc
, CHAR
*pszArrayName
, INT nSize
)
958 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
959 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
962 BOOL
PSDRV_WriteRectClip(DC
*dc
, INT x
, INT y
, INT w
, INT h
)
966 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
967 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
970 BOOL
PSDRV_WriteRectClip2(DC
*dc
, CHAR
*pszArrayName
)
974 sprintf(buf
, psrectclip2
, pszArrayName
);
975 return PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
978 BOOL
PSDRV_WritePatternDict(DC
*dc
, BITMAP
*bm
, BYTE
*bits
)
980 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
981 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
983 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
988 w
= bm
->bmWidth
& ~0x7;
989 h
= bm
->bmHeight
& ~0x7;
991 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
992 sprintf(buf
, start
, w
, h
, w
, h
);
993 PSDRV_WriteSpool(dc
, buf
, strlen(buf
));
994 PSDRV_WriteIndexColorSpaceBegin(dc
, 1);
995 map
[0] = dc
->textColor
;
996 map
[1] = dc
->backgroundColor
;
997 PSDRV_WriteRGB(dc
, map
, 2);
998 PSDRV_WriteIndexColorSpaceEnd(dc
);
1000 for(y
= h
-1; y
>= 0; y
--) {
1001 for(x
= 0; x
< w
/8; x
++) {
1002 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
1006 PSDRV_WriteImageDict(dc
, 1, 0, 0, 8, 8, 8, 8, buf
);
1007 PSDRV_WriteSpool(dc
, end
, sizeof(end
) - 1);
1008 HeapFree(PSDRV_Heap
, 0, buf
);