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 */
51 static const char cups_collate_false
[] = "%cupsJobTicket: collate=false\n";
52 static const char cups_collate_true
[] = "%cupsJobTicket: collate=true\n";
53 static const char cups_ap_d_inputslot
[] = "%cupsJobTicket: AP_D_InputSlot=\n"; /* intentionally empty value */
55 static const char psheader
[] = /* title llx lly urx ury orientation */
56 "%%%%Creator: Wine PostScript Driver\n"
58 "%%%%BoundingBox: %d %d %d %d\n"
59 "%%%%Pages: (atend)\n"
60 "%%%%Orientation: %s\n"
63 static const char psbeginprolog
[] =
66 static const char psendprolog
[] =
69 static const char psprolog
[] =
70 "/tmpmtrx matrix def\n"
73 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
74 " l cvi gap idiv gap mul\n"
76 " r cvi gap idiv gap mul\n"
77 " {t moveto 0 b t sub rlineto}\n"
80 "/B {pop pop pop pop} def\n"
82 "/havetype42gdir {version cvi 2015 ge} bind def\n";
84 static const char psbeginsetup
[] =
87 static const char psendsetup
[] =
90 static const char psbeginfeature
[] = /* feature, value */
92 "%%%%BeginFeature: %s %s\n";
94 static const char psendfeature
[] =
96 "} stopped cleartomark\n";
98 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
100 "%%%%BeginPageSetup\n"
102 "72 %d div 72 %d div scale\n"
106 "%%%%EndPageSetup\n";
108 static const char psendpage
[] =
112 static const char psfooter
[] = /* pages */
117 static const char psmoveto
[] = /* x, y */
120 static const char pslineto
[] = /* x, y */
123 static const char psstroke
[] =
126 static const char psrectangle
[] = /* x, y, width, height, -width */
133 static const char psglyphshow
[] = /* glyph name */
136 static const char psfindfont
[] = /* fontname */
139 static const char psfakeitalic
[] =
140 "[1 0 0.25 1 0 0]\n";
142 static const char pssizematrix
[] =
143 "[%d %d %d %d 0 0]\n";
145 static const char psconcat
[] =
146 "matrix concatmatrix\n";
148 static const char psrotatefont
[] = /* escapement */
149 "%d 10 div matrix rotate\n"
150 "matrix concatmatrix\n";
152 static const char pssetfont
[] =
153 "makefont setfont\n";
155 static const char pssetline
[] = /* width, join, endcap */
156 "%d setlinewidth %u setlinejoin %u setlinecap\n";
158 static const char pssetgray
[] = /* gray */
161 static const char pssetrgbcolor
[] = /* r, g, b */
162 "%.2f %.2f %.2f setrgbcolor\n";
164 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
165 "tmpmtrx currentmatrix pop\n"
168 "0 0 0.5 %.1f %.1f arc\n"
169 "tmpmtrx setmatrix\n";
171 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
172 "%d %d %d %d %d %d curveto\n";
174 static const char psgsave
[] =
177 static const char psgrestore
[] =
180 static const char psfill
[] =
183 static const char pseofill
[] =
186 static const char psnewpath
[] =
189 static const char psclosepath
[] =
192 static const char psclip
[] =
195 static const char pseoclip
[] =
198 static const char psrectclip
[] =
199 "%d %d %d %d rectclip\n";
201 static const char psrectclip2
[] =
204 static const char pshatch
[] =
207 static const char psrotate
[] = /* ang */
210 static const char psarrayput
[] =
213 static const char psarraydef
[] =
214 "/%s %d array def\n";
216 static const char psenddocument
[] =
219 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
221 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
222 int num
, num_left
= cch
;
224 if(physDev
->job
.quiet
) {
225 TRACE("ignoring output\n");
229 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
230 write_spool( dev
, psenddocument
, sizeof(psenddocument
)-1 );
231 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
234 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
235 if( !PSDRV_StartPage(dev
) )
240 num
= min(num_left
, 0x8000);
241 if(write_spool( dev
, lpData
, num
) != num
)
251 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
254 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
255 strlen(feature
) + strlen(value
));
257 sprintf(buf
, psbeginfeature
, feature
, value
);
258 write_spool( dev
, buf
, strlen(buf
) );
259 write_spool( dev
, invocation
, strlen(invocation
) );
260 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
262 HeapFree( GetProcessHeap(), 0, buf
);
266 /********************************************************
269 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
270 * as octal. If we've had to use an escape then surround the entire string
271 * in brackets. Truncate string to represent at most 0x80 characters.
274 static char *escape_title(LPCWSTR wstr
)
276 char *ret
, *cp
, *str
;
281 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
286 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
287 str
= HeapAlloc( GetProcessHeap(), 0, i
);
288 if (!str
) return NULL
;
289 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
291 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
299 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
305 extra
+= 2; /* two for the brackets */
306 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
308 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
312 BYTE b
= (BYTE
)str
[i
];
314 *cp
++ = ((b
>> 6) & 0x7) + '0';
315 *cp
++ = ((b
>> 3) & 0x7) + '0';
316 *cp
++ = ((b
) & 0x7) + '0';
325 HeapFree( GetProcessHeap(), 0, str
);
335 static void write_cups_job_ticket( PHYSDEV dev
, const struct ticket_info
*info
)
337 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
341 if (info
->page
&& info
->page
->InvocationString
)
343 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
344 if (len
<= sizeof(buf
))
346 memcpy( buf
, media
, sizeof(media
) );
347 strcat( buf
, info
->page
->Name
);
349 write_spool( dev
, buf
, len
- 1 );
352 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
355 if (info
->duplex
&& info
->duplex
->InvocationString
)
357 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
359 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
360 write_spool( dev
, str
, strlen( str
) );
364 if (physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1)
366 len
= snprintf( buf
, sizeof(buf
), "%%cupsJobTicket: copies=%d\n",
367 physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
368 if (len
> 0 && len
< sizeof(buf
))
369 write_spool( dev
, buf
, len
);
371 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_COLLATE
)
373 if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_FALSE
)
374 write_spool( dev
, cups_collate_false
, sizeof(cups_collate_false
) - 1 );
375 else if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_TRUE
)
376 write_spool( dev
, cups_collate_true
, sizeof(cups_collate_true
) - 1 );
380 if (!(physDev
->Devmode
->dmPublic
.dmFields
& DM_DEFAULTSOURCE
) ||
381 physDev
->Devmode
->dmPublic
.u1
.s1
.dmDefaultSource
== DMBIN_AUTO
)
382 write_spool( dev
, cups_ap_d_inputslot
, sizeof(cups_ap_d_inputslot
) - 1 );
385 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
387 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
388 char *buf
, *escaped_title
;
389 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
390 PAGESIZE
*page
= find_pagesize( physDev
->pi
->ppd
, physDev
->Devmode
);
391 DUPLEX
*duplex
= find_duplex( physDev
->pi
->ppd
, physDev
->Devmode
);
392 int llx
, lly
, urx
, ury
;
394 const char * dmOrientation
;
396 struct ticket_info ticket_info
= { page
, duplex
};
398 TRACE("%s\n", debugstr_w(title
));
400 len
= strlen( psadobe
);
401 ret
= write_spool( dev
, psadobe
, len
);
404 WARN("WriteSpool error\n");
408 write_cups_job_ticket( dev
, &ticket_info
);
410 escaped_title
= escape_title(title
);
411 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
412 strlen(escaped_title
) + 30 );
414 WARN("HeapAlloc failed\n");
415 HeapFree(GetProcessHeap(), 0, escaped_title
);
419 /* BBox co-ords are in default user co-ord system so urx < ury even in
421 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
422 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
423 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
424 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
425 /* FIXME should do something better with BBox */
427 dmOrientation
= (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
? "Landscape" : "Portrait");
428 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
, dmOrientation
);
430 HeapFree(GetProcessHeap(), 0, escaped_title
);
433 write_spool( dev
, buf
, len
);
434 HeapFree( GetProcessHeap(), 0, buf
);
436 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
437 write_spool( dev
, psprolog
, strlen(psprolog
) );
438 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
439 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
441 if (slot
&& slot
->InvocationString
)
442 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
444 if (page
&& page
->InvocationString
)
445 PSDRV_WriteFeature( dev
, "*PageSize", page
->Name
, page
->InvocationString
);
447 if (duplex
&& duplex
->InvocationString
)
448 PSDRV_WriteFeature( dev
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
450 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
457 INT
PSDRV_WriteFooter( PHYSDEV dev
)
459 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
463 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
465 WARN("HeapAlloc failed\n");
469 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
471 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
472 WARN("WriteSpool error\n");
475 HeapFree( GetProcessHeap(), 0, buf
);
481 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
483 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
484 WARN("WriteSpool error\n");
493 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
495 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
498 signed int xtrans
, ytrans
, rotation
;
501 sprintf(name
, "%d", physDev
->job
.PageNo
);
503 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
505 WARN("HeapAlloc failed\n");
509 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
510 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
511 xtrans
= physDev
->ImageableArea
.right
;
512 ytrans
= physDev
->ImageableArea
.top
;
515 xtrans
= physDev
->ImageableArea
.left
;
516 ytrans
= physDev
->ImageableArea
.bottom
;
520 xtrans
= physDev
->ImageableArea
.left
;
521 ytrans
= physDev
->ImageableArea
.top
;
525 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
526 physDev
->logPixelsX
, physDev
->logPixelsY
,
527 xtrans
, ytrans
, rotation
);
529 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
530 WARN("WriteSpool error\n");
533 HeapFree( GetProcessHeap(), 0, buf
);
538 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
542 sprintf(buf
, psmoveto
, x
, y
);
543 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
546 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
550 sprintf(buf
, pslineto
, x
, y
);
551 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
555 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
557 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
562 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
567 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
568 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
571 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
576 /* Make angles -ve and swap order because we're working with an upside
578 push_lc_numeric("C");
579 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
581 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
584 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
588 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
589 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
592 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
, BOOL fake_italic
)
596 buf
= HeapAlloc( GetProcessHeap(), 0, strlen(name
) + 256 );
599 WARN("HeapAlloc failed\n");
603 sprintf( buf
, psfindfont
, name
);
604 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
606 if (fake_italic
) PSDRV_WriteSpool( dev
, psfakeitalic
, sizeof(psfakeitalic
) - 1 );
608 sprintf( buf
, pssizematrix
, size
.xx
, size
.xy
, size
.yx
, size
.yy
);
609 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
611 if (fake_italic
) PSDRV_WriteSpool( dev
, psconcat
, sizeof(psconcat
) - 1 );
615 sprintf( buf
, psrotatefont
, -escapement
);
616 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
619 PSDRV_WriteSpool( dev
, pssetfont
, sizeof(pssetfont
) - 1 );
620 HeapFree( GetProcessHeap(), 0, buf
);
625 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
627 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
630 PSDRV_CopyColor(&physDev
->inkColor
, color
);
631 switch(color
->type
) {
633 push_lc_numeric("C");
634 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
637 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
640 push_lc_numeric("C");
641 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
643 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
646 ERR("Unknown colour type %d\n", color
->type
);
653 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
655 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
659 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
660 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
662 if (physDev
->pen
.dash_len
)
664 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
665 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
667 sprintf(buf
+ pos
, "] %u setdash\n", 0);
670 sprintf(buf
, "[] %u setdash\n", 0);
672 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
677 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
682 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
684 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
685 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
689 PSDRV_WriteSpool(dev
, buf
, l
);
693 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
695 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
698 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
700 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
703 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
705 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
708 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
710 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
713 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
715 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
718 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
720 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
723 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
725 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
728 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
730 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
733 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
735 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
738 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
742 push_lc_numeric("C");
743 sprintf(buf
, psrotate
, ang
);
745 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
748 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
751 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
752 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
755 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
757 static const char buf
[] = ">\n] setcolorspace\n";
758 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
761 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
763 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
767 for(i
= 0; i
< number
; i
++) {
768 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
769 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
770 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
773 PSDRV_WriteSpool(dev
, buf
, number
* 7);
774 HeapFree( GetProcessHeap(), 0, buf
);
778 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
780 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
784 for(i
= 0; i
< number
; i
++, rgb
++)
785 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
786 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
788 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
789 HeapFree( GetProcessHeap(), 0, buf
);
793 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
, BOOL grayscale
,
794 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
796 static const char start
[] = "<<\n"
797 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
798 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
800 static const char decode1
[] = " /Decode [0 %d]\n";
801 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
803 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
804 static const char endbits
[] = " /DataSource <%s>\n>>\n";
808 sprintf(buf
, start
, widthSrc
, heightSrc
,
809 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
811 sprintf(buf
, start
, widthSrc
, heightSrc
,
812 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
814 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
818 sprintf(buf
, decode1
, 255);
822 sprintf(buf
, decode1
, 15);
826 sprintf(buf
, decode1
, 1);
831 sprintf(buf
, decode1
, 1);
833 strcpy(buf
, decode3
);
837 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
840 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
842 sprintf(buf
, endbits
, bits
);
843 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
849 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, BOOL grayscale
, INT xDst
, INT yDst
,
850 INT widthDst
, INT heightDst
, INT widthSrc
,
851 INT heightSrc
, BOOL mask
, BOOL top_down
)
853 static const char start
[] = "%d %d translate\n%d %d scale\n";
854 static const char image
[] = "image\n";
855 static const char imagemask
[] = "imagemask\n";
858 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
859 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
860 PSDRV_WriteImageDict(dev
, depth
, grayscale
, widthSrc
, heightSrc
, NULL
, top_down
);
862 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
864 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
869 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
871 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
877 for(i
= 0; i
< number
; i
++) {
878 sprintf(ptr
, "%02x", bytes
[i
]);
880 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
885 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
886 HeapFree( GetProcessHeap(), 0, buf
);
890 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
892 int num
, num_left
= number
;
895 num
= min(num_left
, 60);
896 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
897 PSDRV_WriteSpool(dev
, "\n", 1);
905 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
909 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
910 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
913 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
917 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
918 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
921 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
925 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
926 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
929 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
933 sprintf(buf
, psrectclip2
, pszArrayName
);
934 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
937 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
939 static const char mypat
[] = "/mypat\n";
940 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
941 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
942 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
943 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
945 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
948 TRACE( "size %dx%dx%d\n",
949 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
951 if(bmi
->bmiHeader
.biBitCount
!= 1) {
952 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
956 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
957 h
= abs_height
& ~0x7;
959 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
961 for(y
= h
-1; y
>= 0; y
--) {
962 for(x
= 0; x
< w
/8; x
++) {
963 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
964 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
968 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
969 PSDRV_WriteImageDict(dev
, 1, FALSE
, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
970 PSDRV_WriteSpool(dev
, "def\n", 4);
972 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
973 map
[0] = GetTextColor( dev
->hdc
);
974 map
[1] = GetBkColor( dev
->hdc
);
975 PSDRV_WriteRGB(dev
, map
, 2);
976 PSDRV_WriteIndexColorSpaceEnd(dev
);
978 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
979 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
980 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
981 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
982 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
983 HeapFree( GetProcessHeap(), 0, buf
);