2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
38 static const char psheader
[] = /* title llx lly urx ury */
40 "%%%%Creator: Wine PostScript Driver\n"
42 "%%%%BoundingBox: %d %d %d %d\n"
43 "%%%%Pages: (atend)\n"
46 static const char psbeginprolog
[] =
49 static const char psendprolog
[] =
52 static const char psprolog
[] =
53 "/tmpmtrx matrix def\n"
56 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
57 " l cvi gap idiv gap mul\n"
59 " r cvi gap idiv gap mul\n"
60 " {t moveto 0 b t sub rlineto}\n"
63 "/B {pop pop pop pop} def\n"
65 "/havetype42gdir {version cvi 2015 ge} bind def\n";
67 static const char psbeginsetup
[] =
70 static const char psendsetup
[] =
73 static const char psbeginfeature
[] = /* feature, value */
75 "%%%%BeginFeature: %s %s\n";
77 static const char psendfeature
[] =
79 "} stopped cleartomark\n";
81 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
83 "%%%%BeginPageSetup\n"
85 "72 %d div 72 %d div scale\n"
91 static const char psendpage
[] =
95 static const char psfooter
[] = /* pages */
100 static const char psmoveto
[] = /* x, y */
103 static const char pslineto
[] = /* x, y */
106 static const char psstroke
[] =
109 static const char psrectangle
[] = /* x, y, width, height, -width */
116 static const char psglyphshow
[] = /* glyph name */
119 static const char pssetfont
[] = /* fontname, xx_scale, xy_scale, yx_scale, yy_scale, escapement */
121 "[%d %d %d %d 0 0]\n"
122 "%d 10 div matrix rotate\n"
123 "matrix concatmatrix\n"
124 "makefont setfont\n";
126 static const char pssetline
[] = /* width, join, endcap */
127 "%d setlinewidth %u setlinejoin %u setlinecap\n";
129 static const char pssetgray
[] = /* gray */
132 static const char pssetrgbcolor
[] = /* r, g, b */
133 "%.2f %.2f %.2f setrgbcolor\n";
135 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
136 "tmpmtrx currentmatrix pop\n"
139 "0 0 0.5 %.1f %.1f arc\n"
140 "tmpmtrx setmatrix\n";
142 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
143 "%d %d %d %d %d %d curveto\n";
145 static const char psgsave
[] =
148 static const char psgrestore
[] =
151 static const char psfill
[] =
154 static const char pseofill
[] =
157 static const char psnewpath
[] =
160 static const char psclosepath
[] =
163 static const char psclip
[] =
166 static const char pseoclip
[] =
169 static const char psrectclip
[] =
170 "%d %d %d %d rectclip\n";
172 static const char psrectclip2
[] =
175 static const char pshatch
[] =
178 static const char psrotate
[] = /* ang */
181 static const char psarrayput
[] =
184 static const char psarraydef
[] =
185 "/%s %d array def\n";
187 static const char psenddocument
[] =
190 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
192 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
193 int num
, num_left
= cch
;
195 if(physDev
->job
.quiet
) {
196 TRACE("ignoring output\n");
200 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
201 write_spool( dev
, psenddocument
, sizeof(psenddocument
)-1 );
202 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
205 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
206 if( !PSDRV_StartPage(dev
) )
211 num
= min(num_left
, 0x8000);
212 if(write_spool( dev
, lpData
, num
) != num
)
222 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
225 char *buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
226 strlen(feature
) + strlen(value
));
228 sprintf(buf
, psbeginfeature
, feature
, value
);
229 write_spool( dev
, buf
, strlen(buf
) );
230 write_spool( dev
, invocation
, strlen(invocation
) );
231 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
233 HeapFree( PSDRV_Heap
, 0, buf
);
237 /********************************************************
240 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
241 * as octal. If we've had to use an escape then surround the entire string
242 * in brackets. Truncate string to represent at most 0x80 characters.
245 static char *escape_title(LPCSTR str
)
252 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
257 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
265 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
271 extra
+= 2; /* two for the brackets */
272 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
274 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
278 BYTE b
= (BYTE
)str
[i
];
280 *cp
++ = ((b
>> 6) & 0x7) + '0';
281 *cp
++ = ((b
>> 3) & 0x7) + '0';
282 *cp
++ = ((b
) & 0x7) + '0';
293 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCSTR title
)
295 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
296 char *buf
, *escaped_title
;
301 int llx
, lly
, urx
, ury
;
303 TRACE("%s\n", debugstr_a(title
));
305 escaped_title
= escape_title(title
);
306 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
307 strlen(escaped_title
) + 30 );
309 WARN("HeapAlloc failed\n");
313 /* BBox co-ords are in default user co-ord system so urx < ury even in
315 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
316 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
317 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
318 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
319 /* FIXME should do something better with BBox */
321 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
);
323 HeapFree(GetProcessHeap(), 0, escaped_title
);
324 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
325 WARN("WriteSpool error\n");
326 HeapFree( PSDRV_Heap
, 0, buf
);
329 HeapFree( PSDRV_Heap
, 0, buf
);
331 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
332 write_spool( dev
, psprolog
, strlen(psprolog
) );
333 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
334 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
336 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1) {
337 char copies_buf
[100];
338 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
339 write_spool(dev
, copies_buf
, strlen(copies_buf
));
342 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
343 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmDefaultSource
) {
344 if(slot
->InvocationString
) {
345 PSDRV_WriteFeature(dev
, "*InputSlot", slot
->Name
,
346 slot
->InvocationString
);
352 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
353 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
354 if(page
->InvocationString
) {
355 PSDRV_WriteFeature(dev
, "*PageSize", page
->Name
,
356 page
->InvocationString
);
362 win_duplex
= physDev
->Devmode
->dmPublic
.dmFields
& DM_DUPLEX
?
363 physDev
->Devmode
->dmPublic
.dmDuplex
: 0;
364 for(duplex
= physDev
->pi
->ppd
->Duplexes
; duplex
; duplex
= duplex
->next
) {
365 if(duplex
->WinDuplex
== win_duplex
) {
366 if(duplex
->InvocationString
) {
367 PSDRV_WriteFeature(dev
, "*Duplex", duplex
->Name
,
368 duplex
->InvocationString
);
374 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
381 INT
PSDRV_WriteFooter( PHYSDEV dev
)
383 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
386 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
388 WARN("HeapAlloc failed\n");
392 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
394 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
395 WARN("WriteSpool error\n");
396 HeapFree( PSDRV_Heap
, 0, buf
);
399 HeapFree( PSDRV_Heap
, 0, buf
);
405 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
407 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
408 WARN("WriteSpool error\n");
417 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
419 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
422 signed int xtrans
, ytrans
, rotation
;
424 sprintf(name
, "%d", physDev
->job
.PageNo
);
426 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
428 WARN("HeapAlloc failed\n");
432 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
433 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
434 xtrans
= physDev
->ImageableArea
.right
;
435 ytrans
= physDev
->ImageableArea
.top
;
438 xtrans
= physDev
->ImageableArea
.left
;
439 ytrans
= physDev
->ImageableArea
.bottom
;
443 xtrans
= physDev
->ImageableArea
.left
;
444 ytrans
= physDev
->ImageableArea
.top
;
448 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
449 physDev
->logPixelsX
, physDev
->logPixelsY
,
450 xtrans
, ytrans
, rotation
);
452 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
453 WARN("WriteSpool error\n");
454 HeapFree( PSDRV_Heap
, 0, buf
);
457 HeapFree( PSDRV_Heap
, 0, buf
);
462 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
466 sprintf(buf
, psmoveto
, x
, y
);
467 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
470 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
474 sprintf(buf
, pslineto
, x
, y
);
475 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
479 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
481 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
486 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
491 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
492 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
495 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
500 /* Make angles -ve and swap order because we're working with an upside
502 push_lc_numeric("C");
503 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
505 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
508 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
512 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
513 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
517 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
)
521 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(pssetfont
) +
525 WARN("HeapAlloc failed\n");
529 sprintf(buf
, pssetfont
, name
, size
.xx
, size
.xy
, size
.yx
, size
.yy
, -escapement
);
531 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
532 HeapFree(PSDRV_Heap
, 0, buf
);
536 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
538 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
541 PSDRV_CopyColor(&physDev
->inkColor
, color
);
542 switch(color
->type
) {
544 push_lc_numeric("C");
545 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
548 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
551 push_lc_numeric("C");
552 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
554 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
557 ERR("Unkonwn colour type %d\n", color
->type
);
564 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
566 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
570 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
571 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
573 if (physDev
->pen
.dash_len
)
575 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
576 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
578 sprintf(buf
+ pos
, "] %u setdash\n", 0);
581 sprintf(buf
, "[] %u setdash\n", 0);
583 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
588 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
593 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
595 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
596 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
600 PSDRV_WriteSpool(dev
, buf
, l
);
604 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
606 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
609 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
611 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
614 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
616 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
619 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
621 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
624 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
626 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
629 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
631 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
634 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
636 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
639 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
641 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
644 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
646 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
649 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
653 push_lc_numeric("C");
654 sprintf(buf
, psrotate
, ang
);
656 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
659 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
662 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
663 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
666 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
668 static const char buf
[] = ">\n] setcolorspace\n";
669 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
672 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
674 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
678 for(i
= 0; i
< number
; i
++) {
679 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
680 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
681 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
684 PSDRV_WriteSpool(dev
, buf
, number
* 7);
685 HeapFree(PSDRV_Heap
, 0, buf
);
689 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
691 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
695 for(i
= 0; i
< number
; i
++, rgb
++)
696 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
697 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
699 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
700 HeapFree(PSDRV_Heap
, 0, buf
);
704 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
,
705 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
707 static const char start
[] = "<<\n"
708 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
709 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
711 static const char decode1
[] = " /Decode [0 %d]\n";
712 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
714 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
715 static const char endbits
[] = " /DataSource <%s>\n>>\n";
717 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
720 sprintf(buf
, start
, widthSrc
, heightSrc
,
721 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
723 sprintf(buf
, start
, widthSrc
, heightSrc
,
724 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
726 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
730 sprintf(buf
, decode1
, 255);
734 sprintf(buf
, decode1
, 15);
738 sprintf(buf
, decode1
, 1);
742 strcpy(buf
, decode3
);
746 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
749 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
751 sprintf(buf
, endbits
, bits
);
752 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
755 HeapFree(PSDRV_Heap
, 0, buf
);
759 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, INT xDst
, INT yDst
,
760 INT widthDst
, INT heightDst
, INT widthSrc
,
761 INT heightSrc
, BOOL mask
, BOOL top_down
)
763 static const char start
[] = "%d %d translate\n%d %d scale\n";
764 static const char image
[] = "image\n";
765 static const char imagemask
[] = "imagemask\n";
768 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
769 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
770 PSDRV_WriteImageDict(dev
, depth
, widthSrc
, heightSrc
, NULL
, top_down
);
772 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
774 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
779 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
781 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
787 for(i
= 0; i
< number
; i
++) {
788 sprintf(ptr
, "%02x", bytes
[i
]);
790 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
795 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
796 HeapFree(PSDRV_Heap
, 0, buf
);
800 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
802 int num
, num_left
= number
;
805 num
= min(num_left
, 60);
806 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
807 PSDRV_WriteSpool(dev
, "\n", 1);
815 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
819 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
820 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
823 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
827 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
828 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
831 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
835 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
836 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
839 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
843 sprintf(buf
, psrectclip2
, pszArrayName
);
844 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
847 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
849 static const char mypat
[] = "/mypat\n";
850 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
851 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
852 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
853 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
855 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
858 TRACE( "size %dx%dx%d\n",
859 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
861 if(bmi
->bmiHeader
.biBitCount
!= 1) {
862 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
866 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
867 h
= abs_height
& ~0x7;
869 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(do_pattern
) + 100);
871 for(y
= h
-1; y
>= 0; y
--) {
872 for(x
= 0; x
< w
/8; x
++) {
873 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
874 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
878 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
879 PSDRV_WriteImageDict(dev
, 1, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
880 PSDRV_WriteSpool(dev
, "def\n", 4);
882 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
883 map
[0] = GetTextColor( dev
->hdc
);
884 map
[1] = GetBkColor( dev
->hdc
);
885 PSDRV_WriteRGB(dev
, map
, 2);
886 PSDRV_WriteIndexColorSpaceEnd(dev
);
888 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
889 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
890 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
891 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
892 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
893 HeapFree(PSDRV_Heap
, 0, buf
);