Skip to content

Japanese in every document and data format - #148

Merged
Chimi6 merged 2 commits into
mainfrom
japanese-input
Oct 31, 2026
Merged

Chimi6 merged 2 commits into
mainfrom
japanese-input

Conversation

@Chimi6

@Chimi6 Chimi6 commented Oct 30, 2026

Copy link
Copy Markdown
Owner

The rest of the Japanese work, after 1.0.1's PDF reading.

  • Legacy encodings read everywhere. Plain text, Markdown and HTML in Shift_JIS, EUC-JP or ISO-2022-JP: a declared charset/encoding is followed, otherwise the encoding is detected. CSV/TSV (Excel saves Japanese CSVs as Shift_JIS) and XML are decoded as they stream. Detection takes bytes for Japanese only when most two-byte characters fall in the common JIS rows, so Latin-1 and Windows-1252 files are still refused with an error rather than turned into kanji.
  • RTF in code page 932. Word's Shift_JIS byte pairs (\ansicpg932, \fcharset128) and half-width katakana read in full; they read as U+FFFD before.
  • PDF output embeds CJK fonts. CID-keyed CFF OpenType (Hiragino, Noto Sans CJK, Source Han Sans) is subset by blanking unused glyphs and subroutines in place, with CID = glyph id (src/io/font/cff.rs). Rendered with poppler, Quartz and MuPDF for both Hiragino and Noto Sans CJK. Japanese text now prefers a Japanese font over Arial Unicode.
  • Kinsoku line breaking in PDF output: Japanese breaks between characters, never starting a line with closing punctuation, small kana or the long-vowel mark, and never ending one with an opening bracket.

Tested with a matrix of 20 Japanese document sources (pandoc, textutil, LibreOffice, Word-style RTF, and Shift_JIS/EUC-JP files) and 5 data sources, each converted to every format and read back: 100% of the text throughout.

New tests:

  • tests/japanese_input.rs: eight legacy-encoded inputs from tests/fixtures/japanese-input/make.py.
  • tests/to_pdf.rs: CFF embedding with a 9.6 KB Noto Sans CJK subset, OFL-licensed.
  • Unit tests for the subsetter, detection and kinsoku.

Legacy encodings read everywhere: text, Markdown, and HTML in
Shift_JIS, EUC-JP, or ISO-2022-JP (declared or detected), CSV/TSV and
XML decoded as they stream, and Word's RTF in code page 932. The PDF
writer embeds CID-keyed CFF fonts (Hiragino, Noto Sans CJK), prefers
Japanese fonts for Japanese, and breaks Japanese lines with kinsoku.
@Chimi6
Chimi6 merged commit 89b0037 into main Oct 31, 2026
16 checks passed
@Chimi6
Chimi6 deleted the japanese-input branch October 31, 2026 11:43
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