Merge pull request #1713

# Conflicts:
#	crates/pptx/tests/it/roundtrip.rs
This commit is contained in:
Brandon Thomas committed 2026-11-03 08:53:00 -05:00
commit 928aa9cc16
4 files changed
+32 -5

No files matched your search

+4 -1
View File
@@ -14,6 +14,7 @@ pub(super) fn align(s: &mut Session, p: &Value) -> Result<Value> {
"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<Align> {
"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",
}
}
+4 -1
View File
@@ -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<Self> {
@@ -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,
+21
View File
@@ -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();
+3 -3
View File
@@ -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,
}
}