From: Michael R Sweet Date: Tue, 27 May 2025 18:55:47 +0000 (-0400) Subject: Update PPD cache private API to support getting custom size names (Issue #1238) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=46c58ec47d3c176a1d665f10a2e9b2681e85f27e;p=thirdparty%2Fcups.git Update PPD cache private API to support getting custom size names (Issue #1238) --- diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 61e63ae1c8..eb7b411b5e 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -209,7 +209,7 @@ _cupsConvertOptions( media_source = _ppdCacheGetSource(pc, cupsGetOption("InputSlot", num_options, options)); media_type = _ppdCacheGetType(pc, cupsGetOption("MediaType", num_options, options)); - size = _ppdCacheGetSize(pc, keyword); + size = _ppdCacheGetSize(pc, keyword, /*ppd_size*/NULL); if (media_col_sup && (size || media_source || media_type)) { @@ -2760,7 +2760,8 @@ _ppdCacheGetPageSize( pwg_size_t * /* O - PWG size or NULL */ _ppdCacheGetSize( _ppd_cache_t *pc, /* I - PPD cache and mapping data */ - const char *page_size) /* I - PPD PageSize */ + const char *page_size, /* I - PPD PageSize */ + ppd_size_t *ppd_size) /* I - PPD page size information */ { int i; /* Looping var */ pwg_media_t *media; /* Media */ @@ -2774,7 +2775,7 @@ _ppdCacheGetSize( if (!pc || !page_size) return (NULL); - if (!_cups_strncasecmp(page_size, "Custom.", 7)) + if (!_cups_strcasecmp(page_size, "Custom") || !_cups_strncasecmp(page_size, "Custom.", 7)) { /* * Custom size; size name can be one of the following: @@ -2791,48 +2792,65 @@ _ppdCacheGetSize( char *ptr; /* Pointer into PageSize */ struct lconv *loc; /* Locale data */ - loc = localeconv(); - w = (float)_cupsStrScand(page_size + 7, &ptr, loc); - if (!ptr || *ptr != 'x') - return (NULL); + if (page_size[6]) + { + loc = localeconv(); + w = (float)_cupsStrScand(page_size + 7, &ptr, loc); + if (!ptr || *ptr != 'x') + return (NULL); - l = (float)_cupsStrScand(ptr + 1, &ptr, loc); - if (!ptr) - return (NULL); + l = (float)_cupsStrScand(ptr + 1, &ptr, loc); + if (!ptr) + return (NULL); - if (!_cups_strcasecmp(ptr, "in")) - { - w *= 2540.0; - l *= 2540.0; - } - else if (!_cups_strcasecmp(ptr, "ft")) - { - w *= 12.0 * 2540.0; - l *= 12.0 * 2540.0; - } - else if (!_cups_strcasecmp(ptr, "mm")) - { - w *= 100.0; - l *= 100.0; - } - else if (!_cups_strcasecmp(ptr, "cm")) - { - w *= 1000.0; - l *= 1000.0; + if (!_cups_strcasecmp(ptr, "in")) + { + w *= 2540.0; + l *= 2540.0; + } + else if (!_cups_strcasecmp(ptr, "ft")) + { + w *= 12.0 * 2540.0; + l *= 12.0 * 2540.0; + } + else if (!_cups_strcasecmp(ptr, "mm")) + { + w *= 100.0; + l *= 100.0; + } + else if (!_cups_strcasecmp(ptr, "cm")) + { + w *= 1000.0; + l *= 1000.0; + } + else if (!_cups_strcasecmp(ptr, "m")) + { + w *= 100000.0; + l *= 100000.0; + } + else + { + w *= 2540.0 / 72.0; + l *= 2540.0 / 72.0; + } } - else if (!_cups_strcasecmp(ptr, "m")) + else if (ppd_size) { - w *= 100000.0; - l *= 100000.0; + w = ppd_size->width * 2540.0 / 72.0; + l = ppd_size->length * 2540.0 / 72.0; } else { - w *= 2540.0 / 72.0; - l *= 2540.0 / 72.0; + // No custom size information... + return (NULL); } - pc->custom_size.width = (int)w; - pc->custom_size.length = (int)l; + pc->custom_size.map.ppd = (char *)page_size; + pc->custom_size.width = (int)w; + pc->custom_size.length = (int)l; + + if ((media = pwgMediaForSize((int)w, (int)l)) != NULL) + pc->custom_size.map.pwg = (char *)media->pwg; return (&(pc->custom_size)); } @@ -2842,22 +2860,28 @@ _ppdCacheGetSize( */ for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++) + { if (!_cups_strcasecmp(page_size, size->map.ppd) || !_cups_strcasecmp(page_size, size->map.pwg)) return (size); + } /* * Look up standard sizes... */ if ((media = pwgMediaForPPD(page_size)) == NULL) + { if ((media = pwgMediaForLegacy(page_size)) == NULL) media = pwgMediaForPWG(page_size); + } if (media) { - pc->custom_size.width = media->width; - pc->custom_size.length = media->length; + pc->custom_size.map.ppd = (char *)page_size; + pc->custom_size.map.pwg = (char *)media->pwg; + pc->custom_size.width = media->width; + pc->custom_size.length = media->length; return (&(pc->custom_size)); } diff --git a/cups/ppd-private.h b/cups/ppd-private.h index 3f88fb46fd..2a0e778359 100644 --- a/cups/ppd-private.h +++ b/cups/ppd-private.h @@ -158,7 +158,7 @@ extern const char *_ppdCacheGetInputSlot(_ppd_cache_t *pc, ipp_t *job, const cha extern const char *_ppdCacheGetMediaType(_ppd_cache_t *pc, ipp_t *job, const char *keyword) _CUPS_PRIVATE; extern const char *_ppdCacheGetOutputBin(_ppd_cache_t *pc, const char *keyword) _CUPS_PRIVATE; extern const char *_ppdCacheGetPageSize(_ppd_cache_t *pc, ipp_t *job, const char *keyword, int *exact) _CUPS_PRIVATE; -extern pwg_size_t *_ppdCacheGetSize(_ppd_cache_t *pc, const char *page_size) _CUPS_PRIVATE; +extern pwg_size_t *_ppdCacheGetSize(_ppd_cache_t *pc, const char *page_size, ppd_size_t *ppd_size) _CUPS_PRIVATE; extern const char *_ppdCacheGetSource(_ppd_cache_t *pc, const char *input_slot) _CUPS_PRIVATE; extern const char *_ppdCacheGetType(_ppd_cache_t *pc, const char *media_type) _CUPS_PRIVATE; extern int _ppdCacheWriteFile(_ppd_cache_t *pc, const char *filename, ipp_t *attrs) _CUPS_PRIVATE; diff --git a/cups/testppd.c b/cups/testppd.c index 9cac71508f..9da66cb748 100644 --- a/cups/testppd.c +++ b/cups/testppd.c @@ -1,7 +1,7 @@ /* * PPD test program for CUPS. * - * Copyright © 2020-2024 by OpenPrinting. + * Copyright © 2020-2025 by OpenPrinting. * Copyright © 2007-2018 by Apple Inc. * Copyright © 1997-2006 by Easy Software Products. * @@ -9,10 +9,6 @@ * information. */ -/* - * Include necessary headers... - */ - #undef _CUPS_NO_DEPRECATED #include "cups-private.h" #include "ppd-private.h" @@ -1208,6 +1204,7 @@ main(int argc, /* I - Number of command-line arguments */ ppd_option_t *option; /* Option */ ppd_coption_t *coption; /* Custom option */ ppd_cparam_t *cparam; /* Custom parameter */ + ppd_size_t *size; /* Default paper size */ ppd_const_t *c; /* UIConstraints */ char lang[255], /* LANG environment variable */ lc_all[255], /* LC_ALL environment variable */ @@ -1359,12 +1356,23 @@ main(int argc, /* I - Number of command-line arguments */ puts("\nPPD Cache:"); if ((pc = _ppdCacheCreateWithPPD(NULL, ppd)) == NULL) + { printf(" Unable to create: %s\n", cupsGetErrorString()); + } else { _ppdCacheWriteFile(pc, "t.cache", NULL); puts(" Wrote t.cache."); } + + if ((size = ppdPageSize(ppd, NULL)) != NULL) + { + pwg_size_t *pwg; /* PWG media size */ + + pwg = _ppdCacheGetSize(pc, size->name, size); + + printf(" media-default: %s\n", pwg ? pwg->map.pwg : "unknown"); + } } if (!strncmp(argv[1], "-d", 2)) diff --git a/filter/rastertopwg.c b/filter/rastertopwg.c index bf6743046e..9c50f71a74 100644 --- a/filter/rastertopwg.c +++ b/filter/rastertopwg.c @@ -1,17 +1,13 @@ /* * CUPS raster to PWG raster format filter for CUPS. * - * Copyright © 2020-2024 by OpenPrinting. + * Copyright © 2020-2025 by OpenPrinting. * Copyright © 2011, 2014-2017 Apple Inc. * * Licensed under Apache License v2.0. See the file "LICENSE" for more * information. */ -/* - * Include necessary headers... - */ - #include #include #include @@ -278,7 +274,7 @@ main(int argc, /* I - Number of command-line args */ } } - if (inheader.cupsPageSizeName[0] && (pwg_size = _ppdCacheGetSize(cache, inheader.cupsPageSizeName)) != NULL && pwg_size->map.pwg) + if (inheader.cupsPageSizeName[0] && (pwg_size = _ppdCacheGetSize(cache, inheader.cupsPageSizeName, /*ppd_size*/NULL)) != NULL && pwg_size->map.pwg) { cupsCopyString(outheader.cupsPageSizeName, pwg_size->map.pwg, sizeof(outheader.cupsPageSizeName)); diff --git a/scheduler/printers.c b/scheduler/printers.c index 31d66322f1..6b78e0d325 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -4297,7 +4297,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ */ if ((size = ppdPageSize(ppd, NULL)) != NULL) - pwgsize = _ppdCacheGetSize(p->pc, size->name); + pwgsize = _ppdCacheGetSize(p->pc, size->name, size); else pwgsize = NULL;