Skip to content

Commit 2892e9a

Browse files
committed
Ignore unsupported resolution values
Since some time the print dialog of Google's Chrome browser send the attribute "Resolution=96dpi" with its print jobs (job itself sent in PDF format). This is a resolution which most modern printers do not support and usually the print filters and drivers should ignore unsupported values for any option or IPP attribute, so such an attribute should not harm. Unfortunately, in some cases the validity of the resolution value is not checked and so the wrong value makes it through to the actual rasterization, messing up the printouts as a raster with a much too low, unsupported resolution is sent to the printer. This commit solves the problem by actually checking the resolution values. This is done in the raster_base_header() function which generates a CUPS/PWG Raster header from scratch, solely based on printer and job IPP attributes, and the option list supplied to the filter functions. This function is called by the cfRasterPrepareHeader() API function which creates a CUPS/PWG Raster header for the filter functions, either as base for the page headers in CUPS/PWG/Apple Raster output or to get a data structure with all important page properties. He we add a check now, by passing resolutions parsed from the options through the cfIPPAttrResolutionForPrinter() function. This way wrong values get ignored and the default value be used instead. If there are no printer attributes available, any resolution value is accepted. Fixes #29: #29
1 parent 9ff1341 commit 2892e9a

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

cupsfilters/raster.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,32 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
10231023
else
10241024
h->Duplex = CUPS_FALSE;
10251025

1026-
if ((val = cupsGetOption("printer-resolution", num_options,
1027-
options)) != NULL ||
1028-
(val = cupsGetOption("Resolution", num_options, options)) != NULL)
1026+
// To avoid that a resolution provided in the option list and not as
1027+
// job IPP attribute is a supported resolution according to the
1028+
// printer IPP attributes, we want to use the
1029+
// cfIPPAttrResolutionForPrinter() function on it, to only accept it
1030+
// if it is supported and use the default if not, and also to accept it if
1031+
// there are no printer IPP attributes.
1032+
//
1033+
// Therefore we create a new IPP message for adding the resolution
1034+
// parsed from the option list, but only if we do not already have a
1035+
// "printer-resolution" in the job IPP attributes, which we use
1036+
// preferrably then.
1037+
int x = 0, y = 0;
1038+
if ((attr = ippFindAttribute(data->job_attrs, "printer-resolution",
1039+
IPP_TAG_ZERO)) != NULL)
1040+
cfIPPAttrResolutionForPrinter(data->printer_attrs, data->job_attrs, NULL,
1041+
&x, &y);
1042+
else if ((val = cupsGetOption("printer-resolution", num_options,
1043+
options)) != NULL ||
1044+
(val = cupsGetOption("Resolution", num_options, options)) != NULL)
10291045
{
10301046
int xres, // X resolution
10311047
yres; // Y resolution
10321048
char *ptr; // Pointer into value
1049+
ipp_t *attrs;
10331050

1051+
attrs = ippNew();
10341052
xres = yres = strtol(val, (char **)&ptr, 10);
10351053
if (ptr > val && xres > 0)
10361054
{
@@ -1050,33 +1068,22 @@ raster_base_header(cups_page_header2_t *h, // O - Raster header
10501068
xres = xres * 254 / 100;
10511069
yres = yres * 254 / 100;
10521070
}
1053-
h->HWResolution[0] = xres;
1054-
h->HWResolution[1] = yres;
1055-
}
1056-
else
1057-
{
1058-
h->HWResolution[0] = 100; // Resolution invalid
1059-
h->HWResolution[1] = 100;
1071+
ippAddResolution(attrs, IPP_TAG_PRINTER, "printer-resolution",
1072+
IPP_RES_PER_INCH, xres, yres);
10601073
}
1074+
cfIPPAttrResolutionForPrinter(data->printer_attrs, attrs, NULL, &x, &y);
1075+
ippDelete(attrs);
1076+
}
1077+
if (x && y)
1078+
{
1079+
h->HWResolution[0] = x;
1080+
h->HWResolution[1] = y;
10611081
}
10621082
else
10631083
{
10641084
h->HWResolution[0] = 100; // Resolution invalid
10651085
h->HWResolution[1] = 100;
10661086
}
1067-
1068-
// Resolution from IPP attrs
1069-
if (h->HWResolution[0] == 100 && h->HWResolution[1] == 100)
1070-
{
1071-
int x = 0, y = 0;
1072-
cfIPPAttrResolutionForPrinter(data->printer_attrs, data->job_attrs,
1073-
NULL, &x, &y);
1074-
if (x && y)
1075-
{
1076-
h->HWResolution[0] = x;
1077-
h->HWResolution[1] = y;
1078-
}
1079-
}
10801087

10811088
// TODO - Support for insert sheets
10821089
h->InsertSheet = CUPS_FALSE;

0 commit comments

Comments
 (0)