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
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
38 static const char psadobe
[] =
41 static const char media
[] = "%cupsJobTicket: media=";
42 static const char cups_one_sided
[] = "%cupsJobTicket: sides=one-sided\n";
43 static const char cups_two_sided_long
[] = "%cupsJobTicket: sides=two-sided-long-edge\n";
44 static const char cups_two_sided_short
[] = "%cupsJobTicket: sides=two-sided-short-edge\n";
45 static const char *cups_duplexes
[3] =
47 cups_one_sided
, /* DMDUP_SIMPLEX */
48 cups_two_sided_long
, /* DMDUP_VERTICAL */
49 cups_two_sided_short
/* DMDUP_HORIZONTAL */
52 static const char psheader
[] = /* title llx lly urx ury */
53 "%%%%Creator: Wine PostScript Driver\n"
55 "%%%%BoundingBox: %d %d %d %d\n"
56 "%%%%Pages: (atend)\n"
59 static const char psbeginprolog
[] =
62 static const char psendprolog
[] =
65 static const char psprolog
[] =
66 "/tmpmtrx matrix def\n"
69 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
70 " l cvi gap idiv gap mul\n"
72 " r cvi gap idiv gap mul\n"
73 " {t moveto 0 b t sub rlineto}\n"
76 "/B {pop pop pop pop} def\n"
78 "/havetype42gdir {version cvi 2015 ge} bind def\n";
80 static const char psbeginsetup
[] =
83 static const char psendsetup
[] =
86 static const char psbeginfeature
[] = /* feature, value */
88 "%%%%BeginFeature: %s %s\n";
90 static const char psendfeature
[] =
92 "} stopped cleartomark\n";
94 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
96 "%%%%BeginPageSetup\n"
98 "72 %d div 72 %d div scale\n"
102 "%%%%EndPageSetup\n";
104 static const char psendpage
[] =
108 static const char psfooter
[] = /* pages */
113 static const char psmoveto
[] = /* x, y */
116 static const char pslineto
[] = /* x, y */
119 static const char psstroke
[] =
122 static const char psrectangle
[] = /* x, y, width, height, -width */
129 static const char psglyphshow
[] = /* glyph name */
132 static const char psfindfont
[] = /* fontname */
135 static const char psfakeitalic
[] =
136 "[1 0 0.25 1 0 0]\n";
138 static const char pssizematrix
[] =
139 "[%d %d %d %d 0 0]\n";
141 static const char psconcat
[] =
142 "matrix concatmatrix\n";
144 static const char psrotatefont
[] = /* escapement */
145 "%d 10 div matrix rotate\n"
146 "matrix concatmatrix\n";
148 static const char pssetfont
[] =
149 "makefont setfont\n";
151 static const char pssetline
[] = /* width, join, endcap */
152 "%d setlinewidth %u setlinejoin %u setlinecap\n";
154 static const char pssetgray
[] = /* gray */
157 static const char pssetrgbcolor
[] = /* r, g, b */
158 "%.2f %.2f %.2f setrgbcolor\n";
160 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
161 "tmpmtrx currentmatrix pop\n"
164 "0 0 0.5 %.1f %.1f arc\n"
165 "tmpmtrx setmatrix\n";
167 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
168 "%d %d %d %d %d %d curveto\n";
170 static const char psgsave
[] =
173 static const char psgrestore
[] =
176 static const char psfill
[] =
179 static const char pseofill
[] =
182 static const char psnewpath
[] =
185 static const char psclosepath
[] =
188 static const char psclip
[] =
191 static const char pseoclip
[] =
194 static const char psrectclip
[] =
195 "%d %d %d %d rectclip\n";
197 static const char psrectclip2
[] =
200 static const char pshatch
[] =
203 static const char psrotate
[] = /* ang */
206 static const char psarrayput
[] =
209 static const char psarraydef
[] =
210 "/%s %d array def\n";
212 static const char psenddocument
[] =
215 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
217 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
218 int num
, num_left
= cch
;
220 if(physDev
->job
.quiet
) {
221 TRACE("ignoring output\n");
225 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
226 write_spool( dev
, psenddocument
, sizeof(psenddocument
)-1 );
227 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
230 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
231 if( !PSDRV_StartPage(dev
) )
236 num
= min(num_left
, 0x8000);
237 if(write_spool( dev
, lpData
, num
) != num
)
247 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
250 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
251 strlen(feature
) + strlen(value
));
253 sprintf(buf
, psbeginfeature
, feature
, value
);
254 write_spool( dev
, buf
, strlen(buf
) );
255 write_spool( dev
, invocation
, strlen(invocation
) );
256 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
258 HeapFree( GetProcessHeap(), 0, buf
);
262 /********************************************************
265 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
266 * as octal. If we've had to use an escape then surround the entire string
267 * in brackets. Truncate string to represent at most 0x80 characters.
270 static char *escape_title(LPCWSTR wstr
)
272 char *ret
, *cp
, *str
;
277 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
282 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
283 str
= HeapAlloc( GetProcessHeap(), 0, i
);
284 if (!str
) return NULL
;
285 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
287 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
295 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
301 extra
+= 2; /* two for the brackets */
302 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
304 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
308 BYTE b
= (BYTE
)str
[i
];
310 *cp
++ = ((b
>> 6) & 0x7) + '0';
311 *cp
++ = ((b
>> 3) & 0x7) + '0';
312 *cp
++ = ((b
) & 0x7) + '0';
321 HeapFree( GetProcessHeap(), 0, str
);
331 static void write_cups_job_ticket( PHYSDEV dev
, const struct ticket_info
*info
)
336 if (info
->page
&& info
->page
->InvocationString
)
338 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
339 if (len
<= sizeof(buf
))
341 memcpy( buf
, media
, sizeof(media
) );
342 strcat( buf
, info
->page
->Name
);
344 write_spool( dev
, buf
, len
- 1 );
347 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
350 if (info
->duplex
&& info
->duplex
->InvocationString
)
352 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
354 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
355 write_spool( dev
, str
, strlen( str
) );
360 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
362 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
363 char *buf
, *escaped_title
;
364 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
365 PAGESIZE
*page
= find_pagesize( physDev
->pi
->ppd
, physDev
->Devmode
);
366 DUPLEX
*duplex
= find_duplex( physDev
->pi
->ppd
, physDev
->Devmode
);
367 int llx
, lly
, urx
, ury
;
369 struct ticket_info ticket_info
= { page
, duplex
};
371 TRACE("%s\n", debugstr_w(title
));
373 len
= strlen( psadobe
);
374 ret
= write_spool( dev
, psadobe
, len
);
377 WARN("WriteSpool error\n");
381 write_cups_job_ticket( dev
, &ticket_info
);
383 escaped_title
= escape_title(title
);
384 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
385 strlen(escaped_title
) + 30 );
387 WARN("HeapAlloc failed\n");
391 /* BBox co-ords are in default user co-ord system so urx < ury even in
393 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
394 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
395 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
396 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
397 /* FIXME should do something better with BBox */
399 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
);
401 HeapFree(GetProcessHeap(), 0, escaped_title
);
404 write_spool( dev
, buf
, len
);
405 HeapFree( GetProcessHeap(), 0, buf
);
407 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
408 write_spool( dev
, psprolog
, strlen(psprolog
) );
409 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
410 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
412 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1) {
413 char copies_buf
[100];
414 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
415 write_spool(dev
, copies_buf
, strlen(copies_buf
));
418 if (slot
&& slot
->InvocationString
)
419 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
421 if (page
&& page
->InvocationString
)
422 PSDRV_WriteFeature( dev
, "*PageSize", page
->Name
, page
->InvocationString
);
424 if (duplex
&& duplex
->InvocationString
)
425 PSDRV_WriteFeature( dev
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
427 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
434 INT
PSDRV_WriteFooter( PHYSDEV dev
)
436 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
440 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
442 WARN("HeapAlloc failed\n");
446 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
448 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
449 WARN("WriteSpool error\n");
452 HeapFree( GetProcessHeap(), 0, buf
);
458 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
460 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
461 WARN("WriteSpool error\n");
470 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
472 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
475 signed int xtrans
, ytrans
, rotation
;
478 sprintf(name
, "%d", physDev
->job
.PageNo
);
480 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
482 WARN("HeapAlloc failed\n");
486 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
487 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
488 xtrans
= physDev
->ImageableArea
.right
;
489 ytrans
= physDev
->ImageableArea
.top
;
492 xtrans
= physDev
->ImageableArea
.left
;
493 ytrans
= physDev
->ImageableArea
.bottom
;
497 xtrans
= physDev
->ImageableArea
.left
;
498 ytrans
= physDev
->ImageableArea
.top
;
502 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
503 physDev
->logPixelsX
, physDev
->logPixelsY
,
504 xtrans
, ytrans
, rotation
);
506 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
507 WARN("WriteSpool error\n");
510 HeapFree( GetProcessHeap(), 0, buf
);
515 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
519 sprintf(buf
, psmoveto
, x
, y
);
520 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
523 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
527 sprintf(buf
, pslineto
, x
, y
);
528 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
532 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
534 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
539 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
544 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
545 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
548 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
553 /* Make angles -ve and swap order because we're working with an upside
555 push_lc_numeric("C");
556 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
558 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
561 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
565 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
566 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
569 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
, BOOL fake_italic
)
573 buf
= HeapAlloc( GetProcessHeap(), 0, strlen(name
) + 256 );
576 WARN("HeapAlloc failed\n");
580 sprintf( buf
, psfindfont
, name
);
581 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
583 if (fake_italic
) PSDRV_WriteSpool( dev
, psfakeitalic
, sizeof(psfakeitalic
) - 1 );
585 sprintf( buf
, pssizematrix
, size
.xx
, size
.xy
, size
.yx
, size
.yy
);
586 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
588 if (fake_italic
) PSDRV_WriteSpool( dev
, psconcat
, sizeof(psconcat
) - 1 );
592 sprintf( buf
, psrotatefont
, -escapement
);
593 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
596 PSDRV_WriteSpool( dev
, pssetfont
, sizeof(pssetfont
) - 1 );
597 HeapFree( GetProcessHeap(), 0, buf
);
602 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
604 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
607 PSDRV_CopyColor(&physDev
->inkColor
, color
);
608 switch(color
->type
) {
610 push_lc_numeric("C");
611 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
614 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
617 push_lc_numeric("C");
618 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
620 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
623 ERR("Unknown colour type %d\n", color
->type
);
630 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
632 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
636 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
637 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
639 if (physDev
->pen
.dash_len
)
641 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
642 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
644 sprintf(buf
+ pos
, "] %u setdash\n", 0);
647 sprintf(buf
, "[] %u setdash\n", 0);
649 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
654 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
659 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
661 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
662 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
666 PSDRV_WriteSpool(dev
, buf
, l
);
670 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
672 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
675 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
677 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
680 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
682 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
685 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
687 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
690 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
692 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
695 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
697 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
700 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
702 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
705 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
707 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
710 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
712 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
715 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
719 push_lc_numeric("C");
720 sprintf(buf
, psrotate
, ang
);
722 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
725 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
728 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
729 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
732 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
734 static const char buf
[] = ">\n] setcolorspace\n";
735 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
738 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
740 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
744 for(i
= 0; i
< number
; i
++) {
745 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
746 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
747 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
750 PSDRV_WriteSpool(dev
, buf
, number
* 7);
751 HeapFree( GetProcessHeap(), 0, buf
);
755 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
757 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
761 for(i
= 0; i
< number
; i
++, rgb
++)
762 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
763 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
765 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
766 HeapFree( GetProcessHeap(), 0, buf
);
770 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
,
771 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
773 static const char start
[] = "<<\n"
774 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
775 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
777 static const char decode1
[] = " /Decode [0 %d]\n";
778 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
780 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
781 static const char endbits
[] = " /DataSource <%s>\n>>\n";
785 sprintf(buf
, start
, widthSrc
, heightSrc
,
786 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
788 sprintf(buf
, start
, widthSrc
, heightSrc
,
789 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
791 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
795 sprintf(buf
, decode1
, 255);
799 sprintf(buf
, decode1
, 15);
803 sprintf(buf
, decode1
, 1);
807 strcpy(buf
, decode3
);
811 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
814 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
816 sprintf(buf
, endbits
, bits
);
817 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
823 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, INT xDst
, INT yDst
,
824 INT widthDst
, INT heightDst
, INT widthSrc
,
825 INT heightSrc
, BOOL mask
, BOOL top_down
)
827 static const char start
[] = "%d %d translate\n%d %d scale\n";
828 static const char image
[] = "image\n";
829 static const char imagemask
[] = "imagemask\n";
832 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
833 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
834 PSDRV_WriteImageDict(dev
, depth
, widthSrc
, heightSrc
, NULL
, top_down
);
836 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
838 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
843 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
845 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
851 for(i
= 0; i
< number
; i
++) {
852 sprintf(ptr
, "%02x", bytes
[i
]);
854 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
859 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
860 HeapFree( GetProcessHeap(), 0, buf
);
864 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
866 int num
, num_left
= number
;
869 num
= min(num_left
, 60);
870 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
871 PSDRV_WriteSpool(dev
, "\n", 1);
879 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
883 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
884 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
887 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
891 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
892 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
895 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
899 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
900 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
903 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
907 sprintf(buf
, psrectclip2
, pszArrayName
);
908 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
911 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
913 static const char mypat
[] = "/mypat\n";
914 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
915 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
916 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
917 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
919 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
922 TRACE( "size %dx%dx%d\n",
923 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
925 if(bmi
->bmiHeader
.biBitCount
!= 1) {
926 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
930 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
931 h
= abs_height
& ~0x7;
933 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
935 for(y
= h
-1; y
>= 0; y
--) {
936 for(x
= 0; x
< w
/8; x
++) {
937 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
938 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
942 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
943 PSDRV_WriteImageDict(dev
, 1, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
944 PSDRV_WriteSpool(dev
, "def\n", 4);
946 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
947 map
[0] = GetTextColor( dev
->hdc
);
948 map
[1] = GetBkColor( dev
->hdc
);
949 PSDRV_WriteRGB(dev
, map
, 2);
950 PSDRV_WriteIndexColorSpaceEnd(dev
);
952 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
953 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
954 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
955 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
956 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
957 HeapFree( GetProcessHeap(), 0, buf
);