From: Benjamin Gordon Date: Fri, 2 Dec 2022 17:22:09 +0000 (-0700) Subject: Update InputSlot selection for photo sizes (fixes #569) X-Git-Tag: v2.4.3~94^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9fc2f44ff0d6bee954c152a2461b05bb175b00d;p=thirdparty%2Fcups.git Update InputSlot selection for photo sizes (fixes #569) _ppdCacheGetInputSlot specifically requests the photo tray for paper sizes up to 5x7" if the client hasn't specified a media-source. This can fail if the photo tray is physically smaller than 5x7 (for example, L-sized). Instead of explicitly requesting the photo tray, try to request "auto" and fall back to "photo" if the printer doesn't provide that as an option. Signed-off-by: Benjamin Gordon --- diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 3da921d0a3..6c7f3a8e79 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -31,6 +31,7 @@ static int cups_connect(http_t **http, const char *url, char *resource, size_t ressize); static int cups_get_url(http_t **http, const char *url, char *name, size_t namesize); +static const char *ppd_inputslot_for_keyword(_ppd_cache_t *pc, const char *keyword); static void pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value); static void pwg_add_message(cups_array_t *a, const char *msg, const char *str); static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b); @@ -2280,6 +2281,28 @@ _ppdCacheGetFinishingValues( } +/* + * 'ppd_inputslot_for_keyword()' - Return the PPD InputSlot associated + * a keyword string, or NULL if no mapping + * exists. + */ +static const char * /* O - PPD InputSlot or NULL */ +ppd_inputslot_for_keyword( + _ppd_cache_t *pc, /* I - PPD cache and mapping data */ + const char *keyword) /* I - Keyword string */ +{ + int i; /* Looping var */ + + if (!pc || !keyword) + return (NULL); + + for (i = 0; i < pc->num_sources; i ++) + if (!_cups_strcasecmp(keyword, pc->sources[i].pwg)) + return (pc->sources[i].ppd); + + return (NULL); +} + /* * '_ppdCacheGetInputSlot()' - Get the PPD InputSlot associated with the job * attributes or a keyword string. @@ -2324,24 +2347,21 @@ _ppdCacheGetInputSlot( else if (pwgInitSize(&size, job, &margins_set)) { /* - * For media <= 5x7, look for a photo tray... + * For media <= 5x7, try to ask for automatic selection so the printer can + * pick the photo tray. If auto isn't available, fall back to explicitly + * asking for the photo tray. */ - if (size.width <= (5 * 2540) && size.length <= (7 * 2540)) + if (size.width <= (5 * 2540) && size.length <= (7 * 2540)) { + const char* match; + if ((match = ppd_inputslot_for_keyword(pc, "auto")) != NULL) + return (match); keyword = "photo"; + } } } - if (keyword) - { - int i; /* Looping var */ - - for (i = 0; i < pc->num_sources; i ++) - if (!_cups_strcasecmp(keyword, pc->sources[i].pwg)) - return (pc->sources[i].ppd); - } - - return (NULL); + return (ppd_inputslot_for_keyword(pc, keyword)); }