|
34 | 34 | * Local functions... |
35 | 35 | */ |
36 | 36 |
|
| 37 | +static void add_ppd_defaults_to_ipp(cupsd_printer_t *p, ppd_file_t *ppd); |
37 | 38 | static void add_printer_defaults(cupsd_printer_t *p); |
38 | 39 | static void add_printer_filter(cupsd_printer_t *p, mime_type_t *type, |
39 | 40 | const char *filter); |
@@ -3376,6 +3377,185 @@ add_printer_defaults(cupsd_printer_t *p)/* I - Printer */ |
3376 | 3377 | } |
3377 | 3378 |
|
3378 | 3379 |
|
| 3380 | +/* |
| 3381 | + * 'add_ppd_defaults_to_ipp()' - Map PPD option defaults to IPP "-default" attributes. |
| 3382 | + */ |
| 3383 | + |
| 3384 | +static void |
| 3385 | +add_ppd_defaults_to_ipp(cupsd_printer_t *p, /* I - Printer */ |
| 3386 | + ppd_file_t *ppd) /* I - PPD file */ |
| 3387 | +{ |
| 3388 | + ppd_option_t *option; /* Current PPD option */ |
| 3389 | + ppd_group_t *group; /* Current PPD group */ |
| 3390 | + const char *ipp_name; /* IPP attribute name */ |
| 3391 | + const char *ipp_value; /* IPP attribute value */ |
| 3392 | + const char *mapped_value; /* Mapped IPP attribute value */ |
| 3393 | + char attr_name[256]; /* Attribute name buffer */ |
| 3394 | + int i; /* Looping var */ |
| 3395 | + |
| 3396 | + |
| 3397 | + /* |
| 3398 | + * Skip if no PPD or PPD cache... |
| 3399 | + */ |
| 3400 | + |
| 3401 | + if (!ppd || !p->pc) |
| 3402 | + return; |
| 3403 | + |
| 3404 | + /* |
| 3405 | + * Loop through all PPD options and map their defaults to IPP attributes... |
| 3406 | + */ |
| 3407 | + |
| 3408 | + for (group = ppd->groups; group; group = group->next) |
| 3409 | + { |
| 3410 | + for (option = (ppd_option_t *)cupsArrayFirst(group->options); |
| 3411 | + option; |
| 3412 | + option = (ppd_option_t *)cupsArrayNext(group->options)) |
| 3413 | + { |
| 3414 | + /* |
| 3415 | + * Skip if no default choice... |
| 3416 | + */ |
| 3417 | + |
| 3418 | + if (!option->defchoice || !option->defchoice[0]) |
| 3419 | + continue; |
| 3420 | + |
| 3421 | + /* |
| 3422 | + * Skip options that are already explicitly handled... |
| 3423 | + */ |
| 3424 | + |
| 3425 | + if (!strcmp(option->keyword, "PageSize") || |
| 3426 | + !strcmp(option->keyword, "PageRegion") || |
| 3427 | + !strcmp(option->keyword, "ColorModel") || |
| 3428 | + !strcmp(option->keyword, "HPColorMode") || |
| 3429 | + !strcmp(option->keyword, "BRMonoColor") || |
| 3430 | + !strcmp(option->keyword, "CNIJSGrayScale") || |
| 3431 | + !strcmp(option->keyword, "HPColorAsGray") || |
| 3432 | + !strcmp(option->keyword, "Resolution") || |
| 3433 | + !strcmp(option->keyword, "JCLResolution") || |
| 3434 | + !strcmp(option->keyword, "SetResolution") || |
| 3435 | + !strcmp(option->keyword, "CNRes_PGP") || |
| 3436 | + !strcmp(option->keyword, "Duplex") || |
| 3437 | + !strcmp(option->keyword, "EFDuplex") || |
| 3438 | + !strcmp(option->keyword, "EFDuplexing") || |
| 3439 | + !strcmp(option->keyword, "KD03Duplex") || |
| 3440 | + !strcmp(option->keyword, "JCLDuplex") || |
| 3441 | + !strcmp(option->keyword, "OutputBin") || |
| 3442 | + !strcmp(option->keyword, "InputSlot") || |
| 3443 | + !strcmp(option->keyword, "HPPaperSource") || |
| 3444 | + !strcmp(option->keyword, "MediaType") || |
| 3445 | + !strcmp(option->keyword, "DefaultMediaType") || |
| 3446 | + !strcmp(option->keyword, "DefaultInputSlot")) |
| 3447 | + continue; |
| 3448 | + |
| 3449 | + /* |
| 3450 | + * Map PPD option names to IPP attribute names... |
| 3451 | + */ |
| 3452 | + |
| 3453 | + ipp_name = NULL; |
| 3454 | + ipp_value = option->defchoice; |
| 3455 | + mapped_value = ipp_value; |
| 3456 | + |
| 3457 | + if (!strcmp(option->keyword, "OutputOrder")) |
| 3458 | + ipp_name = "output-order"; |
| 3459 | + else if (!strcmp(option->keyword, "Collate")) |
| 3460 | + { |
| 3461 | + ipp_name = "multiple-document-handling"; |
| 3462 | + /* |
| 3463 | + * Map Collate values to IPP multiple-document-handling values... |
| 3464 | + */ |
| 3465 | + if (!_cups_strcasecmp(ipp_value, "True") || |
| 3466 | + !_cups_strcasecmp(ipp_value, "On") || |
| 3467 | + !_cups_strcasecmp(ipp_value, "Yes")) |
| 3468 | + { |
| 3469 | + mapped_value = "separate-documents-collated-copies"; |
| 3470 | + } |
| 3471 | + else |
| 3472 | + { |
| 3473 | + mapped_value = "separate-documents-uncollated-copies"; |
| 3474 | + } |
| 3475 | + } |
| 3476 | + else if (!strcmp(option->keyword, "cupsPrintQuality") || |
| 3477 | + !strcmp(option->keyword, "OutputMode")) |
| 3478 | + { |
| 3479 | + ipp_name = "print-quality"; |
| 3480 | + /* |
| 3481 | + * Map quality names to IPP enum values... |
| 3482 | + */ |
| 3483 | + if (!_cups_strcasecmp(ipp_value, "draft") || |
| 3484 | + !_cups_strcasecmp(ipp_value, "fast")) |
| 3485 | + { |
| 3486 | + if (!ippFindAttribute(p->attrs, "print-quality-default", IPP_TAG_ZERO)) |
| 3487 | + ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "print-quality-default", IPP_QUALITY_DRAFT); |
| 3488 | + } |
| 3489 | + else if (!_cups_strcasecmp(ipp_value, "best") || |
| 3490 | + !_cups_strcasecmp(ipp_value, "high")) |
| 3491 | + { |
| 3492 | + if (!ippFindAttribute(p->attrs, "print-quality-default", IPP_TAG_ZERO)) |
| 3493 | + ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "print-quality-default", IPP_QUALITY_HIGH); |
| 3494 | + } |
| 3495 | + else |
| 3496 | + { |
| 3497 | + if (!ippFindAttribute(p->attrs, "print-quality-default", IPP_TAG_ZERO)) |
| 3498 | + ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM, "print-quality-default", IPP_QUALITY_NORMAL); |
| 3499 | + } |
| 3500 | + continue; |
| 3501 | + } |
| 3502 | + else |
| 3503 | + { |
| 3504 | + /* |
| 3505 | + * For other options, convert the option name to lowercase with dashes |
| 3506 | + * and append "-default"... |
| 3507 | + */ |
| 3508 | + |
| 3509 | + snprintf(attr_name, sizeof(attr_name), "%s-default", option->keyword); |
| 3510 | + for (i = 0; attr_name[i]; i ++) |
| 3511 | + { |
| 3512 | + if (attr_name[i] >= 'A' && attr_name[i] <= 'Z') |
| 3513 | + attr_name[i] = (char)(attr_name[i] | 32); /* tolower */ |
| 3514 | + else if (attr_name[i] == '_') |
| 3515 | + attr_name[i] = '-'; |
| 3516 | + } |
| 3517 | + |
| 3518 | + ipp_name = attr_name; |
| 3519 | + } |
| 3520 | + |
| 3521 | + /* |
| 3522 | + * Skip if we already have this attribute... |
| 3523 | + */ |
| 3524 | + |
| 3525 | + if (ippFindAttribute(p->attrs, ipp_name, IPP_TAG_ZERO)) |
| 3526 | + continue; |
| 3527 | + |
| 3528 | + /* |
| 3529 | + * Add the IPP "-default" attribute... |
| 3530 | + */ |
| 3531 | + |
| 3532 | + if (ipp_name && mapped_value) |
| 3533 | + { |
| 3534 | + /* |
| 3535 | + * For boolean options, convert to boolean... |
| 3536 | + */ |
| 3537 | + |
| 3538 | + if (option->ui == PPD_UI_BOOLEAN) |
| 3539 | + { |
| 3540 | + ippAddBoolean(p->attrs, IPP_TAG_PRINTER, ipp_name, |
| 3541 | + !_cups_strcasecmp(mapped_value, "True") || |
| 3542 | + !_cups_strcasecmp(mapped_value, "On") || |
| 3543 | + !_cups_strcasecmp(mapped_value, "Yes")); |
| 3544 | + } |
| 3545 | + else |
| 3546 | + { |
| 3547 | + /* |
| 3548 | + * For other options, add as string/keyword... |
| 3549 | + */ |
| 3550 | + |
| 3551 | + ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, ipp_name, NULL, mapped_value); |
| 3552 | + } |
| 3553 | + } |
| 3554 | + } |
| 3555 | + } |
| 3556 | +} |
| 3557 | + |
| 3558 | + |
3379 | 3559 | /* |
3380 | 3560 | * 'add_printer_filter()' - Add a MIME filter for a printer. |
3381 | 3561 | */ |
@@ -5271,6 +5451,12 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ |
5271 | 5451 | } |
5272 | 5452 | #endif /* HAVE_APPLICATIONSERVICES_H */ |
5273 | 5453 |
|
| 5454 | + /* |
| 5455 | + * Map PPD defaults to IPP "-default" attributes... |
| 5456 | + */ |
| 5457 | + |
| 5458 | + add_ppd_defaults_to_ipp(p, ppd); |
| 5459 | + |
5274 | 5460 | /* |
5275 | 5461 | * Close the PPD and set the type... |
5276 | 5462 | */ |
|
0 commit comments