mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-05 01:49:35 +00:00
Preserve Thai distributed paragraph alignment
This commit is contained in:
1 parent
8ec4f6cabb
commit
bb417bf98a
4 files changed
+32
-5
No files matched your search
@@ -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)
|
||||
@@ -184,7 +185,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")),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -196,6 +198,7 @@ fn align_name(a: Align) -> &'static str {
|
||||
Align::Justify => "justify",
|
||||
Align::JustLow => "justLow",
|
||||
Align::Distributed => "distributed",
|
||||
Align::ThaiDistributed => "thaiDist",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -468,6 +468,27 @@ fn text_and_formatting_round_trip() {
|
||||
assert_eq!(run.text, "x=1");
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user