Skip to content

Subset already-embedded fonts during PDF compression - #253

Open
balazs-szucs wants to merge 1 commit into
feat/adobe-glyph-list-dictfrom
feat/font-compress-subset
Open

balazs-szucs wants to merge 1 commit into
feat/adobe-glyph-list-dictfrom
feat/font-compress-subset

Conversation

@balazs-szucs

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

Copy link
Copy Markdown
Collaborator

Description of Changes

Adds opt-in subsetting of already-embedded TrueType and OpenType fonts to PdfCompressor while keeping default compression behavior unchanged (subsetFonts=false). Subsetting verifies glyph mappings and advance widths before mutating any font stream and skips signed PDFs and shared descriptors.

Changed:

  • Export jpdfium_qpdf_subset_fonts in jpdfium.h and jpdfium_qpdf.cpp and wire QpdfLib FFM bindings.
  • Thread subsetFonts opt-in configuration through CompressOptions, CompressPreset, PdfCompressor, and PdfOptimizer.
  • Skip signed documents, shared font descriptors, and unknown encodings; verify subset outputs in PdfCompressorTest and PdfFontEmbedderRoundTripTest.

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 10, 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 d40e6e1 and 155c3c3.

Files selected for processing: 11

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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/doc/PdfOptimizer.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • native/bridge/include/jpdfium.h
  • native/bridge/src/jpdfium_qpdf.cpp
Summary

Summary by CodeRabbit

  • New Features
    • Added an option to reduce PDF file sizes by subsetting embedded fonts during compression. Font subsetting can be controlled through compression presets and optimizer options, and is applied only when supported and safe for the document.
  • Bug Fixes
    • Font audits now continue past pages that cannot be opened, and font checks handle empty PDF input without attempting to open a document.
    • Font embedding now handles additional font formats and matching cases more reliably.

Compression options now control embedded-font subsetting through a native qpdf operation. Font embedding and mapping behavior, font auditing, and round-trip validation also change.

Changes: PDF Font Processing

Layer / File(s) Summary
Subsetting options and API contract
jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java, .../CompressPreset.java, .../PdfOptimizer.java, native/bridge/include/jpdfium.h
Compression options and presets expose font subsetting. The Java optimizer and native header define the flag and operation contract.
Font selection, mapping, and auditing
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java, .../PdfFontAuditor.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java, native/bridge/src/jpdfium_qpdf.cpp
Java font embedding selects embeddable matches and normalizes font programs. Native font handling updates cmap, symbolic-font, and width processing. Auditing and round-trip checks change their handling of empty input, page-open failures, and font comparisons.
Native font subsetting
native/bridge/src/jpdfium_qpdf.cpp
The native qpdf path selects eligible embedded fonts, verifies and applies smaller subsets, and updates font data. The exported operation returns rewritten output and a subset count.
Compression integration and subset result
jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java, jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java, jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
QpdfLib binds the native operation. PdfCompressor invokes it under configured conditions and adopts a smaller result. A test checks the subset count, output size, and extracted text.

Possibly related PRs

Change: Feature

Merge Risk: High · previous review d40e6

