Do not erase local files on uninstall if install dir does not exist.
[wine.git] / graphics / psdrv / ps.c
blob92f5ea7d75e6b4f52d09c310855bf539f06a642c
1 /*
2 * PostScript output functions
4 * Copyright 1998 Huw D M Davies
6 */
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include "psdrv.h"
12 #include "winspool.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(psdrv);
17 static char psheader[] = /* title llx lly urx ury orientation */
18 "%%!PS-Adobe-3.0\n"
19 "%%%%Creator: Wine PostScript Driver\n"
20 "%%%%Title: %s\n"
21 "%%%%BoundingBox: %d %d %d %d\n"
22 "%%%%Pages: (atend)\n"
23 "%%%%Orientation: %s\n"
24 "%%%%EndComments\n";
26 static char psbeginprolog[] =
27 "%%BeginProlog\n";
29 static char psendprolog[] =
30 "%%EndProlog\n";
32 static char psvectorstart[] =
33 "/ANSIEncoding [\n";
35 static char psvectorend[] =
36 "] def\n";
38 static char psprolog[] = /* output ANSIEncoding vector first */
39 "/reencodefont {\n"
40 " findfont\n"
41 " dup length dict begin\n"
42 " {1 index /FID ne {def} {pop pop} ifelse} forall\n"
43 " /Encoding ANSIEncoding def\n"
44 " currentdict\n"
45 " end\n"
46 " definefont pop\n"
47 "} bind def\n"
48 "/tmpmtrx matrix def\n"
49 "/hatch {\n"
50 " pathbbox\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"
53 " gap\n"
54 " r cvi gap idiv gap mul\n"
55 " {t moveto 0 b t sub rlineto}\n"
56 " for\n"
57 "} bind def\n";
59 static char psbeginsetup[] =
60 "%%BeginSetup\n";
62 static char psendsetup[] =
63 "%%EndSetup\n";
65 static char psbeginfeature[] = /* feature, value */
66 "mark {\n"
67 "%%%%BeginFeature: %s %s\n";
69 static char psendfeature[] =
70 "\n%%EndFeature\n"
71 "} stopped cleartomark\n";
73 static char psnewpage[] = /* name, number, xres, yres, xtrans, ytrans, rot */
74 "%%%%Page: %s %d\n"
75 "%%%%BeginPageSetup\n"
76 "/pgsave save def\n"
77 "72 %d div 72 %d div scale\n"
78 "%d %d translate\n"
79 "1 -1 scale\n"
80 "%d rotate\n"
81 "%%%%EndPageSetup\n";
83 static char psendpage[] =
84 "pgsave restore\n"
85 "showpage\n";
87 static char psfooter[] = /* pages */
88 "%%%%Trailer\n"
89 "%%%%Pages: %d\n"
90 "%%%%EOF\n";
92 static char psmoveto[] = /* x, y */
93 "%d %d moveto\n";
95 static char pslineto[] = /* x, y */
96 "%d %d lineto\n";
98 static char psstroke[] =
99 "stroke\n";
101 static char psrectangle[] = /* x, y, width, height, -width */
102 "%d %d moveto\n"
103 "%d 0 rlineto\n"
104 "0 %d rlineto\n"
105 "%d 0 rlineto\n"
106 "closepath\n";
108 static char psrrectangle[] = /* x, y, width, height, -width */
109 "%d %d rmoveto\n"
110 "%d 0 rlineto\n"
111 "0 %d rlineto\n"
112 "%d 0 rlineto\n"
113 "closepath\n";
115 static char psshow[] = /* string */
116 "(%s) show\n";
118 static char pssetfont[] = /* fontname, xscale, yscale, ascent, escapement */
119 "/%s findfont\n"
120 "[%d 0 0 %d 0 0]\n"
121 "%d 10 div matrix rotate\n"
122 "matrix concatmatrix\n"
123 "makefont setfont\n";
125 static char pssetlinewidth[] = /* width */
126 "%d setlinewidth\n";
128 static char pssetdash[] = /* dash, offset */
129 "[%s] %d setdash\n";
131 static char pssetgray[] = /* gray */
132 "%.2f setgray\n";
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"
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 char psgsave[] =
145 "gsave\n";
147 static char psgrestore[] =
148 "grestore\n";
150 static char psfill[] =
151 "fill\n";
153 static char pseofill[] =
154 "eofill\n";
156 static char psnewpath[] =
157 "newpath\n";
159 static char psclosepath[] =
160 "closepath\n";
162 static char psclip[] =
163 "clip\n";
165 static char psinitclip[] =
166 "initclip\n";
168 static char pseoclip[] =
169 "eoclip\n";
171 static char psrectclip[] =
172 "%d %d %d %d rectclip\n";
174 static char psrectclip2[] =
175 "%s rectclip\n";
177 static char pshatch[] =
178 "hatch\n";
180 static char psrotate[] = /* ang */
181 "%.1f rotate\n";
183 static char psarrayget[] =
184 "%s %d get\n";
186 static char psarrayput[] =
187 "%s %d %ld put\n";
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 */
206 "D", "E", "F", "G",
207 "H", "I", "J", "K",
208 "L", "M", "N", "O",
209 "P", "Q", "R", "S", /* 0x50 */
210 "T", "U", "V", "W",
211 "X", "Y", "Z", "bracketleft",
212 "backslash", "bracketright", "asciicircum", "underscore",
213 "grave", "a", "b", "c", /* 0x60 */
214 "d", "e", "f", "g",
215 "h", "i", "j", "k",
216 "l", "m", "n", "o",
217 "p", "q", "r", "s", /* 0x70 */
218 "t", "u", "v", "w",
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) )
266 return FALSE;
268 return WriteSpool16( physDev->job.hJob, lpData, cch );
272 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
273 char *invocation)
276 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
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 );
288 return 1;
293 INT PSDRV_WriteHeader( DC *dc, LPCSTR title )
295 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
296 char *buf, *orient, vectbuf[256];
297 INPUTSLOT *slot;
298 PAGESIZE *page;
299 int urx, ury, i, j;
301 TRACE("'%s'\n", title);
303 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
304 strlen(title) + 30 );
305 if(!buf) {
306 WARN("HeapAlloc failed\n");
307 return 0;
310 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
311 /* BBox co-ords are in default user co-ord system so urx < ury even in
312 landscape mode */
313 urx = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
314 ury = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
315 orient = "Landscape";
316 } else {
317 urx = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
318 ury = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
319 orient = "Portrait";
322 /* FIXME should do something better with BBox */
324 sprintf(buf, psheader, title, 0, 0, urx, ury, orient);
326 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
327 strlen(buf) ) {
328 WARN("WriteSpool error\n");
329 HeapFree( PSDRV_Heap, 0, buf );
330 return 0;
332 HeapFree( PSDRV_Heap, 0, buf );
334 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
335 WriteSpool16( physDev->job.hJob, psvectorstart, strlen(psvectorstart) );
337 for(i = 0; i < 256; i += 8) {
338 vectbuf[0] = '\0';
339 for(j = 0; j < 8; j++) {
340 strcat(vectbuf, "/");
341 if(PSDRV_ANSIVector[i+j]) {
342 strcat(vectbuf, PSDRV_ANSIVector[i+j]);
343 strcat(vectbuf, " ");
344 } else {
345 strcat(vectbuf, ".notdef ");
348 strcat(vectbuf, "\n");
349 WriteSpool16( physDev->job.hJob, vectbuf, strlen(vectbuf) );
352 WriteSpool16( physDev->job.hJob, psvectorend, strlen(psvectorend) );
353 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
354 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
357 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
359 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
360 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
361 if(slot->InvocationString) {
362 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
363 slot->InvocationString);
364 break;
369 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
370 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
371 if(page->InvocationString) {
372 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
373 page->InvocationString);
374 break;
379 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
382 return 1;
386 INT PSDRV_WriteFooter( DC *dc )
388 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
389 char *buf;
391 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
392 if(!buf) {
393 WARN("HeapAlloc failed\n");
394 return 0;
397 sprintf(buf, psfooter, physDev->job.PageNo);
399 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
400 strlen(buf) ) {
401 WARN("WriteSpool error\n");
402 HeapFree( PSDRV_Heap, 0, buf );
403 return 0;
405 HeapFree( PSDRV_Heap, 0, buf );
406 return 1;
411 INT PSDRV_WriteEndPage( DC *dc )
413 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
415 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
416 sizeof(psendpage)-1 ) {
417 WARN("WriteSpool error\n");
418 return 0;
420 return 1;
426 INT PSDRV_WriteNewPage( DC *dc )
428 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
429 char *buf;
430 char name[100];
431 signed int xtrans, ytrans, rotation;
433 sprintf(name, "%d", physDev->job.PageNo);
435 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
436 if(!buf) {
437 WARN("HeapAlloc failed\n");
438 return 0;
441 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
442 if(physDev->pi->ppd->LandscapeOrientation == -90) {
443 xtrans = dc->w.devCaps->vertRes;
444 ytrans = dc->w.devCaps->horzRes;
445 rotation = 90;
446 } else {
447 xtrans = ytrans = 0;
448 rotation = -90;
450 } else {
451 xtrans = 0;
452 ytrans = dc->w.devCaps->vertRes;
453 rotation = 0;
456 sprintf(buf, psnewpage, name, physDev->job.PageNo,
457 dc->w.devCaps->logPixelsX, dc->w.devCaps->logPixelsY,
458 xtrans, ytrans, rotation);
460 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
461 strlen(buf) ) {
462 WARN("WriteSpool error\n");
463 HeapFree( PSDRV_Heap, 0, buf );
464 return 0;
466 HeapFree( PSDRV_Heap, 0, buf );
467 return 1;
471 BOOL PSDRV_WriteMoveTo(DC *dc, INT x, INT y)
473 char buf[100];
475 sprintf(buf, psmoveto, x, y);
476 return PSDRV_WriteSpool(dc, buf, strlen(buf));
479 BOOL PSDRV_WriteLineTo(DC *dc, INT x, INT y)
481 char buf[100];
483 sprintf(buf, pslineto, x, y);
484 return PSDRV_WriteSpool(dc, buf, strlen(buf));
488 BOOL PSDRV_WriteStroke(DC *dc)
490 return PSDRV_WriteSpool(dc, psstroke, sizeof(psstroke)-1);
495 BOOL PSDRV_WriteRectangle(DC *dc, INT x, INT y, INT width,
496 INT height)
498 char buf[100];
500 sprintf(buf, psrectangle, x, y, width, height, -width);
501 return PSDRV_WriteSpool(dc, buf, strlen(buf));
504 BOOL PSDRV_WriteRRectangle(DC *dc, INT x, INT y, INT width,
505 INT height)
507 char buf[100];
509 sprintf(buf, psrrectangle, x, y, width, height, -width);
510 return PSDRV_WriteSpool(dc, buf, strlen(buf));
513 BOOL PSDRV_WriteArc(DC *dc, INT x, INT y, INT w, INT h, double ang1,
514 double ang2)
516 char buf[256];
518 /* Make angles -ve and swap order because we're working with an upside
519 down y-axis */
520 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
521 return PSDRV_WriteSpool(dc, buf, strlen(buf));
524 static char encodingext[] = "-ANSI";
526 BOOL PSDRV_WriteSetFont(DC *dc, BOOL UseANSI)
528 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
529 char *buf, *newbuf;
531 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
532 sizeof(pssetfont) + strlen(physDev->font.afm->FontName) + 40);
534 if(!buf) {
535 WARN("HeapAlloc failed\n");
536 return FALSE;
539 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
540 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
542 if(!newbuf) {
543 WARN("HeapAlloc failed\n");
544 HeapFree(PSDRV_Heap, 0, buf);
545 return FALSE;
548 if(UseANSI)
549 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
550 else
551 strcpy(newbuf, physDev->font.afm->FontName);
553 sprintf(buf, pssetfont, newbuf,
554 physDev->font.size, -physDev->font.size,
555 -physDev->font.escapement);
557 PSDRV_WriteSpool(dc, buf, strlen(buf));
558 HeapFree(PSDRV_Heap, 0, buf);
559 return TRUE;
562 BOOL PSDRV_WriteSetColor(DC *dc, PSCOLOR *color)
564 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
565 char buf[256];
567 PSDRV_CopyColor(&physDev->inkColor, color);
568 switch(color->type) {
569 case PSCOLOR_RGB:
570 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
571 color->value.rgb.b);
572 return PSDRV_WriteSpool(dc, buf, strlen(buf));
574 case PSCOLOR_GRAY:
575 sprintf(buf, pssetgray, color->value.gray.i);
576 return PSDRV_WriteSpool(dc, buf, strlen(buf));
578 default:
579 ERR("Unkonwn colour type %d\n", color->type);
580 break;
583 return FALSE;
586 BOOL PSDRV_WriteSetPen(DC *dc)
588 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
589 char buf[256];
591 sprintf(buf, pssetlinewidth, physDev->pen.width);
592 PSDRV_WriteSpool(dc, buf, strlen(buf));
594 if(physDev->pen.dash) {
595 sprintf(buf, pssetdash, physDev->pen.dash, 0);
596 PSDRV_WriteSpool(dc, buf, strlen(buf));
599 return TRUE;
602 BOOL PSDRV_WriteReencodeFont(DC *dc)
604 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
605 char *buf, *newbuf;
607 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
608 sizeof(psreencodefont) + 2 * strlen(physDev->font.afm->FontName)
609 + sizeof(encodingext));
611 if(!buf) {
612 WARN("HeapAlloc failed\n");
613 return FALSE;
616 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
617 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
619 if(!newbuf) {
620 WARN("HeapAlloc failed\n");
621 HeapFree(PSDRV_Heap, 0, buf);
622 return FALSE;
625 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
626 sprintf(buf, psreencodefont, newbuf, physDev->font.afm->FontName);
628 PSDRV_WriteSpool(dc, buf, strlen(buf));
630 HeapFree(PSDRV_Heap, 0, newbuf);
631 HeapFree(PSDRV_Heap, 0, buf);
632 return TRUE;
635 BOOL PSDRV_WriteShow(DC *dc, LPCWSTR str, INT count)
637 char *buf, *buf1;
638 INT buflen = count + 10, i, done;
640 buf = (char *)HeapAlloc( PSDRV_Heap, 0, buflen );
642 for(i = done = 0; i < count; i++) {
643 char c = PSDRV_UnicodeToANSI(str[i]);
644 if(!isprint(c)) {
645 if(done + 4 >= buflen)
646 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
647 sprintf(buf + done, "\\%03o", (int)(unsigned char)c);
648 done += 4;
649 } else if(c == '\\' || c == '(' || c == ')' ) {
650 if(done + 2 >= buflen)
651 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
652 buf[done++] = '\\';
653 buf[done++] = c;
654 } else {
655 if(done + 1 >= buflen)
656 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
657 buf[done++] = c;
660 buf[done] = '\0';
662 buf1 = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psshow) + done);
664 sprintf(buf1, psshow, buf);
666 PSDRV_WriteSpool(dc, buf1, strlen(buf1));
667 HeapFree(PSDRV_Heap, 0, buf);
668 HeapFree(PSDRV_Heap, 0, buf1);
670 return TRUE;
673 BOOL PSDRV_WriteFill(DC *dc)
675 return PSDRV_WriteSpool(dc, psfill, sizeof(psfill)-1);
678 BOOL PSDRV_WriteEOFill(DC *dc)
680 return PSDRV_WriteSpool(dc, pseofill, sizeof(pseofill)-1);
683 BOOL PSDRV_WriteGSave(DC *dc)
685 return PSDRV_WriteSpool(dc, psgsave, sizeof(psgsave)-1);
688 BOOL PSDRV_WriteGRestore(DC *dc)
690 return PSDRV_WriteSpool(dc, psgrestore, sizeof(psgrestore)-1);
693 BOOL PSDRV_WriteNewPath(DC *dc)
695 return PSDRV_WriteSpool(dc, psnewpath, sizeof(psnewpath)-1);
698 BOOL PSDRV_WriteClosePath(DC *dc)
700 return PSDRV_WriteSpool(dc, psclosepath, sizeof(psclosepath)-1);
703 BOOL PSDRV_WriteClip(DC *dc)
705 return PSDRV_WriteSpool(dc, psclip, sizeof(psclip)-1);
708 BOOL PSDRV_WriteEOClip(DC *dc)
710 return PSDRV_WriteSpool(dc, pseoclip, sizeof(pseoclip)-1);
713 BOOL PSDRV_WriteInitClip(DC *dc)
715 return PSDRV_WriteSpool(dc, psinitclip, sizeof(psinitclip)-1);
718 BOOL PSDRV_WriteHatch(DC *dc)
720 return PSDRV_WriteSpool(dc, pshatch, sizeof(pshatch)-1);
723 BOOL PSDRV_WriteRotate(DC *dc, float ang)
725 char buf[256];
727 sprintf(buf, psrotate, ang);
728 return PSDRV_WriteSpool(dc, buf, strlen(buf));
731 BOOL PSDRV_WriteIndexColorSpaceBegin(DC *dc, int size)
733 char buf[256];
734 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
735 return PSDRV_WriteSpool(dc, buf, strlen(buf));
738 BOOL PSDRV_WriteIndexColorSpaceEnd(DC *dc)
740 char buf[] = ">\n] setcolorspace\n";
741 return PSDRV_WriteSpool(dc, buf, sizeof(buf) - 1);
744 BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number)
746 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
747 int i;
749 ptr = buf;
750 for(i = 0; i < number; i++) {
751 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
752 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
753 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
754 ptr += 7;
756 PSDRV_WriteSpool(dc, buf, number * 7);
757 HeapFree(PSDRV_Heap, 0, buf);
758 return TRUE;
762 BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst,
763 INT widthDst, INT heightDst, INT widthSrc,
764 INT heightSrc, char *bits)
766 char start[] = "%d %d translate\n%d %d scale\n<<\n"
767 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
768 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
770 char decode1[] = " /Decode [0 %d]\n";
771 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
773 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
774 char endbits[] = " /DataSource <%s>\n>> image\n";
776 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
778 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
779 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
781 PSDRV_WriteSpool(dc, buf, strlen(buf));
783 switch(depth) {
784 case 8:
785 sprintf(buf, decode1, 255);
786 break;
788 case 4:
789 sprintf(buf, decode1, 15);
790 break;
792 case 1:
793 sprintf(buf, decode1, 1);
794 break;
796 default:
797 strcpy(buf, decode3);
798 break;
801 PSDRV_WriteSpool(dc, buf, strlen(buf));
803 if(!bits)
804 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
805 else {
806 sprintf(buf, endbits, bits);
807 PSDRV_WriteSpool(dc, buf, strlen(buf));
810 HeapFree(PSDRV_Heap, 0, buf);
811 return TRUE;
815 BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number)
817 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
818 char *ptr;
819 int i;
821 ptr = buf;
823 for(i = 0; i < number; i++) {
824 sprintf(ptr, "%02x%c", bytes[i],
825 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
826 ptr += 3;
828 PSDRV_WriteSpool(dc, buf, number * 3);
830 HeapFree(PSDRV_Heap, 0, buf);
831 return TRUE;
834 BOOL PSDRV_WriteDIBits16(DC *dc, const WORD *words, int number)
836 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
837 char *ptr;
838 int i;
840 ptr = buf;
842 for(i = 0; i < number; i++) {
843 int r, g, b;
845 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
847 r = words[i] >> 10 & 0x1f;
848 r = r << 3 | r >> 2;
849 g = words[i] >> 5 & 0x1f;
850 g = g << 3 | g >> 2;
851 b = words[i] & 0x1f;
852 b = b << 3 | b >> 2;
853 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
854 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
855 ptr += 7;
857 PSDRV_WriteSpool(dc, buf, number * 7);
859 HeapFree(PSDRV_Heap, 0, buf);
860 return TRUE;
863 BOOL PSDRV_WriteDIBits24(DC *dc, const BYTE *bits, int number)
865 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
866 char *ptr;
867 int i;
869 ptr = buf;
871 for(i = 0; i < number; i++) {
872 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
873 bits[i * 3],
874 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
875 ptr += 7;
877 PSDRV_WriteSpool(dc, buf, number * 7);
879 HeapFree(PSDRV_Heap, 0, buf);
880 return TRUE;
883 BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number)
885 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
886 char *ptr;
887 int i;
889 ptr = buf;
891 for(i = 0; i < number; i++) {
892 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
893 bits[i * 4],
894 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
895 ptr += 7;
897 PSDRV_WriteSpool(dc, buf, number * 7);
899 HeapFree(PSDRV_Heap, 0, buf);
900 return TRUE;
903 BOOL PSDRV_WriteArrayGet(DC *dc, CHAR *pszArrayName, INT nIndex)
905 char buf[100];
907 sprintf(buf, psarrayget, pszArrayName, nIndex);
908 return PSDRV_WriteSpool(dc, buf, strlen(buf));
911 BOOL PSDRV_WriteArrayPut(DC *dc, CHAR *pszArrayName, INT nIndex, LONG lObject)
913 char buf[100];
915 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
916 return PSDRV_WriteSpool(dc, buf, strlen(buf));
919 BOOL PSDRV_WriteArrayDef(DC *dc, CHAR *pszArrayName, INT nSize)
921 char buf[100];
923 sprintf(buf, psarraydef, pszArrayName, nSize);
924 return PSDRV_WriteSpool(dc, buf, strlen(buf));
927 BOOL PSDRV_WriteRectClip(DC *dc, INT x, INT y, INT w, INT h)
929 char buf[100];
931 sprintf(buf, psrectclip, x, y, w, h);
932 return PSDRV_WriteSpool(dc, buf, strlen(buf));
935 BOOL PSDRV_WriteRectClip2(DC *dc, CHAR *pszArrayName)
937 char buf[100];
939 sprintf(buf, psrectclip2, pszArrayName);
940 return PSDRV_WriteSpool(dc, buf, strlen(buf));
943 BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits)
945 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
946 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
948 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
949 char *buf, *ptr;
950 INT w, h, x, y;
951 COLORREF map[2];
953 w = bm->bmWidth & ~0x7;
954 h = bm->bmHeight & ~0x7;
956 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
957 sprintf(buf, start, w, h, w, h);
958 PSDRV_WriteSpool(dc, buf, strlen(buf));
959 PSDRV_WriteIndexColorSpaceBegin(dc, 1);
960 map[0] = dc->w.textColor;
961 map[1] = dc->w.backgroundColor;
962 PSDRV_WriteRGB(dc, map, 2);
963 PSDRV_WriteIndexColorSpaceEnd(dc);
964 ptr = buf;
965 for(y = h-1; y >= 0; y--) {
966 for(x = 0; x < w/8; x++) {
967 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
968 ptr += 2;
971 PSDRV_WriteImageDict(dc, 1, 0, 0, 8, 8, 8, 8, buf);
972 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
973 HeapFree(PSDRV_Heap, 0, buf);
974 return TRUE;