Skip to content

Commit 82a1d73

Browse files
committed
Update PPD cache private API to support getting custom size names (Issue #1238)
1 parent bb43acc commit 82a1d73

5 files changed

Lines changed: 79 additions & 51 deletions

File tree

cups/ppd-cache.c

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ _cupsConvertOptions(
210210

211211
media_source = _ppdCacheGetSource(pc, cupsGetOption("InputSlot", num_options, options));
212212
media_type = _ppdCacheGetType(pc, cupsGetOption("MediaType", num_options, options));
213-
size = _ppdCacheGetSize(pc, keyword);
213+
size = _ppdCacheGetSize(pc, keyword, /*ppd_size*/NULL);
214214

215215
if (media_col_sup && (size || media_source || media_type))
216216
{
@@ -2767,7 +2767,8 @@ _ppdCacheGetPageSize(
27672767
pwg_size_t * /* O - PWG size or NULL */
27682768
_ppdCacheGetSize(
27692769
_ppd_cache_t *pc, /* I - PPD cache and mapping data */
2770-
const char *page_size) /* I - PPD PageSize */
2770+
const char *page_size, /* I - PPD PageSize */
2771+
ppd_size_t *ppd_size) /* I - PPD page size information */
27712772
{
27722773
int i; /* Looping var */
27732774
pwg_media_t *media; /* Media */
@@ -2781,7 +2782,7 @@ _ppdCacheGetSize(
27812782
if (!pc || !page_size)
27822783
return (NULL);
27832784

2784-
if (!_cups_strncasecmp(page_size, "Custom.", 7))
2785+
if (!_cups_strcasecmp(page_size, "Custom") || !_cups_strncasecmp(page_size, "Custom.", 7))
27852786
{
27862787
/*
27872788
* Custom size; size name can be one of the following:
@@ -2798,48 +2799,65 @@ _ppdCacheGetSize(
27982799
char *ptr; /* Pointer into PageSize */
27992800
struct lconv *loc; /* Locale data */
28002801

2801-
loc = localeconv();
2802-
w = (float)_cupsStrScand(page_size + 7, &ptr, loc);
2803-
if (!ptr || *ptr != 'x')
2804-
return (NULL);
2802+
if (page_size[6])
2803+
{
2804+
loc = localeconv();
2805+
w = (float)_cupsStrScand(page_size + 7, &ptr, loc);
2806+
if (!ptr || *ptr != 'x')
2807+
return (NULL);
28052808

2806-
l = (float)_cupsStrScand(ptr + 1, &ptr, loc);
2807-
if (!ptr)
2808-
return (NULL);
2809+
l = (float)_cupsStrScand(ptr + 1, &ptr, loc);
2810+
if (!ptr)
2811+
return (NULL);
28092812

2810-
if (!_cups_strcasecmp(ptr, "in"))
2811-
{
2812-
w *= 2540.0;
2813-
l *= 2540.0;
2814-
}
2815-
else if (!_cups_strcasecmp(ptr, "ft"))
2816-
{
2817-
w *= 12.0 * 2540.0;
2818-
l *= 12.0 * 2540.0;
2819-
}
2820-
else if (!_cups_strcasecmp(ptr, "mm"))
2821-
{
2822-
w *= 100.0;
2823-
l *= 100.0;
2824-
}
2825-
else if (!_cups_strcasecmp(ptr, "cm"))
2826-
{
2827-
w *= 1000.0;
2828-
l *= 1000.0;
2813+
if (!_cups_strcasecmp(ptr, "in"))
2814+
{
2815+
w *= 2540.0;
2816+
l *= 2540.0;
2817+
}
2818+
else if (!_cups_strcasecmp(ptr, "ft"))
2819+
{
2820+
w *= 12.0 * 2540.0;
2821+
l *= 12.0 * 2540.0;
2822+
}
2823+
else if (!_cups_strcasecmp(ptr, "mm"))
2824+
{
2825+
w *= 100.0;
2826+
l *= 100.0;
2827+
}
2828+
else if (!_cups_strcasecmp(ptr, "cm"))
2829+
{
2830+
w *= 1000.0;
2831+
l *= 1000.0;
2832+
}
2833+
else if (!_cups_strcasecmp(ptr, "m"))
2834+
{
2835+
w *= 100000.0;
2836+
l *= 100000.0;
2837+
}
2838+
else
2839+
{
2840+
w *= 2540.0 / 72.0;
2841+
l *= 2540.0 / 72.0;
2842+
}
28292843
}
2830-
else if (!_cups_strcasecmp(ptr, "m"))
2844+
else if (ppd_size)
28312845
{
2832-
w *= 100000.0;
2833-
l *= 100000.0;
2846+
w = ppd_size->width * 2540.0 / 72.0;
2847+
l = ppd_size->length * 2540.0 / 72.0;
28342848
}
28352849
else
28362850
{
2837-
w *= 2540.0 / 72.0;
2838-
l *= 2540.0 / 72.0;
2851+
// No custom size information...
2852+
return (NULL);
28392853
}
28402854

2841-
pc->custom_size.width = (int)w;
2842-
pc->custom_size.length = (int)l;
2855+
pc->custom_size.map.ppd = (char *)page_size;
2856+
pc->custom_size.width = (int)w;
2857+
pc->custom_size.length = (int)l;
2858+
2859+
if ((media = pwgMediaForSize((int)w, (int)l)) != NULL)
2860+
pc->custom_size.map.pwg = (char *)media->pwg;
28432861

28442862
return (&(pc->custom_size));
28452863
}
@@ -2849,22 +2867,28 @@ _ppdCacheGetSize(
28492867
*/
28502868

28512869
for (i = pc->num_sizes, size = pc->sizes; i > 0; i --, size ++)
2870+
{
28522871
if (!_cups_strcasecmp(page_size, size->map.ppd) ||
28532872
!_cups_strcasecmp(page_size, size->map.pwg))
28542873
return (size);
2874+
}
28552875

28562876
/*
28572877
* Look up standard sizes...
28582878
*/
28592879

28602880
if ((media = pwgMediaForPPD(page_size)) == NULL)
2881+
{
28612882
if ((media = pwgMediaForLegacy(page_size)) == NULL)
28622883
media = pwgMediaForPWG(page_size);
2884+
}
28632885

28642886
if (media)
28652887
{
2866-
pc->custom_size.width = media->width;
2867-
pc->custom_size.length = media->length;
2888+
pc->custom_size.map.ppd = (char *)page_size;
2889+
pc->custom_size.map.pwg = (char *)media->pwg;
2890+
pc->custom_size.width = media->width;
2891+
pc->custom_size.length = media->length;
28682892

28692893
return (&(pc->custom_size));
28702894
}

cups/ppd-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ extern const char *_ppdCacheGetOutputBin(_ppd_cache_t *pc,
181181
extern const char *_ppdCacheGetPageSize(_ppd_cache_t *pc, ipp_t *job,
182182
const char *keyword, int *exact) _CUPS_PRIVATE;
183183
extern pwg_size_t *_ppdCacheGetSize(_ppd_cache_t *pc,
184-
const char *page_size) _CUPS_PRIVATE;
184+
const char *page_size, ppd_size_t *ppd_size) _CUPS_PRIVATE;
185185
extern const char *_ppdCacheGetSource(_ppd_cache_t *pc,
186186
const char *input_slot) _CUPS_PRIVATE;
187187
extern const char *_ppdCacheGetType(_ppd_cache_t *pc,

cups/testppd.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/*
22
* PPD test program for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2025 by OpenPrinting.
55
* Copyright © 2007-2018 by Apple Inc.
66
* Copyright © 1997-2006 by Easy Software Products.
77
*
88
* Licensed under Apache License v2.0. See the file "LICENSE" for more
99
* information.
1010
*/
1111

12-
/*
13-
* Include necessary headers...
14-
*/
15-
1612
#undef _CUPS_NO_DEPRECATED
1713
#include "cups-private.h"
1814
#include "ppd-private.h"
@@ -1208,6 +1204,7 @@ main(int argc, /* I - Number of command-line arguments */
12081204
ppd_option_t *option; /* Option */
12091205
ppd_coption_t *coption; /* Custom option */
12101206
ppd_cparam_t *cparam; /* Custom parameter */
1207+
ppd_size_t *size; /* Default paper size */
12111208
ppd_const_t *c; /* UIConstraints */
12121209
char lang[255], /* LANG environment variable */
12131210
lc_all[255], /* LC_ALL environment variable */
@@ -1359,12 +1356,23 @@ main(int argc, /* I - Number of command-line arguments */
13591356

13601357
puts("\nPPD Cache:");
13611358
if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL)
1359+
{
13621360
printf(" Unable to create: %s\n", cupsLastErrorString());
1361+
}
13631362
else
13641363
{
13651364
_ppdCacheWriteFile(pc, "t.cache", NULL);
13661365
puts(" Wrote t.cache.");
13671366
}
1367+
1368+
if ((size = ppdPageSize(ppd, NULL)) != NULL)
1369+
{
1370+
pwg_size_t *pwg; /* PWG media size */
1371+
1372+
pwg = _ppdCacheGetSize(pc, size->name, size);
1373+
1374+
printf(" media-default: %s\n", pwg ? pwg->map.pwg : "unknown");
1375+
}
13681376
}
13691377

13701378
if (!strncmp(argv[1], "-d", 2))

filter/rastertopwg.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
/*
22
* CUPS raster to PWG raster format filter for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2025 by OpenPrinting.
55
* Copyright © 2011, 2014-2017 Apple Inc.
66
*
77
* Licensed under Apache License v2.0. See the file "LICENSE" for more
88
* information.
99
*/
1010

11-
/*
12-
* Include necessary headers...
13-
*/
14-
1511
#include <cups/cups-private.h>
1612
#include <cups/ppd-private.h>
1713
#include <cups/raster.h>
@@ -278,7 +274,7 @@ main(int argc, /* I - Number of command-line args */
278274
}
279275
}
280276

281-
if (inheader.cupsPageSizeName[0] && (pwg_size = _ppdCacheGetSize(cache, inheader.cupsPageSizeName)) != NULL && pwg_size->map.pwg)
277+
if (inheader.cupsPageSizeName[0] && (pwg_size = _ppdCacheGetSize(cache, inheader.cupsPageSizeName, /*ppd_size*/NULL)) != NULL && pwg_size->map.pwg)
282278
{
283279
strlcpy(outheader.cupsPageSizeName, pwg_size->map.pwg,
284280
sizeof(outheader.cupsPageSizeName));

scheduler/printers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4191,7 +4191,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */
41914191
*/
41924192

41934193
if ((size = ppdPageSize(ppd, NULL)) != NULL)
4194-
pwgsize = _ppdCacheGetSize(p->pc, size->name);
4194+
pwgsize = _ppdCacheGetSize(p->pc, size->name, size);
41954195
else
41964196
pwgsize = NULL;
41974197

0 commit comments

Comments
 (0)