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
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 */
50 static const char cups_collate_false
[] = "%cupsJobTicket: collate=false\n";
51 static const char cups_collate_true
[] = "%cupsJobTicket: collate=true\n";
52 static const char cups_ap_d_inputslot
[] = "%cupsJobTicket: AP_D_InputSlot=\n"; /* intentionally empty value */
54 static const char psheader
[] = /* title llx lly urx ury orientation */
55 "%%%%Creator: Wine PostScript Driver\n"
57 "%%%%BoundingBox: %d %d %d %d\n"
58 "%%%%Pages: (atend)\n"
59 "%%%%Orientation: %s\n"
62 static const char psbeginprolog
[] =
65 static const char psendprolog
[] =
68 static const char psprolog
[] =
69 "/tmpmtrx matrix def\n"
72 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
73 " l cvi gap idiv gap mul\n"
75 " r cvi gap idiv gap mul\n"
76 " {t moveto 0 b t sub rlineto}\n"
79 "/B {pop pop pop pop} def\n"
81 "/havetype42gdir {version cvi 2015 ge} bind def\n";
83 static const char psbeginsetup
[] =
86 static const char psendsetup
[] =
89 static const char psbeginfeature
[] = /* feature, value */
91 "%%%%BeginFeature: %s %s\n";
93 static const char psendfeature
[] =
95 "} stopped cleartomark\n";
97 static const char psnewpage
[] = /* name, number, xres, yres, xtrans, ytrans, rot */
99 "%%%%BeginPageSetup\n"
101 "72 %d div 72 %d div scale\n"
105 "%%%%EndPageSetup\n";
107 static const char psendpage
[] =
111 static const char psfooter
[] = /* pages */
116 static const char psmoveto
[] = /* x, y */
119 static const char pslineto
[] = /* x, y */
122 static const char psstroke
[] =
125 static const char psrectangle
[] = /* x, y, width, height, -width */
132 static const char psglyphshow
[] = /* glyph name */
135 static const char psfindfont
[] = /* fontname */
138 static const char psfakeitalic
[] =
139 "[1 0 0.25 1 0 0]\n";
141 static const char pssizematrix
[] =
142 "[%d %d %d %d 0 0]\n";
144 static const char psconcat
[] =
145 "matrix concatmatrix\n";
147 static const char psrotatefont
[] = /* escapement */
148 "%d 10 div matrix rotate\n"
149 "matrix concatmatrix\n";
151 static const char pssetfont
[] =
152 "makefont setfont\n";
154 static const char pssetline
[] = /* width, join, endcap */
155 "%d setlinewidth %u setlinejoin %u setlinecap\n";
157 static const char pssetgray
[] = /* gray */
160 static const char pssetrgbcolor
[] = /* r, g, b */
161 "%.2f %.2f %.2f setrgbcolor\n";
163 static const char psarc
[] = /* x, y, w, h, ang1, ang2 */
164 "tmpmtrx currentmatrix pop\n"
167 "0 0 0.5 %.1f %.1f arc\n"
168 "tmpmtrx setmatrix\n";
170 static const char pscurveto
[] = /* x1, y1, x2, y2, x3, y3 */
171 "%ld %ld %ld %ld %ld %ld curveto\n";
173 static const char psgsave
[] =
176 static const char psgrestore
[] =
179 static const char psfill
[] =
182 static const char pseofill
[] =
185 static const char psnewpath
[] =
188 static const char psclosepath
[] =
191 static const char psclip
[] =
194 static const char pseoclip
[] =
197 static const char psrectclip
[] =
198 "%d %d %d %d rectclip\n";
200 static const char psrectclip2
[] =
203 static const char pshatch
[] =
206 static const char psrotate
[] = /* ang */
209 static const char psarrayput
[] =
212 static const char psarraydef
[] =
213 "/%s %d array def\n";
215 static const char psbegindocument
[] =
216 "%%BeginDocument: Wine passthrough\n";
217 static const char psenddocument
[] =
220 void passthrough_enter(print_ctx
*ctx
)
222 if (ctx
->job
.passthrough_state
!= passthrough_none
) return;
224 write_spool(ctx
, psbegindocument
, sizeof(psbegindocument
) - 1);
225 ctx
->job
.passthrough_state
= passthrough_active
;
228 void passthrough_leave(print_ctx
*ctx
)
230 if (ctx
->job
.passthrough_state
== passthrough_none
) return;
232 write_spool(ctx
, psenddocument
, sizeof(psenddocument
) - 1);
233 ctx
->job
.passthrough_state
= passthrough_none
;
236 DWORD
PSDRV_WriteSpool(print_ctx
*ctx
, LPCSTR lpData
, DWORD cch
)
238 int num
, num_left
= cch
;
241 TRACE("ignoring output\n");
245 passthrough_leave(ctx
);
247 if(ctx
->job
.OutOfPage
) { /* Will get here after NEWFRAME Escape */
248 if( !PSDRV_StartPage(ctx
) )
253 num
= min(num_left
, 0x8000);
254 if(write_spool( ctx
, lpData
, num
) != num
)
264 static INT
PSDRV_WriteFeature(print_ctx
*ctx
, LPCSTR feature
, LPCSTR value
, LPCSTR invocation
)
267 char *buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psbeginfeature
) +
268 strlen(feature
) + strlen(value
));
270 sprintf(buf
, psbeginfeature
, feature
, value
);
271 write_spool( ctx
, buf
, strlen(buf
) );
272 write_spool( ctx
, invocation
, strlen(invocation
) );
273 write_spool( ctx
, psendfeature
, strlen(psendfeature
) );
275 HeapFree( GetProcessHeap(), 0, buf
);
279 /********************************************************
282 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
283 * as octal. If we've had to use an escape then surround the entire string
284 * in brackets. Truncate string to represent at most 0x80 characters.
287 static char *escape_title(LPCWSTR wstr
)
289 char *ret
, *cp
, *str
;
294 ret
= HeapAlloc(GetProcessHeap(), 0, 1);
299 i
= WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
300 str
= HeapAlloc( GetProcessHeap(), 0, i
);
301 if (!str
) return NULL
;
302 WideCharToMultiByte( CP_ACP
, 0, wstr
, -1, str
, i
, NULL
, NULL
);
304 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
312 ret
= HeapAlloc(GetProcessHeap(), 0, i
+ 1);
318 extra
+= 2; /* two for the brackets */
319 cp
= ret
= HeapAlloc(GetProcessHeap(), 0, i
+ extra
+ 1);
321 for(i
= 0; i
< 0x80 && str
[i
]; i
++)
325 BYTE b
= (BYTE
)str
[i
];
327 *cp
++ = ((b
>> 6) & 0x7) + '0';
328 *cp
++ = ((b
>> 3) & 0x7) + '0';
329 *cp
++ = ((b
) & 0x7) + '0';
338 HeapFree( GetProcessHeap(), 0, str
);
348 static void write_cups_job_ticket( print_ctx
*ctx
, const struct ticket_info
*info
)
353 if (info
->page
&& info
->page
->InvocationString
)
355 len
= sizeof(media
) + strlen( info
->page
->Name
) + 1;
356 if (len
<= sizeof(buf
))
358 memcpy( buf
, media
, sizeof(media
) );
359 strcat( buf
, info
->page
->Name
);
361 write_spool( ctx
, buf
, len
- 1 );
364 WARN( "paper name %s will be too long for DSC\n", info
->page
->Name
);
367 if (info
->duplex
&& info
->duplex
->InvocationString
)
369 if (info
->duplex
->WinDuplex
>= 1 && info
->duplex
->WinDuplex
<= 3)
371 const char *str
= cups_duplexes
[ info
->duplex
->WinDuplex
- 1 ];
372 write_spool( ctx
, str
, strlen( str
) );
376 if (ctx
->Devmode
->dmPublic
.dmCopies
> 1)
378 len
= snprintf( buf
, sizeof(buf
), "%%cupsJobTicket: copies=%d\n",
379 ctx
->Devmode
->dmPublic
.dmCopies
);
380 if (len
> 0 && len
< sizeof(buf
))
381 write_spool( ctx
, buf
, len
);
383 if (ctx
->Devmode
->dmPublic
.dmFields
& DM_COLLATE
)
385 if (ctx
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_FALSE
)
386 write_spool( ctx
, cups_collate_false
, sizeof(cups_collate_false
) - 1 );
387 else if (ctx
->Devmode
->dmPublic
.dmCollate
== DMCOLLATE_TRUE
)
388 write_spool( ctx
, cups_collate_true
, sizeof(cups_collate_true
) - 1 );
392 if (!(ctx
->Devmode
->dmPublic
.dmFields
& DM_DEFAULTSOURCE
) ||
393 ctx
->Devmode
->dmPublic
.dmDefaultSource
== DMBIN_AUTO
)
394 write_spool( ctx
, cups_ap_d_inputslot
, sizeof(cups_ap_d_inputslot
) - 1 );
397 INT
PSDRV_WriteHeader( print_ctx
*ctx
, LPCWSTR title
)
399 char *buf
, *escaped_title
;
400 INPUTSLOT
*slot
= find_slot( ctx
->pi
->ppd
, &ctx
->Devmode
->dmPublic
);
401 PAGESIZE
*page
= find_pagesize( ctx
->pi
->ppd
, &ctx
->Devmode
->dmPublic
);
402 DUPLEX
*duplex
= find_duplex( ctx
->pi
->ppd
, &ctx
->Devmode
->dmPublic
);
403 int llx
, lly
, urx
, ury
;
405 const char * dmOrientation
;
407 struct ticket_info ticket_info
= { page
, duplex
};
409 TRACE("%s\n", debugstr_w(title
));
411 len
= strlen( psadobe
);
412 ret
= write_spool( ctx
, psadobe
, len
);
415 WARN("WriteSpool error\n");
419 write_cups_job_ticket( ctx
, &ticket_info
);
421 escaped_title
= escape_title(title
);
422 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psheader
) +
423 strlen(escaped_title
) + 30 );
425 WARN("HeapAlloc failed\n");
426 HeapFree(GetProcessHeap(), 0, escaped_title
);
430 /* BBox co-ords are in default user co-ord system so urx < ury even in
432 if ((ctx
->Devmode
->dmPublic
.dmFields
& DM_PAPERSIZE
) && page
)
434 if (page
->ImageableArea
)
436 llx
= page
->ImageableArea
->llx
;
437 lly
= page
->ImageableArea
->lly
;
438 urx
= page
->ImageableArea
->urx
;
439 ury
= page
->ImageableArea
->ury
;
444 urx
= page
->PaperDimension
->x
;
445 ury
= page
->PaperDimension
->y
;
448 else if ((ctx
->Devmode
->dmPublic
.dmFields
& DM_PAPERLENGTH
) &&
449 (ctx
->Devmode
->dmPublic
.dmFields
& DM_PAPERWIDTH
))
451 /* Devmode sizes in 1/10 mm */
453 urx
= ctx
->Devmode
->dmPublic
.dmPaperWidth
* 72.0 / 254.0;
454 ury
= ctx
->Devmode
->dmPublic
.dmPaperLength
* 72.0 / 254.0;
458 llx
= lly
= urx
= ury
= 0;
460 /* FIXME should do something better with BBox */
462 dmOrientation
= (ctx
->Devmode
->dmPublic
.dmOrientation
== DMORIENT_LANDSCAPE
? "Landscape" : "Portrait");
463 sprintf(buf
, psheader
, escaped_title
, llx
, lly
, urx
, ury
, dmOrientation
);
465 HeapFree(GetProcessHeap(), 0, escaped_title
);
468 write_spool( ctx
, buf
, len
);
469 HeapFree( GetProcessHeap(), 0, buf
);
471 write_spool( ctx
, psbeginprolog
, strlen(psbeginprolog
) );
472 write_spool( ctx
, psprolog
, strlen(psprolog
) );
473 write_spool( ctx
, psendprolog
, strlen(psendprolog
) );
474 write_spool( ctx
, psbeginsetup
, strlen(psbeginsetup
) );
476 if (slot
&& slot
->InvocationString
)
477 PSDRV_WriteFeature( ctx
, "*InputSlot", slot
->Name
, slot
->InvocationString
);
479 if (page
&& page
->InvocationString
)
480 PSDRV_WriteFeature( ctx
, "*PageSize", page
->Name
, page
->InvocationString
);
482 if (duplex
&& duplex
->InvocationString
)
483 PSDRV_WriteFeature( ctx
, "*Duplex", duplex
->Name
, duplex
->InvocationString
);
485 write_spool( ctx
, psendsetup
, strlen(psendsetup
) );
492 INT
PSDRV_WriteFooter( print_ctx
*ctx
)
497 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psfooter
) + 100 );
499 WARN("HeapAlloc failed\n");
503 sprintf(buf
, psfooter
, ctx
->job
.PageNo
);
505 if( write_spool( ctx
, buf
, strlen(buf
) ) != strlen(buf
) ) {
506 WARN("WriteSpool error\n");
509 HeapFree( GetProcessHeap(), 0, buf
);
515 INT
PSDRV_WriteEndPage( print_ctx
*ctx
)
517 if( write_spool( ctx
, psendpage
, sizeof(psendpage
)-1 ) != sizeof(psendpage
)-1 ) {
518 WARN("WriteSpool error\n");
527 INT
PSDRV_WriteNewPage( print_ctx
*ctx
)
531 signed int xtrans
, ytrans
, rotation
;
534 sprintf(name
, "%d", ctx
->job
.PageNo
);
536 buf
= HeapAlloc( GetProcessHeap(), 0, sizeof(psnewpage
) + 200 );
538 WARN("HeapAlloc failed\n");
542 if(ctx
->Devmode
->dmPublic
.dmOrientation
== DMORIENT_LANDSCAPE
) {
543 if(ctx
->pi
->ppd
->LandscapeOrientation
== -90) {
544 xtrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALHEIGHT
) -
545 GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETY
);
546 ytrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALWIDTH
) -
547 GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETX
);
550 xtrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETY
);
551 ytrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETX
);
555 xtrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETX
);
556 ytrans
= GetDeviceCaps(ctx
->hdc
, PHYSICALHEIGHT
) -
557 GetDeviceCaps(ctx
->hdc
, PHYSICALOFFSETY
);
561 sprintf(buf
, psnewpage
, name
, ctx
->job
.PageNo
,
562 GetDeviceCaps(ctx
->hdc
, ASPECTX
), GetDeviceCaps(ctx
->hdc
, ASPECTY
),
563 xtrans
, ytrans
, rotation
);
565 if( write_spool( ctx
, buf
, strlen(buf
) ) != strlen(buf
) ) {
566 WARN("WriteSpool error\n");
569 HeapFree( GetProcessHeap(), 0, buf
);
574 BOOL
PSDRV_WriteMoveTo(print_ctx
*ctx
, INT x
, INT y
)
578 sprintf(buf
, psmoveto
, x
, y
);
579 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
582 BOOL
PSDRV_WriteLineTo(print_ctx
*ctx
, INT x
, INT y
)
586 sprintf(buf
, pslineto
, x
, y
);
587 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
591 BOOL
PSDRV_WriteStroke(print_ctx
*ctx
)
593 return PSDRV_WriteSpool(ctx
, psstroke
, sizeof(psstroke
)-1);
598 BOOL
PSDRV_WriteRectangle(print_ctx
*ctx
, INT x
, INT y
, INT width
,
603 sprintf(buf
, psrectangle
, x
, y
, width
, height
, -width
);
604 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
607 BOOL
PSDRV_WriteArc(print_ctx
*ctx
, INT x
, INT y
, INT w
, INT h
, double ang1
,
612 /* Make angles -ve and swap order because we're working with an upside
614 push_lc_numeric("C");
615 sprintf(buf
, psarc
, x
, y
, w
, h
, -ang2
, -ang1
);
617 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
620 BOOL
PSDRV_WriteCurveTo(print_ctx
*ctx
, POINT pts
[3])
624 sprintf(buf
, pscurveto
, pts
[0].x
, pts
[0].y
, pts
[1].x
, pts
[1].y
, pts
[2].x
, pts
[2].y
);
625 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
628 BOOL
PSDRV_WriteSetFont(print_ctx
*ctx
, const char *name
, matrix size
, INT escapement
, BOOL fake_italic
)
632 buf
= HeapAlloc( GetProcessHeap(), 0, strlen(name
) + 256 );
635 WARN("HeapAlloc failed\n");
639 sprintf( buf
, psfindfont
, name
);
640 PSDRV_WriteSpool( ctx
, buf
, strlen(buf
) );
642 if (fake_italic
) PSDRV_WriteSpool( ctx
, psfakeitalic
, sizeof(psfakeitalic
) - 1 );
644 sprintf( buf
, pssizematrix
, size
.xx
, size
.xy
, size
.yx
, size
.yy
);
645 PSDRV_WriteSpool( ctx
, buf
, strlen(buf
) );
647 if (fake_italic
) PSDRV_WriteSpool( ctx
, psconcat
, sizeof(psconcat
) - 1 );
651 sprintf( buf
, psrotatefont
, -escapement
);
652 PSDRV_WriteSpool( ctx
, buf
, strlen(buf
) );
655 PSDRV_WriteSpool( ctx
, pssetfont
, sizeof(pssetfont
) - 1 );
656 HeapFree( GetProcessHeap(), 0, buf
);
661 BOOL
PSDRV_WriteSetColor(print_ctx
*ctx
, PSCOLOR
*color
)
665 switch(color
->type
) {
667 push_lc_numeric("C");
668 sprintf(buf
, pssetrgbcolor
, color
->value
.rgb
.r
, color
->value
.rgb
.g
,
671 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
674 push_lc_numeric("C");
675 sprintf(buf
, pssetgray
, color
->value
.gray
.i
);
677 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
680 ERR("Unknown colour type %d\n", color
->type
);
687 BOOL
PSDRV_WriteSetPen(print_ctx
*ctx
)
692 sprintf(buf
, pssetline
, ctx
->pen
.width
, ctx
->pen
.join
, ctx
->pen
.endcap
);
693 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
695 if (ctx
->pen
.dash_len
)
697 for (i
= pos
= 0; i
< ctx
->pen
.dash_len
; i
++)
698 pos
+= sprintf( buf
+ pos
, " %lu", ctx
->pen
.dash
[i
] );
700 sprintf(buf
+ pos
, "] %u setdash\n", 0);
703 sprintf(buf
, "[] %u setdash\n", 0);
705 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
710 BOOL
PSDRV_WriteGlyphShow(print_ctx
*ctx
, LPCSTR g_name
)
715 l
= snprintf(buf
, sizeof(buf
), psglyphshow
, g_name
);
717 if (l
< sizeof(psglyphshow
) - 2 || l
> sizeof(buf
) - 1) {
718 WARN("Unusable glyph name '%s' - ignoring\n", g_name
);
722 PSDRV_WriteSpool(ctx
, buf
, l
);
726 BOOL
PSDRV_WriteFill(print_ctx
*ctx
)
728 return PSDRV_WriteSpool(ctx
, psfill
, sizeof(psfill
)-1);
731 BOOL
PSDRV_WriteEOFill(print_ctx
*ctx
)
733 return PSDRV_WriteSpool(ctx
, pseofill
, sizeof(pseofill
)-1);
736 BOOL
PSDRV_WriteGSave(print_ctx
*ctx
)
738 return PSDRV_WriteSpool(ctx
, psgsave
, sizeof(psgsave
)-1);
741 BOOL
PSDRV_WriteGRestore(print_ctx
*ctx
)
743 return PSDRV_WriteSpool(ctx
, psgrestore
, sizeof(psgrestore
)-1);
746 BOOL
PSDRV_WriteNewPath(print_ctx
*ctx
)
748 return PSDRV_WriteSpool(ctx
, psnewpath
, sizeof(psnewpath
)-1);
751 BOOL
PSDRV_WriteClosePath(print_ctx
*ctx
)
753 return PSDRV_WriteSpool(ctx
, psclosepath
, sizeof(psclosepath
)-1);
756 BOOL
PSDRV_WriteClip(print_ctx
*ctx
)
758 return PSDRV_WriteSpool(ctx
, psclip
, sizeof(psclip
)-1);
761 BOOL
PSDRV_WriteEOClip(print_ctx
*ctx
)
763 return PSDRV_WriteSpool(ctx
, pseoclip
, sizeof(pseoclip
)-1);
766 BOOL
PSDRV_WriteHatch(print_ctx
*ctx
)
768 return PSDRV_WriteSpool(ctx
, pshatch
, sizeof(pshatch
)-1);
771 BOOL
PSDRV_WriteRotate(print_ctx
*ctx
, float ang
)
775 push_lc_numeric("C");
776 sprintf(buf
, psrotate
, ang
);
778 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
781 BOOL
PSDRV_WriteIndexColorSpaceBegin(print_ctx
*ctx
, int size
)
784 sprintf(buf
, "[/Indexed /DeviceRGB %d\n<\n", size
);
785 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
788 BOOL
PSDRV_WriteIndexColorSpaceEnd(print_ctx
*ctx
)
790 static const char buf
[] = ">\n] setcolorspace\n";
791 return PSDRV_WriteSpool(ctx
, buf
, sizeof(buf
) - 1);
794 static BOOL
PSDRV_WriteRGB(print_ctx
*ctx
, COLORREF
*map
, int number
)
796 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
800 for(i
= 0; i
< number
; i
++) {
801 sprintf(ptr
, "%02x%02x%02x%c", (int)GetRValue(map
[i
]),
802 (int)GetGValue(map
[i
]), (int)GetBValue(map
[i
]),
803 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
806 PSDRV_WriteSpool(ctx
, buf
, number
* 7);
807 HeapFree( GetProcessHeap(), 0, buf
);
811 BOOL
PSDRV_WriteRGBQUAD(print_ctx
*ctx
, const RGBQUAD
*rgb
, int number
)
813 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 7 + 1 ), *ptr
;
817 for(i
= 0; i
< number
; i
++, rgb
++)
818 ptr
+= sprintf(ptr
, "%02x%02x%02x%c", rgb
->rgbRed
, rgb
->rgbGreen
, rgb
->rgbBlue
,
819 ((i
& 0x7) == 0x7) || (i
== number
- 1) ? '\n' : ' ');
821 PSDRV_WriteSpool(ctx
, buf
, ptr
- buf
);
822 HeapFree( GetProcessHeap(), 0, buf
);
826 static BOOL
PSDRV_WriteImageDict(print_ctx
*ctx
, WORD depth
, BOOL grayscale
,
827 INT widthSrc
, INT heightSrc
, char *bits
, BOOL top_down
)
829 static const char start
[] = "<<\n"
830 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
831 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
833 static const char decode1
[] = " /Decode [0 %d]\n";
834 static const char decode3
[] = " /Decode [0 1 0 1 0 1]\n";
836 static const char end
[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
837 static const char endbits
[] = " /DataSource <%s>\n>>\n";
841 sprintf(buf
, start
, widthSrc
, heightSrc
,
842 (depth
< 8) ? depth
: 8, widthSrc
, heightSrc
, 0);
844 sprintf(buf
, start
, widthSrc
, heightSrc
,
845 (depth
< 8) ? depth
: 8, widthSrc
, -heightSrc
, heightSrc
);
847 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
851 sprintf(buf
, decode1
, 255);
855 sprintf(buf
, decode1
, 15);
859 sprintf(buf
, decode1
, 1);
864 sprintf(buf
, decode1
, 1);
866 strcpy(buf
, decode3
);
870 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
873 PSDRV_WriteSpool(ctx
, end
, sizeof(end
) - 1);
875 sprintf(buf
, endbits
, bits
);
876 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
882 BOOL
PSDRV_WriteImage(print_ctx
*ctx
, WORD depth
, BOOL grayscale
, INT xDst
, INT yDst
,
883 INT widthDst
, INT heightDst
, INT widthSrc
,
884 INT heightSrc
, BOOL mask
, BOOL top_down
)
886 static const char start
[] = "%d %d translate\n%d %d scale\n";
887 static const char image
[] = "image\n";
888 static const char imagemask
[] = "imagemask\n";
891 sprintf(buf
, start
, xDst
, yDst
, widthDst
, heightDst
);
892 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
893 PSDRV_WriteImageDict(ctx
, depth
, grayscale
, widthSrc
, heightSrc
, NULL
, top_down
);
895 PSDRV_WriteSpool(ctx
, imagemask
, sizeof(imagemask
) - 1);
897 PSDRV_WriteSpool(ctx
, image
, sizeof(image
) - 1);
902 BOOL
PSDRV_WriteBytes(print_ctx
*ctx
, const BYTE
*bytes
, DWORD number
)
904 char *buf
= HeapAlloc( GetProcessHeap(), 0, number
* 3 + 1 );
910 for(i
= 0; i
< number
; i
++) {
911 sprintf(ptr
, "%02x", bytes
[i
]);
913 if(((i
& 0xf) == 0xf) || (i
== number
- 1)) {
918 PSDRV_WriteSpool(ctx
, buf
, ptr
- buf
);
919 HeapFree( GetProcessHeap(), 0, buf
);
923 BOOL
PSDRV_WriteData(print_ctx
*ctx
, const BYTE
*data
, DWORD number
)
925 int num
, num_left
= number
;
928 num
= min(num_left
, 60);
929 PSDRV_WriteSpool(ctx
, (LPCSTR
)data
, num
);
930 PSDRV_WriteSpool(ctx
, "\n", 1);
938 BOOL
PSDRV_WriteArrayPut(print_ctx
*ctx
, CHAR
*pszArrayName
, INT nIndex
, LONG lObject
)
942 sprintf(buf
, psarrayput
, pszArrayName
, nIndex
, lObject
);
943 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
946 BOOL
PSDRV_WriteArrayDef(print_ctx
*ctx
, CHAR
*pszArrayName
, INT nSize
)
950 sprintf(buf
, psarraydef
, pszArrayName
, nSize
);
951 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
954 BOOL
PSDRV_WriteRectClip(print_ctx
*ctx
, INT x
, INT y
, INT w
, INT h
)
958 sprintf(buf
, psrectclip
, x
, y
, w
, h
);
959 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
962 BOOL
PSDRV_WriteRectClip2(print_ctx
*ctx
, CHAR
*pszArrayName
)
966 sprintf(buf
, psrectclip2
, pszArrayName
);
967 return PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
970 BOOL
PSDRV_WriteDIBPatternDict(print_ctx
*ctx
, const BITMAPINFO
*bmi
, BYTE
*bits
, UINT usage
)
972 static const char mypat
[] = "/mypat\n";
973 static const char do_pattern
[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
974 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
975 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
977 INT w
, h
, x
, y
, w_mult
, h_mult
, abs_height
= abs( bmi
->bmiHeader
.biHeight
);
980 TRACE( "size %ldx%ldx%d\n",
981 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
, bmi
->bmiHeader
.biBitCount
);
983 if(bmi
->bmiHeader
.biBitCount
!= 1) {
984 FIXME("dib depth %d not supported\n", bmi
->bmiHeader
.biBitCount
);
988 w
= bmi
->bmiHeader
.biWidth
& ~0x7;
989 h
= abs_height
& ~0x7;
991 buf
= HeapAlloc( GetProcessHeap(), 0, max(sizeof(do_pattern
) + 100, 2 * w
/8 * h
+ 1) );
993 for(y
= h
-1; y
>= 0; y
--) {
994 for(x
= 0; x
< w
/8; x
++) {
995 sprintf(ptr
, "%02x", *(bits
+ x
/8 + y
*
996 ((bmi
->bmiHeader
.biWidth
+ 31) / 32) * 4));
1000 PSDRV_WriteSpool(ctx
, mypat
, sizeof(mypat
) - 1);
1001 PSDRV_WriteImageDict(ctx
, 1, FALSE
, 8, 8, buf
, bmi
->bmiHeader
.biHeight
< 0);
1002 PSDRV_WriteSpool(ctx
, "def\n", 4);
1004 PSDRV_WriteIndexColorSpaceBegin(ctx
, 1);
1005 map
[0] = GetTextColor( ctx
->hdc
);
1006 map
[1] = GetBkColor( ctx
->hdc
);
1007 PSDRV_WriteRGB(ctx
, map
, 2);
1008 PSDRV_WriteIndexColorSpaceEnd(ctx
);
1010 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
1011 w_mult
= (GetDeviceCaps(ctx
->hdc
, ASPECTX
) + 150) / 300;
1012 h_mult
= (GetDeviceCaps(ctx
->hdc
, ASPECTY
) + 150) / 300;
1013 sprintf(buf
, do_pattern
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
, w
* w_mult
, h
* h_mult
);
1014 PSDRV_WriteSpool(ctx
, buf
, strlen(buf
));
1015 HeapFree( GetProcessHeap(), 0, buf
);