configure: Print a warning when prelink isn't found.
[wine/hramrach.git] / dlls / wineps.drv / ps.c
blobe06e892afaa6f2648b77d5abbecdc561be6111a8
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
25 #include <locale.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "psdrv.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
37 static const char psheader[] = /* title llx lly urx ury */
38 "%%!PS-Adobe-3.0\n"
39 "%%%%Creator: Wine PostScript Driver\n"
40 "%%%%Title: %s\n"
41 "%%%%BoundingBox: %d %d %d %d\n"
42 "%%%%Pages: (atend)\n"
43 "%%%%EndComments\n";
45 static const char psbeginprolog[] =
46 "%%BeginProlog\n";
48 static const char psendprolog[] =
49 "%%EndProlog\n";
51 static const char psprolog[] =
52 "/tmpmtrx matrix def\n"
53 "/hatch {\n"
54 " pathbbox\n"
55 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
56 " l cvi gap idiv gap mul\n"
57 " gap\n"
58 " r cvi gap idiv gap mul\n"
59 " {t moveto 0 b t sub rlineto}\n"
60 " for\n"
61 "} bind def\n"
62 "/B {pop pop pop pop} def\n"
63 "/N {newpath} def\n"
64 "/havetype42gdir {version cvi 2015 ge} bind def\n";
66 static const char psbeginsetup[] =
67 "%%BeginSetup\n";
69 static const char psendsetup[] =
70 "%%EndSetup\n";
72 static const char psbeginfeature[] = /* feature, value */
73 "mark {\n"
74 "%%%%BeginFeature: %s %s\n";
76 static const char psendfeature[] =
77 "\n%%EndFeature\n"
78 "} stopped cleartomark\n";
80 static const char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
81 "%%%%Page: %s %d\n"
82 "%%%%BeginPageSetup\n"
83 "/pgsave save def\n"
84 "72 %d div 72 %d div scale\n"
85 "%d %d translate\n"
86 "1 -1 scale\n"
87 "%d rotate\n"
88 "%%%%EndPageSetup\n";
90 static const char psendpage[] =
91 "pgsave restore\n"
92 "showpage\n";
94 static const char psfooter[] = /* pages */
95 "%%%%Trailer\n"
96 "%%%%Pages: %d\n"
97 "%%%%EOF\n";
99 static const char psmoveto[] = /* x, y */
100 "%d %d moveto\n";
102 static const char pslineto[] = /* x, y */
103 "%d %d lineto\n";
105 static const char psstroke[] =
106 "stroke\n";
108 static const char psrectangle[] = /* x, y, width, height, -width */
109 "%d %d moveto\n"
110 "%d 0 rlineto\n"
111 "0 %d rlineto\n"
112 "%d 0 rlineto\n"
113 "closepath\n";
115 static const char psglyphshow[] = /* glyph name */
116 "/%s glyphshow\n";
118 static const char pssetfont[] = /* fontname, xx_scale, xy_scale, yx_scale, yy_scale, escapement */
119 "/%s findfont\n"
120 "[%d %d %d %d 0 0]\n"
121 "%d 10 div matrix rotate\n"
122 "matrix concatmatrix\n"
123 "makefont setfont\n";
125 static const char pssetline[] = /* width, join, endcap */
126 "%d setlinewidth %u setlinejoin %u setlinecap\n";
128 static const char pssetdash[] = /* dash, offset */
129 "[%s] %d setdash\n";
131 static const char pssetgray[] = /* gray */
132 "%.2f setgray\n";
134 static const char pssetrgbcolor[] = /* r, g, b */
135 "%.2f %.2f %.2f setrgbcolor\n";
137 static const char psarc[] = /* x, y, w, h, ang1, ang2 */
138 "tmpmtrx currentmatrix pop\n"
139 "%d %d translate\n"
140 "%d %d scale\n"
141 "0 0 0.5 %.1f %.1f arc\n"
142 "tmpmtrx setmatrix\n";
144 static const char psgsave[] =
145 "gsave\n";
147 static const char psgrestore[] =
148 "grestore\n";
150 static const char psfill[] =
151 "fill\n";
153 static const char pseofill[] =
154 "eofill\n";
156 static const char psnewpath[] =
157 "newpath\n";
159 static const char psclosepath[] =
160 "closepath\n";
162 static const char psclip[] =
163 "clip\n";
165 static const char pseoclip[] =
166 "eoclip\n";
168 static const char psrectclip[] =
169 "%d %d %d %d rectclip\n";
171 static const char psrectclip2[] =
172 "%s rectclip\n";
174 static const char pshatch[] =
175 "hatch\n";
177 static const char psrotate[] = /* ang */
178 "%.1f rotate\n";
180 static const char psarrayput[] =
181 "%s %d %d put\n";
183 static const char psarraydef[] =
184 "/%s %d array def\n";
186 static const char psenddocument[] =
187 "\n%%EndDocument\n";
189 DWORD PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, DWORD cch)
191 int num, num_left = cch;
193 if(physDev->job.quiet) {
194 TRACE("ignoring output\n");
195 return 0;
198 if(physDev->job.in_passthrough) { /* Was in PASSTHROUGH mode */
199 write_spool( physDev, psenddocument, sizeof(psenddocument)-1 );
200 physDev->job.in_passthrough = physDev->job.had_passthrough_rect = FALSE;
203 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
204 if( !PSDRV_StartPage(physDev) )
205 return 0;
208 do {
209 num = min(num_left, 0x8000);
210 if(write_spool( physDev, lpData, num ) != num)
211 return 0;
212 lpData += num;
213 num_left -= num;
214 } while(num_left);
216 return cch;
220 static INT PSDRV_WriteFeature(PSDRV_PDEVICE *physDev, LPCSTR feature, LPCSTR value, LPCSTR invocation)
223 char *buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
224 strlen(feature) + strlen(value));
226 sprintf(buf, psbeginfeature, feature, value);
227 write_spool( physDev, buf, strlen(buf) );
228 write_spool( physDev, invocation, strlen(invocation) );
229 write_spool( physDev, psendfeature, strlen(psendfeature) );
231 HeapFree( PSDRV_Heap, 0, buf );
232 return 1;
235 /********************************************************
236 * escape_title
238 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
239 * as octal. If we've had to use an escape then surround the entire string
240 * in brackets. Truncate string to represent at most 0x80 characters.
243 static char *escape_title(LPCSTR str)
245 char *ret, *cp;
246 int i, extra = 0;
248 if(!str)
250 ret = HeapAlloc(GetProcessHeap(), 0, 1);
251 *ret = '\0';
252 return ret;
255 for(i = 0; i < 0x80 && str[i]; i++)
257 if(!isprint(str[i]))
258 extra += 3;
261 if(!extra)
263 ret = HeapAlloc(GetProcessHeap(), 0, i + 1);
264 memcpy(ret, str, i);
265 ret[i] = '\0';
266 return ret;
269 extra += 2; /* two for the brackets */
270 cp = ret = HeapAlloc(GetProcessHeap(), 0, i + extra + 1);
271 *cp++ = '(';
272 for(i = 0; i < 0x80 && str[i]; i++)
274 if(!isprint(str[i]))
276 BYTE b = (BYTE)str[i];
277 *cp++ = '\\';
278 *cp++ = ((b >> 6) & 0x7) + '0';
279 *cp++ = ((b >> 3) & 0x7) + '0';
280 *cp++ = ((b) & 0x7) + '0';
282 else
283 *cp++ = str[i];
285 *cp++ = ')';
286 *cp = '\0';
287 return ret;
291 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
293 char *buf, *escaped_title;
294 INPUTSLOT *slot;
295 PAGESIZE *page;
296 DUPLEX *duplex;
297 int win_duplex;
298 int llx, lly, urx, ury;
300 TRACE("%s\n", debugstr_a(title));
302 escaped_title = escape_title(title);
303 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
304 strlen(escaped_title) + 30 );
305 if(!buf) {
306 WARN("HeapAlloc failed\n");
307 return 0;
310 /* BBox co-ords are in default user co-ord system so urx < ury even in
311 landscape mode */
312 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
313 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
314 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
315 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
316 /* FIXME should do something better with BBox */
318 sprintf(buf, psheader, escaped_title, llx, lly, urx, ury);
320 HeapFree(GetProcessHeap(), 0, escaped_title);
321 if( write_spool( physDev, buf, strlen(buf) ) != strlen(buf) ) {
322 WARN("WriteSpool error\n");
323 HeapFree( PSDRV_Heap, 0, buf );
324 return 0;
326 HeapFree( PSDRV_Heap, 0, buf );
328 write_spool( physDev, psbeginprolog, strlen(psbeginprolog) );
329 write_spool( physDev, psprolog, strlen(psprolog) );
330 write_spool( physDev, psendprolog, strlen(psendprolog) );
331 write_spool( physDev, psbeginsetup, strlen(psbeginsetup) );
333 if(physDev->Devmode->dmPublic.u1.s1.dmCopies > 1) {
334 char copies_buf[100];
335 sprintf(copies_buf, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev->Devmode->dmPublic.u1.s1.dmCopies);
336 write_spool(physDev, copies_buf, strlen(copies_buf));
339 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
340 if(slot->WinBin == physDev->Devmode->dmPublic.u1.s1.dmDefaultSource) {
341 if(slot->InvocationString) {
342 PSDRV_WriteFeature(physDev, "*InputSlot", slot->Name,
343 slot->InvocationString);
344 break;
349 LIST_FOR_EACH_ENTRY(page, &physDev->pi->ppd->PageSizes, PAGESIZE, entry) {
350 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
351 if(page->InvocationString) {
352 PSDRV_WriteFeature(physDev, "*PageSize", page->Name,
353 page->InvocationString);
354 break;
359 win_duplex = physDev->Devmode->dmPublic.dmFields & DM_DUPLEX ?
360 physDev->Devmode->dmPublic.dmDuplex : 0;
361 for(duplex = physDev->pi->ppd->Duplexes; duplex; duplex = duplex->next) {
362 if(duplex->WinDuplex == win_duplex) {
363 if(duplex->InvocationString) {
364 PSDRV_WriteFeature(physDev, "*Duplex", duplex->Name,
365 duplex->InvocationString);
366 break;
371 write_spool( physDev, psendsetup, strlen(psendsetup) );
374 return 1;
378 INT PSDRV_WriteFooter( PSDRV_PDEVICE *physDev )
380 char *buf;
382 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
383 if(!buf) {
384 WARN("HeapAlloc failed\n");
385 return 0;
388 sprintf(buf, psfooter, physDev->job.PageNo);
390 if( write_spool( physDev, buf, strlen(buf) ) != strlen(buf) ) {
391 WARN("WriteSpool error\n");
392 HeapFree( PSDRV_Heap, 0, buf );
393 return 0;
395 HeapFree( PSDRV_Heap, 0, buf );
396 return 1;
401 INT PSDRV_WriteEndPage( PSDRV_PDEVICE *physDev )
403 if( write_spool( physDev, psendpage, sizeof(psendpage)-1 ) != sizeof(psendpage)-1 ) {
404 WARN("WriteSpool error\n");
405 return 0;
407 return 1;
413 INT PSDRV_WriteNewPage( PSDRV_PDEVICE *physDev )
415 char *buf;
416 char name[100];
417 signed int xtrans, ytrans, rotation;
419 sprintf(name, "%d", physDev->job.PageNo);
421 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
422 if(!buf) {
423 WARN("HeapAlloc failed\n");
424 return 0;
427 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
428 if(physDev->pi->ppd->LandscapeOrientation == -90) {
429 xtrans = physDev->ImageableArea.right;
430 ytrans = physDev->ImageableArea.top;
431 rotation = 90;
432 } else {
433 xtrans = physDev->ImageableArea.left;
434 ytrans = physDev->ImageableArea.bottom;
435 rotation = -90;
437 } else {
438 xtrans = physDev->ImageableArea.left;
439 ytrans = physDev->ImageableArea.top;
440 rotation = 0;
443 sprintf(buf, psnewpage, name, physDev->job.PageNo,
444 physDev->logPixelsX, physDev->logPixelsY,
445 xtrans, ytrans, rotation);
447 if( write_spool( physDev, buf, strlen(buf) ) != strlen(buf) ) {
448 WARN("WriteSpool error\n");
449 HeapFree( PSDRV_Heap, 0, buf );
450 return 0;
452 HeapFree( PSDRV_Heap, 0, buf );
453 return 1;
457 BOOL PSDRV_WriteMoveTo(PSDRV_PDEVICE *physDev, INT x, INT y)
459 char buf[100];
461 sprintf(buf, psmoveto, x, y);
462 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
465 BOOL PSDRV_WriteLineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
467 char buf[100];
469 sprintf(buf, pslineto, x, y);
470 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
474 BOOL PSDRV_WriteStroke(PSDRV_PDEVICE *physDev)
476 return PSDRV_WriteSpool(physDev, psstroke, sizeof(psstroke)-1);
481 BOOL PSDRV_WriteRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
482 INT height)
484 char buf[100];
486 sprintf(buf, psrectangle, x, y, width, height, -width);
487 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
490 BOOL PSDRV_WriteArc(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h, double ang1,
491 double ang2)
493 char buf[256];
495 /* Make angles -ve and swap order because we're working with an upside
496 down y-axis */
497 push_lc_numeric("C");
498 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
499 pop_lc_numeric();
500 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
504 BOOL PSDRV_WriteSetFont(PSDRV_PDEVICE *physDev, const char *name, matrix size, INT escapement)
506 char *buf;
508 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
509 strlen(name) + 40);
511 if(!buf) {
512 WARN("HeapAlloc failed\n");
513 return FALSE;
516 sprintf(buf, pssetfont, name, size.xx, size.xy, size.yx, size.yy, -escapement);
518 PSDRV_WriteSpool(physDev, buf, strlen(buf));
519 HeapFree(PSDRV_Heap, 0, buf);
520 return TRUE;
523 BOOL PSDRV_WriteSetColor(PSDRV_PDEVICE *physDev, PSCOLOR *color)
525 char buf[256];
527 PSDRV_CopyColor(&physDev->inkColor, color);
528 switch(color->type) {
529 case PSCOLOR_RGB:
530 push_lc_numeric("C");
531 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
532 color->value.rgb.b);
533 pop_lc_numeric();
534 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
536 case PSCOLOR_GRAY:
537 push_lc_numeric("C");
538 sprintf(buf, pssetgray, color->value.gray.i);
539 pop_lc_numeric();
540 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
542 default:
543 ERR("Unkonwn colour type %d\n", color->type);
544 break;
547 return FALSE;
550 BOOL PSDRV_WriteSetPen(PSDRV_PDEVICE *physDev)
552 char buf[256];
554 sprintf(buf, pssetline, physDev->pen.width, physDev->pen.join, physDev->pen.endcap);
555 PSDRV_WriteSpool(physDev, buf, strlen(buf));
557 if(physDev->pen.dash) {
558 sprintf(buf, pssetdash, physDev->pen.dash, 0);
560 else
561 sprintf(buf, pssetdash, "", 0);
563 PSDRV_WriteSpool(physDev, buf, strlen(buf));
565 return TRUE;
568 BOOL PSDRV_WriteGlyphShow(PSDRV_PDEVICE *physDev, LPCSTR g_name)
570 char buf[128];
571 int l;
573 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
575 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
576 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
577 return FALSE;
580 PSDRV_WriteSpool(physDev, buf, l);
581 return TRUE;
584 BOOL PSDRV_WriteFill(PSDRV_PDEVICE *physDev)
586 return PSDRV_WriteSpool(physDev, psfill, sizeof(psfill)-1);
589 BOOL PSDRV_WriteEOFill(PSDRV_PDEVICE *physDev)
591 return PSDRV_WriteSpool(physDev, pseofill, sizeof(pseofill)-1);
594 BOOL PSDRV_WriteGSave(PSDRV_PDEVICE *physDev)
596 return PSDRV_WriteSpool(physDev, psgsave, sizeof(psgsave)-1);
599 BOOL PSDRV_WriteGRestore(PSDRV_PDEVICE *physDev)
601 return PSDRV_WriteSpool(physDev, psgrestore, sizeof(psgrestore)-1);
604 BOOL PSDRV_WriteNewPath(PSDRV_PDEVICE *physDev)
606 return PSDRV_WriteSpool(physDev, psnewpath, sizeof(psnewpath)-1);
609 BOOL PSDRV_WriteClosePath(PSDRV_PDEVICE *physDev)
611 return PSDRV_WriteSpool(physDev, psclosepath, sizeof(psclosepath)-1);
614 BOOL PSDRV_WriteClip(PSDRV_PDEVICE *physDev)
616 return PSDRV_WriteSpool(physDev, psclip, sizeof(psclip)-1);
619 BOOL PSDRV_WriteEOClip(PSDRV_PDEVICE *physDev)
621 return PSDRV_WriteSpool(physDev, pseoclip, sizeof(pseoclip)-1);
624 BOOL PSDRV_WriteHatch(PSDRV_PDEVICE *physDev)
626 return PSDRV_WriteSpool(physDev, pshatch, sizeof(pshatch)-1);
629 BOOL PSDRV_WriteRotate(PSDRV_PDEVICE *physDev, float ang)
631 char buf[256];
633 push_lc_numeric("C");
634 sprintf(buf, psrotate, ang);
635 pop_lc_numeric();
636 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
639 BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size)
641 char buf[256];
642 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
643 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
646 BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev)
648 static const char buf[] = ">\n] setcolorspace\n";
649 return PSDRV_WriteSpool(physDev, buf, sizeof(buf) - 1);
652 BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number)
654 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
655 int i;
657 ptr = buf;
658 for(i = 0; i < number; i++) {
659 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
660 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
661 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
662 ptr += 7;
664 PSDRV_WriteSpool(physDev, buf, number * 7);
665 HeapFree(PSDRV_Heap, 0, buf);
666 return TRUE;
669 static BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth,
670 INT widthSrc, INT heightSrc, char *bits)
672 static const char start[] = "<<\n"
673 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
674 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
676 static const char decode1[] = " /Decode [0 %d]\n";
677 static const char decode3[] = " /Decode [0 1 0 1 0 1]\n";
679 static const char end[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
680 static const char endbits[] = " /DataSource <%s>\n>>\n";
682 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
684 sprintf(buf, start, widthSrc, heightSrc,
685 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
687 PSDRV_WriteSpool(physDev, buf, strlen(buf));
689 switch(depth) {
690 case 8:
691 sprintf(buf, decode1, 255);
692 break;
694 case 4:
695 sprintf(buf, decode1, 15);
696 break;
698 case 1:
699 sprintf(buf, decode1, 1);
700 break;
702 default:
703 strcpy(buf, decode3);
704 break;
707 PSDRV_WriteSpool(physDev, buf, strlen(buf));
709 if(!bits) {
710 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
711 } else {
712 sprintf(buf, endbits, bits);
713 PSDRV_WriteSpool(physDev, buf, strlen(buf));
716 HeapFree(PSDRV_Heap, 0, buf);
717 return TRUE;
720 BOOL PSDRV_WriteImage(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
721 INT widthDst, INT heightDst, INT widthSrc,
722 INT heightSrc, BOOL mask)
724 static const char start[] = "%d %d translate\n%d %d scale\n";
725 static const char image[] = "image\n";
726 static const char imagemask[] = "imagemask\n";
727 char buf[100];
729 sprintf(buf, start, xDst, yDst, widthDst, heightDst);
730 PSDRV_WriteSpool(physDev, buf, strlen(buf));
731 PSDRV_WriteImageDict(physDev, depth, widthSrc, heightSrc, NULL);
732 if(mask)
733 PSDRV_WriteSpool(physDev, imagemask, sizeof(imagemask) - 1);
734 else
735 PSDRV_WriteSpool(physDev, image, sizeof(image) - 1);
736 return TRUE;
740 BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, DWORD number)
742 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
743 char *ptr;
744 unsigned int i;
746 ptr = buf;
748 for(i = 0; i < number; i++) {
749 sprintf(ptr, "%02x", bytes[i]);
750 ptr += 2;
751 if(((i & 0xf) == 0xf) || (i == number - 1)) {
752 strcpy(ptr, "\n");
753 ptr++;
756 PSDRV_WriteSpool(physDev, buf, ptr - buf);
757 HeapFree(PSDRV_Heap, 0, buf);
758 return TRUE;
761 BOOL PSDRV_WriteData(PSDRV_PDEVICE *physDev, const BYTE *data, DWORD number)
763 int num, num_left = number;
765 do {
766 num = min(num_left, 60);
767 PSDRV_WriteSpool(physDev, (LPCSTR)data, num);
768 PSDRV_WriteSpool(physDev, "\n", 1);
769 data += num;
770 num_left -= num;
771 } while(num_left);
773 return TRUE;
776 BOOL PSDRV_WriteArrayPut(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex, LONG lObject)
778 char buf[100];
780 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
781 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
784 BOOL PSDRV_WriteArrayDef(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nSize)
786 char buf[100];
788 sprintf(buf, psarraydef, pszArrayName, nSize);
789 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
792 BOOL PSDRV_WriteRectClip(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h)
794 char buf[100];
796 sprintf(buf, psrectclip, x, y, w, h);
797 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
800 BOOL PSDRV_WriteRectClip2(PSDRV_PDEVICE *physDev, CHAR *pszArrayName)
802 char buf[100];
804 sprintf(buf, psrectclip2, pszArrayName);
805 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
808 BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
810 static const char mypat[] = "/mypat\n";
811 static const char do_pattern[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
812 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
813 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
815 char *buf, *ptr;
816 INT w, h, x, y, w_mult, h_mult;
817 COLORREF map[2];
819 w = bm->bmWidth & ~0x7;
820 h = bm->bmHeight & ~0x7;
822 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
823 ptr = buf;
824 for(y = h-1; y >= 0; y--) {
825 for(x = 0; x < w/8; x++) {
826 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
827 ptr += 2;
830 PSDRV_WriteSpool(physDev, mypat, sizeof(mypat) - 1);
831 PSDRV_WriteImageDict(physDev, 1, 8, 8, buf);
832 PSDRV_WriteSpool(physDev, "def\n", 4);
834 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
835 map[0] = GetTextColor( physDev->hdc );
836 map[1] = GetBkColor( physDev->hdc );
837 PSDRV_WriteRGB(physDev, map, 2);
838 PSDRV_WriteIndexColorSpaceEnd(physDev);
840 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
841 w_mult = (physDev->logPixelsX + 150) / 300;
842 h_mult = (physDev->logPixelsY + 150) / 300;
843 sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
844 PSDRV_WriteSpool(physDev, buf, strlen(buf));
846 HeapFree(PSDRV_Heap, 0, buf);
847 return TRUE;
850 BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
852 static const char mypat[] = "/mypat\n";
853 static const char do_pattern[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
854 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
855 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
856 char *buf, *ptr;
857 BYTE *bits;
858 INT w, h, x, y, colours, w_mult, h_mult;
859 COLORREF map[2];
861 if(bmi->bmiHeader.biBitCount != 1) {
862 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
863 return FALSE;
866 bits = (LPBYTE)bmi + bmi->bmiHeader.biSize;
867 colours = bmi->bmiHeader.biClrUsed;
868 if (colours > 256) colours = 256;
869 if(!colours && bmi->bmiHeader.biBitCount <= 8)
870 colours = 1 << bmi->bmiHeader.biBitCount;
871 bits += colours * ((usage == DIB_RGB_COLORS) ?
872 sizeof(RGBQUAD) : sizeof(WORD));
874 w = bmi->bmiHeader.biWidth & ~0x7;
875 h = bmi->bmiHeader.biHeight & ~0x7;
877 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
878 ptr = buf;
879 for(y = h-1; y >= 0; y--) {
880 for(x = 0; x < w/8; x++) {
881 sprintf(ptr, "%02x", *(bits + x/8 + y *
882 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
883 ptr += 2;
886 PSDRV_WriteSpool(physDev, mypat, sizeof(mypat) - 1);
887 PSDRV_WriteImageDict(physDev, 1, 8, 8, buf);
888 PSDRV_WriteSpool(physDev, "def\n", 4);
890 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
891 map[0] = GetTextColor( physDev->hdc );
892 map[1] = GetBkColor( physDev->hdc );
893 PSDRV_WriteRGB(physDev, map, 2);
894 PSDRV_WriteIndexColorSpaceEnd(physDev);
896 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
897 w_mult = (physDev->logPixelsX + 150) / 300;
898 h_mult = (physDev->logPixelsY + 150) / 300;
899 sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
900 PSDRV_WriteSpool(physDev, buf, strlen(buf));
901 HeapFree(PSDRV_Heap, 0, buf);
902 return TRUE;