diff --git a/crates/engine/src/cmd/format/paragraph.rs b/crates/engine/src/cmd/format/paragraph.rs index 6d575ff1a..e4b02a4b9 100644 --- a/crates/engine/src/cmd/format/paragraph.rs +++ b/crates/engine/src/cmd/format/paragraph.rs @@ -14,6 +14,7 @@ pub(super) fn align(s: &mut Session, p: &Value) -> Result { "justify" | "just" => Align::Justify, "justifyLow" | "justLow" => Align::JustLow, "distributed" | "dist" => Align::Distributed, + "thaiDist" => Align::ThaiDistributed, _ => Align::Left, }; align_to(s, a) @@ -186,7 +187,8 @@ fn parse_align(cmd: &str, s: &str) -> Result { "justify" | "just" => Align::Justify, "justLow" => Align::JustLow, "distributed" | "dist" => Align::Distributed, - _ => return Err(bad(cmd, "`align` must be left, center, right, justify, justLow or distributed")), + "thaiDist" => Align::ThaiDistributed, + _ => return Err(bad(cmd, "`align` must be left, center, right, justify, justLow, distributed or thaiDist")), }) } @@ -198,6 +200,7 @@ fn align_name(a: Align) -> &'static str { Align::Justify => "justify", Align::JustLow => "justLow", Align::Distributed => "distributed", + Align::ThaiDistributed => "thaiDist", } } diff --git a/crates/model/src/text.rs b/crates/model/src/text.rs index f9263a117..ac8dd2cd6 100644 --- a/crates/model/src/text.rs +++ b/crates/model/src/text.rs @@ -157,6 +157,7 @@ pub enum Align { /// Justified with kashida (tatweel) elongation for Arabic (`justLow`). JustLow, Distributed, + ThaiDistributed, } impl Align { @@ -168,6 +169,7 @@ impl Align { Align::Justify => "just", Align::JustLow => "justLow", Align::Distributed => "dist", + Align::ThaiDistributed => "thaiDist", } } pub fn from_xml(s: &str) -> Option { @@ -175,7 +177,8 @@ impl Align { "l" => Align::Left, "ctr" => Align::Center, "r" => Align::Right, - "just" | "thaiDist" => Align::Justify, + "just" => Align::Justify, + "thaiDist" => Align::ThaiDistributed, "justLow" => Align::JustLow, "dist" => Align::Distributed, _ => return None, diff --git a/crates/pptx/tests/it/roundtrip.rs b/crates/pptx/tests/it/roundtrip.rs index 5dd390530..29b75c83f 100644 --- a/crates/pptx/tests/it/roundtrip.rs +++ b/crates/pptx/tests/it/roundtrip.rs @@ -519,6 +519,27 @@ fn normalized_character_height_survives_two_pptx_round_trips() { assert_eq!(run.props.normalize_height, None); } +#[test] +fn thai_distributed_alignment_survives_two_pptx_round_trips() { + assert_eq!(Align::from_xml("thaiDist"), Some(Align::ThaiDistributed)); + assert_eq!(Align::ThaiDistributed.xml(), "thaiDist"); + assert_eq!(Align::from_xml("just"), Some(Align::Justify)); + + let mut p = Presentation::default(); + let mut slide = new_slide(&mut p, "Thai distributed alignment"); + let mut text = shape(&mut p, "Text", 10.0, 10.0, 200.0, 80.0); + let mut body = TextBody::from_text("one two three"); + body.paragraphs[0].props.align = Some(Align::ThaiDistributed); + text.text = Some(body); + slide.shapes.push(text); + p.slides.push(Arc::new(slide)); + + let twice = round(&round(&p)); + let slide = twice.slides.last().expect("added slide"); + let text = by_name(slide, "Text").text.as_ref().expect("text body"); + assert_eq!(text.paragraphs[0].props.align, Some(Align::ThaiDistributed)); +} + #[test] fn shapes_fills_lines_effects_round_trip() { let p = rich_deck(); diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index c0422815e..c52b840a2 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -418,7 +418,7 @@ fn justify_line(p: &ParaShaped, rl: &RawLine, adv: &mut [f64], align: Align, sla filled = true; } } - if stretch && !filled && matches!(align, Align::Justify | Align::JustLow) { + if stretch && !filled && matches!(align, Align::Justify | Align::JustLow | Align::ThaiDistributed) { let spaces = line_cells.iter().filter(|c| c.ch == ' ').count(); if spaces > 0 { for (a, c) in adv.iter_mut().zip(line_cells) { @@ -450,8 +450,8 @@ fn line_left(align: Align, filled: bool, rtl: bool, bx: (f64, f64), line_w: f64, Align::Center => box_l + (box_r - box_l - line_w) / 2.0, Align::Distributed if n <= 1 => box_l + slack / 2.0, // Justified lines that aren't stretched (the last one) sit at the start edge. - Align::Justify | Align::JustLow | Align::Distributed if rtl => box_r - line_w, - Align::Justify | Align::JustLow | Align::Distributed => box_l, + Align::Justify | Align::JustLow | Align::Distributed | Align::ThaiDistributed if rtl => box_r - line_w, + Align::Justify | Align::JustLow | Align::Distributed | Align::ThaiDistributed => box_l, } }