proof-pdf 0.3.3__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/PKG-INFO +56 -2
  2. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/README.md +55 -1
  3. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/pyproject.toml +1 -1
  4. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/__init__.py +4 -2
  5. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/contrast.py +3 -0
  6. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/fonts.py +64 -0
  7. proof_pdf-0.3.5/src/proof_pdf/_internal/functions.py +233 -0
  8. proof_pdf-0.3.5/src/proof_pdf/_internal/interactive.py +286 -0
  9. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/paint.py +110 -8
  10. proof_pdf-0.3.5/src/proof_pdf/_internal/previews.py +269 -0
  11. proof_pdf-0.3.5/src/proof_pdf/_internal/spots.py +55 -0
  12. proof_pdf-0.3.5/src/proof_pdf/_internal/tables.py +230 -0
  13. proof_pdf-0.3.5/src/proof_pdf/_internal/tagged.py +193 -0
  14. proof_pdf-0.3.5/src/proof_pdf/_internal/vector.py +675 -0
  15. proof_pdf-0.3.5/src/proof_pdf/_internal/xmp.py +76 -0
  16. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/cli.py +125 -1
  17. proof_pdf-0.3.5/src/proof_pdf/crop.py +56 -0
  18. proof_pdf-0.3.5/src/proof_pdf/extract.py +873 -0
  19. proof_pdf-0.3.5/src/proof_pdf/layout.py +625 -0
  20. proof_pdf-0.3.5/tests/test_proof_pdf/test_crop.py +92 -0
  21. proof_pdf-0.3.5/tests/test_proof_pdf/test_extract.py +631 -0
  22. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_public_api.py +1 -1
  23. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/LICENSE +0 -0
  24. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/NOTICE +0 -0
  25. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/__init__.py +0 -0
  26. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/colour.py +0 -0
  27. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/config.py +0 -0
  28. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/content.py +0 -0
  29. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/deltae.py +0 -0
  30. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/proc.py +0 -0
  31. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/resolution.py +0 -0
  32. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/spaces.py +0 -0
  33. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/structure.py +0 -0
  34. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/text.py +0 -0
  35. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/_internal/verapdf.py +0 -0
  36. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/config.py +0 -0
  37. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/core.py +0 -0
  38. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/inventory.py +0 -0
  39. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/models.py +0 -0
  40. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/preview.py +0 -0
  41. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/py.typed +0 -0
  42. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/src/proof_pdf/texlog.py +0 -0
  43. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/build_pdfs.py +0 -0
  44. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/black-text.pdf +0 -0
  45. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/corrupt.pdf +0 -0
  46. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/cyan-text.pdf +0 -0
  47. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/edge-text.pdf +0 -0
  48. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/embedded-text.pdf +0 -0
  49. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/good.pdf +0 -0
  50. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/hairline.pdf +0 -0
  51. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/heavy-ink.pdf +0 -0
  52. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/high-contrast.pdf +0 -0
  53. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/low-contrast.pdf +0 -0
  54. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/low-dpi-image.pdf +0 -0
  55. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/no-bleed.pdf +0 -0
  56. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/no-output-intent.pdf +0 -0
  57. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/notdef-text.pdf +0 -0
  58. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/plain.pdf +0 -0
  59. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/registration-spot.pdf +0 -0
  60. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/rgb-image.pdf +0 -0
  61. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/rich-black-text.pdf +0 -0
  62. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/small-text.pdf +0 -0
  63. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/spot-ink.pdf +0 -0
  64. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/three-pages.pdf +0 -0
  65. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/transparent-matching.pdf +0 -0
  66. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/transparent-mismatch.pdf +0 -0
  67. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/transparent-undeclared.pdf +0 -0
  68. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/two-sizes.pdf +0 -0
  69. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/type3-text.pdf +0 -0
  70. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/white-overprint.pdf +0 -0
  71. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/pdfs/wrong-size.pdf +0 -0
  72. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/suites/README.md +0 -0
  73. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/fixtures/suites/expected.toml +0 -0
  74. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/__init__.py +0 -0
  75. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/conftest.py +0 -0
  76. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_bleed.py +0 -0
  77. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_cli.py +0 -0
  78. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_colour.py +0 -0
  79. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_config.py +0 -0
  80. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_content.py +0 -0
  81. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_contrast.py +0 -0
  82. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_core.py +0 -0
  83. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_deltae.py +0 -0
  84. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_fixtures_current.py +0 -0
  85. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_integration.py +0 -0
  86. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_inventory.py +0 -0
  87. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_load_profile.py +0 -0
  88. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_paint.py +0 -0
  89. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_preview.py +0 -0
  90. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_proc.py +0 -0
  91. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_resolution.py +0 -0
  92. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_structure.py +0 -0
  93. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_suites.py +0 -0
  94. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_texlog.py +0 -0
  95. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_text.py +0 -0
  96. {proof_pdf-0.3.3 → proof_pdf-0.3.5}/tests/test_proof_pdf/test_verapdf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: proof-pdf
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Hold print PDFs to PDF/X-4 and PDF/A: veraPDF, page boxes, geometry, ink and image resolution.
5
5
  Keywords: pdf,pdf/x-4,pdf/a,verapdf,prepress,print,preflight,ghostscript,lualatex
