Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into i18n-id-vi

sanches6496dc6f4750
diff --cc crates/engine/src/dates.rs
index a28f1e674,8c14a5b1b..6c5acfeac
--- a/crates/engine/src/dates.rs
+++ b/crates/engine/src/dates.rs
@@@ -360,19 -360,9 +360,20 @@@ pub static DATE_LANGUAGES: [DateLanguag
days: ["sekmadienis", "pirmadienis", "antradienis", "trečiadienis", "ketvirtadienis", "penktadienis", "šeštadienis"],
days_short: ["sk", "pr", "an", "tr", "kt", "pn", "št"],
},
+ // Indonesian. Month and weekday names are the same with and after a day number, so
+ // `months_with_day` is `None`.
+ DateLanguage {
+ code: "id",
+ name: "Bahasa Indonesia",
+ months: ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"],
+ months_with_day: None,
+ months_short: ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des"],
+ days: ["Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu"],
+ days_short: ["Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"],
+ },
- // Vietnamese: the month name is `tháng Một` with a day number and `Tháng Một` standing
- // alone, as in English.
+ // Vietnamese: numeric month forms (`tháng 1` with a day, `Tháng 1` standing alone).
+ // Fill & Sign still refuses any format whose final text fails the existing WinAnsi check
+ // (for example weekday names); `dd.mm.yyyy` remains writable.
DateLanguage {
code: "vi",
name: "Tiếng Việt",
@@@ -728,41 -718,6 +749,35 @@@ mod tests
assert_eq!(in_lang("dddd, mmmm", "cs"), "sobota, březen");
}
- /// Indonesian month names are the same with and after a day number; Vietnamese lowers `tháng`
- /// after a day number and keeps it capitalised standing alone.
++ /// Indonesian month and weekday names are the same with and after a day number. (Vietnamese
++ /// has its own test upstream: its numeric month forms are writable, weekday names are not.)
+ #[test]
- fn indonesian_and_vietnamese_month_and_weekday_names() {
++ fn indonesian_month_and_weekday_names() {
+ assert_eq!(in_lang("d mmmm yyyy", "id"), "7 Maret 2026");
+ assert_eq!(in_lang("mmmm yyyy", "id"), "Maret 2026");
+ assert_eq!(in_lang("dddd, d mmmm yyyy", "id"), "Sabtu, 7 Maret 2026");
- assert_eq!(in_lang("d mmmm yyyy", "vi"), "7 tháng Ba 2026");
- assert_eq!(in_lang("mmmm yyyy", "vi"), "Tháng Ba 2026");
- assert_eq!(in_lang("ddd, d mmm", "vi"), "T7, 7 Thg 3");
- // Indonesian month names are Latin, so they reach a PDF; Vietnamese ones are not Western
- // European, and the date-text path refuses them with what to use instead.
++ // Indonesian month names are Latin, so they reach a PDF.
+ let mut s = Session::new().with_clock(|| 1_700_000_000);
- s.set_date_language(Some("vi")).unwrap();
- assert!(s.today_text_for_pdf(Some("d mmmm yyyy"), None).unwrap_err().contains("dd.mm.yyyy"));
+ s.set_date_language(Some("id")).unwrap();
+ assert_eq!(s.today_text_for_pdf(Some("d mmmm yyyy"), None).as_deref(), Ok("14 November 2023"));
+ }
+
+ /// Hindi and Korean names are the same with and after a day number. Neither is Western
+ /// European, so the date-text path refuses them with what to use instead.
+ #[test]
+ fn hindi_and_korean_month_and_weekday_names() {
+ assert_eq!(in_lang("d mmmm yyyy", "hi"), "7 मार्च 2026");
+ assert_eq!(in_lang("dddd, mmmm", "hi"), "शनिवार, मार्च");
+ assert_eq!(in_lang("ddd, d mmm", "hi"), "शनि, 7 मार्च");
+ assert_eq!(in_lang("yyyy\\년 mmmm d\\일 dddd", "ko"), "2026년 3월 7일 토요일");
+ assert_eq!(in_lang("ddd", "ko"), "토");
+ let mut s = Session::new().with_clock(|| 1_700_000_000);
+ for code in ["hi", "ko"] {
+ s.set_date_language(Some(code)).unwrap();
+ assert!(s.today_text_for_pdf(Some("d mmmm yyyy"), None).unwrap_err().contains("dd.mm.yyyy"), "{code}");
+ }
+ }
+
#[test]
fn the_session_writes_names_in_its_date_language() {
let mut s = Session::new().with_clock(|| 1_700_000_000);
diff --cc crates/ui-egui/src/i18n/mod.rs
index 20121d123,5bb2889c9..9158e02d5
--- a/crates/ui-egui/src/i18n/mod.rs
+++ b/crates/ui-egui/src/i18n/mod.rs
@@@ -207,19 -207,9 +207,16 @@@ pub static LANGUAGES: [LangInfo; 26] =
LangInfo { code: "tr", name: "Türkçe", source: include_str!("tr.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
// Lithuanian; every `lt-*` locale (`lt-LT`, `lt_LT.UTF-8`) resolves here. Three plural forms (one, few, other).
LangInfo { code: "lt", name: "Lietuvių", source: include_str!("lt.tsv"), plural: plural_lithuanian, rtl: false, catalog: OnceLock::new() },
- // Vietnamese; every `vi-*` locale (`vi-VN`, `vi_VN.UTF-8`) resolves here. CLDR `vi` counts have
+ // Indonesian; every `id-*` locale (`id-ID`, `id_ID.UTF-8`) resolves here. CLDR `id` counts have
// one form ("other"), so `@plural` entries list a single form.
- LangInfo { code: "vi", name: "Tiếng Việt", source: include_str!("vi.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
+ LangInfo { code: "id", name: "Bahasa Indonesia", source: include_str!("id.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
- // Vietnamese; every `vi-*` locale (`vi-VN`, `vi_VN.UTF-8`) resolves here. CLDR `vi` counts have
- // one form ("other"), so `@plural` entries list a single form.
- LangInfo { code: "vi", name: "Tiếng Việt", source: include_str!("vi.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
+ // Hindi; every `hi-*` locale (`hi-IN`, `hi_IN.UTF-8`) resolves here. CLDR `hi` has "one"
+ // (0 and 1) and "other", but the catalog's nouns are the same in both ("{n} पृष्ठ"), so
+ // `@plural` entries list a single form.
+ LangInfo { code: "hi", name: "हिन्दी", source: include_str!("hi.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
+ // Korean; every `ko-*` locale (`ko-KR`, `ko_KR.UTF-8`) resolves here. CLDR `ko` counts have
+ // one form ("other"), so `@plural` entries list a single form.
+ LangInfo { code: "ko", name: "한국어", source: include_str!("ko.tsv"), plural: plural_none, rtl: false, catalog: OnceLock::new() },
];
impl LangInfo {
diff --cc crates/ui-egui/src/system_fonts.rs
index db654e6b0,606fa923d..d560ab448
--- a/crates/ui-egui/src/system_fonts.rs
+++ b/crates/ui-egui/src/system_fonts.rs
@@@ -3,8 -3,8 +3,9 @@@
//! The embedded faces (Inter, egui's defaults, craft-fonts) come first in every family; this one
//! only draws characters none of them has, such as an Arabic file name in a build without
//! craft-fonts, or the Simplified Chinese interface in a build without a `Hans` face (#826). A
- //! second, a third and a fourth installed face, [`devanagari_fallback`], [`telugu_fallback`] and
- //! [`hangul_fallback`], draw Hindi, Telugu and Korean when one is installed. It is
-//! few more installed faces, [`devanagari_fallback`], [`telugu_fallback`], [`sinhala_fallback`]
-//! and [`tamil_fallback`], draw Hindi, Telugu, Sinhala and Tamil when one is installed. It is
++//! few more installed faces, [`devanagari_fallback`], [`telugu_fallback`], [`hangul_fallback`],
++//! [`sinhala_fallback`] and [`tamil_fallback`], draw Hindi, Telugu, Korean, Sinhala and Tamil
++//! when one is installed. It is
//! read at runtime and never embedded or shipped (AGENTS.md §1.4), and `PDFCRAFT_SYSTEM_FONTS=0`
//! turns it off (published screenshots do).
@@@ -25,8 -28,10 +29,12 @@@ const PROBE: char = '\u{0627}'
const DEVANAGARI_PROBE: char = '\u{0915}';
/// Telugu letter ka: the face must have it to cover Telugu.
const TELUGU_PROBE: char = '\u{0C15}';
+/// Hangul syllable han (한, U+D55C): the face must have it to cover Korean.
+const HANGUL_PROBE: char = '\u{D55C}';
+ /// Sinhala letter ka (ක): the face must have it to cover Sinhala.
+ const SINHALA_PROBE: char = '\u{0D9A}';
+ /// Tamil letter ka (க): the face must have it to cover Tamil.
+ const TAMIL_PROBE: char = '\u{0B95}';
/// 欢 (U+6B22): Simplified only, absent from the Japanese craft-fonts faces.
const HANS_PROBE: char = '\u{6B22}';
/// 說 (U+8AAA): Traditional only, absent from the Japanese craft-fonts faces.
@@@ -81,48 -86,30 +89,62 @@@ pub fn devanagari_fallback() -> Option<
/// candidate is installed; the interface then draws what the embedded faces can.
pub fn telugu_fallback() -> Option<Arc<FontData>> {
static CACHE: OnceLock<Option<Arc<FontData>>> = OnceLock::new();
- CACHE.get_or_init(|| script_fallback(&telugu_candidates(), TELUGU_PROBE, MAX_BYTES)).clone()
+ CACHE.get_or_init(|| script_fallback(&telugu_candidates(), TELUGU_PROBE)).clone()
}
+/// The installed fallback face for Hangul (Korean), read once. `None` when it is turned off or no
+/// candidate is installed; the interface then draws what the embedded faces can (no embedded face
+/// has Hangul, so Korean text shows replacement boxes).
+pub fn hangul_fallback() -> Option<Arc<FontData>> {
+ static CACHE: OnceLock<Option<Arc<FontData>>> = OnceLock::new();
- CACHE.get_or_init(|| script_fallback(&hangul_candidates(), HANGUL_PROBE, MAX_HAN_BYTES)).clone()
++ CACHE.get_or_init(|| script_fallback(&hangul_candidates(), HANGUL_PROBE)).clone()
++}
++
+ /// The installed fallback face for Sinhala, read once. `None` when it is turned off or no
+ /// candidate is installed; the interface then draws what the embedded faces can.
+ pub fn sinhala_fallback() -> Option<Arc<FontData>> {
+ static CACHE: OnceLock<Option<Arc<FontData>>> = OnceLock::new();
+ CACHE.get_or_init(|| script_fallback(&sinhala_candidates(), SINHALA_PROBE)).clone()
}
- fn script_fallback(candidates: &[PathBuf], probe: char, max: u64) -> Option<Arc<FontData>> {
+ /// The installed fallback face for Tamil, read once. `None` when it is turned off or no
+ /// candidate is installed; the interface then draws what the embedded faces can.
+ pub fn tamil_fallback() -> Option<Arc<FontData>> {
+ static CACHE: OnceLock<Option<Arc<FontData>>> = OnceLock::new();
+ CACHE.get_or_init(|| script_fallback(&tamil_candidates(), TAMIL_PROBE)).clone()
+ }
+
+ fn script_fallback(candidates: &[PathBuf], probe: char) -> Option<Arc<FontData>> {
if std::env::var_os("PDFCRAFT_SYSTEM_FONTS").is_some_and(|v| v == "0") {
return None;
}
- candidates.iter().find_map(|path| read(path, probe, max))
+ candidates.iter().find_map(|path| read(path, probe, MAX_BYTES))
}
+/// Well-known locations of Korean system faces, best first. Noto CJK and Source Han are left out
+/// on purpose (AGENTS.md §1.1).
+fn hangul_candidates() -> Vec<PathBuf> {
+ if cfg!(windows) {
+ ["malgun.ttf", "gulim.ttc", "batang.ttc", "malgunsl.ttf"].iter().map(|f| windows_fonts().join(f)).collect()
+ } else if cfg!(target_os = "macos") {
+ ["/System/Library/Fonts/AppleSDGothicNeo.ttc", "/System/Library/Fonts/Supplemental/AppleGothic.ttf", "/Library/Fonts/Arial Unicode.ttf"]
+ .iter()
+ .map(PathBuf::from)
+ .collect()
+ } else {
+ unix_fonts(&[
+ "truetype/nanum/NanumGothic.ttf",
+ "nanum/NanumGothic.ttf",
+ "naver-nanum/NanumGothic.ttf",
+ "truetype/unfonts-core/UnDotum.ttf",
+ "baekmuk-ttf/gulim.ttf",
+ "truetype/baekmuk/gulim.ttf",
+ "truetype/droid/DroidSansFallbackFull.ttf",
+ "google-droid-sans-fonts/DroidSansFallbackFull.ttf",
+ ])
+ }
+}
+
/// Well-known locations of Devanagari (Hindi) faces, best first.
fn devanagari_candidates() -> Vec<PathBuf> {
if cfg!(windows) {
@@@ -323,14 -402,16 +437,17 @@@ mod tests
fn a_script_fallback_is_the_first_candidate_with_the_probe() {
let inter = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../../assets/fonts/Inter-Regular.ttf"));
let candidates = [PathBuf::from("definitely/not/here.ttf"), inter];
- assert!(script_fallback(&candidates, 'A', MAX_BYTES).is_some());
- assert!(script_fallback(&candidates, TELUGU_PROBE, MAX_BYTES).is_none());
- assert!(script_fallback(&candidates, DEVANAGARI_PROBE, MAX_BYTES).is_none());
+ assert!(script_fallback(&candidates, 'A').is_some());
+ assert!(script_fallback(&candidates, TELUGU_PROBE).is_none());
+ assert!(script_fallback(&candidates, DEVANAGARI_PROBE).is_none());
++ assert!(script_fallback(&candidates, HANGUL_PROBE).is_none());
+ assert!(script_fallback(&candidates, SINHALA_PROBE).is_none());
+ assert!(script_fallback(&candidates, TAMIL_PROBE).is_none());
}
#[test]
fn script_candidates_are_absolute_font_files() {
- for list in [devanagari_candidates(), telugu_candidates(), hangul_candidates()] {
- for list in [devanagari_candidates(), telugu_candidates(), sinhala_candidates(), tamil_candidates()] {
++ for list in [devanagari_candidates(), telugu_candidates(), hangul_candidates(), sinhala_candidates(), tamil_candidates()] {
assert!(!list.is_empty());
assert!(list.iter().all(|p| p.is_absolute() || cfg!(windows)), "{list:?}");
assert!(list.iter().all(|p| p.extension().is_some_and(|e| e == "ttf" || e == "ttc")), "{list:?}");
diff --cc crates/ui-egui/src/theme.rs
index 94c6019be,3f43a03dc..3298826b1
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@@ -220,8 -220,10 +220,12 @@@ pub const SYSTEM_FALLBACK: &str = "syst
pub const SYSTEM_DEVANAGARI_FALLBACK: &str = "system-devanagari-fallback";
/// The name of the installed Telugu face [`installed_font_definitions`] may add.
pub const SYSTEM_TELUGU_FALLBACK: &str = "system-telugu-fallback";
+/// The name of the installed Hangul (Korean) face [`installed_font_definitions`] may add.
+pub const SYSTEM_HANGUL_FALLBACK: &str = "system-hangul-fallback";
+ /// The name of the installed Sinhala face [`installed_font_definitions`] may add.
+ pub const SYSTEM_SINHALA_FALLBACK: &str = "system-sinhala-fallback";
+ /// The name of the installed Tamil face [`installed_font_definitions`] may add.
+ pub const SYSTEM_TAMIL_FALLBACK: &str = "system-tamil-fallback";
/// What [`install_fonts_for`] installs: [`font_definitions_for`], then, on desktop, one face
/// already installed on this machine. It only draws characters no embedded face has.
@@@ -234,9 -236,9 +238,10 @@@
/// - Otherwise it is the last fallback of every family (an Arabic file name in a build without
/// craft-fonts).
///
- /// An installed Devanagari face, an installed Telugu face and an installed Hangul face, when
- /// there are, end every family just before that one, so Hindi, Telugu and Korean text draw in a
- /// build without such faces (#1531); no craft-fonts face has Hangul yet.
-/// Installed Devanagari, Telugu, Sinhala and Tamil faces, when there are, end every family just
-/// before that one, so Hindi, Telugu (#1531), Sinhala and Tamil (#1688) text, such as a file
-/// name, draws in a build without such faces.
++/// Installed Devanagari, Telugu, Hangul, Sinhala and Tamil faces, when there are, end every
++/// family just before that one, so Hindi, Telugu (#1531), Korean, Sinhala and Tamil (#1688)
++/// text, such as a file name, draws in a build without such faces; no craft-fonts face has
++/// Hangul yet.
///
/// `PDFCRAFT_SYSTEM_FONTS=0` leaves them out.
pub fn installed_font_definitions(cjk: CjkPreference) -> FontDefinitions {
@@@ -249,7 -251,8 +254,9 @@@
for (name, data) in [
(SYSTEM_DEVANAGARI_FALLBACK, crate::system_fonts::devanagari_fallback()),
(SYSTEM_TELUGU_FALLBACK, crate::system_fonts::telugu_fallback()),
+ (SYSTEM_HANGUL_FALLBACK, crate::system_fonts::hangul_fallback()),
+ (SYSTEM_SINHALA_FALLBACK, crate::system_fonts::sinhala_fallback()),
+ (SYSTEM_TAMIL_FALLBACK, crate::system_fonts::tamil_fallback()),
] {
let Some(data) = data else { continue };
fonts.font_data.insert(name.to_owned(), data);
diff --cc crates/ui-egui/tests/fonts.rs
index d9b3d467c,9cfa36c8a..80b93f768
--- a/crates/ui-egui/tests/fonts.rs
+++ b/crates/ui-egui/tests/fonts.rs
@@@ -311,8 -290,8 +337,8 @@@ fn ui_fonts_work_without_craft_fonts()
theme::install_fonts(&ctx);
}
-/// Latin- and Cyrillic-script catalogs (Czech, Brazilian Portuguese, German, Spanish, French, Russian, Bulgarian, Hungarian, Ukrainian, Italian, Slovene) are drawn entirely by the app's own faces
+/// Latin- and Cyrillic-script catalogs (Czech, Brazilian Portuguese, German, Spanish, French, Russian, Bulgarian, Kazakh, Hungarian, Ukrainian, Italian, Slovene, Lithuanian, Greek, Turkish, Indonesian, Vietnamese) are drawn entirely by the app's own faces
- /// (Inter, JetBrains Mono): no letter falls through to egui's defaults or a CJK fallback. (egui's
+ /// (Inter, JetBrains Mono with Inter fallback): no letter falls through to egui's defaults or a CJK fallback. (egui's
/// `has_glyphs` can't answer this: with only the primary face it is also the replacement face.)
#[test]
fn primary_ui_fonts_cover_latin_and_cyrillic_catalogs() {