How openprinting/cups-filters works
Project Type and Purpose
• This is an open-source printing-filter tool-chain for CUPS (Common UNIX Printing System).
• Its purpose is to provide a set of backends and filters that convert incoming print jobs (PDF, images, text, PCLm, etc.) into printer-specific output streams or raster formats, and to wrap error handling for CUPS backends.
High-Level Architecture Overview
a. Job Submission & Scheduler (CUPS daemon)
b. Filter Chain Layer (cups-filters)
c. Backend Layer & Driver/PPD Resources
Main Components
• CUPS Scheduler (external) – Accepts IPP jobs.
• Filter Chain:
– imagetopdf, texttopdf, pdftopdf, pdftoraster, pclmtoraster, universal, foomatic-rip, etc. (each in filter/).
– beh (backend error-handler wrapper in backend/beh.c).
• Driver Definitions (drv/*.drv and ppdfiles/*.ppd) – PPD templates and driver metadata.
• MIME Configuration (mime/*.convs, *.types) – Rules to select which filter to invoke.
• Backends (backend/parallel.c, serial.c, cupsfilters.drv) – Final transport layer (USB, socket, file).
• External Tools & Libraries: Ghostscript, Poppler, MuPDF, QPDF, libfontembed.
Relationships & Data Flow
1. Client submits job → CUPS Scheduler
2. Scheduler consults mime/*.convs to select first filter (e.g. PDF → pdftopdf).
3. Filters execute in a pipeline:
a. Convert images/text to PDF (imagetopdf, texttopdf)
b. Modify or paginate PDF (pdftopdf)
c. Rasterize for printing (pdftoraster, pclmtoraster)
d. (Optionally) wrap with foomatic-rip for proprietary drivers
4. Filter output is CUPS Raster or PCL stream → passed to backend.
5. beh wrapper optionally intercepts errors and retries or suppresses disabling.
6. Backend sends final byte stream to printer device or network URI.
Architectural Patterns & Principles
• Modular Filter Chain (pluggable CUPS filters)
• Pipeline Data Flow – each filter reads stdin, writes stdout
• Plugin/Convention-Based Integration via mime and PPD lookup
• Separation of Concerns: conversion (imagetopdf), PDF manipulation (pdftopdf), rasterization (pdftoraster), error handling (beh), transport (backend).
• External Tool Wrapping – Ghostscript, QPDF, Ghostscript devices are invoked where needed.
Technologies & Frameworks
• C language with Autotools build (configure.ac, Makefile.am, m4/*)
• CUPS Filter API (stdin/stdout interface, PPD parsing)
• libqpdf (PDF manipulation in pdftopdf)
• Ghostscript, Poppler, MuPDF (external rendering backends)
• libfontembed for text-to-PDF font embedding
• Shell scripts for test harness (filter/test.sh)