Skip to content

Address the remaining font-stack review findings - #262

Open
balazs-szucs wants to merge 2 commits into
refactor/font-15b-compress-repair-javafrom
refactor/font-16-review-hardening
Open

balazs-szucs wants to merge 2 commits into
refactor/font-15b-compress-repair-javafrom
refactor/font-16-review-hardening

Conversation

@balazs-szucs

@balazs-szucs balazs-szucs commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description of Changes

Addresses cross-cutting review findings across the font audit, embedding, normalization, and compression stack. Hardens producer encoding preservation, fail-closed auditing, TTC bounds checking, and strict round-trip assertions so text and layout never silently degrade.

Changed:

  • Preserve producer encodings/flags, harden TTC directory bounds checking, and fail closed on unopenable pages in PdfFontAuditor, PdfFontEmbedder, and FontNormalizer.
  • Synchronize native font/PDF-X guards in jpdfium_advanced.cpp, jpdfium_pdfx.cpp, and jpdfium_qpdf.cpp.
  • Strengthen strict render, width, and text assertions in PdfCompressorTest, PdfFontEmbedderRoundTripTest, PdfFontEmbedderTest, and FontNormalizerTest.

Checklist

General

  • I have read the Contributing Guide
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Notable user-facing changes are recorded under ## [Unreleased] in CHANGELOG.md

Library changes

  • Javadoc covers any new or changed public type or member
  • Public API changes are additive, or .github/workflows/compatibility.yml excludes the break with a reason
  • Version references stay consistent across the README, docs/installation.md, and the POMs

Native or FFM changes

  • Rebuilt the bridge at the stack tip (bash native/build-real.sh)
  • Ran ./gradlew :jpdfium:integrationTest
  • Updated native/bridge/include/jpdfium.h and the ABI notes for any ABI change

Testing

  • Added or updated tests that cover the change
  • ./gradlew :jpdfium:integrationTest passes

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1d4c018 and ea02c32.

Files selected for processing: 11

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/fonts/FontNormalizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.cpp
  • native/bridge/src/jpdfium_pdfx.cpp
  • native/bridge/src/jpdfium_qpdf.cpp
Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved font embedding and subsetting reliability, including clearer reporting when a font cannot be safely embedded.
    • Improved font-width repair while preserving valid existing widths, and strengthened handling of malformed PDF content and pattern settings.
    • Improved font inventory for unmodified documents when source-file information is available.
  • Documentation
    • Clarified font-subsetting and font-width repair behavior.
  • Tests
    • Expanded coverage for font subsetting, embedding, text preservation, and width repair.

The change updates PDF font inventory, substitution, embedding, subsetting, and width-normalization paths. It tightens content-stream and font-map handling, adds integration tests for text and rendering preservation, and adjusts tiling-pattern step repair.

Changes: PDF Font Processing

Layer / File(s) Summary
Inventory and embedding eligibility
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java, jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java, native/bridge/src/jpdfium_qpdf.cpp, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedder*Test.java
Inventory can use the source file for eligible unmodified documents. Embedding records specific substitution blockers, caches font programs per operation, and adds checks for encodings and font coverage. Tests cover scan limits, Type 1 fonts, malformed collections, symbolic fonts, and text round trips.
Font subsetting and retained glyphs
native/bridge/src/jpdfium_qpdf.cpp, native/bridge/src/jpdfium_advanced.cpp, jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Subsetting verifies glyph mappings and advances, and derives CIDSet entries from retained glyphs. CFF conversion is restricted to eligible simple fonts. Tests cover compression subsetting and CIDSet output.
Content scanning and width repair
native/bridge/src/jpdfium_advanced.cpp, native/bridge/src/jpdfium_qpdf.cpp, jpdfium/src/main/java/stirling/software/jpdfium/fonts/FontNormalizer.java, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
The native lexer uses PDF-defined whitespace and validates inline-image boundaries. Width repair applies scan-completeness and preservation rules. Tests cover producer widths, multiple pages, and unresolved-width fixtures.

Tiling-Pattern Step Repair

Layer / File(s) Summary
Clamp tiling-pattern steps
native/bridge/src/jpdfium_pdfx.cpp, native/bridge/src/jpdfium_qpdf.cpp
Pattern-step repair replaces nonnumeric and out-of-range values with bounded values.

Possibly related PRs

Change: Bug fix

Merge Risk: Moderate · previous review 1d4c0

The new tiling-pattern step clamp does not run for stream-based patterns, so invalid step values can survive PDF/X repair. Negative widths on zero-advance glyphs can also remain after width repair. The round-trip tests can skip silently on a classpath fault, which weakens confidence in the font changes. Fix the pattern clamp and the width condition before merging.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description supplies a summary of changes and checks the template boxes. It omits the template's Closes #(issue) reference, the CHANGELOG entry (left unchecked), and the ABI/header note (left unch… Add a 'Closes #' reference or state that no issue applies. Either add the CHANGELOG.md entry under '## [Unreleased]' or explain why it is not needed. Confirm that no ABI change exists, and note that 'native/bridge/include/jpdfium.h' was not…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title "Address the remaining font-stack review findings" is specific to the font-handling changes in this PR, which cover font embedding, width repair, CIDSet, and encoding handling. It does not n…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Address the remaining font-stack review findings" is specific to the font-handling changes in this PR, which cover font embedding, width repair, CIDSet, and encoding handling. It does not name the single most important change, and "review findings" is somewhat generic, but it refers to the real scope of the changeset.

