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 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 char psbeginprolog
[] =
45 static char psendprolog
[] =
48 static 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 char psbeginsetup
[] =
65 static char psendsetup
[] =
68 static char psbeginfeature
[] = /* feature, value */
70 "%%%%BeginFeature: %s %s\n";
72 static char psendfeature
[] =
74 "} stopped cleartomark\n";
76 static char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
78 "%%%%BeginPageSetup\n"
80 "72 %d div 72 %d div scale\n"
86 static char psendpage
[] =
90 static char psfooter
[] = /* pages */
95 static char psmoveto
[] = /* x, y */
98 static char pslineto
[] = /* x, y */
101 static char psstroke
[] =
104 static char psrectangle
[] = /* x, y, width, height, -width */
111 static char psrrectangle
[] = /* x, y, width, height, -width */
118 static const char psglyphshow
[] = /* glyph name */
121 static char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
124 "%d 10 div matrix rotate\n"
125 "matrix concatmatrix\n"
126 "makefont setfont\n";
128 static char pssetlinewidth
[] = /* width */
131 static char pssetdash
[] = /* dash, offset */
134 static char pssetgray
[] = /* gray */
137 static char pssetrgbcolor
[] = /* r, g, b */
138 "%.2f %.2f %.2f setrgbcolor\n";
140 static 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 char psgsave
[] =
150 static char psgrestore
[] =
153 static char psfill
[] =
156 static char pseofill
[] =
159 static char psnewpath
[] =
162 static char psclosepath
[] =
165 static char psclip
[] =
168 static char psinitclip
[] =
171 static char pseoclip
[] =
174 static char psrectclip
[] =
175 "%d %d %d %d rectclip\n";
177 static char psrectclip2
[] =
180 static char pshatch
[] =
183 static char psrotate
[] = /* ang */
186 static char psarrayget
[] =
189 static char psarrayput
[] =
192 static char psarraydef
[] =
193 "/%s %d array def\n";
196 int PSDRV_WriteSpool(PSDRV_PDEVICE
*physDev
, LPSTR lpData
, WORD cch
)
198 if(physDev
->job
.quiet
) {
199 TRACE("ignoring output\n");
203 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
204 if( !PSDRV_StartPage(physDev
) )
207 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
211 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
215 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
216 strlen(feature
) + strlen(value
));
219 sprintf(buf
, psbeginfeature
, feature
, value
);
220 WriteSpool16( hJob
, buf
, strlen(buf
) );
222 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
224 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
226 HeapFree( PSDRV_Heap
, 0, buf
);
232 INT
PSDRV_WriteHeader( PSDRV_PDEVICE
*physDev
, LPCSTR title
)
237 int llx
, lly
, urx
, ury
;
239 TRACE("'%s'\n", debugstr_a(title
));
241 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
242 (title
? strlen(title
) : 0) + 30 );
244 WARN("HeapAlloc failed\n");
248 /* BBox co-ords are in default user co-ord system so urx < ury even in
250 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
251 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
252 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
253 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
254 /* FIXME should do something better with BBox */
256 sprintf(buf
, psheader
, title
? title
: "", llx
, lly
, urx
, ury
);
258 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
260 WARN("WriteSpool error\n");
261 HeapFree( PSDRV_Heap
, 0, buf
);
264 HeapFree( PSDRV_Heap
, 0, buf
);
266 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
267 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
268 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
270 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
272 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
273 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
274 if(slot
->InvocationString
) {
275 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
276 slot
->InvocationString
);
282 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
283 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
284 if(page
->InvocationString
) {
285 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
286 page
->InvocationString
);
292 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
299 INT
PSDRV_WriteFooter( PSDRV_PDEVICE
*physDev
)
303 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
305 WARN("HeapAlloc failed\n");
309 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
311 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
313 WARN("WriteSpool error\n");
314 HeapFree( PSDRV_Heap
, 0, buf
);
317 HeapFree( PSDRV_Heap
, 0, buf
);
323 INT
PSDRV_WriteEndPage( PSDRV_PDEVICE
*physDev
)
325 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
326 sizeof(psendpage
)-1 ) {
327 WARN("WriteSpool error\n");
336 INT
PSDRV_WriteNewPage( PSDRV_PDEVICE
*physDev
)
340 signed int xtrans
, ytrans
, rotation
;
342 sprintf(name
, "%d", physDev
->job
.PageNo
);
344 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
346 WARN("HeapAlloc failed\n");
350 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
351 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
352 xtrans
= physDev
->ImageableArea
.right
;
353 ytrans
= physDev
->ImageableArea
.top
;
356 xtrans
= physDev
->ImageableArea
.left
;
357 ytrans
= physDev
->ImageableArea
.bottom
;
361 xtrans
= physDev
->ImageableArea
.left
;
362 ytrans
= physDev
->ImageableArea
.top
;
366 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
367 physDev
->logPixelsX
, physDev
->logPixelsY
,
368 xtrans
, ytrans
, rotation
);
370 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
372 WARN("WriteSpool error\n");
373 HeapFree( PSDRV_Heap
, 0, buf
);
376 HeapFree( PSDRV_Heap
, 0, buf
);
381 BOOL
PSDRV_WriteMoveTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
385 sprintf(buf
, psmoveto
, x
, y
);
386 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
389 BOOL
PSDRV_WriteLineTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
393 sprintf(buf
, pslineto
, x
, y
);
394 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
398 BOOL
PSDRV_WriteStroke(PSDRV_PDEVICE
*physDev
)
400 return PSDRV_WriteSpool(physDev
, psstroke
, sizeof(psstroke
)-1);
405 BOOL
PSDRV_WriteRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
410 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
411 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
414 BOOL
PSDRV_WriteRRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
419 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
420 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
423 BOOL
PSDRV_WriteArc(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
428 /* Make angles -ve and swap order because we're working with an upside
430 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
431 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
435 BOOL
PSDRV_WriteSetFont(PSDRV_PDEVICE
*physDev
, const char *name
, INT size
, INT escapement
)
439 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(pssetfont
) +
443 WARN("HeapAlloc failed\n");
447 sprintf(buf
, pssetfont
, name
, size
, -size
, -escapement
);
449 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
450 HeapFree(PSDRV_Heap
, 0, buf
);
454 BOOL
PSDRV_WriteSetColor(PSDRV_PDEVICE
*physDev
, PSCOLOR
*color
)
458 PSDRV_CopyColor(&physDev
->inkColor
, color
);
459 switch(color
->type
) {
461 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
463 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
466 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
467 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
470 ERR("Unkonwn colour type %d\n", color
->type
);
477 BOOL
PSDRV_WriteSetPen(PSDRV_PDEVICE
*physDev
)
481 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
482 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
484 if(physDev
->pen
.dash
) {
485 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
486 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
492 BOOL
PSDRV_WriteGlyphShow(PSDRV_PDEVICE
*physDev
, LPCSTR g_name
)
497 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
499 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
500 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
504 PSDRV_WriteSpool(physDev
, buf
, l
);
508 BOOL
PSDRV_WriteFill(PSDRV_PDEVICE
*physDev
)
510 return PSDRV_WriteSpool(physDev
, psfill
, sizeof(psfill
)-1);
513 BOOL
PSDRV_WriteEOFill(PSDRV_PDEVICE
*physDev
)
515 return PSDRV_WriteSpool(physDev
, pseofill
, sizeof(pseofill
)-1);
518 BOOL
PSDRV_WriteGSave(PSDRV_PDEVICE
*physDev
)
520 return PSDRV_WriteSpool(physDev
, psgsave
, sizeof(psgsave
)-1);
523 BOOL
PSDRV_WriteGRestore(PSDRV_PDEVICE
*physDev
)
525 return PSDRV_WriteSpool(physDev
, psgrestore
, sizeof(psgrestore
)-1);
528 BOOL
PSDRV_WriteNewPath(PSDRV_PDEVICE
*physDev
)
530 return PSDRV_WriteSpool(physDev
, psnewpath
, sizeof(psnewpath
)-1);
533 BOOL
PSDRV_WriteClosePath(PSDRV_PDEVICE
*physDev
)
535 return PSDRV_WriteSpool(physDev
, psclosepath
, sizeof(psclosepath
)-1);
538 BOOL
PSDRV_WriteClip(PSDRV_PDEVICE
*physDev
)
540 return PSDRV_WriteSpool(physDev
, psclip
, sizeof(psclip
)-1);
543 BOOL
PSDRV_WriteEOClip(PSDRV_PDEVICE
*physDev
)
545 return PSDRV_WriteSpool(physDev
, pseoclip
, sizeof(pseoclip
)-1);
548 BOOL
PSDRV_WriteInitClip(PSDRV_PDEVICE
*physDev
)
550 return PSDRV_WriteSpool(physDev
, psinitclip
, sizeof(psinitclip
)-1);
553 BOOL
PSDRV_WriteHatch(PSDRV_PDEVICE
*physDev
)
555 return PSDRV_WriteSpool(physDev
, pshatch
, sizeof(pshatch
)-1);
558 BOOL
PSDRV_WriteRotate(PSDRV_PDEVICE
*physDev
, float ang
)
562 sprintf(buf
, psrotate
, ang
);
563 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
566 BOOL
PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE
*physDev
, int size
)
569 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
570 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
573 BOOL
PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE
*physDev
)
575 char buf
[] = ">\n] setcolorspace\n";
576 return PSDRV_WriteSpool(physDev
, buf
, sizeof(buf
) - 1);
579 BOOL
PSDRV_WriteRGB(PSDRV_PDEVICE
*physDev
, COLORREF
*map
, int number
)
581 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
585 for(i
= 0; i
< number
; i
++) {
586 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
587 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
588 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
591 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
592 HeapFree(PSDRV_Heap
, 0, buf
);
597 BOOL
PSDRV_WriteImageDict(PSDRV_PDEVICE
*physDev
, WORD depth
, INT xDst
, INT yDst
,
598 INT widthDst
, INT heightDst
, INT widthSrc
,
599 INT heightSrc
, char *bits
, BOOL mask
)
601 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
602 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
603 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
605 char decode1
[] = " /Decode [0 %d]\n";
606 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
608 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
609 char endmask
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> imagemask\n";
611 char endbits
[] = " /DataSource <%s>\n>> image\n";
613 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
615 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
616 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
618 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
622 sprintf(buf
, decode1
, 255);
626 sprintf(buf
, decode1
, 15);
630 sprintf(buf
, decode1
, 1);
634 strcpy(buf
, decode3
);
638 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
642 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
644 PSDRV_WriteSpool(physDev
, endmask
, sizeof(endmask
) - 1);
646 sprintf(buf
, endbits
, bits
);
647 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
650 HeapFree(PSDRV_Heap
, 0, buf
);
655 BOOL
PSDRV_WriteBytes(PSDRV_PDEVICE
*physDev
, const BYTE
*bytes
, int number
)
657 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
663 for(i
= 0; i
< number
; i
++) {
664 sprintf(ptr
, "%02x", bytes
[i
]);
666 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
671 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
672 HeapFree(PSDRV_Heap
, 0, buf
);
676 BOOL
PSDRV_WriteDIBits16(PSDRV_PDEVICE
*physDev
, const WORD
*words
, int number
)
678 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
684 for(i
= 0; i
< number
; i
++) {
687 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
689 r
= words
[i
] >> 10 & 0x1f;
691 g
= words
[i
] >> 5 & 0x1f;
695 sprintf(ptr
, "%02x%02x%02x", r
, g
, b
);
697 if(((i
& 0x7) == 0x7) || (i
== number
- 1)) {
702 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
704 HeapFree(PSDRV_Heap
, 0, buf
);
708 BOOL
PSDRV_WriteDIBits24(PSDRV_PDEVICE
*physDev
, const BYTE
*bits
, int number
)
710 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
716 for(i
= 0; i
< number
; i
++) {
717 sprintf(ptr
, "%02x%02x%02x", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
720 if(((i
& 0x7) == 0x7) || (i
== number
- 1)) {
725 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
727 HeapFree(PSDRV_Heap
, 0, buf
);
731 BOOL
PSDRV_WriteDIBits32(PSDRV_PDEVICE
*physDev
, const BYTE
*bits
, int number
)
733 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
739 for(i
= 0; i
< number
; i
++) {
740 sprintf(ptr
, "%02x%02x%02x", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
743 if(((i
& 0x7) == 0x7) || (i
== number
- 1)) {
748 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
750 HeapFree(PSDRV_Heap
, 0, buf
);
754 BOOL
PSDRV_WriteArrayGet(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
)
758 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
759 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
762 BOOL
PSDRV_WriteArrayPut(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
766 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
767 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
770 BOOL
PSDRV_WriteArrayDef(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nSize
)
774 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
775 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
778 BOOL
PSDRV_WriteRectClip(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
)
782 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
783 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
786 BOOL
PSDRV_WriteRectClip2(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
)
790 sprintf(buf
, psrectclip2
, pszArrayName
);
791 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
794 BOOL
PSDRV_WritePatternDict(PSDRV_PDEVICE
*physDev
, BITMAP
*bm
, BYTE
*bits
)
796 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
797 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
799 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
804 w
= bm
->bmWidth
& ~0x7;
805 h
= bm
->bmHeight
& ~0x7;
807 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
808 sprintf(buf
, start
, w
, h
, w
, h
);
809 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
810 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
811 map
[0] = GetTextColor( physDev
->hdc
);
812 map
[1] = GetBkColor( physDev
->hdc
);
813 PSDRV_WriteRGB(physDev
, map
, 2);
814 PSDRV_WriteIndexColorSpaceEnd(physDev
);
816 for(y
= h
-1; y
>= 0; y
--) {
817 for(x
= 0; x
< w
/8; x
++) {
818 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
822 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
, FALSE
);
823 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
824 HeapFree(PSDRV_Heap
, 0, buf
);
828 BOOL
PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE
*physDev
, BITMAPINFO
*bmi
, UINT usage
)
830 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
831 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
833 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
836 INT w
, h
, x
, y
, colours
;
839 if(bmi
->bmiHeader
.biBitCount
!= 1) {
840 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
844 bits
= (char*)bmi
+ bmi
->bmiHeader
.biSize
;
845 colours
= bmi
->bmiHeader
.biClrUsed
;
846 if(!colours
&& bmi
->bmiHeader
.biBitCount
<= 8)
847 colours
= 1 << bmi
->bmiHeader
.biBitCount
;
848 bits
+= colours
* ((usage
== DIB_RGB_COLORS
) ?
849 sizeof(RGBQUAD
) : sizeof(WORD
));
851 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
852 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
854 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
855 sprintf(buf
, start
, w
, h
, w
, h
);
856 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
857 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
858 map
[0] = physDev
->dc
->textColor
;
859 map
[1] = physDev
->dc
->backgroundColor
;
860 PSDRV_WriteRGB(physDev
, map
, 2);
861 PSDRV_WriteIndexColorSpaceEnd(physDev
);
863 for(y
= h
-1; y
>= 0; y
--) {
864 for(x
= 0; x
< w
/8; x
++) {
865 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
866 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
870 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
, FALSE
);
871 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
872 HeapFree(PSDRV_Heap
, 0, buf
);