Release 20030408.
[wine/gsoc-2012-control.git] / dlls / wineps / ps.c
blob08d503624e2e3b5554c2887e6cb05f3adc1b9b8a
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>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "gdi.h"
28 #include "psdrv.h"
29 #include "winspool.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
34 static char psheader[] = /* title llx lly urx ury orientation */
35 "%%!PS-Adobe-3.0\n"
36 "%%%%Creator: Wine PostScript Driver\n"
37 "%%%%Title: %s\n"
38 "%%%%BoundingBox: %d %d %d %d\n"
39 "%%%%Pages: (atend)\n"
40 "%%%%Orientation: %s\n"
41 "%%%%EndComments\n";
43 static char psbeginprolog[] =
44 "%%BeginProlog\n";
46 static char psendprolog[] =
47 "%%EndProlog\n";
49 static char psprolog[] =
50 "/tmpmtrx matrix def\n"
51 "/hatch {\n"
52 " pathbbox\n"
53 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
54 " l cvi gap idiv gap mul\n"
55 " gap\n"
56 " r cvi gap idiv gap mul\n"
57 " {t moveto 0 b t sub rlineto}\n"
58 " for\n"
59 "} bind def\n"
60 "/B {pop pop pop pop} def\n";
62 static char psbeginsetup[] =
63 "%%BeginSetup\n";
65 static char psendsetup[] =
66 "%%EndSetup\n";
68 static char psbeginfeature[] = /* feature, value */
69 "mark {\n"
70 "%%%%BeginFeature: %s %s\n";
72 static char psendfeature[] =
73 "\n%%EndFeature\n"
74 "} stopped cleartomark\n";
76 static char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
77 "%%%%Page: %s %d\n"
78 "%%%%BeginPageSetup\n"
79 "/pgsave save def\n"
80 "72 %d div 72 %d div scale\n"
81 "%d %d translate\n"
82 "1 -1 scale\n"
83 "%d rotate\n"
84 "%%%%EndPageSetup\n";
86 static char psendpage[] =
87 "pgsave restore\n"
88 "showpage\n";
90 static char psfooter[] = /* pages */
91 "%%%%Trailer\n"
92 "%%%%Pages: %d\n"
93 "%%%%EOF\n";
95 static char psmoveto[] = /* x, y */
96 "%d %d moveto\n";
98 static char pslineto[] = /* x, y */
99 "%d %d lineto\n";
101 static char psstroke[] =
102 "stroke\n";
104 static char psrectangle[] = /* x, y, width, height, -width */
105 "%d %d moveto\n"
106 "%d 0 rlineto\n"
107 "0 %d rlineto\n"
108 "%d 0 rlineto\n"
109 "closepath\n";
111 static char psrrectangle[] = /* x, y, width, height, -width */
112 "%d %d rmoveto\n"
113 "%d 0 rlineto\n"
114 "0 %d rlineto\n"
115 "%d 0 rlineto\n"
116 "closepath\n";
118 static const char psglyphshow[] = /* glyph name */
119 "/%s glyphshow\n";
121 static char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
122 "/%s findfont\n"
123 "[%d 0 0 %d 0 0]\n"
124 "%d 10 div matrix rotate\n"
125 "matrix concatmatrix\n"
126 "makefont setfont\n";
128 static char pssetlinewidth[] = /* width */
129 "%d setlinewidth\n";
131 static char pssetdash[] = /* dash, offset */
132 "[%s] %d setdash\n";
134 static char pssetgray[] = /* gray */
135 "%.2f setgray\n";
137 static char pssetrgbcolor[] = /* r, g, b */
138 "%.2f %.2f %.2f setrgbcolor\n";
140 static char psarc[] = /* x, y, w, h, ang1, ang2 */
141 "tmpmtrx currentmatrix pop\n"
142 "%d %d translate\n"
143 "%d %d scale\n"
144 "0 0 0.5 %.1f %.1f arc\n"
145 "tmpmtrx setmatrix\n";
147 static char psgsave[] =
148 "gsave\n";
150 static char psgrestore[] =
151 "grestore\n";
153 static char psfill[] =
154 "fill\n";
156 static char pseofill[] =
157 "eofill\n";
159 static char psnewpath[] =
160 "newpath\n";
162 static char psclosepath[] =
163 "closepath\n";
165 static char psclip[] =
166 "clip\n";
168 static char psinitclip[] =
169 "initclip\n";
171 static char pseoclip[] =
172 "eoclip\n";
174 static char psrectclip[] =
175 "%d %d %d %d rectclip\n";
177 static char psrectclip2[] =
178 "%s rectclip\n";
180 static char pshatch[] =
181 "hatch\n";
183 static char psrotate[] = /* ang */
184 "%.1f rotate\n";
186 static char psarrayget[] =
187 "%s %d get\n";
189 static char psarrayput[] =
190 "%s %d %ld put\n";
192 static char psarraydef[] =
193 "/%s %d array def\n";
196 int PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPSTR lpData, WORD cch)
198 if(physDev->job.quiet) {
199 TRACE("ignoring output\n");
200 return 0;
203 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
204 if( !PSDRV_StartPage(physDev) )
205 return 0;
207 return WriteSpool16( physDev->job.hJob, lpData, cch );
211 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
212 char *invocation)
215 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
216 strlen(feature) + strlen(value));
219 sprintf(buf, psbeginfeature, feature, value);
220 WriteSpool16( hJob, buf, strlen(buf) );
222 WriteSpool16( hJob, invocation, strlen(invocation) );
224 WriteSpool16( hJob, psendfeature, strlen(psendfeature) );
226 HeapFree( PSDRV_Heap, 0, buf );
227 return 1;
232 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
234 char *buf, *orient;
235 INPUTSLOT *slot;
236 PAGESIZE *page;
237 int llx, lly, urx, ury;
239 TRACE("'%s'\n", title);
241 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
242 strlen(title) + 30 );
243 if(!buf) {
244 WARN("HeapAlloc failed\n");
245 return 0;
248 /* BBox co-ords are in default user co-ord system so urx < ury even in
249 landscape mode */
250 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
251 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
252 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
253 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
255 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
256 orient = "Landscape";
257 } else {
258 orient = "Portrait";
261 /* FIXME should do something better with BBox */
263 sprintf(buf, psheader, title, llx, lly, urx, ury, orient);
265 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
266 strlen(buf) ) {
267 WARN("WriteSpool error\n");
268 HeapFree( PSDRV_Heap, 0, buf );
269 return 0;
271 HeapFree( PSDRV_Heap, 0, buf );
273 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
274 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
275 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
277 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
279 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
280 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
281 if(slot->InvocationString) {
282 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
283 slot->InvocationString);
284 break;
289 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
290 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
291 if(page->InvocationString) {
292 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
293 page->InvocationString);
294 break;
299 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
302 return 1;
306 INT PSDRV_WriteFooter( PSDRV_PDEVICE *physDev )
308 char *buf;
310 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
311 if(!buf) {
312 WARN("HeapAlloc failed\n");
313 return 0;
316 sprintf(buf, psfooter, physDev->job.PageNo);
318 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
319 strlen(buf) ) {
320 WARN("WriteSpool error\n");
321 HeapFree( PSDRV_Heap, 0, buf );
322 return 0;
324 HeapFree( PSDRV_Heap, 0, buf );
325 return 1;
330 INT PSDRV_WriteEndPage( PSDRV_PDEVICE *physDev )
332 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
333 sizeof(psendpage)-1 ) {
334 WARN("WriteSpool error\n");
335 return 0;
337 return 1;
343 INT PSDRV_WriteNewPage( PSDRV_PDEVICE *physDev )
345 char *buf;
346 char name[100];
347 signed int xtrans, ytrans, rotation;
349 sprintf(name, "%d", physDev->job.PageNo);
351 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
352 if(!buf) {
353 WARN("HeapAlloc failed\n");
354 return 0;
357 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
358 if(physDev->pi->ppd->LandscapeOrientation == -90) {
359 xtrans = physDev->ImageableArea.right;
360 ytrans = physDev->ImageableArea.top;
361 rotation = 90;
362 } else {
363 xtrans = physDev->ImageableArea.left;
364 ytrans = physDev->ImageableArea.bottom;
365 rotation = -90;
367 } else {
368 xtrans = physDev->ImageableArea.left;
369 ytrans = physDev->ImageableArea.top;
370 rotation = 0;
373 sprintf(buf, psnewpage, name, physDev->job.PageNo,
374 physDev->logPixelsX, physDev->logPixelsY,
375 xtrans, ytrans, rotation);
377 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
378 strlen(buf) ) {
379 WARN("WriteSpool error\n");
380 HeapFree( PSDRV_Heap, 0, buf );
381 return 0;
383 HeapFree( PSDRV_Heap, 0, buf );
384 return 1;
388 BOOL PSDRV_WriteMoveTo(PSDRV_PDEVICE *physDev, INT x, INT y)
390 char buf[100];
392 sprintf(buf, psmoveto, x, y);
393 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
396 BOOL PSDRV_WriteLineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
398 char buf[100];
400 sprintf(buf, pslineto, x, y);
401 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
405 BOOL PSDRV_WriteStroke(PSDRV_PDEVICE *physDev)
407 return PSDRV_WriteSpool(physDev, psstroke, sizeof(psstroke)-1);
412 BOOL PSDRV_WriteRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
413 INT height)
415 char buf[100];
417 sprintf(buf, psrectangle, x, y, width, height, -width);
418 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
421 BOOL PSDRV_WriteRRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
422 INT height)
424 char buf[100];
426 sprintf(buf, psrrectangle, x, y, width, height, -width);
427 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
430 BOOL PSDRV_WriteArc(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h, double ang1,
431 double ang2)
433 char buf[256];
435 /* Make angles -ve and swap order because we're working with an upside
436 down y-axis */
437 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
438 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
442 BOOL PSDRV_WriteSetFont(PSDRV_PDEVICE *physDev, const char *name, INT size, INT escapement)
444 char *buf;
446 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
447 strlen(name) + 40);
449 if(!buf) {
450 WARN("HeapAlloc failed\n");
451 return FALSE;
454 sprintf(buf, pssetfont, name, size, -size, -escapement);
456 PSDRV_WriteSpool(physDev, buf, strlen(buf));
457 HeapFree(PSDRV_Heap, 0, buf);
458 return TRUE;
461 BOOL PSDRV_WriteSetColor(PSDRV_PDEVICE *physDev, PSCOLOR *color)
463 char buf[256];
465 PSDRV_CopyColor(&physDev->inkColor, color);
466 switch(color->type) {
467 case PSCOLOR_RGB:
468 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
469 color->value.rgb.b);
470 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
472 case PSCOLOR_GRAY:
473 sprintf(buf, pssetgray, color->value.gray.i);
474 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
476 default:
477 ERR("Unkonwn colour type %d\n", color->type);
478 break;
481 return FALSE;
484 BOOL PSDRV_WriteSetPen(PSDRV_PDEVICE *physDev)
486 char buf[256];
488 sprintf(buf, pssetlinewidth, physDev->pen.width);
489 PSDRV_WriteSpool(physDev, buf, strlen(buf));
491 if(physDev->pen.dash) {
492 sprintf(buf, pssetdash, physDev->pen.dash, 0);
493 PSDRV_WriteSpool(physDev, buf, strlen(buf));
496 return TRUE;
499 BOOL PSDRV_WriteGlyphShow(PSDRV_PDEVICE *physDev, LPCSTR g_name)
501 char buf[128];
502 int l;
504 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
506 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
507 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
508 return FALSE;
511 PSDRV_WriteSpool(physDev, buf, l);
512 return TRUE;
515 BOOL PSDRV_WriteFill(PSDRV_PDEVICE *physDev)
517 return PSDRV_WriteSpool(physDev, psfill, sizeof(psfill)-1);
520 BOOL PSDRV_WriteEOFill(PSDRV_PDEVICE *physDev)
522 return PSDRV_WriteSpool(physDev, pseofill, sizeof(pseofill)-1);
525 BOOL PSDRV_WriteGSave(PSDRV_PDEVICE *physDev)
527 return PSDRV_WriteSpool(physDev, psgsave, sizeof(psgsave)-1);
530 BOOL PSDRV_WriteGRestore(PSDRV_PDEVICE *physDev)
532 return PSDRV_WriteSpool(physDev, psgrestore, sizeof(psgrestore)-1);
535 BOOL PSDRV_WriteNewPath(PSDRV_PDEVICE *physDev)
537 return PSDRV_WriteSpool(physDev, psnewpath, sizeof(psnewpath)-1);
540 BOOL PSDRV_WriteClosePath(PSDRV_PDEVICE *physDev)
542 return PSDRV_WriteSpool(physDev, psclosepath, sizeof(psclosepath)-1);
545 BOOL PSDRV_WriteClip(PSDRV_PDEVICE *physDev)
547 return PSDRV_WriteSpool(physDev, psclip, sizeof(psclip)-1);
550 BOOL PSDRV_WriteEOClip(PSDRV_PDEVICE *physDev)
552 return PSDRV_WriteSpool(physDev, pseoclip, sizeof(pseoclip)-1);
555 BOOL PSDRV_WriteInitClip(PSDRV_PDEVICE *physDev)
557 return PSDRV_WriteSpool(physDev, psinitclip, sizeof(psinitclip)-1);
560 BOOL PSDRV_WriteHatch(PSDRV_PDEVICE *physDev)
562 return PSDRV_WriteSpool(physDev, pshatch, sizeof(pshatch)-1);
565 BOOL PSDRV_WriteRotate(PSDRV_PDEVICE *physDev, float ang)
567 char buf[256];
569 sprintf(buf, psrotate, ang);
570 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
573 BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size)
575 char buf[256];
576 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
577 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
580 BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev)
582 char buf[] = ">\n] setcolorspace\n";
583 return PSDRV_WriteSpool(physDev, buf, sizeof(buf) - 1);
586 BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number)
588 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
589 int i;
591 ptr = buf;
592 for(i = 0; i < number; i++) {
593 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
594 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
595 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
596 ptr += 7;
598 PSDRV_WriteSpool(physDev, buf, number * 7);
599 HeapFree(PSDRV_Heap, 0, buf);
600 return TRUE;
604 BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
605 INT widthDst, INT heightDst, INT widthSrc,
606 INT heightSrc, char *bits)
608 char start[] = "%d %d translate\n%d %d scale\n<<\n"
609 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
610 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
612 char decode1[] = " /Decode [0 %d]\n";
613 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
615 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
616 char endbits[] = " /DataSource <%s>\n>> image\n";
618 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
620 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
621 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
623 PSDRV_WriteSpool(physDev, buf, strlen(buf));
625 switch(depth) {
626 case 8:
627 sprintf(buf, decode1, 255);
628 break;
630 case 4:
631 sprintf(buf, decode1, 15);
632 break;
634 case 1:
635 sprintf(buf, decode1, 1);
636 break;
638 default:
639 strcpy(buf, decode3);
640 break;
643 PSDRV_WriteSpool(physDev, buf, strlen(buf));
645 if(!bits)
646 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
647 else {
648 sprintf(buf, endbits, bits);
649 PSDRV_WriteSpool(physDev, buf, strlen(buf));
652 HeapFree(PSDRV_Heap, 0, buf);
653 return TRUE;
657 BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, int number)
659 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
660 char *ptr;
661 int i;
663 ptr = buf;
665 for(i = 0; i < number; i++) {
666 sprintf(ptr, "%02x%c", bytes[i],
667 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
668 ptr += 3;
670 PSDRV_WriteSpool(physDev, buf, number * 3);
672 HeapFree(PSDRV_Heap, 0, buf);
673 return TRUE;
676 BOOL PSDRV_WriteDIBits16(PSDRV_PDEVICE *physDev, const WORD *words, int number)
678 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
679 char *ptr;
680 int i;
682 ptr = buf;
684 for(i = 0; i < number; i++) {
685 int r, g, b;
687 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
689 r = words[i] >> 10 & 0x1f;
690 r = r << 3 | r >> 2;
691 g = words[i] >> 5 & 0x1f;
692 g = g << 3 | g >> 2;
693 b = words[i] & 0x1f;
694 b = b << 3 | b >> 2;
695 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
696 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
697 ptr += 7;
699 PSDRV_WriteSpool(physDev, buf, number * 7);
701 HeapFree(PSDRV_Heap, 0, buf);
702 return TRUE;
705 BOOL PSDRV_WriteDIBits24(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
707 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
708 char *ptr;
709 int i;
711 ptr = buf;
713 for(i = 0; i < number; i++) {
714 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
715 bits[i * 3],
716 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
717 ptr += 7;
719 PSDRV_WriteSpool(physDev, buf, number * 7);
721 HeapFree(PSDRV_Heap, 0, buf);
722 return TRUE;
725 BOOL PSDRV_WriteDIBits32(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
727 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
728 char *ptr;
729 int i;
731 ptr = buf;
733 for(i = 0; i < number; i++) {
734 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
735 bits[i * 4],
736 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
737 ptr += 7;
739 PSDRV_WriteSpool(physDev, buf, number * 7);
741 HeapFree(PSDRV_Heap, 0, buf);
742 return TRUE;
745 BOOL PSDRV_WriteArrayGet(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex)
747 char buf[100];
749 sprintf(buf, psarrayget, pszArrayName, nIndex);
750 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
753 BOOL PSDRV_WriteArrayPut(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex, LONG lObject)
755 char buf[100];
757 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
758 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
761 BOOL PSDRV_WriteArrayDef(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nSize)
763 char buf[100];
765 sprintf(buf, psarraydef, pszArrayName, nSize);
766 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
769 BOOL PSDRV_WriteRectClip(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h)
771 char buf[100];
773 sprintf(buf, psrectclip, x, y, w, h);
774 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
777 BOOL PSDRV_WriteRectClip2(PSDRV_PDEVICE *physDev, CHAR *pszArrayName)
779 char buf[100];
781 sprintf(buf, psrectclip2, pszArrayName);
782 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
785 BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
787 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
788 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
790 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
791 char *buf, *ptr;
792 INT w, h, x, y;
793 COLORREF map[2];
795 w = bm->bmWidth & ~0x7;
796 h = bm->bmHeight & ~0x7;
798 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
799 sprintf(buf, start, w, h, w, h);
800 PSDRV_WriteSpool(physDev, buf, strlen(buf));
801 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
802 map[0] = GetTextColor( physDev->hdc );
803 map[1] = GetBkColor( physDev->hdc );
804 PSDRV_WriteRGB(physDev, map, 2);
805 PSDRV_WriteIndexColorSpaceEnd(physDev);
806 ptr = buf;
807 for(y = h-1; y >= 0; y--) {
808 for(x = 0; x < w/8; x++) {
809 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
810 ptr += 2;
813 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf);
814 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
815 HeapFree(PSDRV_Heap, 0, buf);
816 return TRUE;
819 BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
821 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
822 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
824 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
825 char *buf, *ptr;
826 BYTE *bits;
827 INT w, h, x, y, colours;
828 COLORREF map[2];
830 if(bmi->bmiHeader.biBitCount != 1) {
831 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
832 return FALSE;
835 bits = (char*)bmi + bmi->bmiHeader.biSize;
836 colours = bmi->bmiHeader.biClrUsed;
837 if(!colours && bmi->bmiHeader.biBitCount <= 8)
838 colours = 1 << bmi->bmiHeader.biBitCount;
839 bits += colours * ((usage == DIB_RGB_COLORS) ?
840 sizeof(RGBQUAD) : sizeof(WORD));
842 w = bmi->bmiHeader.biWidth & ~0x7;
843 h = bmi->bmiHeader.biHeight & ~0x7;
845 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
846 sprintf(buf, start, w, h, w, h);
847 PSDRV_WriteSpool(physDev, buf, strlen(buf));
848 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
849 map[0] = physDev->dc->textColor;
850 map[1] = physDev->dc->backgroundColor;
851 PSDRV_WriteRGB(physDev, map, 2);
852 PSDRV_WriteIndexColorSpaceEnd(physDev);
853 ptr = buf;
854 for(y = h-1; y >= 0; y--) {
855 for(x = 0; x < w/8; x++) {
856 sprintf(ptr, "%02x", *(bits + x/8 + y *
857 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
858 ptr += 2;
861 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf);
862 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
863 HeapFree(PSDRV_Heap, 0, buf);
864 return TRUE;