Make COMSPEC point to wcmd.exe, not command.com.
[wine/multimedia.git] / dlls / wineps / ps.c
blobb8904e352c66b6b91c3aa86ba496e2a7decf8cff
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "gdi.h"
25 #include "psdrv.h"
26 #include "winspool.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
31 static char psheader[] = /* title llx lly urx ury orientation */
32 "%%!PS-Adobe-3.0\n"
33 "%%%%Creator: Wine PostScript Driver\n"
34 "%%%%Title: %s\n"
35 "%%%%BoundingBox: %d %d %d %d\n"
36 "%%%%Pages: (atend)\n"
37 "%%%%Orientation: %s\n"
38 "%%%%EndComments\n";
40 static char psbeginprolog[] =
41 "%%BeginProlog\n";
43 static char psendprolog[] =
44 "%%EndProlog\n";
46 static char psprolog[] =
47 "/tmpmtrx matrix def\n"
48 "/hatch {\n"
49 " pathbbox\n"
50 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
51 " l cvi gap idiv gap mul\n"
52 " gap\n"
53 " r cvi gap idiv gap mul\n"
54 " {t moveto 0 b t sub rlineto}\n"
55 " for\n"
56 "} bind def\n";
58 static char psbeginsetup[] =
59 "%%BeginSetup\n";
61 static char psendsetup[] =
62 "%%EndSetup\n";
64 static char psbeginfeature[] = /* feature, value */
65 "mark {\n"
66 "%%%%BeginFeature: %s %s\n";
68 static char psendfeature[] =
69 "\n%%EndFeature\n"
70 "} stopped cleartomark\n";
72 static char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
73 "%%%%Page: %s %d\n"
74 "%%%%BeginPageSetup\n"
75 "/pgsave save def\n"
76 "72 %d div 72 %d div scale\n"
77 "%d %d translate\n"
78 "1 -1 scale\n"
79 "%d rotate\n"
80 "%%%%EndPageSetup\n";
82 static char psendpage[] =
83 "pgsave restore\n"
84 "showpage\n";
86 static char psfooter[] = /* pages */
87 "%%%%Trailer\n"
88 "%%%%Pages: %d\n"
89 "%%%%EOF\n";
91 static char psmoveto[] = /* x, y */
92 "%d %d moveto\n";
94 static char pslineto[] = /* x, y */
95 "%d %d lineto\n";
97 static char psstroke[] =
98 "stroke\n";
100 static char psrectangle[] = /* x, y, width, height, -width */
101 "%d %d moveto\n"
102 "%d 0 rlineto\n"
103 "0 %d rlineto\n"
104 "%d 0 rlineto\n"
105 "closepath\n";
107 static char psrrectangle[] = /* x, y, width, height, -width */
108 "%d %d rmoveto\n"
109 "%d 0 rlineto\n"
110 "0 %d rlineto\n"
111 "%d 0 rlineto\n"
112 "closepath\n";
114 static const char psglyphshow[] = /* glyph name */
115 "/%s glyphshow\n";
117 static char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
118 "/%s findfont\n"
119 "[%d 0 0 %d 0 0]\n"
120 "%d 10 div matrix rotate\n"
121 "matrix concatmatrix\n"
122 "makefont setfont\n";
124 static char pssetlinewidth[] = /* width */
125 "%d setlinewidth\n";
127 static char pssetdash[] = /* dash, offset */
128 "[%s] %d setdash\n";
130 static char pssetgray[] = /* gray */
131 "%.2f setgray\n";
133 static char pssetrgbcolor[] = /* r, g, b */
134 "%.2f %.2f %.2f setrgbcolor\n";
136 static char psarc[] = /* x, y, w, h, ang1, ang2 */
137 "tmpmtrx currentmatrix pop\n"
138 "%d %d translate\n"
139 "%d %d scale\n"
140 "0 0 0.5 %.1f %.1f arc\n"
141 "tmpmtrx setmatrix\n";
143 static char psgsave[] =
144 "gsave\n";
146 static char psgrestore[] =
147 "grestore\n";
149 static char psfill[] =
150 "fill\n";
152 static char pseofill[] =
153 "eofill\n";
155 static char psnewpath[] =
156 "newpath\n";
158 static char psclosepath[] =
159 "closepath\n";
161 static char psclip[] =
162 "clip\n";
164 static char psinitclip[] =
165 "initclip\n";
167 static char pseoclip[] =
168 "eoclip\n";
170 static char psrectclip[] =
171 "%d %d %d %d rectclip\n";
173 static char psrectclip2[] =
174 "%s rectclip\n";
176 static char pshatch[] =
177 "hatch\n";
179 static char psrotate[] = /* ang */
180 "%.1f rotate\n";
182 static char psarrayget[] =
183 "%s %d get\n";
185 static char psarrayput[] =
186 "%s %d %ld put\n";
188 static char psarraydef[] =
189 "/%s %d array def\n";
192 int PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPSTR lpData, WORD cch)
194 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
195 if( !PSDRV_StartPage(physDev) )
196 return FALSE;
198 return WriteSpool16( physDev->job.hJob, lpData, cch );
202 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
203 char *invocation)
206 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
207 strlen(feature) + strlen(value));
210 sprintf(buf, psbeginfeature, feature, value);
211 WriteSpool16( hJob, buf, strlen(buf) );
213 WriteSpool16( hJob, invocation, strlen(invocation) );
215 WriteSpool16( hJob, psendfeature, strlen(psendfeature) );
217 HeapFree( PSDRV_Heap, 0, buf );
218 return 1;
223 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
225 char *buf, *orient;
226 INPUTSLOT *slot;
227 PAGESIZE *page;
228 int llx, lly, urx, ury;
230 TRACE("'%s'\n", title);
232 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
233 strlen(title) + 30 );
234 if(!buf) {
235 WARN("HeapAlloc failed\n");
236 return 0;
239 /* BBox co-ords are in default user co-ord system so urx < ury even in
240 landscape mode */
241 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
242 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
243 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
244 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
246 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
247 orient = "Landscape";
248 } else {
249 orient = "Portrait";
252 /* FIXME should do something better with BBox */
254 sprintf(buf, psheader, title, llx, lly, urx, ury, orient);
256 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
257 strlen(buf) ) {
258 WARN("WriteSpool error\n");
259 HeapFree( PSDRV_Heap, 0, buf );
260 return 0;
262 HeapFree( PSDRV_Heap, 0, buf );
264 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
265 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
266 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
268 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
270 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
271 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
272 if(slot->InvocationString) {
273 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
274 slot->InvocationString);
275 break;
280 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
281 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
282 if(page->InvocationString) {
283 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
284 page->InvocationString);
285 break;
290 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
293 return 1;
297 INT PSDRV_WriteFooter( PSDRV_PDEVICE *physDev )
299 char *buf;
301 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
302 if(!buf) {
303 WARN("HeapAlloc failed\n");
304 return 0;
307 sprintf(buf, psfooter, physDev->job.PageNo);
309 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
310 strlen(buf) ) {
311 WARN("WriteSpool error\n");
312 HeapFree( PSDRV_Heap, 0, buf );
313 return 0;
315 HeapFree( PSDRV_Heap, 0, buf );
316 return 1;
321 INT PSDRV_WriteEndPage( PSDRV_PDEVICE *physDev )
323 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
324 sizeof(psendpage)-1 ) {
325 WARN("WriteSpool error\n");
326 return 0;
328 return 1;
334 INT PSDRV_WriteNewPage( PSDRV_PDEVICE *physDev )
336 char *buf;
337 char name[100];
338 signed int xtrans, ytrans, rotation;
340 sprintf(name, "%d", physDev->job.PageNo);
342 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
343 if(!buf) {
344 WARN("HeapAlloc failed\n");
345 return 0;
348 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
349 if(physDev->pi->ppd->LandscapeOrientation == -90) {
350 xtrans = physDev->ImageableArea.right;
351 ytrans = physDev->ImageableArea.top;
352 rotation = 90;
353 } else {
354 xtrans = physDev->ImageableArea.left;
355 ytrans = physDev->ImageableArea.bottom;
356 rotation = -90;
358 } else {
359 xtrans = physDev->ImageableArea.left;
360 ytrans = physDev->ImageableArea.top;
361 rotation = 0;
364 sprintf(buf, psnewpage, name, physDev->job.PageNo,
365 physDev->logPixelsX, physDev->logPixelsY,
366 xtrans, ytrans, rotation);
368 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
369 strlen(buf) ) {
370 WARN("WriteSpool error\n");
371 HeapFree( PSDRV_Heap, 0, buf );
372 return 0;
374 HeapFree( PSDRV_Heap, 0, buf );
375 return 1;
379 BOOL PSDRV_WriteMoveTo(PSDRV_PDEVICE *physDev, INT x, INT y)
381 char buf[100];
383 sprintf(buf, psmoveto, x, y);
384 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
387 BOOL PSDRV_WriteLineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
389 char buf[100];
391 sprintf(buf, pslineto, x, y);
392 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
396 BOOL PSDRV_WriteStroke(PSDRV_PDEVICE *physDev)
398 return PSDRV_WriteSpool(physDev, psstroke, sizeof(psstroke)-1);
403 BOOL PSDRV_WriteRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
404 INT height)
406 char buf[100];
408 sprintf(buf, psrectangle, x, y, width, height, -width);
409 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
412 BOOL PSDRV_WriteRRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
413 INT height)
415 char buf[100];
417 sprintf(buf, psrrectangle, x, y, width, height, -width);
418 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
421 BOOL PSDRV_WriteArc(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h, double ang1,
422 double ang2)
424 char buf[256];
426 /* Make angles -ve and swap order because we're working with an upside
427 down y-axis */
428 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
429 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
433 BOOL PSDRV_WriteSetFont(PSDRV_PDEVICE *physDev, const char *name, INT size, INT escapement)
435 char *buf;
437 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
438 strlen(name) + 40);
440 if(!buf) {
441 WARN("HeapAlloc failed\n");
442 return FALSE;
445 sprintf(buf, pssetfont, name, size, -size, -escapement);
447 PSDRV_WriteSpool(physDev, buf, strlen(buf));
448 HeapFree(PSDRV_Heap, 0, buf);
449 return TRUE;
452 BOOL PSDRV_WriteSetColor(PSDRV_PDEVICE *physDev, PSCOLOR *color)
454 char buf[256];
456 PSDRV_CopyColor(&physDev->inkColor, color);
457 switch(color->type) {
458 case PSCOLOR_RGB:
459 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
460 color->value.rgb.b);
461 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
463 case PSCOLOR_GRAY:
464 sprintf(buf, pssetgray, color->value.gray.i);
465 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
467 default:
468 ERR("Unkonwn colour type %d\n", color->type);
469 break;
472 return FALSE;
475 BOOL PSDRV_WriteSetPen(PSDRV_PDEVICE *physDev)
477 char buf[256];
479 sprintf(buf, pssetlinewidth, physDev->pen.width);
480 PSDRV_WriteSpool(physDev, buf, strlen(buf));
482 if(physDev->pen.dash) {
483 sprintf(buf, pssetdash, physDev->pen.dash, 0);
484 PSDRV_WriteSpool(physDev, buf, strlen(buf));
487 return TRUE;
490 BOOL PSDRV_WriteGlyphShow(PSDRV_PDEVICE *physDev, LPCSTR g_name)
492 char buf[128];
493 int l;
495 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
497 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
498 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
499 return FALSE;
502 PSDRV_WriteSpool(physDev, buf, l);
503 return TRUE;
506 BOOL PSDRV_WriteFill(PSDRV_PDEVICE *physDev)
508 return PSDRV_WriteSpool(physDev, psfill, sizeof(psfill)-1);
511 BOOL PSDRV_WriteEOFill(PSDRV_PDEVICE *physDev)
513 return PSDRV_WriteSpool(physDev, pseofill, sizeof(pseofill)-1);
516 BOOL PSDRV_WriteGSave(PSDRV_PDEVICE *physDev)
518 return PSDRV_WriteSpool(physDev, psgsave, sizeof(psgsave)-1);
521 BOOL PSDRV_WriteGRestore(PSDRV_PDEVICE *physDev)
523 return PSDRV_WriteSpool(physDev, psgrestore, sizeof(psgrestore)-1);
526 BOOL PSDRV_WriteNewPath(PSDRV_PDEVICE *physDev)
528 return PSDRV_WriteSpool(physDev, psnewpath, sizeof(psnewpath)-1);
531 BOOL PSDRV_WriteClosePath(PSDRV_PDEVICE *physDev)
533 return PSDRV_WriteSpool(physDev, psclosepath, sizeof(psclosepath)-1);
536 BOOL PSDRV_WriteClip(PSDRV_PDEVICE *physDev)
538 return PSDRV_WriteSpool(physDev, psclip, sizeof(psclip)-1);
541 BOOL PSDRV_WriteEOClip(PSDRV_PDEVICE *physDev)
543 return PSDRV_WriteSpool(physDev, pseoclip, sizeof(pseoclip)-1);
546 BOOL PSDRV_WriteInitClip(PSDRV_PDEVICE *physDev)
548 return PSDRV_WriteSpool(physDev, psinitclip, sizeof(psinitclip)-1);
551 BOOL PSDRV_WriteHatch(PSDRV_PDEVICE *physDev)
553 return PSDRV_WriteSpool(physDev, pshatch, sizeof(pshatch)-1);
556 BOOL PSDRV_WriteRotate(PSDRV_PDEVICE *physDev, float ang)
558 char buf[256];
560 sprintf(buf, psrotate, ang);
561 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
564 BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size)
566 char buf[256];
567 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
568 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
571 BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev)
573 char buf[] = ">\n] setcolorspace\n";
574 return PSDRV_WriteSpool(physDev, buf, sizeof(buf) - 1);
577 BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number)
579 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
580 int i;
582 ptr = buf;
583 for(i = 0; i < number; i++) {
584 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
585 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
586 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
587 ptr += 7;
589 PSDRV_WriteSpool(physDev, buf, number * 7);
590 HeapFree(PSDRV_Heap, 0, buf);
591 return TRUE;
595 BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
596 INT widthDst, INT heightDst, INT widthSrc,
597 INT heightSrc, char *bits)
599 char start[] = "%d %d translate\n%d %d scale\n<<\n"
600 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
601 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
603 char decode1[] = " /Decode [0 %d]\n";
604 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
606 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
607 char endbits[] = " /DataSource <%s>\n>> image\n";
609 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
611 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
612 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
614 PSDRV_WriteSpool(physDev, buf, strlen(buf));
616 switch(depth) {
617 case 8:
618 sprintf(buf, decode1, 255);
619 break;
621 case 4:
622 sprintf(buf, decode1, 15);
623 break;
625 case 1:
626 sprintf(buf, decode1, 1);
627 break;
629 default:
630 strcpy(buf, decode3);
631 break;
634 PSDRV_WriteSpool(physDev, buf, strlen(buf));
636 if(!bits)
637 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
638 else {
639 sprintf(buf, endbits, bits);
640 PSDRV_WriteSpool(physDev, buf, strlen(buf));
643 HeapFree(PSDRV_Heap, 0, buf);
644 return TRUE;
648 BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, int number)
650 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
651 char *ptr;
652 int i;
654 ptr = buf;
656 for(i = 0; i < number; i++) {
657 sprintf(ptr, "%02x%c", bytes[i],
658 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
659 ptr += 3;
661 PSDRV_WriteSpool(physDev, buf, number * 3);
663 HeapFree(PSDRV_Heap, 0, buf);
664 return TRUE;
667 BOOL PSDRV_WriteDIBits16(PSDRV_PDEVICE *physDev, const WORD *words, int number)
669 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
670 char *ptr;
671 int i;
673 ptr = buf;
675 for(i = 0; i < number; i++) {
676 int r, g, b;
678 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
680 r = words[i] >> 10 & 0x1f;
681 r = r << 3 | r >> 2;
682 g = words[i] >> 5 & 0x1f;
683 g = g << 3 | g >> 2;
684 b = words[i] & 0x1f;
685 b = b << 3 | b >> 2;
686 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
687 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
688 ptr += 7;
690 PSDRV_WriteSpool(physDev, buf, number * 7);
692 HeapFree(PSDRV_Heap, 0, buf);
693 return TRUE;
696 BOOL PSDRV_WriteDIBits24(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
698 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
699 char *ptr;
700 int i;
702 ptr = buf;
704 for(i = 0; i < number; i++) {
705 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
706 bits[i * 3],
707 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
708 ptr += 7;
710 PSDRV_WriteSpool(physDev, buf, number * 7);
712 HeapFree(PSDRV_Heap, 0, buf);
713 return TRUE;
716 BOOL PSDRV_WriteDIBits32(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
718 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
719 char *ptr;
720 int i;
722 ptr = buf;
724 for(i = 0; i < number; i++) {
725 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
726 bits[i * 4],
727 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
728 ptr += 7;
730 PSDRV_WriteSpool(physDev, buf, number * 7);
732 HeapFree(PSDRV_Heap, 0, buf);
733 return TRUE;
736 BOOL PSDRV_WriteArrayGet(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex)
738 char buf[100];
740 sprintf(buf, psarrayget, pszArrayName, nIndex);
741 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
744 BOOL PSDRV_WriteArrayPut(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex, LONG lObject)
746 char buf[100];
748 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
749 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
752 BOOL PSDRV_WriteArrayDef(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nSize)
754 char buf[100];
756 sprintf(buf, psarraydef, pszArrayName, nSize);
757 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
760 BOOL PSDRV_WriteRectClip(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h)
762 char buf[100];
764 sprintf(buf, psrectclip, x, y, w, h);
765 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
768 BOOL PSDRV_WriteRectClip2(PSDRV_PDEVICE *physDev, CHAR *pszArrayName)
770 char buf[100];
772 sprintf(buf, psrectclip2, pszArrayName);
773 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
776 BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
778 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
779 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
781 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
782 char *buf, *ptr;
783 INT w, h, x, y;
784 COLORREF map[2];
786 w = bm->bmWidth & ~0x7;
787 h = bm->bmHeight & ~0x7;
789 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
790 sprintf(buf, start, w, h, w, h);
791 PSDRV_WriteSpool(physDev, buf, strlen(buf));
792 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
793 map[0] = GetTextColor( physDev->hdc );
794 map[1] = GetBkColor( physDev->hdc );
795 PSDRV_WriteRGB(physDev, map, 2);
796 PSDRV_WriteIndexColorSpaceEnd(physDev);
797 ptr = buf;
798 for(y = h-1; y >= 0; y--) {
799 for(x = 0; x < w/8; x++) {
800 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
801 ptr += 2;
804 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf);
805 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
806 HeapFree(PSDRV_Heap, 0, buf);
807 return TRUE;
810 BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
812 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
813 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
815 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
816 char *buf, *ptr;
817 BYTE *bits;
818 INT w, h, x, y, colours;
819 COLORREF map[2];
821 if(bmi->bmiHeader.biBitCount != 1) {
822 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
823 return FALSE;
826 bits = (char*)bmi + bmi->bmiHeader.biSize;
827 colours = bmi->bmiHeader.biClrUsed;
828 if(!colours && bmi->bmiHeader.biBitCount <= 8)
829 colours = 1 << bmi->bmiHeader.biBitCount;
830 bits += colours * ((usage == DIB_RGB_COLORS) ?
831 sizeof(RGBQUAD) : sizeof(WORD));
833 w = bmi->bmiHeader.biWidth & ~0x7;
834 h = bmi->bmiHeader.biHeight & ~0x7;
836 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
837 sprintf(buf, start, w, h, w, h);
838 PSDRV_WriteSpool(physDev, buf, strlen(buf));
839 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
840 map[0] = physDev->dc->textColor;
841 map[1] = physDev->dc->backgroundColor;
842 PSDRV_WriteRGB(physDev, map, 2);
843 PSDRV_WriteIndexColorSpaceEnd(physDev);
844 ptr = buf;
845 for(y = h-1; y >= 0; y--) {
846 for(x = 0; x < w/8; x++) {
847 sprintf(ptr, "%02x", *(bits + x/8 + y *
848 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
849 ptr += 2;
852 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf);
853 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
854 HeapFree(PSDRV_Heap, 0, buf);
855 return TRUE;