From a6c3ffe90f224cfc0d6699669d309569f30fb8bf Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 22:56:58 -0800 Subject: [PATCH 1/2] Type: text hyphenates in Bulgarian, Turkish and Russian, and in German, Polish, Portuguese and Italian with CRAFT_I18N_DIR A run whose language is German, Polish, Portuguese or Italian (any region) now breaks at that language's hyph-utf8 patterns from craft-proof, and a Bulgarian, Turkish or Russian run at that language's syllable rules. The paragraph's Hyphenation options and the Preferences exceptions apply as before, and points that would split a grapheme are dropped. For Bulgarian, Turkish and Russian, craft-proof hyphenates a word outside the language's script as English. For German, Polish, Portuguese and Italian it can also return points from its own heuristics. Those points are refused, so a word outside its language's script stays whole. German, Polish, Portuguese and Italian need craft-proof built with CRAFT_I18N_DIR; without it they keep today's behavior. Other languages, English and the eleven Indian languages are unchanged. --- Cargo.lock | 1 + crates/text/Cargo.toml | 3 + crates/text/src/hyphen.rs | 134 +++++++++++++++++++++++++++++--- crates/text/src/hyphen/proof.rs | 72 +++++++++++++++++ crates/text/src/tests/typo.rs | 37 ++++++++- docs/gaps.md | 5 +- docs/target-app-parity.md | 1 + docs/type-parity.md | 4 +- 8 files changed, 239 insertions(+), 18 deletions(-) create mode 100644 crates/text/src/hyphen/proof.rs diff --git a/Cargo.lock b/Cargo.lock index 81946466b5..806d5d9707 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6996,6 +6996,7 @@ dependencies = [ name = "vectorcraft-text" version = "0.24.1" dependencies = [ + "craft-proof", "harfrust 0.13.3", "icu_segmenter", "kurbo 0.13.1", diff --git a/crates/text/Cargo.toml b/crates/text/Cargo.toml index 1f8ddc3755..aa98fe747f 100644 --- a/crates/text/Cargo.toml +++ b/crates/text/Cargo.toml @@ -28,6 +28,9 @@ icu_segmenter = "2.3" # Grapheme clusters (a Thai consonant with its vowel and tone marks, an accented letter, an emoji # sequence) for caret movement; MIT OR Apache-2.0, already in the build. unicode-segmentation = "1.13" +# Hyphenation patterns and rules for German, Polish, Portuguese, Italian, Bulgarian, Turkish and +# Russian; MIT OR Apache-2.0, already in the build through the engine's spell checking. +craft-proof = { workspace = true } # Draws COLR colour glyphs whose paints documents have no form for (sweep gradients, compositing # modes) into images: the canvas's renderer, already in the build. vello_cpu = { workspace = true } diff --git a/crates/text/src/hyphen.rs b/crates/text/src/hyphen.rs index c940ed85a4..a8fa1cc65b 100644 --- a/crates/text/src/hyphen.rs +++ b/crates/text/src/hyphen.rs @@ -9,8 +9,11 @@ //! [`set_hyphenation_exceptions`]. //! //! Each run hyphenates in its own language ([`vectorcraft_doc::CharStyle::language`]). English -//! uses the rules above; eleven Indian languages use bundled hyph-utf8 patterns. Other languages -//! only break at user exceptions. Indic breaks always preserve Unicode grapheme boundaries. +//! uses the rules above; eleven Indian languages use bundled hyph-utf8 patterns; German, Polish, +//! Portuguese, Italian, Bulgarian, Turkish and Russian use craft-proof's patterns and rules (German, +//! Polish, Portuguese and Italian only in builds that embed their patterns). Other languages only +//! break at user exceptions. Indic and craft-proof breaks always preserve Unicode grapheme +//! boundaries. use std::collections::HashMap; use std::sync::{Mutex, MutexGuard, OnceLock}; @@ -18,22 +21,28 @@ use std::sync::{Mutex, MutexGuard, OnceLock}; use vectorcraft_doc::HyphenationOptions; mod indic; +mod proof; #[derive(Clone, Copy, Debug)] pub(crate) enum Language { None, English, Indic(u8), + /// One of [`proof::TAGS`]. + Proof(u8), } impl Language { /// Select rules by the primary BCP 47 subtag; absent tags retain the English default. pub(crate) fn from_tag(tag: Option<&str>) -> Self { let primary = tag.unwrap_or("en").split('-').next().unwrap_or_default(); + let index = |tags: &[&str]| tags.iter().position(|t| primary.eq_ignore_ascii_case(t)).and_then(|i| u8::try_from(i).ok()); if primary.eq_ignore_ascii_case("en") { Self::English + } else if let Some(i) = index(&indic::TAGS) { + Self::Indic(i) } else { - indic::TAGS.iter().position(|t| primary.eq_ignore_ascii_case(t)).and_then(|i| u8::try_from(i).ok()).map_or(Self::None, Self::Indic) + index(&proof::TAGS).map_or(Self::None, Self::Proof) } } } @@ -189,11 +198,16 @@ fn onset_pair(a: char, b: char) -> bool { /// Whether text in `language` (a [`vectorcraft_doc::CharStyle::language`]: a BCP 47 tag, `None` for /// the default, English: USA) has break points of its own. pub fn language_has_patterns(language: Option<&str>) -> bool { - !matches!(Language::from_tag(language), Language::None) + match Language::from_tag(language) { + Language::None => false, + Language::Proof(index) => proof::available(usize::from(index)), + Language::English | Language::Indic(_) => true, + } } -/// Language-specific break points as character indices. Indic patterns and exceptions are -/// filtered to whole graphemes; the paragraph's length options count Unicode characters. +/// Language-specific break points as character indices. Indic and craft-proof points and +/// exceptions are filtered to whole graphemes; the paragraph's length options count Unicode +/// characters. pub fn hyphen_points_for_language(word: &str, opts: &HyphenationOptions, language: Option<&str>) -> Vec { points_for(word, opts, Language::from_tag(language)) } @@ -220,14 +234,15 @@ pub fn hyphen_points_in(word: &str, opts: &HyphenationOptions, patterns: bool) - points_for(word, opts, if patterns { Language::English } else { Language::None }) } -/// Apply exceptions first, then language rules and paragraph limits, protecting Indic clusters. +/// Apply exceptions first, then language rules and paragraph limits, protecting Indic and +/// craft-proof clusters. pub(crate) fn points_for(word: &str, opts: &HyphenationOptions, language: Language) -> Vec { if let Some(ex) = exception_for(word) { let mut points = match ex { Exception::Never => vec![], Exception::Only(pts) => lowercase_points_to_word(word, &pts), }; - if matches!(language, Language::Indic(_)) { + if matches!(language, Language::Indic(_) | Language::Proof(_)) { indic::retain_boundaries(word, &mut points); } return points; @@ -250,8 +265,9 @@ pub(crate) fn points_for(word: &str, opts: &HyphenationOptions, language: Langua } let before = usize::try_from(opts.after_first).unwrap_or(usize::MAX).max(1); let after = usize::try_from(opts.before_last).unwrap_or(usize::MAX).max(1); - if let Language::Indic(index) = language { - let mut points = indic::points(word, usize::from(index)); + if let Language::Indic(index) | Language::Proof(index) = language { + let mut points = + if matches!(language, Language::Indic(_)) { indic::points(word, usize::from(index)) } else { proof::points(word, usize::from(index)) }; points.retain(|p| *p >= before && n.saturating_sub(*p) >= after); indic::retain_boundaries(word, &mut points); return points; @@ -308,6 +324,96 @@ pub(crate) fn with_hyphenation_exceptions_for_test(source: &str, f: impl FnOnce( #[cfg(test)] mod tests { use super::*; + use craft_proof::hyphen::Patterns; + + /// Paragraph options that let every point through: words of any length, one letter each side. + fn open() -> HyphenationOptions { + HyphenationOptions { words_longer_than: 0, after_first: 1, before_last: 1, ..Default::default() } + } + + /// Bulgarian, Turkish and Russian break by their own syllable rules in every build, with + /// regional tags too. + #[test] + fn rule_languages_break_by_their_own_rules() { + for (tags, word, points) in [ + (["bg", "bg-BG"], "планина", vec![3, 5]), + (["tr", "TR-cy"], "öğrenci", vec![2, 5]), + (["tr", "tr-TR"], "kardeş", vec![3]), + (["ru", "ru-RU"], "родина", vec![2, 4]), + (["ru", "RU"], "сестра", vec![3]), + ] { + for tag in tags { + assert_eq!(hyphen_points_for_language(word, &open(), Some(tag)), points, "{tag}: {word}"); + } + } + // Capitals keep their points. + assert_eq!(hyphen_points_for_language("Родина", &open(), Some("ru")), vec![2, 4]); + } + + /// German, Polish, Portuguese and Italian break at their own TeX patterns when craft-proof + /// embeds them, and not at all otherwise (two letters on each side, as TeX's defaults keep). + #[test] + fn pattern_languages_break_at_their_own_patterns() { + let open = || HyphenationOptions { after_first: 2, before_last: 2, ..open() }; + for (tags, patterns, word, points) in [ + (["de", "de-CH"], Patterns::de(), "Silbentrennung", vec![3, 6, 10]), + (["pl", "pl-PL"], Patterns::pl(), "kobieta", vec![2, 5]), + (["pt", "pt-BR"], Patterns::pt(), "computador", vec![3, 5, 7]), + (["it", "it-CH"], Patterns::it(), "montagna", vec![3, 5]), + ] { + for tag in tags { + let got = hyphen_points_for_language(word, &open(), Some(tag)); + if patterns.is_empty() { + assert!(got.is_empty(), "{tag}: {word}: no patterns embedded, no English fallback: {got:?}"); + } else { + assert_eq!(got, points, "{tag}: {word}"); + } + } + } + // A letter outside the language's patterns sends craft-proof to a general syllable + // heuristic, which isn't the language's own: the word stays whole. + for (tag, word) in [("de", "Søndergaard"), ("pl", "Müllerowa"), ("pt", "Łódzkaliano"), ("it", "Łódzkaliano")] { + assert!(hyphen_points_for_language(word, &open(), Some(tag)).is_empty(), "{tag}: {word}"); + } + } + + /// A word outside its language's script stays whole: craft-proof would hyphenate it as English. + #[test] + fn other_scripts_in_a_language_get_no_english_points() { + for (tag, word) in [("ru", "typography"), ("bg", "typography"), ("ru", "Москваcity"), ("bg", "ёжикова"), ("tr", "родина")] + { + assert!(hyphen_points_for_language(word, &open(), Some(tag)).is_empty(), "{tag}: {word}"); + } + // A combining stress mark in a Russian word, and a joiner in a German one. + assert!(hyphen_points_for_language("моло\u{301}ко", &open(), Some("ru")).is_empty()); + assert!(hyphen_points_for_language("Silben\u{200d}trennung", &open(), Some("de")).is_empty()); + for tag in ["fr", "es", "hr", "cs", "sr", "nl", "sa", "ur", "x-none", "zz"] { + assert!(hyphen_points_for_language("typography", &open(), Some(tag)).is_empty(), "{tag}"); + assert!(hyphen_points_for_language("родина", &open(), Some(tag)).is_empty(), "{tag}"); + } + } + + /// The paragraph's limits and the Preferences exceptions apply to the new languages as they + /// do to English. + #[test] + fn limits_and_exceptions_apply_in_the_rule_languages() { + let d = HyphenationOptions::default(); + // 3 letters each side by default: "ро-ди-на" keeps neither point, "сес-тра" keeps its one. + assert!(hyphen_points_for_language("родина", &d, Some("ru")).is_empty()); + assert_eq!(hyphen_points_for_language("сестра", &d, Some("ru")), vec![3]); + assert!(hyphen_points_for_language("сестра", &HyphenationOptions { words_longer_than: 6, ..d.clone() }, Some("ru")).is_empty()); + assert!(hyphen_points_for_language("Сестра", &HyphenationOptions { capitalized: false, ..d.clone() }, Some("ru")).is_empty()); + assert!(hyphen_points_for_language("СЕСТРА", &d, Some("ru")).is_empty(), "all capitals"); + assert!(hyphen_points_for_language("", &open(), Some("ru")).is_empty()); + assert!(hyphen_points_for_language("я", &open(), Some("ru")).is_empty()); + with_exceptions("родина, kar-deş", || { + assert!(hyphen_points_for_language("родина", &open(), Some("ru")).is_empty()); + assert_eq!(hyphen_points_for_language("kardeş", &d, Some("tr")), vec![3], "marked points ignore the limits"); + }); + with_exceptions("ро-дина", || { + assert_eq!(hyphen_points_for_language("родина", &open(), Some("ru")), vec![2]); + }); + } fn with_exceptions(source: &str, f: impl FnOnce()) { with_hyphenation_exceptions_for_test(source, f); @@ -319,9 +425,15 @@ mod tests { for l in [None, Some("en-US"), Some("en-GB"), Some("EN-gb"), Some("en")] { assert!(language_has_patterns(l), "{l:?}"); } - for l in [Some("de"), Some("fr"), Some("pt"), Some("eng"), Some("x-unknown"), Some(""), Some("é")] { + for l in [Some("fr"), Some("es"), Some("hr"), Some("cs"), Some("nl"), Some("eng"), Some("x-unknown"), Some(""), Some("é")] { assert!(!language_has_patterns(l), "{l:?}"); } + for l in ["bg", "tr", "ru", "BG-bg", "tr-CY", "ru-RU"] { + assert!(language_has_patterns(Some(l)), "{l}"); + } + for (l, embedded) in [("de", Patterns::de()), ("pl", Patterns::pl()), ("pt", Patterns::pt()), ("it", Patterns::it())] { + assert_eq!(language_has_patterns(Some(l)), !embedded.is_empty(), "{l}"); + } for tag in indic::TAGS { assert!(language_has_patterns(Some(tag))); assert!(language_has_patterns(Some(&format!("{}-IN", tag.to_uppercase())))); diff --git a/crates/text/src/hyphen/proof.rs b/crates/text/src/hyphen/proof.rs new file mode 100644 index 0000000000..0baa7ca445 --- /dev/null +++ b/crates/text/src/hyphen/proof.rs @@ -0,0 +1,72 @@ +//! Break points from craft-proof for the languages it has rules or patterns of its own for: +//! German, Polish, Portuguese and Italian (hyph-utf8's TeX patterns, embedded only when craft-proof +//! is built with `CRAFT_I18N_DIR`), Bulgarian and Turkish (syllable rules) and Russian (word-division +//! rules). craft-proof hyphenates any other word as English; those points are dropped here, so a +//! word outside its language's script, or one these rules don't cover, stays whole. + +use craft_proof::hyphen::{Patterns, ProofLang, Source, word_breaks_in}; +use unicode_script::{Script, UnicodeScript}; + +pub(super) const TAGS: [&str; 7] = ["de", "pl", "pt", "it", "bg", "tr", "ru"]; + +fn lang(index: usize) -> Option { + Some(match *TAGS.get(index)? { + "de" => ProofLang::De, + "pl" => ProofLang::Pl, + "pt" => ProofLang::Pt, + "it" => ProofLang::It, + "bg" => ProofLang::Bg, + "tr" => ProofLang::Tr, + "ru" => ProofLang::Ru, + _ => return None, + }) +} + +/// The pattern file of a pattern language, `None` for the languages with rules. +fn patterns(lang: ProofLang) -> Option<&'static Patterns> { + match lang { + ProofLang::De => Some(Patterns::de()), + ProofLang::Pl => Some(Patterns::pl()), + ProofLang::Pt => Some(Patterns::pt()), + ProofLang::It => Some(Patterns::it()), + _ => None, + } +} + +/// Whether the language has break points in this build: the rule languages always, the pattern +/// languages when their patterns are embedded. +pub(super) fn available(index: usize) -> bool { + lang(index).is_some_and(|l| patterns(l).is_none_or(|p| !p.is_empty())) +} + +/// A Latin letter or a combining mark. +fn latin(c: char) -> bool { + matches!(c.script(), Script::Latin | Script::Inherited) && c != '\u{200c}' && c != '\u{200d}' +} + +/// A Cyrillic letter, as craft-proof's Russian rules read them. +fn cyrillic(c: char) -> bool { + matches!(c, '\u{0400}'..='\u{052F}') && c.is_alphabetic() +} + +/// Whether `word` is written in the language's script, and the sources of points that come from +/// the language's own rules or patterns. +fn fits(lang: ProofLang, word: &str) -> Option<&'static [Source]> { + let all = |f: fn(char) -> bool| word.chars().all(f); + match lang { + ProofLang::De | ProofLang::Pl | ProofLang::Pt | ProofLang::It => all(latin).then_some(&[Source::Patterns, Source::Dictionary]), + ProofLang::Tr => word.chars().all(|c| latin(c) || matches!(c, '\'' | '’')).then_some(&[Source::Rules]), + ProofLang::Bg => all(cyrillic).then_some(&[Source::Rules]), + ProofLang::Ru => all(cyrillic).then_some(&[Source::Heuristic]), + _ => None, + } +} + +/// Character-index candidates for one language, before the paragraph's limits; empty when the +/// word isn't in the language's script or the language's own rules give it none. +pub(super) fn points(word: &str, index: usize) -> Vec { + let Some(lang) = lang(index) else { return vec![] }; + let Some(sources) = fits(lang, word) else { return vec![] }; + let (points, source) = word_breaks_in(word, lang); + if sources.contains(&source) { points } else { vec![] } +} diff --git a/crates/text/src/tests/typo.rs b/crates/text/src/tests/typo.rs index 351c698451..80bd7c783a 100644 --- a/crates/text/src/tests/typo.rs +++ b/crates/text/src/tests/typo.rs @@ -1108,18 +1108,49 @@ fn each_run_hyphenates_in_its_own_language() { let saved_without_one = hyphens(None); assert!(saved_without_one > 0, "some words hyphenated"); assert_eq!(hyphens(Some("en-GB")), saved_without_one); - assert_eq!(hyphens(Some("de")), 0, "German has no break points yet"); + assert_eq!(hyphens(Some("fr")), 0, "French has no break points yet"); + assert_eq!(hyphens(Some("ru")), 0, "English words in a Russian run are not hyphenated as English"); assert_eq!(hyphens(Some("x-from-a-file")), 0, "a tag that isn't known has no hyphenation"); - // both in one paragraph: the English run breaks and the German one doesn't + // both in one paragraph: the English run breaks and the French one doesn't let mut t = area(&format!("{text} {text}"), style(14.0), frame, Justify::Left); t.para.hyphenate = true; - edit::style_range(&mut t.runs, text.len(), 2 * text.len() + 1, |s| s.language = Some("de".into())); + edit::style_range(&mut t.runs, text.len(), 2 * text.len() + 1, |s| s.language = Some("fr".into())); let l = layout(db(), &t); let at: Vec = l.glyphs.iter().filter(|g| g.len == 0).map(|g| g.byte).collect(); assert!(!at.is_empty() && at.iter().all(|b| *b < text.len()), "hyphens only in the English run: {at:?}"); } +/// A justified Russian paragraph in a narrow frame breaks its long words at the Russian rules' +/// points with either composer, and not at all with Hyphenate off. +#[test] +fn a_russian_run_hyphenates_at_russian_break_points() { + let text = "Государственное законодательство регулирует достопримечательности."; + let frame = Rect::new(0.0, 0.0, 120.0, 600.0); + let st = CharStyle { language: Some("ru-RU".into()), ..style(14.0) }; + for composer in [Composer::EveryLine, Composer::SingleLine] { + let mut t = area(text, st.clone(), frame, Justify::JustifyLeft); + t.para.composer = composer; + t.para.hyphenate = true; + let l = layout(db(), &t); + let at: Vec = l.glyphs.iter().filter(|g| g.len == 0).map(|g| g.byte).collect(); + assert!(!at.is_empty(), "{composer:?}: some words hyphenated"); + for b in at { + // The word the hyphen splits, and where in it the line ends. + let start = text[..b].rfind(' ').map_or(0, |i| i + 1); + let end = text[b..].find([' ', '.']).map_or(text.len(), |i| b + i); + let word = &text[start..end]; + let point = text[start..b].chars().count(); + assert!( + hyphen::hyphen_points_for_language(word, &t.para.hyphenation, Some("ru")).contains(&point), + "{composer:?}: {word} broken after {point} letters" + ); + } + t.para.hyphenate = false; + assert_eq!(layout(db(), &t).glyphs.iter().filter(|g| g.len == 0).count(), 0, "{composer:?}: Hyphenate off"); + } +} + #[test] fn hyphenated_layout_adds_hyphens() { let text = "Extraordinarily comprehensive typographical considerations notwithstanding everything."; diff --git a/docs/gaps.md b/docs/gaps.md index eda7bb21dd..c09d0e1281 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -515,8 +515,9 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi afterwards opens in a floating window of its own (G7's Float in Window); documents already open stay where they are. Estimate unchanged. - **Done:** Hyphenation › Default Language is the language of new type, unless Document Setup chose one, and each - run hyphenates in its own language (Character panel). English and eleven Indian languages have break - points; other languages stay whole apart from the Exceptions list (#394, #4947). + run hyphenates in its own language (Character panel). English, eleven Indian languages, Bulgarian, Turkish + and Russian have break points, and German, Polish, Portuguese and Italian have them in builds that embed + their patterns; other languages stay whole apart from the Exceptions list (#394, #4947). - **Done (2026-11-14):** Layers panel row context menu: right-clicking a layer, group, or object row shows a context menu (Options…, Duplicate, Delete, Lock Others / Unlock All, Hide Others / Show All, Locate Object, Collect for Export) with proper selection behavior and Undo/Redo tracking. Tests in `crates/ui-egui/src/panels/layers/tests.rs`. - **Missing:** 2 Preferences options stored but not acted on (#394), each waiting on a subsystem of its own: Plug-ins & Scratch Disks › Primary and Secondary (documents are kept in memory; nothing pages to diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 0782bacab9..a3af153277 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1504,6 +1504,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur The Paragraph panel menu's Korean Line Break Anywhere (`text.setFormat {koreanLineBreakAnywhere}`, with the East Asian options, and the East Asian Composition Settings section of Paragraph Style Options) sets for each paragraph whether a line may break between any two Hangul syllables. When it is off, a word that contains Hangul breaks only at its spaces and after punctuation, or where the word is wider than the line, and takes no hyphen. New type has it off; paragraphs saved before the option read as on, so their lines do not move. The Paragraph panel menu's Reset Panel (`text.setStyle`, `text.setFormat` and `text.tabs.clear`) gives the selected type's paragraphs, or the paragraphs the Type tool's selection touches, Auto alignment, no indents or paragraph spacing, Hyphenate off with the default Hyphenation and Justification options, Auto direction, Bottom-to-Bottom Leading, the Line-end Punctuation Half Width Mojikumi Set, Regular burasagari, the Hard kinsoku set, Push Out Only, the Every-line Composer, Bunri-Kinshi, Roman Hanging Punctuation and Korean Line Break Anywhere off, no kashidas and no tab stops, as one undo step. The Paragraph panel menu's Hyphenation… (`ui.hyphenation`, `text.setFormat {wordsLongerThan, afterFirst, beforeLast, hyphenLimit, hyphenationZone, hyphenateCapitalized}`) sets each paragraph's hyphenation limits: the shortest word that breaks, the fewest letters on each side of the hyphen, the most hyphenated lines in a row, a zone at the right edge where the Single-line Composer breaks before a word instead of hyphenating it, and whether capitalized words break. The defaults are words longer than 5 letters, 3 letters on each side, no limit or zone, and capitalized words hyphenated; paragraph styles and the native file keep the options. + Text whose Character panel Language is Bulgarian, Turkish or Russian hyphenates by that language's syllable rules, and German, Polish, Portuguese or Italian text by that language's hyph-utf8 patterns in builds that embed them, within the paragraph's Hyphenation options, in both composers ([Assign languages to text](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/assign-languages-to-text.html)). A word written outside its language's script stays whole, and the Preferences exceptions still come first. PDF export with type as text writes the hyphen that ends a line broken inside a word as a hyphen character where the line draws it, and the file opens with the hyphen in the line's text; kashidas are drawn as paths. The Paragraph panel's Insert Kashidas (with the Indic options; `text.setFormat {kashida}`) lengthens each Arabic word of a justified horizontal area type line with a kashida, a tatweel between its last pair of joined letters, before the word spaces widen: Short, Medium and Long kashidas are at most a quarter, half and a whole em long, Stylistic ones are whole tatweels up to an em, and None (the default) leaves the line as before; paragraph styles and the native file keep the setting. The Character panel menu's Kashidas switch (with the Indic options; `text.setFormat` / `text.setRangeStyle {kashidas}`) allows Kashidas on selected characters, on by default for new and old text. A pair of joined letters receives one only when both characters allow it; turning one off leaves other eligible pairs in the word available. Character styles and the native file keep the switch. [Public help](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/justify-text-using-kashida-and-hyphenation.html) documents the menu control and the separate paragraph length choices; the default and pair rule are VectorCraft choices. diff --git a/docs/type-parity.md b/docs/type-parity.md index 7697025ca9..70e82e7020 100644 --- a/docs/type-parity.md +++ b/docs/type-parity.md @@ -77,8 +77,8 @@ against Illustrator's public documentation; **estimated** unless noted. | CJK: warichu | done | Character panel menu › Warichu and Warichu Settings… (`text.setFormat` / `text.setRangeStyle {warichu, warichuLines, warichuGap, warichuScale, warichuAlign}`, `ui.warichuSettings`), with Show East Asian Options ([Format East Asian characters](https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html)): marked characters set at a percentage of their size and stacked on 1 to 6 lines inside their line, one above the other in horizontal type and side by side in vertical type, with a line gap and eight alignments; a block stays whole on one line. Saved natively, carried by character styles, drawn on the canvas and in every export (SVG, PDF and `.ai` write such type as outlines). Type on a path sets the characters at their own size. Evidence: `tests::warichu`, `dialogs::warichu::tests`, `typecmd::area_tests::warichu_is_a_character_attribute_set_saved_and_exported` | | CJK: composite fonts | partial | Type › Composite Fonts… (`type.compositeFonts.set`), with Show East Asian Options: a font made of a font per class of character (Kanji, Kana, Punctuation, Symbols, Roman, Numerals), each with its own style, size and baseline in percent of the type's size, Kana, Roman and Numerals with horizontal and vertical scale, and Kana with Scale at Center; New, Delete Font, Import… and Export… (`.vccomposite`, `type.compositeFonts.import` and `.export`) ([Creating composite fonts](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=347)); custom character sets (Custom: New, Delete Set, characters added by Direct Entry or Unicode code and deleted), each with its own font, style, size, baseline and scales, ahead of the classes, the later set winning a character two list (`custom` in `type.compositeFonts.set`) ([Customize characters in a composite font](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=348)). Composite fonts are listed first in the font menus, saved with the document, and their type is laid out per set and class; SVG and legacy `.ai` write it as outlines. Show Sample draws the font picked with lines for its ICF box, em box, baseline, cap height, highest ascent and lowest descent, highest ascender and x-height, each shown or hidden by its button, at the Zoom picked ([Creating composite fonts](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf#page=352)). Not yet: the Units menu. Evidence: `text::composite::tests::characters_fall_in_their_classes`, `text::composite::tests::custom_sets_take_their_characters_before_the_classes`, `tests::composite::composite_type_draws_each_class_in_its_font`, `tests::composite::custom_character_sets_take_their_characters_first`, `compositefonts::tests`, `dialogs::composite_fonts::tests` | | CJK: ruby | partial | ruby (ふりがな) for live text (`type.ruby`): a reading over a byte range, above (right of the column in vertical type) or below, start/centre/end alignment, size, overhang or squeeze; saved natively, laid out with its line growing, drawn on the canvas, in SVG and PDF (as outlines where ruby is present), in EPS, EMF/WMF and legacy `.ai` (legacy `.ai` writes type with ruby as outlines), and kept by Create Outlines, Expand Appearance and flattening, each glyph where the layout puts it (`typecmd::ruby_tests::create_outlines_keeps_the_ruby_where_it_is_laid_out`) | #633 | -| Language per character (Character panel › Language, character styles), text shaped in it | done | `text.setFormat` / `text.setRangeStyle {language}` by name or BCP 47 tag, one of Document Setup's languages (Hindi, Marathi, Gujarati, Bengali, Punjabi, Tamil, Telugu, Kannada, Malayalam, Odia and Urdu added, #4943; Assamese and Sanskrit added, #4947; Serbian: Cyrillic, Serbian: Latin and Croatian); the shaper gets the tag, so the font's language forms apply (OpenType `locl`: Turkish keeps `fi` apart and the dot on its i, #4940); new type takes the document's language; saved as the tag only when set, carried by character styles (#4946). English and eleven Indian languages hyphenate by run language; Sanskrit automatic hyphenation awaits allowlisted patterns (#4947). Not yet: `.ai`/PDF import of a text's language, paragraph styles. Evidence: `features::tests::language_picks_the_fonts_forms`, `features::tests::serbian_gets_the_fonts_serbian_forms`, `typecmd::area_tests::language_is_a_character_attribute_saved_only_when_set`, `tests::typo::indic_language_runs_hyphenate_with_both_composers`, `hyphen::tests::sanskrit_without_allowlisted_patterns_uses_only_exceptions`; spelling is checked in each run's Language (`text.spelling.check`, #4936) | -| Language per character (Character panel › Language, character styles), text shaped in it | done | `text.setFormat` / `text.setRangeStyle {language}` by name or BCP 47 tag, one of Document Setup's languages (Hindi, Marathi, Gujarati, Bengali, Punjabi, Tamil, Telugu, Kannada, Malayalam, Odia and Urdu added, #4943; Serbian: Cyrillic, Serbian: Latin and Croatian; Bulgarian, #5945); the shaper gets the tag, so the font's language forms apply (OpenType `locl`: Turkish keeps `fi` apart and the dot on its i, #4940); new type takes the document's language; saved as the tag only when set, carried by character styles (#4946). Not yet: hyphenation by it in languages other than English and the eleven Indian languages above, `.ai`/PDF import of a text's language, paragraph styles. Evidence: `features::tests::language_picks_the_fonts_forms`, `features::tests::serbian_gets_the_fonts_serbian_forms`, `typecmd::area_tests::language_is_a_character_attribute_saved_only_when_set`; spelling is checked in each run's Language (`text.spelling.check`, #4936) | +| Language per character (Character panel › Language, character styles), text shaped in it | done | `text.setFormat` / `text.setRangeStyle {language}` by name or BCP 47 tag, one of Document Setup's languages (Hindi, Marathi, Gujarati, Bengali, Punjabi, Tamil, Telugu, Kannada, Malayalam, Odia and Urdu added, #4943; Assamese and Sanskrit added, #4947; Serbian: Cyrillic, Serbian: Latin and Croatian); the shaper gets the tag, so the font's language forms apply (OpenType `locl`: Turkish keeps `fi` apart and the dot on its i, #4940); new type takes the document's language; saved as the tag only when set, carried by character styles (#4946). English, eleven Indian languages, Bulgarian, Turkish and Russian hyphenate by run language, and German, Polish, Portuguese and Italian do in builds that embed their patterns; a word outside its language's script stays whole; Sanskrit automatic hyphenation awaits allowlisted patterns (#4947). Not yet: `.ai`/PDF import of a text's language, paragraph styles. Evidence: `features::tests::language_picks_the_fonts_forms`, `features::tests::serbian_gets_the_fonts_serbian_forms`, `typecmd::area_tests::language_is_a_character_attribute_saved_only_when_set`, `tests::typo::indic_language_runs_hyphenate_with_both_composers`, `hyphen::tests::sanskrit_without_allowlisted_patterns_uses_only_exceptions`, `hyphen::tests::rule_languages_break_by_their_own_rules`, `hyphen::tests::pattern_languages_break_at_their_own_patterns`, `tests::typo::a_russian_run_hyphenates_at_russian_break_points`; spelling is checked in each run's Language (`text.spelling.check`, #4936) | +| Language per character (Character panel › Language, character styles), text shaped in it | done | `text.setFormat` / `text.setRangeStyle {language}` by name or BCP 47 tag, one of Document Setup's languages (Hindi, Marathi, Gujarati, Bengali, Punjabi, Tamil, Telugu, Kannada, Malayalam, Odia and Urdu added, #4943; Serbian: Cyrillic, Serbian: Latin and Croatian; Bulgarian, #5945); the shaper gets the tag, so the font's language forms apply (OpenType `locl`: Turkish keeps `fi` apart and the dot on its i, #4940); new type takes the document's language; saved as the tag only when set, carried by character styles (#4946). Not yet: hyphenation by it in languages other than English, the eleven Indian languages above, Bulgarian, Turkish, Russian, German, Polish, Portuguese and Italian, `.ai`/PDF import of a text's language, paragraph styles. Evidence: `features::tests::language_picks_the_fonts_forms`, `features::tests::serbian_gets_the_fonts_serbian_forms`, `typecmd::area_tests::language_is_a_character_attribute_saved_only_when_set`; spelling is checked in each run's Language (`text.spelling.check`, #4936) | | No Break | done | Character panel menu (`text.setFormat` / `text.setRangeStyle {noBreak}`): the marked characters stay on one line, including across a space; a run that does not fit after earlier text moves together, and a run longer than the line stays together. Evidence: `layout::wrapping_tests::no_break_keeps_marked_characters_on_one_line`, `tests::no_break_keeps_marked_words_on_one_line`, `typecmd::no_break_is_a_character_attribute_saved_only_when_on` | | Inline symbols in text | beyond Illustrator | not scored | | Align Stroke (inside, outside) on live type's character stroke | beyond Illustrator | not scored; `stroke.set {align}` and `text.setRangeStyle {strokeOptions: {align}}`; saved natively, drawn around the glyphs on the canvas and in PDF, EPS and SVG (live text, stroke on the glyph outlines); visual bounds grow with it (#2294) | From 6a66f9ad94a2a3465f2821881f8e16052c97b19f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 07:33:39 -0800 Subject: [PATCH 2/2] Type: decomposed Cyrillic and capital words hyphenate as their composed spelling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Russian or Bulgarian word written with a combining breve (`и` + U+0306 for `й`) failed the Cyrillic script check and stayed whole; the check now reads the composed word, so it breaks at the same characters as `чайник`. A stress mark, which composes with nothing, still keeps the word whole. The all-capitals guard skipped a decomposed capital such as `O` + U+0308, since a combining mark has no case, so `ÖĞRENCİ` spelled that way was hyphenated in Turkish; the guard now counts only the letters. --- Cargo.lock | 1 + crates/text/Cargo.toml | 3 +++ crates/text/src/hyphen.rs | 21 +++++++++++++++++++-- crates/text/src/hyphen/proof.rs | 10 +++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f55b9ebc77..783f779f0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7142,6 +7142,7 @@ dependencies = [ "subsetter", "unicode-bidi", "unicode-general-category", + "unicode-normalization", "unicode-script", "unicode-segmentation", "vectorcraft-doc", diff --git a/crates/text/Cargo.toml b/crates/text/Cargo.toml index aa98fe747f..fa88e3f9ef 100644 --- a/crates/text/Cargo.toml +++ b/crates/text/Cargo.toml @@ -31,6 +31,9 @@ unicode-segmentation = "1.13" # Hyphenation patterns and rules for German, Polish, Portuguese, Italian, Bulgarian, Turkish and # Russian; MIT OR Apache-2.0, already in the build through the engine's spell checking. craft-proof = { workspace = true } +# Composes a decomposed Cyrillic word (`и` + U+0306 is `й`) before its script check; MIT OR +# Apache-2.0, already in the build through craft-proof. +unicode-normalization = "0.1.26" # Draws COLR colour glyphs whose paints documents have no form for (sweep gradients, compositing # modes) into images: the canvas's renderer, already in the build. vello_cpu = { workspace = true } diff --git a/crates/text/src/hyphen.rs b/crates/text/src/hyphen.rs index a8fa1cc65b..435aae7ea9 100644 --- a/crates/text/src/hyphen.rs +++ b/crates/text/src/hyphen.rs @@ -256,8 +256,9 @@ pub(crate) fn points_for(word: &str, opts: &HyphenationOptions, language: Langua if n <= longer_than || !c.iter().all(|&ch| is_word_char(ch)) { return vec![]; } - // A capitalised run like "NASA" or a proper name stays whole only when all caps. - if c.iter().all(|c| c.is_uppercase()) { + // A capitalised run like "NASA" or a proper name stays whole only when all caps. Combining + // marks have no case, so a decomposed capital ("O" + U+0308) counts by its letter. + if c.iter().filter(|&&ch| !unicode_normalization::char::is_combining_mark(ch)).all(|c| c.is_uppercase()) { return vec![]; } if !opts.capitalized && c.first().is_some_and(|c| c.is_uppercase()) { @@ -393,6 +394,22 @@ mod tests { } } + /// A decomposed word breaks as its composed spelling does, at the matching characters, and a + /// decomposed all-capitals word stays whole as the composed one does. + #[test] + fn decomposed_words_break_as_composed_ones() { + for tag in ["ru", "bg"] { + let composed = hyphen_points_for_language("чайник", &open(), Some(tag)); + assert!(!composed.is_empty(), "{tag}"); + // `и` + U+0306 is `й`: points after it move one character on. + let shifted: Vec = composed.iter().map(|&p| if p >= 3 { p + 1 } else { p }).collect(); + assert_eq!(hyphen_points_for_language("чаи\u{306}ник", &open(), Some(tag)), shifted, "{tag}"); + } + assert!(hyphen_points_for_language("ÖĞRENCİ", &open(), Some("tr")).is_empty()); + assert!(hyphen_points_for_language("O\u{308}ĞRENCİ", &open(), Some("tr")).is_empty(), "decomposed capitals"); + assert_eq!(hyphen_points_for_language("o\u{308}ğrenci", &open(), Some("tr")), vec![3, 6]); + } + /// The paragraph's limits and the Preferences exceptions apply to the new languages as they /// do to English. #[test] diff --git a/crates/text/src/hyphen/proof.rs b/crates/text/src/hyphen/proof.rs index 0baa7ca445..05d5f4634b 100644 --- a/crates/text/src/hyphen/proof.rs +++ b/crates/text/src/hyphen/proof.rs @@ -5,6 +5,7 @@ //! word outside its language's script, or one these rules don't cover, stays whole. use craft_proof::hyphen::{Patterns, ProofLang, Source, word_breaks_in}; +use unicode_normalization::UnicodeNormalization; use unicode_script::{Script, UnicodeScript}; pub(super) const TAGS: [&str; 7] = ["de", "pl", "pt", "it", "bg", "tr", "ru"]; @@ -50,14 +51,17 @@ fn cyrillic(c: char) -> bool { } /// Whether `word` is written in the language's script, and the sources of points that come from -/// the language's own rules or patterns. +/// the language's own rules or patterns. A Cyrillic word is checked composed, as craft-proof +/// hyphenates it: `и` + U+0306 is `й`, while a stress mark, which composes with nothing, is not a +/// letter. fn fits(lang: ProofLang, word: &str) -> Option<&'static [Source]> { let all = |f: fn(char) -> bool| word.chars().all(f); + let composed_cyrillic = || word.nfc().all(cyrillic); match lang { ProofLang::De | ProofLang::Pl | ProofLang::Pt | ProofLang::It => all(latin).then_some(&[Source::Patterns, Source::Dictionary]), ProofLang::Tr => word.chars().all(|c| latin(c) || matches!(c, '\'' | '’')).then_some(&[Source::Rules]), - ProofLang::Bg => all(cyrillic).then_some(&[Source::Rules]), - ProofLang::Ru => all(cyrillic).then_some(&[Source::Heuristic]), + ProofLang::Bg => composed_cyrillic().then_some(&[Source::Rules]), + ProofLang::Ru => composed_cyrillic().then_some(&[Source::Heuristic]), _ => None, } }