You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Repair CIDSet, widths, and CFF/PDF/X font handling in native bridge - #261
Added a strict font-embedding option that reports fonts that could not be embedded.
Expanded font character coverage and improved handling of Unicode text.
Bug Fixes
Font normalization now repairs incorrect character widths and coverage information, helping preserve text appearance and extraction.
Font subsetting is off by default and is accepted only when the result passes checks for page count, text, and visual output.
Improved handling of malformed PDF patterns and inline images during processing.
The pull request changes Java compression and font-embedding behavior, native font normalization and subsetting, and native handling of tiling-pattern step values. It adds checks and tests for PDF validity, extracted text, rendered output, font metadata, and unresolved fonts.
Changes: Font handling
Layer / File(s)
Summary
Compression controls and verification jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java, CompressPreset.java, PdfCompressor.java, jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java, CHANGELOG.md
Font subsetting is now opt-in, all presets disable Zopfli, and compression adopts a subsetted candidate only after validity, text, and rendering checks. Tests cover the defaults and pixel-identical output.
Font embedding and audit checks jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java, PdfFontAuditor.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderTest.java, PdfFontEmbedderRoundTripTest.java, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontCoverageTest.java, CHANGELOG.md
The Java API adds strict checks for unresolved fonts and validates font collection, symbolic-name, and cmap data. Audits now fail when a page cannot be opened. Tests check embedding failures, text, rendering, and subset-font use.
Native CID width and CIDSet repair native/bridge/src/jpdfium_advanced.cpp, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java, CHANGELOG.md
Normalization repairs CID /W widths and rebuilds /CIDSet from embedded-font mappings. Inline-image terminator recognition and subset output flags also change. Regression tests cover repaired widths, CIDSet coverage, and extracted text.
Native font discovery and subsetting native/bridge/src/jpdfium_qpdf.cpp, jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java, CHANGELOG.md
Native font processing changes content scanning, glyph mapping, /Widths, /ToUnicode, /CharSet, and /CIDSet handling. It traverses form and nested XObject resources, isolates failures per font, and changes the CFF fallback and no-qpdf stub.
Font normalization regression coverage jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Tests now expect CIDSet to cover the embedded program and check width repair and text extraction on issue20065.pdf.
Both native resource paths normalize invalid or excessive tiling-pattern /XStep and /YStep values. The qpdf path also traverses annotation appearances, nested XObjects, and Type 3 font resources.
Possibly related PRs
Stirling-Tools/JPDFium#247: Both changes use drawn CIDs to guide /W-related processing in separate code paths.
Stirling-Tools/JPDFium#271: Both changes update CID enumeration and subsetting behavior in jpdfium_advanced.cpp.
Stirling-Tools/JPDFium#263: Both changes touch the native font-subsetting contract and the compressor’s font-subsetting path.
Change: Bug fix
Merge Risk: Moderate · previous review 367b8
The pattern-step handling can alter the rendering of valid PDFs while leaving malformed stream patterns untouched. A crafted PDF can hang the opt-in font-subsetting path. Font repair can drop embedded programs or widths in edge cases. These should be fixed before merging.
Pre-merge checks: 3 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Description check
The description follows the template structure and most required items are checked. Two gaps remain. First, the CHANGELOG.md entry is unchecked, yet the raw summary shows CHANGELOG.md was updated with…
1. Check the CHANGELOG.md item, or explain why the Unreleased entries do not apply. 2. Add a 'Changed' bullet for each public or behavior change: CompressOptions.Builder subsetFonts default now false; CompressPreset useZopfliDeflate now fal…
Passed checks: 3 passed
Check name
Status
Explanation
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Title check
The title names the native bridge font work: CIDSet repair, /W widths, and CFF/PDF/X font handling. The changeset covers these areas, including CIDSet and /W repair in jpdfium_advanced.cpp and jpdfium…
Full details: Title check
Explanation
The title names the native bridge font work: CIDSet repair, /W widths, and CFF/PDF/X font handling. The changeset covers these areas, including CIDSet and /W repair in jpdfium_advanced.cpp and jpdfium_qpdf.cpp, and CFF handling for pre-1.6 PDFs. It does not mention the Java compression defaults, strict embedding, or the Type3 pattern clamping, which are also large parts of the change. The title is specific and accurate, but it is not a full summary.
Full details: Description check
Explanation
The description follows the template structure and most required items are checked. Two gaps remain. First, the CHANGELOG.md entry is unchecked, yet the raw summary shows CHANGELOG.md was updated with three Unreleased 'Fixed' entries, so the item should be checked and the description should acknowledge that. Second, the description does not cover the bulk of the change: the 'Changed' list omits the PDF compression defaults (subsetFonts now false, useZopfliDeflate now false), the new embedMissingStrict and Result.requireAllEmbedded public API, the PdfFontAuditor fail-on-unopenable-page change, the QpdfLib isSubsetFontsSupported change, and the removal of the jpdfium_qpdf_subset_fonts stub in the no-qpdf build. The 'Testing' item for new or updated tests is unchecked even though multiple test files were changed, and the 'Updated jpdfium.h and ABI notes' item is unchecked while the function removal in jpdfium_qpdf.cpp is an ABI-relevant change. The description also states that FFM declarations in QpdfLib.java expose native subsetting diagnostics, but the raw summary says only isSubsetFontsSupported changed, which does not match. The 'Closes #(issue number)' line is also missing.
Resolution
Check the CHANGELOG.md item, or explain why the Unreleased entries do not apply. 2. Add a 'Changed' bullet for each public or behavior change: CompressOptions.Builder subsetFonts default now false; CompressPreset useZopfliDeflate now false; new PdfFontEmbedder.embedMissingStrict and Result.requireAllEmbedded; PdfFontAuditor.audit now throws JPDFiumException on pages that cannot be opened; QpdfLib.isSubsetFontsSupported now also requires font replacement; removal of the jpdfium_qpdf_subset_fonts stub in the no-qpdf build. 3. Correct or explain the QpdfLib.java bullet, since the summary shows only isSubsetFontsSupported changed. 4. Check 'Added or updated tests' and list the test files touched (PdfCompressorTest, PdfFontEmbedderRoundTripTest, PdfFontEmbedderTest, FontCoverageTest, FontNormalizerTest). 5. Either update native/bridge/include/jpdfium.h and the ABI notes for the removed jpdfium_qpdf_subset_fonts function, or explain why no update is needed. 6. Add the 'Closes #(issue number)' reference.
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.
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
## Java 25 style
- Reuse repository formatting, naming, and visibility conventions. Do not recommend preview/incubator APIs or a higher Java requirement without explicit project agreement.
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
## Comments and documentation
- Remove stale TODOs, placeholder branches, speculative fallbacks, and obsolete comments in changed code. Do not require unrelated cleanup.
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.
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
- Fuzz operation sequences with a real state model and expected statuses, not only no-crash parsing. Bound inputs/work, preserve corpus, and instrument the relevant native code.
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
## Java 25 style
- Avoid boxing, stream pipelines, repeated string encoding, capturing callbacks, and temporary collections in demonstrated hot paths. Do not claim that source-level allocations survive JIT optimization without measurement.
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
## Java 25 style
- Use imports rather than package-qualified type names in method bodies and signatures. Qualification is acceptable for genuine name collisions, generated code, and intentionally explicit disambiguation.
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
## Memory and performance
- Scratch must support alignment, nesting, exceptions, overflow, and no escaping views. Resetting a bump pointer does not invalidate old FFM segments.
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
## Comments and documentation
- Keep ordinary inline comments to one or two concise sentences. Longer public contracts and subtle ABI/lifetime explanations are justified; do not shorten them until ambiguity remains.
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
## FFM and ABI
- Confined arenas must remain on their owner thread. An execution-backend change must account for caller-confined buffers; extracting an address is not a solution.
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
## FFM and ABI
- Validate pointer/length pairs and capacity before reinterpretation. Zero-length address views do not establish ownership or safe bounds.
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
## C++23 style and ownership
- Reject undefined behavior used as an optimization. Alias, alignment, lifetime, and CPU-feature assumptions must be true and tested.
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
## C++23 style and ownership
- Use `span`/`string_view` for bounded borrowing only when backing lifetime is established. Do not return dangling views or operation-workspace-backed results.
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
## C++23 style and ownership
- Explicitly finalize fallible writers and check the result. A nonthrowing destructor is fallback cleanup, not evidence of successful output.
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
## FFM and ABI
- Review native-image metadata and ABI probes when signatures change. Prefer reproducible generation to handwritten drift.
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
## C++23 style and ownership
- Keep destructors and C ABI cleanup nonthrowing. Exported boundaries translate exceptions; `noexcept` alone does not translate them.
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
## Output, preservation, and security
- Redaction must remove content, not merely paint an overlay. Extraction checks are scoped evidence, not proof about every PDF representation.
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
## Native integrations
- PDFium bitmap formats, row stride, alpha, and renderer behavior must be queried or explicitly guaranteed. Preserve public pixel semantics.
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.
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.
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.
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
## Java 25 style
- Use imports rather than package-qualified type names in method bodies and signatures. Qualification is acceptable for genuine name collisions, generated code, and intentionally explicit disambiguation.
[warning] 588-588: Use a randomly-generated IV
Context: byte[] staleCidSet = new byte[] {(byte) 0x80, 0, 0, 0, 0x08, 0, 0x20};
Note: [CWE-329] Generation of Predictable IV with CBC Mode.
(random-iv)
GitHub Check: CodeQL
native/bridge/src/jpdfium_pdfx.cpp
[notice] 259-259: Equality test on floating-point values
Equality checks on floating point values can yield unexpected results.
native/bridge/src/jpdfium_qpdf.cpp
[notice] 237-237: Equality test on floating-point values
Equality checks on floating point values can yield unexpected results.
[warning] 2220-2220: Poorly documented large function
Poorly documented function: fewer than 2% comments for a function of 110 lines.
balazs-szucs
changed the title
Repair CIDSet and widths and fail closed on unresolved fonts
Repair CIDSet, widths, and CFF/PDF/X font handling in native bridge
Nov 15, 2026
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
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.
Description of Changes
Repairs
/CIDSetstreams, CID/Wwidth arrays, CFF extraction, and PDF/X pattern/font invariants inside the native C++ bridge. Separating width calculation from descriptor mutation and fixing inline tiling-pattern dictionary checks prevents corrupt output on edge-case PDFs.Changed:
/CIDSetbitmasks,/Wwidths, and CFF re-subsetting injpdfium_advanced.cppandjpdfium_qpdf.cpp.jpdfium_pdfx.cppandjpdfium_qpdf.cpp.QpdfLib.javaFFM declarations to expose native subsetting diagnostics.Checklist
General
## [Unreleased]inCHANGELOG.mdLibrary changes
.github/workflows/compatibility.ymlexcludes the break with a reasondocs/installation.md, and the POMsNative or FFM changes
bash native/build-real.sh)./gradlew :jpdfium:integrationTestnative/bridge/include/jpdfium.hand the ABI notes for any ABI changeTesting
./gradlew :jpdfium:integrationTestpasses