Skip to content

PDF: set Romanian ș ț Ș Ț (comma below) in the Latin font (on #2556) - #2816

Open
vioreltus wants to merge 5 commits into
storytold:mainfrom
vioreltus:fix/pdf-romanian-comma-below
Open

vioreltus wants to merge 5 commits into
storytold:mainfrom
vioreltus:fix/pdf-romanian-comma-below

Conversation

@vioreltus

@vioreltus vioreltus commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2556 (its commit is the first one here; only the top commit, PDF: set Romanian ș ț Ș Ț (comma below) in the Latin font too, is new). Part of #446.

Why

#2556 sets the Latin Extended-A letters (U+0100..U+017F) in the standard face, which covers Romanian ă/Ă. But Romanian ș ț Ș Ț are U+0218..U+021B, Latin Extended-B, so with #2556 they still go to the non-embedded STSong-Light CID font. Adobe-GB1 has no glyph for them: on Windows they print as boxes followed by a full-em gap (Comand□ manuale, □tiin□e). Every Romanian document has them.

What this changes

  • ext_code gives Ș ș Ț ț bytes 0x01..0x04 of the same per-face resource, and the /Differences array names them uni0218 uni0219 uni021A uni021B. The uniXXXX form is found both by fonts that name these glyphs so (TeX Gyre Heros, poppler's Helvetica substitute, has no scommaaccent) and by viewers that map a glyph name to its code point. The AGL names would not do for Ț/ț: the AGL maps Tcommaaccent to the cedilla letter U+0162.
  • The resource now carries /FirstChar 1 /LastChar 255 /Widths. A viewer takes a standard font's advances from its own metrics by glyph name; those have no uni0219, so without widths ș advanced by nothing and overprinted the next letter (seen with poppler). Unused codes are 0.
  • fold measures them like S and T, so wrapping and alignment use the right widths.

How it was verified

Provenance

My own change, from the PDF spec (font /Differences, /Widths) and the AGL specification; no other implementation consulted. AI-assisted (Claude Code) for @vioreltus, a native Romanian speaker who tested the print on Windows.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JadgGo4G2GHaAMNb3qyygk

Summary by CodeRabbit

  • New Features
    • PDF output now supports Latin Extended-A characters, including Romanian letters with comma below. These characters are rendered distinctly from similar letters with cedillas, while common Latin characters retain their existing rendering. Characters that cannot be mapped to the supported Latin fonts continue to use the existing fallback rendering. This expands the range of Latin text that can be represented in PDF documents.

Silvertree2010 and others added 2 commits October 25, 2026 13:11
Fixes storytold#2547

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Builds on storytold#2556. Ș ș Ț ț are U+0218..U+021B (Latin Extended-B), outside the
Latin Extended-A block storytold#2556 routes to the Latin face, so Romanian text still went
to the CJK CID font, which has no glyph for them: printed boxes followed by a
full-em gap. They now take bytes 0x01..0x04 of each face's /Differences
encoding as uni0218..uni021B and are measured like S and T. The uniXXXX names
are found both by fonts that name the glyphs so (TeX Gyre Heros has no
scommaaccent) and by viewers that map a name to its code point; the AGL name
Tcommaaccent would map to the cedilla letter U+0162.

The resource now also carries /Widths: a viewer takes a standard font's advances
from its own metrics by glyph name, which have no uni0219, so ș advanced by
nothing and overprinted the next letter (seen with poppler).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JadgGo4G2GHaAMNb3qyygk
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4831a38 and 8c7551a.

Files selected for processing: 2
  • crates/pdf/src/lib.rs
  • crates/pdf/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The PDF crate now renders supported Latin Extended-A and Romanian comma-below characters through per-face Extended font resources. It groups text into ANSI, Extended, or CID runs and serializes each run with the matching encoding and font resource.

Changes: Latin Extended PDF text rendering

Layer / File(s) Summary
Character mappings
crates/pdf/src/metrics.rs
Character tables and lookups map supported Latin Extended-A and Romanian comma-below letters to glyph names and ASCII base characters.
Text run classification and encoding
crates/pdf/src/lib.rs
Text is grouped into ANSI, Extended, or CID runs. Extended characters use per-face resource slots and widths.
Font resource emission and rendering tests
crates/pdf/src/lib.rs, crates/pdf/src/tests.rs
Serialization emits Type1 Extended resources with face-specific widths and Differences encodings. Tests check character mappings, routing, and resources across eligible font faces.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant text_rotated
  participant EncodingHelpers
  participant PDFSerialization
  text_rotated->>EncodingHelpers: classify and encode text runs
  EncodingHelpers-->>text_rotated: return run encodings and font slots
  text_rotated->>PDFSerialization: provide ANSI, Extended, and CID strings
Loading

Suggested reviewers: silvertree2010, fredapps

Merge Risk: Low · up to 8c755

Some viewers relying on standard font glyphs may display missing Romanian letters. The reported tested viewers rendered them correctly.

Architecture risk: Low · up to 4831a

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 3 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/pdf/src/lib.rs: The crate documentation now says Latin Extended-A characters missing from WinAnsiEncoding are rendered through a second resource in the same face, while other unsupported characters use the CID font.
  • observed — Modified behavior in crates/pdf/src/lib.rs: Adds a font-slot range for one Latin Extended-A resource per standard face. needs_cid now excludes characters supported by ext_code, so those characters are assigned to the extended resource rather than the CID font.
  • observed — Modified behavior in crates/pdf/src/lib.rs: Adds mappings between supported Latin Extended-A and Romanian comma-below characters and their extended encoding bytes, plus per-face widths for codes 1–255; unmapped codes receive width zero.
  • observed — Modified behavior in crates/pdf/src/lib.rs: Adds ANSI, extended, and CID run classification and a hex-string encoder for extended runs. Extended strings encode each character using ext_code, falling back to ? if no code is available.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: placing Romanian comma-below letters in the PDF Latin font. The issue reference is extra but does not reduce clarity.
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: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 14 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Harrison-Booth

Copy link
Copy Markdown
Contributor

I checked the comma-below encoding and per-glyph widths in the changed code, then rendered an original mixed ANSI/extended-run Romanian sample with MuPDF. Ș/ș/Ț/ț render with visible commas below and advance without colliding with adjacent text; both MuPDF and Poppler pdftotext extracted the four characters correctly from the uni0218–uni021B glyph names, despite the Type1 resource having no explicit /ToUnicode map. Merge-tree against upstream/main is clean. I did not run Rust or Windows checks.

alehel added a commit to alehel/gridcraft that referenced this pull request Oct 30, 2026

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ReviewerA — source-read COMMENT (not an approval)

I read the first hunk: the PDF writer's documentation now says Latin Extended-A letters that WinAnsiEncoding lacks (ő, ű, ł, č and so on) are set in the same standard face through a second resource with a /Differences encoding of standard glyph names; the title adds Romanian ș, ț, Ș and Ț (comma below) and says it is built on #2556. A /Differences array with standard glyph names (scommaaccent, tcommaaccent) is the right way to reach glyphs in the 14 standard fonts, but not every viewer's substitute font has those glyphs, so they may show as blanks: say which viewers were tried. The distinction between the cedilla letters (ş, ţ) and the comma-below letters (ș, ț) must be kept, since Romanian text uses the second. Text extraction should still give the right letters (a ToUnicode map is not present for standard fonts, so extraction may give the glyph names' mapped values). I did not read the code. Add tests for each of the four letters, a mix with other Latin Extended-A letters, and the width table for the new glyphs. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

Each of Ș ș Ț ț gets its own code (0x01..0x04), its uniXXXX glyph name and
its base letter's width, apart from the cedilla letters Ş ş Ţ ţ; a run that
mixes them with other Latin Extended-A letters stays in one resource.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JadgGo4G2GHaAMNb3qyygk
@vioreltus

Copy link
Copy Markdown
Contributor Author

Thanks. A few points from the code, which the review didn't read:

  • Glyph names: the comma-below letters are named uni0218 uni0219 uni021A uni021B (/Differences [1 /uni0218 /uni0219 /uni021A /uni021B 128 …]), not scommaaccent/tcommaaccent. Viewers find the uniXXXX names, and so do substitute fonts that name the glyphs that way (TeX Gyre Heros, poppler's Helvetica substitute, has no scommaaccent). Viewers also map these names back to the code point, so extraction gives ș ț Ș Ț. The AGL's Tcommaaccent would extract as the cedilla letter U+0162.
  • Viewers tried: Microsoft Print to PDF and a Brother MFC-L8340CDW on Windows (every ă â î ș ț Ș Ț prints), and poppler on Linux (pdftoppm draws them, pdftotext extracts them).
  • Widths: the resource carries /FirstChar 1 /LastChar 255 /Widths, because standard metrics have no uni0219. Without the widths, ș advanced by 0 and overprinted the next letter.
  • Comma below vs cedilla: kept apart. Ș ș Ț ț are codes 0x01–0x04; Ş ş Ţ ţ keep their Latin Extended-A codes and names from Set ő, ű and other Latin Extended-A letters in the Latin PDF font #2556.
  • Tests: besides romanian_letters_use_the_latin_font, I added romanian_comma_below_and_cedilla_letters_stay_distinct. For each of the four letters it checks the code, the glyph name, its cedilla counterpart's separate code and name, and the width against the base letter. It also checks a mixed run ăşșţțőŁ in one resource and the /Differences array in the output. Both tests fail if the comma-below codes are shifted (verified).

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.

5 participants