Removed XInitThreads call, the X libraries still have too many bugs to
[wine/multimedia.git] / dlls / wineps / ps.c
blob42634b5f762600bfa756b73adb2603870b3a3fe5
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 const char psheader[] = /* title llx lly urx ury */
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 "%%%%EndComments\n";
42 static const char psbeginprolog[] =
43 "%%BeginProlog\n";
45 static const char psendprolog[] =
46 "%%EndProlog\n";
48 static const char psprolog[] =
49 "/tmpmtrx matrix def\n"
50 "/hatch {\n"
51 " pathbbox\n"
52 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
53 " l cvi gap idiv gap mul\n"
54 " gap\n"
55 " r cvi gap idiv gap mul\n"
56 " {t moveto 0 b t sub rlineto}\n"
57 " for\n"
58 "} bind def\n"
59 "/B {pop pop pop pop} def\n"
60 "/havetype42gdir {version cvi 2015 ge} bind def\n";
62 static const char psbeginsetup[] =
63 "%%BeginSetup\n";
65 static const char psendsetup[] =
66 "%%EndSetup\n";
68 static const char psbeginfeature[] = /* feature, value */
69 "mark {\n"
70 "%%%%BeginFeature: %s %s\n";
72 static const char psendfeature[] =
73 "\n%%EndFeature\n"
74 "} stopped cleartomark\n";
76 static const 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 const char psendpage[] =
87 "pgsave restore\n"
88 "showpage\n";
90 static const char psfooter[] = /* pages */
91 "%%%%Trailer\n"
92 "%%%%Pages: %d\n"
93 "%%%%EOF\n";
95 static const char psmoveto[] = /* x, y */
96 "%d %d moveto\n";
98 static const char pslineto[] = /* x, y */
99 "%d %d lineto\n";
101 static const char psstroke[] =
102 "stroke\n";
104 static const 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 const 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 const 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 const char pssetlinewidth[] = /* width */
129 "%d setlinewidth\n";
131 static const char pssetdash[] = /* dash, offset */
132 "[%s] %d setdash\n";
134 static const char pssetgray[] = /* gray */
135 "%.2f setgray\n";
137 static const char pssetrgbcolor[] = /* r, g, b */
138 "%.2f %.2f %.2f setrgbcolor\n";
140 static const 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 const char psgsave[] =
148 "gsave\n";
150 static const char psgrestore[] =
151 "grestore\n";
153 static const char psfill[] =
154 "fill\n";
156 static const char pseofill[] =
157 "eofill\n";
159 static const char psnewpath[] =
160 "newpath\n";
162 static const char psclosepath[] =
163 "closepath\n";
165 static const char psclip[] =
166 "clip\n";
168 static const char psinitclip[] =
169 "initclip\n";
171 static const char pseoclip[] =
172 "eoclip\n";
174 static const char psrectclip[] =
175 "%d %d %d %d rectclip\n";
177 static const char psrectclip2[] =
178 "%s rectclip\n";
180 static const char pshatch[] =
181 "hatch\n";
183 static const char psrotate[] = /* ang */
184 "%.1f rotate\n";
186 static const char psarrayget[] =
187 "%s %d get\n";
189 static const char psarrayput[] =
190 "%s %d %ld put\n";
192 static const char psarraydef[] =
193 "/%s %d array def\n";
196 DWORD PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, DWORD cch)
198 int num, num_left = cch;
200 if(physDev->job.quiet) {
201 TRACE("ignoring output\n");
202 return 0;
205 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
206 if( !PSDRV_StartPage(physDev) )
207 return 0;
210 do {
211 num = min(num_left, 0x8000);
212 if(WriteSpool16( physDev->job.hJob, (LPSTR)lpData, num ) != num)
213 return 0;
214 lpData += num;
215 num_left -= num;
216 } while(num_left);
218 return cch;
222 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
223 char *invocation)
226 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
227 strlen(feature) + strlen(value));
230 sprintf(buf, psbeginfeature, feature, value);
231 WriteSpool16( hJob, buf, strlen(buf) );
233 WriteSpool16( hJob, invocation, strlen(invocation) );
235 WriteSpool16( hJob, (LPSTR)psendfeature, strlen(psendfeature) );
237 HeapFree( PSDRV_Heap, 0, buf );
238 return 1;
243 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
245 char *buf;
246 INPUTSLOT *slot;
247 PAGESIZE *page;
248 DUPLEX *duplex;
249 int win_duplex;
250 int llx, lly, urx, ury;
252 TRACE("'%s'\n", debugstr_a(title));
254 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
255 (title ? strlen(title) : 0) + 30 );
256 if(!buf) {
257 WARN("HeapAlloc failed\n");
258 return 0;
261 /* BBox co-ords are in default user co-ord system so urx < ury even in
262 landscape mode */
263 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
264 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
265 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
266 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
267 /* FIXME should do something better with BBox */
269 sprintf(buf, psheader, title ? title : "", llx, lly, urx, ury);
271 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
272 strlen(buf) ) {
273 WARN("WriteSpool error\n");
274 HeapFree( PSDRV_Heap, 0, buf );
275 return 0;
277 HeapFree( PSDRV_Heap, 0, buf );
279 WriteSpool16( physDev->job.hJob, (LPSTR)psbeginprolog, strlen(psbeginprolog) );
280 WriteSpool16( physDev->job.hJob, (LPSTR)psprolog, strlen(psprolog) );
281 WriteSpool16( physDev->job.hJob, (LPSTR)psendprolog, strlen(psendprolog) );
283 WriteSpool16( physDev->job.hJob, (LPSTR)psbeginsetup, strlen(psbeginsetup) );
285 if(physDev->Devmode->dmPublic.dmCopies > 1) {
286 char copies_buf[100];
287 sprintf(copies_buf, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev->Devmode->dmPublic.dmCopies);
288 WriteSpool16(physDev->job.hJob, copies_buf, strlen(copies_buf));
291 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
292 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
293 if(slot->InvocationString) {
294 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
295 slot->InvocationString);
296 break;
301 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
302 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
303 if(page->InvocationString) {
304 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
305 page->InvocationString);
306 break;
311 win_duplex = physDev->Devmode->dmPublic.dmFields & DM_DUPLEX ?
312 physDev->Devmode->dmPublic.dmDuplex : 0;
313 for(duplex = physDev->pi->ppd->Duplexes; duplex; duplex = duplex->next) {
314 if(duplex->WinDuplex == win_duplex) {
315 if(duplex->InvocationString) {
316 PSDRV_WriteFeature(physDev->job.hJob, "*Duplex", duplex->Name,
317 duplex->InvocationString);
318 break;
323 WriteSpool16( physDev->job.hJob, (LPSTR)psendsetup, strlen(psendsetup) );
326 return 1;
330 INT PSDRV_WriteFooter( PSDRV_PDEVICE *physDev )
332 char *buf;
334 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
335 if(!buf) {
336 WARN("HeapAlloc failed\n");
337 return 0;
340 sprintf(buf, psfooter, physDev->job.PageNo);
342 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
343 strlen(buf) ) {
344 WARN("WriteSpool error\n");
345 HeapFree( PSDRV_Heap, 0, buf );
346 return 0;
348 HeapFree( PSDRV_Heap, 0, buf );
349 return 1;
354 INT PSDRV_WriteEndPage( PSDRV_PDEVICE *physDev )
356 if( WriteSpool16( physDev->job.hJob, (LPSTR)psendpage, sizeof(psendpage)-1 ) !=
357 sizeof(psendpage)-1 ) {
358 WARN("WriteSpool error\n");
359 return 0;
361 return 1;
367 INT PSDRV_WriteNewPage( PSDRV_PDEVICE *physDev )
369 char *buf;
370 char name[100];
371 signed int xtrans, ytrans, rotation;
373 sprintf(name, "%d", physDev->job.PageNo);
375 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
376 if(!buf) {
377 WARN("HeapAlloc failed\n");
378 return 0;
381 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
382 if(physDev->pi->ppd->LandscapeOrientation == -90) {
383 xtrans = physDev->ImageableArea.right;
384 ytrans = physDev->ImageableArea.top;
385 rotation = 90;
386 } else {
387 xtrans = physDev->ImageableArea.left;
388 ytrans = physDev->ImageableArea.bottom;
389 rotation = -90;
391 } else {
392 xtrans = physDev->ImageableArea.left;
393 ytrans = physDev->ImageableArea.top;
394 rotation = 0;
397 sprintf(buf, psnewpage, name, physDev->job.PageNo,
398 physDev->logPixelsX, physDev->logPixelsY,
399 xtrans, ytrans, rotation);
401 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
402 strlen(buf) ) {
403 WARN("WriteSpool error\n");
404 HeapFree( PSDRV_Heap, 0, buf );
405 return 0;
407 HeapFree( PSDRV_Heap, 0, buf );
408 return 1;
412 BOOL PSDRV_WriteMoveTo(PSDRV_PDEVICE *physDev, INT x, INT y)
414 char buf[100];
416 sprintf(buf, psmoveto, x, y);
417 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
420 BOOL PSDRV_WriteLineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
422 char buf[100];
424 sprintf(buf, pslineto, x, y);
425 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
429 BOOL PSDRV_WriteStroke(PSDRV_PDEVICE *physDev)
431 return PSDRV_WriteSpool(physDev, psstroke, sizeof(psstroke)-1);
436 BOOL PSDRV_WriteRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
437 INT height)
439 char buf[100];
441 sprintf(buf, psrectangle, x, y, width, height, -width);
442 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
445 BOOL PSDRV_WriteRRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
446 INT height)
448 char buf[100];
450 sprintf(buf, psrrectangle, x, y, width, height, -width);
451 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
454 BOOL PSDRV_WriteArc(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h, double ang1,
455 double ang2)
457 char buf[256];
459 /* Make angles -ve and swap order because we're working with an upside
460 down y-axis */
461 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
462 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
466 BOOL PSDRV_WriteSetFont(PSDRV_PDEVICE *physDev, const char *name, INT size, INT escapement)
468 char *buf;
470 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
471 strlen(name) + 40);
473 if(!buf) {
474 WARN("HeapAlloc failed\n");
475 return FALSE;
478 sprintf(buf, pssetfont, name, size, -size, -escapement);
480 PSDRV_WriteSpool(physDev, buf, strlen(buf));
481 HeapFree(PSDRV_Heap, 0, buf);
482 return TRUE;
485 BOOL PSDRV_WriteSetColor(PSDRV_PDEVICE *physDev, PSCOLOR *color)
487 char buf[256];
489 PSDRV_CopyColor(&physDev->inkColor, color);
490 switch(color->type) {
491 case PSCOLOR_RGB:
492 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
493 color->value.rgb.b);
494 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
496 case PSCOLOR_GRAY:
497 sprintf(buf, pssetgray, color->value.gray.i);
498 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
500 default:
501 ERR("Unkonwn colour type %d\n", color->type);
502 break;
505 return FALSE;
508 BOOL PSDRV_WriteSetPen(PSDRV_PDEVICE *physDev)
510 char buf[256];
512 sprintf(buf, pssetlinewidth, physDev->pen.width);
513 PSDRV_WriteSpool(physDev, buf, strlen(buf));
515 if(physDev->pen.dash) {
516 sprintf(buf, pssetdash, physDev->pen.dash, 0);
517 PSDRV_WriteSpool(physDev, buf, strlen(buf));
520 return TRUE;
523 BOOL PSDRV_WriteGlyphShow(PSDRV_PDEVICE *physDev, LPCSTR g_name)
525 char buf[128];
526 int l;
528 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
530 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
531 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
532 return FALSE;
535 PSDRV_WriteSpool(physDev, buf, l);
536 return TRUE;
539 BOOL PSDRV_WriteFill(PSDRV_PDEVICE *physDev)
541 return PSDRV_WriteSpool(physDev, psfill, sizeof(psfill)-1);
544 BOOL PSDRV_WriteEOFill(PSDRV_PDEVICE *physDev)
546 return PSDRV_WriteSpool(physDev, pseofill, sizeof(pseofill)-1);
549 BOOL PSDRV_WriteGSave(PSDRV_PDEVICE *physDev)
551 return PSDRV_WriteSpool(physDev, psgsave, sizeof(psgsave)-1);
554 BOOL PSDRV_WriteGRestore(PSDRV_PDEVICE *physDev)
556 return PSDRV_WriteSpool(physDev, psgrestore, sizeof(psgrestore)-1);
559 BOOL PSDRV_WriteNewPath(PSDRV_PDEVICE *physDev)
561 return PSDRV_WriteSpool(physDev, psnewpath, sizeof(psnewpath)-1);
564 BOOL PSDRV_WriteClosePath(PSDRV_PDEVICE *physDev)
566 return PSDRV_WriteSpool(physDev, psclosepath, sizeof(psclosepath)-1);
569 BOOL PSDRV_WriteClip(PSDRV_PDEVICE *physDev)
571 return PSDRV_WriteSpool(physDev, psclip, sizeof(psclip)-1);
574 BOOL PSDRV_WriteEOClip(PSDRV_PDEVICE *physDev)
576 return PSDRV_WriteSpool(physDev, pseoclip, sizeof(pseoclip)-1);
579 BOOL PSDRV_WriteInitClip(PSDRV_PDEVICE *physDev)
581 return PSDRV_WriteSpool(physDev, psinitclip, sizeof(psinitclip)-1);
584 BOOL PSDRV_WriteHatch(PSDRV_PDEVICE *physDev)
586 return PSDRV_WriteSpool(physDev, pshatch, sizeof(pshatch)-1);
589 BOOL PSDRV_WriteRotate(PSDRV_PDEVICE *physDev, float ang)
591 char buf[256];
593 sprintf(buf, psrotate, ang);
594 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
597 BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size)
599 char buf[256];
600 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
601 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
604 BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev)
606 char buf[] = ">\n] setcolorspace\n";
607 return PSDRV_WriteSpool(physDev, buf, sizeof(buf) - 1);
610 BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number)
612 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
613 int i;
615 ptr = buf;
616 for(i = 0; i < number; i++) {
617 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
618 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
619 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
620 ptr += 7;
622 PSDRV_WriteSpool(physDev, buf, number * 7);
623 HeapFree(PSDRV_Heap, 0, buf);
624 return TRUE;
628 BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
629 INT widthDst, INT heightDst, INT widthSrc,
630 INT heightSrc, char *bits, BOOL mask)
632 const char start[] = "%d %d translate\n%d %d scale\n<<\n"
633 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
634 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
636 const char decode1[] = " /Decode [0 %d]\n";
637 const char decode3[] = " /Decode [0 1 0 1 0 1]\n";
639 const char end[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> image\n";
640 const char endmask[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>> imagemask\n";
642 const char endbits[] = " /DataSource <%s>\n>> image\n";
644 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
646 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
647 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
649 PSDRV_WriteSpool(physDev, buf, strlen(buf));
651 switch(depth) {
652 case 8:
653 sprintf(buf, decode1, 255);
654 break;
656 case 4:
657 sprintf(buf, decode1, 15);
658 break;
660 case 1:
661 sprintf(buf, decode1, 1);
662 break;
664 default:
665 strcpy(buf, decode3);
666 break;
669 PSDRV_WriteSpool(physDev, buf, strlen(buf));
671 if(!bits) {
672 if(!mask)
673 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
674 else
675 PSDRV_WriteSpool(physDev, endmask, sizeof(endmask) - 1);
676 } else {
677 sprintf(buf, endbits, bits);
678 PSDRV_WriteSpool(physDev, buf, strlen(buf));
681 HeapFree(PSDRV_Heap, 0, buf);
682 return TRUE;
686 BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, DWORD number)
688 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
689 char *ptr;
690 int i;
692 ptr = buf;
694 for(i = 0; i < number; i++) {
695 sprintf(ptr, "%02x", bytes[i]);
696 ptr += 2;
697 if(((i & 0xf) == 0xf) || (i == number - 1)) {
698 strcpy(ptr, "\n");
699 ptr++;
702 PSDRV_WriteSpool(physDev, buf, ptr - buf);
703 HeapFree(PSDRV_Heap, 0, buf);
704 return TRUE;
707 BOOL PSDRV_WriteData(PSDRV_PDEVICE *physDev, const BYTE *data, DWORD number)
709 int num, num_left = number;
711 do {
712 num = min(num_left, 60);
713 PSDRV_WriteSpool(physDev, data, num);
714 PSDRV_WriteSpool(physDev, "\n", 1);
715 data += num;
716 num_left -= num;
717 } while(num_left);
719 return TRUE;
722 BOOL PSDRV_WriteArrayGet(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex)
724 char buf[100];
726 sprintf(buf, psarrayget, pszArrayName, nIndex);
727 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
730 BOOL PSDRV_WriteArrayPut(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex, LONG lObject)
732 char buf[100];
734 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
735 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
738 BOOL PSDRV_WriteArrayDef(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nSize)
740 char buf[100];
742 sprintf(buf, psarraydef, pszArrayName, nSize);
743 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
746 BOOL PSDRV_WriteRectClip(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h)
748 char buf[100];
750 sprintf(buf, psrectclip, x, y, w, h);
751 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
754 BOOL PSDRV_WriteRectClip2(PSDRV_PDEVICE *physDev, CHAR *pszArrayName)
756 char buf[100];
758 sprintf(buf, psrectclip2, pszArrayName);
759 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
762 BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
764 const char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
765 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
767 const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
768 char *buf, *ptr;
769 INT w, h, x, y;
770 COLORREF map[2];
772 w = bm->bmWidth & ~0x7;
773 h = bm->bmHeight & ~0x7;
775 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
776 sprintf(buf, start, w, h, w, h);
777 PSDRV_WriteSpool(physDev, buf, strlen(buf));
778 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
779 map[0] = GetTextColor( physDev->hdc );
780 map[1] = GetBkColor( physDev->hdc );
781 PSDRV_WriteRGB(physDev, map, 2);
782 PSDRV_WriteIndexColorSpaceEnd(physDev);
783 ptr = buf;
784 for(y = h-1; y >= 0; y--) {
785 for(x = 0; x < w/8; x++) {
786 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
787 ptr += 2;
790 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
791 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
792 HeapFree(PSDRV_Heap, 0, buf);
793 return TRUE;
796 BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
798 const char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
799 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
801 const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
802 char *buf, *ptr;
803 BYTE *bits;
804 INT w, h, x, y, colours;
805 COLORREF map[2];
807 if(bmi->bmiHeader.biBitCount != 1) {
808 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
809 return FALSE;
812 bits = (char*)bmi + bmi->bmiHeader.biSize;
813 colours = bmi->bmiHeader.biClrUsed;
814 if(!colours && bmi->bmiHeader.biBitCount <= 8)
815 colours = 1 << bmi->bmiHeader.biBitCount;
816 bits += colours * ((usage == DIB_RGB_COLORS) ?
817 sizeof(RGBQUAD) : sizeof(WORD));
819 w = bmi->bmiHeader.biWidth & ~0x7;
820 h = bmi->bmiHeader.biHeight & ~0x7;
822 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
823 sprintf(buf, start, w, h, w, h);
824 PSDRV_WriteSpool(physDev, buf, strlen(buf));
825 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
826 map[0] = physDev->dc->textColor;
827 map[1] = physDev->dc->backgroundColor;
828 PSDRV_WriteRGB(physDev, map, 2);
829 PSDRV_WriteIndexColorSpaceEnd(physDev);
830 ptr = buf;
831 for(y = h-1; y >= 0; y--) {
832 for(x = 0; x < w/8; x++) {
833 sprintf(ptr, "%02x", *(bits + x/8 + y *
834 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
835 ptr += 2;
838 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
839 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
840 HeapFree(PSDRV_Heap, 0, buf);
841 return TRUE;