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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
31 static char psheader
[] = /* title llx lly urx ury orientation */
33 "%%%%Creator: Wine PostScript Driver\n"
35 "%%%%BoundingBox: %d %d %d %d\n"
36 "%%%%Pages: (atend)\n"
37 "%%%%Orientation: %s\n"
40 static char psbeginprolog
[] =
43 static char psendprolog
[] =
46 static char psprolog
[] =
47 "/tmpmtrx matrix def\n"
50 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
51 " l cvi gap idiv gap mul\n"
53 " r cvi gap idiv gap mul\n"
54 " {t moveto 0 b t sub rlineto}\n"
58 static char psbeginsetup
[] =
61 static char psendsetup
[] =
64 static char psbeginfeature
[] = /* feature, value */
66 "%%%%BeginFeature: %s %s\n";
68 static char psendfeature
[] =
70 "} stopped cleartomark\n";
72 static char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
74 "%%%%BeginPageSetup\n"
76 "72 %d div 72 %d div scale\n"
82 static char psendpage
[] =
86 static char psfooter
[] = /* pages */
91 static char psmoveto
[] = /* x, y */
94 static char pslineto
[] = /* x, y */
97 static char psstroke
[] =
100 static char psrectangle
[] = /* x, y, width, height, -width */
107 static char psrrectangle
[] = /* x, y, width, height, -width */
114 static const char psglyphshow
[] = /* glyph name */
117 static char pssetfont
[] = /* fontname, xscale, yscale, ascent, escapement */
120 "%d 10 div matrix rotate\n"
121 "matrix concatmatrix\n"
122 "makefont setfont\n";
124 static char pssetlinewidth
[] = /* width */
127 static char pssetdash
[] = /* dash, offset */
130 static char pssetgray
[] = /* gray */
133 static char pssetrgbcolor
[] = /* r, g, b */
134 "%.2f %.2f %.2f setrgbcolor\n";
136 static char psarc
[] = /* x, y, w, h, ang1, ang2 */
137 "tmpmtrx currentmatrix pop\n"
140 "0 0 0.5 %.1f %.1f arc\n"
141 "tmpmtrx setmatrix\n";
143 static char psgsave
[] =
146 static char psgrestore
[] =
149 static char psfill
[] =
152 static char pseofill
[] =
155 static char psnewpath
[] =
158 static char psclosepath
[] =
161 static char psclip
[] =
164 static char psinitclip
[] =
167 static char pseoclip
[] =
170 static char psrectclip
[] =
171 "%d %d %d %d rectclip\n";
173 static char psrectclip2
[] =
176 static char pshatch
[] =
179 static char psrotate
[] = /* ang */
182 static char psarrayget
[] =
185 static char psarrayput
[] =
188 static char psarraydef
[] =
189 "/%s %d array def\n";
192 int PSDRV_WriteSpool(PSDRV_PDEVICE
*physDev
, LPSTR lpData
, WORD cch
)
194 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
195 if( !PSDRV_StartPage(physDev
) )
198 return WriteSpool16( physDev
->job
.hJob
, lpData
, cch
);
202 INT
PSDRV_WriteFeature(HANDLE16 hJob
, char *feature
, char *value
,
206 char *buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
207 strlen(feature
) + strlen(value
));
210 sprintf(buf
, psbeginfeature
, feature
, value
);
211 WriteSpool16( hJob
, buf
, strlen(buf
) );
213 WriteSpool16( hJob
, invocation
, strlen(invocation
) );
215 WriteSpool16( hJob
, psendfeature
, strlen(psendfeature
) );
217 HeapFree( PSDRV_Heap
, 0, buf
);
223 INT
PSDRV_WriteHeader( PSDRV_PDEVICE
*physDev
, LPCSTR title
)
228 int llx
, lly
, urx
, ury
;
230 TRACE("'%s'\n", title
);
232 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
233 strlen(title
) + 30 );
235 WARN("HeapAlloc failed\n");
239 /* BBox co-ords are in default user co-ord system so urx < ury even in
241 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
242 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
243 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
244 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
246 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
247 orient
= "Landscape";
252 /* FIXME should do something better with BBox */
254 sprintf(buf
, psheader
, title
, llx
, lly
, urx
, ury
, orient
);
256 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
258 WARN("WriteSpool error\n");
259 HeapFree( PSDRV_Heap
, 0, buf
);
262 HeapFree( PSDRV_Heap
, 0, buf
);
264 WriteSpool16( physDev
->job
.hJob
, psbeginprolog
, strlen(psbeginprolog
) );
265 WriteSpool16( physDev
->job
.hJob
, psprolog
, strlen(psprolog
) );
266 WriteSpool16( physDev
->job
.hJob
, psendprolog
, strlen(psendprolog
) );
268 WriteSpool16( physDev
->job
.hJob
, psbeginsetup
, strlen(psbeginsetup
) );
270 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
271 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.dmDefaultSource
) {
272 if(slot
->InvocationString
) {
273 PSDRV_WriteFeature(physDev
->job
.hJob
, "*InputSlot", slot
->Name
,
274 slot
->InvocationString
);
280 for(page
= physDev
->pi
->ppd
->PageSizes
; page
; page
= page
->next
) {
281 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
282 if(page
->InvocationString
) {
283 PSDRV_WriteFeature(physDev
->job
.hJob
, "*PageSize", page
->Name
,
284 page
->InvocationString
);
290 WriteSpool16( physDev
->job
.hJob
, psendsetup
, strlen(psendsetup
) );
297 INT
PSDRV_WriteFooter( PSDRV_PDEVICE
*physDev
)
301 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
303 WARN("HeapAlloc failed\n");
307 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
309 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
311 WARN("WriteSpool error\n");
312 HeapFree( PSDRV_Heap
, 0, buf
);
315 HeapFree( PSDRV_Heap
, 0, buf
);
321 INT
PSDRV_WriteEndPage( PSDRV_PDEVICE
*physDev
)
323 if( WriteSpool16( physDev
->job
.hJob
, psendpage
, sizeof(psendpage
)-1 ) !=
324 sizeof(psendpage
)-1 ) {
325 WARN("WriteSpool error\n");
334 INT
PSDRV_WriteNewPage( PSDRV_PDEVICE
*physDev
)
338 signed int xtrans
, ytrans
, rotation
;
340 sprintf(name
, "%d", physDev
->job
.PageNo
);
342 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
344 WARN("HeapAlloc failed\n");
348 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
349 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
350 xtrans
= physDev
->ImageableArea
.right
;
351 ytrans
= physDev
->ImageableArea
.top
;
354 xtrans
= physDev
->ImageableArea
.left
;
355 ytrans
= physDev
->ImageableArea
.bottom
;
359 xtrans
= physDev
->ImageableArea
.left
;
360 ytrans
= physDev
->ImageableArea
.top
;
364 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
365 physDev
->logPixelsX
, physDev
->logPixelsY
,
366 xtrans
, ytrans
, rotation
);
368 if( WriteSpool16( physDev
->job
.hJob
, buf
, strlen(buf
) ) !=
370 WARN("WriteSpool error\n");
371 HeapFree( PSDRV_Heap
, 0, buf
);
374 HeapFree( PSDRV_Heap
, 0, buf
);
379 BOOL
PSDRV_WriteMoveTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
383 sprintf(buf
, psmoveto
, x
, y
);
384 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
387 BOOL
PSDRV_WriteLineTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
391 sprintf(buf
, pslineto
, x
, y
);
392 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
396 BOOL
PSDRV_WriteStroke(PSDRV_PDEVICE
*physDev
)
398 return PSDRV_WriteSpool(physDev
, psstroke
, sizeof(psstroke
)-1);
403 BOOL
PSDRV_WriteRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
408 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
409 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
412 BOOL
PSDRV_WriteRRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
417 sprintf(buf
, psrrectangle
, x
, y
, width
, height
, -width
);
418 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
421 BOOL
PSDRV_WriteArc(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
426 /* Make angles -ve and swap order because we're working with an upside
428 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
429 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
433 BOOL
PSDRV_WriteSetFont(PSDRV_PDEVICE
*physDev
, const char *name
, INT size
, INT escapement
)
437 buf
= (char *)HeapAlloc( PSDRV_Heap
, 0, sizeof(pssetfont
) +
441 WARN("HeapAlloc failed\n");
445 sprintf(buf
, pssetfont
, name
, size
, -size
, -escapement
);
447 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
448 HeapFree(PSDRV_Heap
, 0, buf
);
452 BOOL
PSDRV_WriteSetColor(PSDRV_PDEVICE
*physDev
, PSCOLOR
*color
)
456 PSDRV_CopyColor(&physDev
->inkColor
, color
);
457 switch(color
->type
) {
459 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
461 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
464 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
465 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
468 ERR("Unkonwn colour type %d\n", color
->type
);
475 BOOL
PSDRV_WriteSetPen(PSDRV_PDEVICE
*physDev
)
479 sprintf(buf
, pssetlinewidth
, physDev
->pen
.width
);
480 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
482 if(physDev
->pen
.dash
) {
483 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
484 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
490 BOOL
PSDRV_WriteGlyphShow(PSDRV_PDEVICE
*physDev
, LPCSTR g_name
)
495 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
497 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
498 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
502 PSDRV_WriteSpool(physDev
, buf
, l
);
506 BOOL
PSDRV_WriteFill(PSDRV_PDEVICE
*physDev
)
508 return PSDRV_WriteSpool(physDev
, psfill
, sizeof(psfill
)-1);
511 BOOL
PSDRV_WriteEOFill(PSDRV_PDEVICE
*physDev
)
513 return PSDRV_WriteSpool(physDev
, pseofill
, sizeof(pseofill
)-1);
516 BOOL
PSDRV_WriteGSave(PSDRV_PDEVICE
*physDev
)
518 return PSDRV_WriteSpool(physDev
, psgsave
, sizeof(psgsave
)-1);
521 BOOL
PSDRV_WriteGRestore(PSDRV_PDEVICE
*physDev
)
523 return PSDRV_WriteSpool(physDev
, psgrestore
, sizeof(psgrestore
)-1);
526 BOOL
PSDRV_WriteNewPath(PSDRV_PDEVICE
*physDev
)
528 return PSDRV_WriteSpool(physDev
, psnewpath
, sizeof(psnewpath
)-1);
531 BOOL
PSDRV_WriteClosePath(PSDRV_PDEVICE
*physDev
)
533 return PSDRV_WriteSpool(physDev
, psclosepath
, sizeof(psclosepath
)-1);
536 BOOL
PSDRV_WriteClip(PSDRV_PDEVICE
*physDev
)
538 return PSDRV_WriteSpool(physDev
, psclip
, sizeof(psclip
)-1);
541 BOOL
PSDRV_WriteEOClip(PSDRV_PDEVICE
*physDev
)
543 return PSDRV_WriteSpool(physDev
, pseoclip
, sizeof(pseoclip
)-1);
546 BOOL
PSDRV_WriteInitClip(PSDRV_PDEVICE
*physDev
)
548 return PSDRV_WriteSpool(physDev
, psinitclip
, sizeof(psinitclip
)-1);
551 BOOL
PSDRV_WriteHatch(PSDRV_PDEVICE
*physDev
)
553 return PSDRV_WriteSpool(physDev
, pshatch
, sizeof(pshatch
)-1);
556 BOOL
PSDRV_WriteRotate(PSDRV_PDEVICE
*physDev
, float ang
)
560 sprintf(buf
, psrotate
, ang
);
561 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
564 BOOL
PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE
*physDev
, int size
)
567 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
568 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
571 BOOL
PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE
*physDev
)
573 char buf
[] = ">\n] setcolorspace\n";
574 return PSDRV_WriteSpool(physDev
, buf
, sizeof(buf
) - 1);
577 BOOL
PSDRV_WriteRGB(PSDRV_PDEVICE
*physDev
, COLORREF
*map
, int number
)
579 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
583 for(i
= 0; i
< number
; i
++) {
584 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
585 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
586 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
589 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
590 HeapFree(PSDRV_Heap
, 0, buf
);
595 BOOL
PSDRV_WriteImageDict(PSDRV_PDEVICE
*physDev
, WORD depth
, INT xDst
, INT yDst
,
596 INT widthDst
, INT heightDst
, INT widthSrc
,
597 INT heightSrc
, char *bits
)
599 char start
[] = "%d %d translate\n%d %d scale\n<<\n"
600 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
601 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
603 char decode1
[] = " /Decode [0 %d]\n";
604 char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
606 char end
[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
607 char endbits
[] = " /DataSource <%s>\n>> image\n";
609 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
611 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
, widthSrc
, heightSrc
,
612 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
614 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
618 sprintf(buf
, decode1
, 255);
622 sprintf(buf
, decode1
, 15);
626 sprintf(buf
, decode1
, 1);
630 strcpy(buf
, decode3
);
634 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
637 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
639 sprintf(buf
, endbits
, bits
);
640 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
643 HeapFree(PSDRV_Heap
, 0, buf
);
648 BOOL
PSDRV_WriteBytes(PSDRV_PDEVICE
*physDev
, const BYTE
*bytes
, int number
)
650 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
656 for(i
= 0; i
< number
; i
++) {
657 sprintf(ptr
, "%02x%c", bytes
[i
],
658 ((i
& 0xf) == 0xf) || (i
== number
- 1) ? '\n' : ' ');
661 PSDRV_WriteSpool(physDev
, buf
, number
* 3);
663 HeapFree(PSDRV_Heap
, 0, buf
);
667 BOOL
PSDRV_WriteDIBits16(PSDRV_PDEVICE
*physDev
, const WORD
*words
, int number
)
669 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
675 for(i
= 0; i
< number
; i
++) {
678 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
680 r
= words
[i
] >> 10 & 0x1f;
682 g
= words
[i
] >> 5 & 0x1f;
686 sprintf(ptr
, "%02x%02x%02x%c", r
, g
, b
,
687 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
690 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
692 HeapFree(PSDRV_Heap
, 0, buf
);
696 BOOL
PSDRV_WriteDIBits24(PSDRV_PDEVICE
*physDev
, const BYTE
*bits
, int number
)
698 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
704 for(i
= 0; i
< number
; i
++) {
705 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 3 + 2], bits
[i
* 3 + 1],
707 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
710 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
712 HeapFree(PSDRV_Heap
, 0, buf
);
716 BOOL
PSDRV_WriteDIBits32(PSDRV_PDEVICE
*physDev
, const BYTE
*bits
, int number
)
718 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1);
724 for(i
= 0; i
< number
; i
++) {
725 sprintf(ptr
, "%02x%02x%02x%c", bits
[i
* 4 + 2], bits
[i
* 4 + 1],
727 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
730 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
732 HeapFree(PSDRV_Heap
, 0, buf
);
736 BOOL
PSDRV_WriteArrayGet(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
)
740 sprintf(buf
, psarrayget
, pszArrayName
, nIndex
);
741 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
744 BOOL
PSDRV_WriteArrayPut(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
748 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
749 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
752 BOOL
PSDRV_WriteArrayDef(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nSize
)
756 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
757 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
760 BOOL
PSDRV_WriteRectClip(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
)
764 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
765 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
768 BOOL
PSDRV_WriteRectClip2(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
)
772 sprintf(buf
, psrectclip2
, pszArrayName
);
773 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
776 BOOL
PSDRV_WritePatternDict(PSDRV_PDEVICE
*physDev
, BITMAP
*bm
, BYTE
*bits
)
778 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
779 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
781 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
786 w
= bm
->bmWidth
& ~0x7;
787 h
= bm
->bmHeight
& ~0x7;
789 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
790 sprintf(buf
, start
, w
, h
, w
, h
);
791 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
792 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
793 map
[0] = GetTextColor( physDev
->hdc
);
794 map
[1] = GetBkColor( physDev
->hdc
);
795 PSDRV_WriteRGB(physDev
, map
, 2);
796 PSDRV_WriteIndexColorSpaceEnd(physDev
);
798 for(y
= h
-1; y
>= 0; y
--) {
799 for(x
= 0; x
< w
/8; x
++) {
800 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
804 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
);
805 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
806 HeapFree(PSDRV_Heap
, 0, buf
);
810 BOOL
PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE
*physDev
, BITMAPINFO
*bmi
, UINT usage
)
812 char start
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
813 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
815 char end
[] = " end\n }\n>>\n matrix makepattern setpattern\n";
818 INT w
, h
, x
, y
, colours
;
821 if(bmi
->bmiHeader
.biBitCount
!= 1) {
822 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
826 bits
= (char*)bmi
+ bmi
->bmiHeader
.biSize
;
827 colours
= bmi
->bmiHeader
.biClrUsed
;
828 if(!colours
&& bmi
->bmiHeader
.biBitCount
<= 8)
829 colours
= 1 << bmi
->bmiHeader
.biBitCount
;
830 bits
+= colours
* ((usage
== DIB_RGB_COLORS
) ?
831 sizeof(RGBQUAD
) : sizeof(WORD
));
833 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
834 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
836 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(start
) + 100);
837 sprintf(buf
, start
, w
, h
, w
, h
);
838 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
839 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
840 map
[0] = physDev
->dc
->textColor
;
841 map
[1] = physDev
->dc
->backgroundColor
;
842 PSDRV_WriteRGB(physDev
, map
, 2);
843 PSDRV_WriteIndexColorSpaceEnd(physDev
);
845 for(y
= h
-1; y
>= 0; y
--) {
846 for(x
= 0; x
< w
/8; x
++) {
847 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
848 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
852 PSDRV_WriteImageDict(physDev
, 1, 0, 0, 8, 8, 8, 8, buf
);
853 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
854 HeapFree(PSDRV_Heap
, 0, buf
);