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 psadobe
[] =
40 static const char media
[] = "%cupsJobTicket: media=";
41 static const char cups_one_sided
[] = "%cupsJobTicket: sides=one-sided\n";
42 static const char cups_two_sided_long
[] = "%cupsJobTicket: sides=two-sided-long-edge\n";
43 static const char cups_two_sided_short
[] = "%cupsJobTicket: sides=two-sided-short-edge\n";
44 static const char *cups_duplexes
[3] =
46 cups_one_sided
, /* DMDUP_SIMPLEX */
47 cups_two_sided_long
, /* DMDUP_VERTICAL */
48 cups_two_sided_short
/* DMDUP_HORIZONTAL */
51 static const char psheader
[] = /* title llx lly urx ury */
52 "%%%%Creator: Wine PostScript Driver\n"
54 "%%%%BoundingBox: %d %d %d %d\n"
55 "%%%%Pages: (atend)\n"
58 static const char psbeginprolog
[] =
61 static const char psendprolog
[] =
64 static const char psprolog
[] =
65 "/tmpmtrx matrix def\n"
68 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
69 " l cvi gap idiv gap mul\n"
71 " r cvi gap idiv gap mul\n"
72 " {t moveto 0 b t sub rlineto}\n"
75 "/B {pop pop pop pop} def\n"
77 "/havetype42gdir {version cvi 2015 ge} bind def\n";
79 static const char psbeginsetup
[] =
82 static const char psendsetup
[] =
85 static const char psbeginfeature
[] = /* feature, value */
87 "%%%%BeginFeature: %s %s\n";
89 static const char psendfeature
[] =
91 "} stopped cleartomark\n";
93 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
95 "%%%%BeginPageSetup\n"
97 "72 %d div 72 %d div scale\n"
101 "%%%%EndPageSetup\n";
103 static const char psendpage
[] =
107 static const char psfooter
[] = /* pages */
112 static const char psmoveto
[] = /* x, y */
115 static const char pslineto
[] = /* x, y */
118 static const char psstroke
[] =
121 static const char psrectangle
[] = /* x, y, width, height, -width */
128 static const char psglyphshow
[] = /* glyph name */
131 static const char pssetfont
[] = /* fontname, xx_scale, xy_scale, yx_scale, yy_scale, escapement */
133 "[%d %d %d %d 0 0]\n"
134 "%d 10 div matrix rotate\n"
135 "matrix concatmatrix\n"
136 "makefont setfont\n";
138 static const char pssetline
[] = /* width, join, endcap */
139 "%d setlinewidth %u setlinejoin %u setlinecap\n";
141 static const char pssetgray
[] = /* gray */
144 static const char pssetrgbcolor
[] = /* r, g, b */
145 "%.2f %.2f %.2f setrgbcolor\n";
147 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
148 "tmpmtrx currentmatrix pop\n"
151 "0 0 0.5 %.1f %.1f arc\n"
152 "tmpmtrx setmatrix\n";
154 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
155 "%d %d %d %d %d %d curveto\n";
157 static const char psgsave
[] =
160 static const char psgrestore
[] =
163 static const char psfill
[] =
166 static const char pseofill
[] =
169 static const char psnewpath
[] =
172 static const char psclosepath
[] =
175 static const char psclip
[] =
178 static const char pseoclip
[] =
181 static const char psrectclip
[] =
182 "%d %d %d %d rectclip\n";
184 static const char psrectclip2
[] =
187 static const char pshatch
[] =
190 static const char psrotate
[] = /* ang */
193 static const char psarrayput
[] =
196 static const char psarraydef
[] =
197 "/%s %d array def\n";
199 static const char psenddocument
[] =
202 DWORD
PSDRV_WriteSpool(PHYSDEV dev
, LPCSTR lpData
, DWORD cch
)
204 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
205 int num
, num_left
= cch
;
207 if(physDev
->job
.quiet
) {
208 TRACE("ignoring output\n");
212 if(physDev
->job
.in_passthrough
) { /* Was in PASSTHROUGH mode */
213 write_spool( dev
, psenddocument
, sizeof(psenddocument
)-1 );
214 physDev
->job
.in_passthrough
= physDev
->job
.had_passthrough_rect
= FALSE
;
217 if(physDev
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
218 if( !PSDRV_StartPage(dev
) )
223 num
= min(num_left
, 0x8000);
224 if(write_spool( dev
, lpData
, num
) != num
)
234 static INT
PSDRV_WriteFeature(PHYSDEV dev
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
237 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
238 strlen(feature
) + strlen(value
));
240 sprintf(buf
, psbeginfeature
, feature
, value
);
241 write_spool( dev
, buf
, strlen(buf
) );
242 write_spool( dev
, invocation
, strlen(invocation
) );
243 write_spool( dev
, psendfeature
, strlen(psendfeature
) );
245 HeapFree( GetProcessHeap(), 0, buf
);
249 /********************************************************
252 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
253 * as octal. If we've had to use an escape then surround the entire string
254 * in brackets. Truncate string to represent at most 0x80 characters.
257 static char *escape_title(LPCWSTR wstr
)
259 char *ret
, *cp
, *str
;
264 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
269 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
270 str
= HeapAlloc( GetProcessHeap(), 0, i
);
271 if (!str
) return NULL
;
272 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
274 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
282 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
288 extra
+= 2; /* two for the brackets */
289 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
291 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
295 BYTE b
= (BYTE
)str
[i
];
297 *cp
++ = ((b
>> 6) & 0x7) + '0';
298 *cp
++ = ((b
>> 3) & 0x7) + '0';
299 *cp
++ = ((b
) & 0x7) + '0';
308 HeapFree( GetProcessHeap(), 0, str
);
318 static void write_cups_job_ticket( PHYSDEV dev
, const struct ticket_info
*info
)
323 if (info
->page
&& info
->page
->InvocationString
)
325 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
326 if (len
<= sizeof(buf
))
328 memcpy( buf
, media
, sizeof(media
) );
329 strcat( buf
, info
->page
->Name
);
331 write_spool( dev
, buf
, len
- 1 );
334 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
337 if (info
->duplex
&& info
->duplex
->InvocationString
)
339 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
341 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
342 write_spool( dev
, str
, strlen( str
) );
347 INT
PSDRV_WriteHeader( PHYSDEV dev
, LPCWSTR title
)
349 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
350 char *buf
, *escaped_title
;
351 INPUTSLOT
*slot
= find_slot( physDev
->pi
->ppd
, physDev
->Devmode
);
352 PAGESIZE
*page
= find_pagesize( physDev
->pi
->ppd
, physDev
->Devmode
);
353 DUPLEX
*duplex
= find_duplex( physDev
->pi
->ppd
, physDev
->Devmode
);
354 int llx
, lly
, urx
, ury
;
356 struct ticket_info ticket_info
= { page
, duplex
};
358 TRACE("%s\n", debugstr_w(title
));
360 len
= strlen( psadobe
);
361 ret
= write_spool( dev
, psadobe
, len
);
364 WARN("WriteSpool error\n");
368 write_cups_job_ticket( dev
, &ticket_info
);
370 escaped_title
= escape_title(title
);
371 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
372 strlen(escaped_title
) + 30 );
374 WARN("HeapAlloc failed\n");
378 /* BBox co-ords are in default user co-ord system so urx < ury even in
380 llx
= physDev
->ImageableArea
.left
* 72.0 / physDev
->logPixelsX
;
381 lly
= physDev
->ImageableArea
.bottom
* 72.0 / physDev
->logPixelsY
;
382 urx
= physDev
->ImageableArea
.right
* 72.0 / physDev
->logPixelsX
;
383 ury
= physDev
->ImageableArea
.top
* 72.0 / physDev
->logPixelsY
;
384 /* FIXME should do something better with BBox */
386 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
);
388 HeapFree(GetProcessHeap(), 0, escaped_title
);
391 write_spool( dev
, buf
, len
);
392 HeapFree( GetProcessHeap(), 0, buf
);
394 write_spool( dev
, psbeginprolog
, strlen(psbeginprolog
) );
395 write_spool( dev
, psprolog
, strlen(psprolog
) );
396 write_spool( dev
, psendprolog
, strlen(psendprolog
) );
397 write_spool( dev
, psbeginsetup
, strlen(psbeginsetup
) );
399 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
> 1) {
400 char copies_buf
[100];
401 sprintf(copies_buf
, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev
->Devmode
->dmPublic
.u1
.s1
.dmCopies
);
402 write_spool(dev
, copies_buf
, strlen(copies_buf
));
405 if (slot
&& slot
->InvocationString
)
406 PSDRV_WriteFeature( dev
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
408 if (page
&& page
->InvocationString
)
409 PSDRV_WriteFeature( dev
, "*PageSize", page
->Name
, page
->InvocationString
);
411 if (duplex
&& duplex
->InvocationString
)
412 PSDRV_WriteFeature( dev
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
414 write_spool( dev
, psendsetup
, strlen(psendsetup
) );
421 INT
PSDRV_WriteFooter( PHYSDEV dev
)
423 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
427 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
429 WARN("HeapAlloc failed\n");
433 sprintf(buf
, psfooter
, physDev
->job
.PageNo
);
435 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
436 WARN("WriteSpool error\n");
439 HeapFree( GetProcessHeap(), 0, buf
);
445 INT
PSDRV_WriteEndPage( PHYSDEV dev
)
447 if( write_spool( dev
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
448 WARN("WriteSpool error\n");
457 INT
PSDRV_WriteNewPage( PHYSDEV dev
)
459 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
462 signed int xtrans
, ytrans
, rotation
;
465 sprintf(name
, "%d", physDev
->job
.PageNo
);
467 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
469 WARN("HeapAlloc failed\n");
473 if(physDev
->Devmode
->dmPublic
.u1
.s1
.dmOrientation
== DMORIENT_LANDSCAPE
) {
474 if(physDev
->pi
->ppd
->LandscapeOrientation
== -90) {
475 xtrans
= physDev
->ImageableArea
.right
;
476 ytrans
= physDev
->ImageableArea
.top
;
479 xtrans
= physDev
->ImageableArea
.left
;
480 ytrans
= physDev
->ImageableArea
.bottom
;
484 xtrans
= physDev
->ImageableArea
.left
;
485 ytrans
= physDev
->ImageableArea
.top
;
489 sprintf(buf
, psnewpage
, name
, physDev
->job
.PageNo
,
490 physDev
->logPixelsX
, physDev
->logPixelsY
,
491 xtrans
, ytrans
, rotation
);
493 if( write_spool( dev
, buf
, strlen(buf
) ) != strlen(buf
) ) {
494 WARN("WriteSpool error\n");
497 HeapFree( GetProcessHeap(), 0, buf
);
502 BOOL
PSDRV_WriteMoveTo(PHYSDEV dev
, INT x
, INT y
)
506 sprintf(buf
, psmoveto
, x
, y
);
507 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
510 BOOL
PSDRV_WriteLineTo(PHYSDEV dev
, INT x
, INT y
)
514 sprintf(buf
, pslineto
, x
, y
);
515 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
519 BOOL
PSDRV_WriteStroke(PHYSDEV dev
)
521 return PSDRV_WriteSpool(dev
, psstroke
, sizeof(psstroke
)-1);
526 BOOL
PSDRV_WriteRectangle(PHYSDEV dev
, INT x
, INT y
, INT width
,
531 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
532 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
535 BOOL
PSDRV_WriteArc(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
, double ang1
,
540 /* Make angles -ve and swap order because we're working with an upside
542 push_lc_numeric("C");
543 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
545 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
548 BOOL
PSDRV_WriteCurveTo(PHYSDEV dev
, POINT pts
[3])
552 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
553 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
557 BOOL
PSDRV_WriteSetFont(PHYSDEV dev
, const char *name
, matrix size
, INT escapement
)
561 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(pssetfont
) + strlen(name
) + 40 );
564 WARN("HeapAlloc failed\n");
568 sprintf(buf
, pssetfont
, name
, size
.xx
, size
.xy
, size
.yx
, size
.yy
, -escapement
);
570 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
571 HeapFree( GetProcessHeap(), 0, buf
);
575 BOOL
PSDRV_WriteSetColor(PHYSDEV dev
, PSCOLOR
*color
)
577 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
580 PSDRV_CopyColor(&physDev
->inkColor
, color
);
581 switch(color
->type
) {
583 push_lc_numeric("C");
584 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
587 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
590 push_lc_numeric("C");
591 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
593 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
596 ERR("Unknown colour type %d\n", color
->type
);
603 BOOL
PSDRV_WriteSetPen(PHYSDEV dev
)
605 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
609 sprintf(buf
, pssetline
, physDev
->pen
.width
, physDev
->pen
.join
, physDev
->pen
.endcap
);
610 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
612 if (physDev
->pen
.dash_len
)
614 for (i
= pos
= 0; i
< physDev
->pen
.dash_len
; i
++)
615 pos
+= sprintf( buf
+ pos
, " %u", physDev
->pen
.dash
[i
] );
617 sprintf(buf
+ pos
, "] %u setdash\n", 0);
620 sprintf(buf
, "[] %u setdash\n", 0);
622 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
627 BOOL
PSDRV_WriteGlyphShow(PHYSDEV dev
, LPCSTR g_name
)
632 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
634 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
635 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
639 PSDRV_WriteSpool(dev
, buf
, l
);
643 BOOL
PSDRV_WriteFill(PHYSDEV dev
)
645 return PSDRV_WriteSpool(dev
, psfill
, sizeof(psfill
)-1);
648 BOOL
PSDRV_WriteEOFill(PHYSDEV dev
)
650 return PSDRV_WriteSpool(dev
, pseofill
, sizeof(pseofill
)-1);
653 BOOL
PSDRV_WriteGSave(PHYSDEV dev
)
655 return PSDRV_WriteSpool(dev
, psgsave
, sizeof(psgsave
)-1);
658 BOOL
PSDRV_WriteGRestore(PHYSDEV dev
)
660 return PSDRV_WriteSpool(dev
, psgrestore
, sizeof(psgrestore
)-1);
663 BOOL
PSDRV_WriteNewPath(PHYSDEV dev
)
665 return PSDRV_WriteSpool(dev
, psnewpath
, sizeof(psnewpath
)-1);
668 BOOL
PSDRV_WriteClosePath(PHYSDEV dev
)
670 return PSDRV_WriteSpool(dev
, psclosepath
, sizeof(psclosepath
)-1);
673 BOOL
PSDRV_WriteClip(PHYSDEV dev
)
675 return PSDRV_WriteSpool(dev
, psclip
, sizeof(psclip
)-1);
678 BOOL
PSDRV_WriteEOClip(PHYSDEV dev
)
680 return PSDRV_WriteSpool(dev
, pseoclip
, sizeof(pseoclip
)-1);
683 BOOL
PSDRV_WriteHatch(PHYSDEV dev
)
685 return PSDRV_WriteSpool(dev
, pshatch
, sizeof(pshatch
)-1);
688 BOOL
PSDRV_WriteRotate(PHYSDEV dev
, float ang
)
692 push_lc_numeric("C");
693 sprintf(buf
, psrotate
, ang
);
695 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
698 BOOL
PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev
, int size
)
701 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
702 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
705 BOOL
PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev
)
707 static const char buf
[] = ">\n] setcolorspace\n";
708 return PSDRV_WriteSpool(dev
, buf
, sizeof(buf
) - 1);
711 static BOOL
PSDRV_WriteRGB(PHYSDEV dev
, COLORREF
*map
, int number
)
713 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
717 for(i
= 0; i
< number
; i
++) {
718 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
719 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
720 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
723 PSDRV_WriteSpool(dev
, buf
, number
* 7);
724 HeapFree( GetProcessHeap(), 0, buf
);
728 BOOL
PSDRV_WriteRGBQUAD(PHYSDEV dev
, const RGBQUAD
*rgb
, int number
)
730 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
734 for(i
= 0; i
< number
; i
++, rgb
++)
735 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
736 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
738 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
739 HeapFree( GetProcessHeap(), 0, buf
);
743 static BOOL
PSDRV_WriteImageDict(PHYSDEV dev
, WORD depth
,
744 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
746 static const char start
[] = "<<\n"
747 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
748 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
750 static const char decode1
[] = " /Decode [0 %d]\n";
751 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
753 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
754 static const char endbits
[] = " /DataSource <%s>\n>>\n";
758 sprintf(buf
, start
, widthSrc
, heightSrc
,
759 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
761 sprintf(buf
, start
, widthSrc
, heightSrc
,
762 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
764 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
768 sprintf(buf
, decode1
, 255);
772 sprintf(buf
, decode1
, 15);
776 sprintf(buf
, decode1
, 1);
780 strcpy(buf
, decode3
);
784 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
787 PSDRV_WriteSpool(dev
, end
, sizeof(end
) - 1);
789 sprintf(buf
, endbits
, bits
);
790 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
796 BOOL
PSDRV_WriteImage(PHYSDEV dev
, WORD depth
, INT xDst
, INT yDst
,
797 INT widthDst
, INT heightDst
, INT widthSrc
,
798 INT heightSrc
, BOOL mask
, BOOL top_down
)
800 static const char start
[] = "%d %d translate\n%d %d scale\n";
801 static const char image
[] = "image\n";
802 static const char imagemask
[] = "imagemask\n";
805 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
806 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
807 PSDRV_WriteImageDict(dev
, depth
, widthSrc
, heightSrc
, NULL
, top_down
);
809 PSDRV_WriteSpool(dev
, imagemask
, sizeof(imagemask
) - 1);
811 PSDRV_WriteSpool(dev
, image
, sizeof(image
) - 1);
816 BOOL
PSDRV_WriteBytes(PHYSDEV dev
, const BYTE
*bytes
, DWORD number
)
818 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
824 for(i
= 0; i
< number
; i
++) {
825 sprintf(ptr
, "%02x", bytes
[i
]);
827 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
832 PSDRV_WriteSpool(dev
, buf
, ptr
- buf
);
833 HeapFree( GetProcessHeap(), 0, buf
);
837 BOOL
PSDRV_WriteData(PHYSDEV dev
, const BYTE
*data
, DWORD number
)
839 int num
, num_left
= number
;
842 num
= min(num_left
, 60);
843 PSDRV_WriteSpool(dev
, (LPCSTR
)data
, num
);
844 PSDRV_WriteSpool(dev
, "\n", 1);
852 BOOL
PSDRV_WriteArrayPut(PHYSDEV dev
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
856 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
857 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
860 BOOL
PSDRV_WriteArrayDef(PHYSDEV dev
, CHAR
*pszArrayName
, INT nSize
)
864 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
865 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
868 BOOL
PSDRV_WriteRectClip(PHYSDEV dev
, INT x
, INT y
, INT w
, INT h
)
872 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
873 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
876 BOOL
PSDRV_WriteRectClip2(PHYSDEV dev
, CHAR
*pszArrayName
)
880 sprintf(buf
, psrectclip2
, pszArrayName
);
881 return PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
884 BOOL
PSDRV_WriteDIBPatternDict(PHYSDEV dev
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
886 static const char mypat
[] = "/mypat\n";
887 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
888 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
889 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
890 PSDRV_PDEVICE
*physDev
= get_psdrv_dev( dev
);
892 INT w
, h
, x
, y
, w_mult
, h_mult
;
895 TRACE( "size %dx%dx%d\n",
896 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
898 if(bmi
->bmiHeader
.biBitCount
!= 1) {
899 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
903 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
904 h
= bmi
->bmiHeader
.biHeight
& ~0x7;
906 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(do_pattern
) + 100 );
908 for(y
= h
-1; y
>= 0; y
--) {
909 for(x
= 0; x
< w
/8; x
++) {
910 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
911 (bmi
->bmiHeader
.biWidth
+ 31) / 32 * 4));
915 PSDRV_WriteSpool(dev
, mypat
, sizeof(mypat
) - 1);
916 PSDRV_WriteImageDict(dev
, 1, 8, 8, buf
, FALSE
);
917 PSDRV_WriteSpool(dev
, "def\n", 4);
919 PSDRV_WriteIndexColorSpaceBegin(dev
, 1);
920 map
[0] = GetTextColor( dev
->hdc
);
921 map
[1] = GetBkColor( dev
->hdc
);
922 PSDRV_WriteRGB(dev
, map
, 2);
923 PSDRV_WriteIndexColorSpaceEnd(dev
);
925 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
926 w_mult
= (physDev
->logPixelsX
+ 150) / 300;
927 h_mult
= (physDev
->logPixelsY
+ 150) / 300;
928 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
929 PSDRV_WriteSpool(dev
, buf
, strlen(buf
));
930 HeapFree( GetProcessHeap(), 0, buf
);