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
31 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(psdrv
);
46 const char *ptr
, *pos
, *end
;
49 /* map of page names in ppd file to Windows paper constants */
55 {"10x11", DMPAPER_10X11
},
56 {"10x14", DMPAPER_10X14
},
57 {"11x17", DMPAPER_11X17
}, /* not in Adobe PPD file spec */
58 {"12x11", DMPAPER_12X11
},
59 {"15x11", DMPAPER_15X11
},
60 {"9x11", DMPAPER_9X11
},
63 {"A3.Transverse", DMPAPER_A3_TRANSVERSE
},
64 {"A3Extra", DMPAPER_A3_EXTRA
},
65 {"A3Extra.Transverse", DMPAPER_A3_EXTRA_TRANSVERSE
},
66 {"A3Rotated", DMPAPER_A3_ROTATED
},
68 {"A4.Transverse", DMPAPER_A4_TRANSVERSE
},
69 {"A4Extra", DMPAPER_A4_EXTRA
},
70 {"A4Plus", DMPAPER_A4_PLUS
},
71 {"A4Rotated", DMPAPER_A4_ROTATED
},
72 {"A4Small", DMPAPER_A4SMALL
},
74 {"A5.Transverse", DMPAPER_A5_TRANSVERSE
},
75 {"A5Extra", DMPAPER_A5_EXTRA
},
76 {"A5Rotated", DMPAPER_A5_ROTATED
},
78 {"A6Rotated", DMPAPER_A6_ROTATED
},
79 {"ARCHC", DMPAPER_CSHEET
},
80 {"ARCHD", DMPAPER_DSHEET
},
81 {"ARCHE", DMPAPER_ESHEET
},
83 {"B4Rotated", DMPAPER_B4_JIS_ROTATED
},
85 {"B5.Transverse", DMPAPER_B5_TRANSVERSE
},
86 {"B5Rotated", DMPAPER_B5_JIS_ROTATED
},
87 {"B6", DMPAPER_B6_JIS
},
88 {"B6Rotated", DMPAPER_B6_JIS_ROTATED
},
89 {"C4", DMPAPER_ENV_C4
}, /* use EnvC4 */
90 {"C5", DMPAPER_ENV_C5
}, /* use EnvC5 */
91 {"C6", DMPAPER_ENV_C6
}, /* use EnvC6 */
92 {"Comm10", DMPAPER_ENV_10
}, /* use Env10 */
93 {"DL", DMPAPER_ENV_DL
}, /* use EnvDL */
94 {"DoublePostcard", DMPAPER_DBL_JAPANESE_POSTCARD
},
95 {"DoublePostcardRotated", DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED
},
96 {"Env10", DMPAPER_ENV_10
},
97 {"Env11", DMPAPER_ENV_11
},
98 {"Env12", DMPAPER_ENV_12
},
99 {"Env14", DMPAPER_ENV_14
},
100 {"Env9", DMPAPER_ENV_9
},
101 {"EnvC3", DMPAPER_ENV_C3
},
102 {"EnvC4", DMPAPER_ENV_C4
},
103 {"EnvC5", DMPAPER_ENV_C5
},
104 {"EnvC6", DMPAPER_ENV_C6
},
105 {"EnvC65", DMPAPER_ENV_C65
},
106 {"EnvChou3", DMPAPER_JENV_CHOU3
},
107 {"EnvChou3Rotated", DMPAPER_JENV_CHOU3_ROTATED
},
108 {"EnvChou4", DMPAPER_JENV_CHOU4
},
109 {"EnvChou4Rotated", DMPAPER_JENV_CHOU4_ROTATED
},
110 {"EnvDL", DMPAPER_ENV_DL
},
111 {"EnvISOB4", DMPAPER_ENV_B4
},
112 {"EnvISOB5", DMPAPER_ENV_B5
},
113 {"EnvISOB6", DMPAPER_ENV_B6
},
114 {"EnvInvite", DMPAPER_ENV_INVITE
},
115 {"EnvItalian", DMPAPER_ENV_ITALY
},
116 {"EnvKaku2", DMPAPER_JENV_KAKU2
},
117 {"EnvKaku2Rotated", DMPAPER_JENV_KAKU2_ROTATED
},
118 {"EnvKaku3", DMPAPER_JENV_KAKU3
},
119 {"EnvKaku3Rotated", DMPAPER_JENV_KAKU3_ROTATED
},
120 {"EnvMonarch", DMPAPER_ENV_MONARCH
},
121 {"EnvPRC1", DMPAPER_PENV_1
},
122 {"EnvPRC10", DMPAPER_PENV_10
},
123 {"EnvPRC10Rotated", DMPAPER_PENV_10_ROTATED
},
124 {"EnvPRC1Rotated", DMPAPER_PENV_1_ROTATED
},
125 {"EnvPRC2", DMPAPER_PENV_2
},
126 {"EnvPRC2Rotated", DMPAPER_PENV_2_ROTATED
},
127 {"EnvPRC3", DMPAPER_PENV_3
},
128 {"EnvPRC3Rotated", DMPAPER_PENV_3_ROTATED
},
129 {"EnvPRC4", DMPAPER_PENV_4
},
130 {"EnvPRC4Rotated", DMPAPER_PENV_4_ROTATED
},
131 {"EnvPRC5", DMPAPER_PENV_5
},
132 {"EnvPRC5Rotated", DMPAPER_PENV_5_ROTATED
},
133 {"EnvPRC6", DMPAPER_PENV_6
},
134 {"EnvPRC6Rotated", DMPAPER_PENV_6_ROTATED
},
135 {"EnvPRC7", DMPAPER_PENV_7
},
136 {"EnvPRC7Rotated", DMPAPER_PENV_7_ROTATED
},
137 {"EnvPRC8", DMPAPER_PENV_8
},
138 {"EnvPRC8Rotated", DMPAPER_PENV_8_ROTATED
},
139 {"EnvPRC9", DMPAPER_PENV_9
},
140 {"EnvPRC9Rotated", DMPAPER_PENV_9_ROTATED
},
141 {"EnvPersonal", DMPAPER_ENV_PERSONAL
},
142 {"EnvYou4", DMPAPER_JENV_YOU4
},
143 {"EnvYou4Rotated", DMPAPER_JENV_YOU4_ROTATED
},
144 {"Executive", DMPAPER_EXECUTIVE
},
145 {"FanFoldGerman", DMPAPER_FANFOLD_STD_GERMAN
},
146 {"FanFoldGermanLegal", DMPAPER_FANFOLD_LGL_GERMAN
},
147 {"FanFoldUS", DMPAPER_FANFOLD_US
},
148 {"Folio", DMPAPER_FOLIO
},
149 {"ISOB4", DMPAPER_ISO_B4
},
150 {"ISOB5Extra", DMPAPER_B5_EXTRA
},
151 {"Ledger", DMPAPER_LEDGER
},
152 {"Legal", DMPAPER_LEGAL
},
153 {"LegalExtra", DMPAPER_LEGAL_EXTRA
},
154 {"Letter", DMPAPER_LETTER
},
155 {"Letter.Transverse", DMPAPER_LETTER_TRANSVERSE
},
156 {"LetterExtra", DMPAPER_LETTER_EXTRA
},
157 {"LetterExtra.Transverse", DMPAPER_LETTER_EXTRA_TRANSVERSE
},
158 {"LetterPlus", DMPAPER_LETTER_PLUS
},
159 {"LetterRotated", DMPAPER_LETTER_ROTATED
},
160 {"LetterSmall", DMPAPER_LETTERSMALL
},
161 {"Monarch", DMPAPER_ENV_MONARCH
}, /* use EnvMonarch */
162 {"Note", DMPAPER_NOTE
},
163 {"PRC16K", DMPAPER_P16K
},
164 {"PRC16KRotated", DMPAPER_P16K_ROTATED
},
165 {"PRC32K", DMPAPER_P32K
},
166 {"PRC32KBig", DMPAPER_P32KBIG
},
167 {"PRC32KBigRotated", DMPAPER_P32KBIG_ROTATED
},
168 {"PRC32KRotated", DMPAPER_P32K_ROTATED
},
169 {"Postcard", DMPAPER_JAPANESE_POSTCARD
},
170 {"PostcardRotated", DMPAPER_JAPANESE_POSTCARD_ROTATED
},
171 {"Quarto", DMPAPER_QUARTO
},
172 {"Statement", DMPAPER_STATEMENT
},
173 {"SuperA", DMPAPER_A_PLUS
},
174 {"SuperB", DMPAPER_B_PLUS
},
175 {"Tabloid", DMPAPER_TABLOID
},
176 {"TabloidExtra", DMPAPER_TABLOID_EXTRA
},
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(const char *start
, PPDTuple
*tuple
)
244 end
= strpbrk(start
, "\r\n");
245 if(end
== start
) return FALSE
;
246 if(!end
) end
= start
+ strlen(start
);
247 buf
= HeapAlloc( PSDRV_Heap
, 0, end
- start
+ 1 );
248 memcpy(buf
, start
, end
- start
);
249 *(buf
+ (end
- start
)) = '\0';
250 tuple
->valtrans
= PSDRV_PPDDecodeHex(buf
);
251 HeapFree( PSDRV_Heap
, 0, buf
);
255 static BOOL
get_line( char *buf
, int size
, struct map_context
*ctx
)
258 if (ctx
->pos
> ctx
->end
) return FALSE
;
260 for (i
= 0; i
< size
- 1; i
++)
262 if (ctx
->pos
> ctx
->end
) break;
263 buf
[i
] = *ctx
->pos
++;
266 if (buf
[i
] == '\r' && ctx
->pos
<= ctx
->end
&& *ctx
->pos
== '\n')
272 if (buf
[i
] == '\n' || buf
[i
] == '\r')
282 /***********************************************************************
284 * PSDRV_PPDGetInvocationValue
286 * Passed string that should be surrounded by `"'s, return string allocated
289 static BOOL
PSDRV_PPDGetInvocationValue(struct map_context
*ctx
, PPDTuple
*tuple
)
292 char *buf
, line
[257];
294 assert( *ctx
->pos
== '"' );
297 for (start
= ctx
->pos
; ctx
->pos
<= ctx
->end
; ctx
->pos
++)
298 if (*ctx
->pos
== '"') break;
299 if (ctx
->pos
> ctx
->end
) return FALSE
;
302 buf
= HeapAlloc( PSDRV_Heap
, 0, ctx
->pos
- start
);
303 memcpy( buf
, start
, ctx
->pos
- start
- 1 );
304 buf
[ctx
->pos
- start
- 1] = '\0';
307 if (get_line( line
, sizeof(line
), ctx
))
309 start
= strchr( line
, '/' );
310 if (start
) return PSDRV_PPDGetTransValue( start
+ 1, tuple
);
316 /***********************************************************************
318 * PSDRV_PPDGetQuotedValue
320 * Passed string that should be surrounded by `"'s. Expand <xx> as hex
321 * return string allocated from process heap.
323 static BOOL
PSDRV_PPDGetQuotedValue(struct map_context
*ctx
, PPDTuple
*tuple
)
327 if(!PSDRV_PPDGetInvocationValue(ctx
, tuple
))
329 buf
= PSDRV_PPDDecodeHex(tuple
->value
);
330 HeapFree(PSDRV_Heap
, 0, tuple
->value
);
336 /***********************************************************************
338 * PSDRV_PPDGetStringValue
340 * Just strip leading white space.
342 static BOOL
PSDRV_PPDGetStringValue(char *str
, PPDTuple
*tuple
)
344 char *start
= str
, *end
;
346 while(*start
!= '\0' && isspace(*start
))
349 end
= strpbrk(start
, "/\r\n");
350 if(!end
) end
= start
+ strlen(start
);
351 tuple
->value
= HeapAlloc( PSDRV_Heap
, 0, (end
- start
) + 1 );
352 memcpy(tuple
->value
, start
, end
- start
);
353 *(tuple
->value
+ (end
- start
)) = '\0';
355 PSDRV_PPDGetTransValue(end
+ 1, tuple
);
360 /***********************************************************************
362 * PSDRV_PPDSymbolValue
364 * Not implemented yet.
366 static BOOL
PSDRV_PPDGetSymbolValue(char *pos
, PPDTuple
*tuple
)
373 /*********************************************************************
375 * PSDRV_PPDGetNextTuple
377 * Gets the next Keyword Option Value tuple from the file. Allocs space off
378 * the process heap which should be free()ed by the caller if not needed.
380 static BOOL
PSDRV_PPDGetNextTuple(struct map_context
*ctx
, PPDTuple
*tuple
)
382 char line
[257], *opt
, *cp
, *trans
, *endkey
;
384 struct map_context save
;
390 memset(tuple
, 0, sizeof(*tuple
));
394 if(!get_line(line
, sizeof(line
), ctx
))
396 if(line
[0] == '*' && line
[1] != '%' && strncmp(line
, "*End", 4))
400 cp
= line
+ strlen(line
) - 1;
401 if (*cp
!= '\n' && *cp
!= '\r')
403 ERR("Line too long.\n");
407 for(cp
= line
; !isspace(*cp
) && *cp
!= ':'; cp
++)
411 while (isspace(*cp
)) cp
++;
412 if (*cp
== ':') /* <key>: */
414 else /* <key> <option> */
417 tuple
->key
= HeapAlloc( PSDRV_Heap
, 0, endkey
- line
+ 1 );
418 if(!tuple
->key
) return FALSE
;
420 memcpy(tuple
->key
, line
, endkey
- line
);
421 tuple
->key
[endkey
- line
] = '\0';
423 if(gotoption
) { /* opt points to 1st non-space character of the option */
424 cp
= strpbrk(opt
, ":/");
426 ERR("Error in line '%s'?\n", line
);
427 HeapFree(GetProcessHeap(), 0, tuple
->key
);
430 tuple
->option
= HeapAlloc( PSDRV_Heap
, 0, cp
- opt
+ 1 );
431 if(!tuple
->option
) return FALSE
;
432 memcpy(tuple
->option
, opt
, cp
- opt
);
433 tuple
->option
[cp
- opt
] = '\0';
437 cp
= strchr(trans
, ':');
439 ERR("Error in line '%s'?\n", line
);
440 HeapFree(GetProcessHeap(), 0, tuple
->option
);
441 HeapFree(GetProcessHeap(), 0, tuple
->key
);
444 buf
= HeapAlloc( PSDRV_Heap
, 0, cp
- trans
+ 1 );
445 if(!buf
) return FALSE
;
446 memcpy(buf
, trans
, cp
- trans
);
447 buf
[cp
- trans
] = '\0';
448 tuple
->opttrans
= PSDRV_PPDDecodeHex(buf
);
449 HeapFree( PSDRV_Heap
, 0, buf
);
453 /* cp should point to a ':', so we increment past it */
461 /* update the context pos so that it points to the opening quote */
462 ctx
->pos
= save
.pos
+ (cp
- line
);
463 if( (!gotoption
&& strncmp(tuple
->key
, "*?", 2) ) ||
464 !strncmp(tuple
->key
, "*JCL", 4))
465 PSDRV_PPDGetQuotedValue(ctx
, tuple
);
467 PSDRV_PPDGetInvocationValue(ctx
, tuple
);
471 PSDRV_PPDGetSymbolValue(cp
, tuple
);
475 PSDRV_PPDGetStringValue(cp
, tuple
);
480 /*********************************************************************
483 * Searches ppd PageSize list to return entry matching name or optionally creates new
484 * entry which is appended to the list if name is not found.
486 static PAGESIZE
*get_pagesize( PPD
*ppd
, char *name
, BOOL create
)
490 LIST_FOR_EACH_ENTRY(page
, &ppd
->PageSizes
, PAGESIZE
, entry
)
492 if(!strcmp(page
->Name
, name
))
496 if (!create
) return NULL
;
498 page
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*page
) );
499 list_add_tail(&ppd
->PageSizes
, &page
->entry
);
503 static DUPLEX
*get_duplex( PPD
*ppd
, const char *name
)
507 LIST_FOR_EACH_ENTRY( duplex
, &ppd
->Duplexes
, DUPLEX
, entry
)
509 if (!strcmp( duplex
->Name
, name
))
516 /**********************************************************************
520 * Returns ptr allocated from heap to first word in str. Strips leading spaces.
521 * Puts ptr to next word in next
523 static char *PSDRV_PPDGetWord(char *str
, char **next
)
525 char *start
, *end
, *ret
;
528 while(start
&& *start
&& isspace(*start
))
530 if(!start
|| !*start
) return FALSE
;
533 while(*end
&& !isspace(*end
))
536 ret
= HeapAlloc( PSDRV_Heap
, 0, end
- start
+ 1 );
537 memcpy(ret
, start
, end
- start
);
538 *(ret
+ (end
- start
)) = '\0';
540 while(*end
&& isspace(*end
))
550 /************************************************************
553 * Helper to extract x and y resolutions from a resolution entry.
554 * Returns TRUE on successful parsing, otherwise FALSE.
556 * The ppd spec says that entries can either be:
560 * in the former case return sz.cx == cx.cy == nnn.
562 * There are broken ppd files out there (notably from Samsung) that
563 * use the form "nnnmmmdpi", so we have to work harder to spot these.
564 * We use a transition from a zero to a non-zero digit as separator
565 * (and fail if we find more than one of these). We also don't bother
566 * trying to parse "dpi" in case that's missing.
568 static BOOL
parse_resolution(const char *str
, SIZE
*sz
)
575 if(sscanf(str
, "%dx%d", tmp
, tmp
+ 1) == 2)
586 for(c
= str
; isdigit(*c
); c
++)
588 if(!had_zero
|| *c
== '0')
604 if(tmp
[0] == 0) return FALSE
;
614 /*******************************************************************************
618 static BOOL
PSDRV_AddSlot(PPD
*ppd
, LPCSTR szName
, LPCSTR szFullName
,
619 LPSTR szInvocationString
, WORD wWinBin
)
621 INPUTSLOT
*slot
= HeapAlloc( PSDRV_Heap
, 0, sizeof(INPUTSLOT
) );
622 if (!slot
) return FALSE
;
625 slot
->FullName
= szFullName
;
626 slot
->InvocationString
= szInvocationString
;
627 slot
->WinBin
= wWinBin
;
629 list_add_tail( &ppd
->InputSlots
, &slot
->entry
);
633 static char *get_ppd_override( HANDLE printer
, const char *value
)
635 DWORD err
, type
, needed
;
638 err
= GetPrinterDataExA( printer
, "PPD Overrides", value
, &type
, NULL
, 0, &needed
);
639 if (err
!= ERROR_MORE_DATA
|| type
!= REG_SZ
|| needed
== 0) return NULL
;
641 data
= HeapAlloc( PSDRV_Heap
, 0, needed
);
644 GetPrinterDataExA( printer
, "PPD Overrides", value
, &type
, (BYTE
*)data
, needed
, &needed
);
645 TRACE( "got override %s: %s\n", value
, data
);
650 static BOOL
map_file( const WCHAR
*filename
, struct map_context
*c
)
652 HANDLE file
, mapping
;
655 file
= CreateFileW( filename
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
656 if (file
== INVALID_HANDLE_VALUE
) return FALSE
;
658 if (!GetFileSizeEx( file
, &size
) || size
.u
.HighPart
)
664 mapping
= CreateFileMappingW( file
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
666 if (!mapping
) return FALSE
;
668 c
->pos
= c
->ptr
= MapViewOfFile( mapping
, FILE_MAP_READ
, 0, 0, 0 );
669 c
->end
= c
->ptr
+ size
.u
.LowPart
- 1;
670 CloseHandle( mapping
);
674 static void unmap_file( struct map_context
*c
)
676 UnmapViewOfFile( c
->ptr
);
679 /***********************************************************************
685 PPD
*PSDRV_ParsePPD( const WCHAR
*fname
, HANDLE printer
)
689 char *default_pagesize
= NULL
, *default_duplex
= NULL
;
690 char *def_pagesize_override
= NULL
, *def_duplex_override
= NULL
;
691 PAGESIZE
*page
, *page_cursor2
;
692 struct map_context c
;
693 WORD UserPageType
= DMPAPER_USER
;
694 WORD UserBinType
= DMBIN_USER
;
696 TRACE("file %s\n", debugstr_w(fname
));
698 if (!map_file( fname
, &c
))
700 WARN("Couldn't open ppd file %s\n", debugstr_w(fname
));
704 ppd
= HeapAlloc( PSDRV_Heap
, HEAP_ZERO_MEMORY
, sizeof(*ppd
));
706 ERR("Unable to allocate memory for ppd\n");
711 ppd
->ColorDevice
= CD_NotSpecified
;
713 list_init( &ppd
->Resolutions
);
714 list_init( &ppd
->InstalledFonts
);
715 list_init( &ppd
->PageSizes
);
716 list_init( &ppd
->Constraints
);
717 list_init( &ppd
->InputSlots
);
718 list_init( &ppd
->Duplexes
);
720 /* Some gimp-print ppd files don't contain a DefaultResolution line
722 ppd
->DefaultResolution
= 300;
725 * The Windows PostScript drivers create the following "virtual bin" for
726 * every PostScript printer
728 if (!PSDRV_AddSlot( ppd
, NULL
, "Automatically Select", NULL
, DMBIN_FORMSOURCE
))
730 HeapFree (PSDRV_Heap
, 0, ppd
);
735 while (PSDRV_PPDGetNextTuple( &c
, &tuple
))
737 if(!strcmp("*NickName", tuple
.key
)) {
738 ppd
->NickName
= tuple
.value
;
740 TRACE("NickName = '%s'\n", ppd
->NickName
);
743 else if(!strcmp("*LanguageLevel", tuple
.key
)) {
744 sscanf(tuple
.value
, "%d", &(ppd
->LanguageLevel
));
745 TRACE("LanguageLevel = %d\n", ppd
->LanguageLevel
);
748 else if(!strcmp("*ColorDevice", tuple
.key
)) {
749 if(!stricmp(tuple
.value
, "true"))
750 ppd
->ColorDevice
= CD_True
;
752 ppd
->ColorDevice
= CD_False
;
753 TRACE("ColorDevice = %s\n", ppd
->ColorDevice
== CD_True
? "True" : "False");
756 else if((!strcmp("*DefaultResolution", tuple
.key
)) ||
757 (!strcmp("*DefaultJCLResolution", tuple
.key
))) {
759 if(parse_resolution(tuple
.value
, &sz
))
761 TRACE("DefaultResolution %ldx%ld\n", sz
.cx
, sz
.cy
);
762 ppd
->DefaultResolution
= sz
.cx
;
765 WARN("failed to parse DefaultResolution %s\n", debugstr_a(tuple
.value
));
768 else if(!strcmp("*Resolution", tuple
.key
))
771 if (parse_resolution(tuple
.option
, &sz
))
775 TRACE("Resolution %ldx%ld, invocation %s\n", sz
.cx
, sz
.cy
, tuple
.value
);
777 res
= HeapAlloc( GetProcessHeap(), 0, sizeof(*res
) );
780 res
->InvocationString
= tuple
.value
;
782 list_add_tail( &ppd
->Resolutions
, &res
->entry
);
785 WARN("failed to parse Resolution %s\n", debugstr_a(tuple
.option
));
788 else if(!strcmp("*Font", tuple
.key
))
790 FONTNAME
*fn
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*fn
) );
791 fn
->Name
= tuple
.option
;
793 list_add_tail( &ppd
->InstalledFonts
, &fn
->entry
);
796 else if(!strcmp("*DefaultFont", tuple
.key
)) {
797 ppd
->DefaultFont
= tuple
.value
;
801 else if(!strcmp("*JCLBegin", tuple
.key
)) {
802 ppd
->JCLBegin
= tuple
.value
;
806 else if(!strcmp("*JCLToPSInterpreter", tuple
.key
)) {
807 ppd
->JCLToPSInterpreter
= tuple
.value
;
811 else if(!strcmp("*JCLEnd", tuple
.key
)) {
812 ppd
->JCLEnd
= tuple
.value
;
816 else if(!strcmp("*PageSize", tuple
.key
))
818 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
821 page
->Name
= tuple
.option
;
824 if(!page
->FullName
) {
826 page
->FullName
= tuple
.opttrans
;
827 tuple
.opttrans
= NULL
;
830 page
->FullName
= HeapAlloc( PSDRV_Heap
, 0, strlen(page
->Name
)+1 );
831 strcpy( page
->FullName
, page
->Name
);
834 if(!page
->InvocationString
) {
835 page
->InvocationString
= tuple
.value
;
841 for (i
= 0; PageTrans
[i
].PSName
; i
++)
843 if (!strcmp( PageTrans
[i
].PSName
, page
->Name
))
845 page
->WinPage
= PageTrans
[i
].WinPage
;
851 TRACE( "Can't find Windows page type for %s - using %u\n", debugstr_a(page
->Name
), UserPageType
);
852 page
->WinPage
= UserPageType
++;
857 else if(!strcmp("*DefaultPageSize", tuple
.key
))
859 if (!default_pagesize
)
861 default_pagesize
= tuple
.value
;
866 else if(!strcmp("*ImageableArea", tuple
.key
)) {
867 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
870 page
->Name
= tuple
.option
;
873 if(!page
->FullName
) {
874 page
->FullName
= tuple
.opttrans
;
875 tuple
.opttrans
= NULL
;
878 #define PIA page->ImageableArea
880 PIA
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*PIA
) );
881 push_lc_numeric("C");
882 sscanf(tuple
.value
, "%f%f%f%f", &PIA
->llx
, &PIA
->lly
,
883 &PIA
->urx
, &PIA
->ury
);
889 else if(!strcmp("*PaperDimension", tuple
.key
)) {
890 page
= get_pagesize( ppd
, tuple
.option
, TRUE
);
893 page
->Name
= tuple
.option
;
896 if(!page
->FullName
) {
897 page
->FullName
= tuple
.opttrans
;
898 tuple
.opttrans
= NULL
;
901 #define PD page->PaperDimension
903 PD
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*PD
) );
904 push_lc_numeric("C");
905 sscanf(tuple
.value
, "%f%f", &PD
->x
, &PD
->y
);
911 else if(!strcmp("*LandscapeOrientation", tuple
.key
)) {
912 if(!strcmp(tuple
.value
, "Plus90"))
913 ppd
->LandscapeOrientation
= 90;
914 else if(!strcmp(tuple
.value
, "Minus90"))
915 ppd
->LandscapeOrientation
= -90;
917 /* anything else, namely 'any', leaves value at 0 */
919 TRACE("LandscapeOrientation = %d\n",
920 ppd
->LandscapeOrientation
);
923 else if(!strcmp("*UIConstraints", tuple
.key
))
926 CONSTRAINT
*con
= HeapAlloc( PSDRV_Heap
, 0, sizeof(*con
) );
929 con
->Feature1
= PSDRV_PPDGetWord(start
, &start
);
930 con
->Value1
= PSDRV_PPDGetWord(start
, &start
);
931 con
->Feature2
= PSDRV_PPDGetWord(start
, &start
);
932 con
->Value2
= PSDRV_PPDGetWord(start
, &start
);
934 list_add_tail( &ppd
->Constraints
, &con
->entry
);
937 else if (!strcmp("*InputSlot", tuple
.key
))
941 tuple
.opttrans
= tuple
.option
;
943 TRACE("Using Windows bin type %u for '%s'\n", UserBinType
,
946 /* FIXME - should check for failure */
947 PSDRV_AddSlot(ppd
, tuple
.option
, tuple
.opttrans
, tuple
.value
,
950 tuple
.option
= tuple
.opttrans
= tuple
.value
= NULL
;
954 * Windows treats "manual feed" as another paper source. Most PPD
955 * files, however, treat it as a separate option which is either on or
958 else if (!strcmp("*ManualFeed", tuple
.key
) && tuple
.option
&&
959 !strcmp ("True", tuple
.option
))
961 /* FIXME - should check for failure */
962 PSDRV_AddSlot(ppd
, "Manual Feed", "Manual Feed", tuple
.value
, DMBIN_MANUAL
);
966 else if(!strcmp("*TTRasterizer", tuple
.key
)) {
967 if(!stricmp("None", tuple
.value
))
968 ppd
->TTRasterizer
= RO_None
;
969 else if(!stricmp("Accept68K", tuple
.value
))
970 ppd
->TTRasterizer
= RO_Accept68K
;
971 else if(!stricmp("Type42", tuple
.value
))
972 ppd
->TTRasterizer
= RO_Type42
;
973 else if(!stricmp("TrueImage", tuple
.value
))
974 ppd
->TTRasterizer
= RO_TrueImage
;
976 FIXME("Unknown option %s for *TTRasterizer\n",
978 ppd
->TTRasterizer
= RO_None
;
980 TRACE("*TTRasterizer = %d\n", ppd
->TTRasterizer
);
983 else if(!strcmp("*Duplex", tuple
.key
))
985 DUPLEX
*duplex
= HeapAlloc( GetProcessHeap(), 0, sizeof(*duplex
) );
986 duplex
->Name
= tuple
.option
;
987 duplex
->FullName
= tuple
.opttrans
;
988 duplex
->InvocationString
= tuple
.value
;
989 if(!stricmp("None", tuple
.option
) || !stricmp("False", tuple
.option
)
990 || !stricmp("Simplex", tuple
.option
))
991 duplex
->WinDuplex
= DMDUP_SIMPLEX
;
992 else if(!stricmp("DuplexNoTumble", tuple
.option
))
993 duplex
->WinDuplex
= DMDUP_VERTICAL
;
994 else if(!stricmp("DuplexTumble", tuple
.option
))
995 duplex
->WinDuplex
= DMDUP_HORIZONTAL
;
996 else if(!stricmp("Notcapable", tuple
.option
))
997 duplex
->WinDuplex
= 0;
999 FIXME("Unknown option %s for *Duplex defaulting to simplex\n", tuple
.option
);
1000 duplex
->WinDuplex
= DMDUP_SIMPLEX
;
1002 tuple
.option
= tuple
.opttrans
= tuple
.value
= NULL
;
1003 list_add_tail( &ppd
->Duplexes
, &duplex
->entry
);
1006 else if (!strcmp("*DefaultDuplex", tuple
.key
))
1008 if (!default_duplex
)
1010 default_duplex
= tuple
.value
;
1015 HeapFree(PSDRV_Heap
, 0, tuple
.key
);
1016 HeapFree(PSDRV_Heap
, 0, tuple
.option
);
1017 HeapFree(PSDRV_Heap
, 0, tuple
.value
);
1018 HeapFree(PSDRV_Heap
, 0, tuple
.opttrans
);
1019 HeapFree(PSDRV_Heap
, 0, tuple
.valtrans
);
1023 /* Remove any partial page size entries, that is any without a PageSize or a PaperDimension (we can
1024 cope with a missing ImageableArea). */
1025 LIST_FOR_EACH_ENTRY_SAFE(page
, page_cursor2
, &ppd
->PageSizes
, PAGESIZE
, entry
)
1027 if(!page
->InvocationString
|| !page
->PaperDimension
)
1029 WARN("Removing page %s since it has a missing %s entry\n", debugstr_a(page
->FullName
),
1030 page
->InvocationString
? "PaperDimension" : "InvocationString");
1031 HeapFree(PSDRV_Heap
, 0, page
->Name
);
1032 HeapFree(PSDRV_Heap
, 0, page
->FullName
);
1033 HeapFree(PSDRV_Heap
, 0, page
->InvocationString
);
1034 HeapFree(PSDRV_Heap
, 0, page
->ImageableArea
);
1035 HeapFree(PSDRV_Heap
, 0, page
->PaperDimension
);
1036 list_remove(&page
->entry
);
1040 ppd
->DefaultPageSize
= NULL
;
1041 def_pagesize_override
= get_ppd_override( printer
, "DefaultPageSize" );
1042 if (def_pagesize_override
)
1043 ppd
->DefaultPageSize
= get_pagesize( ppd
, def_pagesize_override
, FALSE
);
1044 if (!ppd
->DefaultPageSize
&& default_pagesize
)
1045 ppd
->DefaultPageSize
= get_pagesize( ppd
, default_pagesize
, FALSE
);
1047 if (!ppd
->DefaultPageSize
)
1049 struct list
*head
= list_head( &ppd
->PageSizes
);
1050 if (head
) ppd
->DefaultPageSize
= LIST_ENTRY( head
, PAGESIZE
, entry
);
1051 TRACE("Setting DefaultPageSize to first in list\n");
1053 TRACE( "DefaultPageSize: %s\n", ppd
->DefaultPageSize
? ppd
->DefaultPageSize
->Name
: "<not set>" );
1055 HeapFree( PSDRV_Heap
, 0, def_pagesize_override
);
1056 HeapFree( PSDRV_Heap
, 0, default_pagesize
);
1058 ppd
->DefaultDuplex
= NULL
;
1059 def_duplex_override
= get_ppd_override( printer
, "DefaultDuplex" );
1060 if (def_duplex_override
)
1061 ppd
->DefaultDuplex
= get_duplex( ppd
, def_duplex_override
);
1062 if (!ppd
->DefaultDuplex
&& default_duplex
)
1063 ppd
->DefaultDuplex
= get_duplex( ppd
, default_duplex
);
1065 if (!ppd
->DefaultDuplex
)
1067 struct list
*head
= list_head( &ppd
->Duplexes
);
1068 if (head
) ppd
->DefaultDuplex
= LIST_ENTRY( head
, DUPLEX
, entry
);
1069 TRACE("Setting DefaultDuplex to first in list\n");
1071 TRACE( "DefaultDuplex: %s\n", ppd
->DefaultDuplex
? ppd
->DefaultDuplex
->Name
: "<not set>" );
1073 HeapFree( PSDRV_Heap
, 0, def_duplex_override
);
1074 HeapFree( PSDRV_Heap
, 0, default_duplex
);
1083 LIST_FOR_EACH_ENTRY( fn
, &ppd
->InstalledFonts
, FONTNAME
, entry
)
1084 TRACE("'%s'\n", fn
->Name
);
1086 LIST_FOR_EACH_ENTRY(page
, &ppd
->PageSizes
, PAGESIZE
, entry
) {
1087 TRACE("'%s' aka '%s' (%d) invoked by '%s'\n", page
->Name
,
1088 page
->FullName
, page
->WinPage
, page
->InvocationString
);
1089 if(page
->ImageableArea
)
1090 TRACE("Area = %.2f,%.2f - %.2f, %.2f\n",
1091 page
->ImageableArea
->llx
, page
->ImageableArea
->lly
,
1092 page
->ImageableArea
->urx
, page
->ImageableArea
->ury
);
1093 if(page
->PaperDimension
)
1094 TRACE("Dimension = %.2f x %.2f\n",
1095 page
->PaperDimension
->x
, page
->PaperDimension
->y
);
1098 LIST_FOR_EACH_ENTRY( con
, &ppd
->Constraints
, CONSTRAINT
, entry
)
1099 TRACE("CONSTRAINTS@ %s %s %s %s\n", con
->Feature1
,
1100 con
->Value1
, con
->Feature2
, con
->Value2
);
1102 LIST_FOR_EACH_ENTRY( slot
, &ppd
->InputSlots
, INPUTSLOT
, entry
)
1103 TRACE("INPUTSLOTS '%s' Name '%s' (%d) Invocation '%s'\n",
1104 debugstr_a(slot
->Name
), slot
->FullName
, slot
->WinBin
,
1105 debugstr_a(slot
->InvocationString
));