mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-18 16:14:35 +00:00
PPTX: horzOverflow never reads or writes ellipsis (vertical only in ST_TextHorzOverflowType)
This commit is contained in:
1 parent
44b133a3c9
commit
67c1d78948
6 files changed
+35
-6
No files matched your search
@@ -150,6 +150,16 @@ impl TextOverflow {
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// A `horzOverflow` value: `ST_TextHorzOverflowType` has only `overflow` and `clip`.
|
||||
pub fn from_horz_xml(value: &str) -> Option<Self> {
|
||||
Self::from_xml(value).filter(|v| *v != Self::Ellipsis)
|
||||
}
|
||||
|
||||
/// The `horzOverflow` attribute to write, leaving out `ellipsis`, which is vertical only.
|
||||
pub fn horz_xml(v: Option<Self>) -> Option<&'static str> {
|
||||
v.filter(|v| *v != Self::Ellipsis).map(Self::xml)
|
||||
}
|
||||
}
|
||||
|
||||
impl BodyProps {
|
||||
|
||||
@@ -359,7 +359,7 @@ pub fn body_pr(b: &El) -> BodyProps {
|
||||
upright: b.bool("upright"),
|
||||
space_first_last: b.bool("spcFirstLastPara"),
|
||||
vert_overflow: b.attr("vertOverflow").and_then(deckcraft_model::text::TextOverflow::from_xml),
|
||||
horz_overflow: b.attr("horzOverflow").and_then(deckcraft_model::text::TextOverflow::from_xml),
|
||||
horz_overflow: b.attr("horzOverflow").and_then(deckcraft_model::text::TextOverflow::from_horz_xml),
|
||||
..Default::default()
|
||||
};
|
||||
for e in b.elements() {
|
||||
|
||||
@@ -805,7 +805,7 @@ fn cell(imp: &mut Imp, part: &Part, tc: &El) -> Cell {
|
||||
]);
|
||||
}
|
||||
c.anchor = pr.attr("anchor").and_then(Anchor::from_xml);
|
||||
c.horz_overflow = pr.attr("horzOverflow").and_then(deckcraft_model::text::TextOverflow::from_xml);
|
||||
c.horz_overflow = pr.attr("horzOverflow").and_then(deckcraft_model::text::TextOverflow::from_horz_xml);
|
||||
c.vertical = pr.attr("vert").and_then(TextDir::from_xml);
|
||||
for (i, n) in ["lnL", "lnR", "lnT", "lnB"].iter().enumerate() {
|
||||
if let Some(ln) = pr.child(n)
|
||||
|
||||
@@ -470,7 +470,7 @@ pub fn body_pr(w: &mut W, b: &BodyProps) {
|
||||
.b("upright", b.upright)
|
||||
.b("spcFirstLastPara", b.space_first_last)
|
||||
.o("vertOverflow", b.vert_overflow.map(|v| v.xml()))
|
||||
.o("horzOverflow", b.horz_overflow.map(|v| v.xml()));
|
||||
.o("horzOverflow", deckcraft_model::text::TextOverflow::horz_xml(b.horz_overflow));
|
||||
let warp = b.warp.as_deref().filter(|s| !s.is_empty() && s.chars().all(|c| c.is_ascii_alphanumeric()));
|
||||
if warp.is_none() && b.autofit.is_none() {
|
||||
w.empty("a:bodyPr", a);
|
||||
|
||||
@@ -746,7 +746,7 @@ fn table(w: &mut W, x: &mut Exp, o: &mut Out, t: &Table) {
|
||||
other => other.xml(),
|
||||
}),
|
||||
);
|
||||
a = a.o("horzOverflow", c.horz_overflow.map(|v| v.xml()));
|
||||
a = a.o("horzOverflow", deckcraft_model::text::TextOverflow::horz_xml(c.horz_overflow));
|
||||
w.open("a:tcPr", a);
|
||||
for (tag, l) in [
|
||||
("a:lnL", &c.borders[0]),
|
||||
|
||||
@@ -475,7 +475,7 @@ fn text_overflow_policies_survive_two_pptx_round_trips() {
|
||||
let mut text = shape(&mut p, "Text", 10.0, 10.0, 200.0, 80.0);
|
||||
let mut body = TextBody::from_text("policy");
|
||||
body.body.vert_overflow = Some(TextOverflow::Clip);
|
||||
body.body.horz_overflow = Some(TextOverflow::Ellipsis);
|
||||
body.body.horz_overflow = Some(TextOverflow::Overflow);
|
||||
text.text = Some(body);
|
||||
let mut table_shape = shape(&mut p, "Table", 10.0, 100.0, 200.0, 80.0);
|
||||
let mut table = Table::new(1, 1, 200.0, 80.0);
|
||||
@@ -488,11 +488,30 @@ fn text_overflow_policies_survive_two_pptx_round_trips() {
|
||||
let slide = twice.slides.last().expect("added slide");
|
||||
let text = by_name(slide, "Text").text.as_ref().expect("text body");
|
||||
assert_eq!(text.body.vert_overflow, Some(TextOverflow::Clip));
|
||||
assert_eq!(text.body.horz_overflow, Some(TextOverflow::Ellipsis));
|
||||
assert_eq!(text.body.horz_overflow, Some(TextOverflow::Overflow));
|
||||
let ShapeKind::Table(table) = &by_name(slide, "Table").kind else { panic!("table") };
|
||||
assert_eq!(table.rows[0].cells[0].horz_overflow, Some(TextOverflow::Clip));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn horizontal_ellipsis_is_not_written_because_only_vertical_overflow_has_it() {
|
||||
let mut p = Presentation::default();
|
||||
let mut slide = new_slide(&mut p, "Horizontal ellipsis");
|
||||
let mut text = shape(&mut p, "Text", 10.0, 10.0, 200.0, 80.0);
|
||||
let mut body = TextBody::from_text("policy");
|
||||
body.body.vert_overflow = Some(TextOverflow::Ellipsis);
|
||||
body.body.horz_overflow = Some(TextOverflow::Ellipsis);
|
||||
text.text = Some(body);
|
||||
slide.shapes = vec![text];
|
||||
p.slides.push(Arc::new(slide));
|
||||
|
||||
let once = round(&p);
|
||||
let slide = once.slides.last().expect("added slide");
|
||||
let text = by_name(slide, "Text").text.as_ref().expect("text body");
|
||||
assert_eq!(text.body.vert_overflow, Some(TextOverflow::Ellipsis));
|
||||
assert_eq!(text.body.horz_overflow, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shapes_fills_lines_effects_round_trip() {
|
||||
let p = rich_deck();
|
||||
|
||||
Reference in new issue
Block a user