diff --git a/Cargo.lock b/Cargo.lock index 6e15cf738..0004ec0c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2347,6 +2347,7 @@ dependencies = [ "regex", "unicode-bidi", "unicode-bidi-mirroring", + "unicode-properties", "unicode-script", "unicode-segmentation", ] diff --git a/crates/compose/Cargo.toml b/crates/compose/Cargo.toml index 48116b1fe..900530b15 100644 --- a/crates/compose/Cargo.toml +++ b/crates/compose/Cargo.toml @@ -13,6 +13,7 @@ unicode-bidi = { workspace = true } unicode-segmentation = { workspace = true } unicode-bidi-mirroring = { workspace = true } unicode-script = { workspace = true } +unicode-properties = { version = "0.1.4", default-features = false, features = ["general-category"] } designcraft-geom = { workspace = true } designcraft-color = { workspace = true } designcraft-doc = { workspace = true } diff --git a/crates/compose/src/breaker.rs b/crates/compose/src/breaker.rs index 792d3f51f..c8035f6a3 100644 --- a/crates/compose/src/breaker.rs +++ b/crates/compose/src/breaker.rs @@ -9,6 +9,8 @@ //! ([`TIER_COST`]), so the composer prefers word-space changes, then hyphenation, then letter //! spacing, then glyph scaling. +use unicode_properties::{GeneralCategoryGroup, UnicodeGeneralCategory}; + use crate::shape::{Glyph, SOFT_HYPHEN}; /// One line chosen by a breaker: glyphs `start..end` are visible; `next` is where the next line starts. @@ -407,10 +409,8 @@ pub(super) fn dot_break(text: &str, glyphs: &[Glyph], i: usize) -> bool { fn has_dot_letters(chars: impl Iterator, minimum: usize) -> bool { // Some combining marks have the Unicode Alphabetic property as well. - static MARK: std::sync::LazyLock> = std::sync::LazyLock::new(|| regex::Regex::new(r"\A\p{M}\z").ok()); - let Some(mark) = MARK.as_ref() else { return false }; chars - .filter(|&c| c.is_ascii() || !mark.is_match(c.encode_utf8(&mut [0; 4]))) + .filter(|&c| c.is_ascii() || c.general_category_group() != GeneralCategoryGroup::Mark) .take_while(|&c| c.is_alphabetic() && !is_cjk(c)) .take(minimum) .count() @@ -1187,6 +1187,17 @@ pub fn balanced(text: &str, glyphs: &[Glyph], hyph_after: &[bool], sp: &Spacing, mod tests { use super::*; + #[test] + fn alphabetic_and_extended_marks_do_not_add_dot_break_letters() { + assert!('\u{0345}'.is_alphabetic()); + assert!('\u{093E}'.is_alphabetic()); + // Nonspacing, spacing, enclosing, and extended combining marks. + for mark in ['\u{0345}', '\u{093E}', '\u{20DD}', '\u{1AB0}'] { + assert!(!has_dot_letters(['P', 'e', mark].into_iter(), 3), "{mark:?}"); + assert!(has_dot_letters(['P', 'e', mark, 'r'].into_iter(), 3), "{mark:?}"); + } + } + #[test] fn tiers_are_used_in_order() { // Word stretch alone.