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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
34 static const char psheader[] = /* title llx lly urx ury */
36 "%%%%Creator: Wine PostScript Driver\n"
38 "%%%%BoundingBox: %d %d %d %d\n"
39 "%%%%Pages: (atend)\n"
42 static const char psbeginprolog[] =
45 static const char psendprolog[] =
48 static const char psprolog[] =
49 "/tmpmtrx matrix def\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"
55 " r cvi gap idiv gap mul\n"
56 " {t moveto 0 b t sub rlineto}\n"
59 "/B {pop pop pop pop} def\n"
60 "/havetype42gdir {version cvi 2015 ge} bind def\n";
62 static const char psbeginsetup[] =
65 static const char psendsetup[] =
68 static const char psbeginfeature[] = /* feature, value */
70 "%%%%BeginFeature: %s %s\n";
72 static const char psendfeature[] =
74 "} stopped cleartomark\n";
76 static const char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
78 "%%%%BeginPageSetup\n"
80 "72 %d div 72 %d div scale\n"
86 static const char psendpage[] =
90 static const char psfooter[] = /* pages */
95 static const char psmoveto[] = /* x, y */
98 static const char pslineto[] = /* x, y */
101 static const char psstroke[] =
104 static const char psrectangle[] = /* x, y, width, height, -width */
111 static const char psrrectangle[] = /* x, y, width, height, -width */
118 static const char psglyphshow[] = /* glyph name */
121 static const char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
124 "%d 10 div matrix rotate\n"
125 "matrix concatmatrix\n"
126 "makefont setfont\n";
128 static const char pssetlinewidth[] = /* width */
131 static const char pssetdash[] = /* dash, offset */
134 static const char pssetgray[] = /* gray */
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"
144 "0 0 0.5 %.1f %.1f arc\n"
145 "tmpmtrx setmatrix\n";
147 static const char psgsave[] =
150 static const char psgrestore[] =
153 static const char psfill[] =
156 static const char pseofill[] =
159 static const char psnewpath[] =
162 static const char psclosepath[] =
165 static const char psclip[] =
168 static const char psinitclip[] =
171 static const char pseoclip[] =
174 static const char psrectclip[] =
175 "%d %d %d %d rectclip\n";
177 static const char psrectclip2[] =
180 static const char pshatch[] =
183 static const char psrotate[] = /* ang */
186 static const char psarrayget[] =
189 static const char psarrayput[] =
192 static const char psarraydef[] =
193 "/%s %d array def\n";
196 int PSDRV_WriteSpool(PSDRV_PDEVICE *physDev, LPCSTR lpData, WORD cch)
198 if(physDev->job.quiet) {
199 TRACE("ignoring output\n");
203 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
204 if( !PSDRV_StartPage(physDev) )
207 return WriteSpool16( physDev->job.hJob, (LPSTR)lpData, cch );
211 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
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, (LPSTR)psendfeature, strlen(psendfeature) );
226 HeapFree( PSDRV_Heap, 0, buf );
232 INT PSDRV_WriteHeader( PSDRV_PDEVICE *physDev, LPCSTR title )
239 int llx, lly, urx, ury;
241 TRACE("'%s'\n", debugstr_a(title));
243 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
244 (title ? strlen(title) : 0) + 30 );
246 WARN("HeapAlloc failed\n");
250 /* BBox co-ords are in default user co-ord system so urx < ury even in
252 llx = physDev->ImageableArea.left * 72.0 / physDev->logPixelsX;
253 lly = physDev->ImageableArea.bottom * 72.0 / physDev->logPixelsY;
254 urx = physDev->ImageableArea.right * 72.0 / physDev->logPixelsX;
255 ury = physDev->ImageableArea.top * 72.0 / physDev->logPixelsY;
256 /* FIXME should do something better with BBox */
258 sprintf(buf, psheader, title ? title : "", llx, lly, urx, ury);
260 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
262 WARN("WriteSpool error\n");
263 HeapFree( PSDRV_Heap, 0, buf );
266 HeapFree( PSDRV_Heap, 0, buf );
268 WriteSpool16( physDev->job.hJob, (LPSTR)psbeginprolog, strlen(psbeginprolog) );
269 WriteSpool16( physDev->job.hJob, (LPSTR)psprolog, strlen(psprolog) );
270 WriteSpool16( physDev->job.hJob, (LPSTR)psendprolog, strlen(psendprolog) );
272 WriteSpool16( physDev->job.hJob, (LPSTR)psbeginsetup, strlen(psbeginsetup) );
274 if(physDev->Devmode->dmPublic.dmCopies > 1) {
275 char copies_buf[100];
276 sprintf(copies_buf, "mark {\n << /NumCopies %d >> setpagedevice\n} stopped cleartomark\n", physDev->Devmode->dmPublic.dmCopies);
277 WriteSpool16(physDev->job.hJob, copies_buf, strlen(copies_buf));
280 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
281 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
282 if(slot->InvocationString) {
283 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
284 slot->InvocationString);
290 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
291 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
292 if(page->InvocationString) {
293 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
294 page->InvocationString);
300 win_duplex = physDev->Devmode->dmPublic.dmFields & DM_DUPLEX ?
301 physDev->Devmode->dmPublic.dmDuplex : 0;
302 for(duplex = physDev->pi->ppd->Duplexes; duplex; duplex = duplex->next) {
303 if(duplex->WinDuplex == win_duplex) {
304 if(duplex->InvocationString) {
305 PSDRV_WriteFeature(physDev->job.hJob, "*Duplex", duplex->Name,
306 duplex->InvocationString);
312 WriteSpool16( physDev->job.hJob, (LPSTR)psendsetup, strlen(psendsetup) );
319 INT PSDRV_WriteFooter( PSDRV_PDEVICE *physDev )
323 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
325 WARN("HeapAlloc failed\n");
329 sprintf(buf, psfooter, physDev->job.PageNo);
331 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
333 WARN("WriteSpool error\n");
334 HeapFree( PSDRV_Heap, 0, buf );
337 HeapFree( PSDRV_Heap, 0, buf );
343 INT PSDRV_WriteEndPage( PSDRV_PDEVICE *physDev )
345 if( WriteSpool16( physDev->job.hJob, (LPSTR)psendpage, sizeof(psendpage)-1 ) !=
346 sizeof(psendpage)-1 ) {
347 WARN("WriteSpool error\n");
356 INT PSDRV_WriteNewPage( PSDRV_PDEVICE *physDev )
360 signed int xtrans, ytrans, rotation;
362 sprintf(name, "%d", physDev->job.PageNo);
364 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
366 WARN("HeapAlloc failed\n");
370 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
371 if(physDev->pi->ppd->LandscapeOrientation == -90) {
372 xtrans = physDev->ImageableArea.right;
373 ytrans = physDev->ImageableArea.top;
376 xtrans = physDev->ImageableArea.left;
377 ytrans = physDev->ImageableArea.bottom;
381 xtrans = physDev->ImageableArea.left;
382 ytrans = physDev->ImageableArea.top;
386 sprintf(buf, psnewpage, name, physDev->job.PageNo,
387 physDev->logPixelsX, physDev->logPixelsY,
388 xtrans, ytrans, rotation);
390 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
392 WARN("WriteSpool error\n");
393 HeapFree( PSDRV_Heap, 0, buf );
396 HeapFree( PSDRV_Heap, 0, buf );
401 BOOL PSDRV_WriteMoveTo(PSDRV_PDEVICE *physDev, INT x, INT y)
405 sprintf(buf, psmoveto, x, y);
406 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
409 BOOL PSDRV_WriteLineTo(PSDRV_PDEVICE *physDev, INT x, INT y)
413 sprintf(buf, pslineto, x, y);
414 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
418 BOOL PSDRV_WriteStroke(PSDRV_PDEVICE *physDev)
420 return PSDRV_WriteSpool(physDev, psstroke, sizeof(psstroke)-1);
425 BOOL PSDRV_WriteRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
430 sprintf(buf, psrectangle, x, y, width, height, -width);
431 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
434 BOOL PSDRV_WriteRRectangle(PSDRV_PDEVICE *physDev, INT x, INT y, INT width,
439 sprintf(buf, psrrectangle, x, y, width, height, -width);
440 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
443 BOOL PSDRV_WriteArc(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h, double ang1,
448 /* Make angles -ve and swap order because we're working with an upside
450 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
451 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
455 BOOL PSDRV_WriteSetFont(PSDRV_PDEVICE *physDev, const char *name, INT size, INT escapement)
459 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(pssetfont) +
463 WARN("HeapAlloc failed\n");
467 sprintf(buf, pssetfont, name, size, -size, -escapement);
469 PSDRV_WriteSpool(physDev, buf, strlen(buf));
470 HeapFree(PSDRV_Heap, 0, buf);
474 BOOL PSDRV_WriteSetColor(PSDRV_PDEVICE *physDev, PSCOLOR *color)
478 PSDRV_CopyColor(&physDev->inkColor, color);
479 switch(color->type) {
481 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
483 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
486 sprintf(buf, pssetgray, color->value.gray.i);
487 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
490 ERR("Unkonwn colour type %d\n", color->type);
497 BOOL PSDRV_WriteSetPen(PSDRV_PDEVICE *physDev)
501 sprintf(buf, pssetlinewidth, physDev->pen.width);
502 PSDRV_WriteSpool(physDev, buf, strlen(buf));
504 if(physDev->pen.dash) {
505 sprintf(buf, pssetdash, physDev->pen.dash, 0);
506 PSDRV_WriteSpool(physDev, buf, strlen(buf));
512 BOOL PSDRV_WriteGlyphShow(PSDRV_PDEVICE *physDev, LPCSTR g_name)
517 l = snprintf(buf, sizeof(buf), psglyphshow, g_name);
519 if (l < sizeof(psglyphshow) - 2 || l > sizeof(buf) - 1) {
520 WARN("Unusable glyph name '%s' - ignoring\n", g_name);
524 PSDRV_WriteSpool(physDev, buf, l);
528 BOOL PSDRV_WriteFill(PSDRV_PDEVICE *physDev)
530 return PSDRV_WriteSpool(physDev, psfill, sizeof(psfill)-1);
533 BOOL PSDRV_WriteEOFill(PSDRV_PDEVICE *physDev)
535 return PSDRV_WriteSpool(physDev, pseofill, sizeof(pseofill)-1);
538 BOOL PSDRV_WriteGSave(PSDRV_PDEVICE *physDev)
540 return PSDRV_WriteSpool(physDev, psgsave, sizeof(psgsave)-1);
543 BOOL PSDRV_WriteGRestore(PSDRV_PDEVICE *physDev)
545 return PSDRV_WriteSpool(physDev, psgrestore, sizeof(psgrestore)-1);
548 BOOL PSDRV_WriteNewPath(PSDRV_PDEVICE *physDev)
550 return PSDRV_WriteSpool(physDev, psnewpath, sizeof(psnewpath)-1);
553 BOOL PSDRV_WriteClosePath(PSDRV_PDEVICE *physDev)
555 return PSDRV_WriteSpool(physDev, psclosepath, sizeof(psclosepath)-1);
558 BOOL PSDRV_WriteClip(PSDRV_PDEVICE *physDev)
560 return PSDRV_WriteSpool(physDev, psclip, sizeof(psclip)-1);
563 BOOL PSDRV_WriteEOClip(PSDRV_PDEVICE *physDev)
565 return PSDRV_WriteSpool(physDev, pseoclip, sizeof(pseoclip)-1);
568 BOOL PSDRV_WriteInitClip(PSDRV_PDEVICE *physDev)
570 return PSDRV_WriteSpool(physDev, psinitclip, sizeof(psinitclip)-1);
573 BOOL PSDRV_WriteHatch(PSDRV_PDEVICE *physDev)
575 return PSDRV_WriteSpool(physDev, pshatch, sizeof(pshatch)-1);
578 BOOL PSDRV_WriteRotate(PSDRV_PDEVICE *physDev, float ang)
582 sprintf(buf, psrotate, ang);
583 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
586 BOOL PSDRV_WriteIndexColorSpaceBegin(PSDRV_PDEVICE *physDev, int size)
589 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
590 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
593 BOOL PSDRV_WriteIndexColorSpaceEnd(PSDRV_PDEVICE *physDev)
595 char buf[] = ">\n] setcolorspace\n";
596 return PSDRV_WriteSpool(physDev, buf, sizeof(buf) - 1);
599 BOOL PSDRV_WriteRGB(PSDRV_PDEVICE *physDev, COLORREF *map, int number)
601 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
605 for(i = 0; i < number; i++) {
606 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
607 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
608 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
611 PSDRV_WriteSpool(physDev, buf, number * 7);
612 HeapFree(PSDRV_Heap, 0, buf);
617 BOOL PSDRV_WriteImageDict(PSDRV_PDEVICE *physDev, WORD depth, INT xDst, INT yDst,
618 INT widthDst, INT heightDst, INT widthSrc,
619 INT heightSrc, char *bits, BOOL mask)
621 const char start[] = "%d %d translate\n%d %d scale\n<<\n"
622 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
623 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
625 const char decode1[] = " /Decode [0 %d]\n";
626 const char decode3[] = " /Decode [0 1 0 1 0 1]\n";
628 const char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
629 const char endmask[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> imagemask\n";
631 const char endbits[] = " /DataSource <%s>\n>> image\n";
633 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
635 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
636 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
638 PSDRV_WriteSpool(physDev, buf, strlen(buf));
642 sprintf(buf, decode1, 255);
646 sprintf(buf, decode1, 15);
650 sprintf(buf, decode1, 1);
654 strcpy(buf, decode3);
658 PSDRV_WriteSpool(physDev, buf, strlen(buf));
662 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
664 PSDRV_WriteSpool(physDev, endmask, sizeof(endmask) - 1);
666 sprintf(buf, endbits, bits);
667 PSDRV_WriteSpool(physDev, buf, strlen(buf));
670 HeapFree(PSDRV_Heap, 0, buf);
675 BOOL PSDRV_WriteBytes(PSDRV_PDEVICE *physDev, const BYTE *bytes, int number)
677 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
683 for(i = 0; i < number; i++) {
684 sprintf(ptr, "%02x", bytes[i]);
686 if(((i & 0xf) == 0xf) || (i == number - 1)) {
691 PSDRV_WriteSpool(physDev, buf, ptr - buf);
692 HeapFree(PSDRV_Heap, 0, buf);
696 BOOL PSDRV_WriteDIBits16(PSDRV_PDEVICE *physDev, const WORD *words, int number)
698 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
704 for(i = 0; i < number; i++) {
707 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
709 r = words[i] >> 10 & 0x1f;
711 g = words[i] >> 5 & 0x1f;
715 sprintf(ptr, "%02x%02x%02x", r, g, b);
717 if(((i & 0x7) == 0x7) || (i == number - 1)) {
722 PSDRV_WriteSpool(physDev, buf, ptr - buf);
724 HeapFree(PSDRV_Heap, 0, buf);
728 BOOL PSDRV_WriteDIBits24(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
730 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
736 for(i = 0; i < number; i++) {
737 sprintf(ptr, "%02x%02x%02x", bits[i * 3 + 2], bits[i * 3 + 1],
740 if(((i & 0x7) == 0x7) || (i == number - 1)) {
745 PSDRV_WriteSpool(physDev, buf, ptr - buf);
747 HeapFree(PSDRV_Heap, 0, buf);
751 BOOL PSDRV_WriteDIBits32(PSDRV_PDEVICE *physDev, const BYTE *bits, int number)
753 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
759 for(i = 0; i < number; i++) {
760 sprintf(ptr, "%02x%02x%02x", bits[i * 4 + 2], bits[i * 4 + 1],
763 if(((i & 0x7) == 0x7) || (i == number - 1)) {
768 PSDRV_WriteSpool(physDev, buf, ptr - buf);
770 HeapFree(PSDRV_Heap, 0, buf);
774 BOOL PSDRV_WriteArrayGet(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex)
778 sprintf(buf, psarrayget, pszArrayName, nIndex);
779 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
782 BOOL PSDRV_WriteArrayPut(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nIndex, LONG lObject)
786 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
787 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
790 BOOL PSDRV_WriteArrayDef(PSDRV_PDEVICE *physDev, CHAR *pszArrayName, INT nSize)
794 sprintf(buf, psarraydef, pszArrayName, nSize);
795 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
798 BOOL PSDRV_WriteRectClip(PSDRV_PDEVICE *physDev, INT x, INT y, INT w, INT h)
802 sprintf(buf, psrectclip, x, y, w, h);
803 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
806 BOOL PSDRV_WriteRectClip2(PSDRV_PDEVICE *physDev, CHAR *pszArrayName)
810 sprintf(buf, psrectclip2, pszArrayName);
811 return PSDRV_WriteSpool(physDev, buf, strlen(buf));
814 BOOL PSDRV_WritePatternDict(PSDRV_PDEVICE *physDev, BITMAP *bm, BYTE *bits)
816 const char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
817 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
819 const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
824 w = bm->bmWidth & ~0x7;
825 h = bm->bmHeight & ~0x7;
827 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
828 sprintf(buf, start, w, h, w, h);
829 PSDRV_WriteSpool(physDev, buf, strlen(buf));
830 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
831 map[0] = GetTextColor( physDev->hdc );
832 map[1] = GetBkColor( physDev->hdc );
833 PSDRV_WriteRGB(physDev, map, 2);
834 PSDRV_WriteIndexColorSpaceEnd(physDev);
836 for(y = h-1; y >= 0; y--) {
837 for(x = 0; x < w/8; x++) {
838 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
842 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
843 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
844 HeapFree(PSDRV_Heap, 0, buf);
848 BOOL PSDRV_WriteDIBPatternDict(PSDRV_PDEVICE *physDev, BITMAPINFO *bmi, UINT usage)
850 const char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
851 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
853 const char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
856 INT w, h, x, y, colours;
859 if(bmi->bmiHeader.biBitCount != 1) {
860 FIXME("dib depth %d not supported\n", bmi->bmiHeader.biBitCount);
864 bits = (char*)bmi + bmi->bmiHeader.biSize;
865 colours = bmi->bmiHeader.biClrUsed;
866 if(!colours && bmi->bmiHeader.biBitCount <= 8)
867 colours = 1 << bmi->bmiHeader.biBitCount;
868 bits += colours * ((usage == DIB_RGB_COLORS) ?
869 sizeof(RGBQUAD) : sizeof(WORD));
871 w = bmi->bmiHeader.biWidth & ~0x7;
872 h = bmi->bmiHeader.biHeight & ~0x7;
874 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
875 sprintf(buf, start, w, h, w, h);
876 PSDRV_WriteSpool(physDev, buf, strlen(buf));
877 PSDRV_WriteIndexColorSpaceBegin(physDev, 1);
878 map[0] = physDev->dc->textColor;
879 map[1] = physDev->dc->backgroundColor;
880 PSDRV_WriteRGB(physDev, map, 2);
881 PSDRV_WriteIndexColorSpaceEnd(physDev);
883 for(y = h-1; y >= 0; y--) {
884 for(x = 0; x < w/8; x++) {
885 sprintf(ptr, "%02x", *(bits + x/8 + y *
886 (bmi->bmiHeader.biWidth + 31) / 32 * 4));
890 PSDRV_WriteImageDict(physDev, 1, 0, 0, 8, 8, 8, 8, buf, FALSE);
891 PSDRV_WriteSpool(physDev, end, sizeof(end) - 1);
892 HeapFree(PSDRV_Heap, 0, buf);