Till Kamppeter [Tue, 8 Mar 2022 19:50:07 +0000 (20:50 +0100)]
libcupsfilters: In ghostscript() do not use gray profile on color PCLm
The "pclm" output device of Ghostscript only supports 8-bit sRGB
output, no sGray and also no color-to -monochrome conversion. There is
also no way to convert to grayscale by simply applying a gray color
profile.
Applying the gray color profile caused a crash in older versions of
Ghostscript and now is rejected with an error. See
Till Kamppeter [Fri, 25 Feb 2022 22:27:38 +0000 (23:27 +0100)]
libcupsfilters: In ghostscript() add monochrome PCLm printing
If a job for PCLm output is requested to be monochrome/grayscale (like
with "print-color-mode=monochrome"), use the sgray.icc color profile
instead of srgb.icc to get grayscale output.
Till Kamppeter [Fri, 25 Feb 2022 22:21:50 +0000 (23:21 +0100)]
libcupsfilters: In cupsRasterPrepareHeader() added monchrome PCLm support
PCLm supports exactly 2 color spaces, sRGB 8-bit for color and sGray
8-bit for monochrome printing. Up to now we only had supported the
sRGB space. This commit adds support for sGray.
This especially allows monchrome printing on color PCLm printers, and
faster (less data to handle) and more economic (use only black
toner/ink, not the colored ones) grayscale printing.
Principally all PCLm printers should support both color spaces.
Till Kamppeter [Thu, 17 Feb 2022 14:41:50 +0000 (15:41 +0100)]
libcupsfilters: Fixed imageto...() with print-scaling=auto
In the imageto...() filter functions with print-scaling=auto the image
size was not compared correctly with the page size to switch between
fit-to-page for large sizes and no scaling for small sizes. The image
size in pixels was compared with the page size in PostScript points
(1/72 inch).
Till Kamppeter [Thu, 17 Feb 2022 13:41:39 +0000 (14:41 +0100)]
libcupsfilters: Let imageto...() with print-scaling=none center correctly
In the imageto...() filter functions with print-scaling=none do the
math for centering the image on the page without the unprintable
margins, so that the image gets correctly centered relative to the
page, not to the printable area of the page.
As in imagetoraster we have to pass on a bitmap of the printable area
for CUPS Raster. we correct for the margins after calculating image
size and position without margins.
Till Kamppeter [Sun, 13 Feb 2022 14:31:56 +0000 (11:31 -0300)]
libcupsfilters: Do not always use high color depth for high quality
The cupsRasterPrepareHeader() function tries to set a high-color-depth
(16 bit per color) color mode for Apple Raster and PWG Raster if high
print quality is requested and the printer supports it.
We cannot do this all the time, as sometimes the filter function does
not support it (imagetoraster(), mupdftoraster()) or it could not be
worthwhile for the input file.
Therefore a new boolean argument is added to cupsRasterPrepareHeader()
to allow suppressing the selection of high color depth.
Currently we make use of this in the imagetoraster() and
mupdftoraster() filter functions.
Poppler's Raster output is 8-bit-sRGB-only, but as the color space
conversion to 16-bit AdobeRGB in pdftoraster is done by the color
space/profile conversion of LittleCMS we allow high color depth here
to allow a more precise color adjustment.
Ghostscript supports high color depth including LittleCMS color
management, therefore we keep support for it in the ghostscript()
filter function.
Till Kamppeter [Sun, 13 Feb 2022 02:39:57 +0000 (23:39 -0300)]
libcupsfilters: Many filter function fixes
- All filter functions, at least the ones producing CUPS/Apple/PWG
Raster output, work with cups-filters-generated PPD files now, where
no pseudo-PostScript code for the color space and depth is contained
any more but instead, copies of the printer IPP attributes telling
about supported color spaces and depths for Apple Raster and PWG
Raster (using cupsRasterPrepareHeader() function). Did this for
imagetoraster(), mupdftoraster(), and pdftoraster().
- In filter functions which only output CUPS Raster and not for
example Apple Raster or PCLm, cups-filters-generated PPD files
without Pseudo-PostScript code but copies of IPP attributes for
color spaces can also be used so that the generated CUPS Raster is
the one needed by rastertopwg() or rastertopdf() to generate the
final format. This is available in ghostscript(), imagetoraster(),
mupdftoraster(), and pdftoraster() now.
- In pdftoraster() and pwgtoraster() 16-bit-per color (high color
depth) modes printed in wrong colors, it was not taken account that
the color space/profile conversion by LittleCMS also converts to the
higher color depth, due to a bug in marking that no color depth
conversion is needed any more.
- In the imageto...() filter functions fixed the print-scaling=none
(crop-to-fit) mode, which prints the image in its original size
(based on PPI resolution stored in the image file or on 200 dpi
resolution, which is the standard resolution for shipping
labels). Also use crop-to-fit always when requested, do not fall
back to fit-to-page when the image is significantly larger or
smaller than the page.
- The cupsRasterPrepareHeader() function got enhanced to get separate
arguments for the actual format of the generated Raster header and
for the final output format of the job, to obtain color space and
depth, and the resolution according to that final output format.
Till Kamppeter [Fri, 11 Feb 2022 02:58:40 +0000 (23:58 -0300)]
libcupsfilters: fixes in cupsRasterSetColorSpace()
- Really do not do cspace_fallback = 0 with cspace = -1 (cspace
is an unsigned type, so -1 can only be checked via "==", not ">= 0")
- Advance search pointer in string of available color spaces after
a false positive (search term is part of the word) and not quit
loop then.
- Support more color spaces when parsing the color_mode string
(value of ColorModel or print-color-mode)
Now all color spaces supported by the printer in Apple/PWG Raster can
get auto-selected according to ColorModel or print-color-mode setting,
and results are more reliable (before we got grayscale on "RGB" color
mode).
Mohit Verma [Thu, 10 Feb 2022 17:47:41 +0000 (23:17 +0530)]
libcupsfilter: Added input-page-ranges attribute to pstops()
Pull request #445
As already to pdftopdf() we add the input-page-ranges attribute to be able to select pages of the input document before we do any re-arranging as number-up or booklet printing (Issue #365).
Till Kamppeter [Thu, 10 Feb 2022 17:37:50 +0000 (14:37 -0300)]
libcupsfilters: In mupdftoraster() direct output to outputfd
mupdftoraster() has called mutool in a forked sub-process but not
captured and re-directed stderr to the log function and stdout to the
outputfd file descriptor.
Till Kamppeter [Wed, 9 Feb 2022 17:37:03 +0000 (14:37 -0300)]
libcupsfilters: Don't call cupsRasterParseIPPOptions() if we have PPD
In a filter function, when we have a PPD file we should not call
cupsRasterParseIPPOptions() as this function guesses the meaning of
job options/attributes from their names.
This can easily cause problems, for example if we supply
"print-color-mode=monochrome" and the function chooses the wromg
monochrome color space, one not supported according to the PPD and so
not supported by the printer or the (rasterto...) driver.
Therefore we remove these calls and trust the PPD's options.
In retro-fitting Printer Applications job IPP attributes are
associated with appropriate PPD options anyway.
Till Kamppeter [Wed, 9 Feb 2022 17:14:52 +0000 (14:14 -0300)]
libcupsfilters: In mupdftoraster() removed ppdClose()
Filter functions should not close the PPD data structure which they
get supplied with the filter data, to once avoid crashes if the filter
function is called in a chain with other filter functions and common
filter data structure, and second, the filterCUPSWrapper() closes the
PPD data structure by itself.
Till Kamppeter [Sun, 6 Feb 2022 01:34:14 +0000 (22:34 -0300)]
implicitclass: If IPP poll of printer fails, use PPD file for capabilities
Member printers of a cups-browsed printer cluster are always IPP
printers, in most cases driverless IPP (IPP 2.x) printers and here a
get-printer-attributes IPP request gets all needed capability info
from the destination printer in order to run the filters to turn the
PDF input into the printer's data format.
If the destination printer is a legacy IPP (IPP 1.x) printer, our
get-printer-attributes IPP request fails (we accept only IPP 2.x here)
and then we fall back to using the PPD file. The PPD file is the
cluster's PPD, not the printer's, but all settings are supported by
our destination printer (otherwise it would not have gotten selected).
This way we recover support for legacy IPP printers which got dropped
with the recent commits to switch over to use filter functions instead
of external filter executables.
Till Kamppeter [Sat, 5 Feb 2022 18:34:21 +0000 (15:34 -0300)]
libcupsfilters: In pdftopdf() add 2% tolerance for input size larger output page
When "print-scaling=auto" or "print-scaling=auto-fit" is used, the
input pages are scaled when they do not fit into the output page
size. Often input ad out page sizes are supposed to be equal, for
example both A4, but rounding errors could make the input considered
larger and unnecessarily scaled.
Therefore we add 2% of tolerance before considering an input page too
large.
libcupsfilters: Changed the default ppi from 128 to 200
This is for image input files which have no PPI resolution in their metadata and are printed without scaling ("print-scaling=none"). In this case the default resolution is used. Formerly it was set to 128 PPI but we change it to 200 PPI now as many shipping labels come as image files with 200 PPI and so it is easier to print them in their original size. For photos this default value is not important though, as photos are usually printed with scaling ("print-scaling=fill" or "print-scaling=fit").
Till Kamppeter [Mon, 31 Jan 2022 16:39:15 +0000 (13:39 -0300)]
libcupsfilters: Undo previous commit of stderr message removal
We do not need to remove the stderr messages from cupsFindAttr(), the
function is only used by printer drivers not by filter functions. It
will be moved into a separate library.
Till Kamppeter [Wed, 26 Jan 2022 02:09:37 +0000 (23:09 -0300)]
libppd: When parsing *.drv files for PPD collections, eliminate stderr
When generating PPD lists for PPD collections or extracting a PPD file
from a collection, *.drv files (CUPS has them in /usr/share/cups/drv)
can be parsed with the CUPS PPD compiler functions which got adopted
into libppd.
These functions are originally created for command line utilities to
handle *.drv files and PPD files and therefore they were rather
verbose on stderr in case there was an error in a file. As the PPD
collection handling functionality (ppd/pdd-collection.cxx) only
retro-fits existing *.drv files and does not serve for creating or
developing them, we simply re-direct stderr to /dev/null while
executing these functions to avoid any messages leaking into syslog or
the journal while running Printer Applications. This is much easier as
and less error-prone than introducing support for logging functions
into the obsolete and retro-fit-only *.drv handling function.
Mohit Verma [Tue, 25 Jan 2022 20:38:04 +0000 (02:08 +0530)]
libcupsfilters: Add input-page-ranges attribute to pdftopdf()
Pull request #444
The page-ranges option/attribute applies to the putput page stream going to the printer. If an 8-page input document is printed with number-up=2 one gets 4 sheets, with input pages 1+2, 3+4, 5+6, and 7+8, applying page-ranges=1,4 in addition will give a sheet with input pages 1+2 and 7+8. This way you can easily repeat sheets if they failed to print correctly on the first attempt to print the job.
There was no way to select for example page 1-3 and page 6 from the input and arrange it on 2 sheets with 1+2 and 3+6, for example if only these pages contain exercises which you have to solve. or content relevant for your exam. This is now solved by adding the new input-page-ranges attribute. If you now print with "input-page-ranges=1-3,6 number-up=2" you get exactly what you want (Issue #365).
Till Kamppeter [Fri, 21 Jan 2022 02:55:47 +0000 (23:55 -0300)]
libppd: When running driver/PPD generator executables, capture stderr
When generating PPD lists for PPD collections or extracting a PPD file
from a collection, CUPS driver/PPD generator executables (CUPS has
them in /usr/lib/cups/driver) can be called. The stderr output
(fortunately rare) of the driver/PPD generator executables did not get
captured and went directly to stderr (to syslog when the caller runs
as a system daemon).
This commit fixes it and re-directs the stderr output into the log
function, so that nothing is leaking into stderr any more.
In addition, more logging is added to the PipeCommand() and
ClosePipeCommand() functions.
Till Kamppeter [Sat, 15 Jan 2022 18:40:43 +0000 (15:40 -0300)]
libcupsfilters: Let PPD generator take default ColorModel from printer
Instead of selecting the "best" available color mode as default for
the PPD file generated from the response to the get-printer-attributes
IPP request we use the printer default according to the IPP attributes
(print-color-mode-default).
This way on can simply change the default on a network printer's web
interface or on a remote CUPS printer and clients using cups-browsed
or the "driverless" utility respect the change.
This solves https://github.com/OpenPrinting/cups/issues/277, together
with the changes done on CUPS for this issue.
Till Kamppeter [Sat, 15 Jan 2022 15:21:27 +0000 (12:21 -0300)]
libcupsfilters: In the PPD generator default to Color if available
The PPD generator takes the choices for the ColorModel option from the
print-color-mode-supported printer IPP attribute, using all listed
choices, including "Auto". It uses "Auto" as default choice if
present.
Michael Sweet in https://github.com/OpenPrinting/cups-filters/issues/426:
The PPD shouldn't have an "auto" option - generally speaking,
"auto" maps to "color" for color pages and "monochrome" for B&W
pages, which is something that the PDF RIP can automatically
detect and use the correct color/grayscale colorspace when "color"
is the default (i.e. optimize for the most common usage and don't
add a separate option to enable it).
Therefore we ignore "Auto" in the IPP attribute now and only add the
other choices, setting color as default if a color choice is present,
monochrome/gray otherwise.
This should fix the color output problem mentioned in
https://github.com/OpenPrinting/cups-filters/issues/426
TinyTrebuchet [Sat, 15 Jan 2022 14:35:32 +0000 (20:05 +0530)]
Braille: In vectortopdf check inkscape version to call inkscape with the correct command line
From version 1.0.x on, Inkscape does not support the '-A' command line flag any more. Now we check the inkscape version and call inkscape always with the correct command line.
chandresh soni [Thu, 13 Jan 2022 20:07:18 +0000 (01:37 +0530)]
libcupsfilters: Close files on file copy error in filter functions
Some filter functions do not close the input file when it comes to an error opening a temporary file to copy the input into. This causes a memory leak in continuously running callers, like Printer Applications.
Till Kamppeter [Thu, 13 Jan 2022 17:39:09 +0000 (14:39 -0300)]
libcupsfilters: In ieee1284NormalizeMakeAndModel() do not remove extra after ()
If a PPD's NickName has extra info in parentheses after the model name
we have thrown away any further text after the parentheses. As
PPD-retro-fitting Printer Applications add the PPD's language (for
example "(en)") to the end of the NickName and then call
ieee1284NormalizeMakeAndModel() to generate the unique driver name,
this language info extension gets thrown away and the unique driver
name identical for all language versions of the same printer's PPD,
making the entries clobbering each other leaving only the first in the
alphabet, which is often German ("de") and rarely English.
Now we do not remove any part of the input string's extra info to
remedy this problem.
Till Kamppeter [Tue, 4 Jan 2022 20:07:50 +0000 (17:07 -0300)]
libcupsfilters: In imagetoraster() fixed crash with SGray
As the SGray color space was not mentioned in the switch for selecting
the raster line formatting function, a 3-channel color formatting
function was selected instead of the 1-channel grayscale one, leading
to an overrun of the input pixel line, causing a crash.
This is fixed now by also mentioning the 3 standard color spaces for
driverless printing, SGray, SRGB, and AdobeRGB explicily (where for
the latter 2 the selection already worked as they are 3-channel color
options).
Till Kamppeter [Sun, 2 Jan 2022 03:49:32 +0000 (00:49 -0300)]
libcupsfilters: Fixed pdftopdf() for asymmetric margins
On some printers the left unprintable margin does not equal the right
one and/or the top margin does not equal the bottom one. pdftopdf()
did not always place the input pages correctly on the output sheets,
having de-centered printouts in crop-to-fit mode
("print-scaling=none") or missing content at the borders in
scale-to-fit mode ("print-scaling=fit").
Probably pdftopdf() did not get (well) tested with such printers.
This commit addresses these issues:
- In crop-to-fit mode we set the margins of the output page to
all-zero befor starting all the math. This way we assure pages get
centered and the correct (asymmetric) crop is done by the following
filters (driver) or the printer (by simply ignoring the pixels
falling into the margins). Alao for N-up here the input pages are
filling exactly the halves, quarters, ... of the sheet, allowing
easy mounting of booklets. pdftopdf() is producing an output PDF
with pages of the size of the output sheet (not of its printable
area) anyway and it does not need to passon pages where the
unprintable margins are actually white.
- Set the auto-fit bit for crop-to-fill mode ("print-scaling=fill"),
to assure that the pages cropped to the aspect ratio of the
printable area of the output page are correctly scaled into that
area (this got probably accidentally dropped in an earlier commit).
- Corrected the margin offsets at the coordinate origin for N-up
printing in Landscape orientation (2-up, 6-up, 8-up, ...), so that
they work with asymmetric margins.
- Let the crop() method for a PDF page not create a page smaller than
the destination page. When "cropping" a smaller input page, set its
crop box so that it gets centered on the output page. This makes the
input pages always printed in original size in crop mode, even if
they are smaller than the output page.
Till Kamppeter [Thu, 30 Dec 2021 14:28:06 +0000 (11:28 -0300)]
libcupsfilters: Let pdftopdf() not send NULL to log function
The variable holding the value of FINAL_CONTENT_TYPE is NULL when the
environment variable is not set. At one place the variable value gets
logged using the log function. Do not send NULL here, to avoid a crash
of the log function.
Till Kamppeter [Thu, 30 Dec 2021 02:49:15 +0000 (23:49 -0300)]
libcupsfilters: Fix orientation-requested = 0 in pdftopdf()
CUPS often adds "orientation-requested=0" to the options in the
filter/backend command line, meaning automatic selection. pdftopdf()
did not support this value and therefore did not do the correct
settings making margins of rotated landscape pages not be done
correctly.
Till Kamppeter [Thu, 30 Dec 2021 02:33:53 +0000 (23:33 -0300)]
libcupsfilters: Let cupsRasterPrepareHeader() create complete header
The cupsRasterPrepareHeader() function creates a CUPS/PWG Raster
header for Raster output based on the printer and job properties
supplied to the calling filter functions.
This commit fixes the header produced by this function to be complete
and consistent so that it can be used for actual Raster output. It
adds the following missing pieces:
- Find correct dimensions and margins for the page size requested by
the job.
- After having found page dimensions, margins, color space, color
depth, and resolution, set all fields of the header which depend on
this to the correct values, to assure that the resulting header is
consistent.
Also did some fixes in cupsRasterParseIPPOptions()
- Create the empty header with all-zero before starting, to have
everything well-defined.
- Fixed setting for requested orientation, to correctly handle 0 as
input or wrong input values.
Till Kamppeter [Thu, 30 Dec 2021 02:12:00 +0000 (23:12 -0300)]
libcupsfilters: Fix resolver functions for DNS-SD-based URIs
CUPS and cups-browsed use DNS-SD-service-name-based URIs, so that the
printer URIs are robust against changes of network details, for
example of the port, if Printer Applications on a system come up in
different order at every boot.
To be able to access the printer these URIs have to get resolved,
which means to get converted into standard IPP URIs. This is done by
two functions with their source being in cupsfilters/ipp.c.
Unfortunately both functions have a bug and in this commit we fix
these bugs to make the functions correctly working in all cases.
1. resolve_uri()
This function calls cupsBackendDeviceURI() of libcups which resolves
device URIs for the CUPS backends. As it is designed for only using in
CUPS backends it needs some workarounds to make it usuable as
universal library function and make it work in a wide range of system
environments.
One workaround was already applied from the beginning on, re-directing
stderr into the Nirwana, to avoid messages to stderr.
Another is needed and now added: We need to unset the DEVICE_URI
environment variable as the function searches for the device URI to
resolve there at first and not as argc[0]. Otherwise, if we are
running under CUPS, in a backend, we get the print queue's device URI
resolved and not the one which we supply.
We save and restore the value of DEVICE_URI to keep the impact as low
as possible.
2. ippfind_based_uri_converter()
In this function the ippfind utility is called in a fork and the
foreground (parent process) is getting ippfind's stdout through a
pipe. The main process is picking up the data to use it for resolving
the given URI. Here the parent process has unnecessarily: "dup"ed the
read end of the pipe to stdin, and then read the lines from
stdin. This prevents the calling program to use stdin by itself, for
example to receive print job data.
Now this is fixed by directly reading from the read end of the pipe.
Till Kamppeter [Thu, 30 Dec 2021 01:52:36 +0000 (22:52 -0300)]
implicitclass: Get printer info via IPP request and not via PPD
If we create a printer cluster with cups-browsed a PPD file covering
the capabilities of all member printers is genererated, which
especially does not represent the capabilities of a single member
printer which gets selected to print a particular job. It also does
not contain the infor about color spaces and color depths which can
vary from printer top printer.
For the implicitclass backend to have the exact information about the
destination printer so that it can call the filters correctly we now
poll this information directly from the printer, using a
get-printer-attributes IPP request. With this we get exact paper sizes
and margins and also the color spaces and color depth which are
especially needed if the printer gets the job as raster data
(Apple/PWG Raster, PCLm).
We completely ignore the print queue's PPD file here and so the
filters get used PPD-less only based on the printer's IPP attributes.
Till Kamppeter [Fri, 24 Dec 2021 01:52:20 +0000 (22:52 -0300)]
libcupsfilters: PCLm support in cupsRasterPrepareHeader()
The cupsRasterPrepareHeader() function only supported Apple/PWG/CUPS
Raster but not PCLm, leading to PCLm output often being broken,
especially when using the univeral() filter function.
Till Kamppeter [Wed, 22 Dec 2021 22:57:32 +0000 (19:57 -0300)]
cups-browsed: Updated naming of locally created print queues
Naming of local queues created by cups-browsed is now matched to CUPS'
current naming of temporary queues (no leading or trailing
underscores), to avoid duplicates in print dialogs which support CUPS'
temporary queues.
Till Kamppeter [Wed, 22 Dec 2021 22:17:53 +0000 (19:17 -0300)]
libcupsfilters: Removed pdftoippprinter.[ch]
As we have filter functions replacing practically all filters and can
call one or another external CUPS filter executable (driver) or even
backends via filterExternalCUPS(), we do not need any more the
apply_filters() API function to execute chains of external CUPS filter
executables. Therefore we remove this function.
Till Kamppeter [Wed, 22 Dec 2021 20:08:04 +0000 (17:08 -0300)]
cups-browsed, implicitclass: Let the implicitclass backend use filter functions
Let the implicitclass backend use filter functions instead of calling
filter executables, to make use with the latest development of
cups-filters.
- We use the universal() filter function, as this automatically
generates and executes a filter chain converting from a given input
to a given output format.
- In cupsfilters/filter.c we create functions to simplify adding the
FD_CLOEXEC and O_NONBLOCK (aka O_NDELAY) flags without losing any
already set flags.
- In the filterChain() filter function we make sure that the file
descriptors have the close-on-exec flag set, to assure that there
are no file descriptors left open or accessible by the executables
called by and of the filter functions in the chain.
- In filterExternalCUPS() we set O_NONBLOCK for stderr, back channel
and side channel.
- In filterChain(), when closing unneeded file descriptors, we do not
close FD 0 and FD 1 (stdin and stdout) as accidentally closing stdin
or stdout can break the data stream connection to/from a backend or
filter called by filterExternalCUPS() in the filter chain. Also
check each file descriptor separately for this, instead of only
checking one file descriptor and then close a group of file
descriptors.
- cups-browsed now removes the unneeded "*cupsFilter:..." lines from the
PPD for the local queue generated by cups-browsed, to assure that the
inserted line for application/vnd.cups-pdf gets used.
Till Kamppeter [Tue, 7 Dec 2021 21:58:54 +0000 (18:58 -0300)]
libcupsfilters: Added filterTee() filter function for debugging
This filter function is mainly for debugging. it resembles the "tee"
utility, passing through the data unfiltered and copying it to a
file. The file name is simply given as parameter. This makes using the
function easy (add it as item of a filter chain called via
filterChain()) and can even be used more than once in the same filter
chain (using different file names).
In case of write error to the copy file, copying is stopped but the
rest of the job is passed on to the next filter. If NULL is supplied
as file name, the data is simply passed through without getting
copied.
Till Kamppeter [Tue, 7 Dec 2021 01:44:45 +0000 (22:44 -0300)]
libcupsfilters: Fixed env variable handling in filterExternalCUPS()
- Do not forward blank environment variables (name is empty string)
into the environment of he called filter/backend.
- Do not match a given env variable name with a part of an existing
name (like CUPS_SERVER with CUPS_SERVERBIN). This way CUPS_SERVER in
the environment of the caller overwrote CUPS_SERVERBIN in the
environment of the filter to be called.
Till Kamppeter [Sat, 4 Dec 2021 23:40:53 +0000 (20:40 -0300)]
libcupsfilters: In universal() do not use pdftopdf() on vnd.cups-pdf input
application/pdf is raw, device-independent PDF, whereas
application/vnd.cups-pdf is PDF prepared for the output device,
usually with the page sizes and scalings adjusted to the output
printer and page management options, like N-up, applied.
The pdftopdf() filter function is to get from the former to the
latter. If we have input data which already has pdftopdf() applied, we
set the input format MIME type to application/vnd.cups-pdf to tell
that pdftopdf() is already done. In this case universal() should not
call pdftopdf() again.
This commit corrects the call of pdftopdf(), to be suppressed if the
input format is application/vnd.cups-pdf. On any other input format
which is going through PDF on the way to get converted into the output
format we call pdftopdf().
RFC7472 requires that 'ipps' must be used over HTTPS, but driverless
does not enforce encryption and will use insecure connection by
default. This makes it unusable with a printer that expects secure
connection only on 'ipps' port.
Till Kamppeter [Fri, 26 Nov 2021 12:53:43 +0000 (13:53 +0100)]
libppd: When running dynamic PPD generators wait for the process to finish
The PPD collection functions come from the cups-driverd daemon helper.
As cups-driverd did not run permanently (like cupsd or a Printer
Application) but was started for each request no sophisticated
clean-up was performed after responding to the request.
This fact was overlooked at some points when the functions were
transferred to libppd and supposed to be directly called by
permanently running Printer Applications. Here especially forked
processes for running dynamic PPD generator executables (the ones CUPS
uses in /usr/lib/cups/driver) were not waited for in the end. This
made them often dandling around as zombie processes and these could
accumulate during the life of a Printer Application process. See
https://github.com/OpenPrinting/cups-filters/issues/430.
This is fixed now by adding an appropriate function.
To avoid zombie processes dangling around during the life of a Printer
Application
Till Kamppeter [Thu, 25 Nov 2021 18:11:21 +0000 (19:11 +0100)]
libcupsfilters: In universal() error on invalis input/output formats
If invalid input and/or output formats get provided as parameters, the
universal() flter function simply silently chooses valid formats
instead of erroring out. This is fixed with this commit.
Till Kamppeter [Thu, 25 Nov 2021 16:25:48 +0000 (17:25 +0100)]
libcupsfilters: In pdftopdf() set a default for "print-scaling"
If no setting for "print-scaling" is provided via IPP attribute pr
command line option there is no default valur for it and we get
undefined behavior and also a scary "should never happen" message in
the log.
Now we check after parsing the appropriate IPP attributes and command
line options whether a setting was provided. If not, we use "auto".
Till Kamppeter [Thu, 25 Nov 2021 15:57:12 +0000 (16:57 +0100)]
libcupsfilters: In pdftops() simplify feeding data into post-processing
In post-processing we stop assigning the file descriptorof the input
pipe to stdin and then read the data from stdin but instead, read the
data directly from stdin.
Without this improvement in some cases, especially when we do not have
a PPD file, we are not able to get the output data of the previous
step (Poppler's pdftops or Ghostscript to turn PDF to PostScript, and
the really strange is that this only happens when we call pdftops()
from the universal() filter function).
Till Kamppeter [Thu, 25 Nov 2021 13:47:07 +0000 (14:47 +0100)]
libcupsfilters: In pdftops() call pstops() only if we have a PPD
After doing the actual PDF-to-PostScript conversion and afterwards
sometimes post-processing to work around PostScript interpreter bugs
in some PostScript printers we call the pstops() filter function to
insert the printer-specific PostScript instructions for the option
settings into the PostScript output data stream.
If there is no PPD file pstops() has nothing to do, and therefore we
simply skip it now. In addition, in absence of a PPD, some standard
PostScript code for standard options is inserted in the postprocessing
step.
Till Kamppeter [Wed, 24 Nov 2021 14:51:46 +0000 (15:51 +0100)]
libcupsfilters: in pdftops() simplified feeding data into pstops()
In the fork for running the pstops() filter function do notdo a file
descriptor redirection detour via stdin. pstops() accepts an input
file descriptor directly.
This made the pstops() filter not getting the job data when pdftops()
used Poppler's pdftops utility as PostScript interpreter when
pdftops() is called by the universal() filter function.
Till Kamppeter [Fri, 19 Nov 2021 21:22:27 +0000 (22:22 +0100)]
libcupsfilters: In universal() use Ghostscript for PDF-to-Raster
As Ghostscript is more optimized for print output we use now the
Ghostscript-based ghostscript() filter function to convert PDF into
PWG/CUPS Raster and not the Poppler-based pdftoraster() any more.
Later on we will add conditional compiling to use Poppler in a
Ghostscript-less build of cups-filters.
Till Kamppeter [Wed, 17 Nov 2021 19:44:57 +0000 (20:44 +0100)]
libcupsfilters: Let universal() pass FINAL_CONTENT_TYPE to pdftopdf()
pdftopdf() uses the FINAL_CONTENT_TYPE environment variable to
determine whether to log the printed pages and for other things, so
the universal() filter function should pass it through.
Till Kamppeter [Wed, 17 Nov 2021 18:42:32 +0000 (19:42 +0100)]
libcupsfilters: Fixed several bugs and did some clean-up in pdftopdf()
- Tested and corrected processing according to the "print-scaling" IPP
attribute, especially an A4 document on A4 destination page size got
shrinked by the width of the unprintable margins.
- Also tested and corrected N-up printing with all settings for
"print-scaling" and with documents containing pages of different
sizes and different orientations.
- On multi-page documents check each page (not only the first page) if
it is larger than the destination page size and with at least one
oversized page apply scale-to-fit/fill to all pages (if
"print-scaling"is "auto" or "auto-fit").
- On multi-page documents check each page individually whether it
needs to get rotated when determining how it should get cropped.
- Make sure that the page->crop() and page->is_landscape() do not
modify the /Rotate keys in the PDF. Save the key and restore it
before returning.
- Cleaned up the code for processing the pages, especially removed
code which never gets called, with any of the possible settings for
"print-scaling".
- For options use the options/num_options data structure which
contains both command line options and IPP attributes.
- Added more log messages, especially for the "print-scaling" and
"ipp-attribute-fidelity" IPP attributes.
Till Kamppeter [Mon, 15 Nov 2021 00:23:20 +0000 (01:23 +0100)]
MIME rules: Added application/vnd.cups-pdf-banner rule for universal filter
bannertopdf() is added to the universal() filter function now, so we
can tell CUPS that the universal CUPS filter accepts banner/test page
instruction files.
Till Kamppeter [Sun, 14 Nov 2021 23:38:31 +0000 (00:38 +0100)]
libcupsfilters: Let filterChain() pass through data on empty chain
If the supplied filter chain does not contain any filter or only
filter entries with the filter function set to NULL, we pass the data
through unchanged now, we simply not applying any filters.
This can happen when the universal() filter function is called iwth
the same MIME type for the input and for the output format
supplied. In such a case we simply want the data passed through.
Till Kamppeter [Wed, 10 Nov 2021 19:20:47 +0000 (20:20 +0100)]
driverless: Do not execute if NO_DRIVERLESS_PPDS env variable is set
If we have a Printer Application which wants to make available all the
CUPS drivers installed on the system (in the directories where CUPOS
would look for them), we have on many systems also the driverless
utility of cups-filters installed, linked into /usr/lib/cups/backend,
to discover driverless IPP printers, and in /usr/lib/cups/driver, to
auto-generate CUPS PPD files for them.
The Printer Application is supposed to make printers available which
use the installed drivers but does not need to make available
driverless IPP printers. Therefore we do not want that the Printer
Application executes the driverless utility to discover printers and
list possible PPD files for them. But we also do not want to remove
the driverless utility.
Therefore we add in this commit a facility to de-activate the
driverless utility by the presence of the NO_DRIVERLESS_PPDS
environment variable. If the variable is defined, the utility exits
right away when it gets called, not doing anything. So a Printer
Application looking for printers and PPD files by running CUPS
backends and dynamich PPD generator executables for CUPS in their
usual places in the file system can set the variable and a perhaps
installed driverless utility will simply do nothing and so the Printer
Application will not list all driverless IPP as supported with a
"driverless" driver choice.
The driverless utility is only thought out as a retro-fit of
driverless printers into classic printer setup tools (and as debugging
tool) but not for PPD-retro-fitting Printer Applications.
Till Kamppeter [Tue, 9 Nov 2021 23:35:20 +0000 (00:35 +0100)]
Build system: ENABLE_... conditionals in Makefile.am only for file inclusion
In makefile.am use "if ENABLE_..." conditionals only to decide which
files get included in general "make" and "make install" processes, not
for compilation rules. This way single filters can be built by "make
NAME" regardless whether appropriate "--enable-..." arguments got
supplied to "./configure".
Now we can do "make pstops" and make "make rastertopwg" without
appropriate arguments for "./configure".
Till Kamppeter [Mon, 8 Nov 2021 20:16:26 +0000 (21:16 +0100)]
Build system: Updated after addition of the universal() filter function
Now, with the cUPS filters all converted to filter functions the
filter executables which are installed into /usr/lib/cups/filter are
only small code stubs which convert the CUPS filter command line
arguments into the filter data and parameters for calling the filter
function and then calling the filter function itself.
With the addition of the universal() filter function, which
automatically converts any supported input format into any supported
output format by automatically creating an appropriate filter chain
there are two ways for interfacing the filter functions with CUPS now:
1. One individual executable for each filter functions: This makes
cups-filters behave as before. CUPS creates chains of the filters
needed for converting the job data to the required output format.
2. A single universal filter executable: This internally chains the
filter functions for getting the input data into the desired output
format. This is less resource-consuming as less external executables
have to be called by CUPS for processing each print job.
cups-filters can be built with either individual filter executables or
the universal filter executable, or also with both. This is controlled
by the "./configure" script with the "--enable-universal-cups-filter"
and "--enable-individual-cups-filters" command line arguments. Default
is to build only the universal filter executable. MIME conversion
rules are installed appropriate to the installed CUPS filter
executables.
Also done:
- Re-arranged the MIME conversion rules for using the classic,
individual CUPS filter executables and for using the universal
filter executable
- Require the QPDF version 10.3.2 and so removed the "./configure"
switch for QPDF not supporting PCLm
- Require CUPS 2.2.2 or newer and removed the "./configure" switch for
using urftopdf instead of Apple Raster support of libcups.
pranshukharkwal [Sun, 7 Nov 2021 17:24:54 +0000 (22:54 +0530)]
libcupsfilters, universal: Add a universal filter function to replace chains of individual filters
To execute a print job CUPS usually has to turn the input data format into PDF, ptocess the PDF with page management functions, like N-up, only even/odd pages, page selection, scaling, ..., and then turn the PDF into a data format understood by the printer. For this it calls a chain of several filters in most cases which causes an overhead of starting individual processes and data input/output.
To reduce this overhead we have here a single, universal filter function which calls a chain of one or more suitable individual filter functions using the filterChain() filter function. It take the input and output format MIME types as parameters and automatically determines a suitable combination of filters to do the desired conversion.
For use with CUPS, to have (except printer drivers) only one single filter for everything, we have also a filter executable as for the individual filters and a MIME conversion rules file to tell CUPS that it converts a wide range of input formats into a wide range of output formats. To not require n * m lines in the conversion rule file to support n input and m output formats, we use an auxiliary input MIME type to reduce the number of lines to n + m, and to allow easy addition and modification of formats as each format is only mentioned once in the file.
This universal filter function is the GSoC 2021 project of Pranshu Kharkwal (Pull Request #421, https://gist.github.com/pranshukharkwal/9413499a6744049ef549159948392023). Thanks a lot!
Till Kamppeter [Sat, 6 Nov 2021 16:18:24 +0000 (17:18 +0100)]
libcupsfilters: In ieee1284NormalizeMakeAndModel() remove "series" from model
We remove "series" from the model names when normalizing now, so we
also get a match if the printer list entry has "series" but the search
term not, or vice-versa (when both printer list enries and search
terms are normalized).
Till Kamppeter [Mon, 1 Nov 2021 22:25:52 +0000 (23:25 +0100)]
libcupsfilters: In ieee1284NormalizeMakeAndModel() also consider " - " as separator
Before, ieee1284NormalizeMakeAndModel() only considered ',', ';', and
'(' as separator between printer model name and extra info (driver,
version, language, ...). Now we also consider " - " (isolated dash) as
such a separator.
Till Kamppeter [Fri, 29 Oct 2021 13:03:02 +0000 (15:03 +0200)]
libcupsfilters: In bannertopdf() get printer name from filter data
In the bannertopdf() filter function get the print queue name from the
filter data and not from the PRINTER environment variable, as the
filter data is the standard source for this item in a filter function.
Till Kamppeter [Fri, 29 Oct 2021 09:04:22 +0000 (11:04 +0200)]
bannertopdf() templates: Adeed instructions to PDF templates
With the change on the bannertopdf() filter function of the previous
commit the template PDF files can get directly fed into bannertopdf()
and the instructions for adding printer- and job-specific text can be
embedded in the templates.
This commit adds the appropriate instructions to each template file,
to not break PDF integrity to the end. So one can even modify the
instructions without breaking the template itself.
If feeding banner instruction files into bannertopdf() as before, the
embedded instructions get ignored.
Also added files with only the instructions, the data/*-append.txt
files. They are not actually used but only FYI.
Till Kamppeter [Fri, 29 Oct 2021 07:50:15 +0000 (09:50 +0200)]
Improved bannertopdf() filter function
Main reason of the improvements is to make the bannertopdf() filter function
more suitable for Printer Applications, conserving its functionality for
CUPS.
Changes:
- Instead of a pair of an instruction file
(application/vnd.cups-pdf-banner) and a template PDF file we can
only use the template PDF file now, sending it as input file to the
filter function instead of the instruction file. The instruction
file content can be added to the PDF file as PDF comments,
preferrably at the end. If no instructions are added to the template
file, default instructions are used.
- Job-/Printer-related text added to a template file without PDF form
(according to "Show" instruction) is now cleaned up, not showing lines
at all for fields for which no content is supplied, instead of showing
"(null)" or nothing as content.
- Page dimensions are now also shown in centimeters and not only in
inches.
Till Kamppeter [Tue, 26 Oct 2021 17:02:59 +0000 (19:02 +0200)]
libppd: Merged libppdc into libppd, *.drv support for PPD collections
CUPS PPD compiler (ppdc) was mainly ported into cups-filters to get
driver information file (*.drv) support for PPD file collections, so
that it gets easier to retro-fit CUPS drivers into Printer
Applications if the drivers provide their PPD files as a driver
information file.
In a first approach the ppdc functionality simply got added by an
additional shared library (libppdc), but this would cause circular
dependencies between libppdc and libppd. Therefore we simply merge the
two into one library.
In addition, all PPD legacy support is in a single library now.
Also note that the ppdc functions are written in C++, so you need to
declare a program which uses them as C++ (give it a *.cxx or *.cpp and
not the simple *.c file name extension), even if the program itself is
written in simple C.
The functions for handling PPD collections nw also take into account
any driver information file (*.drv) in the directories supplied to
them, in addition to the already supported static PPD files, PPD file
tarballs, and PPD-generating executables, both for enumerating
available PPDs/drivers and for loading the actual PPD files.
Till Kamppeter [Mon, 25 Oct 2021 23:02:28 +0000 (01:02 +0200)]
Ported CUPS' PPD compiler into cups-filters
Together with PPD files the PPD compiler, which generates PPD files
from driver information files (*.drv) is deprecated in CUPS and will
get removed in CUPS 3.x.
CUPS 3.x and later (and also earlier CUPS versions when sandboxed,
like in a Snap) do not support classic CUPS drivers any more and need
Printer Applications (emulations of driverless IPP printers) for
non-driverless printers.
For retro-fitting classic CUPS drivers, consisting of PPD files, CUPS
filters, and CUPS backends, into Printer Applications without needing
to rewrite the driver (which can be old and the printer it supports
not at hand for testing) we wrap the driver into the Printer
Application without changing the driver itself (usually with the
pappl-retrofit library). Therefore we need to be able to handle PPD
files and especially also the driver information files (*.drv) which
some drivers use to generate their PPD files on-the-fly. Therefore we
conserve CUPS' PPD compiler here to be able to pre-build the PPDs (or
even also generate them on-the-fly) when retro-fitting the drivers
into Printer Applications.
In contrary to recent CUPS we provide the PPD compiler code as a
shared library (libppdc), so that other projects, like pappl-retrofit
can use it.
Note that this is only for retro-fitting existing printer drivers.
This should not motivate you to create new printer drivers using PPD
files or driver information files. Therefore we will also not add new
features to this code or to the corresponding file formats.
Till Kamppeter [Sun, 24 Oct 2021 09:07:28 +0000 (11:07 +0200)]
libcupsfilters: In texttopdf() did redirrection of stdout to outputfd
The texttopdf() filter function was missing the redirection of stdout
to the output file descriptor of the function call, outputfd.
On error of parsing the charset configuration file and loading the
fonts exit(1) was called which would kill the caller in a filter
function. This is corrected now, too.
The files filter/pdfutils.c and filter/pdfutils.h got moved into
libcupsfilters, for the texttopdf() filter function. But they did not
get removed from the filter/ directory and the build rules for
filter/test_pdf[12].c not updated to use the pdfutils files of the
library now.
Till Kamppeter [Fri, 22 Oct 2021 19:20:52 +0000 (21:20 +0200)]
libcupsfilters: In ieee1284NormalizeMakeAndModel() fix parsing device IDs
Some IEEE-1284 device IDs have spaces before and after the
manufacturer and model names. These need to be removed when generating
make-and-model strings for display, sorting, ... THis especially leads
to duplicate manufacturer names (extra mention of manufacturer in
model name) not being recognized and removed.
Till Kamppeter [Wed, 20 Oct 2021 14:51:15 +0000 (16:51 +0200)]
libcupsfilters: In pwgtoraster() with PPD do not modify header via IPP options
In the pwgtoraster() filter function, if we have a PPD file, we do not
call cupsRasterParseIPPOptions() as it sets the Raster header entries
solely by the names and choice names of the IPP attributes and command
line options, regardless of what the PPD supports. This broke some
jobs.
If we have a PPD, we need to convert IPP attributes into proper PPD
options before calling the filter functions (what is done by
libpappl-retrofit for example).
Till Kamppeter [Tue, 19 Oct 2021 10:14:11 +0000 (12:14 +0200)]
libppd: Added "FXOutputMode" of Fuji Xerox to auto-mapping
Fuji Xerox has several high-end printers which take jobs in PDF from
the pre-driverless-IPP era, for which they had the "fxlinuxprint"
driver. The PPD contains an "FXOutputMode" option with an odd
"Quality2" choice for high quality. Now it is solved by an explicit
treatment of this option.