2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(psdrv);
17 static char psheader[] = /* title llx lly urx ury orientation */
19 "%%%%Creator: Wine PostScript Driver\n"
21 "%%%%BoundingBox: %d %d %d %d\n"
22 "%%%%Pages: (atend)\n"
23 "%%%%Orientation: %s\n"
26 static char psbeginprolog[] =
29 static char psendprolog[] =
32 static char psvectorstart[] =
35 static char psvectorend[] =
38 static char psprolog[] = /* output ANSIEncoding vector first */
41 " dup length dict begin\n"
42 " {1 index /FID ne {def} {pop pop} ifelse} forall\n"
43 " /Encoding ANSIEncoding def\n"
48 "/tmpmtrx matrix def\n"
51 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
52 " l cvi gap idiv gap mul\n"
54 " r cvi gap idiv gap mul\n"
55 " {t moveto 0 b t sub rlineto}\n"
59 static char psbeginsetup[] =
62 static char psendsetup[] =
65 static char psbeginfeature[] = /* feature, value */
67 "%%%%BeginFeature: %s %s\n";
69 static char psendfeature[] =
71 "} stopped cleartomark\n";
73 static char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
75 "%%%%BeginPageSetup\n"
77 "72 %d div 72 %d div scale\n"
83 static char psendpage[] =
87 static char psfooter[] = /* pages */
92 static char psmoveto[] = /* x, y */
95 static char pslineto[] = /* x, y */
98 static char psstroke[] =
101 static char psrectangle[] = /* x, y, width, height, -width */
108 static char psrrectangle[] = /* x, y, width, height, -width */
115 static char psshow[] = /* string */
118 static char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
121 "%d 10 div matrix rotate\n"
122 "matrix concatmatrix\n"
123 "makefont setfont\n";
125 static char pssetlinewidth[] = /* width */
128 static char pssetdash[] = /* dash, offset */
131 static char pssetgray[] = /* gray */
134 static char pssetrgbcolor[] = /* r, g, b */
135 "%.2f %.2f %.2f setrgbcolor\n";
137 static char psarc[] = /* x, y, w, h, ang1, ang2 */
138 "tmpmtrx currentmatrix pop\n"
141 "0 0 0.5 %.1f %.1f arc\n"
142 "tmpmtrx setmatrix\n";
144 static char psgsave[] =
147 static char psgrestore[] =
150 static char psfill[] =
153 static char pseofill[] =
156 static char psnewpath[] =
159 static char psclosepath[] =
162 static char psclip[] =
165 static char psinitclip[] =
168 static char pseoclip[] =
171 static char psrectclip[] =
172 "%d %d %d %d rectclip\n";
174 static char psrectclip2[] =
177 static char pshatch[] =
180 static char psrotate[] = /* ang */
183 static char psarrayget[] =
186 static char psarrayput[] =
189 static char psarraydef[] =
190 "/%s %d array def\n";
192 char *PSDRV_ANSIVector[256] = {
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x00 */
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x10 */
196 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
197 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
198 "dollar", "percent", "ampersand", "quotesingle",
199 "parenleft", "parenright", "asterisk", "plus",
200 "comma", "hyphen", "period", "slash",
201 "zero", "one", "two", "three", /* 0x30 */
202 "four", "five", "six", "seven",
203 "eight", "nine", "colon", "semicolon",
204 "less", "equal", "greater", "question",
205 "at", "A", "B", "C", /* 0x40 */
209 "P", "Q", "R", "S", /* 0x50 */
211 "X", "Y", "Z", "bracketleft",
212 "backslash", "bracketright", "asciicircum", "underscore",
213 "grave", "a", "b", "c", /* 0x60 */
217 "p", "q", "r", "s", /* 0x70 */
219 "x", "y", "z", "braceleft",
220 "bar", "braceright", "asciitilde", NULL,
221 NULL, NULL, NULL, NULL, /* 0x80 */
222 NULL, NULL, NULL, NULL,
223 NULL, NULL, NULL, NULL,
224 NULL, NULL, NULL, NULL,
225 NULL, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
226 "quotedblright","bullet", "endash", "emdash",
227 NULL, NULL, NULL, NULL,
228 NULL, NULL, NULL, NULL,
229 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
230 "currency", "yen", "brokenbar", "section",
231 "dieresis", "copyright", "ordfeminine", "guillemotleft",
232 "logicalnot", "hyphen", "registered", "macron",
233 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
234 "acute", "mu", "paragraph", "periodcentered",
235 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
236 "onequarter", "onehalf", "threequarters","questiondown",
237 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
238 "Adieresis", "Aring", "AE", "Ccedilla",
239 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
240 "Igrave", "Iacute", "Icircumflex", "Idieresis",
241 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
242 "Ocircumflex", "Otilde", "Odieresis", "multiply",
243 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
244 "Udieresis", "Yacute", "Thorn", "germandbls",
245 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
246 "adieresis", "aring", "ae", "ccedilla",
247 "egrave", "eacute", "ecircumflex", "edieresis",
248 "igrave", "iacute", "icircumflex", "idieresis",
249 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
250 "ocircumflex", "otilde", "odieresis", "divide",
251 "oslash", "ugrave", "uacute", "ucircumflex",
252 "udieresis", "yacute", "thorn", "ydieresis"
256 char psreencodefont[] = /* newfontname basefontname*/
257 "/%s /%s reencodefont\n";
260 int PSDRV_WriteSpool(DC *dc, LPSTR lpData, WORD cch)
262 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
264 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
265 if( !PSDRV_StartPage(dc) )
268 return WriteSpool16( physDev->job.hJob, lpData, cch );
272 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
276 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psbeginfeature) +
277 strlen(feature) + strlen(value));
280 sprintf(buf, psbeginfeature, feature, value);
281 WriteSpool16( hJob, buf, strlen(buf) );
283 WriteSpool16( hJob, invocation, strlen(invocation) );
285 WriteSpool16( hJob, psendfeature, strlen(psendfeature) );
287 HeapFree( PSDRV_Heap, 0, buf );
293 INT PSDRV_WriteHeader( DC *dc, LPCSTR title )
295 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
296 char *buf, *orient, vectbuf[256];
299 int llx, lly, urx, ury, i, j;
301 TRACE("'%s'\n", title);
303 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
304 strlen(title) + 30 );
306 WARN("HeapAlloc failed\n");
310 /* BBox co-ords are in default user co-ord system so urx < ury even in
312 llx = physDev->PageSize.left * 72.0 / dc->devCaps->logPixelsX;
313 lly = physDev->PageSize.bottom * 72.0 / dc->devCaps->logPixelsY;
314 urx = physDev->PageSize.right * 72.0 / dc->devCaps->logPixelsX;
315 ury = physDev->PageSize.top * 72.0 / dc->devCaps->logPixelsY;
317 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
318 orient = "Landscape";
323 /* FIXME should do something better with BBox */
325 sprintf(buf, psheader, title, llx, lly, urx, ury, orient);
327 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
329 WARN("WriteSpool error\n");
330 HeapFree( PSDRV_Heap, 0, buf );
333 HeapFree( PSDRV_Heap, 0, buf );
335 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
336 WriteSpool16( physDev->job.hJob, psvectorstart, strlen(psvectorstart) );
338 for(i = 0; i < 256; i += 8) {
340 for(j = 0; j < 8; j++) {
341 strcat(vectbuf, "/");
342 if(PSDRV_ANSIVector[i+j]) {
343 strcat(vectbuf, PSDRV_ANSIVector[i+j]);
344 strcat(vectbuf, " ");
346 strcat(vectbuf, ".notdef ");
349 strcat(vectbuf, "\n");
350 WriteSpool16( physDev->job.hJob, vectbuf, strlen(vectbuf) );
353 WriteSpool16( physDev->job.hJob, psvectorend, strlen(psvectorend) );
354 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
355 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
358 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
360 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
361 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
362 if(slot->InvocationString) {
363 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
364 slot->InvocationString);
370 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
371 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
372 if(page->InvocationString) {
373 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
374 page->InvocationString);
380 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
387 INT PSDRV_WriteFooter( DC *dc )
389 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
392 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
394 WARN("HeapAlloc failed\n");
398 sprintf(buf, psfooter, physDev->job.PageNo);
400 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
402 WARN("WriteSpool error\n");
403 HeapFree( PSDRV_Heap, 0, buf );
406 HeapFree( PSDRV_Heap, 0, buf );
412 INT PSDRV_WriteEndPage( DC *dc )
414 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
416 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
417 sizeof(psendpage)-1 ) {
418 WARN("WriteSpool error\n");
427 INT PSDRV_WriteNewPage( DC *dc )
429 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
432 signed int xtrans, ytrans, rotation;
434 sprintf(name, "%d", physDev->job.PageNo);
436 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
438 WARN("HeapAlloc failed\n");
442 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
443 if(physDev->pi->ppd->LandscapeOrientation == -90) {
444 xtrans = physDev->PageSize.right;
445 ytrans = physDev->PageSize.top;
448 xtrans = physDev->PageSize.left;
449 ytrans = physDev->PageSize.bottom;
453 xtrans = physDev->PageSize.left;
454 ytrans = physDev->PageSize.top;
458 sprintf(buf, psnewpage, name, physDev->job.PageNo,
459 dc->devCaps->logPixelsX, dc->devCaps->logPixelsY,
460 xtrans, ytrans, rotation);
462 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
464 WARN("WriteSpool error\n");
465 HeapFree( PSDRV_Heap, 0, buf );
468 HeapFree( PSDRV_Heap, 0, buf );
473 BOOL PSDRV_WriteMoveTo(DC *dc, INT x, INT y)
477 sprintf(buf, psmoveto, x, y);
478 return PSDRV_WriteSpool(dc, buf, strlen(buf));
481 BOOL PSDRV_WriteLineTo(DC *dc, INT x, INT y)
485 sprintf(buf, pslineto, x, y);
486 return PSDRV_WriteSpool(dc, buf, strlen(buf));
490 BOOL PSDRV_WriteStroke(DC *dc)
492 return PSDRV_WriteSpool(dc, psstroke, sizeof(psstroke)-1);
497 BOOL PSDRV_WriteRectangle(DC *dc, INT x, INT y, INT width,
502 sprintf(buf, psrectangle, x, y, width, height, -width);
503 return PSDRV_WriteSpool(dc, buf, strlen(buf));
506 BOOL PSDRV_WriteRRectangle(DC *dc, INT x, INT y, INT width,
511 sprintf(buf, psrrectangle, x, y, width, height, -width);
512 return PSDRV_WriteSpool(dc, buf, strlen(buf));
515 BOOL PSDRV_WriteArc(DC *dc, INT x, INT y, INT w, INT h, double ang1,
520 /* Make angles -ve and swap order because we're working with an upside
522 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
523 return PSDRV_WriteSpool(dc, buf, strlen(buf));
526 static char encodingext[] = "-ANSI";
528 BOOL PSDRV_WriteSetFont(DC *dc, BOOL UseANSI)
530 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
533 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
534 sizeof(pssetfont) + strlen(physDev->font.afm->FontName) + 40);
537 WARN("HeapAlloc failed\n");
541 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
542 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
545 WARN("HeapAlloc failed\n");
546 HeapFree(PSDRV_Heap, 0, buf);
551 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
553 strcpy(newbuf, physDev->font.afm->FontName);
555 sprintf(buf, pssetfont, newbuf,
556 physDev->font.size, -physDev->font.size,
557 -physDev->font.escapement);
559 PSDRV_WriteSpool(dc, buf, strlen(buf));
560 HeapFree(PSDRV_Heap, 0, buf);
564 BOOL PSDRV_WriteSetColor(DC *dc, PSCOLOR *color)
566 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
569 PSDRV_CopyColor(&physDev->inkColor, color);
570 switch(color->type) {
572 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
574 return PSDRV_WriteSpool(dc, buf, strlen(buf));
577 sprintf(buf, pssetgray, color->value.gray.i);
578 return PSDRV_WriteSpool(dc, buf, strlen(buf));
581 ERR("Unkonwn colour type %d\n", color->type);
588 BOOL PSDRV_WriteSetPen(DC *dc)
590 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
593 sprintf(buf, pssetlinewidth, physDev->pen.width);
594 PSDRV_WriteSpool(dc, buf, strlen(buf));
596 if(physDev->pen.dash) {
597 sprintf(buf, pssetdash, physDev->pen.dash, 0);
598 PSDRV_WriteSpool(dc, buf, strlen(buf));
604 BOOL PSDRV_WriteReencodeFont(DC *dc)
606 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
609 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
610 sizeof(psreencodefont) + 2 * strlen(physDev->font.afm->FontName)
611 + sizeof(encodingext));
614 WARN("HeapAlloc failed\n");
618 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
619 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
622 WARN("HeapAlloc failed\n");
623 HeapFree(PSDRV_Heap, 0, buf);
627 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
628 sprintf(buf, psreencodefont, newbuf, physDev->font.afm->FontName);
630 PSDRV_WriteSpool(dc, buf, strlen(buf));
632 HeapFree(PSDRV_Heap, 0, newbuf);
633 HeapFree(PSDRV_Heap, 0, buf);
637 BOOL PSDRV_WriteShow(DC *dc, LPCWSTR str, INT count)
640 INT buflen = count + 10, i, done;
642 buf = (char *)HeapAlloc( PSDRV_Heap, 0, buflen );
644 for(i = done = 0; i < count; i++) {
645 char c = PSDRV_UnicodeToANSI(str[i]);
647 if(done + 4 >= buflen)
648 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
649 sprintf(buf + done, "\\%03o", (int)(unsigned char)c);
651 } else if(c == '\\' || c == '(' || c == ')' ) {
652 if(done + 2 >= buflen)
653 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
657 if(done + 1 >= buflen)
658 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
664 buf1 = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psshow) + done);
666 sprintf(buf1, psshow, buf);
668 PSDRV_WriteSpool(dc, buf1, strlen(buf1));
669 HeapFree(PSDRV_Heap, 0, buf);
670 HeapFree(PSDRV_Heap, 0, buf1);
675 BOOL PSDRV_WriteFill(DC *dc)
677 return PSDRV_WriteSpool(dc, psfill, sizeof(psfill)-1);
680 BOOL PSDRV_WriteEOFill(DC *dc)
682 return PSDRV_WriteSpool(dc, pseofill, sizeof(pseofill)-1);
685 BOOL PSDRV_WriteGSave(DC *dc)
687 return PSDRV_WriteSpool(dc, psgsave, sizeof(psgsave)-1);
690 BOOL PSDRV_WriteGRestore(DC *dc)
692 return PSDRV_WriteSpool(dc, psgrestore, sizeof(psgrestore)-1);
695 BOOL PSDRV_WriteNewPath(DC *dc)
697 return PSDRV_WriteSpool(dc, psnewpath, sizeof(psnewpath)-1);
700 BOOL PSDRV_WriteClosePath(DC *dc)
702 return PSDRV_WriteSpool(dc, psclosepath, sizeof(psclosepath)-1);
705 BOOL PSDRV_WriteClip(DC *dc)
707 return PSDRV_WriteSpool(dc, psclip, sizeof(psclip)-1);
710 BOOL PSDRV_WriteEOClip(DC *dc)
712 return PSDRV_WriteSpool(dc, pseoclip, sizeof(pseoclip)-1);
715 BOOL PSDRV_WriteInitClip(DC *dc)
717 return PSDRV_WriteSpool(dc, psinitclip, sizeof(psinitclip)-1);
720 BOOL PSDRV_WriteHatch(DC *dc)
722 return PSDRV_WriteSpool(dc, pshatch, sizeof(pshatch)-1);
725 BOOL PSDRV_WriteRotate(DC *dc, float ang)
729 sprintf(buf, psrotate, ang);
730 return PSDRV_WriteSpool(dc, buf, strlen(buf));
733 BOOL PSDRV_WriteIndexColorSpaceBegin(DC *dc, int size)
736 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
737 return PSDRV_WriteSpool(dc, buf, strlen(buf));
740 BOOL PSDRV_WriteIndexColorSpaceEnd(DC *dc)
742 char buf[] = ">\n] setcolorspace\n";
743 return PSDRV_WriteSpool(dc, buf, sizeof(buf) - 1);
746 BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number)
748 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
752 for(i = 0; i < number; i++) {
753 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
754 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
755 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
758 PSDRV_WriteSpool(dc, buf, number * 7);
759 HeapFree(PSDRV_Heap, 0, buf);
764 BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst,
765 INT widthDst, INT heightDst, INT widthSrc,
766 INT heightSrc, char *bits)
768 char start[] = "%d %d translate\n%d %d scale\n<<\n"
769 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
770 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
772 char decode1[] = " /Decode [0 %d]\n";
773 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
775 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
776 char endbits[] = " /DataSource <%s>\n>> image\n";
778 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
780 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
781 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
783 PSDRV_WriteSpool(dc, buf, strlen(buf));
787 sprintf(buf, decode1, 255);
791 sprintf(buf, decode1, 15);
795 sprintf(buf, decode1, 1);
799 strcpy(buf, decode3);
803 PSDRV_WriteSpool(dc, buf, strlen(buf));
806 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
808 sprintf(buf, endbits, bits);
809 PSDRV_WriteSpool(dc, buf, strlen(buf));
812 HeapFree(PSDRV_Heap, 0, buf);
817 BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number)
819 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
825 for(i = 0; i < number; i++) {
826 sprintf(ptr, "%02x%c", bytes[i],
827 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
830 PSDRV_WriteSpool(dc, buf, number * 3);
832 HeapFree(PSDRV_Heap, 0, buf);
836 BOOL PSDRV_WriteDIBits16(DC *dc, const WORD *words, int number)
838 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
844 for(i = 0; i < number; i++) {
847 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
849 r = words[i] >> 10 & 0x1f;
851 g = words[i] >> 5 & 0x1f;
855 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
856 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
859 PSDRV_WriteSpool(dc, buf, number * 7);
861 HeapFree(PSDRV_Heap, 0, buf);
865 BOOL PSDRV_WriteDIBits24(DC *dc, const BYTE *bits, int number)
867 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
873 for(i = 0; i < number; i++) {
874 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
876 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
879 PSDRV_WriteSpool(dc, buf, number * 7);
881 HeapFree(PSDRV_Heap, 0, buf);
885 BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number)
887 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
893 for(i = 0; i < number; i++) {
894 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
896 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
899 PSDRV_WriteSpool(dc, buf, number * 7);
901 HeapFree(PSDRV_Heap, 0, buf);
905 BOOL PSDRV_WriteArrayGet(DC *dc, CHAR *pszArrayName, INT nIndex)
909 sprintf(buf, psarrayget, pszArrayName, nIndex);
910 return PSDRV_WriteSpool(dc, buf, strlen(buf));
913 BOOL PSDRV_WriteArrayPut(DC *dc, CHAR *pszArrayName, INT nIndex, LONG lObject)
917 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
918 return PSDRV_WriteSpool(dc, buf, strlen(buf));
921 BOOL PSDRV_WriteArrayDef(DC *dc, CHAR *pszArrayName, INT nSize)
925 sprintf(buf, psarraydef, pszArrayName, nSize);
926 return PSDRV_WriteSpool(dc, buf, strlen(buf));
929 BOOL PSDRV_WriteRectClip(DC *dc, INT x, INT y, INT w, INT h)
933 sprintf(buf, psrectclip, x, y, w, h);
934 return PSDRV_WriteSpool(dc, buf, strlen(buf));
937 BOOL PSDRV_WriteRectClip2(DC *dc, CHAR *pszArrayName)
941 sprintf(buf, psrectclip2, pszArrayName);
942 return PSDRV_WriteSpool(dc, buf, strlen(buf));
945 BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits)
947 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
948 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
950 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
955 w = bm->bmWidth & ~0x7;
956 h = bm->bmHeight & ~0x7;
958 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
959 sprintf(buf, start, w, h, w, h);
960 PSDRV_WriteSpool(dc, buf, strlen(buf));
961 PSDRV_WriteIndexColorSpaceBegin(dc, 1);
962 map[0] = dc->textColor;
963 map[1] = dc->backgroundColor;
964 PSDRV_WriteRGB(dc, map, 2);
965 PSDRV_WriteIndexColorSpaceEnd(dc);
967 for(y = h-1; y >= 0; y--) {
968 for(x = 0; x < w/8; x++) {
969 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
973 PSDRV_WriteImageDict(dc, 1, 0, 0, 8, 8, 8, 8, buf);
974 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
975 HeapFree(PSDRV_Heap, 0, buf);