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
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
37 static const char psheader
[] = /* title llx lly urx ury */
39 "%%%%Creator: Wine PostScript Driver\n"
41 "%%%%BoundingBox: %d %d %d %d\n"
42 "%%%%Pages: (atend)\n"
45 static const char psbeginprolog
[] =
48 static const char psendprolog
[] =
51 static const char psprolog
[] =
52 "/tmpmtrx matrix def\n"
55 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
56 " l cvi gap idiv gap mul\n"
58 " r cvi gap idiv gap mul\n"
59 " {t moveto 0 b t sub rlineto}\n"
62 "/B {pop pop pop pop} def\n"
64 "/havetype42gdir {version cvi 2015 ge} bind def\n";
66 static const char psbeginsetup
[] =
69 static const char psendsetup
[] =
72 static const char psbeginfeature
[] = /* feature, value */
74 "%%%%BeginFeature: %s %s\n";
76 static const char psendfeature
[] =
78 "} stopped cleartomark\n";
80 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
82 "%%%%BeginPageSetup\n"
84 "72 %d div 72 %d div scale\n"
90 static const char psendpage
[] =
94 static const char psfooter
[] = /* pages */
99 static const char psmoveto
[] = /* x, y */
102 static const char pslineto
[] = /* x, y */
105 static const char psstroke
[] =
108 static const char psrectangle
[] = /* x, y, width, height, -width */
115 static const char psglyphshow
[] = /* glyph name */
118 static const char pssetfont
[] = /* fontname, xx_scale, xy_scale, yx_scale, yy_scale, escapement */
120 "[%d %d %d %d 0 0]\n"
121 "%d 10 div matrix rotate\n"
122 "matrix concatmatrix\n"
123 "makefont setfont\n";
125 static const char pssetline
[] = /* width, join, endcap */
126 "%d setlinewidth %u setlinejoin %u setlinecap\n";
128 static const char pssetdash
[] = /* dash, offset */
131 static const char pssetgray
[] = /* gray */
134 static const char pssetrgbcolor
[] = /* r, g, b */
135 "%.2f %.2f %.2f setrgbcolor\n";
137 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
138 "tmpmtrx currentmatrix pop\n"
141 "0 0 0.5 %.1f %.1f arc\n"
142 "tmpmtrx setmatrix\n";
144 static const char psgsave
[] =
147 static const char psgrestore
[] =
150 static const char psfill
[] =
153 static const char pseofill
[] =
156 static const char psnewpath
[] =
159 static const char psclosepath
[] =
162 static const char psclip
[] =
165 static const char pseoclip
[] =
168 static const char psrectclip
[] =
169 "%d %d %d %d rectclip\n";
171 static const char psrectclip2
[] =
174 static const char pshatch
[] =
177 static const char psrotate
[] = /* ang */
180 static const char psarrayput
[] =
183 static const char psarraydef
[] =
184 "/%s %d array def\n";
186 static const char psenddocument
[] =
189 DWORD
PSDRV_WriteSpool(PSDRV_PDEVICE
*physDev
, LPCSTR lpData
, DWORD cch
)
191 int num
, num_left
= cch
;
193 if(physDev
->job
.quiet
) {
194 TRACE("ignoring output\n");
198 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
199 write_spool( physDev
, psenddocument
, sizeof(psenddocument
)-1 );
200 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
203 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
204 if( !PSDRV_StartPage(physDev
) )
209 num
= min(num_left
, 0x8000);
210 if(write_spool( physDev
, lpData
, num
) != num
)
220 static INT
PSDRV_WriteFeature(PSDRV_PDEVICE
*physDev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
223 char *buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psbeginfeature
) +
224 strlen(feature
) + strlen(value
));
226 sprintf(buf
, psbeginfeature
, feature
, value
);
227 write_spool( physDev
, buf
, strlen(buf
) );
228 write_spool( physDev
, invocation
, strlen(invocation
) );
229 write_spool( physDev
, psendfeature
, strlen(psendfeature
) );
231 HeapFree( PSDRV_Heap
, 0, buf
);
235 /********************************************************
238 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
239 * as octal. If we've had to use an escape then surround the entire string
240 * in brackets. Truncate string to represent at most 0x80 characters.
243 static char *escape_title(LPCSTR str
)
250 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
255 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
263 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
269 extra
+= 2; /* two for the brackets */
270 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
272 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
276 BYTE b
= (BYTE
)str
[i
];
278 *cp
++ = ((b
>> 6) & 0x7) + '0';
279 *cp
++ = ((b
>> 3) & 0x7) + '0';
280 *cp
++ = ((b
) & 0x7) + '0';
291 INT
PSDRV_WriteHeader( PSDRV_PDEVICE
*physDev
, LPCSTR title
)
293 char *buf
, *escaped_title
;
298 int llx
, lly
, urx
, ury
;
300 TRACE("%s\n", debugstr_a(title
));
302 escaped_title
= escape_title(title
);
303 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psheader
) +
304 strlen(escaped_title
) + 30 );
306 WARN("HeapAlloc failed\n");
310 /* BBox co-ords are in default user co-ord system so urx < ury even in
312 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
313 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
314 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
315 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
316 /* FIXME should do something better with BBox */
318 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
);
320 HeapFree(GetProcessHeap(), 0, escaped_title
);
321 if( write_spool( physDev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
322 WARN("WriteSpool error\n");
323 HeapFree( PSDRV_Heap
, 0, buf
);
326 HeapFree( PSDRV_Heap
, 0, buf
);
328 write_spool( physDev
, psbeginprolog
, strlen(psbeginprolog
) );
329 write_spool( physDev
, psprolog
, strlen(psprolog
) );
330 write_spool( physDev
, psendprolog
, strlen(psendprolog
) );
331 write_spool( physDev
, psbeginsetup
, strlen(psbeginsetup
) );
333 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1) {
334 char copies_buf
[100];
335 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
336 write_spool(physDev
, copies_buf
, strlen(copies_buf
));
339 for(slot
= physDev
->pi
->ppd
->InputSlots
; slot
; slot
= slot
->next
) {
340 if(slot
->WinBin
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmDefaultSource
) {
341 if(slot
->InvocationString
) {
342 PSDRV_WriteFeature(physDev
, "*InputSlot", slot
->Name
,
343 slot
->InvocationString
);
349 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
350 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
351 if(page
->InvocationString
) {
352 PSDRV_WriteFeature(physDev
, "*PageSize", page
->Name
,
353 page
->InvocationString
);
359 win_duplex
= physDev
->Devmode
->dmPublic
.dmFields
& DM_DUPLEX
?
360 physDev
->Devmode
->dmPublic
.dmDuplex
: 0;
361 for(duplex
= physDev
->pi
->ppd
->Duplexes
; duplex
; duplex
= duplex
->next
) {
362 if(duplex
->WinDuplex
== win_duplex
) {
363 if(duplex
->InvocationString
) {
364 PSDRV_WriteFeature(physDev
, "*Duplex", duplex
->Name
,
365 duplex
->InvocationString
);
371 write_spool( physDev
, psendsetup
, strlen(psendsetup
) );
378 INT
PSDRV_WriteFooter( PSDRV_PDEVICE
*physDev
)
382 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psfooter
) + 100 );
384 WARN("HeapAlloc failed\n");
388 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
390 if( write_spool( physDev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
391 WARN("WriteSpool error\n");
392 HeapFree( PSDRV_Heap
, 0, buf
);
395 HeapFree( PSDRV_Heap
, 0, buf
);
401 INT
PSDRV_WriteEndPage( PSDRV_PDEVICE
*physDev
)
403 if( write_spool( physDev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
404 WARN("WriteSpool error\n");
413 INT
PSDRV_WriteNewPage( PSDRV_PDEVICE
*physDev
)
417 signed int xtrans
, ytrans
, rotation
;
419 sprintf(name
, "%d", physDev
->job
.PageNo
);
421 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(psnewpage
) + 200 );
423 WARN("HeapAlloc failed\n");
427 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
428 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
429 xtrans
= physDev
->ImageableArea
.right
;
430 ytrans
= physDev
->ImageableArea
.top
;
433 xtrans
= physDev
->ImageableArea
.left
;
434 ytrans
= physDev
->ImageableArea
.bottom
;
438 xtrans
= physDev
->ImageableArea
.left
;
439 ytrans
= physDev
->ImageableArea
.top
;
443 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
444 physDev
->logPixelsX
, physDev
->logPixelsY
,
445 xtrans
, ytrans
, rotation
);
447 if( write_spool( physDev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
448 WARN("WriteSpool error\n");
449 HeapFree( PSDRV_Heap
, 0, buf
);
452 HeapFree( PSDRV_Heap
, 0, buf
);
457 BOOL
PSDRV_WriteMoveTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
461 sprintf(buf
, psmoveto
, x
, y
);
462 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
465 BOOL
PSDRV_WriteLineTo(PSDRV_PDEVICE
*physDev
, INT x
, INT y
)
469 sprintf(buf
, pslineto
, x
, y
);
470 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
474 BOOL
PSDRV_WriteStroke(PSDRV_PDEVICE
*physDev
)
476 return PSDRV_WriteSpool(physDev
, psstroke
, sizeof(psstroke
)-1);
481 BOOL
PSDRV_WriteRectangle(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT width
,
486 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
487 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
490 BOOL
PSDRV_WriteArc(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
495 /* Make angles -ve and swap order because we're working with an upside
497 push_lc_numeric("C");
498 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
500 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
504 BOOL
PSDRV_WriteSetFont(PSDRV_PDEVICE
*physDev
, const char *name
, matrix size
, INT escapement
)
508 buf
= HeapAlloc( PSDRV_Heap
, 0, sizeof(pssetfont
) +
512 WARN("HeapAlloc failed\n");
516 sprintf(buf
, pssetfont
, name
, size
.xx
, size
.xy
, size
.yx
, size
.yy
, -escapement
);
518 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
519 HeapFree(PSDRV_Heap
, 0, buf
);
523 BOOL
PSDRV_WriteSetColor(PSDRV_PDEVICE
*physDev
, PSCOLOR
*color
)
527 PSDRV_CopyColor(&physDev
->inkColor
, color
);
528 switch(color
->type
) {
530 push_lc_numeric("C");
531 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
534 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
537 push_lc_numeric("C");
538 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
540 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
543 ERR("Unkonwn colour type %d\n", color
->type
);
550 BOOL
PSDRV_WriteSetPen(PSDRV_PDEVICE
*physDev
)
554 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
555 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
557 if(physDev
->pen
.dash
) {
558 sprintf(buf
, pssetdash
, physDev
->pen
.dash
, 0);
561 sprintf(buf
, pssetdash
, "", 0);
563 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
568 BOOL
PSDRV_WriteGlyphShow(PSDRV_PDEVICE
*physDev
, LPCSTR g_name
)
573 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
575 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
576 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
580 PSDRV_WriteSpool(physDev
, buf
, l
);
584 BOOL
PSDRV_WriteFill(PSDRV_PDEVICE
*physDev
)
586 return PSDRV_WriteSpool(physDev
, psfill
, sizeof(psfill
)-1);
589 BOOL
PSDRV_WriteEOFill(PSDRV_PDEVICE
*physDev
)
591 return PSDRV_WriteSpool(physDev
, pseofill
, sizeof(pseofill
)-1);
594 BOOL
PSDRV_WriteGSave(PSDRV_PDEVICE
*physDev
)
596 return PSDRV_WriteSpool(physDev
, psgsave
, sizeof(psgsave
)-1);
599 BOOL
PSDRV_WriteGRestore(PSDRV_PDEVICE
*physDev
)
601 return PSDRV_WriteSpool(physDev
, psgrestore
, sizeof(psgrestore
)-1);
604 BOOL
PSDRV_WriteNewPath(PSDRV_PDEVICE
*physDev
)
606 return PSDRV_WriteSpool(physDev
, psnewpath
, sizeof(psnewpath
)-1);
609 BOOL
PSDRV_WriteClosePath(PSDRV_PDEVICE
*physDev
)
611 return PSDRV_WriteSpool(physDev
, psclosepath
, sizeof(psclosepath
)-1);
614 BOOL
PSDRV_WriteClip(PSDRV_PDEVICE
*physDev
)
616 return PSDRV_WriteSpool(physDev
, psclip
, sizeof(psclip
)-1);
619 BOOL
PSDRV_WriteEOClip(PSDRV_PDEVICE
*physDev
)
621 return PSDRV_WriteSpool(physDev
, pseoclip
, sizeof(pseoclip
)-1);
624 BOOL
PSDRV_WriteHatch(PSDRV_PDEVICE
*physDev
)
626 return PSDRV_WriteSpool(physDev
, pshatch
, sizeof(pshatch
)-1);
629 BOOL
PSDRV_WriteRotate(PSDRV_PDEVICE
*physDev
, float ang
)
633 push_lc_numeric("C");
634 sprintf(buf
, psrotate
, ang
);
636 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
639 BOOL
PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE
*physDev
, int size
)
642 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
643 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
646 BOOL
PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE
*physDev
)
648 static const char buf
[] = ">\n] setcolorspace\n";
649 return PSDRV_WriteSpool(physDev
, buf
, sizeof(buf
) - 1);
652 BOOL
PSDRV_WriteRGB(PSDRV_PDEVICE
*physDev
, COLORREF
*map
, int number
)
654 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 7 + 1), *ptr
;
658 for(i
= 0; i
< number
; i
++) {
659 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
660 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
661 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
664 PSDRV_WriteSpool(physDev
, buf
, number
* 7);
665 HeapFree(PSDRV_Heap
, 0, buf
);
669 static BOOL
PSDRV_WriteImageDict(PSDRV_PDEVICE
*physDev
, WORD depth
,
670 INT widthSrc
, INT heightSrc
, char *bits
)
672 static const char start
[] = "<<\n"
673 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
674 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
676 static const char decode1
[] = " /Decode [0 %d]\n";
677 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
679 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
680 static const char endbits
[] = " /DataSource <%s>\n>>\n";
682 char *buf
= HeapAlloc(PSDRV_Heap
, 0, 1000);
684 sprintf(buf
, start
, widthSrc
, heightSrc
,
685 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
687 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
691 sprintf(buf
, decode1
, 255);
695 sprintf(buf
, decode1
, 15);
699 sprintf(buf
, decode1
, 1);
703 strcpy(buf
, decode3
);
707 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
710 PSDRV_WriteSpool(physDev
, end
, sizeof(end
) - 1);
712 sprintf(buf
, endbits
, bits
);
713 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
716 HeapFree(PSDRV_Heap
, 0, buf
);
720 BOOL
PSDRV_WriteImage(PSDRV_PDEVICE
*physDev
, WORD depth
, INT xDst
, INT yDst
,
721 INT widthDst
, INT heightDst
, INT widthSrc
,
722 INT heightSrc
, BOOL mask
)
724 static const char start
[] = "%d %d translate\n%d %d scale\n";
725 static const char image
[] = "image\n";
726 static const char imagemask
[] = "imagemask\n";
729 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
730 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
731 PSDRV_WriteImageDict(physDev
, depth
, widthSrc
, heightSrc
, NULL
);
733 PSDRV_WriteSpool(physDev
, imagemask
, sizeof(imagemask
) - 1);
735 PSDRV_WriteSpool(physDev
, image
, sizeof(image
) - 1);
740 BOOL
PSDRV_WriteBytes(PSDRV_PDEVICE
*physDev
, const BYTE
*bytes
, DWORD number
)
742 char *buf
= HeapAlloc(PSDRV_Heap
, 0, number
* 3 + 1);
748 for(i
= 0; i
< number
; i
++) {
749 sprintf(ptr
, "%02x", bytes
[i
]);
751 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
756 PSDRV_WriteSpool(physDev
, buf
, ptr
- buf
);
757 HeapFree(PSDRV_Heap
, 0, buf
);
761 BOOL
PSDRV_WriteData(PSDRV_PDEVICE
*physDev
, const BYTE
*data
, DWORD number
)
763 int num
, num_left
= number
;
766 num
= min(num_left
, 60);
767 PSDRV_WriteSpool(physDev
, (LPCSTR
)data
, num
);
768 PSDRV_WriteSpool(physDev
, "\n", 1);
776 BOOL
PSDRV_WriteArrayPut(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
780 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
781 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
784 BOOL
PSDRV_WriteArrayDef(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
, INT nSize
)
788 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
789 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
792 BOOL
PSDRV_WriteRectClip(PSDRV_PDEVICE
*physDev
, INT x
, INT y
, INT w
, INT h
)
796 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
797 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
800 BOOL
PSDRV_WriteRectClip2(PSDRV_PDEVICE
*physDev
, CHAR
*pszArrayName
)
804 sprintf(buf
, psrectclip2
, pszArrayName
);
805 return PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
808 BOOL
PSDRV_WritePatternDict(PSDRV_PDEVICE
*physDev
, BITMAP
*bm
, BYTE
*bits
)
810 static const char mypat
[] = "/mypat\n";
811 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
812 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
813 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
816 INT w
, h
, x
, y
, w_mult
, h_mult
;
819 w
= bm
->bmWidth
& ~0x7;
820 h
= bm
->bmHeight
& ~0x7;
822 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(do_pattern
) + 100);
824 for(y
= h
-1; y
>= 0; y
--) {
825 for(x
= 0; x
< w
/8; x
++) {
826 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
* bm
->bmWidthBytes
));
830 PSDRV_WriteSpool(physDev
, mypat
, sizeof(mypat
) - 1);
831 PSDRV_WriteImageDict(physDev
, 1, 8, 8, buf
);
832 PSDRV_WriteSpool(physDev
, "def\n", 4);
834 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
835 map
[0] = GetTextColor( physDev
->hdc
);
836 map
[1] = GetBkColor( physDev
->hdc
);
837 PSDRV_WriteRGB(physDev
, map
, 2);
838 PSDRV_WriteIndexColorSpaceEnd(physDev
);
840 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
841 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
842 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
843 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
844 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
846 HeapFree(PSDRV_Heap
, 0, buf
);
850 BOOL
PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE
*physDev
, BITMAPINFO
*bmi
, UINT usage
)
852 static const char mypat
[] = "/mypat\n";
853 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
854 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
855 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
858 INT w
, h
, x
, y
, colours
, w_mult
, h_mult
;
861 if(bmi
->bmiHeader
.biBitCount
!= 1) {
862 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
866 bits
= (LPBYTE
)bmi
+ bmi
->bmiHeader
.biSize
;
867 colours
= bmi
->bmiHeader
.biClrUsed
;
868 if (colours
> 256) colours
= 256;
869 if(!colours
&& bmi
->bmiHeader
.biBitCount
<= 8)
870 colours
= 1 << bmi
->bmiHeader
.biBitCount
;
871 bits
+= colours
* ((usage
== DIB_RGB_COLORS
) ?
872 sizeof(RGBQUAD
) : sizeof(WORD
));
874 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
875 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
877 buf
= HeapAlloc(PSDRV_Heap
, 0, sizeof(do_pattern
) + 100);
879 for(y
= h
-1; y
>= 0; y
--) {
880 for(x
= 0; x
< w
/8; x
++) {
881 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
882 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
886 PSDRV_WriteSpool(physDev
, mypat
, sizeof(mypat
) - 1);
887 PSDRV_WriteImageDict(physDev
, 1, 8, 8, buf
);
888 PSDRV_WriteSpool(physDev
, "def\n", 4);
890 PSDRV_WriteIndexColorSpaceBegin(physDev
, 1);
891 map
[0] = GetTextColor( physDev
->hdc
);
892 map
[1] = GetBkColor( physDev
->hdc
);
893 PSDRV_WriteRGB(physDev
, map
, 2);
894 PSDRV_WriteIndexColorSpaceEnd(physDev
);
896 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
897 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
898 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
899 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
900 PSDRV_WriteSpool(physDev
, buf
, strlen(buf
));
901 HeapFree(PSDRV_Heap
, 0, buf
);