Added stub for CryptSetKeyParams().
[wine.git] / graphics / psdrv / ps.c
blobf7e5aab22ecc5a1199882524a55febce2df012c7
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 pseoclip[] =
165 "eoclip\n";
167 static char psrectclip[] =
168 "%s rectclip\n";
170 static char pshatch[] =
171 "hatch\n";
173 static char psrotate[] = /* ang */
174 "%.1f rotate\n";
176 static char psarrayget[] =
177 "%s %d get\n";
179 static char psarrayput[] =
180 "%s %d %ld put\n";
182 static char psarraydef[] =
183 "/%s %d array def\n";
185 char *PSDRV_ANSIVector[256] = {
186 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x00 */
187 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
188 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x10 */
189 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
190 "space", "exclam", "quotedbl", "numbersign", /* 0x20 */
191 "dollar", "percent", "ampersand", "quotesingle",
192 "parenleft", "parenright", "asterisk", "plus",
193 "comma", "hyphen", "period", "slash",
194 "zero", "one", "two", "three", /* 0x30 */
195 "four", "five", "six", "seven",
196 "eight", "nine", "colon", "semicolon",
197 "less", "equal", "greater", "question",
198 "at", "A", "B", "C", /* 0x40 */
199 "D", "E", "F", "G",
200 "H", "I", "J", "K",
201 "L", "M", "N", "O",
202 "P", "Q", "R", "S", /* 0x50 */
203 "T", "U", "V", "W",
204 "X", "Y", "Z", "bracketleft",
205 "backslash", "bracketright", "asciicircum", "underscore",
206 "grave", "a", "b", "c", /* 0x60 */
207 "d", "e", "f", "g",
208 "h", "i", "j", "k",
209 "l", "m", "n", "o",
210 "p", "q", "r", "s", /* 0x70 */
211 "t", "u", "v", "w",
212 "x", "y", "z", "braceleft",
213 "bar", "braceright", "asciitilde", NULL,
214 NULL, NULL, NULL, NULL, /* 0x80 */
215 NULL, NULL, NULL, NULL,
216 NULL, NULL, NULL, NULL,
217 NULL, NULL, NULL, NULL,
218 NULL, "quoteleft", "quoteright", "quotedblleft", /* 0x90 */
219 "quotedblright","bullet", "endash", "emdash",
220 NULL, NULL, NULL, NULL,
221 NULL, NULL, NULL, NULL,
222 "space", "exclamdown", "cent", "sterling", /* 0xa0 */
223 "currency", "yen", "brokenbar", "section",
224 "dieresis", "copyright", "ordfeminine", "guillemotleft",
225 "logicalnot", "hyphen", "registered", "macron",
226 "degree", "plusminus", "twosuperior", "threesuperior", /* 0xb0 */
227 "acute", "mu", "paragraph", "periodcentered",
228 "cedilla", "onesuperior", "ordmasculine", "guillemotright",
229 "onequarter", "onehalf", "threequarters","questiondown",
230 "Agrave", "Aacute", "Acircumflex", "Atilde", /* 0xc0 */
231 "Adieresis", "Aring", "AE", "Ccedilla",
232 "Egrave", "Eacute", "Ecircumflex", "Edieresis",
233 "Igrave", "Iacute", "Icircumflex", "Idieresis",
234 "Eth", "Ntilde", "Ograve", "Oacute", /* 0xd0 */
235 "Ocircumflex", "Otilde", "Odieresis", "multiply",
236 "Oslash", "Ugrave", "Uacute", "Ucircumflex",
237 "Udieresis", "Yacute", "Thorn", "germandbls",
238 "agrave", "aacute", "acircumflex", "atilde", /* 0xe0 */
239 "adieresis", "aring", "ae", "ccedilla",
240 "egrave", "eacute", "ecircumflex", "edieresis",
241 "igrave", "iacute", "icircumflex", "idieresis",
242 "eth", "ntilde", "ograve", "oacute", /* 0xf0 */
243 "ocircumflex", "otilde", "odieresis", "divide",
244 "oslash", "ugrave", "uacute", "ucircumflex",
245 "udieresis", "yacute", "thorn", "ydieresis"
249 char psreencodefont[] = /* newfontname basefontname*/
250 "/%s /%s reencodefont\n";
253 int PSDRV_WriteSpool(DC *dc, LPSTR lpData, WORD cch)
255 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
257 if(physDev->job.OutOfPage) { /* Will get here after NEWFRAME Escape */
258 if( !PSDRV_StartPage(dc) )
259 return FALSE;
261 return WriteSpool16( physDev->job.hJob, lpData, cch );
265 INT PSDRV_WriteFeature(HANDLE16 hJob, char *feature, char *value,
266 char *invocation)
269 char *buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
270 strlen(feature) + strlen(value));
273 sprintf(buf, psbeginfeature, feature, value);
274 WriteSpool16( hJob, buf, strlen(buf) );
276 WriteSpool16( hJob, invocation, strlen(invocation) );
278 WriteSpool16( hJob, psendfeature, strlen(psendfeature) );
280 HeapFree( PSDRV_Heap, 0, buf );
281 return 1;
286 INT PSDRV_WriteHeader( DC *dc, LPCSTR title )
288 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
289 char *buf, *orient, vectbuf[256];
290 INPUTSLOT *slot;
291 PAGESIZE *page;
292 int urx, ury, i, j;
294 TRACE("'%s'\n", title);
296 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psheader) +
297 strlen(title) + 30 );
298 if(!buf) {
299 WARN("HeapAlloc failed\n");
300 return 0;
303 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
304 /* BBox co-ords are in default user co-ord system so urx < ury even in
305 landscape mode */
306 urx = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
307 ury = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
308 orient = "Landscape";
309 } else {
310 urx = (int) (dc->w.devCaps->horzSize * 72.0 / 25.4);
311 ury = (int) (dc->w.devCaps->vertSize * 72.0 / 25.4);
312 orient = "Portrait";
315 /* FIXME should do something better with BBox */
317 sprintf(buf, psheader, title, 0, 0, urx, ury, orient);
319 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
320 strlen(buf) ) {
321 WARN("WriteSpool error\n");
322 HeapFree( PSDRV_Heap, 0, buf );
323 return 0;
325 HeapFree( PSDRV_Heap, 0, buf );
327 WriteSpool16( physDev->job.hJob, psbeginprolog, strlen(psbeginprolog) );
328 WriteSpool16( physDev->job.hJob, psvectorstart, strlen(psvectorstart) );
330 for(i = 0; i < 256; i += 8) {
331 vectbuf[0] = '\0';
332 for(j = 0; j < 8; j++) {
333 strcat(vectbuf, "/");
334 if(PSDRV_ANSIVector[i+j]) {
335 strcat(vectbuf, PSDRV_ANSIVector[i+j]);
336 strcat(vectbuf, " ");
337 } else {
338 strcat(vectbuf, ".notdef ");
341 strcat(vectbuf, "\n");
342 WriteSpool16( physDev->job.hJob, vectbuf, strlen(vectbuf) );
345 WriteSpool16( physDev->job.hJob, psvectorend, strlen(psvectorend) );
346 WriteSpool16( physDev->job.hJob, psprolog, strlen(psprolog) );
347 WriteSpool16( physDev->job.hJob, psendprolog, strlen(psendprolog) );
350 WriteSpool16( physDev->job.hJob, psbeginsetup, strlen(psbeginsetup) );
352 for(slot = physDev->pi->ppd->InputSlots; slot; slot = slot->next) {
353 if(slot->WinBin == physDev->Devmode->dmPublic.dmDefaultSource) {
354 if(slot->InvocationString) {
355 PSDRV_WriteFeature(physDev->job.hJob, "*InputSlot", slot->Name,
356 slot->InvocationString);
357 break;
362 for(page = physDev->pi->ppd->PageSizes; page; page = page->next) {
363 if(page->WinPage == physDev->Devmode->dmPublic.u1.s1.dmPaperSize) {
364 if(page->InvocationString) {
365 PSDRV_WriteFeature(physDev->job.hJob, "*PageSize", page->Name,
366 page->InvocationString);
367 break;
372 WriteSpool16( physDev->job.hJob, psendsetup, strlen(psendsetup) );
375 return 1;
379 INT PSDRV_WriteFooter( DC *dc )
381 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
382 char *buf;
384 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psfooter) + 100 );
385 if(!buf) {
386 WARN("HeapAlloc failed\n");
387 return 0;
390 sprintf(buf, psfooter, physDev->job.PageNo);
392 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
393 strlen(buf) ) {
394 WARN("WriteSpool error\n");
395 HeapFree( PSDRV_Heap, 0, buf );
396 return 0;
398 HeapFree( PSDRV_Heap, 0, buf );
399 return 1;
404 INT PSDRV_WriteEndPage( DC *dc )
406 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
408 if( WriteSpool16( physDev->job.hJob, psendpage, sizeof(psendpage)-1 ) !=
409 sizeof(psendpage)-1 ) {
410 WARN("WriteSpool error\n");
411 return 0;
413 return 1;
419 INT PSDRV_WriteNewPage( DC *dc )
421 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
422 char *buf;
423 char name[100];
424 signed int xtrans, ytrans, rotation;
426 sprintf(name, "%d", physDev->job.PageNo);
428 buf = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psnewpage) + 200 );
429 if(!buf) {
430 WARN("HeapAlloc failed\n");
431 return 0;
434 if(physDev->Devmode->dmPublic.u1.s1.dmOrientation == DMORIENT_LANDSCAPE) {
435 if(physDev->pi->ppd->LandscapeOrientation == -90) {
436 xtrans = dc->w.devCaps->vertRes;
437 ytrans = dc->w.devCaps->horzRes;
438 rotation = 90;
439 } else {
440 xtrans = ytrans = 0;
441 rotation = -90;
443 } else {
444 xtrans = 0;
445 ytrans = dc->w.devCaps->vertRes;
446 rotation = 0;
449 sprintf(buf, psnewpage, name, physDev->job.PageNo,
450 dc->w.devCaps->logPixelsX, dc->w.devCaps->logPixelsY,
451 xtrans, ytrans, rotation);
453 if( WriteSpool16( physDev->job.hJob, buf, strlen(buf) ) !=
454 strlen(buf) ) {
455 WARN("WriteSpool error\n");
456 HeapFree( PSDRV_Heap, 0, buf );
457 return 0;
459 HeapFree( PSDRV_Heap, 0, buf );
460 return 1;
464 BOOL PSDRV_WriteMoveTo(DC *dc, INT x, INT y)
466 char buf[100];
468 sprintf(buf, psmoveto, x, y);
469 return PSDRV_WriteSpool(dc, buf, strlen(buf));
472 BOOL PSDRV_WriteLineTo(DC *dc, INT x, INT y)
474 char buf[100];
476 sprintf(buf, pslineto, x, y);
477 return PSDRV_WriteSpool(dc, buf, strlen(buf));
481 BOOL PSDRV_WriteStroke(DC *dc)
483 return PSDRV_WriteSpool(dc, psstroke, sizeof(psstroke)-1);
488 BOOL PSDRV_WriteRectangle(DC *dc, INT x, INT y, INT width,
489 INT height)
491 char buf[100];
493 sprintf(buf, psrectangle, x, y, width, height, -width);
494 return PSDRV_WriteSpool(dc, buf, strlen(buf));
497 BOOL PSDRV_WriteRRectangle(DC *dc, INT x, INT y, INT width,
498 INT height)
500 char buf[100];
502 sprintf(buf, psrrectangle, x, y, width, height, -width);
503 return PSDRV_WriteSpool(dc, buf, strlen(buf));
506 BOOL PSDRV_WriteArc(DC *dc, INT x, INT y, INT w, INT h, double ang1,
507 double ang2)
509 char buf[256];
511 /* Make angles -ve and swap order because we're working with an upside
512 down y-axis */
513 sprintf(buf, psarc, x, y, w, h, -ang2, -ang1);
514 return PSDRV_WriteSpool(dc, buf, strlen(buf));
517 static char encodingext[] = "-ANSI";
519 BOOL PSDRV_WriteSetFont(DC *dc, BOOL UseANSI)
521 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
522 char *buf, *newbuf;
524 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
525 sizeof(pssetfont) + strlen(physDev->font.afm->FontName) + 40);
527 if(!buf) {
528 WARN("HeapAlloc failed\n");
529 return FALSE;
532 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
533 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
535 if(!newbuf) {
536 WARN("HeapAlloc failed\n");
537 HeapFree(PSDRV_Heap, 0, buf);
538 return FALSE;
541 if(UseANSI)
542 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
543 else
544 strcpy(newbuf, physDev->font.afm->FontName);
546 sprintf(buf, pssetfont, newbuf,
547 physDev->font.size, -physDev->font.size,
548 -physDev->font.escapement);
550 PSDRV_WriteSpool(dc, buf, strlen(buf));
551 HeapFree(PSDRV_Heap, 0, buf);
552 return TRUE;
555 BOOL PSDRV_WriteSetColor(DC *dc, PSCOLOR *color)
557 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
558 char buf[256];
560 PSDRV_CopyColor(&physDev->inkColor, color);
561 switch(color->type) {
562 case PSCOLOR_RGB:
563 sprintf(buf, pssetrgbcolor, color->value.rgb.r, color->value.rgb.g,
564 color->value.rgb.b);
565 return PSDRV_WriteSpool(dc, buf, strlen(buf));
567 case PSCOLOR_GRAY:
568 sprintf(buf, pssetgray, color->value.gray.i);
569 return PSDRV_WriteSpool(dc, buf, strlen(buf));
571 default:
572 ERR("Unkonwn colour type %d\n", color->type);
573 break;
576 return FALSE;
579 BOOL PSDRV_WriteSetPen(DC *dc)
581 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
582 char buf[256];
584 sprintf(buf, pssetlinewidth, physDev->pen.width);
585 PSDRV_WriteSpool(dc, buf, strlen(buf));
587 if(physDev->pen.dash) {
588 sprintf(buf, pssetdash, physDev->pen.dash, 0);
589 PSDRV_WriteSpool(dc, buf, strlen(buf));
592 return TRUE;
595 BOOL PSDRV_WriteReencodeFont(DC *dc)
597 PSDRV_PDEVICE *physDev = (PSDRV_PDEVICE *)dc->physDev;
598 char *buf, *newbuf;
600 buf = (char *)HeapAlloc( PSDRV_Heap, 0,
601 sizeof(psreencodefont) + 2 * strlen(physDev->font.afm->FontName)
602 + sizeof(encodingext));
604 if(!buf) {
605 WARN("HeapAlloc failed\n");
606 return FALSE;
609 newbuf = (char *)HeapAlloc( PSDRV_Heap, 0,
610 strlen(physDev->font.afm->FontName) + sizeof(encodingext));
612 if(!newbuf) {
613 WARN("HeapAlloc failed\n");
614 HeapFree(PSDRV_Heap, 0, buf);
615 return FALSE;
618 sprintf(newbuf, "%s%s", physDev->font.afm->FontName, encodingext);
619 sprintf(buf, psreencodefont, newbuf, physDev->font.afm->FontName);
621 PSDRV_WriteSpool(dc, buf, strlen(buf));
623 HeapFree(PSDRV_Heap, 0, newbuf);
624 HeapFree(PSDRV_Heap, 0, buf);
625 return TRUE;
628 BOOL PSDRV_WriteShow(DC *dc, char *str, INT count)
630 char *buf, *buf1;
631 INT buflen = count + 10, i, done;
633 buf = (char *)HeapAlloc( PSDRV_Heap, 0, buflen );
635 for(i = done = 0; i < count; i++) {
636 if(!isprint(str[i])) {
637 if(done + 4 >= buflen)
638 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
639 sprintf(buf + done, "\\%03o", (int)(unsigned char)str[i] );
640 done += 4;
641 } else if(str[i] == '\\' || str[i] == '(' || str[i] == ')' ) {
642 if(done + 2 >= buflen)
643 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
644 buf[done++] = '\\';
645 buf[done++] = str[i];
646 } else {
647 if(done + 1 >= buflen)
648 buf = HeapReAlloc( PSDRV_Heap, 0, buf, buflen += 10 );
649 buf[done++] = str[i];
652 buf[done] = '\0';
654 buf1 = (char *)HeapAlloc( PSDRV_Heap, 0, sizeof(psshow) + done);
656 sprintf(buf1, psshow, buf);
658 PSDRV_WriteSpool(dc, buf1, strlen(buf1));
659 HeapFree(PSDRV_Heap, 0, buf);
660 HeapFree(PSDRV_Heap, 0, buf1);
662 return TRUE;
665 BOOL PSDRV_WriteFill(DC *dc)
667 return PSDRV_WriteSpool(dc, psfill, sizeof(psfill)-1);
670 BOOL PSDRV_WriteEOFill(DC *dc)
672 return PSDRV_WriteSpool(dc, pseofill, sizeof(pseofill)-1);
675 BOOL PSDRV_WriteGSave(DC *dc)
677 return PSDRV_WriteSpool(dc, psgsave, sizeof(psgsave)-1);
680 BOOL PSDRV_WriteGRestore(DC *dc)
682 return PSDRV_WriteSpool(dc, psgrestore, sizeof(psgrestore)-1);
685 BOOL PSDRV_WriteNewPath(DC *dc)
687 return PSDRV_WriteSpool(dc, psnewpath, sizeof(psnewpath)-1);
690 BOOL PSDRV_WriteClosePath(DC *dc)
692 return PSDRV_WriteSpool(dc, psclosepath, sizeof(psclosepath)-1);
695 BOOL PSDRV_WriteClip(DC *dc)
697 return PSDRV_WriteSpool(dc, psclip, sizeof(psclip)-1);
700 BOOL PSDRV_WriteEOClip(DC *dc)
702 return PSDRV_WriteSpool(dc, pseoclip, sizeof(pseoclip)-1);
705 BOOL PSDRV_WriteHatch(DC *dc)
707 return PSDRV_WriteSpool(dc, pshatch, sizeof(pshatch)-1);
710 BOOL PSDRV_WriteRotate(DC *dc, float ang)
712 char buf[256];
714 sprintf(buf, psrotate, ang);
715 return PSDRV_WriteSpool(dc, buf, strlen(buf));
718 BOOL PSDRV_WriteIndexColorSpaceBegin(DC *dc, int size)
720 char buf[256];
721 sprintf(buf, "[/Indexed /DeviceRGB %d\n<\n", size);
722 return PSDRV_WriteSpool(dc, buf, strlen(buf));
725 BOOL PSDRV_WriteIndexColorSpaceEnd(DC *dc)
727 char buf[] = ">\n] setcolorspace\n";
728 return PSDRV_WriteSpool(dc, buf, sizeof(buf) - 1);
731 BOOL PSDRV_WriteRGB(DC *dc, COLORREF *map, int number)
733 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1), *ptr;
734 int i;
736 ptr = buf;
737 for(i = 0; i < number; i++) {
738 sprintf(ptr, "%02x%02x%02x%c", (int)GetRValue(map[i]),
739 (int)GetGValue(map[i]), (int)GetBValue(map[i]),
740 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
741 ptr += 7;
743 PSDRV_WriteSpool(dc, buf, number * 7);
744 HeapFree(PSDRV_Heap, 0, buf);
745 return TRUE;
749 BOOL PSDRV_WriteImageDict(DC *dc, WORD depth, INT xDst, INT yDst,
750 INT widthDst, INT heightDst, INT widthSrc,
751 INT heightSrc, char *bits)
753 char start[] = "%d %d translate\n%d %d scale\n<<\n"
754 " /ImageType 1\n /Width %d\n /Height %d\n /BitsPerComponent %d\n"
755 " /ImageMatrix [%d 0 0 %d 0 %d]\n";
757 char decode1[] = " /Decode [0 %d]\n";
758 char decode3[] = " /Decode [0 1 0 1 0 1]\n";
760 char end[] = " /DataSource currentfile /ASCIIHexDecode filter\n>> image\n";
761 char endbits[] = " /DataSource <%s>\n>> image\n";
763 char *buf = HeapAlloc(PSDRV_Heap, 0, 1000);
765 sprintf(buf, start, xDst, yDst, widthDst, heightDst, widthSrc, heightSrc,
766 (depth < 8) ? depth : 8, widthSrc, -heightSrc, heightSrc);
768 PSDRV_WriteSpool(dc, buf, strlen(buf));
770 switch(depth) {
771 case 8:
772 sprintf(buf, decode1, 255);
773 break;
775 case 4:
776 sprintf(buf, decode1, 15);
777 break;
779 case 1:
780 sprintf(buf, decode1, 1);
781 break;
783 default:
784 strcpy(buf, decode3);
785 break;
788 PSDRV_WriteSpool(dc, buf, strlen(buf));
790 if(!bits)
791 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
792 else {
793 sprintf(buf, endbits, bits);
794 PSDRV_WriteSpool(dc, buf, strlen(buf));
797 HeapFree(PSDRV_Heap, 0, buf);
798 return TRUE;
802 BOOL PSDRV_WriteBytes(DC *dc, const BYTE *bytes, int number)
804 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 3 + 1);
805 char *ptr;
806 int i;
808 ptr = buf;
810 for(i = 0; i < number; i++) {
811 sprintf(ptr, "%02x%c", bytes[i],
812 ((i & 0xf) == 0xf) || (i == number - 1) ? '\n' : ' ');
813 ptr += 3;
815 PSDRV_WriteSpool(dc, buf, number * 3);
817 HeapFree(PSDRV_Heap, 0, buf);
818 return TRUE;
821 BOOL PSDRV_WriteDIBits16(DC *dc, const WORD *words, int number)
823 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
824 char *ptr;
825 int i;
827 ptr = buf;
829 for(i = 0; i < number; i++) {
830 int r, g, b;
832 /* We want 0x0 -- 0x1f to map to 0x0 -- 0xff */
834 r = words[i] >> 10 & 0x1f;
835 r = r << 3 | r >> 2;
836 g = words[i] >> 5 & 0x1f;
837 g = g << 3 | g >> 2;
838 b = words[i] & 0x1f;
839 b = b << 3 | b >> 2;
840 sprintf(ptr, "%02x%02x%02x%c", r, g, b,
841 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
842 ptr += 7;
844 PSDRV_WriteSpool(dc, buf, number * 7);
846 HeapFree(PSDRV_Heap, 0, buf);
847 return TRUE;
850 BOOL PSDRV_WriteDIBits24(DC *dc, const BYTE *bits, int number)
852 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
853 char *ptr;
854 int i;
856 ptr = buf;
858 for(i = 0; i < number; i++) {
859 sprintf(ptr, "%02x%02x%02x%c", bits[i * 3 + 2], bits[i * 3 + 1],
860 bits[i * 3],
861 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
862 ptr += 7;
864 PSDRV_WriteSpool(dc, buf, number * 7);
866 HeapFree(PSDRV_Heap, 0, buf);
867 return TRUE;
870 BOOL PSDRV_WriteDIBits32(DC *dc, const BYTE *bits, int number)
872 char *buf = HeapAlloc(PSDRV_Heap, 0, number * 7 + 1);
873 char *ptr;
874 int i;
876 ptr = buf;
878 for(i = 0; i < number; i++) {
879 sprintf(ptr, "%02x%02x%02x%c", bits[i * 4 + 2], bits[i * 4 + 1],
880 bits[i * 4],
881 ((i & 0x7) == 0x7) || (i == number - 1) ? '\n' : ' ');
882 ptr += 7;
884 PSDRV_WriteSpool(dc, buf, number * 7);
886 HeapFree(PSDRV_Heap, 0, buf);
887 return TRUE;
890 BOOL PSDRV_WriteArrayGet(DC *dc, CHAR *pszArrayName, INT nIndex)
892 char buf[100];
894 sprintf(buf, psarrayget, pszArrayName, nIndex);
895 return PSDRV_WriteSpool(dc, buf, strlen(buf));
898 BOOL PSDRV_WriteArrayPut(DC *dc, CHAR *pszArrayName, INT nIndex, LONG lObject)
900 char buf[100];
902 sprintf(buf, psarrayput, pszArrayName, nIndex, lObject);
903 return PSDRV_WriteSpool(dc, buf, strlen(buf));
906 BOOL PSDRV_WriteArrayDef(DC *dc, CHAR *pszArrayName, INT nSize)
908 char buf[100];
910 sprintf(buf, psarraydef, pszArrayName, nSize);
911 return PSDRV_WriteSpool(dc, buf, strlen(buf));
914 BOOL PSDRV_WriteRectClip(DC *dc, CHAR *pszArrayName)
916 char buf[100];
918 sprintf(buf, psrectclip, pszArrayName);
919 return PSDRV_WriteSpool(dc, buf, strlen(buf));
923 BOOL PSDRV_WritePatternDict(DC *dc, BITMAP *bm, BYTE *bits)
925 char start[] = "<<\n /PaintType 1\n /PatternType 1\n /TilingType 1\n "
926 "/BBox [0 0 %d %d]\n /XStep %d\n /YStep %d\n /PaintProc {\n begin\n";
928 char end[] = " end\n }\n>>\n matrix makepattern setpattern\n";
929 char *buf, *ptr;
930 INT w, h, x, y;
931 COLORREF map[2];
933 w = bm->bmWidth & ~0x7;
934 h = bm->bmHeight & ~0x7;
936 buf = HeapAlloc(PSDRV_Heap, 0, sizeof(start) + 100);
937 sprintf(buf, start, w, h, w, h);
938 PSDRV_WriteSpool(dc, buf, strlen(buf));
939 PSDRV_WriteIndexColorSpaceBegin(dc, 1);
940 map[0] = dc->w.textColor;
941 map[1] = dc->w.backgroundColor;
942 PSDRV_WriteRGB(dc, map, 2);
943 PSDRV_WriteIndexColorSpaceEnd(dc);
944 ptr = buf;
945 for(y = h-1; y >= 0; y--) {
946 for(x = 0; x < w/8; x++) {
947 sprintf(ptr, "%02x", *(bits + x/8 + y * bm->bmWidthBytes));
948 ptr += 2;
951 PSDRV_WriteImageDict(dc, 1, 0, 0, 8, 8, 8, 8, buf);
952 PSDRV_WriteSpool(dc, end, sizeof(end) - 1);
953 HeapFree(PSDRV_Heap, 0, buf);
954 return TRUE;