Font subsetting is on by default in the builder and presets, and it can remove glyphs that pages still draw, so text can render blank after compression. A subsetting failure can also abort the whole compress call. Several of these defects, and the weakened tests that should catch them, need fixing before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: opt-in subsetting of already-embedded fonts during PDF compression. The raw summary shows this is the core of the changeset, touching PdfCompressor, CompressOptions, C…
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.
Description check Passed The description states the PR adds opt-in font subsetting to PdfCompressor with subsetFonts=false by default, and lists the changed areas (QpdfLib FFM wiring, CompressOptions/CompressPreset/PdfOptimiz…
Full details: Title check

Explanation

The title names the main change: opt-in subsetting of already-embedded fonts during PDF compression. The raw summary shows this is the core of the changeset, touching PdfCompressor, CompressOptions, CompressPreset, QpdfLib, and the native bridge.

Full details: Description check

Explanation

The description states the PR adds opt-in font subsetting to PdfCompressor with subsetFonts=false by default, and lists the changed areas (QpdfLib FFM wiring, CompressOptions/CompressPreset/PdfOptimizer options, tests) and safety checks (signed PDFs, shared descriptors, unknown encodings). It follows the template sections and most checklist items are ticked. Two gaps: the CHANGELOG item is unchecked, and the description does not link an issue ('Closes #(issue number)' is missing). Also, the raw summary shows CompressPreset sets subsetFonts=true for presets, which conflicts with the described default of false for compression behavior, and the description's test claim ('./gradlew :jpdfium:integrationTest passes') is not matched by the ./gradlew test checkbox being left unticked.

Resolution

Consider the following before merge: (1) Tick or resolve the unchecked CHANGELOG.md item, or explain why no user-facing entry is needed. (2) Add the linked issue reference in the 'Closes #(issue number)' line, or remove that line if no issue exists. (3) Clarify in the description whether CompressPreset presets (WEB, SCREEN, PRINT, LOSSLESS, MAXIMUM) enable subsetFonts=true, since this differs from the stated default of subsetFonts=false and may change default compression behavior for preset users. (4) Confirm whether ./gradlew test was run, since the checklist lists only integrationTest.

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 #245 November 10, 2026 18:07
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 43270a3 to d4aaf8c Compare November 11, 2026 00:10
Comment thread native/bridge/src/jpdfium_qpdf.cpp Fixed

@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: 16

Additional comments: 1

native/bridge/src/jpdfium_qpdf.cpp-2806-2810: 1

2806-2810: Minor · Stability & Availability · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Isolate failures per font.

subsetEmbeddedFontResource has no exception guard. Malformed objects can make qpdf throw from getKey, getArrayItem or newStream. One damaged font then aborts the whole pass. jpdfium_qpdf_subset_fonts returns JPDFIUM_ERR_NATIVE in that case. In the applyDocumentOptions path, the same exception fails an optimize that would otherwise succeed.

Catch std::exception around each font and skip that font. The per-font operations replace keys only after verification, so a skipped font keeps its original program.

Proposed fix

     for (auto& font : uniqueFonts) {
-        if (subsetEmbeddedFontResource(qpdf, lib, font, descriptorUseCount, streamUseCount))
-            ++subsetCount;
+        try {
+            if (subsetEmbeddedFontResource(qpdf, lib, font, descriptorUseCount, streamUseCount))
+                ++subsetCount;
+        } catch (std::exception const&) {
+            // Leave this font unchanged.
+        }
     }
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a23dcc2 and d4aaf8c.

Files selected for processing: 13

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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/doc/PdfOptimizer.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • native/bridge/include/jpdfium.h
  • native/bridge/include/jpdfium_font_encoding.h
  • native/bridge/src/adobe_glyph_names.inc
  • native/bridge/src/jpdfium_qpdf.cpp
Files not fully reviewed because they exceed a per-file size limit: 1

  • native/bridge/src/adobe_glyph_names.inc

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

Context from checks skipped due to timeout: 31

  • GitHub Check: Native bridge libFuzzer (ASan/UBSan, real PDFium)
  • GitHub Check: Samples E2E Suite (All 88 Feature Samples)
  • GitHub Check: JMH Benchmarks (advisory)
  • GitHub Check: Unit & Integration E2E Tests (Linux x64)
  • GitHub Check: Build & Verify (Compilation) (macos-15)
  • GitHub Check: GraalVM Native Image Smoke & E2E Test (Linux x64)
  • GitHub Check: Natural System Libvips & Downstream Integration (Linux x64)
  • GitHub Check: Robustness, Leak & Determinism Tests (Linux x64)
  • GitHub Check: Publish Maven Dry Run
  • GitHub Check: Build & Verify (Compilation) (ubuntu-latest)
  • GitHub Check: Build & Verify (Compilation) (windows-latest)
  • GitHub Check: Build patched PDFium and run Ghent V50
  • GitHub Check: CLI correctness & no-corruption tests
  • GitHub Check: Corpus (generate + native)
  • GitHub Check: Javadoc builds cleanly
  • GitHub Check: CodeQL Analysis (c-cpp)
  • GitHub Check: Java - SpotBugs + Checkstyle + PMD + Spotless
  • GitHub Check: CodeQL Analysis (java-kotlin)
  • GitHub Check: build-natives (linux-arm64, ubuntu-24.04-arm)
  • GitHub Check: build-natives (windows-x64, windows-latest)
  • GitHub Check: Restricted-env compat (no execstack + hermetic bundle)
  • GitHub Check: build-natives (windows-arm64, windows-11-arm)
  • GitHub Check: build-natives (darwin-x64, macos-15-intel)
  • GitHub Check: JaCoCo coverage (non-blocking ratchet)
  • GitHub Check: build-natives (linux-x64, ubuntu-latest)
  • GitHub Check: build-natives (darwin-arm64, macos-15)
  • GitHub Check: Bundle verify (symbols, RPATH, linkage, sizes)
  • GitHub Check: CodeQL (java-kotlin)
  • GitHub Check: Corpus + integration e2e
  • GitHub Check: Flaky-test guard (3× rerun)
  • GitHub Check: Samples E2E (88 features via RunAllSamples)
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/include/jpdfium.h
  • native/bridge/include/jpdfium_font_encoding.h
  • 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
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfOptimizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.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/PdfOptimizer.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • native/bridge/include/jpdfium.h
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java
  • native/bridge/include/jpdfium_font_encoding.h
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • native/bridge/src/jpdfium_qpdf.cpp
Learnings: 1

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
Additional comments: 9

native/bridge/include/jpdfium_font_encoding.h: 1

154-163: LGTM!

native/bridge/src/jpdfium_qpdf.cpp: 1

216-231: LGTM!

Also applies to: 3665-3701, 4422-4429

native/bridge/include/jpdfium.h: 1

570-571: LGTM!

Also applies to: 662-668

jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java: 1

134-139: LGTM!

Also applies to: 146-172

jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java: 1

34-34: LGTM!

Also applies to: 48-48, 88-92, 122-122, 153-153, 199-204

jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java: 1

11-21: LGTM!

Also applies to: 34-59, 69-69

jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfOptimizer.java: 1

30-31: LGTM!

jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java: 1

5-5: LGTM!

Also applies to: 368-368, 406-406, 431-431

jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java: 1

3-13: LGTM!

Also applies to: 49-79

Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
@balazs-szucs
balazs-szucs removed this pull request from stack #245 November 11, 2026 00:50
@balazs-szucs
balazs-szucs changed the base branch from feat/font-scanner-hardening to feat/adobe-glyph-list-dict November 11, 2026 00:50
@balazs-szucs
balazs-szucs added this pull request to stack #255 November 11, 2026 00:50
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch 2 times, most recently from bc9497b to ac39aaf Compare November 11, 2026 00:57
Comment thread native/bridge/src/jpdfium_qpdf.cpp Fixed
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 28ce8be to bf3c127 Compare November 11, 2026 13:14
@coderabbitai coderabbitai Bot mentioned this pull request Nov 11, 2026
8 of 12 tasks
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch 2 times, most recently from 7f18037 to 0fefffa Compare November 11, 2026 16:10
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch 2 times, most recently from 1bbd2ce to 51dce35 Compare November 11, 2026 16:46
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 51dce35 to e2b20bd Compare November 11, 2026 16:51
@balazs-szucs
balazs-szucs added this pull request to stack #269 November 11, 2026 22:56
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 13758b4 to eb16d3b Compare November 11, 2026 23:29
@balazs-szucs balazs-szucs reopened this Nov 11, 2026

@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: 4

Caution

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

⚠️ Outside diff range comments (1)

Minor · Reject empty PDF input instead of reporting success. · PdfFontEmbedder.java:228-230

jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java:228-230
Minor · Functional Correctness · Quick win

Reject empty PDF input instead of reporting success.

If pdf is null or empty, embedMissing now returns a result with no unresolved fonts and no valid PDF. A caller cannot distinguish that result from a completed no-op by inspecting its status lists. Reject the input, as embed(byte[], Map) does, before returning a result. As per coding guidelines: “Preserve stable public behavior. Flag incompatible ownership, exception, thread-access, output-format, or save semantics.”

Source: Coding guidelines

Additional comments: 1

jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java-877-878: 1

877-878: Major · Data Integrity & Integration · Heavy lift

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Update the whole-font checksum after changing cmap.

When sanitization changes a standalone TrueType font, the code updates the cmap directory checksum but leaves head.checkSumAdjustment unchanged. The returned font therefore fails the OpenType whole-font checksum requirement; a reader that validates it can reject the embedded program. Recalculate the adjustment after the table edit, and add a regression that validates the resulting font. (learn.microsoft.com) As per coding guidelines: “Validate semantic preservation through reopen, independent structural checks, and representative rendering/text properties.”

Source: Coding guidelines

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a99a2a6 and eb16d3b.

Files selected for processing: 9

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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/panama/QpdfLib.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • 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_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
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontAuditor.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.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/PdfFontAuditor.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressPreset.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfFontEmbedder.java
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/CompressOptions.java
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
  • 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-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

- Do not catch `Throwable` merely to swallow or log it. Catch broadly only at a justified boundary or cleanup guard, preserving fatal-error policy and cleanup ordering.

Applied to files:

  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfFontEmbedderRoundTripTest.java
Additional comments: 7

jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java: 1

148-148: Capability reporting still accepts the no-qpdf stub.

The supplied no-qpdf export resolves this handle but always returns -1. This method reports support, and subsetFonts then throws. The earlier capability finding remains applicable.

jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java: 3

359-359: The EXACT exclusion is still missing.

LOSSLESS enables subsetting, and this condition permits replacement despite preserve == true. Use the preservation guard and retain a regression with subsetting explicitly enabled. This repeats the earlier finding.


360-360: Subsetting failures still abort compression.

QpdfLib.subsetFonts throws for native failures, and this call has no recovery branch. The previous image-pass recovery and subsequent size fallback do not handle this exception. This repeats the earlier optional-pass failure finding.


361-363: Data Integrity & Integration

The native glyph collector scans annotation appearance streams (/AP with /N, /R, and /D). Both simple-font and CID-font subsetting use this collector, so the reported glyph-omission path does not occur.

jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java: 1

80-82: The rendering regression remains untested.

The assertion checks extracted text, not rendered glyphs. Add a source/output rendering comparison. This repeats the earlier test finding.

Based on learnings: “Validate semantic preservation through reopen, independent structural checks, and representative rendering/text properties.”

Source: Learnings

native/bridge/src/jpdfium_qpdf.cpp: 2

216-231: LGTM!


4500-4507: LGTM!

Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
Comment thread native/bridge/src/jpdfium_qpdf.cpp Resolved
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from eb16d3b to 84a5e27 Compare November 11, 2026 23:57
@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 84a5e27 to b2ec920 Compare November 12, 2026 00:14

@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.

Caution

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

⚠️ Outside diff range comments (2)

Major · Track font changes made through gs before removing glyphs. · jpdfium_qpdf.cpp:2108

native/bridge/src/jpdfium_qpdf.cpp:2108
Major · Data Integrity & Integration · Quick win

Track font changes made through gs before removing glyphs.

An ExtGState /Font entry can change the current font. (opensource.adobe.com)

scanContentStream handles Tf, but ignores this change. For /F1 12 Tf (A) Tj /F2 12 Tf /GS1 gs (B) Tj, where /GS1 selects /F1, the scan records only A for /F1. The new subset pass can then remove the independent B glyph while scan.complete remains true.

Resolve ExtGState /Font during scanning, or mark the scan incomplete when this entry occurs. Add a regression that checks the rendered B after subsetting.

Major · Reject unsupported encodings before destructive subsetting. · jpdfium_qpdf.cpp:1375-1376

native/bridge/src/jpdfium_qpdf.cpp:1375-1376
Major · Data Integrity & Integration · Quick win

Reject unsupported encodings before destructive subsetting.

MacExpertEncoding has mappings distinct from the three encodings collected by the new subset path. (opensource.adobe.com)

parseEncoding silently interprets it as Standard. Consequently, subsetEmbeddedSimpleFont can retain the wrong glyphs, and subsetKeepsSimpleGlyphs validates the same wrong interpretation. A used expert glyph outside the collected glyph set can disappear from the output.

Reject /MacExpertEncoding, including dictionary /BaseEncoding, before subsetting. The embedding path already has this guard at Line 2954. Reject other unsupported encodings rather than defaulting them to Standard.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between eb16d3b and d40e6e1.

Files selected for processing: 1

  • 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

Context from checks skipped due to timeout: 40

  • GitHub Check: Bundle verify (symbols, RPATH, linkage, sizes)
  • GitHub Check: GraalVM Native Image Smoke & E2E Test (Linux x64)
  • GitHub Check: README Quick Start Example (Linux x64)
  • GitHub Check: Build & Verify (Compilation) (windows-latest)
  • GitHub Check: Samples E2E Suite (All 88 Feature Samples)
  • GitHub Check: Publish Maven Dry Run
  • GitHub Check: Build & Verify (Compilation) (ubuntu-latest)
  • GitHub Check: Robustness, Leak & Determinism Tests (Linux x64)
  • GitHub Check: Restricted-env compat (no execstack + hermetic bundle)
  • GitHub Check: Build & Verify (Compilation) (macos-15)
  • GitHub Check: Natural System Libvips & Downstream Integration (Linux x64)
  • GitHub Check: Musl Native Detection (Alpine)
  • GitHub Check: Concurrency Stress Tests (Linux x64)
  • GitHub Check: JMH Benchmarks (advisory)
  • GitHub Check: Unit & Integration E2E Tests (Linux x64)
  • GitHub Check: CodeQL Analysis (java-kotlin)
  • GitHub Check: Module descriptor integrity
  • GitHub Check: Java - SpotBugs + Checkstyle + PMD + Spotless
  • GitHub Check: Corpus + integration e2e
  • GitHub Check: Public API compatibility (japicmp vs last release)
  • GitHub Check: CodeQL Analysis (c-cpp)
  • GitHub Check: FFM layout vs pinned PDFium headers
  • GitHub Check: C++ - clang-tidy + cppcheck + clang-format
  • GitHub Check: EditorConfig + whitespace hygiene
  • GitHub Check: Javadoc builds cleanly
  • GitHub Check: Corpus (generate + native)
  • GitHub Check: Shellcheck (scripts + native/*.sh)
  • GitHub Check: CodeQL (c-cpp)
  • GitHub Check: build-natives (windows-x64, windows-latest)
  • GitHub Check: CLI correctness & no-corruption tests
  • GitHub Check: build-natives (windows-arm64, windows-11-arm)
  • GitHub Check: CodeQL (java-kotlin)
  • GitHub Check: build-natives (linux-x64, ubuntu-latest)
  • GitHub Check: Samples E2E (88 features via RunAllSamples)
  • GitHub Check: build-natives (linux-arm64, ubuntu-24.04-arm)
  • GitHub Check: build-natives (darwin-x64, macos-15-intel)
  • GitHub Check: OSV vulnerability scan
  • GitHub Check: Flaky-test guard (3× rerun)
  • GitHub Check: build-natives (darwin-arm64, macos-15)
  • GitHub Check: JaCoCo coverage (non-blocking ratchet)
Additional context used

Code guidelines: 1

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

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_qpdf.cpp
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • native/bridge/src/jpdfium_qpdf.cpp

@balazs-szucs
balazs-szucs force-pushed the feat/font-compress-subset branch from 4af925b to 155c3c3 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.

2 participants