Skip to content

Add opt-in re-subsetting for tagged fonts - #263

Open
balazs-szucs wants to merge 4 commits into
refactor/font-16-review-hardeningfrom
refactor/font-17-tagged-subset
Open

balazs-szucs wants to merge 4 commits into
refactor/font-16-review-hardeningfrom
refactor/font-17-tagged-subset

Conversation

@balazs-szucs

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

Copy link
Copy Markdown
Collaborator

Description of Changes

Adds opt-in re-subsetting for embedded fonts that already carry an ABCDEF+ subset prefix tag (CompressOptions.reSubsetTaggedFonts(boolean)). Default behavior continues to skip tagged producer subsets while allowing callers to reclaim extra space when needed under existing safety gates.

Changed:

  • Add reSubsetTaggedFonts option to CompressOptions and thread it through PdfCompressor, QpdfLib, JpdfiumLib, and jpdfium_qpdf_subset_fonts in jpdfium.h/jpdfium_qpdf.cpp.
  • Update GraalVM reachability metadata JSON files for the updated native downcall signature.
  • Add opt-in re-subsetting verification tests in PdfCompressorTest.

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 9e04fbb and c71efba.

Files selected for processing: 9

  • 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/panama/JpdfiumLib.java
  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java
  • jpdfium/src/main/resources/META-INF/native-image/com.stirling/jpdfium/reachability-metadata.json
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • native/bridge/include/jpdfium.h
  • native/bridge/src/jpdfium_qpdf.cpp
  • reachability-metadata/metadata/com.stirling/jpdfium/1.2.0/reachability-metadata.json
Summary

Summary by CodeRabbit

  • New Features
    • PDF compression now offers an opt-in setting to re-subset fonts that have already been subsetted. By default, those fonts remain unchanged, preserving existing behavior. Enable the setting when you want compression to process tagged fonts again.

The change adds an opt-in for re-subsetting fonts with existing subset tags and passes it through the Java and native font-subsetting interfaces. It also adds an integration test and closes page handles used during text comparisons.

Changes: Tagged font subsetting

Layer / File(s) Summary
Option and Java-to-native forwarding
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/panama/QpdfLib.java, jpdfium/src/main/resources/META-INF/native-image/.../reachability-metadata.json, reachability-metadata/metadata/.../reachability-metadata.json
CompressOptions adds reSubsetTaggedFonts, which defaults to false. PdfCompressor passes the value to QpdfLib, which forwards it through the native binding.
Native tagged-font handling
native/bridge/include/jpdfium.h, native/bridge/src/jpdfium_qpdf.cpp
The native subsetting entry point accepts the option. Tagged fonts remain skipped when it is false; when true, recognized tags are removed before subsequent processing.
Tagged-font integration test
jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
The test checks the default behavior, initial font subsetting, and the explicit re-subsetting option.

Page-handle closure

Layer / File(s) Summary
Close page handles after text comparison
jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.java
sameText obtains both pages as PdfPage handles and closes them after comparing extracted text.

Possibly related PRs

  • Stirling-Tools/JPDFium#253: Adds the native font-subsetting entry point and Java binding that this change extends with the tagged-font option.

Change: Feature

Merge Risk: Moderate · previous review 9e04f

The new tagged-font option changes the native function signature without bumping the ABI version. A mismatched native library would then be accepted at load time and could crash the process instead of failing cleanly. The new test also would not detect the option being ignored. Bump the ABI version and tighten the test before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: an opt-in option that re-subsets fonts already carrying a subset tag. The changeset adds CompressOptions.reSubsetTaggedFonts, threads it through PdfCompressor and Qpdf…
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 follows the template's Description of Changes section with a clear summary of the opt-in re-subsetting option and the files it threads through. Checklist items are mostly ticked. One i…
Full details: Title check

Explanation

The title names the main change: an opt-in option that re-subsets fonts already carrying a subset tag. The changeset adds CompressOptions.reSubsetTaggedFonts, threads it through PdfCompressor and QpdfLib, and updates the native bridge. The title matches the changeset and the PR objectives. Minor naming mismatch: the description and objectives refer to subsetTaggedFonts(boolean), while the code uses reSubsetTaggedFonts. This does not affect the title's relevance.

Full details: Description check

Explanation

The description follows the template's Description of Changes section with a clear summary of the opt-in re-subsetting option and the files it threads through. Checklist items are mostly ticked. One item is unchecked: the CHANGELOG.md entry under Unreleased. The PR also contains a mismatch: the description names CompressOptions.reSubsetTaggedFonts(boolean), while the PR objectives name CompressOptions.subsetTaggedFonts(boolean). The description also lists the Javadoc and version-reference checks as done without showing evidence of them. It does not include an explicit 'Closes #' issue reference, although the template comment asks for one.

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 force-pushed the refactor/font-17-tagged-subset branch from c9a48a6 to e041b80 Compare November 11, 2026 22:56
@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-17-tagged-subset branch from e041b80 to 30b2695 Compare November 11, 2026 23:16
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch 2 times, most recently from bb80e25 to bf08f6f Compare November 11, 2026 23:40
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from bf08f6f to 0bc7913 Compare November 11, 2026 23:57
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from 0bc7913 to f7bffa2 Compare November 12, 2026 00:14
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from f7bffa2 to 3853ca1 Compare November 12, 2026 00:37
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from 3853ca1 to aee84f6 Compare November 12, 2026 00:44
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from aee84f6 to 6c4f8cf Compare November 12, 2026 03:11

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

