DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge upstream main 464a442 (7 PRs landed) into next
aiongg7e0afa24e830
diff --cc crates/compose/src/tests.rsindex fc982e398,70b0198ff..3f726d033--- a/crates/compose/src/tests.rs+++ b/crates/compose/src/tests.rs@@@ -2330,24 -1094,40 +2330,45 @@@ fn empty_paragraph_takes_its_marks_form}#[test]-fn only_english_text_gets_english_hyphenation() {- let text = "internationalization internationalization internationalization internationalization";- let narrow = Rect::new(36.0, 36.0, 120.0, 700.0);- let hyphenated = |d: &Document, sid| all_lines(&compose_story(d, sid, &ComposeOptions::default())).iter().filter(|l| l.hyphenated).count();- let (d, sid, _) = doc_with(text, narrow, ParaAttrs::default());- assert!(hyphenated(&d, sid) > 0, "English hyphenates");- let mut d2 = d.clone();- let st = d2.story_mut(sid).unwrap();- let n = st.len();- st.format_chars(0..n, |f| f.over.language = Some("French".into()));- assert_eq!(hyphenated(&d2, sid), 0, "French isn't hyphenated with English rules");+fn empty_paragraph_uses_its_own_mark_not_the_previous_one() {+ // "One\n" is 20 pt; the empty paragraph's mark (byte 4) and "Two" are 6 pt with 8 pt leading.+ // The format run boundary sits exactly at the empty paragraph's start: its line must take the+ // 8 pt leading of its own mark, not the previous paragraph's 20 pt (auto 24) mark.+ let text = "One\n\nTwo";+ let (mut d, sid, _) = doc_with(text, Rect::new(0.0, 0.0, 200.0, 200.0), ParaAttrs::default());+ let st = d.story_mut(sid).unwrap();+ st.format_chars(0..4, |f| f.over.size = Some(20.0));+ st.format_chars(4..text.len(), |f| {+ f.over.size = Some(6.0);+ f.over.leading = Some(designcraft_doc::Leading::Points(8.0));+ });+ let cs = compose_story(&d, sid, &ComposeOptions::default());+ let lines = all_lines(&cs);+ assert_eq!(lines.len(), 3);+ assert!((lines[1].baseline - lines[0].baseline - 8.0).abs() < 1e-6, "{} {}", lines[0].baseline, lines[1].baseline);}+ #[test]+ fn spanish_text_gets_spanish_hyphenation() {+ let text = "La transición democrática fue una construcción colectiva extraordinariamente compleja y desesperadamente necesaria.";+ let narrow = Rect::new(36.0, 36.0, 120.0, 700.0);+ let (mut d, sid, _) = doc_with(text, narrow, ParaAttrs::default());+ let st = d.story_mut(sid).unwrap();+ let n = st.len();+ st.format_chars(0..n, |f| f.over.language = Some("Spanish".into()));+ let cs = compose_story(&d, sid, &ComposeOptions::default());+ let lines = all_lines(&cs);+ let hy: Vec<&str> = lines.iter().filter(|l| l.hyphenated).map(|l| text[l.range.clone()].trim_end()).collect();+ assert!(!hy.is_empty(), "Spanish hyphenates");+ for l in &hy {+ let last: String = l.chars().rev().take_while(|c| c.is_alphabetic()).collect::<Vec<_>>().into_iter().rev().collect();+ let whole = text[text.find(l).unwrap() + l.len() - last.len()..].split(|c: char| !c.is_alphabetic()).next().unwrap();+ let es = hyphen::Lang::for_language("Spanish").unwrap();+ let pts = hyphen::hyphen_points_in(whole, &hyphen::Limits::default(), es);+ assert!(pts.contains(&last.chars().count()), "break {last}- in {whole} is a Bezos point");+ }+ }+#[test]fn cjk_aki_adds_space_without_scaling_outlines() {let (mut d, sid, _) = doc_with("AB", Rect::new(0.0, 0.0, 300.0, 100.0), ParaAttrs::default());