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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
32 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
46 /* map of page names in ppd file to Windows paper constants */
52 {"10x11", DMPAPER_10X11
},
53 {"10x14", DMPAPER_10X14
},
54 {"11x17", DMPAPER_11X17
}, /* not in Adobe PPD file spec */
55 {"12x11", DMPAPER_12X11
},
56 {"15x11", DMPAPER_15X11
},
57 {"9x11", DMPAPER_9X11
},
60 {"A3.Transverse", DMPAPER_A3_TRANSVERSE
},
61 {"A3Extra", DMPAPER_A3_EXTRA
},
62 {"A3Extra.Transverse", DMPAPER_A3_EXTRA_TRANSVERSE
},
63 {"A3Rotated", DMPAPER_A3_ROTATED
},
65 {"A4.Transverse", DMPAPER_A4_TRANSVERSE
},
66 {"A4Extra", DMPAPER_A4_EXTRA
},
67 {"A4Plus", DMPAPER_A4_PLUS
},
68 {"A4Rotated", DMPAPER_A4_ROTATED
},
69 {"A4Small", DMPAPER_A4SMALL
},
71 {"A5.Transverse", DMPAPER_A5_TRANSVERSE
},
72 {"A5Extra", DMPAPER_A5_EXTRA
},
73 {"A5Rotated", DMPAPER_A5_ROTATED
},
75 {"A6Rotated", DMPAPER_A6_ROTATED
},
76 {"ARCHC", DMPAPER_CSHEET
},
77 {"ARCHD", DMPAPER_DSHEET
},
78 {"ARCHE", DMPAPER_ESHEET
},
80 {"B4Rotated", DMPAPER_B4_JIS_ROTATED
},
82 {"B5.Transverse", DMPAPER_B5_TRANSVERSE
},
83 {"B5Rotated", DMPAPER_B5_JIS_ROTATED
},
84 {"B6", DMPAPER_B6_JIS
},
85 {"B6Rotated", DMPAPER_B6_JIS_ROTATED
},
86 {"C4", DMPAPER_ENV_C4
}, /* use EnvC4 */
87 {"C5", DMPAPER_ENV_C5
}, /* use EnvC5 */
88 {"C6", DMPAPER_ENV_C6
}, /* use EnvC6 */
89 {"Comm10", DMPAPER_ENV_10
}, /* use Env10 */
90 {"DL", DMPAPER_ENV_DL
}, /* use EnvDL */
91 {"DoublePostcard", DMPAPER_DBL_JAPANESE_POSTCARD
},
92 {"DoublePostcardRotated", DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED
},
93 {"Env10", DMPAPER_ENV_10
},
94 {"Env11", DMPAPER_ENV_11
},
95 {"Env12", DMPAPER_ENV_12
},
96 {"Env14", DMPAPER_ENV_14
},
97 {"Env9", DMPAPER_ENV_9
},
98 {"EnvC3", DMPAPER_ENV_C3
},
99 {"EnvC4", DMPAPER_ENV_C4
},
100 {"EnvC5", DMPAPER_ENV_C5
},
101 {"EnvC6", DMPAPER_ENV_C6
},
102 {"EnvC65", DMPAPER_ENV_C65
},
103 {"EnvChou3", DMPAPER_JENV_CHOU3
},
104 {"EnvChou3Rotated", DMPAPER_JENV_CHOU3_ROTATED
},
105 {"EnvChou4", DMPAPER_JENV_CHOU4
},
106 {"EnvChou4Rotated", DMPAPER_JENV_CHOU4_ROTATED
},
107 {"EnvDL", DMPAPER_ENV_DL
},
108 {"EnvISOB4", DMPAPER_ENV_B4
},
109 {"EnvISOB5", DMPAPER_ENV_B5
},
110 {"EnvISOB6", DMPAPER_ENV_B6
},
111 {"EnvInvite", DMPAPER_ENV_INVITE
},
112 {"EnvItalian", DMPAPER_ENV_ITALY
},
113 {"EnvKaku2", DMPAPER_JENV_KAKU2
},
114 {"EnvKaku2Rotated", DMPAPER_JENV_KAKU2_ROTATED
},
115 {"EnvKaku3", DMPAPER_JENV_KAKU3
},
116 {"EnvKaku3Rotated", DMPAPER_JENV_KAKU3_ROTATED
},
117 {"EnvMonarch", DMPAPER_ENV_MONARCH
},
118 {"EnvPRC1", DMPAPER_PENV_1
},
119 {"EnvPRC10", DMPAPER_PENV_10
},
120 {"EnvPRC10Rotated", DMPAPER_PENV_10_ROTATED
},
121 {"EnvPRC1Rotated", DMPAPER_PENV_1_ROTATED
},
122 {"EnvPRC2", DMPAPER_PENV_2
},
123 {"EnvPRC2Rotated", DMPAPER_PENV_2_ROTATED
},
124 {"EnvPRC3", DMPAPER_PENV_3
},
125 {"EnvPRC3Rotated", DMPAPER_PENV_3_ROTATED
},
126 {"EnvPRC4", DMPAPER_PENV_4
},
127 {"EnvPRC4Rotated", DMPAPER_PENV_4_ROTATED
},
128 {"EnvPRC5", DMPAPER_PENV_5
},
129 {"EnvPRC5Rotated", DMPAPER_PENV_5_ROTATED
},
130 {"EnvPRC6", DMPAPER_PENV_6
},
131 {"EnvPRC6Rotated", DMPAPER_PENV_6_ROTATED
},
132 {"EnvPRC7", DMPAPER_PENV_7
},
133 {"EnvPRC7Rotated", DMPAPER_PENV_7_ROTATED
},
134 {"EnvPRC8", DMPAPER_PENV_8
},
135 {"EnvPRC8Rotated", DMPAPER_PENV_8_ROTATED
},
136 {"EnvPRC9", DMPAPER_PENV_9
},
137 {"EnvPRC9Rotated", DMPAPER_PENV_9_ROTATED
},
138 {"EnvPersonal", DMPAPER_ENV_PERSONAL
},
139 {"EnvYou4", DMPAPER_JENV_YOU4
},
140 {"EnvYou4Rotated", DMPAPER_JENV_YOU4_ROTATED
},
141 {"Executive", DMPAPER_EXECUTIVE
},
142 {"FanFoldGerman", DMPAPER_FANFOLD_STD_GERMAN
},
143 {"FanFoldGermanLegal", DMPAPER_FANFOLD_LGL_GERMAN
},
144 {"FanFoldUS", DMPAPER_FANFOLD_US
},
145 {"Folio", DMPAPER_FOLIO
},
146 {"ISOB4", DMPAPER_ISO_B4
},
147 {"ISOB5Extra", DMPAPER_B5_EXTRA
},
148 {"Ledger", DMPAPER_LEDGER
},
149 {"Legal", DMPAPER_LEGAL
},
150 {"LegalExtra", DMPAPER_LEGAL_EXTRA
},
151 {"Letter", DMPAPER_LETTER
},
152 {"Letter.Transverse", DMPAPER_LETTER_TRANSVERSE
},
153 {"LetterExtra", DMPAPER_LETTER_EXTRA
},
154 {"LetterExtra.Transverse", DMPAPER_LETTER_EXTRA_TRANSVERSE
},
155 {"LetterPlus", DMPAPER_LETTER_PLUS
},
156 {"LetterRotated", DMPAPER_LETTER_ROTATED
},
157 {"LetterSmall", DMPAPER_LETTERSMALL
},
158 {"Monarch", DMPAPER_ENV_MONARCH
}, /* use EnvMonarch */
159 {"Note", DMPAPER_NOTE
},
160 {"PRC16K", DMPAPER_P16K
},
161 {"PRC16KRotated", DMPAPER_P16K_ROTATED
},
162 {"PRC32K", DMPAPER_P32K
},
163 {"PRC32KBig", DMPAPER_P32KBIG
},
164 {"PRC32KBigRotated", DMPAPER_P32KBIG_ROTATED
},
165 {"PRC32KRotated", DMPAPER_P32K_ROTATED
},
166 {"Postcard", DMPAPER_JAPANESE_POSTCARD
},
167 {"PostcardRotated", DMPAPER_JAPANESE_POSTCARD_ROTATED
},
168 {"Quarto", DMPAPER_QUARTO
},
169 {"Statement", DMPAPER_STATEMENT
},
170 {"SuperA", DMPAPER_A_PLUS
},
171 {"SuperB", DMPAPER_B_PLUS
},
172 {"Tabloid", DMPAPER_TABLOID
},
173 {"TabloidExtra", DMPAPER_TABLOID_EXTRA
},
177 static WORD UserPageType
= DMPAPER_USER
;
178 static WORD UserBinType
= DMBIN_USER
;
180 /***********************************************************************
184 * Copies str into a newly allocated string from the process heap substituting
185 * hex strings enclosed in '<' and '>' for their byte codes.
188 static char *PSDRV_PPDDecodeHex(char *str
)
190 char *buf
, *in
, *out
;
193 buf
= HeapAlloc(PSDRV_Heap
, 0, strlen(str
) + 1);
197 for(in
= str
, out
= buf
; *in
; in
++) {
208 else if(isspace(*in
))
212 if(!isxdigit(*in
) || !isxdigit(*(in
+ 1))) {
213 ERR("Invalid hex char in hex string\n");
214 HeapFree(PSDRV_Heap
, 0, buf
);
218 for(i
= 0; i
< 2; i
++) {
219 if(isdigit(*(in
+ i
)))
220 *out
|= (*(in
+ i
) - '0') << ((1-i
) * 4);
222 *out
|= (toupper(*(in
+ i
)) - 'A' + 10) << ((1-i
) * 4);
234 /***********************************************************************
236 * PSDRV_PPDGetTransValue
239 static BOOL
PSDRV_PPDGetTransValue(char *start
, PPDTuple
*tuple
)
243 end
= strpbrk(start
, "\r\n");
244 if(end
== start
) return FALSE
;
245 if(!end
) end
= start
+ strlen(start
);
246 buf
= HeapAlloc( PSDRV_Heap
, 0, end
- start
+ 1 );
247 memcpy(buf
, start
, end
- start
);
248 *(buf
+ (end
- start
)) = '\0';
249 tuple
->valtrans
= PSDRV_PPDDecodeHex(buf
);
250 HeapFree( PSDRV_Heap
, 0, buf
);
255 /***********************************************************************
257 * PSDRV_PPDGetInvocationValue
259 * Passed string that should be surrounded by `"'s, return string alloced
262 static BOOL
PSDRV_PPDGetInvocationValue(FILE *fp
, char *pos
, PPDTuple
*tuple
)
264 char *start
, *end
, *buf
;
269 buf
= HeapAlloc( PSDRV_Heap
, 0, strlen(start
) + 1 );
272 end
= strchr(start
, '"');
274 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
,
275 len
+ (end
- start
) + 1 );
276 memcpy(buf
+ len
, start
, end
- start
);
277 *(buf
+ len
+ (end
- start
)) = '\0';
279 start
= strchr(end
, '/');
281 return PSDRV_PPDGetTransValue(start
+ 1, tuple
);
284 int sl
= strlen(start
);
285 buf
= HeapReAlloc( PSDRV_Heap
, 0, buf
, len
+ sl
+ 1 );
286 strcpy(buf
+ len
, start
);
289 } while( fgets((start
= line
), sizeof(line
), fp
) );
292 HeapFree( PSDRV_Heap
, 0, buf
);
297 /***********************************************************************
299 * PSDRV_PPDGetQuotedValue
301 * Passed string that should be surrounded by `"'s. Expand <xx> as hex
302 * return string alloced from process heap.
304 static BOOL
PSDRV_PPDGetQuotedValue(FILE *fp
, char *pos
, PPDTuple
*tuple
)
308 if(!PSDRV_PPDGetInvocationValue(fp
, pos
, tuple
))
310 buf
= PSDRV_PPDDecodeHex(tuple
->value
);
311 HeapFree(PSDRV_Heap
, 0, tuple
->value
);
317 /***********************************************************************
319 * PSDRV_PPDGetStringValue
321 * Just strip leading white space.
323 static BOOL
PSDRV_PPDGetStringValue(char *str
, PPDTuple
*tuple
)
325 char *start
= str
, *end
;
327 while(*start
!= '\0' && isspace(*start
))
330 end
= strpbrk(start
, "/\r\n");
331 if(!end
) end
= start
+ strlen(start
);
332 tuple
->value
= HeapAlloc( PSDRV_Heap
, 0, (end
- start
) + 1 );
333 memcpy(tuple
->value
, start
, end
- start
);
334 *(tuple
->value
+ (end
- start
)) = '\0';
336 PSDRV_PPDGetTransValue(end
+ 1, tuple
);
341 /***********************************************************************
343 * PSDRV_PPDSymbolValue
345 * Not implemented yet.
347 static BOOL
PSDRV_PPDGetSymbolValue(char *pos
, PPDTuple
*tuple
)
354 /*********************************************************************
356 * PSDRV_PPDGetNextTuple
358 * Gets the next Keyword Option Value tuple from the file. Allocs space off
359 * the process heap which should be free()ed by the caller if not needed.
361 static BOOL
PSDRV_PPDGetNextTuple(FILE *fp
, PPDTuple
*tuple
)
363 char line
[257], *opt
, *cp
, *trans
, *endkey
;
370 memset(tuple
, 0, sizeof(*tuple
));
373 if(!fgets(line
, sizeof(line
), fp
))
375 if(line
[0] == '*' && line
[1] != '%' && strncmp(line
, "*End", 4))
379 if(line
[strlen(line
)-1] != '\n') {
380 ERR("Line too long.\n");
384 for(cp
= line
; !isspace(*cp
) && *cp
!= ':'; cp
++)
388 if(*cp
== ':') { /* <key>: */
393 if(*cp
== ':') { /* <key> : */
395 } else { /* <key> <option> */
400 tuple
->key
= HeapAlloc( PSDRV_Heap
, 0, endkey
- line
+ 1 );
401 if(!tuple
->key
) return FALSE
;
403 memcpy(tuple
->key
, line
, endkey
- line
);
404 tuple
->key
[endkey
- line
] = '\0';
406 if(gotoption
) { /* opt points to 1st non-space character of the option */
407 cp
= strpbrk(opt
, ":/");
409 ERR("Error in line '%s'?\n", line
);
410 HeapFree(GetProcessHeap(), 0, tuple
->key
);
413 tuple
->option
= HeapAlloc( PSDRV_Heap
, 0, cp
- opt
+ 1 );
414 if(!tuple
->option
) return FALSE
;
415 memcpy(tuple
->option
, opt
, cp
- opt
);
416 tuple
->option
[cp
- opt
] = '\0';
420 cp
= strchr(trans
, ':');
422 ERR("Error in line '%s'?\n", line
);
423 HeapFree(GetProcessHeap(), 0, tuple
->option
);
424 HeapFree(GetProcessHeap(), 0, tuple
->key
);
427 buf
= HeapAlloc( PSDRV_Heap
, 0, cp
- trans
+ 1 );
428 if(!buf
) return FALSE
;
429 memcpy(buf
, trans
, cp
- trans
);
430 buf
[cp
- trans
] = '\0';
431 tuple
->opttrans
= PSDRV_PPDDecodeHex(buf
);
432 HeapFree( PSDRV_Heap
, 0, buf
);
436 /* cp should point to a ':', so we increment past it */
444 if( (!gotoption
&& strncmp(tuple
->key
, "*?", 2) ) ||
445 !strncmp(tuple
->key
, "*JCL", 4))
446 PSDRV_PPDGetQuotedValue(fp
, cp
, tuple
);
448 PSDRV_PPDGetInvocationValue(fp
, cp
, tuple
);
452 PSDRV_PPDGetSymbolValue(cp
, tuple
);
456 PSDRV_PPDGetStringValue(cp
, tuple
);
461 /*********************************************************************
464 * Searches ppd PageSize list to return entry matching name or optionally creates new
465 * entry which is appended to the list if name is not found.
467 static PAGESIZE
*get_pagesize( PPD
*ppd
, char *name
, BOOL create
)
471 LIST_FOR_EACH_ENTRY(page
, &ppd
->PageSizes
, PAGESIZE
, entry
)
473 if(!strcmp(page
->Name
, name
))
477 if (!create
) return NULL
;
479 page
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*page
) );
480 list_add_tail(&ppd
->PageSizes
, &page
->entry
);
484 static DUPLEX
*get_duplex( PPD
*ppd
, const char *name
)
488 LIST_FOR_EACH_ENTRY( duplex
, &ppd
->Duplexes
, DUPLEX
, entry
)
490 if (!strcmp( duplex
->Name
, name
))
497 /**********************************************************************
501 * Returns ptr alloced from heap to first word in str. Strips leading spaces.
502 * Puts ptr to next word in next
504 static char *PSDRV_PPDGetWord(char *str
, char **next
)
506 char *start
, *end
, *ret
;
509 while(start
&& *start
&& isspace(*start
))
511 if(!start
|| !*start
) return FALSE
;
514 while(*end
&& !isspace(*end
))
517 ret
= HeapAlloc( PSDRV_Heap
, 0, end
- start
+ 1 );
518 memcpy(ret
, start
, end
- start
);
519 *(ret
+ (end
- start
)) = '\0';
521 while(*end
&& isspace(*end
))
531 /************************************************************
534 * Helper to extract x and y resolutions from a resolution entry.
535 * Returns TRUE on successful parsing, otherwise FALSE.
537 * The ppd spec says that entries can either be:
541 * in the former case return sz.cx == cx.cy == nnn.
543 * There are broken ppd files out there (notably from Samsung) that
544 * use the form "nnnmmmdpi", so we have to work harder to spot these.
545 * We use a transition from a zero to a non-zero digit as separator
546 * (and fail if we find more than one of these). We also don't bother
547 * trying to parse "dpi" in case that's missing.
549 static BOOL
parse_resolution(const char *str
, SIZE
*sz
)
556 if(sscanf(str
, "%dx%d", tmp
, tmp
+ 1) == 2)
567 for(c
= str
; isdigit(*c
); c
++)
569 if(!had_zero
|| *c
== '0')
585 if(tmp
[0] == 0) return FALSE
;
595 /*******************************************************************************
599 static BOOL
PSDRV_AddSlot(PPD
*ppd
, LPCSTR szName
, LPCSTR szFullName
,
600 LPSTR szInvocationString
, WORD wWinBin
)
602 INPUTSLOT
*slot
= HeapAlloc( PSDRV_Heap
, 0, sizeof(INPUTSLOT
) );
603 if (!slot
) return FALSE
;
606 slot
->FullName
= szFullName
;
607 slot
->InvocationString
= szInvocationString
;
608 slot
->WinBin
= wWinBin
;
610 list_add_tail( &ppd
->InputSlots
, &slot
->entry
);
614 static char *get_ppd_override( HANDLE printer
, const char *value
)
616 DWORD err
, type
, needed
;
619 err
= GetPrinterDataExA( printer
, "PPD Overrides", value
, &type
, NULL
, 0, &needed
);
620 if (err
!= ERROR_MORE_DATA
|| type
!= REG_SZ
|| needed
== 0) return NULL
;
622 data
= HeapAlloc( PSDRV_Heap
, 0, needed
);
625 GetPrinterDataExA( printer
, "PPD Overrides", value
, &type
, (BYTE
*)data
, needed
, &needed
);
626 TRACE( "got override %s: %s\n", value
, data
);
631 /***********************************************************************
637 PPD
*PSDRV_ParsePPD( char *fname
, HANDLE printer
)
642 char *default_pagesize
= NULL
, *default_duplex
= NULL
;
643 char *def_pagesize_override
= NULL
, *def_duplex_override
= NULL
;
644 PAGESIZE
*page
, *page_cursor2
;
646 TRACE("file '%s'\n", fname
);
648 if((fp
= fopen(fname
, "r")) == NULL
) {
649 WARN("Couldn't open ppd file '%s'\n", fname
);
653 ppd
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*ppd
));
655 ERR("Unable to allocate memory for ppd\n");
660 ppd
->ColorDevice
= CD_NotSpecified
;
662 list_init( &ppd
->InstalledFonts
);
663 list_init( &ppd
->PageSizes
);
664 list_init( &ppd
->Constraints
);
665 list_init( &ppd
->InputSlots
);
666 list_init( &ppd
->Duplexes
);
668 /* Some gimp-print ppd files don't contain a DefaultResolution line
670 ppd
->DefaultResolution
= 300;
673 * The Windows PostScript drivers create the following "virtual bin" for
674 * every PostScript printer
676 if (!PSDRV_AddSlot( ppd
, NULL
, "Automatically Select", NULL
, DMBIN_FORMSOURCE
))
678 HeapFree (PSDRV_Heap
, 0, ppd
);
683 while( PSDRV_PPDGetNextTuple(fp
, &tuple
)) {
685 if(!strcmp("*NickName", tuple
.key
)) {
686 ppd
->NickName
= tuple
.value
;
688 TRACE("NickName = '%s'\n", ppd
->NickName
);
691 else if(!strcmp("*LanguageLevel", tuple
.key
)) {
692 sscanf(tuple
.value
, "%d", &(ppd
->LanguageLevel
));
693 TRACE("LanguageLevel = %d\n", ppd
->LanguageLevel
);
696 else if(!strcmp("*ColorDevice", tuple
.key
)) {
697 if(!strcasecmp(tuple
.value
, "true"))
698 ppd
->ColorDevice
= CD_True
;
700 ppd
->ColorDevice
= CD_False
;
701 TRACE("ColorDevice = %s\n", ppd
->ColorDevice
== CD_True
? "True" : "False");
704 else if((!strcmp("*DefaultResolution", tuple
.key
)) ||
705 (!strcmp("*DefaultJCLResolution", tuple
.key
))) {
707 if(parse_resolution(tuple
.value
, &sz
))
709 TRACE("DefaultResolution %dx%d\n", sz
.cx
, sz
.cy
);
710 ppd
->DefaultResolution
= sz
.cx
;
713 WARN("failed to parse DefaultResolution %s\n", debugstr_a(tuple
.value
));
716 else if(!strcmp("*Font", tuple
.key
))
718 FONTNAME
*fn
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*fn
) );
719 fn
->Name
= tuple
.option
;
721 list_add_tail( &ppd
->InstalledFonts
, &fn
->entry
);
724 else if(!strcmp("*DefaultFont", tuple
.key
)) {
725 ppd
->DefaultFont
= tuple
.value
;
729 else if(!strcmp("*JCLBegin", tuple
.key
)) {
730 ppd
->JCLBegin
= tuple
.value
;
734 else if(!strcmp("*JCLToPSInterpreter", tuple
.key
)) {
735 ppd
->JCLToPSInterpreter
= tuple
.value
;
739 else if(!strcmp("*JCLEnd", tuple
.key
)) {
740 ppd
->JCLEnd
= tuple
.value
;
744 else if(!strcmp("*PageSize", tuple
.key
)) {
745 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
750 page
->Name
= tuple
.option
;
753 for(i
= 0; PageTrans
[i
].PSName
; i
++) {
754 if(!strcmp(PageTrans
[i
].PSName
, page
->Name
)) { /* case ? */
755 page
->WinPage
= PageTrans
[i
].WinPage
;
760 TRACE("Can't find Windows page type for '%s' - using %u\n",
761 page
->Name
, UserPageType
);
762 page
->WinPage
= UserPageType
++;
765 if(!page
->FullName
) {
767 page
->FullName
= tuple
.opttrans
;
768 tuple
.opttrans
= NULL
;
771 page
->FullName
= HeapAlloc( PSDRV_Heap
, 0, strlen(page
->Name
)+1 );
772 strcpy( page
->FullName
, page
->Name
);
775 if(!page
->InvocationString
) {
776 page
->InvocationString
= tuple
.value
;
781 else if(!strcmp("*DefaultPageSize", tuple
.key
))
783 if (!default_pagesize
)
785 default_pagesize
= tuple
.value
;
790 else if(!strcmp("*ImageableArea", tuple
.key
)) {
791 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
794 page
->Name
= tuple
.option
;
797 if(!page
->FullName
) {
798 page
->FullName
= tuple
.opttrans
;
799 tuple
.opttrans
= NULL
;
802 #define PIA page->ImageableArea
804 PIA
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*PIA
) );
805 push_lc_numeric("C");
806 sscanf(tuple
.value
, "%f%f%f%f", &PIA
->llx
, &PIA
->lly
,
807 &PIA
->urx
, &PIA
->ury
);
813 else if(!strcmp("*PaperDimension", tuple
.key
)) {
814 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
817 page
->Name
= tuple
.option
;
820 if(!page
->FullName
) {
821 page
->FullName
= tuple
.opttrans
;
822 tuple
.opttrans
= NULL
;
825 #define PD page->PaperDimension
827 PD
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*PD
) );
828 push_lc_numeric("C");
829 sscanf(tuple
.value
, "%f%f", &PD
->x
, &PD
->y
);
835 else if(!strcmp("*LandscapeOrientation", tuple
.key
)) {
836 if(!strcmp(tuple
.value
, "Plus90"))
837 ppd
->LandscapeOrientation
= 90;
838 else if(!strcmp(tuple
.value
, "Minus90"))
839 ppd
->LandscapeOrientation
= -90;
841 /* anything else, namely 'any', leaves value at 0 */
843 TRACE("LandscapeOrientation = %d\n",
844 ppd
->LandscapeOrientation
);
847 else if(!strcmp("*UIConstraints", tuple
.key
))
850 CONSTRAINT
*con
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*con
) );
853 con
->Feature1
= PSDRV_PPDGetWord(start
, &start
);
854 con
->Value1
= PSDRV_PPDGetWord(start
, &start
);
855 con
->Feature2
= PSDRV_PPDGetWord(start
, &start
);
856 con
->Value2
= PSDRV_PPDGetWord(start
, &start
);
858 list_add_tail( &ppd
->Constraints
, &con
->entry
);
861 else if (!strcmp("*InputSlot", tuple
.key
))
865 tuple
.opttrans
= tuple
.option
;
867 TRACE("Using Windows bin type %u for '%s'\n", UserBinType
,
870 /* FIXME - should check for failure */
871 PSDRV_AddSlot(ppd
, tuple
.option
, tuple
.opttrans
, tuple
.value
,
874 tuple
.option
= tuple
.opttrans
= tuple
.value
= NULL
;
878 * Windows treats "manual feed" as another paper source. Most PPD
879 * files, however, treat it as a separate option which is either on or
882 else if (!strcmp("*ManualFeed", tuple
.key
) && tuple
.option
&&
883 !strcmp ("True", tuple
.option
))
885 /* FIXME - should check for failure */
886 PSDRV_AddSlot(ppd
, "Manual Feed", "Manual Feed", tuple
.value
, DMBIN_MANUAL
);
890 else if(!strcmp("*TTRasterizer", tuple
.key
)) {
891 if(!strcasecmp("None", tuple
.value
))
892 ppd
->TTRasterizer
= RO_None
;
893 else if(!strcasecmp("Accept68K", tuple
.value
))
894 ppd
->TTRasterizer
= RO_Accept68K
;
895 else if(!strcasecmp("Type42", tuple
.value
))
896 ppd
->TTRasterizer
= RO_Type42
;
897 else if(!strcasecmp("TrueImage", tuple
.value
))
898 ppd
->TTRasterizer
= RO_TrueImage
;
900 FIXME("Unknown option %s for *TTRasterizer\n",
902 ppd
->TTRasterizer
= RO_None
;
904 TRACE("*TTRasterizer = %d\n", ppd
->TTRasterizer
);
907 else if(!strcmp("*Duplex", tuple
.key
))
909 DUPLEX
*duplex
= HeapAlloc( GetProcessHeap(), 0, sizeof(*duplex
) );
910 duplex
->Name
= tuple
.option
;
911 duplex
->FullName
= tuple
.opttrans
;
912 duplex
->InvocationString
= tuple
.value
;
913 if(!strcasecmp("None", tuple
.option
) || !strcasecmp("False", tuple
.option
)
914 || !strcasecmp("Simplex", tuple
.option
))
915 duplex
->WinDuplex
= DMDUP_SIMPLEX
;
916 else if(!strcasecmp("DuplexNoTumble", tuple
.option
))
917 duplex
->WinDuplex
= DMDUP_VERTICAL
;
918 else if(!strcasecmp("DuplexTumble", tuple
.option
))
919 duplex
->WinDuplex
= DMDUP_HORIZONTAL
;
920 else if(!strcasecmp("Notcapable", tuple
.option
))
921 duplex
->WinDuplex
= 0;
923 FIXME("Unknown option %s for *Duplex defaulting to simplex\n", tuple
.option
);
924 duplex
->WinDuplex
= DMDUP_SIMPLEX
;
926 tuple
.option
= tuple
.opttrans
= tuple
.value
= NULL
;
927 list_add_tail( &ppd
->Duplexes
, &duplex
->entry
);
930 else if (!strcmp("*DefaultDuplex", tuple
.key
))
934 default_duplex
= tuple
.value
;
939 HeapFree(PSDRV_Heap
, 0, tuple
.key
);
940 HeapFree(PSDRV_Heap
, 0, tuple
.option
);
941 HeapFree(PSDRV_Heap
, 0, tuple
.value
);
942 HeapFree(PSDRV_Heap
, 0, tuple
.opttrans
);
943 HeapFree(PSDRV_Heap
, 0, tuple
.valtrans
);
947 /* Remove any partial page size entries, that is any without a PageSize or a PaperDimension (we can
948 cope with a missing ImageableArea). */
949 LIST_FOR_EACH_ENTRY_SAFE(page
, page_cursor2
, &ppd
->PageSizes
, PAGESIZE
, entry
)
951 if(!page
->InvocationString
|| !page
->PaperDimension
)
953 WARN("Removing page %s since it has a missing %s entry\n", debugstr_a(page
->FullName
),
954 page
->InvocationString
? "PaperDimension" : "InvocationString");
955 HeapFree(PSDRV_Heap
, 0, page
->Name
);
956 HeapFree(PSDRV_Heap
, 0, page
->FullName
);
957 HeapFree(PSDRV_Heap
, 0, page
->InvocationString
);
958 HeapFree(PSDRV_Heap
, 0, page
->ImageableArea
);
959 HeapFree(PSDRV_Heap
, 0, page
->PaperDimension
);
960 list_remove(&page
->entry
);
964 ppd
->DefaultPageSize
= NULL
;
965 def_pagesize_override
= get_ppd_override( printer
, "DefaultPageSize" );
966 if (def_pagesize_override
)
967 ppd
->DefaultPageSize
= get_pagesize( ppd
, def_pagesize_override
, FALSE
);
968 if (!ppd
->DefaultPageSize
&& default_pagesize
)
969 ppd
->DefaultPageSize
= get_pagesize( ppd
, default_pagesize
, FALSE
);
971 if (!ppd
->DefaultPageSize
)
973 struct list
*head
= list_head( &ppd
->PageSizes
);
974 if (head
) ppd
->DefaultPageSize
= LIST_ENTRY( head
, PAGESIZE
, entry
);
975 TRACE("Setting DefaultPageSize to first in list\n");
977 TRACE( "DefaultPageSize: %s\n", ppd
->DefaultPageSize
? ppd
->DefaultPageSize
->Name
: "<not set>" );
979 HeapFree( PSDRV_Heap
, 0, def_pagesize_override
);
980 HeapFree( PSDRV_Heap
, 0, default_pagesize
);
982 ppd
->DefaultDuplex
= NULL
;
983 def_duplex_override
= get_ppd_override( printer
, "DefaultDuplex" );
984 if (def_duplex_override
)
985 ppd
->DefaultDuplex
= get_duplex( ppd
, def_duplex_override
);
986 if (!ppd
->DefaultDuplex
&& default_duplex
)
987 ppd
->DefaultDuplex
= get_duplex( ppd
, default_duplex
);
989 if (!ppd
->DefaultDuplex
)
991 struct list
*head
= list_head( &ppd
->Duplexes
);
992 if (head
) ppd
->DefaultDuplex
= LIST_ENTRY( head
, DUPLEX
, entry
);
993 TRACE("Setting DefaultDuplex to first in list\n");
995 TRACE( "DefaultDuplex: %s\n", ppd
->DefaultDuplex
? ppd
->DefaultDuplex
->Name
: "<not set>" );
997 HeapFree( PSDRV_Heap
, 0, def_duplex_override
);
998 HeapFree( PSDRV_Heap
, 0, default_duplex
);
1007 LIST_FOR_EACH_ENTRY( fn
, &ppd
->InstalledFonts
, FONTNAME
, entry
)
1008 TRACE("'%s'\n", fn
->Name
);
1010 LIST_FOR_EACH_ENTRY(page
, &ppd
->PageSizes
, PAGESIZE
, entry
) {
1011 TRACE("'%s' aka '%s' (%d) invoked by '%s'\n", page
->Name
,
1012 page
->FullName
, page
->WinPage
, page
->InvocationString
);
1013 if(page
->ImageableArea
)
1014 TRACE("Area = %.2f,%.2f - %.2f, %.2f\n",
1015 page
->ImageableArea
->llx
, page
->ImageableArea
->lly
,
1016 page
->ImageableArea
->urx
, page
->ImageableArea
->ury
);
1017 if(page
->PaperDimension
)
1018 TRACE("Dimension = %.2f x %.2f\n",
1019 page
->PaperDimension
->x
, page
->PaperDimension
->y
);
1022 LIST_FOR_EACH_ENTRY( con
, &ppd
->Constraints
, CONSTRAINT
, entry
)
1023 TRACE("CONSTRAINTS@ %s %s %s %s\n", con
->Feature1
,
1024 con
->Value1
, con
->Feature2
, con
->Value2
);
1026 LIST_FOR_EACH_ENTRY( slot
, &ppd
->InputSlots
, INPUTSLOT
, entry
)
1027 TRACE("INPUTSLOTS '%s' Name '%s' (%d) Invocation '%s'\n",
1028 debugstr_a(slot
->Name
), slot
->FullName
, slot
->WinBin
,
1029 debugstr_a(slot
->InvocationString
));