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 psbegindocument
[] =
217 "%%BeginDocument: Wine passthrough\n";
218 static const char psenddocument
[] =
221 void passthrough_enter(PHYSDEV dev
)
223 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
225 if (physDev
->job
.passthrough_state
!= passthrough_none
) return;
227 write_spool(dev
, psbegindocument
, sizeof(psbegindocument
) - 1);
228 physDev
->job
.passthrough_state
= passthrough_active
;
231 void passthrough_leave(PHYSDEV dev
)
233 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
235 if (physDev
->job
.passthrough_state
== passthrough_none
) return;
237 write_spool(dev
, psenddocument
, sizeof(psenddocument
) - 1);
238 physDev
->job
.passthrough_state
= passthrough_none
;
241 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
243 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
244 int num
, num_left
= cch
;
246 if(physDev
->job
.quiet
) {
247 TRACE("ignoring output\n");
251 passthrough_leave(dev
);
253 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
254 if( !PSDRV_StartPage(dev
) )
259 num
= min(num_left
, 0x8000);
260 if(write_spool( dev
, lpData
, num
) != num
)
270 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
273 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
274 strlen(feature
) + strlen(value
));
276 sprintf(buf
, psbeginfeature
, feature
, value
);
277 write_spool( dev
, buf
, strlen(buf
) );
278 write_spool( dev
, invocation
, strlen(invocation
) );
279 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
281 HeapFree( GetProcessHeap(), 0, buf
);
285 /********************************************************
288 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
289 * as octal. If we've had to use an escape then surround the entire string
290 * in brackets. Truncate string to represent at most 0x80 characters.
293 static char *escape_title(LPCWSTR wstr
)
295 char *ret
, *cp
, *str
;
300 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
305 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
306 str
= HeapAlloc( GetProcessHeap(), 0, i
);
307 if (!str
) return NULL
;
308 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
310 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
318 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
324 extra
+= 2; /* two for the brackets */
325 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
327 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
331 BYTE b
= (BYTE
)str
[i
];
333 *cp
++ = ((b
>> 6) & 0x7) + '0';
334 *cp
++ = ((b
>> 3) & 0x7) + '0';
335 *cp
++ = ((b
) & 0x7) + '0';
344 HeapFree( GetProcessHeap(), 0, str
);
354 static void write_cups_job_ticket( PHYSDEV dev
, const struct ticket_info
*info
)
356 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
360 if (info
->page
&& info
->page
->InvocationString
)
362 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
363 if (len
<= sizeof(buf
))
365 memcpy( buf
, media
, sizeof(media
) );
366 strcat( buf
, info
->page
->Name
);
368 write_spool( dev
, buf
, len
- 1 );
371 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
374 if (info
->duplex
&& info
->duplex
->InvocationString
)
376 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
378 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
379 write_spool( dev
, str
, strlen( str
) );
383 if (physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1)
385 len
= snprintf( buf
, sizeof(buf
), "%%cupsJobTicket: copies=%d\n",
386 physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
387 if (len
> 0 && len
< sizeof(buf
))
388 write_spool( dev
, buf
, len
);
390 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_COLLATE
)
392 if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_FALSE
)
393 write_spool( dev
, cups_collate_false
, sizeof(cups_collate_false
) - 1 );
394 else if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_TRUE
)
395 write_spool( dev
, cups_collate_true
, sizeof(cups_collate_true
) - 1 );
399 if (!(physDev
->Devmode
->dmPublic
.dmFields
& DM_DEFAULTSOURCE
) ||
400 physDev
->Devmode
->dmPublic
.u1
.s1
.dmDefaultSource
== DMBIN_AUTO
)
401 write_spool( dev
, cups_ap_d_inputslot
, sizeof(cups_ap_d_inputslot
) - 1 );
404 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
406 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
407 char *buf
, *escaped_title
;
408 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
409 PAGESIZE
*page
= find_pagesize( physDev
->pi
->ppd
, physDev
->Devmode
);
410 DUPLEX
*duplex
= find_duplex( physDev
->pi
->ppd
, physDev
->Devmode
);
411 int llx
, lly
, urx
, ury
;
413 const char * dmOrientation
;
415 struct ticket_info ticket_info
= { page
, duplex
};
417 TRACE("%s\n", debugstr_w(title
));
419 len
= strlen( psadobe
);
420 ret
= write_spool( dev
, psadobe
, len
);
423 WARN("WriteSpool error\n");
427 write_cups_job_ticket( dev
, &ticket_info
);
429 escaped_title
= escape_title(title
);
430 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
431 strlen(escaped_title
) + 30 );
433 WARN("HeapAlloc failed\n");
434 HeapFree(GetProcessHeap(), 0, escaped_title
);
438 /* BBox co-ords are in default user co-ord system so urx < ury even in
440 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
441 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
442 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
443 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
444 /* FIXME should do something better with BBox */
446 dmOrientation
= (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
? "Landscape" : "Portrait");
447 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
, dmOrientation
);
449 HeapFree(GetProcessHeap(), 0, escaped_title
);
452 write_spool( dev
, buf
, len
);
453 HeapFree( GetProcessHeap(), 0, buf
);
455 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
456 write_spool( dev
, psprolog
, strlen(psprolog
) );
457 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
458 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
460 if (slot
&& slot
->InvocationString
)
461 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
463 if (page
&& page
->InvocationString
)
464 PSDRV_WriteFeature( dev
, "*PageSize", page
->Name
, page
->InvocationString
);
466 if (duplex
&& duplex
->InvocationString
)
467 PSDRV_WriteFeature( dev
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
469 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
476 INT
PSDRV_WriteFooter( PHYSDEV dev
)
478 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
482 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
484 WARN("HeapAlloc failed\n");
488 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
490 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
491 WARN("WriteSpool error\n");
494 HeapFree( GetProcessHeap(), 0, buf
);
500 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
502 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
503 WARN("WriteSpool error\n");
512 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
514 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
517 signed int xtrans
, ytrans
, rotation
;
520 sprintf(name
, "%d", physDev
->job
.PageNo
);
522 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
524 WARN("HeapAlloc failed\n");
528 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
529 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
530 xtrans
= physDev
->ImageableArea
.right
;
531 ytrans
= physDev
->ImageableArea
.top
;
534 xtrans
= physDev
->ImageableArea
.left
;
535 ytrans
= physDev
->ImageableArea
.bottom
;
539 xtrans
= physDev
->ImageableArea
.left
;
540 ytrans
= physDev
->ImageableArea
.top
;
544 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
545 physDev
->logPixelsX
, physDev
->logPixelsY
,
546 xtrans
, ytrans
, rotation
);
548 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
549 WARN("WriteSpool error\n");
552 HeapFree( GetProcessHeap(), 0, buf
);
557 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
561 sprintf(buf
, psmoveto
, x
, y
);
562 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
565 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
569 sprintf(buf
, pslineto
, x
, y
);
570 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
574 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
576 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
581 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
586 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
587 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
590 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
595 /* Make angles -ve and swap order because we're working with an upside
597 push_lc_numeric("C");
598 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
600 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
603 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
607 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
608 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
611 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
, BOOL fake_italic
)
615 buf
= HeapAlloc( GetProcessHeap(), 0, strlen(name
) + 256 );
618 WARN("HeapAlloc failed\n");
622 sprintf( buf
, psfindfont
, name
);
623 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
625 if (fake_italic
) PSDRV_WriteSpool( dev
, psfakeitalic
, sizeof(psfakeitalic
) - 1 );
627 sprintf( buf
, pssizematrix
, size
.xx
, size
.xy
, size
.yx
, size
.yy
);
628 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
630 if (fake_italic
) PSDRV_WriteSpool( dev
, psconcat
, sizeof(psconcat
) - 1 );
634 sprintf( buf
, psrotatefont
, -escapement
);
635 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
638 PSDRV_WriteSpool( dev
, pssetfont
, sizeof(pssetfont
) - 1 );
639 HeapFree( GetProcessHeap(), 0, buf
);
644 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
646 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
649 PSDRV_CopyColor(&physDev
->inkColor
, color
);
650 switch(color
->type
) {
652 push_lc_numeric("C");
653 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
656 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
659 push_lc_numeric("C");
660 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
662 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
665 ERR("Unknown colour type %d\n", color
->type
);
672 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
674 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
678 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
679 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
681 if (physDev
->pen
.dash_len
)
683 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
684 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
686 sprintf(buf
+ pos
, "] %u setdash\n", 0);
689 sprintf(buf
, "[] %u setdash\n", 0);
691 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
696 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
701 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
703 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
704 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
708 PSDRV_WriteSpool(dev
, buf
, l
);
712 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
714 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
717 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
719 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
722 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
724 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
727 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
729 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
732 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
734 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
737 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
739 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
742 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
744 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
747 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
749 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
752 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
754 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
757 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
761 push_lc_numeric("C");
762 sprintf(buf
, psrotate
, ang
);
764 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
767 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
770 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
771 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
774 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
776 static const char buf
[] = ">\n] setcolorspace\n";
777 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
780 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
782 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
786 for(i
= 0; i
< number
; i
++) {
787 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
788 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
789 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
792 PSDRV_WriteSpool(dev
, buf
, number
* 7);
793 HeapFree( GetProcessHeap(), 0, buf
);
797 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
799 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
803 for(i
= 0; i
< number
; i
++, rgb
++)
804 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
805 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
807 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
808 HeapFree( GetProcessHeap(), 0, buf
);
812 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
, BOOL grayscale
,
813 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
815 static const char start
[] = "<<\n"
816 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
817 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
819 static const char decode1
[] = " /Decode [0 %d]\n";
820 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
822 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
823 static const char endbits
[] = " /DataSource <%s>\n>>\n";
827 sprintf(buf
, start
, widthSrc
, heightSrc
,
828 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
830 sprintf(buf
, start
, widthSrc
, heightSrc
,
831 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
833 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
837 sprintf(buf
, decode1
, 255);
841 sprintf(buf
, decode1
, 15);
845 sprintf(buf
, decode1
, 1);
850 sprintf(buf
, decode1
, 1);
852 strcpy(buf
, decode3
);
856 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
859 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
861 sprintf(buf
, endbits
, bits
);
862 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
868 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, BOOL grayscale
, INT xDst
, INT yDst
,
869 INT widthDst
, INT heightDst
, INT widthSrc
,
870 INT heightSrc
, BOOL mask
, BOOL top_down
)
872 static const char start
[] = "%d %d translate\n%d %d scale\n";
873 static const char image
[] = "image\n";
874 static const char imagemask
[] = "imagemask\n";
877 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
878 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
879 PSDRV_WriteImageDict(dev
, depth
, grayscale
, widthSrc
, heightSrc
, NULL
, top_down
);
881 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
883 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
888 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
890 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
896 for(i
= 0; i
< number
; i
++) {
897 sprintf(ptr
, "%02x", bytes
[i
]);
899 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
904 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
905 HeapFree( GetProcessHeap(), 0, buf
);
909 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
911 int num
, num_left
= number
;
914 num
= min(num_left
, 60);
915 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
916 PSDRV_WriteSpool(dev
, "\n", 1);
924 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
928 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
929 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
932 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
936 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
937 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
940 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
944 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
945 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
948 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
952 sprintf(buf
, psrectclip2
, pszArrayName
);
953 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
956 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
958 static const char mypat
[] = "/mypat\n";
959 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
960 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
961 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
962 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
964 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
967 TRACE( "size %dx%dx%d\n",
968 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
970 if(bmi
->bmiHeader
.biBitCount
!= 1) {
971 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
975 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
976 h
= abs_height
& ~0x7;
978 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
980 for(y
= h
-1; y
>= 0; y
--) {
981 for(x
= 0; x
< w
/8; x
++) {
982 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
983 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
987 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
988 PSDRV_WriteImageDict(dev
, 1, FALSE
, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
989 PSDRV_WriteSpool(dev
, "def\n", 4);
991 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
992 map
[0] = GetTextColor( dev
->hdc
);
993 map
[1] = GetBkColor( dev
->hdc
);
994 PSDRV_WriteRGB(dev
, map
, 2);
995 PSDRV_WriteIndexColorSpaceEnd(dev
);
997 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
998 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
999 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
1000 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
1001 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
1002 HeapFree( GetProcessHeap(), 0, buf
);