[watermark] embed a bundled font so stamped PDFs are reproducible#350
Merged
Conversation
_build_watermark_overlay measures the watermark's true glyph extent by rasterizing it (pdf_oxide render_pixmap -> Pillow getbbox) and uses that extent to place the stamp. With the default base-14 "Times-Roman" - which carries no font program - pdf_oxide rasterizes with whatever font it finds on the host, so the measured extent, and thus the stamp position, differs from machine to machine. The resulting PDF is therefore not byte-identical across a dev box, CI, and production, which breaks the reproducible-build checksum tests downstream (arxiv-converter genpdf). Embed a bundled Nimbus Roman (URW's metrically-Times-compatible face, the Ghostscript default Times substitute) whenever the caller passes no custom font. pdf_oxide then rasterizes the embedded face itself, independent of host fonts, so the measurement - and the output - is identical everywhere. As a bonus the stamp now renders consistently in every PDF viewer instead of relying on a base-14 substitution. Verified byte-identical output between an Arch host and a fontless Debian container (differed before, identical after). The font is AGPL-3.0-only WITH PS-or-PDF-font-exception-20170817, which explicitly permits embedding and redistribution; the license text ships alongside it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_build_watermark_overlay measures the watermark's true glyph extent by rasterizing it (pdf_oxide render_pixmap -> Pillow getbbox) and uses that extent to place the stamp. With the default base-14 "Times-Roman" - which carries no font program - pdf_oxide rasterizes with whatever font it finds on the host, so the measured extent, and thus the stamp position, differs from machine to machine. The resulting PDF is therefore not byte-identical across a dev box, CI, and production, which breaks the reproducible-build checksum tests downstream (arxiv-converter genpdf).
Embed a bundled Nimbus Roman (URW's metrically-Times-compatible face, the Ghostscript default Times substitute) whenever the caller passes no custom font. pdf_oxide then rasterizes the embedded face itself, independent of host fonts, so the measurement - and the output - is identical everywhere. As a bonus the stamp now renders consistently in every PDF viewer instead of relying on a base-14 substitution.
Verified byte-identical output between an Arch host and a fontless Debian container (differed before, identical after). The font is AGPL-3.0-only WITH PS-or-PDF-font-exception-20170817, which explicitly permits embedding and redistribution; the license text ships alongside it.