- Added missing __attribute__ ((com_interface)) for IUnknown with.
[wine/hacks.git] / graphics / psdrv / ps.c
blob9c0b2c736d9fcec838109f9f8891c7bb32d80431
1 /*
2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
6 */
8 #include <ctype.h>
9 #include <string.h>
10 #include "psdrv.h"
11 #include "winspool.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(psdrv)
16 static char psheader[] = /* title llx lly urx ury orientation */
17 "%%!PS-Adobe-3.0\n"
18 "%%%%Creator: Wine PostScript Driver\n"
19 "%%%%Title: %s\n"
20 "%%%%BoundingBox: %d %d %d %d\n"
21 "%%%%Pages: (atend)\n"
22 "%%%%Orientation: %s\n"
23 "%%%%EndComments\n";
25 static char psbeginprolog[] =
26 "%%BeginProlog\n";
28 static char psendprolog[] =
29 "%%EndProlog\n";
31 static char psvectorstart[] =
32 "/ANSIEncoding [\n";
34 static char psvectorend[] =
35 "] def\n";
37 static char psprolog[] = /* output ANSIEncoding vector first */
38 "/reencodefont {\n"
39 " findfont\n"
40 " dup length dict begin\n"
41 " {1 index /FID ne {def} {pop pop} ifelse} forall\n"
42 " /Encoding ANSIEncoding def\n"
43 " currentdict\n"
44 " end\n"
45 " definefont pop\n"
46 "} bind def\n"
47 "/tmpmtrx matrix def\n"
48 "/hatch {\n"
49 " pathbbox\n"
50 " /b exch def /r exch def /t exch def /l exch def /gap 32 def\n"
51 " l cvi gap idiv gap mul\n"
52 " gap\n"
53 " r cvi gap idiv gap mul\n"
54 " {t moveto 0 b t sub rlineto}\n"
55 " for\n"
56 "} bind def\n";
58 static char psbeginsetup[] =
59 "%%BeginSetup\n";
61 static char psendsetup[] =
62 "%%EndSetup\n";
64 static char psbeginfeature[] = /* feature, value */
65 "mark {\n"
66 "%%%%BeginFeature: %s %s\n";
68 static char psendfeature[] =
69 "\n%%EndFeature\n"
70 "} stopped cleartomark\n";
72 static char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
73 "%%%%Page: %s %d\n"
74 "%%%%BeginPageSetup\n"
75 "/pgsave save def\n"
76 "72 %d div 72 %d div scale\n"
77 "%d %d translate\n"
78 "1 -1 scale\n"
79 "%d rotate\n"
80 "%%%%EndPageSetup\n";
82 static char psendpage[] =
83 "pgsave restore\n"
84 "showpage\n";
86 static char psfooter[] = /* pages */
87 "%%%%Trailer\n"
88 "%%%%Pages: %d\n"
89 "%%%%EOF\n";
91 static char psmoveto[] = /* x, y */
92 "%d %d moveto\n";
94 static char pslineto[] = /* x, y */
95 "%d %d lineto\n";
97 static char psstroke[] =
98 "stroke\n";
100 static char psrectangle[] = /* x, y, width, height, -width */
101 "%d %d moveto\n"
102 "%d 0 rlineto\n"
103 "0 %d rlineto\n"
104 "%d 0 rlineto\n"
105 "closepath\n";
107 static char psrrectangle[] = /* x, y, width, height, -width */
108 "%d %d rmoveto\n"
109 "%d 0 rlineto\n"
110 "0 %d rlineto\n"
111 "%d 0 rlineto\n"
112 "closepath\n";
114 static char psshow[] = /* string */
115 "(%s) show\n";
117 static char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
118 "/%s findfont\n"
119 "[%d 0 0 %d 0 0]\n"
120 "%d 10 div matrix rotate\n"
121 "matrix concatmatrix\n"
122 "makefont setfont\n";
124 static char pssetlinewidth[] = /* width */
125 "%d setlinewidth\n";
127 static char pssetdash[] = /* dash, offset */
128 "[%s] %d setdash\n";
130 static char pssetgray[] = /* gray */
131 "%.2f setgray\n";
133 static char pssetrgbcolor[] = /* r, g, b */
134 "%.2f %.2f %.2f setrgbcolor\n";
136 static char psarc[] = /* x, y, w, h, ang1, ang2 */
137 "tmpmtrx currentmatrix pop\n"
138 "%d %d translate\n"
139 "%d %d scale\n"
140 "0 0 0.5 %.1f %.1f arc\n"
141 "tmpmtrx setmatrix\n";
143 static char psgsave[] =
144 "gsave\n";
146 static char psgrestore[] =
147 "grestore\n";
149 static char psfill[] =
150 "fill\n";
152 static char pseofill[] =
153 "eofill\n";
155 static char psnewpath[] =
156 "newpath\n";
158 static char psclosepath[] =
159 "closepath\n";
161 static char psclip[] =
162 "clip\n";
164 static char psinitclip[] =
165 "initclip\n";
167 static char pseoclip[] =
168 "eoclip\n";
170 static char psrectclip[] =
171 "%d %d %d %d rectclip\n";
173 static char psrectclip2[] =
174 "%s rectclip\n";
176 static char pshatch[] =
177 "hatch\n";
179 static char psrotate[] = /* ang */
180 "%.1f rotate\n";
182 static char psarrayget[] =
183 "%s %d get\n";
185 static char psarrayput[] =
186 "%s %d %ld put\n";
188 static char psarraydef[] =
189 "/%s %d array def\n";
191 char *PSDRV_ANSIVector[256] = {
192 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x00 */
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x10 */
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
196 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
197 "dollar", "percent", "ampersand", "quotesingle",
198 "parenleft", "parenright", "asterisk", "plus",
199 "comma", "hyphen", "period", "slash",
200 "zero", "one", "two", "three", /* 0x30 */
201 "four", "five", "six", "seven",
202 "eight", "nine", "colon", "semicolon",
203 "less", "equal", "greater", "question",
204 "at", "A", "B", "C", /* 0x40 */
205 "D", "E", "F", "G",
206 "H", "I", "J", "K",
207 "L", "M", "N", "O",
208 "P", "Q", "R", "S", /* 0x50 */
209 "T", "U", "V", "W",
210 "X", "Y", "Z", "bracketleft",
211 "backslash", "bracketright", "asciicircum", "underscore",
212 "grave", "a", "b", "c", /* 0x60 */
213 "d", "e", "f", "g",
214 "h", "i", "j", "k",
215 "l", "m", "n", "o",
216 "p", "q", "r", "s", /* 0x70 */
217 "t", "u", "v", "w",
218 "x", "y", "z", "braceleft",
219 "bar", "braceright", "asciitilde", NULL,
220 NULL, NULL, NULL, NULL, /* 0x80 */
221 NULL, NULL, NULL, NULL,
222 NULL, NULL, NULL, NULL,
223 NULL, NULL, NULL, NULL,
224 NULL, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
225 "quotedblright","bullet", "endash", "emdash",
226 NULL, NULL, NULL, NULL,
227 NULL, NULL, NULL, NULL,
228 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
229 "currency", "yen", "brokenbar", "section",
230 "dieresis", "copyright", "ordfeminine", "guillemotleft",
231 "logicalnot", "hyphen", "registered", "macron",
232 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
233 "acute", "mu", "paragraph", "periodcentered",
234 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
235 "onequarter", "onehalf", "threequarters","questiondown",
236 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
237 "Adieresis", "Aring", "AE", "Ccedilla",
238 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
239 "Igrave", "Iacute", "Icircumflex", "Idieresis",
240 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
241 "Ocircumflex", "Otilde", "Odieresis", "multiply",
242 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
243 "Udieresis", "Yacute", "Thorn", "germandbls",
244 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
245 "adieresis", "aring", "ae", "ccedilla",
246 "egrave", "eacute", "ecircumflex", "edieresis",
247 "igrave", "iacute", "icircumflex", "idieresis",
248 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
249 "ocircumflex", "otilde", "odieresis", "divide",
250 "oslash", "ugrave", "uacute", "ucircumflex",
251 "udieresis", "yacute", "thorn", "ydieresis"
255 char psreencodefont[] = /* newfontname basefontname*/
256 "/%s /%s reencodefont\n";
259 int PSDRV_WriteSpool(DC *dc, LPSTR lpData, WORD cch)
261 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
263 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
264 if( !PSDRV_StartPage(dc) )
265 return FALSE;
267 return WriteSpool16( physDev->job.hJob, lpData, cch );
271 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
272 char *invocation)
275 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
276 strlen(feature) + strlen(value));
279 sprintf(buf, psbeginfeature, feature, value);
280 WriteSpool16( hJob, buf, strlen(buf) );
282 WriteSpool16( hJob, invocation, strlen(invocation) );
284 WriteSpool16( hJob, psendfeature, strlen(psendfeature) );
286 HeapFree( PSDRV_Heap, 0, buf );
287 return 1;
292 INT PSDRV_WriteHeader( DC *dc, LPCSTR title )
294 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
295 char *buf, *orient, vectbuf[256];
296 INPUTSLOT *slot;
297 PAGESIZE *page;
298 int urx, ury, i, j;
300 TRACE("'%s'\n", title);
302 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
303 strlen(title) + 30 );
304 if(!buf) {
305 WARN("HeapAlloc failed\n");
306 return 0;
309 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
310 /* BBox co-ords are in default user co-ord system so urx < ury even in
311 landscape mode */
312 urx = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
313 ury = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
314 orient = "Landscape";
315 } else {
316 urx = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
317 ury = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
318 orient = "Portrait";
321 /* FIXME should do something better with BBox */
323 sprintf(buf, psheader, title, 0, 0, urx, ury, orient);
325 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
326 strlen(buf) ) {
327 WARN("WriteSpool error\n");
328 HeapFree( PSDRV_Heap, 0, buf );
329 return 0;
331 HeapFree( PSDRV_Heap, 0, buf );
333 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
334 WriteSpool16( physDev->job.hJob, psvectorstart, strlen(psvectorstart) );
336 for(i = 0; i < 256; i += 8) {
337 vectbuf[0] = '\0';
338 for(j = 0; j < 8; j++) {
339 strcat(vectbuf, "/");
340 if(PSDRV_ANSIVector[i+j]) {
341 strcat(vectbuf, PSDRV_ANSIVector[i+j]);
342 strcat(vectbuf, " ");
343 } else {
344 strcat(vectbuf, ".notdef ");
347 strcat(vectbuf, "\n");
348 WriteSpool16( physDev->job.hJob, vectbuf, strlen(vectbuf) );
351 WriteSpool16( physDev->job.hJob, psvectorend, strlen(psvectorend) );
352 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
353 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
356 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
358 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
359 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
360 if(slot->InvocationString) {
361 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
362 slot->InvocationString);
363 break;
368 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
369 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
370 if(page->InvocationString) {
371 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
372 page->InvocationString);
373 break;
378 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
381 return 1;
385 INT PSDRV_WriteFooter( DC *dc )
387 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
388 char *buf;
390 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
391 if(!buf) {
392 WARN("HeapAlloc failed\n");
393 return 0;
396 sprintf(buf, psfooter, physDev->job.PageNo);
398 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
399 strlen(buf) ) {
400 WARN("WriteSpool error\n");
401 HeapFree( PSDRV_Heap, 0, buf );
402 return 0;
404 HeapFree( PSDRV_Heap, 0, buf );
405 return 1;
410 INT PSDRV_WriteEndPage( DC *dc )
412 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
414 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
415 sizeof(psendpage)-1 ) {
416 WARN("WriteSpool error\n");
417 return 0;
419 return 1;
425 INT PSDRV_WriteNewPage( DC *dc )
427 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
428 char *buf;
429 char name[100];
430 signed int xtrans, ytrans, rotation;
432 sprintf(name, "%d", physDev->job.PageNo);
434 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
435 if(!buf) {
436 WARN("HeapAlloc failed\n");
437 return 0;
440 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
441 if(physDev->pi->ppd->LandscapeOrientation == -90) {
442 xtrans = dc->w.devCaps->vertRes;
443 ytrans = dc->w.devCaps->horzRes;
444 rotation = 90;
445 } else {
446 xtrans = ytrans = 0;
447 rotation = -90;
449 } else {
450 xtrans = 0;
451 ytrans = dc->w.devCaps->vertRes;
452 rotation = 0;
455 sprintf(buf, psnewpage, name, physDev->job.PageNo,
456 dc->w.devCaps->logPixelsX, dc->w.devCaps->logPixelsY,
457 xtrans, ytrans, rotation);
459 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
460 strlen(buf) ) {
461 WARN("WriteSpool error\n");
462 HeapFree( PSDRV_Heap, 0, buf );
463 return 0;
465 HeapFree( PSDRV_Heap, 0, buf );
466 return 1;
470 BOOL PSDRV_WriteMoveTo(DC *dc, INT x, INT y)
472 char buf[100];
474 sprintf(buf, psmoveto, x, y);
475 return PSDRV_WriteSpool(dc, buf, strlen(buf));
478 BOOL PSDRV_WriteLineTo(DC *dc, INT x, INT y)
480 char buf[100];
482 sprintf(buf, pslineto, x, y);
483 return PSDRV_WriteSpool(dc, buf, strlen(buf));
487 BOOL PSDRV_WriteStroke(DC *dc)
489 return PSDRV_WriteSpool(dc, psstroke, sizeof(psstroke)-1);
494 BOOL PSDRV_WriteRectangle(DC *dc, INT x, INT y, INT width,
495 INT height)
497 char buf[100];
499 sprintf(buf, psrectangle, x, y, width, height, -width);
500 return PSDRV_WriteSpool(dc, buf, strlen(buf));
503 BOOL PSDRV_WriteRRectangle(DC *dc, INT x, INT y, INT width,
504 INT height)
506 char buf[100];
508 sprintf(buf, psrrectangle, x, y, width, height, -width);
509 return PSDRV_WriteSpool(dc, buf, strlen(buf));
512 BOOL PSDRV_WriteArc(DC *dc, INT x, INT y, INT w, INT h, double ang1,
513 double ang2)
515 char buf[256];
517 /* Make angles -ve and swap order because we're working with an upside
518 down y-axis */
519 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
520 return PSDRV_WriteSpool(dc, buf, strlen(buf));
523 static char encodingext[] = "-ANSI";
525 BOOL PSDRV_WriteSetFont(DC *dc, BOOL UseANSI)
527 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
528 char *buf, *newbuf;
530 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
531 sizeof(pssetfont) + strlen(physDev->font.afm->FontName) + 40);
533 if(!buf) {
534 WARN("HeapAlloc failed\n");
535 return FALSE;
538 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
539 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
541 if(!newbuf) {
542 WARN("HeapAlloc failed\n");
543 HeapFree(PSDRV_Heap, 0, buf);
544 return FALSE;
547 if(UseANSI)
548 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
549 else
550 strcpy(newbuf, physDev->font.afm->FontName);
552 sprintf(buf, pssetfont, newbuf,
553 physDev->font.size, -physDev->font.size,
554 -physDev->font.escapement);
556 PSDRV_WriteSpool(dc, buf, strlen(buf));
557 HeapFree(PSDRV_Heap, 0, buf);
558 return TRUE;
561 BOOL PSDRV_WriteSetColor(DC *dc, PSCOLOR *color)
563 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
564 char buf[256];
566 PSDRV_CopyColor(&physDev->inkColor, color);
567 switch(color->type) {
568 case PSCOLOR_RGB:
569 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
570 color->value.rgb.b);
571 return PSDRV_WriteSpool(dc, buf, strlen(buf));
573 case PSCOLOR_GRAY:
574 sprintf(buf, pssetgray, color->value.gray.i);
575 return PSDRV_WriteSpool(dc, buf, strlen(buf));
577 default:
578 ERR("Unkonwn colour type %d\n", color->type);
579 break;
582 return FALSE;
585 BOOL PSDRV_WriteSetPen(DC *dc)
587 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
588 char buf[256];
590 sprintf(buf, pssetlinewidth, physDev->pen.width);
591 PSDRV_WriteSpool(dc, buf, strlen(buf));
593 if(physDev->pen.dash) {
594 sprintf(buf, pssetdash, physDev->pen.dash, 0);
595 PSDRV_WriteSpool(dc, buf, strlen(buf));
598 return TRUE;
601 BOOL PSDRV_WriteReencodeFont(DC *dc)
603 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
604 char *buf, *newbuf;
606 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
607 sizeof(psreencodefont) + 2 * strlen(physDev->font.afm->FontName)
608 + sizeof(encodingext));
610 if(!buf) {
611 WARN("HeapAlloc failed\n");
612 return FALSE;
615 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
616 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
618 if(!newbuf) {
619 WARN("HeapAlloc failed\n");
620 HeapFree(PSDRV_Heap, 0, buf);
621 return FALSE;
624 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
625 sprintf(buf, psreencodefont, newbuf, physDev->font.afm->FontName);
627 PSDRV_WriteSpool(dc, buf, strlen(buf));
629 HeapFree(PSDRV_Heap, 0, newbuf);
630 HeapFree(PSDRV_Heap, 0, buf);
631 return TRUE;
634 BOOL PSDRV_WriteShow(DC *dc, char *str, INT count)
636 char *buf, *buf1;
637 INT buflen = count + 10, i, done;
639 buf = (char *)HeapAlloc( PSDRV_Heap, 0, buflen );
641 for(i = done = 0; i < count; i++) {
642 if(!isprint(str[i])) {
643 if(done + 4 >= buflen)
644 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
645 sprintf(buf + done, "\\%03o", (int)(unsigned char)str[i] );
646 done += 4;
647 } else if(str[i] == '\\' || str[i] == '(' || str[i] == ')' ) {
648 if(done + 2 >= buflen)
649 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
650 buf[done++] = '\\';
651 buf[done++] = str[i];
652 } else {
653 if(done + 1 >= buflen)
654 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
655 buf[done++] = str[i];
658 buf[done] = '\0';
660 buf1 = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psshow) + done);
662 sprintf(buf1, psshow, buf);
664 PSDRV_WriteSpool(dc, buf1, strlen(buf1));
665 HeapFree(PSDRV_Heap, 0, buf);
666 HeapFree(PSDRV_Heap, 0, buf1);
668 return TRUE;
671 BOOL PSDRV_WriteFill(DC *dc)
673 return PSDRV_WriteSpool(dc, psfill, sizeof(psfill)-1);
676 BOOL PSDRV_WriteEOFill(DC *dc)
678 return PSDRV_WriteSpool(dc, pseofill, sizeof(pseofill)-1);
681 BOOL PSDRV_WriteGSave(DC *dc)
683 return PSDRV_WriteSpool(dc, psgsave, sizeof(psgsave)-1);
686 BOOL PSDRV_WriteGRestore(DC *dc)
688 return PSDRV_WriteSpool(dc, psgrestore, sizeof(psgrestore)-1);
691 BOOL PSDRV_WriteNewPath(DC *dc)
693 return PSDRV_WriteSpool(dc, psnewpath, sizeof(psnewpath)-1);
696 BOOL PSDRV_WriteClosePath(DC *dc)
698 return PSDRV_WriteSpool(dc, psclosepath, sizeof(psclosepath)-1);
701 BOOL PSDRV_WriteClip(DC *dc)
703 return PSDRV_WriteSpool(dc, psclip, sizeof(psclip)-1);
706 BOOL PSDRV_WriteEOClip(DC *dc)
708 return PSDRV_WriteSpool(dc, pseoclip, sizeof(pseoclip)-1);
711 BOOL PSDRV_WriteInitClip(DC *dc)
713 return PSDRV_WriteSpool(dc, psinitclip, sizeof(psinitclip)-1);
716 BOOL PSDRV_WriteHatch(DC *dc)
718 return PSDRV_WriteSpool(dc, pshatch, sizeof(pshatch)-1);
721 BOOL PSDRV_WriteRotate(DC *dc, float ang)
723 char buf[256];
725 sprintf(buf, psrotate, ang);
726 return PSDRV_WriteSpool(dc, buf, strlen(buf));
729 BOOL PSDRV_WriteIndexColorSpaceBegin(DC *dc, int size)
731 char buf[256];
732 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
733 return PSDRV_WriteSpool(dc, buf, strlen(buf));
736 BOOL PSDRV_WriteIndexColorSpaceEnd(DC *dc)
738 char buf[] = ">\n] setcolorspace\n";
739 return PSDRV_WriteSpool(dc, buf, sizeof(buf) - 1);
742 BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number)
744 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
745 int i;
747 ptr = buf;
748 for(i = 0; i < number; i++) {
749 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
750 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
751 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
752 ptr += 7;
754 PSDRV_WriteSpool(dc, buf, number * 7);
755 HeapFree(PSDRV_Heap, 0, buf);
756 return TRUE;
760 BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst,
761 INT widthDst, INT heightDst, INT widthSrc,
762 INT heightSrc, char *bits)
764 char start[] = "%d %d translate\n%d %d scale\n<<\n"
765 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
766 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
768 char decode1[] = " /Decode [0 %d]\n";
769 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
771 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
772 char endbits[] = " /DataSource <%s>\n>> image\n";
774 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
776 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
777 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
779 PSDRV_WriteSpool(dc, buf, strlen(buf));
781 switch(depth) {
782 case 8:
783 sprintf(buf, decode1, 255);
784 break;
786 case 4:
787 sprintf(buf, decode1, 15);
788 break;
790 case 1:
791 sprintf(buf, decode1, 1);
792 break;
794 default:
795 strcpy(buf, decode3);
796 break;
799 PSDRV_WriteSpool(dc, buf, strlen(buf));
801 if(!bits)
802 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
803 else {
804 sprintf(buf, endbits, bits);
805 PSDRV_WriteSpool(dc, buf, strlen(buf));
808 HeapFree(PSDRV_Heap, 0, buf);
809 return TRUE;
813 BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number)
815 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
816 char *ptr;
817 int i;
819 ptr = buf;
821 for(i = 0; i < number; i++) {
822 sprintf(ptr, "%02x%c", bytes[i],
823 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
824 ptr += 3;
826 PSDRV_WriteSpool(dc, buf, number * 3);
828 HeapFree(PSDRV_Heap, 0, buf);
829 return TRUE;
832 BOOL PSDRV_WriteDIBits16(DC *dc, const WORD *words, int number)
834 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
835 char *ptr;
836 int i;
838 ptr = buf;
840 for(i = 0; i < number; i++) {
841 int r, g, b;
843 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
845 r = words[i] >> 10 & 0x1f;
846 r = r << 3 | r >> 2;
847 g = words[i] >> 5 & 0x1f;
848 g = g << 3 | g >> 2;
849 b = words[i] & 0x1f;
850 b = b << 3 | b >> 2;
851 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
852 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
853 ptr += 7;
855 PSDRV_WriteSpool(dc, buf, number * 7);
857 HeapFree(PSDRV_Heap, 0, buf);
858 return TRUE;
861 BOOL PSDRV_WriteDIBits24(DC *dc, const BYTE *bits, int number)
863 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
864 char *ptr;
865 int i;
867 ptr = buf;
869 for(i = 0; i < number; i++) {
870 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
871 bits[i * 3],
872 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
873 ptr += 7;
875 PSDRV_WriteSpool(dc, buf, number * 7);
877 HeapFree(PSDRV_Heap, 0, buf);
878 return TRUE;
881 BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number)
883 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
884 char *ptr;
885 int i;
887 ptr = buf;
889 for(i = 0; i < number; i++) {
890 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
891 bits[i * 4],
892 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
893 ptr += 7;
895 PSDRV_WriteSpool(dc, buf, number * 7);
897 HeapFree(PSDRV_Heap, 0, buf);
898 return TRUE;
901 BOOL PSDRV_WriteArrayGet(DC *dc, CHAR *pszArrayName, INT nIndex)
903 char buf[100];
905 sprintf(buf, psarrayget, pszArrayName, nIndex);
906 return PSDRV_WriteSpool(dc, buf, strlen(buf));
909 BOOL PSDRV_WriteArrayPut(DC *dc, CHAR *pszArrayName, INT nIndex, LONG lObject)
911 char buf[100];
913 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
914 return PSDRV_WriteSpool(dc, buf, strlen(buf));
917 BOOL PSDRV_WriteArrayDef(DC *dc, CHAR *pszArrayName, INT nSize)
919 char buf[100];
921 sprintf(buf, psarraydef, pszArrayName, nSize);
922 return PSDRV_WriteSpool(dc, buf, strlen(buf));
925 BOOL PSDRV_WriteRectClip(DC *dc, INT x, INT y, INT w, INT h)
927 char buf[100];
929 sprintf(buf, psrectclip, x, y, w, h);
930 return PSDRV_WriteSpool(dc, buf, strlen(buf));
933 BOOL PSDRV_WriteRectClip2(DC *dc, CHAR *pszArrayName)
935 char buf[100];
937 sprintf(buf, psrectclip2, pszArrayName);
938 return PSDRV_WriteSpool(dc, buf, strlen(buf));
941 BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits)
943 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
944 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
946 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
947 char *buf, *ptr;
948 INT w, h, x, y;
949 COLORREF map[2];
951 w = bm->bmWidth & ~0x7;
952 h = bm->bmHeight & ~0x7;
954 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
955 sprintf(buf, start, w, h, w, h);
956 PSDRV_WriteSpool(dc, buf, strlen(buf));
957 PSDRV_WriteIndexColorSpaceBegin(dc, 1);
958 map[0] = dc->w.textColor;
959 map[1] = dc->w.backgroundColor;
960 PSDRV_WriteRGB(dc, map, 2);
961 PSDRV_WriteIndexColorSpaceEnd(dc);
962 ptr = buf;
963 for(y = h-1; y >= 0; y--) {
964 for(x = 0; x < w/8; x++) {
965 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
966 ptr += 2;
969 PSDRV_WriteImageDict(dc, 1, 0, 0, 8, 8, 8, 8, buf);
970 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
971 HeapFree(PSDRV_Heap, 0, buf);
972 return TRUE;