Skip to content

Thai edition: edit text set in Sarabun in Sarabun, not TH Sarabun PSK - #1

Open
cyk-logistics wants to merge 7 commits into
mixlnwuu:thaifrom
cyk-logistics:fix/sarabun-font-size
Open

cyk-logistics wants to merge 7 commits into
mixlnwuu:thaifrom
cyk-logistics:fix/sarabun-font-size

Conversation

@cyk-logistics

Copy link
Copy Markdown

What this changes

Editing existing text set in Google's Sarabun (what Chrome's print-to-PDF and TCPDF embed, e.g. AAAAAC+Sarabun-Regular) redrew it in TH Sarabun PSK. Family::like_font treated the plain name sarabun like thsarabunpsk. At one point size, TH Sarabun PSK's letters are 68% as tall as Sarabun's (ก is 400 vs 586 thousandths of an em; H is 476 vs 700). So every edited line came out about a third smaller and lighter than the text around it, even when only one digit changed. Fonts installed on the machine weren't consulted for that name. On macOS, Sarabun is only an on-demand system font collection, which isn't scanned and couldn't be embedded anyway.

  • Bundles Sarabun (SIL OFL 1.1, unmodified, from google/fonts@88058c7 ofl/sarabun, Regular/Bold/Italic/Bold Italic, about 90 KB each). It goes in thai/fonts/sarabun/ next to TH Sarabun PSK, with OFL.txt and 4 manifest lines. They're tagged Docu, so the interface and Thai-fallback face order is unchanged.
  • Family::GoogleSarabun (label "Sarabun") is added in crates/edit/src/added.rs. like_font maps the TH Sarabun names to TH Sarabun PSK and sarabun to Sarabun. If the build lacks the face, it falls back to an installed font, as before.
  • text_regions::thai_face (Thai fallback for runs restyled within a paragraph) goes through like_font too. It used to go straight from installed fonts to TH Sarabun PSK.
  • thai/build-windows.ps1 copies both font folders and appends every manifest line that isn't there yet. The old script appended once, keyed on ^TH Sarabun PSK, so an existing target\thai-fonts would never have gained the new lines. package.ps1 already ships each fonts/<family>/OFL.txt.
  • README-TH.md lists the new font and its licence. ATTRIBUTION.toml gets entries for the 4 font files.

Side effect: upstream's embedding::matching_faces now finds the approved full face for *+Sarabun-Regular / *+Sarabun-Bold sources. That affects the inline editor's font stack and the renderer's substitute for a non-embedded Sarabun.

How you verified it

Built natively on macOS (Apple silicon) with CRAFT_FONTS_DIR = craft-fonts@3d9ab3a plus thai/fonts, as build-windows.ps1 does.

End to end, using pdfcraft-cli run --script (doc_open → text_edit by line → doc_save), rendered with pdftoppm and with MuPDF. Both renderers gave the same numbers.

Test Letter-body height Line width Stroke weight
Chrome PDF, Sarabun 18 pt, one line retyped with one digit changed: original 12.50 pt 232.25 pt 5.16
same, before this PR (TH Sarabun PSK) 8.50 pt 152.75 pt 2.59
same, after this PR (Sarabun) 12.50 pt 233.00 pt 5.13
TCPDF form, Sarabun 11 pt, a word retyped with new letters: untouched neighbour 6.66 pt
same, before this PR 4.32 pt
same, after this PR 6.57–6.66 pt
  • Bold lines keep their weight.
  • pdftotext finds every edited line.
  • Whole-paragraph edits and partly restyled paragraphs (ranges) now use Sarabun. Before, they used a TH Sarabun PSK Type 3 font or an embedded copy of TH Sarabun PSK.

Checklist

  • cargo fmt --check -p pdfcraft-edit: OK.

  • clippy with -D warnings: no warnings in the changed files. cargo clippy -p pdfcraft-edit -- -D warnings still stops on 3 existing lints in crates/fonts/src/installed.rs (clippy 1.99: type_complexity, two chunks_exact_to_as_chunks) and 1 in crates/edit/src/text.rs (too_many_arguments). This PR doesn't touch those files.

  • Tests: cargo test -p pdfcraft-edit -p pdfcraft-fonts -p pdfcraft-automation with the craft-fonts input gives edit 141 passed, fonts 69 passed, automation 194 passed.

    • One edit test fails: added_thai_text_wraps_clusters_and_survives_reopen (the narrow-box wrap expects 3 rows and gets 2).
    • It fails the same way on thai at 4326798 without this change (checked from git archive with a separate target dir), so it's an existing failure.
  • cargo xtask layers: OK.

  • cargo xtask assets: the new Sarabun files pass. 37 violations already exist on thai and remain:

    • TH Sarabun PSK files with no entry
    • some i18n catalogues
    • docs/brand and docs/images
    • ATTRIBUTION.md out of date

    I didn't regenerate ATTRIBUTION.md, so this PR touches no unrelated entries.

