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
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
37 static const char psheader[] = /* title llx lly urx ury */
39 "%%%%Creator: Wine PostScript Driver\n"
41 "%%%%BoundingBox: %d %d %d %d\n"
42 "%%%%Pages: (atend)\n"
45 static const char psbeginprolog[] =
48 static const char psendprolog[] =
51 static const char psprolog[] =
52 "/tmpmtrx matrix def\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"
58 " r cvi gap idiv gap mul\n"
59 " {t moveto 0 b t sub rlineto}\n"
62 "/B {pop pop pop pop} def\n"
64 "/havetype42gdir {version cvi 2015 ge} bind def\n";
66 static const char psbeginsetup[] =
69 static const char psendsetup[] =
72 static const char psbeginfeature[] = /* feature, value */
74 "%%%%BeginFeature: %s %s\n";
76 static const char psendfeature[] =
78 "} stopped cleartomark\n";
80 static const char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
82 "%%%%BeginPageSetup\n"
84 "72 %d div 72 %d div scale\n"
90 static const char psendpage[] =
94 static const char psfooter[] = /* pages */
99 static const char psmoveto[] = /* x, y */
102 static const char pslineto[] = /* x, y */
105 static const char psstroke[] =
108 static const char psrectangle[] = /* x, y, width, height, -width */
115 static const char psglyphshow[] = /* glyph name */
118 static const char pssetfont[] = /* fontname, xx_scale, xy_scale, yx_scale, yy_scale, escapement */
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 pssetgray[] = /* gray */
131 static const char pssetrgbcolor[] = /* r, g, b */
132 "%.2f %.2f %.2f setrgbcolor\n";
134 static const char psarc[] = /* x, y, w, h, ang1, ang2 */
135 "tmpmtrx currentmatrix pop\n"
138 "0 0 0.5 %.1f %.1f arc\n"
139 "tmpmtrx setmatrix\n";
141 static const char psgsave[] =
144 static const char psgrestore[] =
147 static const char psfill[] =
150 static const char pseofill[] =
153 static const char psnewpath[] =
156 static const char psclosepath[] =
159 static const char psclip[] =
162 static const char pseoclip[] =
165 static const char psrectclip[] =
166 "%d %d %d %d rectclip\n";
168 static const char psrectclip2[] =
171 static const char pshatch[] =
174 static const char psrotate[] = /* ang */
177 static const char psarrayput[] =
180 static const char psarraydef[] =
181 "/%s %d array def\n";
183 static const char psenddocument[] =
186 DWORD PSDRV_WriteSpool(PHYSDEV dev, LPCSTR lpData, DWORD cch)
188 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
189 int num, num_left = cch;
191 if(physDev->job.quiet) {
192 TRACE("ignoring output\n");
196 if(physDev->job.in_passthrough) { /* Was in PASSTHROUGH mode */
197 write_spool( dev, psenddocument, sizeof(psenddocument)-1 );
198 physDev->job.in_passthrough = physDev->job.had_passthrough_rect = FALSE;
201 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
202 if( !PSDRV_StartPage(dev) )
207 num = min(num_left, 0x8000);
208 if(write_spool( dev, lpData, num ) != num)
218 static INT PSDRV_WriteFeature(PHYSDEV dev, LPCSTR feature, LPCSTR value, LPCSTR invocation)
221 char *buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
222 strlen(feature) + strlen(value));
224 sprintf(buf, psbeginfeature, feature, value);
225 write_spool( dev, buf, strlen(buf) );
226 write_spool( dev, invocation, strlen(invocation) );
227 write_spool( dev, psendfeature, strlen(psendfeature) );
229 HeapFree( PSDRV_Heap, 0, buf );
233 /********************************************************
236 * Helper for PSDRV_WriteHeader. Escape any non-printable characters
237 * as octal. If we've had to use an escape then surround the entire string
238 * in brackets. Truncate string to represent at most 0x80 characters.
241 static char *escape_title(LPCSTR str)
248 ret = HeapAlloc(GetProcessHeap(), 0, 1);
253 for(i = 0; i < 0x80 && str[i]; i++)
261 ret = HeapAlloc(GetProcessHeap(), 0, i + 1);
267 extra += 2; /* two for the brackets */
268 cp = ret = HeapAlloc(GetProcessHeap(), 0, i + extra + 1);
270 for(i = 0; i < 0x80 && str[i]; i++)
274 BYTE b = (BYTE)str[i];
276 *cp++ = ((b >> 6) & 0x7) + '0';
277 *cp++ = ((b >> 3) & 0x7) + '0';
278 *cp++ = ((b) & 0x7) + '0';
289 INT PSDRV_WriteHeader( PHYSDEV dev, LPCSTR title )
291 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
292 char *buf, *escaped_title;
297 int llx, lly, urx, ury;
299 TRACE("%s\n", debugstr_a(title));
301 escaped_title = escape_title(title);
302 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
303 strlen(escaped_title) + 30 );
305 WARN("HeapAlloc failed\n");
309 /* BBox co-ords are in default user co-ord system so urx < ury even in
311 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
312 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
313 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
314 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
315 /* FIXME should do something better with BBox */
317 sprintf(buf, psheader, escaped_title, llx, lly, urx, ury);
319 HeapFree(GetProcessHeap(), 0, escaped_title);
320 if( write_spool( dev, buf, strlen(buf) ) != strlen(buf) ) {
321 WARN("WriteSpool error\n");
322 HeapFree( PSDRV_Heap, 0, buf );
325 HeapFree( PSDRV_Heap, 0, buf );
327 write_spool( dev, psbeginprolog, strlen(psbeginprolog) );
328 write_spool( dev, psprolog, strlen(psprolog) );
329 write_spool( dev, psendprolog, strlen(psendprolog) );
330 write_spool( dev, psbeginsetup, strlen(psbeginsetup) );
332 if(physDev->Devmode->dmPublic.u1.s1.dmCopies > 1) {
333 char copies_buf[100];
334 sprintf(copies_buf, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev->Devmode->dmPublic.u1.s1.dmCopies);
335 write_spool(dev, copies_buf, strlen(copies_buf));
338 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
339 if(slot->WinBin == physDev->Devmode->dmPublic.u1.s1.dmDefaultSource) {
340 if(slot->InvocationString) {
341 PSDRV_WriteFeature(dev, "*InputSlot", slot->Name,
342 slot->InvocationString);
348 LIST_FOR_EACH_ENTRY(page, &physDev->pi->ppd->PageSizes, PAGESIZE, entry) {
349 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
350 if(page->InvocationString) {
351 PSDRV_WriteFeature(dev, "*PageSize", page->Name,
352 page->InvocationString);
358 win_duplex = physDev->Devmode->dmPublic.dmFields & DM_DUPLEX ?
359 physDev->Devmode->dmPublic.dmDuplex : 0;
360 for(duplex = physDev->pi->ppd->Duplexes; duplex; duplex = duplex->next) {
361 if(duplex->WinDuplex == win_duplex) {
362 if(duplex->InvocationString) {
363 PSDRV_WriteFeature(dev, "*Duplex", duplex->Name,
364 duplex->InvocationString);
370 write_spool( dev, psendsetup, strlen(psendsetup) );
377 INT PSDRV_WriteFooter( PHYSDEV dev )
379 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
382 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
384 WARN("HeapAlloc failed\n");
388 sprintf(buf, psfooter, physDev->job.PageNo);
390 if( write_spool( dev, buf, strlen(buf) ) != strlen(buf) ) {
391 WARN("WriteSpool error\n");
392 HeapFree( PSDRV_Heap, 0, buf );
395 HeapFree( PSDRV_Heap, 0, buf );
401 INT PSDRV_WriteEndPage( PHYSDEV dev )
403 if( write_spool( dev, psendpage, sizeof(psendpage)-1 ) != sizeof(psendpage)-1 ) {
404 WARN("WriteSpool error\n");
413 INT PSDRV_WriteNewPage( PHYSDEV dev )
415 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
418 signed int xtrans, ytrans, rotation;
420 sprintf(name, "%d", physDev->job.PageNo);
422 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
424 WARN("HeapAlloc failed\n");
428 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
429 if(physDev->pi->ppd->LandscapeOrientation == -90) {
430 xtrans = physDev->ImageableArea.right;
431 ytrans = physDev->ImageableArea.top;
434 xtrans = physDev->ImageableArea.left;
435 ytrans = physDev->ImageableArea.bottom;
439 xtrans = physDev->ImageableArea.left;
440 ytrans = physDev->ImageableArea.top;
444 sprintf(buf, psnewpage, name, physDev->job.PageNo,
445 physDev->logPixelsX, physDev->logPixelsY,
446 xtrans, ytrans, rotation);
448 if( write_spool( dev, buf, strlen(buf) ) != strlen(buf) ) {
449 WARN("WriteSpool error\n");
450 HeapFree( PSDRV_Heap, 0, buf );
453 HeapFree( PSDRV_Heap, 0, buf );
458 BOOL PSDRV_WriteMoveTo(PHYSDEV dev, INT x, INT y)
462 sprintf(buf, psmoveto, x, y);
463 return PSDRV_WriteSpool(dev, buf, strlen(buf));
466 BOOL PSDRV_WriteLineTo(PHYSDEV dev, INT x, INT y)
470 sprintf(buf, pslineto, x, y);
471 return PSDRV_WriteSpool(dev, buf, strlen(buf));
475 BOOL PSDRV_WriteStroke(PHYSDEV dev)
477 return PSDRV_WriteSpool(dev, psstroke, sizeof(psstroke)-1);
482 BOOL PSDRV_WriteRectangle(PHYSDEV dev, INT x, INT y, INT width,
487 sprintf(buf, psrectangle, x, y, width, height, -width);
488 return PSDRV_WriteSpool(dev, buf, strlen(buf));
491 BOOL PSDRV_WriteArc(PHYSDEV dev, INT x, INT y, INT w, INT h, double ang1,
496 /* Make angles -ve and swap order because we're working with an upside
498 push_lc_numeric("C");
499 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
501 return PSDRV_WriteSpool(dev, buf, strlen(buf));
505 BOOL PSDRV_WriteSetFont(PHYSDEV dev, const char *name, matrix size, INT escapement)
509 buf = HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
513 WARN("HeapAlloc failed\n");
517 sprintf(buf, pssetfont, name, size.xx, size.xy, size.yx, size.yy, -escapement);
519 PSDRV_WriteSpool(dev, buf, strlen(buf));
520 HeapFree(PSDRV_Heap, 0, buf);
524 BOOL PSDRV_WriteSetColor(PHYSDEV dev, PSCOLOR *color)
526 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
529 PSDRV_CopyColor(&physDev->inkColor, color);
530 switch(color->type) {
532 push_lc_numeric("C");
533 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
536 return PSDRV_WriteSpool(dev, buf, strlen(buf));
539 push_lc_numeric("C");
540 sprintf(buf, pssetgray, color->value.gray.i);
542 return PSDRV_WriteSpool(dev, buf, strlen(buf));
545 ERR("Unkonwn colour type %d\n", color->type);
552 BOOL PSDRV_WriteSetPen(PHYSDEV dev)
554 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
558 sprintf(buf, pssetline, physDev->pen.width, physDev->pen.join, physDev->pen.endcap);
559 PSDRV_WriteSpool(dev, buf, strlen(buf));
561 if (physDev->pen.dash_len)
563 for (i = pos = 0; i < physDev->pen.dash_len; i++)
564 pos += sprintf( buf + pos, " %u", physDev->pen.dash[i] );
566 sprintf(buf + pos, "] %u setdash\n", 0);
569 sprintf(buf, "[] %u setdash\n", 0);
571 PSDRV_WriteSpool(dev, buf, strlen(buf));
576 BOOL PSDRV_WriteGlyphShow(PHYSDEV dev, LPCSTR g_name)
581 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
583 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
584 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
588 PSDRV_WriteSpool(dev, buf, l);
592 BOOL PSDRV_WriteFill(PHYSDEV dev)
594 return PSDRV_WriteSpool(dev, psfill, sizeof(psfill)-1);
597 BOOL PSDRV_WriteEOFill(PHYSDEV dev)
599 return PSDRV_WriteSpool(dev, pseofill, sizeof(pseofill)-1);
602 BOOL PSDRV_WriteGSave(PHYSDEV dev)
604 return PSDRV_WriteSpool(dev, psgsave, sizeof(psgsave)-1);
607 BOOL PSDRV_WriteGRestore(PHYSDEV dev)
609 return PSDRV_WriteSpool(dev, psgrestore, sizeof(psgrestore)-1);
612 BOOL PSDRV_WriteNewPath(PHYSDEV dev)
614 return PSDRV_WriteSpool(dev, psnewpath, sizeof(psnewpath)-1);
617 BOOL PSDRV_WriteClosePath(PHYSDEV dev)
619 return PSDRV_WriteSpool(dev, psclosepath, sizeof(psclosepath)-1);
622 BOOL PSDRV_WriteClip(PHYSDEV dev)
624 return PSDRV_WriteSpool(dev, psclip, sizeof(psclip)-1);
627 BOOL PSDRV_WriteEOClip(PHYSDEV dev)
629 return PSDRV_WriteSpool(dev, pseoclip, sizeof(pseoclip)-1);
632 BOOL PSDRV_WriteHatch(PHYSDEV dev)
634 return PSDRV_WriteSpool(dev, pshatch, sizeof(pshatch)-1);
637 BOOL PSDRV_WriteRotate(PHYSDEV dev, float ang)
641 push_lc_numeric("C");
642 sprintf(buf, psrotate, ang);
644 return PSDRV_WriteSpool(dev, buf, strlen(buf));
647 BOOL PSDRV_WriteIndexColorSpaceBegin(PHYSDEV dev, int size)
650 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
651 return PSDRV_WriteSpool(dev, buf, strlen(buf));
654 BOOL PSDRV_WriteIndexColorSpaceEnd(PHYSDEV dev)
656 static const char buf[] = ">\n] setcolorspace\n";
657 return PSDRV_WriteSpool(dev, buf, sizeof(buf) - 1);
660 static BOOL PSDRV_WriteRGB(PHYSDEV dev, COLORREF *map, int number)
662 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
666 for(i = 0; i < number; i++) {
667 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
668 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
669 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
672 PSDRV_WriteSpool(dev, buf, number * 7);
673 HeapFree(PSDRV_Heap, 0, buf);
677 BOOL PSDRV_WriteRGBQUAD(PHYSDEV dev, const RGBQUAD *rgb, int number)
679 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
683 for(i = 0; i < number; i++, rgb++)
684 ptr += sprintf(ptr, "%02x%02x%02x%c", rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue,
685 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
687 PSDRV_WriteSpool(dev, buf, ptr - buf);
688 HeapFree(PSDRV_Heap, 0, buf);
692 static BOOL PSDRV_WriteImageDict(PHYSDEV dev, WORD depth,
693 INT widthSrc, INT heightSrc, char *bits, BOOL top_down)
695 static const char start[] = "<<\n"
696 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
697 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
699 static const char decode1[] = " /Decode [0 %d]\n";
700 static const char decode3[] = " /Decode [0 1 0 1 0 1]\n";
702 static const char end[] = " /DataSource currentfile /ASCII85Decode filter /RunLengthDecode filter\n>>\n";
703 static const char endbits[] = " /DataSource <%s>\n>>\n";
705 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
708 sprintf(buf, start, widthSrc, heightSrc,
709 (depth < 8) ? depth : 8, widthSrc, heightSrc, 0);
711 sprintf(buf, start, widthSrc, heightSrc,
712 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
714 PSDRV_WriteSpool(dev, buf, strlen(buf));
718 sprintf(buf, decode1, 255);
722 sprintf(buf, decode1, 15);
726 sprintf(buf, decode1, 1);
730 strcpy(buf, decode3);
734 PSDRV_WriteSpool(dev, buf, strlen(buf));
737 PSDRV_WriteSpool(dev, end, sizeof(end) - 1);
739 sprintf(buf, endbits, bits);
740 PSDRV_WriteSpool(dev, buf, strlen(buf));
743 HeapFree(PSDRV_Heap, 0, buf);
747 BOOL PSDRV_WriteImage(PHYSDEV dev, WORD depth, INT xDst, INT yDst,
748 INT widthDst, INT heightDst, INT widthSrc,
749 INT heightSrc, BOOL mask, BOOL top_down)
751 static const char start[] = "%d %d translate\n%d %d scale\n";
752 static const char image[] = "image\n";
753 static const char imagemask[] = "imagemask\n";
756 sprintf(buf, start, xDst, yDst, widthDst, heightDst);
757 PSDRV_WriteSpool(dev, buf, strlen(buf));
758 PSDRV_WriteImageDict(dev, depth, widthSrc, heightSrc, NULL, top_down);
760 PSDRV_WriteSpool(dev, imagemask, sizeof(imagemask) - 1);
762 PSDRV_WriteSpool(dev, image, sizeof(image) - 1);
767 BOOL PSDRV_WriteBytes(PHYSDEV dev, const BYTE *bytes, DWORD number)
769 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
775 for(i = 0; i < number; i++) {
776 sprintf(ptr, "%02x", bytes[i]);
778 if(((i & 0xf) == 0xf) || (i == number - 1)) {
783 PSDRV_WriteSpool(dev, buf, ptr - buf);
784 HeapFree(PSDRV_Heap, 0, buf);
788 BOOL PSDRV_WriteData(PHYSDEV dev, const BYTE *data, DWORD number)
790 int num, num_left = number;
793 num = min(num_left, 60);
794 PSDRV_WriteSpool(dev, (LPCSTR)data, num);
795 PSDRV_WriteSpool(dev, "\n", 1);
803 BOOL PSDRV_WriteArrayPut(PHYSDEV dev, CHAR *pszArrayName, INT nIndex, LONG lObject)
807 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
808 return PSDRV_WriteSpool(dev, buf, strlen(buf));
811 BOOL PSDRV_WriteArrayDef(PHYSDEV dev, CHAR *pszArrayName, INT nSize)
815 sprintf(buf, psarraydef, pszArrayName, nSize);
816 return PSDRV_WriteSpool(dev, buf, strlen(buf));
819 BOOL PSDRV_WriteRectClip(PHYSDEV dev, INT x, INT y, INT w, INT h)
823 sprintf(buf, psrectclip, x, y, w, h);
824 return PSDRV_WriteSpool(dev, buf, strlen(buf));
827 BOOL PSDRV_WriteRectClip2(PHYSDEV dev, CHAR *pszArrayName)
831 sprintf(buf, psrectclip2, pszArrayName);
832 return PSDRV_WriteSpool(dev, buf, strlen(buf));
835 BOOL PSDRV_WritePatternDict(PHYSDEV dev, BITMAP *bm, BYTE *bits)
837 static const char mypat[] = "/mypat\n";
838 static const char do_pattern[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
839 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
840 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
842 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
844 INT w, h, x, y, w_mult, h_mult;
847 w = bm->bmWidth & ~0x7;
848 h = bm->bmHeight & ~0x7;
850 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
852 for(y = h-1; y >= 0; y--) {
853 for(x = 0; x < w/8; x++) {
854 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
858 PSDRV_WriteSpool(dev, mypat, sizeof(mypat) - 1);
859 PSDRV_WriteImageDict(dev, 1, 8, 8, buf, FALSE);
860 PSDRV_WriteSpool(dev, "def\n", 4);
862 PSDRV_WriteIndexColorSpaceBegin(dev, 1);
863 map[0] = GetTextColor( dev->hdc );
864 map[1] = GetBkColor( dev->hdc );
865 PSDRV_WriteRGB(dev, map, 2);
866 PSDRV_WriteIndexColorSpaceEnd(dev);
868 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
869 w_mult = (physDev->logPixelsX + 150) / 300;
870 h_mult = (physDev->logPixelsY + 150) / 300;
871 sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
872 PSDRV_WriteSpool(dev, buf, strlen(buf));
874 HeapFree(PSDRV_Heap, 0, buf);
878 BOOL PSDRV_WriteDIBPatternDict(PHYSDEV dev, BITMAPINFO *bmi, UINT usage)
880 static const char mypat[] = "/mypat\n";
881 static const char do_pattern[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
882 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n 0 0 translate\n"
883 " %d %d scale\n mypat image\n end\n }\n>>\n matrix makepattern setpattern\n";
884 PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
887 INT w, h, x, y, colours, w_mult, h_mult;
890 if(bmi->bmiHeader.biBitCount != 1) {
891 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
895 bits = (LPBYTE)bmi + bmi->bmiHeader.biSize;
896 colours = bmi->bmiHeader.biClrUsed;
897 if (colours > 256) colours = 256;
898 if(!colours && bmi->bmiHeader.biBitCount <= 8)
899 colours = 1 << bmi->bmiHeader.biBitCount;
900 bits += colours * ((usage == DIB_RGB_COLORS) ?
901 sizeof(RGBQUAD) : sizeof(WORD));
903 w = bmi->bmiHeader.biWidth & ~0x7;
904 h = bmi->bmiHeader.biHeight & ~0x7;
906 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(do_pattern) + 100);
908 for(y = h-1; y >= 0; y--) {
909 for(x = 0; x < w/8; x++) {
910 sprintf(ptr, "%02x", *(bits + x/8 + y *
911 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
915 PSDRV_WriteSpool(dev, mypat, sizeof(mypat) - 1);
916 PSDRV_WriteImageDict(dev, 1, 8, 8, buf, FALSE);
917 PSDRV_WriteSpool(dev, "def\n", 4);
919 PSDRV_WriteIndexColorSpaceBegin(dev, 1);
920 map[0] = GetTextColor( dev->hdc );
921 map[1] = GetBkColor( dev->hdc );
922 PSDRV_WriteRGB(dev, map, 2);
923 PSDRV_WriteIndexColorSpaceEnd(dev);
925 /* Windows seems to scale patterns so that a one pixel corresponds to 1/300" */
926 w_mult = (physDev->logPixelsX + 150) / 300;
927 h_mult = (physDev->logPixelsY + 150) / 300;
928 sprintf(buf, do_pattern, w * w_mult, h * h_mult, w * w_mult, h * h_mult, w * w_mult, h * h_mult);
929 PSDRV_WriteSpool(dev, buf, strlen(buf));
930 HeapFree(PSDRV_Heap, 0, buf);