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
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
39 static const char psadobe
[] =
42 static const char media
[] = "%cupsJobTicket: media=";
43 static const char cups_one_sided
[] = "%cupsJobTicket: sides=one-sided\n";
44 static const char cups_two_sided_long
[] = "%cupsJobTicket: sides=two-sided-long-edge\n";
45 static const char cups_two_sided_short
[] = "%cupsJobTicket: sides=two-sided-short-edge\n";
46 static const char *cups_duplexes
[3] =
48 cups_one_sided
, /* DMDUP_SIMPLEX */
49 cups_two_sided_long
, /* DMDUP_VERTICAL */
50 cups_two_sided_short
/* DMDUP_HORIZONTAL */
52 static const char cups_collate_false
[] = "%cupsJobTicket: collate=false\n";
53 static const char cups_collate_true
[] = "%cupsJobTicket: collate=true\n";
54 static const char cups_ap_d_inputslot
[] = "%cupsJobTicket: AP_D_InputSlot=\n"; /* intentionally empty value */
56 static const char psheader
[] = /* title llx lly urx ury orientation */
57 "%%%%Creator: Wine PostScript Driver\n"
59 "%%%%BoundingBox: %d %d %d %d\n"
60 "%%%%Pages: (atend)\n"
61 "%%%%Orientation: %s\n"
64 static const char psbeginprolog
[] =
67 static const char psendprolog
[] =
70 static const char psprolog
[] =
71 "/tmpmtrx matrix def\n"
74 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
75 " l cvi gap idiv gap mul\n"
77 " r cvi gap idiv gap mul\n"
78 " {t moveto 0 b t sub rlineto}\n"
81 "/B {pop pop pop pop} def\n"
83 "/havetype42gdir {version cvi 2015 ge} bind def\n";
85 static const char psbeginsetup
[] =
88 static const char psendsetup
[] =
91 static const char psbeginfeature
[] = /* feature, value */
93 "%%%%BeginFeature: %s %s\n";
95 static const char psendfeature
[] =
97 "} stopped cleartomark\n";
99 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
101 "%%%%BeginPageSetup\n"
103 "72 %d div 72 %d div scale\n"
107 "%%%%EndPageSetup\n";
109 static const char psendpage
[] =
113 static const char psfooter
[] = /* pages */
118 static const char psmoveto
[] = /* x, y */
121 static const char pslineto
[] = /* x, y */
124 static const char psstroke
[] =
127 static const char psrectangle
[] = /* x, y, width, height, -width */
134 static const char psglyphshow
[] = /* glyph name */
137 static const char psfindfont
[] = /* fontname */
140 static const char psfakeitalic
[] =
141 "[1 0 0.25 1 0 0]\n";
143 static const char pssizematrix
[] =
144 "[%d %d %d %d 0 0]\n";
146 static const char psconcat
[] =
147 "matrix concatmatrix\n";
149 static const char psrotatefont
[] = /* escapement */
150 "%d 10 div matrix rotate\n"
151 "matrix concatmatrix\n";
153 static const char pssetfont
[] =
154 "makefont setfont\n";
156 static const char pssetline
[] = /* width, join, endcap */
157 "%d setlinewidth %u setlinejoin %u setlinecap\n";
159 static const char pssetgray
[] = /* gray */
162 static const char pssetrgbcolor
[] = /* r, g, b */
163 "%.2f %.2f %.2f setrgbcolor\n";
165 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
166 "tmpmtrx currentmatrix pop\n"
169 "0 0 0.5 %.1f %.1f arc\n"
170 "tmpmtrx setmatrix\n";
172 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
173 "%d %d %d %d %d %d curveto\n";
175 static const char psgsave
[] =
178 static const char psgrestore
[] =
181 static const char psfill
[] =
184 static const char pseofill
[] =
187 static const char psnewpath
[] =
190 static const char psclosepath
[] =
193 static const char psclip
[] =
196 static const char pseoclip
[] =
199 static const char psrectclip
[] =
200 "%d %d %d %d rectclip\n";
202 static const char psrectclip2
[] =
205 static const char pshatch
[] =
208 static const char psrotate
[] = /* ang */
211 static const char psarrayput
[] =
214 static const char psarraydef
[] =
215 "/%s %d array def\n";
217 static const char psbegindocument
[] =
218 "%%BeginDocument: Wine passthrough\n";
219 static const char psenddocument
[] =
222 void passthrough_enter(PHYSDEV dev
)
224 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
226 if (physDev
->job
.passthrough_state
!= passthrough_none
) return;
228 write_spool(dev
, psbegindocument
, sizeof(psbegindocument
) - 1);
229 physDev
->job
.passthrough_state
= passthrough_active
;
232 void passthrough_leave(PHYSDEV dev
)
234 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
236 if (physDev
->job
.passthrough_state
== passthrough_none
) return;
238 write_spool(dev
, psenddocument
, sizeof(psenddocument
) - 1);
239 physDev
->job
.passthrough_state
= passthrough_none
;
242 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
244 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
245 int num
, num_left
= cch
;
247 if(physDev
->job
.quiet
) {
248 TRACE("ignoring output\n");
252 passthrough_leave(dev
);
254 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
255 if( !PSDRV_StartPage(dev
) )
260 num
= min(num_left
, 0x8000);
261 if(write_spool( dev
, lpData
, num
) != num
)
271 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
274 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
275 strlen(feature
) + strlen(value
));
277 sprintf(buf
, psbeginfeature
, feature
, value
);
278 write_spool( dev
, buf
, strlen(buf
) );
279 write_spool( dev
, invocation
, strlen(invocation
) );
280 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
282 HeapFree( GetProcessHeap(), 0, buf
);
286 /********************************************************
289 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
290 * as octal. If we've had to use an escape then surround the entire string
291 * in brackets. Truncate string to represent at most 0x80 characters.
294 static char *escape_title(LPCWSTR wstr
)
296 char *ret
, *cp
, *str
;
301 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
306 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
307 str
= HeapAlloc( GetProcessHeap(), 0, i
);
308 if (!str
) return NULL
;
309 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
311 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
319 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
325 extra
+= 2; /* two for the brackets */
326 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
328 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
332 BYTE b
= (BYTE
)str
[i
];
334 *cp
++ = ((b
>> 6) & 0x7) + '0';
335 *cp
++ = ((b
>> 3) & 0x7) + '0';
336 *cp
++ = ((b
) & 0x7) + '0';
345 HeapFree( GetProcessHeap(), 0, str
);
355 static void write_cups_job_ticket( PHYSDEV dev
, const struct ticket_info
*info
)
357 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
361 if (info
->page
&& info
->page
->InvocationString
)
363 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
364 if (len
<= sizeof(buf
))
366 memcpy( buf
, media
, sizeof(media
) );
367 strcat( buf
, info
->page
->Name
);
369 write_spool( dev
, buf
, len
- 1 );
372 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
375 if (info
->duplex
&& info
->duplex
->InvocationString
)
377 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
379 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
380 write_spool( dev
, str
, strlen( str
) );
384 if (physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1)
386 len
= snprintf( buf
, sizeof(buf
), "%%cupsJobTicket: copies=%d\n",
387 physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
388 if (len
> 0 && len
< sizeof(buf
))
389 write_spool( dev
, buf
, len
);
391 if (physDev
->Devmode
->dmPublic
.dmFields
& DM_COLLATE
)
393 if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_FALSE
)
394 write_spool( dev
, cups_collate_false
, sizeof(cups_collate_false
) - 1 );
395 else if (physDev
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_TRUE
)
396 write_spool( dev
, cups_collate_true
, sizeof(cups_collate_true
) - 1 );
400 if (!(physDev
->Devmode
->dmPublic
.dmFields
& DM_DEFAULTSOURCE
) ||
401 physDev
->Devmode
->dmPublic
.u1
.s1
.dmDefaultSource
== DMBIN_AUTO
)
402 write_spool( dev
, cups_ap_d_inputslot
, sizeof(cups_ap_d_inputslot
) - 1 );
405 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
407 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
408 char *buf
, *escaped_title
;
409 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
410 PAGESIZE
*page
= find_pagesize( physDev
->pi
->ppd
, physDev
->Devmode
);
411 DUPLEX
*duplex
= find_duplex( physDev
->pi
->ppd
, physDev
->Devmode
);
412 int llx
, lly
, urx
, ury
;
414 const char * dmOrientation
;
416 struct ticket_info ticket_info
= { page
, duplex
};
418 TRACE("%s\n", debugstr_w(title
));
420 len
= strlen( psadobe
);
421 ret
= write_spool( dev
, psadobe
, len
);
424 WARN("WriteSpool error\n");
428 write_cups_job_ticket( dev
, &ticket_info
);
430 escaped_title
= escape_title(title
);
431 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
432 strlen(escaped_title
) + 30 );
434 WARN("HeapAlloc failed\n");
435 HeapFree(GetProcessHeap(), 0, escaped_title
);
439 /* BBox co-ords are in default user co-ord system so urx < ury even in
441 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
442 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
443 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
444 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
445 /* FIXME should do something better with BBox */
447 dmOrientation
= (physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
? "Landscape" : "Portrait");
448 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
, dmOrientation
);
450 HeapFree(GetProcessHeap(), 0, escaped_title
);
453 write_spool( dev
, buf
, len
);
454 HeapFree( GetProcessHeap(), 0, buf
);
456 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
457 write_spool( dev
, psprolog
, strlen(psprolog
) );
458 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
459 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
461 if (slot
&& slot
->InvocationString
)
462 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
464 if (page
&& page
->InvocationString
)
465 PSDRV_WriteFeature( dev
, "*PageSize", page
->Name
, page
->InvocationString
);
467 if (duplex
&& duplex
->InvocationString
)
468 PSDRV_WriteFeature( dev
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
470 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
477 INT
PSDRV_WriteFooter( PHYSDEV dev
)
479 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
483 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
485 WARN("HeapAlloc failed\n");
489 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
491 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
492 WARN("WriteSpool error\n");
495 HeapFree( GetProcessHeap(), 0, buf
);
501 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
503 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
504 WARN("WriteSpool error\n");
513 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
515 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
518 signed int xtrans
, ytrans
, rotation
;
521 sprintf(name
, "%d", physDev
->job
.PageNo
);
523 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
525 WARN("HeapAlloc failed\n");
529 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
530 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
531 xtrans
= physDev
->ImageableArea
.right
;
532 ytrans
= physDev
->ImageableArea
.top
;
535 xtrans
= physDev
->ImageableArea
.left
;
536 ytrans
= physDev
->ImageableArea
.bottom
;
540 xtrans
= physDev
->ImageableArea
.left
;
541 ytrans
= physDev
->ImageableArea
.top
;
545 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
546 physDev
->logPixelsX
, physDev
->logPixelsY
,
547 xtrans
, ytrans
, rotation
);
549 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
550 WARN("WriteSpool error\n");
553 HeapFree( GetProcessHeap(), 0, buf
);
558 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
562 sprintf(buf
, psmoveto
, x
, y
);
563 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
566 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
570 sprintf(buf
, pslineto
, x
, y
);
571 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
575 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
577 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
582 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
587 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
588 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
591 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
596 /* Make angles -ve and swap order because we're working with an upside
598 push_lc_numeric("C");
599 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
601 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
604 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
608 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
609 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
612 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
, BOOL fake_italic
)
616 buf
= HeapAlloc( GetProcessHeap(), 0, strlen(name
) + 256 );
619 WARN("HeapAlloc failed\n");
623 sprintf( buf
, psfindfont
, name
);
624 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
626 if (fake_italic
) PSDRV_WriteSpool( dev
, psfakeitalic
, sizeof(psfakeitalic
) - 1 );
628 sprintf( buf
, pssizematrix
, size
.xx
, size
.xy
, size
.yx
, size
.yy
);
629 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
631 if (fake_italic
) PSDRV_WriteSpool( dev
, psconcat
, sizeof(psconcat
) - 1 );
635 sprintf( buf
, psrotatefont
, -escapement
);
636 PSDRV_WriteSpool( dev
, buf
, strlen(buf
) );
639 PSDRV_WriteSpool( dev
, pssetfont
, sizeof(pssetfont
) - 1 );
640 HeapFree( GetProcessHeap(), 0, buf
);
645 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
647 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
650 PSDRV_CopyColor(&physDev
->inkColor
, color
);
651 switch(color
->type
) {
653 push_lc_numeric("C");
654 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
657 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
660 push_lc_numeric("C");
661 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
663 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
666 ERR("Unknown colour type %d\n", color
->type
);
673 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
675 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
679 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
680 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
682 if (physDev
->pen
.dash_len
)
684 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
685 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
687 sprintf(buf
+ pos
, "] %u setdash\n", 0);
690 sprintf(buf
, "[] %u setdash\n", 0);
692 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
697 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
702 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
704 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
705 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
709 PSDRV_WriteSpool(dev
, buf
, l
);
713 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
715 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
718 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
720 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
723 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
725 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
728 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
730 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
733 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
735 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
738 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
740 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
743 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
745 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
748 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
750 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
753 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
755 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
758 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
762 push_lc_numeric("C");
763 sprintf(buf
, psrotate
, ang
);
765 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
768 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
771 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
772 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
775 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
777 static const char buf
[] = ">\n] setcolorspace\n";
778 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
781 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
783 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
787 for(i
= 0; i
< number
; i
++) {
788 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
789 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
790 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
793 PSDRV_WriteSpool(dev
, buf
, number
* 7);
794 HeapFree( GetProcessHeap(), 0, buf
);
798 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
800 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
804 for(i
= 0; i
< number
; i
++, rgb
++)
805 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
806 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
808 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
809 HeapFree( GetProcessHeap(), 0, buf
);
813 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
, BOOL grayscale
,
814 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
816 static const char start
[] = "<<\n"
817 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
818 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
820 static const char decode1
[] = " /Decode [0 %d]\n";
821 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
823 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
824 static const char endbits
[] = " /DataSource <%s>\n>>\n";
828 sprintf(buf
, start
, widthSrc
, heightSrc
,
829 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
831 sprintf(buf
, start
, widthSrc
, heightSrc
,
832 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
834 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
838 sprintf(buf
, decode1
, 255);
842 sprintf(buf
, decode1
, 15);
846 sprintf(buf
, decode1
, 1);
851 sprintf(buf
, decode1
, 1);
853 strcpy(buf
, decode3
);
857 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
860 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
862 sprintf(buf
, endbits
, bits
);
863 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
869 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, BOOL grayscale
, INT xDst
, INT yDst
,
870 INT widthDst
, INT heightDst
, INT widthSrc
,
871 INT heightSrc
, BOOL mask
, BOOL top_down
)
873 static const char start
[] = "%d %d translate\n%d %d scale\n";
874 static const char image
[] = "image\n";
875 static const char imagemask
[] = "imagemask\n";
878 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
879 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
880 PSDRV_WriteImageDict(dev
, depth
, grayscale
, widthSrc
, heightSrc
, NULL
, top_down
);
882 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
884 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
889 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
891 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
897 for(i
= 0; i
< number
; i
++) {
898 sprintf(ptr
, "%02x", bytes
[i
]);
900 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
905 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
906 HeapFree( GetProcessHeap(), 0, buf
);
910 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
912 int num
, num_left
= number
;
915 num
= min(num_left
, 60);
916 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
917 PSDRV_WriteSpool(dev
, "\n", 1);
925 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
929 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
930 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
933 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
937 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
938 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
941 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
945 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
946 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
949 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
953 sprintf(buf
, psrectclip2
, pszArrayName
);
954 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
957 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
959 static const char mypat
[] = "/mypat\n";
960 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
961 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
962 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
963 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
965 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
968 TRACE( "size %dx%dx%d\n",
969 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
971 if(bmi
->bmiHeader
.biBitCount
!= 1) {
972 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
976 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
977 h
= abs_height
& ~0x7;
979 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
981 for(y
= h
-1; y
>= 0; y
--) {
982 for(x
= 0; x
< w
/8; x
++) {
983 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
984 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
988 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
989 PSDRV_WriteImageDict(dev
, 1, FALSE
, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
990 PSDRV_WriteSpool(dev
, "def\n", 4);
992 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
993 map
[0] = GetTextColor( dev
->hdc
);
994 map
[1] = GetBkColor( dev
->hdc
);
995 PSDRV_WriteRGB(dev
, map
, 2);
996 PSDRV_WriteIndexColorSpaceEnd(dev
);
998 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
999 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
1000 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
1001 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
1002 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
1003 HeapFree( GetProcessHeap(), 0, buf
);