6
6
  Author-Email: Ilja Orlovs <ilja@release.art>
@@ -150,6 +150,8 @@ typo cannot silently switch a check off.
150
150
  ```zsh
151
151
  proof-pdf inspect card.pdf # fonts (embedded?, .notdef), text colours and sizes, spot inks, images, contrast
152
152
  proof-pdf inspect card.pdf --json # the same as data, for other tools
153
+ proof-pdf extract old/brochure.pdf # recover images, fonts, ICC profiles, vector artwork and text into old/brochure/
154
+ proof-pdf extract old/brochure.pdf --previews # ...plus old/brochure/previews/index.html to review it
153
155
  proof-pdf texlog build/card.log # dropped characters, TeX errors, undefined references, substituted fonts, overfull boxes
154
156
  proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-profile FOGRA51.icc
155
157
  ```
@@ -159,7 +161,59 @@ proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-p
159
161
  undefined references are errors; font substitution, package warnings, a pending rerun and overfull boxes are warnings
160
162
  (`--max-overfull-pt N` promotes the worst overfull boxes).
161
163
 
162
- The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, and the checks are
164
+ `extract` is for the archive: a customer's old PDF is all that is left of a job, and you want its logo, pictograms and
165
+ photos back. It writes `images/`, `fonts/`, `icc/` and `vector/` (one cropped PDF per piece of artwork, ready for
166
+ `\includegraphics`) and a `document.json` with the page boxes, every asset's placements in points from the page's
167
+ bottom-left, every text run with font, size, colour and position (and the runs joined into lines), and the plain rectangles and rules of
168
+ the layout.
169
+ Vector artwork has no names in a PDF, so pieces are found by grouping shapes that touch (`--gap-pt`) and ignoring
170
+ anything covering more than `--max-fraction` of the page; clips are not applied and text is not part of a piece.
171
+ `document.json` also holds what a template rebuild needs: `metadata.xmp` (the XMP packet decoded, also saved as `xmp.xml`;
172
+ InDesign writes its fonts, plates and swatches there), `palette`, and `layout`. The layout reads the page back from where
173
+ the text sits: the type styles in use and what each is for (body, heading levels, small print), the paragraphs with their
174
+ alignment, indent and spacing, the text columns, margins and content box of every page, the running headers, footers and
175
+ folios, and a `summary` of the numbers a document class takes (page size, margins, columns, gutter, measure, body font,
176
+ size and leading). It is inferred from geometry, so treat it as evidence to check against the page, not as fact; datasheets
177
+ full of tables read poorly, flowing text well.
178
+
179
+ `interactive` lists the form fields (with type, value, font and size, so a fillable certificate comes back as a form), the
180
+ links and where they go, the outline, page labels, layers and attachments. A digital signature is described by who, when
181
+ and how it was made, never copied. Text lying on a piece of artwork (dimensions on a drawing, labels on a diagram) is
182
+ drawn into that piece's PDF and listed in its `details.text`, as well as recovered as text; `--no-vector-text` leaves the
183
+ pieces as the drawn shapes alone.
184
+
185
+ `spot_colours` names every ink the file paints with and what it stands in for on screen (the tint transform evaluated at
186
+ full tint: a PANTONE usually comes back as Lab, a die-line as a CMYK tint); the printer's ink book, not this, says what the
187
+ ink really is. `layout.pages[].tables` are tables read from their rules, with cells, spans and text, so a results table or
188
+ a product list comes back as rows and columns rather than as scattered text; they need rules (a table made of whitespace
189
+ alone is not found).
190
+
191
+ For a tagged PDF (Word, InDesign and Acrobat export them), `structure` is what the producer said each piece is: which
192
+ text is a level-2 heading, where a paragraph or table cell begins and ends, a figure's alt text (the nearest thing a PDF has
193
+ to a name for an image or drawing, copied to the asset as `details.alt`), and its own alignment, indent and spacing
194
+ numbers. Where the file is tagged it is better evidence than the geometry, and the layout uses it for heading roles and
195
+ paragraph boundaries; an untagged file (`structure.tagged` is false) is read from geometry alone. Fonts carry their
196
+ descriptor facts (bold, italic, weight, flags, metrics).
197
+
198
+ `crop` is for what the extraction missed: it cuts a rectangle out of one page as a one-page PDF, exactly as the page
199
+ shows it (text stays text, vectors stay vectors, images keep their pixels).
200
+
201
+ ```zsh
202
+ proof-pdf crop old/brochure.pdf --page 14 --box 64,300,556,607 --pad-pt 2 --out figure-14.pdf
203
+ ```
204
+
205
+ The box is `X0,Y0,X1,Y1` in points from the page's bottom-left, the numbers `document.json` gives every placement (`x`, `y`,
206
+ `x + width`, `y + height`) and the review page shows under the mouse; from a preview PNG at a given dpi, a pixel is
207
+ `x = media_x0 + px / dpi * 72`, `y = media_y1 - py / dpi * 72`. In code, `proof_pdf.crop.crop_page(path, page, box, out)`.
208
+ The piece also holds the rest of the page's content outside the window, which a viewer does not show; rasterise it when
209
+ that matters.
210
+
211
+ `--previews` renders `previews/index.html` (needs Ghostscript): each page with every recovered asset boxed on it and
212
+ linked to its thumbnail below, so a whole archive job can be reviewed by eye. Text in fonts without a `/ToUnicode` map
213
+ cannot be read from the PDF; `document.json` says so in `notes` and keeps the font codes. Mind who owns the artwork you
214
+ recover.
215
+
216
+ The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, `proof_pdf.extract.extract_pdf(path, out_dir)` writes the assets and returns what it found, and the checks are
163
217
  functions over an opened `pikepdf.Pdf`.
