Release 20030408.
[wine/gsoc-2012-control.git] / dlls / wineps / ppd.c
blob64ec6aee8e729538ba54daff95c240439d66a52e
1 /* PostScript Printer Description (PPD) file parser
3 * See http://www.adobe.com/supportservice/devrelations/PDFS/TN/5003.PPD_Spec_v4.3.pdf
5 * Copyright 1998 Huw D M Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <string.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include "windef.h" /* HEAP_ZERO_MEMORY */
26 #include "wine/debug.h"
27 #include "psdrv.h"
28 #include "winspool.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
32 typedef struct {
33 char *key;
34 char *option;
35 char *opttrans;
36 char *value;
37 char *valtrans;
38 } PPDTuple;
41 /* map of page names in ppd file to Windows paper constants */
43 static struct {
44 char *PSName;
45 WORD WinPage;
46 } PageTrans[] = {
47 {"10x11", DMPAPER_10X11},
48 {"10x14", DMPAPER_10X14},
49 {"11x17", DMPAPER_11X17}, /* not in Adobe PPD file spec */
50 {"12x11", DMPAPER_12X11},
51 {"15x11", DMPAPER_15X11},
52 {"9x11", DMPAPER_9X11},
53 {"A2", DMPAPER_A2},
54 {"A3", DMPAPER_A3},
55 {"A3.Transverse", DMPAPER_A3_TRANSVERSE},
56 {"A3Extra", DMPAPER_A3_EXTRA},
57 {"A3Extra.Transverse", DMPAPER_A3_EXTRA_TRANSVERSE},
58 {"A3Rotated", DMPAPER_A3_ROTATED},
59 {"A4", DMPAPER_A4},
60 {"A4.Transverse", DMPAPER_A4_TRANSVERSE},
61 {"A4Extra", DMPAPER_A4_EXTRA},
62 {"A4Plus", DMPAPER_A4_PLUS},
63 {"A4Rotated", DMPAPER_A4_ROTATED},
64 {"A4Small", DMPAPER_A4SMALL},
65 {"A5", DMPAPER_A5},
66 {"A5.Transverse", DMPAPER_A5_TRANSVERSE},
67 {"A5Extra", DMPAPER_A5_EXTRA},
68 {"A5Rotated", DMPAPER_A5_ROTATED},
69 {"A6", DMPAPER_A6},
70 {"A6Rotated", DMPAPER_A6_ROTATED},
71 {"ARCHC", DMPAPER_CSHEET},
72 {"ARCHD", DMPAPER_DSHEET},
73 {"ARCHE", DMPAPER_ESHEET},
74 {"B4", DMPAPER_B4},
75 {"B4Rotated", DMPAPER_B4_JIS_ROTATED},
76 {"B5", DMPAPER_B5},
77 {"B5.Transverse", DMPAPER_B5_TRANSVERSE},
78 {"B5Rotated", DMPAPER_B5_JIS_ROTATED},
79 {"B6", DMPAPER_B6_JIS},
80 {"B6Rotated", DMPAPER_B6_JIS_ROTATED},
81 {"C4", DMPAPER_ENV_C4}, /* use EnvC4 */
82 {"C5", DMPAPER_ENV_C5}, /* use EnvC5 */
83 {"C6", DMPAPER_ENV_C6}, /* use EnvC6 */
84 {"Comm10", DMPAPER_ENV_10}, /* use Env10 */
85 {"DL", DMPAPER_ENV_DL}, /* use EnvDL */
86 {"DoublePostcard", DMPAPER_DBL_JAPANESE_POSTCARD},
87 {"DoublePostcardRotated", DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED},
88 {"Env10", DMPAPER_ENV_10},
89 {"Env11", DMPAPER_ENV_11},
90 {"Env12", DMPAPER_ENV_12},
91 {"Env14", DMPAPER_ENV_14},
92 {"Env9", DMPAPER_ENV_9},
93 {"EnvC3", DMPAPER_ENV_C3},
94 {"EnvC4", DMPAPER_ENV_C4},
95 {"EnvC5", DMPAPER_ENV_C5},
96 {"EnvC6", DMPAPER_ENV_C6},
97 {"EnvC65", DMPAPER_ENV_C65},
98 {"EnvChou3", DMPAPER_JENV_CHOU3},
99 {"EnvChou3Rotated", DMPAPER_JENV_CHOU3_ROTATED},
100 {"EnvChou4", DMPAPER_JENV_CHOU4},
101 {"EnvChou4Rotated", DMPAPER_JENV_CHOU4_ROTATED},
102 {"EnvDL", DMPAPER_ENV_DL},
103 {"EnvISOB4", DMPAPER_ENV_B4},
104 {"EnvISOB5", DMPAPER_ENV_B5},
105 {"EnvISOB6", DMPAPER_ENV_B6},
106 {"EnvInvite", DMPAPER_ENV_INVITE},
107 {"EnvItalian", DMPAPER_ENV_ITALY},
108 {"EnvKaku2", DMPAPER_JENV_KAKU2},
109 {"EnvKaku2Rotated", DMPAPER_JENV_KAKU2_ROTATED},
110 {"EnvKaku3", DMPAPER_JENV_KAKU3},
111 {"EnvKaku3Rotated", DMPAPER_JENV_KAKU3_ROTATED},
112 {"EnvMonarch", DMPAPER_ENV_MONARCH},
113 {"EnvPRC1", DMPAPER_PENV_1},
114 {"EnvPRC10", DMPAPER_PENV_10},
115 {"EnvPRC10Rotated", DMPAPER_PENV_10_ROTATED},
116 {"EnvPRC1Rotated", DMPAPER_PENV_1_ROTATED},
117 {"EnvPRC2", DMPAPER_PENV_2},
118 {"EnvPRC2Rotated", DMPAPER_PENV_2_ROTATED},
119 {"EnvPRC3", DMPAPER_PENV_3},
120 {"EnvPRC3Rotated", DMPAPER_PENV_3_ROTATED},
121 {"EnvPRC4", DMPAPER_PENV_4},
122 {"EnvPRC4Rotated", DMPAPER_PENV_4_ROTATED},
123 {"EnvPRC5", DMPAPER_PENV_5},
124 {"EnvPRC5Rotated", DMPAPER_PENV_5_ROTATED},
125 {"EnvPRC6", DMPAPER_PENV_6},
126 {"EnvPRC6Rotated", DMPAPER_PENV_6_ROTATED},
127 {"EnvPRC7", DMPAPER_PENV_7},
128 {"EnvPRC7Rotated", DMPAPER_PENV_7_ROTATED},
129 {"EnvPRC8", DMPAPER_PENV_8},
130 {"EnvPRC8Rotated", DMPAPER_PENV_8_ROTATED},
131 {"EnvPRC9", DMPAPER_PENV_9},
132 {"EnvPRC9Rotated", DMPAPER_PENV_9_ROTATED},
133 {"EnvPersonal", DMPAPER_ENV_PERSONAL},
134 {"EnvYou4", DMPAPER_JENV_YOU4},
135 {"EnvYou4Rotated", DMPAPER_JENV_YOU4_ROTATED},
136 {"Executive", DMPAPER_EXECUTIVE},
137 {"FanFoldGerman", DMPAPER_FANFOLD_STD_GERMAN},
138 {"FanFoldGermanLegal", DMPAPER_FANFOLD_LGL_GERMAN},
139 {"FanFoldUS", DMPAPER_FANFOLD_US},
140 {"Folio", DMPAPER_FOLIO},
141 {"ISOB4", DMPAPER_ISO_B4},
142 {"ISOB5Extra", DMPAPER_B5_EXTRA},
143 {"Ledger", DMPAPER_LEDGER},
144 {"Legal", DMPAPER_LEGAL},
145 {"LegalExtra", DMPAPER_LEGAL_EXTRA},
146 {"Letter", DMPAPER_LETTER},
147 {"Letter.Transverse", DMPAPER_LETTER_TRANSVERSE},
148 {"LetterExtra", DMPAPER_LETTER_EXTRA},
149 {"LetterExtra.Transverse", DMPAPER_LETTER_EXTRA_TRANSVERSE},
150 {"LetterPlus", DMPAPER_LETTER_PLUS},
151 {"LetterRotated", DMPAPER_LETTER_ROTATED},
152 {"LetterSmall", DMPAPER_LETTERSMALL},
153 {"Monarch", DMPAPER_ENV_MONARCH}, /* use EnvMonarch */
154 {"Note", DMPAPER_NOTE},
155 {"PRC16K", DMPAPER_P16K},
156 {"PRC16KRotated", DMPAPER_P16K_ROTATED},
157 {"PRC32K", DMPAPER_P32K},
158 {"PRC32KBig", DMPAPER_P32KBIG},
159 {"PRC32KBigRotated", DMPAPER_P32KBIG_ROTATED},
160 {"PRC32KRotated", DMPAPER_P32K_ROTATED},
161 {"Postcard", DMPAPER_JAPANESE_POSTCARD},
162 {"PostcardRotated", DMPAPER_JAPANESE_POSTCARD_ROTATED},
163 {"Quarto", DMPAPER_QUARTO},
164 {"Statement", DMPAPER_STATEMENT},
165 {"SuperA", DMPAPER_A_PLUS},
166 {"SuperB", DMPAPER_B_PLUS},
167 {"Tabloid", DMPAPER_TABLOID},
168 {"TabloidExtra", DMPAPER_TABLOID_EXTRA},
169 {NULL, 0}
172 static WORD UserPageType = DMPAPER_USER;
173 static WORD UserBinType = DMBIN_USER;
175 /***********************************************************************
177 * PSDRV_PPDDecodeHex
179 * Copies str into a newly allocated string from the process heap subsituting
180 * hex strings enclosed in '<' and '>' for their byte codes.
183 static char *PSDRV_PPDDecodeHex(char *str)
185 char *buf, *in, *out;
186 BOOL inhex = FALSE;
188 buf = HeapAlloc(PSDRV_Heap, 0, strlen(str) + 1);
189 if(!buf)
190 return NULL;
192 for(in = str, out = buf; *in; in++) {
193 if(!inhex) {
194 if(*in != '<')
195 *out++ = *in;
196 else
197 inhex = TRUE;
198 } else {
199 if(*in == '>') {
200 inhex = FALSE;
201 continue;
203 else if(isspace(*in))
204 continue;
205 else {
206 int i;
207 if(!isxdigit(*in) || !isxdigit(*(in + 1))) {
208 ERR("Invalid hex char in hex string\n");
209 HeapFree(PSDRV_Heap, 0, buf);
210 return NULL;
212 *out = 0;
213 for(i = 0; i < 2; i++) {
214 if(isdigit(*(in + i)))
215 *out |= (*(in + i) - '0') << ((1-i) * 4);
216 else
217 *out |= (toupper(*(in + i)) - 'A' + 10) << ((1-i) * 4);
219 out++;
220 in++;
224 *out = '\0';
225 return buf;
229 /***********************************************************************
231 * PSDRV_PPDGetTransValue
234 static BOOL PSDRV_PPDGetTransValue(char *start, PPDTuple *tuple)
236 char *buf, *end;
238 end = strpbrk(start, "\r\n");
239 if(end == start) return FALSE;
240 if(!end) end = start + strlen(start);
241 buf = HeapAlloc( PSDRV_Heap, 0, end - start + 1 );
242 memcpy(buf, start, end - start);
243 *(buf + (end - start)) = '\0';
244 tuple->valtrans = PSDRV_PPDDecodeHex(buf);
245 HeapFree( PSDRV_Heap, 0, buf );
246 return TRUE;
250 /***********************************************************************
252 * PSDRV_PPDGetInvocationValue
254 * Passed string that should be surrounded by `"'s, return string alloced
255 * from process heap.
257 static BOOL PSDRV_PPDGetInvocationValue(FILE *fp, char *pos, PPDTuple *tuple)
259 char *start, *end, *buf;
260 char line[257];
261 int len;
263 start = pos + 1;
264 buf = HeapAlloc( PSDRV_Heap, 0, strlen(start) + 1 );
265 len = 0;
266 do {
267 end = strchr(start, '"');
268 if(end) {
269 buf = HeapReAlloc( PSDRV_Heap, 0, buf,
270 len + (end - start) + 1 );
271 memcpy(buf + len, start, end - start);
272 *(buf + len + (end - start)) = '\0';
273 tuple->value = buf;
274 start = strchr(end, '/');
275 if(start)
276 return PSDRV_PPDGetTransValue(start + 1, tuple);
277 return TRUE;
278 } else {
279 int sl = strlen(start);
280 buf = HeapReAlloc( PSDRV_Heap, 0, buf, len + sl + 1 );
281 strcpy(buf + len, start);
282 len += sl;
284 } while( fgets((start = line), sizeof(line), fp) );
286 tuple->value = NULL;
287 HeapFree( PSDRV_Heap, 0, buf );
288 return FALSE;
292 /***********************************************************************
294 * PSDRV_PPDGetQuotedValue
296 * Passed string that should be surrounded by `"'s. Expand <xx> as hex
297 * return string alloced from process heap.
299 static BOOL PSDRV_PPDGetQuotedValue(FILE *fp, char *pos, PPDTuple *tuple)
301 char *buf;
303 if(!PSDRV_PPDGetInvocationValue(fp, pos, tuple))
304 return FALSE;
305 buf = PSDRV_PPDDecodeHex(tuple->value);
306 HeapFree(PSDRV_Heap, 0, tuple->value);
307 tuple->value = buf;
308 return TRUE;
312 /***********************************************************************
314 * PSDRV_PPDGetStringValue
316 * Just strip leading white space.
318 static BOOL PSDRV_PPDGetStringValue(char *str, PPDTuple *tuple)
320 char *start = str, *end;
322 while(*start != '\0' && isspace(*start))
323 start++;
325 end = strpbrk(start, "/\r\n");
326 if(!end) end = start + strlen(start);
327 tuple->value = HeapAlloc( PSDRV_Heap, 0, (end - start) + 1 );
328 memcpy(tuple->value, start, end - start);
329 *(tuple->value + (end - start)) = '\0';
330 if(*end == '/')
331 PSDRV_PPDGetTransValue(end + 1, tuple);
332 return TRUE;
336 /***********************************************************************
338 * PSDRV_PPDSymbolValue
340 * Not implemented yet.
342 static BOOL PSDRV_PPDGetSymbolValue(char *pos, PPDTuple *tuple)
344 FIXME("Stub\n");
345 return FALSE;
349 /*********************************************************************
351 * PSDRV_PPDGetNextTuple
353 * Gets the next Keyword Option Value tuple from the file. Allocs space off
354 * the process heap which should be free()ed by the caller if not needed.
356 static BOOL PSDRV_PPDGetNextTuple(FILE *fp, PPDTuple *tuple)
358 char line[257], *opt = NULL, *cp, *trans, *endkey;
359 BOOL gotoption = TRUE;
361 memset(tuple, 0, sizeof(*tuple));
363 do {
364 if(!fgets(line, sizeof(line), fp))
365 return FALSE;
366 if(line[0] == '*' && line[1] != '%' && strncmp(line, "*End", 4))
367 break;
368 } while(1);
370 if(line[strlen(line)-1] != '\n') {
371 ERR("Line too long.\n");
372 return FALSE;
375 for(cp = line; !isspace(*cp) && *cp != ':'; cp++)
378 endkey = cp;
379 if(*cp == ':') { /* <key>: */
380 gotoption = FALSE;
381 } else {
382 while(isspace(*cp))
383 cp++;
384 if(*cp == ':') { /* <key> : */
385 gotoption = FALSE;
386 } else { /* <key> <option> */
387 opt = cp;
391 tuple->key = HeapAlloc( PSDRV_Heap, 0, endkey - line + 1 );
392 if(!tuple->key) return FALSE;
394 memcpy(tuple->key, line, endkey - line);
395 tuple->key[endkey - line] = '\0';
397 if(gotoption) { /* opt points to 1st non-space character of the option */
398 cp = strpbrk(opt, ":/");
399 if(!cp) {
400 ERR("Error in line '%s'?\n", line);
401 return FALSE;
403 tuple->option = HeapAlloc( PSDRV_Heap, 0, cp - opt + 1 );
404 if(!tuple->option) return FALSE;
405 memcpy(tuple->option, opt, cp - opt);
406 tuple->option[cp - opt] = '\0';
407 if(*cp == '/') {
408 char *buf;
409 trans = cp + 1;
410 cp = strchr(trans, ':');
411 if(!cp) {
412 ERR("Error in line '%s'?\n", line);
413 return FALSE;
415 buf = HeapAlloc( PSDRV_Heap, 0, cp - trans + 1 );
416 if(!buf) return FALSE;
417 memcpy(buf, trans, cp - trans);
418 buf[cp - trans] = '\0';
419 tuple->opttrans = PSDRV_PPDDecodeHex(buf);
420 HeapFree( PSDRV_Heap, 0, buf );
424 /* cp should point to a ':', so we increment past it */
425 cp++;
427 while(isspace(*cp))
428 cp++;
430 switch(*cp) {
431 case '"':
432 if( (!gotoption && strncmp(tuple->key, "*?", 2) ) ||
433 !strncmp(tuple->key, "*JCL", 4))
434 PSDRV_PPDGetQuotedValue(fp, cp, tuple);
435 else
436 PSDRV_PPDGetInvocationValue(fp, cp, tuple);
437 break;
439 case '^':
440 PSDRV_PPDGetSymbolValue(cp, tuple);
441 break;
443 default:
444 PSDRV_PPDGetStringValue(cp, tuple);
446 return TRUE;
449 /*********************************************************************
451 * PSDRV_PPDGetPageSizeInfo
453 * Searches ppd PageSize list to return entry matching name or creates new
454 * entry which is appended to the list if name is not found.
457 PAGESIZE *PSDRV_PPDGetPageSizeInfo(PPD *ppd, char *name)
459 PAGESIZE *page = ppd->PageSizes, *lastpage;
461 if(!page) {
462 page = ppd->PageSizes = HeapAlloc( PSDRV_Heap,
463 HEAP_ZERO_MEMORY, sizeof(*page) );
464 return page;
465 } else {
466 for( ; page; page = page->next) {
467 if(!strcmp(page->Name, name))
468 return page;
469 lastpage = page;
472 lastpage->next = HeapAlloc( PSDRV_Heap,
473 HEAP_ZERO_MEMORY, sizeof(*page) );
474 return lastpage->next;
478 /**********************************************************************
480 * PSDRV_PPDGetWord
482 * Returns ptr alloced from heap to first word in str. Strips leading spaces.
483 * Puts ptr to next word in next
485 static char *PSDRV_PPDGetWord(char *str, char **next)
487 char *start, *end, *ret;
489 start = str;
490 while(start && *start && isspace(*start))
491 start++;
492 if(!start || !*start) return FALSE;
494 end = start;
495 while(*end && !isspace(*end))
496 end++;
498 ret = HeapAlloc( PSDRV_Heap, 0, end - start + 1 );
499 memcpy(ret, start, end - start );
500 *(ret + (end - start)) = '\0';
502 while(*end && isspace(*end))
503 end++;
504 if(*end)
505 *next = end;
506 else
507 *next = NULL;
509 return ret;
512 /*******************************************************************************
513 * PSDRV_AddSlot
516 static INT PSDRV_AddSlot(PPD *ppd, LPSTR szName, LPSTR szFullName,
517 LPSTR szInvocationString, WORD wWinBin)
519 INPUTSLOT *slot, **insert = &ppd->InputSlots;
521 while (*insert)
522 insert = &((*insert)->next);
524 slot = *insert = HeapAlloc(PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(INPUTSLOT));
525 if (!slot)
527 ERR("Failed to allocate %i bytes of memory\n", sizeof(INPUTSLOT));
528 return 1;
531 slot->Name = szName;
532 slot->FullName = szFullName;
533 slot->InvocationString = szInvocationString;
534 slot->WinBin = wWinBin;
536 return 0;
539 /***********************************************************************
541 * PSDRV_ParsePPD
545 PPD *PSDRV_ParsePPD(char *fname)
547 FILE *fp;
548 PPD *ppd;
549 PPDTuple tuple;
551 TRACE("file '%s'\n", fname);
553 if((fp = fopen(fname, "r")) == NULL) {
554 WARN("Couldn't open ppd file '%s'\n", fname);
555 return NULL;
558 ppd = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*ppd));
559 if(!ppd) {
560 ERR("Unable to allocate memory for ppd\n");
561 fclose(fp);
562 return NULL;
566 * The Windows PostScript drivers create the following "virtual bin" for
567 * every PostScript printer
569 if (PSDRV_AddSlot(ppd, NULL, "Automatically Select", NULL,
570 DMBIN_FORMSOURCE))
572 HeapFree (PSDRV_Heap, 0, ppd);
573 fclose(fp);
574 return NULL;
577 while( PSDRV_PPDGetNextTuple(fp, &tuple)) {
579 if(!strcmp("*NickName", tuple.key)) {
580 ppd->NickName = tuple.value;
581 tuple.value = NULL;
582 TRACE("NickName = '%s'\n", ppd->NickName);
585 else if(!strcmp("*LanguageLevel", tuple.key)) {
586 sscanf(tuple.value, "%d", &(ppd->LanguageLevel));
587 TRACE("LanguageLevel = %d\n", ppd->LanguageLevel);
590 else if(!strcmp("*ColorDevice", tuple.key)) {
591 if(!strcasecmp(tuple.value, "true"))
592 ppd->ColorDevice = TRUE;
593 TRACE("ColorDevice = %d\n", (int)ppd->ColorDevice);
596 else if((!strcmp("*DefaultResolution", tuple.key)) ||
597 (!strcmp("*DefaultJCLResolution", tuple.key))) {
598 sscanf(tuple.value, "%d", &(ppd->DefaultResolution));
599 TRACE("DefaultResolution = %d\n", ppd->DefaultResolution);
602 else if(!strcmp("*Font", tuple.key)) {
603 FONTNAME *fn;
605 for(fn = ppd->InstalledFonts; fn && fn->next; fn = fn->next)
607 if(!fn) {
608 ppd->InstalledFonts = HeapAlloc(PSDRV_Heap,
609 HEAP_ZERO_MEMORY, sizeof(*fn));
610 fn = ppd->InstalledFonts;
611 } else {
612 fn->next = HeapAlloc(PSDRV_Heap,
613 HEAP_ZERO_MEMORY, sizeof(*fn));
614 fn = fn->next;
616 fn->Name = tuple.option;
617 tuple.option = NULL;
620 else if(!strcmp("*DefaultFont", tuple.key)) {
621 ppd->DefaultFont = tuple.value;
622 tuple.value = NULL;
625 else if(!strcmp("*JCLBegin", tuple.key)) {
626 ppd->JCLBegin = tuple.value;
627 tuple.value = NULL;
630 else if(!strcmp("*JCLToPSInterpreter", tuple.key)) {
631 ppd->JCLToPSInterpreter = tuple.value;
632 tuple.value = NULL;
635 else if(!strcmp("*JCLEnd", tuple.key)) {
636 ppd->JCLEnd = tuple.value;
637 tuple.value = NULL;
640 else if(!strcmp("*PageSize", tuple.key)) {
641 PAGESIZE *page;
642 page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
644 if(!page->Name) {
645 int i;
647 page->Name = tuple.option;
648 tuple.option = NULL;
650 for(i = 0; PageTrans[i].PSName; i++) {
651 if(!strcmp(PageTrans[i].PSName, page->Name)) { /* case ? */
652 page->WinPage = PageTrans[i].WinPage;
653 break;
656 if(!page->WinPage) {
657 TRACE("Can't find Windows page type for '%s' - using %u\n",
658 page->Name, UserPageType);
659 page->WinPage = UserPageType++;
662 if(!page->FullName) {
663 if(tuple.opttrans) {
664 page->FullName = tuple.opttrans;
665 tuple.opttrans = NULL;
666 } else
668 page->FullName = HeapAlloc( PSDRV_Heap, 0, strlen(page->Name)+1 );
669 strcpy( page->FullName, page->Name );
672 if(!page->InvocationString) {
673 page->InvocationString = tuple.value;
674 tuple.value = NULL;
678 else if(!strcmp("*ImageableArea", tuple.key)) {
679 PAGESIZE *page;
680 page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
682 if(!page->Name) {
683 page->Name = tuple.option;
684 tuple.option = NULL;
686 if(!page->FullName) {
687 page->FullName = tuple.opttrans;
688 tuple.opttrans = NULL;
691 #define PIA page->ImageableArea
692 if(!PIA) {
693 PIA = HeapAlloc( PSDRV_Heap, 0, sizeof(*PIA) );
694 sscanf(tuple.value, "%f%f%f%f", &PIA->llx, &PIA->lly,
695 &PIA->urx, &PIA->ury);
697 #undef PIA
701 else if(!strcmp("*PaperDimension", tuple.key)) {
702 PAGESIZE *page;
703 page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
705 if(!page->Name) {
706 page->Name = tuple.option;
707 tuple.option = NULL;
709 if(!page->FullName) {
710 page->FullName = tuple.opttrans;
711 tuple.opttrans = NULL;
714 #define PD page->PaperDimension
715 if(!PD) {
716 PD = HeapAlloc( PSDRV_Heap, 0, sizeof(*PD) );
717 sscanf(tuple.value, "%f%f", &PD->x, &PD->y);
719 #undef PD
722 else if(!strcmp("*LandscapeOrientation", tuple.key)) {
723 if(!strcmp(tuple.value, "Plus90"))
724 ppd->LandscapeOrientation = 90;
725 else if(!strcmp(tuple.value, "Minus90"))
726 ppd->LandscapeOrientation = -90;
728 /* anything else, namely 'any', leaves value at 0 */
730 TRACE("LandscapeOrientation = %d\n",
731 ppd->LandscapeOrientation);
734 else if(!strcmp("*UIConstraints", tuple.key)) {
735 char *start;
736 CONSTRAINT *con, **insert = &ppd->Constraints;
738 while(*insert)
739 insert = &((*insert)->next);
741 con = *insert = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
742 sizeof(*con) );
744 start = tuple.value;
746 con->Feature1 = PSDRV_PPDGetWord(start, &start);
747 con->Value1 = PSDRV_PPDGetWord(start, &start);
748 con->Feature2 = PSDRV_PPDGetWord(start, &start);
749 con->Value2 = PSDRV_PPDGetWord(start, &start);
752 else if (!strcmp("*InputSlot", tuple.key))
755 if (!tuple.opttrans)
756 tuple.opttrans = tuple.option;
758 TRACE("Using Windows bin type %u for '%s'\n", UserBinType,
759 tuple.option);
761 /* FIXME - should check for failure */
762 PSDRV_AddSlot(ppd, tuple.option, tuple.opttrans, tuple.value,
763 UserBinType++);
765 tuple.option = tuple.opttrans = tuple.value = NULL;
769 * Windows treats "manual feed" as another paper source. Most PPD
770 * files, however, treat it as a separate option which is either on or
771 * off.
773 else if (!strcmp("*ManualFeed", tuple.key) && tuple.option &&
774 !strcmp ("True", tuple.option))
776 /* FIXME - should check for failure */
777 PSDRV_AddSlot(ppd, "Manual Feed", "Manual Feed", tuple.value, DMBIN_MANUAL);
778 tuple.value = NULL;
781 else if(!strcmp("*TTRasterizer", tuple.key)) {
782 if(!strcasecmp("None", tuple.value))
783 ppd->TTRasterizer = RO_None;
784 else if(!strcasecmp("Accept68K", tuple.value))
785 ppd->TTRasterizer = RO_Accept68K;
786 else if(!strcasecmp("Type42", tuple.value))
787 ppd->TTRasterizer = RO_Type42;
788 else if(!strcasecmp("TrueImage", tuple.value))
789 ppd->TTRasterizer = RO_TrueImage;
790 else {
791 FIXME("Unknown option %s for *TTRasterizer\n",
792 tuple.value);
793 ppd->TTRasterizer = RO_None;
795 TRACE("*TTRasterizer = %d\n", ppd->TTRasterizer);
798 if(tuple.key) HeapFree(PSDRV_Heap, 0, tuple.key);
799 if(tuple.option) HeapFree(PSDRV_Heap, 0, tuple.option);
800 if(tuple.value) HeapFree(PSDRV_Heap, 0, tuple.value);
801 if(tuple.opttrans) HeapFree(PSDRV_Heap, 0, tuple.opttrans);
802 if(tuple.valtrans) HeapFree(PSDRV_Heap, 0, tuple.valtrans);
808 FONTNAME *fn;
809 PAGESIZE *page;
810 CONSTRAINT *con;
811 INPUTSLOT *slot;
812 OPTION *option;
813 OPTIONENTRY *optionEntry;
815 for(fn = ppd->InstalledFonts; fn; fn = fn->next)
816 TRACE("'%s'\n", fn->Name);
818 for(page = ppd->PageSizes; page; page = page->next) {
819 TRACE("'%s' aka '%s' (%d) invoked by '%s'\n", page->Name,
820 page->FullName, page->WinPage, page->InvocationString);
821 if(page->ImageableArea)
822 TRACE("Area = %.2f,%.2f - %.2f, %.2f\n",
823 page->ImageableArea->llx, page->ImageableArea->lly,
824 page->ImageableArea->urx, page->ImageableArea->ury);
825 if(page->PaperDimension)
826 TRACE("Dimension = %.2f x %.2f\n",
827 page->PaperDimension->x, page->PaperDimension->y);
830 for(con = ppd->Constraints; con; con = con->next)
831 TRACE("CONSTRAINTS@ %s %s %s %s\n", con->Feature1,
832 con->Value1, con->Feature2, con->Value2);
834 for(option = ppd->InstalledOptions; option; option = option->next) {
835 TRACE("OPTION: %s %s %s\n", option->OptionName,
836 option->FullName, option->DefaultOption);
837 for(optionEntry = option->Options; optionEntry;
838 optionEntry = optionEntry->next)
839 TRACE("\tOPTIONENTRY: %s %s %s\n", optionEntry->Name,
840 optionEntry->FullName, optionEntry->InvocationString);
843 for(slot = ppd->InputSlots; slot; slot = slot->next)
844 TRACE("INPUTSLOTS '%s' Name '%s' (%d) Invocation '%s'\n",
845 slot->Name, slot->FullName, slot->WinBin,
846 slot->InvocationString);
849 return ppd;