Review info

Run configuration

Commits

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

Files selected for processing: 8

  • 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/panama/QpdfLib.java
  • jpdfium/src/main/resources/META-INF/native-image/com.stirling/jpdfium/reachability-metadata.json
  • jpdfium/src/test/java/stirling/software/jpdfium/doc/PdfCompressorTest.java
  • native/bridge/include/jpdfium.h
  • native/bridge/src/jpdfium_qpdf.cpp
  • reachability-metadata/metadata/com.stirling/jpdfium/1.2.0/reachability-metadata.json

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: 44

  • GitHub Check: README Quick Start Example (Linux x64)
  • GitHub Check: Unit & Integration E2E Tests (Linux x64)
  • GitHub Check: Build & Verify (Compilation) (ubuntu-latest)
  • GitHub Check: Publish Maven Dry Run
  • GitHub Check: Robustness, Leak & Determinism Tests (Linux x64)
  • GitHub Check: JMH Benchmarks (advisory)
  • GitHub Check: Build & Verify (Compilation) (macos-15)
  • GitHub Check: Natural System Libvips & Downstream Integration (Linux x64)
  • GitHub Check: Samples E2E Suite (All 88 Feature Samples)
  • GitHub Check: Build & Verify (Compilation) (windows-latest)
  • GitHub Check: Concurrency Stress Tests (Linux x64)
  • GitHub Check: GraalVM Native Image Smoke & E2E Test (Linux x64)
  • GitHub Check: Musl Native Detection (Alpine)
  • GitHub Check: build-natives (windows-x64, windows-latest)
  • GitHub Check: build-natives (darwin-arm64, macos-15)
  • GitHub Check: Build patched PDFium and run Ghent V50
  • GitHub Check: FFM layout vs pinned PDFium headers
  • GitHub Check: Public API compatibility (japicmp vs last release)
  • GitHub Check: build-natives (windows-arm64, windows-11-arm)
  • GitHub Check: build-natives (linux-arm64, ubuntu-24.04-arm)
  • GitHub Check: build-natives (darwin-x64, macos-15-intel)
  • GitHub Check: prep-windows-icu
  • GitHub Check: CodeQL Analysis (java-kotlin)
  • GitHub Check: C++ - clang-tidy + cppcheck + clang-format
  • GitHub Check: Corpus (generate + native)
  • GitHub Check: CLI correctness & no-corruption tests
  • GitHub Check: build-natives (linux-x64, ubuntu-latest)
  • GitHub Check: Module descriptor integrity
  • GitHub Check: Java - SpotBugs + Checkstyle + PMD + Spotless
  • GitHub Check: Corpus + integration e2e
  • GitHub Check: Bundle verify (symbols, RPATH, linkage, sizes)
  • GitHub Check: Samples E2E (88 features via RunAllSamples)
  • GitHub Check: CodeQL Analysis (c-cpp)
  • GitHub Check: Native bridge libFuzzer (ASan/UBSan, real PDFium)
  • GitHub Check: Version bump script regression tests
  • GitHub Check: Shellcheck (scripts + native/*.sh)
  • GitHub Check: Flaky-test guard (3× rerun)
  • GitHub Check: OSV vulnerability scan
  • GitHub Check: Restricted-env compat (no execstack + hermetic bundle)
  • GitHub Check: CodeQL (java-kotlin)
  • GitHub Check: Javadoc builds cleanly
  • GitHub Check: Gradle wrapper validation
  • GitHub Check: JaCoCo coverage (non-blocking ratchet)
  • GitHub Check: CodeQL (c-cpp)
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/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
Apply the Java 25 and FFM rules from .github/CODERABBIT_REVIEW.md.

CodeRabbit configuration file

Files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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/panama/QpdfLib.java
Source excerpt: These rules apply to maintained source.

CodeRabbit inference engine (.github/CODERABBIT_REVIEW.md)

Files:

  • jpdfium/src/main/resources/META-INF/native-image/com.stirling/jpdfium/reachability-metadata.json
  • reachability-metadata/metadata/com.stirling/jpdfium/1.2.0/reachability-metadata.json
  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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/panama/QpdfLib.java
  • native/bridge/src/jpdfium_qpdf.cpp
Learnings: 3

Common learnings

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

## PDFium execution and lifecycle

- Page/text/form/progressive resources must retire before their parent state becomes invalid. Generation checking does not substitute for native cleanup.

Applied to files:

  • jpdfium/src/main/java/stirling/software/jpdfium/doc/PdfCompressor.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

## FFM and ABI

- Verify `FunctionDescriptor` argument order, return carrier, native widths, alignment, padding, and calling convention against the real C declarations.

Applied to files:

  • jpdfium/src/main/java/stirling/software/jpdfium/panama/QpdfLib.java

Comment thread native/bridge/include/jpdfium.h Resolved
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from a6a0cae to 0ff656c 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 added this pull request to stack #298 November 15, 2026 12:00
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from 0ff656c to be7918b Compare November 15, 2026 16:50
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from be7918b to 9deb180 Compare November 18, 2026 19:54
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from 9deb180 to 74579af Compare November 18, 2026 20:32
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
@balazs-szucs
balazs-szucs force-pushed the refactor/font-17-tagged-subset branch from 74579af to c71efba 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