164
218
 
165
219
  ## Docker images
@@ -124,6 +124,8 @@ typo cannot silently switch a check off.
124
124
  ```zsh
125
125
  proof-pdf inspect card.pdf # fonts (embedded?, .notdef), text colours and sizes, spot inks, images, contrast
126
126
  proof-pdf inspect card.pdf --json # the same as data, for other tools
127
+ proof-pdf extract old/brochure.pdf # recover images, fonts, ICC profiles, vector artwork and text into old/brochure/
128
+ proof-pdf extract old/brochure.pdf --previews # ...plus old/brochure/previews/index.html to review it
127
129
  proof-pdf texlog build/card.log # dropped characters, TeX errors, undefined references, substituted fonts, overfull boxes
128
130
  proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-profile FOGRA51.icc
129
131
  ```
@@ -133,7 +135,59 @@ proof-pdf verify card.pdf --safe-mm 3 --min-text-pt 6 --min-delta-l 30 --proof-p
133
135
  undefined references are errors; font substitution, package warnings, a pending rerun and overfull boxes are warnings
134
136
  (`--max-overfull-pt N` promotes the worst overfull boxes).
135
137
 
136
- The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, and the checks are
138
+ `extract` is for the archive: a customer's old PDF is all that is left of a job, and you want its logo, pictograms and
139
+ photos back. It writes `images/`, `fonts/`, `icc/` and `vector/` (one cropped PDF per piece of artwork, ready for
140
+ `\includegraphics`) and a `document.json` with the page boxes, every asset's placements in points from the page's
141
+ bottom-left, every text run with font, size, colour and position (and the runs joined into lines), and the plain rectangles and rules of
142
+ the layout.
143
+ Vector artwork has no names in a PDF, so pieces are found by grouping shapes that touch (`--gap-pt`) and ignoring
144
+ anything covering more than `--max-fraction` of the page; clips are not applied and text is not part of a piece.
145
+ `document.json` also holds what a template rebuild needs: `metadata.xmp` (the XMP packet decoded, also saved as `xmp.xml`;
146
+ InDesign writes its fonts, plates and swatches there), `palette`, and `layout`. The layout reads the page back from where
147
+ the text sits: the type styles in use and what each is for (body, heading levels, small print), the paragraphs with their
148
+ alignment, indent and spacing, the text columns, margins and content box of every page, the running headers, footers and
149
+ folios, and a `summary` of the numbers a document class takes (page size, margins, columns, gutter, measure, body font,
150
+ size and leading). It is inferred from geometry, so treat it as evidence to check against the page, not as fact; datasheets
151
+ full of tables read poorly, flowing text well.
152
+
153
+ `interactive` lists the form fields (with type, value, font and size, so a fillable certificate comes back as a form), the
154
+ links and where they go, the outline, page labels, layers and attachments. A digital signature is described by who, when
155
+ and how it was made, never copied. Text lying on a piece of artwork (dimensions on a drawing, labels on a diagram) is
156
+ drawn into that piece's PDF and listed in its `details.text`, as well as recovered as text; `--no-vector-text` leaves the
157
+ pieces as the drawn shapes alone.
158
+
159
+ `spot_colours` names every ink the file paints with and what it stands in for on screen (the tint transform evaluated at
160
+ full tint: a PANTONE usually comes back as Lab, a die-line as a CMYK tint); the printer's ink book, not this, says what the
161
+ ink really is. `layout.pages[].tables` are tables read from their rules, with cells, spans and text, so a results table or
162
+ a product list comes back as rows and columns rather than as scattered text; they need rules (a table made of whitespace
163
+ alone is not found).
164
+
165
+ For a tagged PDF (Word, InDesign and Acrobat export them), `structure` is what the producer said each piece is: which
166
+ text is a level-2 heading, where a paragraph or table cell begins and ends, a figure's alt text (the nearest thing a PDF has
167
+ to a name for an image or drawing, copied to the asset as `details.alt`), and its own alignment, indent and spacing
168
+ numbers. Where the file is tagged it is better evidence than the geometry, and the layout uses it for heading roles and
169
+ paragraph boundaries; an untagged file (`structure.tagged` is false) is read from geometry alone. Fonts carry their
170
+ descriptor facts (bold, italic, weight, flags, metrics).
171
+
172
+ `crop` is for what the extraction missed: it cuts a rectangle out of one page as a one-page PDF, exactly as the page
173
+ shows it (text stays text, vectors stay vectors, images keep their pixels).
174
+
175
+ ```zsh
176
+ proof-pdf crop old/brochure.pdf --page 14 --box 64,300,556,607 --pad-pt 2 --out figure-14.pdf
177
+ ```
178
+
179
+ The box is `X0,Y0,X1,Y1` in points from the page's bottom-left, the numbers `document.json` gives every placement (`x`, `y`,
180
+ `x + width`, `y + height`) and the review page shows under the mouse; from a preview PNG at a given dpi, a pixel is
181
+ `x = media_x0 + px / dpi * 72`, `y = media_y1 - py / dpi * 72`. In code, `proof_pdf.crop.crop_page(path, page, box, out)`.
182
+ The piece also holds the rest of the page's content outside the window, which a viewer does not show; rasterise it when
183
+ that matters.
184
+
185
+ `--previews` renders `previews/index.html` (needs Ghostscript): each page with every recovered asset boxed on it and
186
+ linked to its thumbnail below, so a whole archive job can be reviewed by eye. Text in fonts without a `/ToUnicode` map
187
+ cannot be read from the PDF; `document.json` says so in `notes` and keeps the font codes. Mind who owns the artwork you
188
+ recover.
189
+
190
+ The library offers the same as data: `proof_pdf.inventory.inspect_pdf(path)` returns plain dataclasses, `proof_pdf.extract.extract_pdf(path, out_dir)` writes the assets and returns what it found, and the checks are
137
191
  functions over an opened `pikepdf.Pdf`.