Tests. New regression test sarabun_text_is_redrawn_in_sarabun_not_th_sarabun_psk in crates/edit/src/tests.rs. It edits a line and a paragraph whose font is AAAAAC+Sarabun-Regular (expects Sarabun) and BCDEEE+THSarabunPSK (expects TH Sarabun PSK still). When the build lacks the faces it is skipped, like the other Thai-edition tests. With the old like_font mapping restored, it fails with left: Some("TH Sarabun PSK Type3") right: Some("Sarabun Type3").

Never-crash

  • No new unwrap/expect/panic!/unreachable!/todo! outside tests
  • No new indexing or slicing; no arithmetic on input
  • No unsafe

Provenance

  • No Adobe asset
  • No font files committed: this PR does commit font files, following how this edition already ships TH Sarabun PSK in thai/fonts. Sarabun isn't in craft-fonts@3d9ab3a. If you'd rather not commit fonts, the build script could download these four files from the pinned google/fonts commit and check their SHA-256 (listed in manifest-additions.txt and ATTRIBUTION.toml). I'm happy to change it.
  • No GPL/AGPL code; Poppler and MuPDF were used only as external renderers for measuring
  • Every new asset has an ATTRIBUTION.toml entry

Security

  • No new paths, network access or control-channel changes

Anything a reviewer should look at first

  • Naming. The existing Family::Sarabun means TH Sarabun PSK. I didn't rename it, to keep the diff small, so the new variant is GoogleSarabun, labelled "Sarabun" in the font menu. In the automation tools, font: "sarabun" still means TH Sarabun PSK (unchanged, so existing scripts behave the same), while "Sarabun" reaches the new family through from_name.
  • Lookup order. For a TH Sarabun New source with that font installed, thai_face now prefers the bundled TH Sarabun PSK over the installed font, matching what like_font already did for line edits. The two are the same design.
  • Not covered here. THSarabunIT๙ (common on Thai government forms) reduces to thsarabunit, which still isn't mapped to TH Sarabun PSK.

🤖 Generated with Claude Code

cyk-logistics and others added 4 commits October 18, 2026 09:46
Text set in Google's Sarabun (Chrome and TCPDF embed it as AAAAAC+Sarabun-Regular) was
redrawn in TH Sarabun PSK when edited: like_font mapped the plain name "sarabun" to the
built-in TH Sarabun PSK. At one size PSK's letters are 68% as tall (ก 400 against 586
thousandths of an em), so an edited line came out a third smaller and lighter than the rest.

Sarabun (SIL OFL 1.1, google/fonts ofl/sarabun, unmodified) joins TH Sarabun PSK in
thai/fonts as its own family, Family::GoogleSarabun ("Sarabun"). like_font maps the
TH Sarabun names to TH Sarabun PSK and "sarabun" to Sarabun, falling back to an installed
font when the build lacks the face. The Thai fallback for runs restyled within a paragraph
(text_regions::thai_face) goes through like_font too, instead of going straight from
installed fonts to TH Sarabun PSK. build-windows.ps1 copies both font folders and appends
each manifest line not there yet, so an existing font set gains the new lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: README-TH.md (the English summary names Sarabun and now v0.9.0) and
ATTRIBUTION.toml (the Sarabun entries follow the new vello_common entry and the updated
Slovene catalogue hash).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict: README-TH.md (the English summary names Sarabun and now v0.10.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict: ATTRIBUTION.toml (the Sarabun entries follow the new Thai edition mark and
screenshot entries).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mixlnwuu pushed a commit that referenced this pull request Oct 23, 2026
mixlnwuu pushed a commit that referenced this pull request Oct 23, 2026
verify_noting adds the note only when the signature verifies. The test
uses a synthetic 1024-bit key and its PKCS #1 v1.5 signature: the valid
signature carries the note, and one that doesn't verify has none.
cyk-logistics and others added 3 commits October 24, 2026 08:11
Conflicts: README-TH.md (the English summary names Sarabun and now v0.13.0) and
ATTRIBUTION.toml (the Sarabun entries follow the new catalogue and icon entries).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: README-TH.md (the English summary names Sarabun and now v0.14.0) and
ATTRIBUTION.toml (translation catalogs no longer carry a sha256; the Sarabun font entries keep
theirs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thai split added.rs (Family is now in added/types.rs) and text_regions.rs (thai_face is now in
text_regions/styled.rs). The upstream files are taken as they are, with the Sarabun change made
again where the code now lives: Family::GoogleSarabun and like_font in added/types.rs, and
thai_face through like_font in text_regions/styled.rs. Also README-TH.md (v0.15.0) and
ATTRIBUTION.toml (the Sarabun entries follow the Catalan catalogue's new usage line).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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