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 pssetgray
[] = /* gray */
131 static const char pssetrgbcolor
[] = /* r, g, b */
132 "%.2f %.2f %.2f setrgbcolor\n";
134 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
135 "tmpmtrx currentmatrix pop\n"
138 "0 0 0.5 %.1f %.1f arc\n"
139 "tmpmtrx setmatrix\n";
141 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
142 "%d %d %d %d %d %d curveto\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(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
191 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
192 int num
, num_left
= cch
;
194 if(physDev
->job
.quiet
) {
195 TRACE("ignoring output\n");
199 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
200 write_spool( dev
, psenddocument
, sizeof(psenddocument
)-1 );
201 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
204 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
205 if( !PSDRV_StartPage(dev
) )
210 num
= min(num_left
, 0x8000);
211 if(write_spool( dev
, lpData
, num
) != num
)
221 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
224 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
225 strlen(feature
) + strlen(value
));
227 sprintf(buf
, psbeginfeature
, feature
, value
);
228 write_spool( dev
, buf
, strlen(buf
) );
229 write_spool( dev
, invocation
, strlen(invocation
) );
230 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
232 HeapFree( GetProcessHeap(), 0, buf
);
236 /********************************************************
239 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
240 * as octal. If we've had to use an escape then surround the entire string
241 * in brackets. Truncate string to represent at most 0x80 characters.
244 static char *escape_title(LPCWSTR wstr
)
246 char *ret
, *cp
, *str
;
251 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
256 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
257 str
= HeapAlloc( GetProcessHeap(), 0, i
);
258 if (!str
) return NULL
;
259 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
261 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
269 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
275 extra
+= 2; /* two for the brackets */
276 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
278 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
282 BYTE b
= (BYTE
)str
[i
];
284 *cp
++ = ((b
>> 6) & 0x7) + '0';
285 *cp
++ = ((b
>> 3) & 0x7) + '0';
286 *cp
++ = ((b
) & 0x7) + '0';
295 HeapFree( GetProcessHeap(), 0, str
);
300 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
302 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
303 char *buf
, *escaped_title
;
304 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
308 int llx
, lly
, urx
, ury
;
311 TRACE("%s\n", debugstr_w(title
));
313 escaped_title
= escape_title(title
);
314 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
315 strlen(escaped_title
) + 30 );
317 WARN("HeapAlloc failed\n");
321 /* BBox co-ords are in default user co-ord system so urx < ury even in
323 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
324 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
325 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
326 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
327 /* FIXME should do something better with BBox */
329 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
);
331 HeapFree(GetProcessHeap(), 0, escaped_title
);
334 ret
= write_spool( dev
, buf
, len
);
335 HeapFree( GetProcessHeap(), 0, buf
);
338 WARN("WriteSpool error\n");
342 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
343 write_spool( dev
, psprolog
, strlen(psprolog
) );
344 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
345 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
347 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1) {
348 char copies_buf
[100];
349 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
350 write_spool(dev
, copies_buf
, strlen(copies_buf
));
353 if (slot
&& slot
->InvocationString
)
354 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
356 LIST_FOR_EACH_ENTRY(page
, &physDev
->pi
->ppd
->PageSizes
, PAGESIZE
, entry
) {
357 if(page
->WinPage
== physDev
->Devmode
->dmPublic
.u1
.s1
.dmPaperSize
) {
358 if(page
->InvocationString
) {
359 PSDRV_WriteFeature(dev
, "*PageSize", page
->Name
,
360 page
->InvocationString
);
366 win_duplex
= physDev
->Devmode
->dmPublic
.dmFields
& DM_DUPLEX
?
367 physDev
->Devmode
->dmPublic
.dmDuplex
: 0;
368 LIST_FOR_EACH_ENTRY( duplex
, &physDev
->pi
->ppd
->Duplexes
, DUPLEX
, entry
)
370 if(duplex
->WinDuplex
== win_duplex
) {
371 if(duplex
->InvocationString
) {
372 PSDRV_WriteFeature(dev
, "*Duplex", duplex
->Name
,
373 duplex
->InvocationString
);
379 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
386 INT
PSDRV_WriteFooter( PHYSDEV dev
)
388 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
392 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
394 WARN("HeapAlloc failed\n");
398 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
400 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
401 WARN("WriteSpool error\n");
404 HeapFree( GetProcessHeap(), 0, buf
);
410 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
412 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
413 WARN("WriteSpool error\n");
422 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
424 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
427 signed int xtrans
, ytrans
, rotation
;
430 sprintf(name
, "%d", physDev
->job
.PageNo
);
432 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
434 WARN("HeapAlloc failed\n");
438 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
439 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
440 xtrans
= physDev
->ImageableArea
.right
;
441 ytrans
= physDev
->ImageableArea
.top
;
444 xtrans
= physDev
->ImageableArea
.left
;
445 ytrans
= physDev
->ImageableArea
.bottom
;
449 xtrans
= physDev
->ImageableArea
.left
;
450 ytrans
= physDev
->ImageableArea
.top
;
454 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
455 physDev
->logPixelsX
, physDev
->logPixelsY
,
456 xtrans
, ytrans
, rotation
);
458 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
459 WARN("WriteSpool error\n");
462 HeapFree( GetProcessHeap(), 0, buf
);
467 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
471 sprintf(buf
, psmoveto
, x
, y
);
472 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
475 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
479 sprintf(buf
, pslineto
, x
, y
);
480 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
484 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
486 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
491 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
496 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
497 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
500 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
505 /* Make angles -ve and swap order because we're working with an upside
507 push_lc_numeric("C");
508 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
510 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
513 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
517 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
518 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
522 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
)
526 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(pssetfont
) + strlen(name
) + 40 );
529 WARN("HeapAlloc failed\n");
533 sprintf(buf
, pssetfont
, name
, size
.xx
, size
.xy
, size
.yx
, size
.yy
, -escapement
);
535 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
536 HeapFree( GetProcessHeap(), 0, buf
);
540 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
542 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
545 PSDRV_CopyColor(&physDev
->inkColor
, color
);
546 switch(color
->type
) {
548 push_lc_numeric("C");
549 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
552 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
555 push_lc_numeric("C");
556 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
558 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
561 ERR("Unkonwn colour type %d\n", color
->type
);
568 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
570 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
574 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
575 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
577 if (physDev
->pen
.dash_len
)
579 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
580 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
582 sprintf(buf
+ pos
, "] %u setdash\n", 0);
585 sprintf(buf
, "[] %u setdash\n", 0);
587 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
592 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
597 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
599 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
600 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
604 PSDRV_WriteSpool(dev
, buf
, l
);
608 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
610 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
613 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
615 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
618 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
620 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
623 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
625 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
628 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
630 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
633 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
635 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
638 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
640 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
643 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
645 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
648 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
650 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
653 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
657 push_lc_numeric("C");
658 sprintf(buf
, psrotate
, ang
);
660 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
663 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
666 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
667 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
670 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
672 static const char buf
[] = ">\n] setcolorspace\n";
673 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
676 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
678 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
682 for(i
= 0; i
< number
; i
++) {
683 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
684 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
685 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
688 PSDRV_WriteSpool(dev
, buf
, number
* 7);
689 HeapFree( GetProcessHeap(), 0, buf
);
693 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
695 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
699 for(i
= 0; i
< number
; i
++, rgb
++)
700 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
701 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
703 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
704 HeapFree( GetProcessHeap(), 0, buf
);
708 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
,
709 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
711 static const char start
[] = "<<\n"
712 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
713 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
715 static const char decode1
[] = " /Decode [0 %d]\n";
716 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
718 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
719 static const char endbits
[] = " /DataSource <%s>\n>>\n";
723 sprintf(buf
, start
, widthSrc
, heightSrc
,
724 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
726 sprintf(buf
, start
, widthSrc
, heightSrc
,
727 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
729 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
733 sprintf(buf
, decode1
, 255);
737 sprintf(buf
, decode1
, 15);
741 sprintf(buf
, decode1
, 1);
745 strcpy(buf
, decode3
);
749 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
752 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
754 sprintf(buf
, endbits
, bits
);
755 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
761 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, INT xDst
, INT yDst
,
762 INT widthDst
, INT heightDst
, INT widthSrc
,
763 INT heightSrc
, BOOL mask
, BOOL top_down
)
765 static const char start
[] = "%d %d translate\n%d %d scale\n";
766 static const char image
[] = "image\n";
767 static const char imagemask
[] = "imagemask\n";
770 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
771 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
772 PSDRV_WriteImageDict(dev
, depth
, widthSrc
, heightSrc
, NULL
, top_down
);
774 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
776 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
781 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
783 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
789 for(i
= 0; i
< number
; i
++) {
790 sprintf(ptr
, "%02x", bytes
[i
]);
792 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
797 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
798 HeapFree( GetProcessHeap(), 0, buf
);
802 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
804 int num
, num_left
= number
;
807 num
= min(num_left
, 60);
808 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
809 PSDRV_WriteSpool(dev
, "\n", 1);
817 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
821 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
822 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
825 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
829 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
830 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
833 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
837 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
838 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
841 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
845 sprintf(buf
, psrectclip2
, pszArrayName
);
846 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
849 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
851 static const char mypat
[] = "/mypat\n";
852 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
853 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
854 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
855 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
857 INT w
, h
, x
, y
, w_mult
, h_mult
;
860 TRACE( "size %dx%dx%d\n",
861 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
863 if(bmi
->bmiHeader
.biBitCount
!= 1) {
864 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
868 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
869 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
871 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
873 for(y
= h
-1; y
>= 0; y
--) {
874 for(x
= 0; x
< w
/8; x
++) {
875 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
876 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
880 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
881 PSDRV_WriteImageDict(dev
, 1, 8, 8, buf
, FALSE
);
882 PSDRV_WriteSpool(dev
, "def\n", 4);
884 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
885 map
[0] = GetTextColor( dev
->hdc
);
886 map
[1] = GetBkColor( dev
->hdc
);
887 PSDRV_WriteRGB(dev
, map
, 2);
888 PSDRV_WriteIndexColorSpaceEnd(dev
);
890 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
891 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
892 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
893 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
894 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
895 HeapFree( GetProcessHeap(), 0, buf
);