138
192
 
139
193
  ## Docker images
@@ -37,7 +37,7 @@ dependencies = [
37
37
  "pillow>=12.3.0",
38
38
  "typer>=0.27.3",
39
39
  ]
40
- version = "0.3.3"
40
+ version = "0.3.5"
41
41
 
42
42
  [project.urls]
43
43
  Homepage = "https://github.com/release-art/proofpress"
@@ -8,8 +8,10 @@ coverage, overprint, rich-black small text, stray RGB, effective image DPI).
8
8
  The entry point is :func:`proof_pdf.core.verify_file`; the CLI group lives in
9
9
  :mod:`proof_pdf.cli` and is the ``proof-pdf`` console script.
10
10
 
11
- Public API is the top-level modules (:mod:`~proof_pdf.core`, :mod:`~proof_pdf.models`, :mod:`~proof_pdf.inventory`,
12
- :mod:`~proof_pdf.preview`, :mod:`~proof_pdf.texlog`, :mod:`~proof_pdf.config`, :mod:`~proof_pdf.cli`) and the
11
+ Public API is the top-level modules (:mod:`~proof_pdf.core`, :mod:`~proof_pdf.models`,
12
+ :mod:`~proof_pdf.inventory`,
13
+ :mod:`~proof_pdf.extract`, :mod:`~proof_pdf.crop`, :mod:`~proof_pdf.layout`, :mod:`~proof_pdf.preview`,
14
+ :mod:`~proof_pdf.texlog`, :mod:`~proof_pdf.config`, :mod:`~proof_pdf.cli`) and the
13
15
  :func:`~proof_pdf.config.load_profile` re-export. Everything under ``proof_pdf._internal`` (the checks, the content and
14
16
  paint walks, the tool wrappers, the config reader) is private and may change at any time.
15
17
 
@@ -159,6 +159,9 @@ def describe(fill: Fill | None) -> str:
159
159
  if fill.family == RGB and len(fill.value) >= 3:
