Skip to content

Cover FontNormalizer ToUnicode and width repair - #258

Open
balazs-szucs wants to merge 1 commit into
refactor/font-07b-normalizer-widthsfrom
refactor/font-08-normalizer-tests
Open

balazs-szucs wants to merge 1 commit into
refactor/font-07b-normalizer-widthsfrom
refactor/font-08-normalizer-tests

Conversation

@balazs-szucs

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

Copy link
Copy Markdown
Collaborator

Description of Changes

Adds unit and integration tests covering FontNormalizer ToUnicode synthesis, FreeType width repair, surrogate pairs, explicit /CIDToGIDMap streams, and zero-advance glyphs. Verifies normalization behavior end-to-end through the public Java API while hardening native ToUnicode scanning edge cases.

Changed:

  • Add FontNormalizerTest cases for simple/CID ToUnicode synthesis, non-BMP surrogate pairs, explicit /CIDToGIDMap streams, and width repair.
  • Harden CMap parsing and zero-advance width handling in jpdfium_advanced.cpp.

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 262cdec and fc25e15.

Files selected for processing: 2

  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.cpp
Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved PDF font normalization so text mappings are recognized across multiple mapping sections, and recoverable character mappings are retained for CID fonts.
    • Improved CID font width handling by accepting numeric default widths, including fractional values, and rounding them to whole units.
    • Added regression coverage for font mappings and widths, including PDFs with forms and annotation appearances, and checks for repeatable normalization.

Native font normalization now scans additional CMap sections, adjusts synthesized CID-to-Unicode mappings, and rounds numeric CID default widths. Integration-gated tests cover simple and CID font repairs, document normalization, and related PDF scenarios.

Changes: Font normalization

Layer / File(s) Summary
ToUnicode mapping behavior
native/bridge/src/jpdfium_advanced.cpp, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
The native code scans all CMap mapping sections and adjusts synthesized mappings for non-CID-keyed fonts. Tests cover generated mappings, multiple CMap sections, WinAnsi differences, and PDF fixtures.
Simple and CID font width repair
native/bridge/src/jpdfium_advanced.cpp, jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
The native code rounds numeric CID default widths. Tests cover repaired and preserved widths, zero-width CIDs, and PDF inspection helpers and fixtures.
Document-level normalization scenarios
jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
Integration-gated tests cover combined normalization, idempotence, fonts in forms and annotation appearances, and stale open pages after document rewrites.

Change: Other

Merge Risk: Low · previous review 262cd

The font normalization changes are small and bounded. The new multi-section CMap test does not actually exercise the scanning fix, so a future regression there could go unnoticed. Add same-type empty-then-populated bfchar and bfrange cases to close the gap.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Cover FontNormalizer ToUnicode and width repair" names the main change. The PR adds tests for FontNormalizer ToUnicode synthesis and width repair, and it hardens native CMap parsing and zer…
Description check Passed The description summarizes the change, lists the added tests and native hardening, and completes most checklist items. It omits the changelog entry and the Javadoc review, and it leaves the ABI note i…
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 "Cover FontNormalizer ToUnicode and width repair" names the main change. The PR adds tests for FontNormalizer ToUnicode synthesis and width repair, and it hardens native CMap parsing and zero-advance width handling. The title does not mention the native changes, which are secondary.

Full details: Description check

Explanation

The description summarizes the change, lists the added tests and native hardening, and completes most checklist items. It omits the changelog entry and the Javadoc review, and it leaves the ABI note item unchecked without explanation. The template's 'Closes #(issue number)' line is also absent. These gaps are non-critical, so the description is mostly complete.

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 changed the base branch from refactor/font-07-normalizer-core to feat/font-normalizer-qpdf November 11, 2026 22:31
@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-08-normalizer-tests branch from 90f99b6 to 69f4edb Compare November 11, 2026 23:28
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from 69f4edb to c191b07 Compare November 11, 2026 23:56
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from c191b07 to 4539148 Compare November 12, 2026 00:14
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from 4539148 to e7b76b4 Compare November 12, 2026 03:11
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch 2 times, most recently from b6810a5 to b66590e 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 feat/font-normalizer-qpdf to refactor/font-07b-normalizer-widths 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-08-normalizer-tests branch from b66590e to 262cdec Compare November 15, 2026 16:48

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

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6203653 and 262cdec.

Files selected for processing: 2

  • jpdfium/src/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.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: 48

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

CodeRabbit configuration file

Files:

  • 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/test/java/stirling/software/jpdfium/fonts/FontNormalizerTest.java
  • native/bridge/src/jpdfium_advanced.cpp
Learnings: 2

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/fonts/FontNormalizerTest.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

## 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/fonts/FontNormalizerTest.java

Comment on lines +521 to +523
1 beginbfrange
<20> <7E> <0020>
endbfrange

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Use a second section of the same mapping type.

This fixture has an empty bfchar followed by a populated bfrange. The immediate-base implementation already checks the first section of each type, so this test passes without the scanning fix. (raw.githubusercontent.com)

Use an empty bfchar followed by a populated bfchar. Add the equivalent bfrange case. Both cases must preserve the existing mapping and report zero repairs only with the fix.

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

Source: Coding guidelines

@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from 262cdec to 6f874b6 Compare November 18, 2026 19:54
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from 6f874b6 to 3662f45 Compare November 18, 2026 20:32
Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
@balazs-szucs
balazs-szucs force-pushed the refactor/font-08-normalizer-tests branch from 3662f45 to fc25e15 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