Skip to content

Share Rust system font registration with Node - #140

Merged
shps951023 merged 1 commit into
mainfrom
feat/rust-node-system-fonts
Sep 5, 2026
Merged

Share Rust system font registration with Node#140
shps951023 merged 1 commit into
mainfrom
feat/rust-node-system-fonts

Conversation

@shps951023

@shps951023 shps951023 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

  • move system fallback and Office cloud font registration into the Rust core crate
  • reuse the shared registration path from the Rust CLI
  • automatically register system fonts before Node path and buffer conversions
  • verify registration is idempotent across Node conversion entry points

Validation

  • cargo test -p minipdf -p minipdf-cli --manifest-path minipdf-rs/Cargo.toml (109 passed)
  • npm run build:debug (passed)
  • npm test (8 passed)
  • git diff --check origin/main...HEAD

Summary by CodeRabbit

  • Improvements

    • PDF conversion now registers available system fonts automatically before processing.
    • Improved font fallback support across platforms, including Windows Office cloud fonts.
    • Font aliases are normalized for more consistent font matching and PDF rendering.
  • Bug Fixes

    • Reduced issues where PDFs could render with incorrect or missing fonts.
    • Font registration occurs only once per application session, helping maintain consistent behavior across conversions.

Copilot AI lite review requested due to automatic review settings September 5, 2026 18:47
@shps951023
shps951023 merged commit 9871d19 into main Sep 5, 2026
5 of 7 checks passed
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 5a818715-0b62-4565-a277-dbeb68274072

📥 Commits

Reviewing files that changed from the base of the PR and between 82a1084 and b360b4f.

📒 Files selected for processing (5)
  • minipdf-node/src/lib.rs
  • minipdf-node/test/index.test.js
  • minipdf-rs/crates/minipdf-cli/src/main.rs
  • minipdf-rs/crates/minipdf/src/fonts.rs
  • minipdf-rs/crates/minipdf/src/lib.rs

📝 Walkthrough

Walkthrough

The change centralizes system font registration in minipdf, adds platform-specific fallback and cloud-font handling, and invokes registration from CLI and Node conversion paths.

Changes

System font registration

Layer / File(s) Summary
Font registration core
minipdf-rs/crates/minipdf/src/fonts.rs, minipdf-rs/crates/minipdf/src/lib.rs
Adds one-time registration for platform fallback fonts and Windows Office cloud fonts. It derives normalized aliases from font metadata and publicly re-exports register_system_fonts.
CLI registration integration
minipdf-rs/crates/minipdf-cli/src/main.rs
The CLI uses shared system font registration instead of manual path and cloud-font registration. Obsolete helpers and Windows path tests were removed.
Node conversion integration
minipdf-node/src/lib.rs, minipdf-node/test/index.test.js
All Node conversion entry points register system fonts before conversion. Registration errors use to_napi_error, and the Windows test checks Arial registration.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NodeConversion
  participant minipdf
  participant SystemFonts
  participant FontRegistry
  NodeConversion->>minipdf: call register_system_fonts
  minipdf->>SystemFonts: discover fallback and cloud-font files
  SystemFonts-->>minipdf: return readable font files
  minipdf->>FontRegistry: register fonts and aliases
  minipdf-->>NodeConversion: return success or mapped error
  NodeConversion->>NodeConversion: continue PDF conversion
Loading
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/rust-node-system-fonts

Comment @coderabbitai help to get the list of available commands.

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

🟡 Changes recommended

register_system_fonts() can fail conversions and break intended idempotence if any single system font read errors mid-registration, leading to partial registration and retries duplicating fonts.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR centralizes system fallback font and Office CloudFonts registration in the Rust minipdf core crate, then reuses that shared registration path from both the Rust CLI and the Node (napi) bindings to ensure consistent, idempotent font setup across entry points.

Changes:

  • Added a core register_system_fonts() API and implementation (including Windows Office CloudFonts scanning).
  • Updated the Rust CLI to delegate system font registration to the core crate.
  • Updated Node conversion entry points to automatically register system fonts, plus a Windows-only test assertion for idempotence.
File summaries
File Description
minipdf-rs/crates/minipdf/src/lib.rs Exposes the new shared system font registration API from the core crate.
minipdf-rs/crates/minipdf/src/fonts.rs Implements idempotent system fallback + Office CloudFonts registration in core.
minipdf-rs/crates/minipdf-cli/src/main.rs Reuses the shared core registration path instead of duplicating font discovery logic.
minipdf-node/src/lib.rs Ensures system fonts are registered before each Node conversion entry point.
minipdf-node/test/index.test.js Adds a Windows-only assertion to validate registration idempotence via registeredFonts().
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +22 to +28
let name = path
.file_stem()
.and_then(|name| name.to_str())
.unwrap_or("font")
.to_owned();
crate::register_font(name, fs::read(path)?);
}
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