160
160
  r, g, b = (round(v * 255) for v in fill.value[:3])
161
161
  return f"RGB({r},{g},{b})"
162
+ if fill.spot:
163
+ tint = f" {round(fill.value[0] * 100)}%" if len(fill.spot) == 1 and fill.value else ""
164
+ return f"spot {'+'.join(fill.spot)}{tint}"
162
165
  return "a spot or pattern colour"
163
166
 
164
167
 
@@ -14,6 +14,8 @@ import pikepdf
14
14
 
15
15
  _SUBSET_PREFIX = re.compile(r"^[A-Z]{6}\+")
16
16
  _IDENTITY = ("/Identity-H", "/Identity-V")
17
+ _ADOBE_COLLECTIONS = ("GB1", "CNS1", "Korea1") # Japan1 differs from ASCII at a few Latin CIDs, so it is left out
18
+ _ADOBE_LATIN_CIDS, _ADOBE_LATIN_OFFSET = 95, 31 # CID 1 is the space, U+0020
17
19
  _FALLBACK_WIDTH = 500.0 # per 1000 em; typical of a text face
18
20
  _DEFAULT_ASCENT, _DEFAULT_DESCENT = 800.0, -200.0
19
21
 
@@ -32,6 +34,19 @@ class Font:
32
34
  descent: float = _DEFAULT_DESCENT
33
35
  composite: bool = False
34
36
  decodable: bool = True # False for a composite font whose encoding is not Identity: codes can't be split reliably
37
+ to_unicode: dict[int, str] = dataclasses.field(default_factory=dict)
38
+ adobe_latin: bool = False # an Adobe GB1/CNS1/Korea1 CID font: CIDs 1-95 are ASCII 0x20-0x7E by definition
39
+
40
+ def text(self, codes: list[int]) -> str | None:
41
+ """The characters *codes* show: from ``/ToUnicode``, else (for an Adobe CJK collection) the Latin CIDs, else
42
+ Latin-1 for a simple font, else ``None`` (unknown)."""
43
+ if self.to_unicode or self.adobe_latin:
44
+ shown = [self.to_unicode.get(code) or self._latin(code) or "\N{REPLACEMENT CHARACTER}" for code in codes]
45
+ return "".join(shown) if self.to_unicode or any(c != "\N{REPLACEMENT CHARACTER}" for c in shown) else None
46
+ return None if self.composite else bytes(code & 0xFF for code in codes).decode("latin-1")
47
+
48
+ def _latin(self, code: int) -> str | None:
49
+ return chr(code + _ADOBE_LATIN_OFFSET) if self.adobe_latin and 1 <= code <= _ADOBE_LATIN_CIDS else None
35
50
 
36
51
  def decode(self, data: bytes) -> list[int]:
37
52
  """The character codes in a shown string."""
@@ -82,6 +97,7 @@ def _load(font: pikepdf.Object) -> Font:
82
97
  default_width=missing or (_FALLBACK_WIDTH if not widths else 0.0),
83
98
  widths=widths,
84
99
  notdef_codes=_notdef_codes(font.get("/Encoding")),
100
+ to_unicode=_to_unicode(font.get("/ToUnicode")),
85
101
  ascent=float(descriptor.get("/Ascent", _DEFAULT_ASCENT)) if descriptor is not None else _DEFAULT_ASCENT,
86
102
  descent=float(descriptor.get("/Descent", _DEFAULT_DESCENT)) if descriptor is not None else _DEFAULT_DESCENT,
87
103
  )
@@ -101,13 +117,61 @@ def _load_composite(font: pikepdf.Object, name: str) -> Font:
101
117
  default_width=float(descendant.get("/DW", 1000)),
102
118
  widths=_cid_widths(descendant.get("/W")),
103
119
  notdef_codes=frozenset(),
120
+ to_unicode=_to_unicode(font.get("/ToUnicode")),
104
121
  ascent=float(descriptor.get("/Ascent", _DEFAULT_ASCENT)) if descriptor is not None else _DEFAULT_ASCENT,
105
122
  descent=float(descriptor.get("/Descent", _DEFAULT_DESCENT)) if descriptor is not None else _DEFAULT_DESCENT,
106
123
  composite=True,
107
124
  decodable=identity,
125
+ adobe_latin=identity and _adobe_collection(descendant),
126
+ )
127
+
128
+
129
+ def _adobe_collection(descendant: pikepdf.Object) -> bool:
130
+ info = descendant.get("/CIDSystemInfo")
131
+ return (
132
+ info is not None and str(info.get("/Registry")) == "Adobe" and str(info.get("/Ordering")) in _ADOBE_COLLECTIONS
108
133
  )
109
134
 
110
135
 