Full details: Description check

Explanation

The description supplies a summary of changes and checks the template boxes. It omits the template's Closes #(issue) reference, the CHANGELOG entry (left unchecked), and the ABI/header note (left unchecked, though the change set does not appear to alter exported declarations). The Testing item was changed from './gradlew test' to ':jpdfium:integrationTest' without a stated reason.

Resolution

Add a 'Closes #' reference or state that no issue applies. Either add the CHANGELOG.md entry under '## [Unreleased]' or explain why it is not needed. Confirm that no ABI change exists, and note that 'native/bridge/include/jpdfium.h' was not updated for that reason. State whether './gradlew test' was run, or explain why only the integration test applies.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@balazs-szucs
balazs-szucs added this pull request to stack #268 November 11, 2026 22:31
@balazs-szucs
balazs-szucs removed this pull request from stack #268 November 11, 2026 22:55
@balazs-szucs
balazs-szucs added this pull request to stack #269 November 11, 2026 22:56
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from d758c45 to d1b4fee Compare November 11, 2026 23:16
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from d1b4fee to ed4391f Compare November 11, 2026 23:29
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from ed4391f to 1f4d8d8 Compare November 11, 2026 23:57
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from 1f4d8d8 to 785669c Compare November 12, 2026 00:14
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch 2 times, most recently from 3796920 to 19aa68f Compare November 12, 2026 00:44
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from 19aa68f to 1d4c018 Compare November 12, 2026 03:11
@balazs-szucs

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit full review

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Clamp the stream dictionary. · jpdfium_pdfx.cpp:248

native/bridge/src/jpdfium_pdfx.cpp:248
Major · Stability & Availability · Quick win

Clamp the stream dictionary.

Tiling patterns are stream objects. QPDF reports streams and dictionaries as distinct types, so this guard returns before the new clamp runs. (raw.githubusercontent.com) An invalid /XStep or /YStep therefore remains in the output.

Use pattern.getDict() for streams. Add a regression that reopens a PDF/X output and checks both step values.

As per coding guidelines, “Every defect fix needs a focused regression with an observable expected result.”

Source: Coding guidelines

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 367b8c8 and 1d4c018.

Files selected for processing: 11

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/fonts/FontNormalizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.cpp
  • native/bridge/src/jpdfium_pdfx.cpp
  • native/bridge/src/jpdfium_qpdf.cpp

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Review details

Additional context used

Code guidelines: 1

.github/CODERABBIT_REVIEW.md — configured
Path-based instructions: 4

Apply the native ownership, C ABI, C++23, engine integration, memory, and SIMD rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • native/bridge/src/jpdfium_advanced.cpp
  • native/bridge/src/jpdfium_pdfx.cpp
  • native/bridge/src/jpdfium_qpdf.cpp
Enforce meaningful assertions, deterministic concurrency, failure-path cleanup, and explicit native/stub requirements.

CodeRabbit configuration file

Files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/fonts/FontNormalizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/fonts/FontNormalizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.cpp
  • native/bridge/src/jpdfium_pdfx.cpp
  • native/bridge/src/jpdfium_qpdf.cpp
Learnings: 2

Learning: 2026-10-31T10:47:27.879Z

Learnt from: CR
Repo: Stirling-Tools/JPDFium PR: 0
File: .github/CODERABBIT_REVIEW.md:0-0
Timestamp: 2026-10-31T10:47:27.879Z
Learning: Source excerpt:
# JPDFium review standards

## Tests, profiling, and delivery

- Validate semantic preservation through reopen, independent structural checks, and representative rendering/text properties. A successful open is insufficient.

Applied to files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
Learning: 2026-10-20T15:53:18.441Z

Learnt from: CR
Repo: Stirling-Tools/JPDFium PR: 0
File: .github/CODERABBIT_REVIEW.md:0-0
Timestamp: 2026-10-20T15:53:18.441Z
Learning: Source excerpt:
# JPDFium review standards

## Tests, profiling, and delivery

- Every defect fix needs a focused regression with an observable expected result. No `assertTrue(true)`, swallowed failures, or tests that silently pass when fixtures/tools/source roots are missing.

Applied to files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java

Comment thread native/bridge/src/jpdfium_advanced.cpp Resolved
Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from 6f28688 to dc4fbb4 Compare November 14, 2026 00:14
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from dc4fbb4 to 36c3911 Compare November 15, 2026 11:55
@balazs-szucs
balazs-szucs removed this pull request from stack #269 November 15, 2026 11:57
@balazs-szucs
balazs-szucs changed the base branch from refactor/font-15-compress-repair to refactor/font-15b-compress-repair-java November 15, 2026 11:58
@balazs-szucs
balazs-szucs added this pull request to stack #298 November 15, 2026 12:00
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from 36c3911 to 1015d92 Compare November 15, 2026 16:50
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from 1015d92 to e5b43bf Compare November 18, 2026 19:54
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from e5b43bf to f574665 Compare November 18, 2026 20:32
@balazs-szucs
balazs-szucs force-pushed the refactor/font-16-review-hardening branch from f574665 to ea02c32 Compare November 19, 2026 12:57

This branch has not been deployed

No deployments
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.

1 participant