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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
34 static const char psheader
[] = /* title llx lly urx ury */
36 "%%%%Creator: Wine PostScript Driver\n"
38 "%%%%BoundingBox: %d %d %d %d\n"
39 "%%%%Pages: (atend)\n"
42 static const char psbeginprolog
[] =
45 static const char psendprolog
[] =
48 static const char psprolog
[] =
49 "/tmpmtrx matrix def\n"
52 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
53 " l cvi gap idiv gap mul\n"
55 " r cvi gap idiv gap mul\n"
56 " {t moveto 0 b t sub rlineto}\n"
59 "/B {pop pop pop pop} def\n"
60 "/havetype42gdir {version cvi 2015 ge} bind def\n";
62 static const char psbeginsetup
[] =
65 static const char psendsetup
[] =
68 static const char psbeginfeature
[] = /* feature, value */
70 "%%%%BeginFeature: %s %s\n";
72 static const char psendfeature
[] =
74 "} stopped cleartomark\n";
76 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
78 "%%%%BeginPageSetup\n"
80 "72 %d div 72 %d div scale\n"
86 static const char psendpage
[] =
90 static const char psfooter
[] = /* pages */
95 static const char psmoveto
[] = /* x, y */
98 static const char pslineto
[] = /* x, y */
101 static const char psstroke
[] =
104 static const char psrectangle
[] = /* x, y, width, height, -width */
111 static const char psrrectangle
[] = /* x, y, width, height, -width */
118 static const char psglyphshow
[] = /* glyph name */
121 static const char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
124 "%d 10 div matrix rotate\n"
125 "matrix concatmatrix\n"
126 "makefont setfont\n";
128 static const char pssetlinewidth
[] = /* width */
131 static const char pssetdash
[] = /* dash, offset */
134 static const char pssetgray
[] = /* gray */
137 static const char pssetrgbcolor
[] = /* r, g, b */
138 "%.2f %.2f %.2f setrgbcolor\n";
140 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
141 "tmpmtrx currentmatrix pop\n"
144 "0 0 0.5 %.1f %.1f arc\n"
145 "tmpmtrx setmatrix\n";
147 static const char psgsave
[] =
150 static const char psgrestore
[] =
153 static const char psfill
[] =
156 static const char pseofill
[] =
159 static const char psnewpath
[] =
162 static const char psclosepath
[] =
165 static const char psclip
[] =
168 static const char psinitclip
[] =
171 static const char pseoclip
[] =
174 static const char psrectclip
[] =
175 "%d %d %d %d rectclip\n";
177 static const char psrectclip2
[] =
180 static const char pshatch
[] =
183 static const char psrotate
[] = /* ang */
186 static const char psarrayget
[] =
189 static const char psarrayput
[] =
192 static const char psarraydef
[] =
193 "/%s %d array def\n";
196 DWORD
PSDRV_WriteSpool(PSDRV_PDEVICE
*physDev
, LPCSTR lpData
, DWORD cch
)
198 int num
, num_left
= cch
;
200 if(physDev
->job
.quiet
) {
201 TRACE("ignoring output\n");
205 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
206 if( !PSDRV_StartPage(physDev
) )
211 num
= min(num_left
, 0x8000);
212 if(WriteSpool16( physDev
->job
.hJob
, (LPSTR
)lpData
, num
) != num
)
222 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
226 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
227 strlen(feature
) + strlen(value
));
230 sprintf(buf
, psbeginfeature
, feature
, value
);
231 WriteSpool16( hJob
, buf
, strlen(buf
) );
233 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
235 WriteSpool16( hJob
, (LPSTR
)psendfeature
, strlen(psendfeature
) );
237 HeapFree( PSDRV_Heap
, 0, buf
);
243 INT
PSDRV_WriteHeader( PSDRV_PDEVICE
*physDev
, LPCSTR title
)
250 int llx
, lly
, urx
, ury
;
252 TRACE("'%s'\n", debugstr_a(title
));
254 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
255 (title
? strlen(title
) : 0) + 30 );
257 WARN("HeapAlloc failed\n");
261 /* BBox co-ords are in default user co-ord system so urx < ury even in
263 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
264 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
265 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
266 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
267 /* FIXME should do something better with BBox */
269 sprintf(buf
, psheader
, title
? title
: "", llx
, lly
, urx
, ury
);
271 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
273 WARN("WriteSpool error\n");
274 HeapFree( PSDRV_Heap
, 0, buf
);
277 HeapFree( PSDRV_Heap
, 0, buf
);
279 WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psbeginprolog
, strlen(psbeginprolog
) );
280 WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psprolog
, strlen(psprolog
) );
281 WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psendprolog
, strlen(psendprolog
) );
283 WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psbeginsetup
, strlen(psbeginsetup
) );
285 if(physDev
->Devmode
->dmPublic
.dmCopies
> 1) {
286 char copies_buf
[100];
287 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.dmCopies
);
288 WriteSpool16(physDev
->job
.hJob
, copies_buf
, strlen(copies_buf
));
291 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
292 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
293 if(slot
->InvocationString
) {
294 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
295 slot
->InvocationString
);
301 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
302 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
303 if(page
->InvocationString
) {
304 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
305 page
->InvocationString
);
311 win_duplex
= physDev
->Devmode
->dmPublic
.dmFields
& DM_DUPLEX
?
312 physDev
->Devmode
->dmPublic
.dmDuplex
: 0;
313 for(duplex
= physDev
->pi
->ppd
->Duplexes
; duplex
; duplex
= duplex
->next
) {
314 if(duplex
->WinDuplex
== win_duplex
) {
315 if(duplex
->InvocationString
) {
316 PSDRV_WriteFeature(physDev
->job
.hJob
, "*Duplex", duplex
->Name
,
317 duplex
->InvocationString
);
323 WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psendsetup
, strlen(psendsetup
) );
330 INT
PSDRV_WriteFooter( PSDRV_PDEVICE
*physDev
)
334 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
336 WARN("HeapAlloc failed\n");
340 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
342 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
344 WARN("WriteSpool error\n");
345 HeapFree( PSDRV_Heap
, 0, buf
);
348 HeapFree( PSDRV_Heap
, 0, buf
);
354 INT
PSDRV_WriteEndPage( PSDRV_PDEVICE
*physDev
)
356 if( WriteSpool16( physDev
->job
.hJob
, (LPSTR
)psendpage
, sizeof(psendpage
)-1 ) !=
357 sizeof(psendpage
)-1 ) {
358 WARN("WriteSpool error\n");
367 INT
PSDRV_WriteNewPage( PSDRV_PDEVICE
*physDev
)
371 signed int xtrans
, ytrans
, rotation
;
373 sprintf(name
, "%d", physDev
->job
.PageNo
);
375 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
377 WARN("HeapAlloc failed\n");
381 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
382 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
383 xtrans
= physDev
->ImageableArea
.right
;
384 ytrans
= physDev
->ImageableArea
.top
;
387 xtrans
= physDev
->ImageableArea
.left
;
388 ytrans
= physDev
->ImageableArea
.bottom
;
392 xtrans
= physDev
->ImageableArea
.left
;
393 ytrans
= physDev
->ImageableArea
.top
;
397 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
398 physDev
->logPixelsX
, physDev
->logPixelsY
,
399 xtrans
, ytrans
, rotation
);
401 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
403 WARN("WriteSpool error\n");
404 HeapFree( PSDRV_Heap
, 0, buf
);
407 HeapFree( PSDRV_Heap
, 0, buf
);
412 BOOL
PSDRV_WriteMoveTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
416 sprintf(buf
, psmoveto
, x
, y
);
417 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
420 BOOL
PSDRV_WriteLineTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
424 sprintf(buf
, pslineto
, x
, y
);
425 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
429 BOOL
PSDRV_WriteStroke(PSDRV_PDEVICE
*physDev
)
431 return PSDRV_WriteSpool(physDev
, psstroke
, sizeof(psstroke
)-1);
436 BOOL
PSDRV_WriteRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
441 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
442 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
445 BOOL
PSDRV_WriteRRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
450 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
451 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
454 BOOL
PSDRV_WriteArc(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
459 /* Make angles -ve and swap order because we're working with an upside
461 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
462 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
466 BOOL
PSDRV_WriteSetFont(PSDRV_PDEVICE
*physDev
, const char *name
, INT size
, INT escapement
)
470 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(pssetfont
) +
474 WARN("HeapAlloc failed\n");
478 sprintf(buf
, pssetfont
, name
, size
, -size
, -escapement
);
480 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
481 HeapFree(PSDRV_Heap
, 0, buf
);
485 BOOL
PSDRV_WriteSetColor(PSDRV_PDEVICE
*physDev
, PSCOLOR
*color
)
489 PSDRV_CopyColor(&physDev
->inkColor
, color
);
490 switch(color
->type
) {
492 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
494 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
497 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
498 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
501 ERR("Unkonwn colour type %d\n", color
->type
);
508 BOOL
PSDRV_WriteSetPen(PSDRV_PDEVICE
*physDev
)
512 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
513 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
515 if(physDev
->pen
.dash
) {
516 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
517 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
523 BOOL
PSDRV_WriteGlyphShow(PSDRV_PDEVICE
*physDev
, LPCSTR g_name
)
528 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
530 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
531 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
535 PSDRV_WriteSpool(physDev
, buf
, l
);
539 BOOL
PSDRV_WriteFill(PSDRV_PDEVICE
*physDev
)
541 return PSDRV_WriteSpool(physDev
, psfill
, sizeof(psfill
)-1);
544 BOOL
PSDRV_WriteEOFill(PSDRV_PDEVICE
*physDev
)
546 return PSDRV_WriteSpool(physDev
, pseofill
, sizeof(pseofill
)-1);
549 BOOL
PSDRV_WriteGSave(PSDRV_PDEVICE
*physDev
)
551 return PSDRV_WriteSpool(physDev
, psgsave
, sizeof(psgsave
)-1);
554 BOOL
PSDRV_WriteGRestore(PSDRV_PDEVICE
*physDev
)
556 return PSDRV_WriteSpool(physDev
, psgrestore
, sizeof(psgrestore
)-1);
559 BOOL
PSDRV_WriteNewPath(PSDRV_PDEVICE
*physDev
)
561 return PSDRV_WriteSpool(physDev
, psnewpath
, sizeof(psnewpath
)-1);
564 BOOL
PSDRV_WriteClosePath(PSDRV_PDEVICE
*physDev
)
566 return PSDRV_WriteSpool(physDev
, psclosepath
, sizeof(psclosepath
)-1);
569 BOOL
PSDRV_WriteClip(PSDRV_PDEVICE
*physDev
)
571 return PSDRV_WriteSpool(physDev
, psclip
, sizeof(psclip
)-1);
574 BOOL
PSDRV_WriteEOClip(PSDRV_PDEVICE
*physDev
)
576 return PSDRV_WriteSpool(physDev
, pseoclip
, sizeof(pseoclip
)-1);
579 BOOL
PSDRV_WriteInitClip(PSDRV_PDEVICE
*physDev
)
581 return PSDRV_WriteSpool(physDev
, psinitclip
, sizeof(psinitclip
)-1);
584 BOOL
PSDRV_WriteHatch(PSDRV_PDEVICE
*physDev
)
586 return PSDRV_WriteSpool(physDev
, pshatch
, sizeof(pshatch
)-1);
589 BOOL
PSDRV_WriteRotate(PSDRV_PDEVICE
*physDev
, float ang
)
593 sprintf(buf
, psrotate
, ang
);
594 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
597 BOOL
PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE
*physDev
, int size
)
600 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
601 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
604 BOOL
PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE
*physDev
)
606 char buf
[] = ">\n] setcolorspace\n";
607 return PSDRV_WriteSpool(physDev
, buf
, sizeof(buf
) - 1);
610 BOOL
PSDRV_WriteRGB(PSDRV_PDEVICE
*physDev
, COLORREF
*map
, int number
)
612 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
616 for(i
= 0; i
< number
; i
++) {
617 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
618 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
619 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
622 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
623 HeapFree(PSDRV_Heap
, 0, buf
);
628 BOOL
PSDRV_WriteImageDict(PSDRV_PDEVICE
*physDev
, WORD depth
, INT xDst
, INT yDst
,
629 INT widthDst
, INT heightDst
, INT widthSrc
,
630 INT heightSrc
, char *bits
, BOOL mask
)
632 const char start
[] = "%d %d translate\n%d %d scale\n<<\n"
633 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
634 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
636 const char decode1
[] = " /Decode [0 %d]\n";
637 const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
639 const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> image\n";
640 const char endmask
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> imagemask\n";
642 const char endbits
[] = " /DataSource <%s>\n>> image\n";
644 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
646 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
647 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
649 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
653 sprintf(buf
, decode1
, 255);
657 sprintf(buf
, decode1
, 15);
661 sprintf(buf
, decode1
, 1);
665 strcpy(buf
, decode3
);
669 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
673 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
675 PSDRV_WriteSpool(physDev
, endmask
, sizeof(endmask
) - 1);
677 sprintf(buf
, endbits
, bits
);
678 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
681 HeapFree(PSDRV_Heap
, 0, buf
);
686 BOOL
PSDRV_WriteBytes(PSDRV_PDEVICE
*physDev
, const BYTE
*bytes
, DWORD number
)
688 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
694 for(i
= 0; i
< number
; i
++) {
695 sprintf(ptr
, "%02x", bytes
[i
]);
697 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
702 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
703 HeapFree(PSDRV_Heap
, 0, buf
);
707 BOOL
PSDRV_WriteData(PSDRV_PDEVICE
*physDev
, const BYTE
*data
, DWORD number
)
709 int num
, num_left
= number
;
712 num
= min(num_left
, 60);
713 PSDRV_WriteSpool(physDev
, data
, num
);
714 PSDRV_WriteSpool(physDev
, "\n", 1);
722 BOOL
PSDRV_WriteArrayGet(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
)
726 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
727 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
730 BOOL
PSDRV_WriteArrayPut(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
734 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
735 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
738 BOOL
PSDRV_WriteArrayDef(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nSize
)
742 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
743 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
746 BOOL
PSDRV_WriteRectClip(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
)
750 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
751 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
754 BOOL
PSDRV_WriteRectClip2(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
)
758 sprintf(buf
, psrectclip2
, pszArrayName
);
759 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
762 BOOL
PSDRV_WritePatternDict(PSDRV_PDEVICE
*physDev
, BITMAP
*bm
, BYTE
*bits
)
764 const char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
765 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
767 const char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
772 w
= bm
->bmWidth
& ~0x7;
773 h
= bm
->bmHeight
& ~0x7;
775 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
776 sprintf(buf
, start
, w
, h
, w
, h
);
777 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
778 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
779 map
[0] = GetTextColor( physDev
->hdc
);
780 map
[1] = GetBkColor( physDev
->hdc
);
781 PSDRV_WriteRGB(physDev
, map
, 2);
782 PSDRV_WriteIndexColorSpaceEnd(physDev
);
784 for(y
= h
-1; y
>= 0; y
--) {
785 for(x
= 0; x
< w
/8; x
++) {
786 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
790 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
, FALSE
);
791 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
792 HeapFree(PSDRV_Heap
, 0, buf
);
796 BOOL
PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE
*physDev
, BITMAPINFO
*bmi
, UINT usage
)
798 const char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
799 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
801 const char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
804 INT w
, h
, x
, y
, colours
;
807 if(bmi
->bmiHeader
.biBitCount
!= 1) {
808 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
812 bits
= (char*)bmi
+ bmi
->bmiHeader
.biSize
;
813 colours
= bmi
->bmiHeader
.biClrUsed
;
814 if(!colours
&& bmi
->bmiHeader
.biBitCount
<= 8)
815 colours
= 1 << bmi
->bmiHeader
.biBitCount
;
816 bits
+= colours
* ((usage
== DIB_RGB_COLORS
) ?
817 sizeof(RGBQUAD
) : sizeof(WORD
));
819 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
820 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
822 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
823 sprintf(buf
, start
, w
, h
, w
, h
);
824 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
825 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
826 map
[0] = physDev
->dc
->textColor
;
827 map
[1] = physDev
->dc
->backgroundColor
;
828 PSDRV_WriteRGB(physDev
, map
, 2);
829 PSDRV_WriteIndexColorSpaceEnd(physDev
);
831 for(y
= h
-1; y
>= 0; y
--) {
832 for(x
= 0; x
< w
/8; x
++) {
833 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
834 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
838 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
, FALSE
);
839 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
840 HeapFree(PSDRV_Heap
, 0, buf
);