136
+ _BF_CHAR = re.compile(rb"beginbfchar(.*?)endbfchar", re.DOTALL)
137
+ _BF_RANGE = re.compile(rb"beginbfrange(.*?)endbfrange", re.DOTALL)
138
+ _BF_TOKEN = re.compile(rb"<[^>]*>|\[|\]")
139
+
140
+
141
+ def _hex(token: bytes) -> bytes:
142
+ return bytes.fromhex(re.sub(rb"[<>\s]", b"", token).decode())
143
+
144
+
145
+ def _to_unicode(stream: pikepdf.Object | None) -> dict[int, str]:
146
+ """A ``/ToUnicode`` CMap's ``bfchar`` and ``bfrange`` entries as code -> text; empty if absent or unreadable."""
147
+ if stream is None:
148
+ return {}
149
+ try:
150
+ data = bytes(stream.read_bytes())
151
+ mapping: dict[int, str] = {}
152
+ for block in _BF_CHAR.findall(data):
153
+ tokens = _BF_TOKEN.findall(block)
154
+ for src, dst in zip(tokens[::2], tokens[1::2], strict=False):
155
+ mapping[int.from_bytes(_hex(src))] = _hex(dst).decode("utf-16-be", "replace")
156
+ for block in _BF_RANGE.findall(data):
157
+ tokens, i = _BF_TOKEN.findall(block), 0
158
+ while i + 2 < len(tokens):
159
+ low, high = int.from_bytes(_hex(tokens[i])), int.from_bytes(_hex(tokens[i + 1]))
160
+ if tokens[i + 2] == b"[":
161
+ end = tokens.index(b"]", i + 2)
162
+ for code, dst in zip(range(low, high + 1), tokens[i + 3 : end], strict=False):
163
+ mapping[code] = _hex(dst).decode("utf-16-be", "replace")
164
+ i = end + 1
165
+ else:
166
+ base = _hex(tokens[i + 2]).decode("utf-16-be", "replace")
167
+ for offset in range(min(high - low, 0xFFFF) + 1):
168
+ mapping[low + offset] = base[:-1] + chr(ord(base[-1]) + offset) if base else ""
169
+ i += 3
170
+ return mapping
171
+ except pikepdf.PdfError, ValueError, IndexError, TypeError, OverflowError:
172
+ return {}
173
+
174
+
111
175
  def _embedded(descriptor: pikepdf.Object | None) -> bool:
112
176
  return descriptor is not None and any(k in descriptor for k in ("/FontFile", "/FontFile2", "/FontFile3"))
113
177
 
