Skip to content

Render text hinted on request: a hinting option of page.pixmap and Document.render (#612) - #623

Merged
yhay81 merged 1 commit into
mainfrom
claude/612-hinting-option
Nov 4, 2026
Merged

yhay81 merged 1 commit into
mainfrom
claude/612-hinting-option

Conversation

@yhay81

@yhay81 yhay81 commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Closes #612

hayro 0.9 hints text, and pyropdf turns that off so that the fonts it subsets draw as their originals (#18). page.pixmap(hinting=True) and Document.render(hinting=True) now render hinted on request, as hayro does with its default RenderSettings. Without the option every render stays as it was, so the change only adds to the public API.

Changes

  • render::Options gains hinting, off in Options::new, and render_settings takes it.
  • render_page and render_pages pass it through. The annotation appearance raster in annotations.rs stays unhinted; that line is outside the option but has to name the new field.
  • Page.pixmap and Document.render gain a keyword-only hinting: bool = False, documented with the note that hinted renders may differ before and after subset_fonts or a compacting save.
  • The API reference is regenerated. The issue names docs/en/api/rendering.md; these methods are generated into pages.md and documents.md.
  • The Rust tests in render/tests.rs, which the issue's paths omit, are there because only a Rust test can call hayro directly.

Acceptance

  • Without hinting, every render is the same, byte for byte, as before the option. Evidence is a one-off comparison, not committed: SHA-256 of page.pixmap() and Document.render() on the 86 pages hashed across the 15 corpus files (at most 40 per file), identical between a build of 614fb83 and this branch. test_hinting_changes_text_and_is_off_by_default keeps the default equal to hinting=False.
  • With hinting=True, text on a corpus page at 72 dpi renders as hayro renders it with its default RenderSettings, and differs from the unhinted render (hinting_renders_as_hayro_renders_with_its_default_settings, on pdf20-simple.pdf).
  • Document.render(..., hinting=True) returns what page.pixmap(hinting=True).to_bytes(...) returns for each page (test_document_render_hints_as_page_pixmap_does), and a render after one with the other setting, through a shared RenderCache, equals a fresh one (a_render_cache_keeps_hinted_and_unhinted_glyphs_apart, test_a_render_with_one_hinting_after_the_other_equals_a_fresh_one).
  • A hinting that is not a bool is refused with TypeError (test_hinting_must_be_a_bool).

Checks

Run locally on Windows: ruff, ruff format, ty, cargo fmt, clippy, and cargo test pass. Clippy and the hayro comparison test were rerun after the last edit, a one-line clippy fix in that test; cargo test as a whole was not. pytest ended with 6577 passed and 16 failed, the same 16 that failed on the #608 branch, in test_pdfua_corpus, test_structural_check, and test_structure_page_deletion. They read PDF fixtures that this checkout holds with CRLF line endings (i/lf w/crlf); that cause is inferred from the byte diffs and was not confirmed on an LF checkout, so CI on Linux is the check for them.

No claim about rendering speed: a hinted render was not measured, and the default does not change.

Left for the owner to review and merge.

🤖 Generated with Claude Code

…cument.render (#612)

hayro 0.9 hints text, which sharpens small text, and pyropdf turns that off
so that the fonts it subsets draw as their originals (#18). `hinting=True`
renders as hayro does with its default settings. Without the option every
render stays as it was, so the change only adds to the public API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render text hinted on request: a hinting option of page.pixmap and Document.render

1 participant