@@ -0,0 +1,233 @@
1
+ """PDF functions, enough to turn a spot colour's tint into the colour it stands in for.
2
+
3
+ A ``/Separation`` or ``/DeviceN`` colour space carries a tint transform: a function from the tint(s) to the alternate
4
+ space (usually CMYK). Evaluating it at full tint says what ink mixture a PANTONE or a die-line stands for on screen and
5
+ in proofs. All four function types are read (sampled, exponential, stitching, PostScript calculator); anything this does
6
+ not understand, or that runs away, gives ``None`` rather than a wrong colour.
7
+ """
8
+
9
+ import math
10
+ import re
11
+ import typing
12
+
13
+ import pikepdf
14
+
15
+ _MAX_STEPS = 20000 # a calculator function is a few dozen operators; a runaway one is a malformed file
16
+ _MAX_DEPTH = 8
17
+
18
+
19
+ def evaluate(function: pikepdf.Object, inputs: list[float], *, depth: int = 0) -> list[float] | None:
20
+ """The function's outputs for *inputs*, or None when it is of a kind or shape not understood."""
21
+ if depth > _MAX_DEPTH:
22
+ return None
23
+ try:
24
+ kind = int(function["/FunctionType"])
25
+ domain = [float(v) for v in function["/Domain"]]
26
+ x = [min(max(v, domain[2 * i]), domain[2 * i + 1]) for i, v in enumerate(inputs)]
27
+ if kind == 2:
28
+ out = _exponential(function, x[0])
29
+ elif kind == 3:
30
+ out = _stitching(function, x[0], domain, depth)
31
+ elif kind == 0:
32
+ out = _sampled(function, x, domain)
33
+ elif kind == 4:
34
+ out = _calculator(function, x)
35
+ else:
36
+ return None
37
+ return _clip(function, out)
38
+ except KeyError, IndexError, TypeError, ValueError, ZeroDivisionError, OverflowError, pikepdf.PdfError:
39
+ return None
40
+
41
+
42
+ def _clip(function: pikepdf.Object, out: list[float] | None) -> list[float] | None:
43
+ if out is None or "/Range" not in function:
44
+ return out
45
+ bounds = [float(v) for v in function["/Range"]]
46
+ return [min(max(v, bounds[2 * i]), bounds[2 * i + 1]) for i, v in enumerate(out) if 2 * i + 1 < len(bounds)]
47
+
48
+
49
+ def _exponential(function: pikepdf.Object, x: float) -> list[float]:
50
+ c0 = [float(v) for v in function.get("/C0", [0.0])]
51
+ c1 = [float(v) for v in function.get("/C1", [1.0])]
52
+ exponent = float(function["/N"])
53
+ return [a + x**exponent * (b - a) for a, b in zip(c0, c1, strict=True)]
54
+
55
+
56
+ def _stitching(function: pikepdf.Object, x: float, domain: list[float], depth: int) -> list[float] | None:
57
+ parts = list(function["/Functions"])
58
+ bounds = [float(v) for v in function.get("/Bounds", [])]
59
+ encode = [float(v) for v in function["/Encode"]]
60
+ edges = [domain[0], *bounds, domain[1]]
61
+ i = next((k for k in range(len(parts)) if x < edges[k + 1]), len(parts) - 1)
62
+ lo, hi = edges[i], edges[i + 1]
63
+ mapped = encode[2 * i] + ((x - lo) / (hi - lo) if hi != lo else 0.0) * (encode[2 * i + 1] - encode[2 * i])
64
+ return evaluate(parts[i], [mapped], depth=depth + 1)
65
+
66
+
67
+ def _sampled(function: pikepdf.Object, x: list[float], domain: list[float]) -> list[float]:
68
+ """The nearest sample (no interpolation): exact at the tints a spot colour is asked about, 0 and 1."""
69
+ size = [int(v) for v in function["/Size"]]
70
+ bits = int(function["/BitsPerSample"])
71
+ bounds = [float(v) for v in function["/Range"]]
72
+ outputs = len(bounds) // 2
73
+ encode = [float(v) for v in function.get("/Encode", [v for s in size for v in (0, s - 1)])]
74
+ decode = [float(v) for v in function.get("/Decode", bounds)]
75
+ data = bytes(function.read_bytes())
76
+ index, stride = 0, 1
77
+ for i, value in enumerate(x):
78
+ span = domain[2 * i + 1] - domain[2 * i]
79
+ e = encode[2 * i] + ((value - domain[2 * i]) / span if span else 0.0) * (encode[2 * i + 1] - encode[2 * i])
80
+ index += min(max(round(e), 0), size[i] - 1) * stride
81
+ stride *= size[i]
82
+ top = (1 << bits) - 1
83
+ result = []
84
+ for j in range(outputs):
85
+ start = (index * outputs + j) * bits
86
+ first, last = start // 8, (start + bits + 7) // 8
87
+ piece = data[first:last]
88
+ if not piece:
89
+ raise ValueError("sample table is shorter than its Size says")
90
+ sample = (int.from_bytes(piece, "big") >> (len(piece) * 8 - start % 8 - bits)) & top
91
+ result.append(decode[2 * j] + sample / top * (decode[2 * j + 1] - decode[2 * j]))
92
+ return result
93
+
94
+
95
+ # ---------------------------------------------------------------------------------------- PostScript calculator
96
+
97
+ _TOKEN = re.compile(rb"[{}]|[^\s{}]+")
98
+
99
+
100
+ def _calculator(function: pikepdf.Object, x: list[float]) -> list[float]:
101
+ program = _parse(_TOKEN.findall(bytes(function.read_bytes())), [0])
102
+ stack: list[typing.Any] = list(x)
103
+ _run(program[0] if len(program) == 1 and isinstance(program[0], list) else program, stack, [0])
104
+ outputs = len(function["/Range"]) // 2
105
+ return [float(v) for v in stack[-outputs:]]
106
+
107
+
108
+ def _parse(tokens: list[bytes], at: list[int]) -> list[typing.Any]:
109
+ items: list[typing.Any] = []
110
+ while at[0] < len(tokens):
111
+ token = tokens[at[0]]
112
+ at[0] += 1
113
+ if token == b"{":
114
+ items.append(_parse(tokens, at))
115
+ elif token == b"}":
116
+ return items
117
+ else:
118
+ items.append(token.decode("latin-1"))
119
+ return items
120
+
121
+
122
+ def _number(text: str) -> float | None:
123
+ try:
124
+ return float(text)
125
+ except ValueError:
126
+ return None
127
+
128
+
129
+ _UNARY: dict[str, typing.Callable[[float], float]] = {
130
+ "abs": abs,
131
+ "neg": lambda a: -a,
132
+ "ceiling": lambda a: float(math.ceil(a)),
133
+ "floor": lambda a: float(math.floor(a)),
134
+ "round": lambda a: float(math.floor(a + 0.5)),
135
+ "truncate": lambda a: float(math.trunc(a)),
136
+ "sqrt": math.sqrt,
137
+ "sin": lambda a: math.sin(math.radians(a)),
138
+ "cos": lambda a: math.cos(math.radians(a)),
139
+ "ln": math.log,
140
+ "log": math.log10,
141
+ "cvi": lambda a: float(math.trunc(a)),
142
+ "cvr": float,
143
+ }
144
+ _BINARY: dict[str, typing.Callable[[typing.Any, typing.Any], typing.Any]] = {
145
+ "add": lambda a, b: a + b,
146
+ "sub": lambda a, b: a - b,
147
+ "mul": lambda a, b: a * b,
148
+ "div": lambda a, b: a / b,
149
+ "idiv": lambda a, b: float(int(a) // int(b)),
150
+ "mod": lambda a, b: float(math.fmod(int(a), int(b))),
151
+ "exp": lambda a, b: a**b,
152
+ "atan": lambda a, b: math.degrees(math.atan2(a, b)) % 360,
153
+ "eq": lambda a, b: a == b,
154
+ "ne": lambda a, b: a != b,
155
+ "gt": lambda a, b: a > b,
156
+ "ge": lambda a, b: a >= b,
157
+ "lt": lambda a, b: a < b,
158
+ "le": lambda a, b: a <= b,
159
+ "and": lambda a, b: a and b if isinstance(a, bool) else float(int(a) & int(b)),
160
+ "or": lambda a, b: a or b if isinstance(a, bool) else float(int(a) | int(b)),
161
+ "xor": lambda a, b: a != b if isinstance(a, bool) else float(int(a) ^ int(b)),
162
+ "bitshift": lambda a, b: float(int(a) << int(b) if b >= 0 else int(a) >> -int(b)),
163
+ }
164
+
165
+
166
+ def _run(program: list[typing.Any], stack: list[typing.Any], steps: list[int]) -> None:
167
+ i = 0
168
+ while i < len(program):
169
+ steps[0] += 1
170
+ if steps[0] > _MAX_STEPS:
171
+ raise ValueError("calculator function does not end")
172
+ word = program[i]
173
+ i += 1
174
+ if isinstance(word, list): # a procedure waiting for if / ifelse
175
+ nxt = program[i] if i < len(program) else None
176
+ if nxt == "if":
177
+ i += 1
178
+ if stack.pop():
179
+ _run(word, stack, steps)
180
+ elif isinstance(nxt, list) and i + 1 < len(program) and program[i + 1] == "ifelse":
181
+ i += 2
182
+ _run(word if stack.pop() else nxt, stack, steps)
183
+ continue
184
+ _word(word, stack)
185
+
186
+
187
+ def _roll(stack: list[typing.Any]) -> None:
188
+ shift, count = int(stack.pop()), int(stack.pop())
189
+ if count:
190
+ part = stack[-count:]
191
+ shift %= count
192
+ stack[-count:] = part[-shift:] + part[:-shift] if shift else part
193
+
194
+
195
+ def _copy(stack: list[typing.Any]) -> None:
196
+ count = int(stack.pop())
197
+ stack.extend(stack[-count:] if count else [])
198
+
199
+
200
+ def _exch(stack: list[typing.Any]) -> None:
201
+ stack[-1], stack[-2] = stack[-2], stack[-1]
202
+
203
+
204
+ def _not(stack: list[typing.Any]) -> None:
205
+ top = stack.pop()
206
+ stack.append(not top if isinstance(top, bool) else float(~int(top)))
207
+
208
+
209
+ _STACK: dict[str, typing.Callable[[list[typing.Any]], None]] = {
210
+ "pop": lambda stack: stack.pop(),
211
+ "dup": lambda stack: stack.append(stack[-1]),
212
+ "exch": _exch,
213
+ "copy": _copy,
214
+ "index": lambda stack: stack.append(stack[-1 - int(stack.pop())]),
215
+ "roll": _roll,
216
+ "not": _not,
217
+ "true": lambda stack: stack.append(True),
218
+ "false": lambda stack: stack.append(False),
219
+ }
220
+
221
+
222
+ def _word(word: str, stack: list[typing.Any]) -> None:
223
+ if (value := _number(word)) is not None:
224
+ stack.append(value)
225
+ elif word in _UNARY:
226
+ stack.append(_UNARY[word](stack.pop()))
227
+ elif word in _BINARY:
228
+ b, a = stack.pop(), stack.pop()
229
+ stack.append(_BINARY[word](a, b))
230
+ elif word in _STACK:
231
+ _STACK[word](stack)
232
+ else:
233
+ raise ValueError(f"unknown operator {word}")