2019-11-11 08:36:26 +02:00
|
|
|
use super::{Justification, ParagraphStyle, RunProperty, Sz, SzCs};
|
2019-11-06 12:17:49 +02:00
|
|
|
use crate::documents::BuildXML;
|
2019-11-11 06:05:07 +02:00
|
|
|
use crate::types::AlignmentType;
|
2019-11-06 12:17:49 +02:00
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2019-11-07 11:45:03 +02:00
|
|
|
#[derive(Debug)]
|
2019-11-11 06:05:07 +02:00
|
|
|
pub struct ParagraphProperty {
|
|
|
|
alignment: Option<Justification>,
|
2019-11-11 07:39:22 +02:00
|
|
|
run_property: RunProperty,
|
2019-11-11 08:36:26 +02:00
|
|
|
style: ParagraphStyle,
|
2019-11-11 06:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ParagraphProperty {
|
|
|
|
fn default() -> Self {
|
2019-11-11 08:36:26 +02:00
|
|
|
let s: Option<&str> = None;
|
2019-11-11 07:39:22 +02:00
|
|
|
ParagraphProperty {
|
|
|
|
alignment: None,
|
|
|
|
run_property: RunProperty::new(),
|
2019-11-11 08:36:26 +02:00
|
|
|
style: ParagraphStyle::new(s),
|
2019-11-11 07:39:22 +02:00
|
|
|
}
|
2019-11-11 06:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 12:17:49 +02:00
|
|
|
|
|
|
|
// 17.3.1.26
|
|
|
|
// pPr (Paragraph Properties)
|
|
|
|
// This element specifies a set of paragraph properties which shall be applied to the contents of the parent
|
|
|
|
// paragraph after all style/numbering/table properties have been applied to the text. These properties are defined
|
|
|
|
// as direct formatting, since they are directly applied to the paragraph and supersede any formatting from styles.
|
|
|
|
impl ParagraphProperty {
|
|
|
|
pub fn new() -> ParagraphProperty {
|
2019-11-11 06:05:07 +02:00
|
|
|
Default::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn align(mut self, alignment_type: AlignmentType) -> ParagraphProperty {
|
|
|
|
self.alignment = Some(Justification::new(alignment_type.to_string()));
|
|
|
|
self
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
2019-11-11 08:36:26 +02:00
|
|
|
|
|
|
|
pub fn style(mut self, style_id: &str) -> ParagraphProperty {
|
|
|
|
self.style = ParagraphStyle::new(Some(style_id));
|
|
|
|
self
|
|
|
|
}
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for ParagraphProperty {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
2019-11-11 08:36:26 +02:00
|
|
|
XMLBuilder::new()
|
2019-11-11 06:05:07 +02:00
|
|
|
.open_paragraph_property()
|
2019-11-11 08:36:26 +02:00
|
|
|
.add_optional_child(&self.alignment)
|
|
|
|
.close()
|
|
|
|
.build()
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
2019-11-07 06:57:58 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
2019-11-06 12:17:49 +02:00
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
2019-11-11 08:36:26 +02:00
|
|
|
fn test_default() {
|
2019-11-06 12:17:49 +02:00
|
|
|
let c = ParagraphProperty::new();
|
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:pPr />"#);
|
|
|
|
}
|
2019-11-11 08:36:26 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_alignment() {
|
|
|
|
let c = ParagraphProperty::new();
|
|
|
|
let b = c.align(AlignmentType::Right).build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
|
|
|
r#"<w:pPr><w:jc w:val="right" /></w:pPr>"#
|
|
|
|
);
|
|
|
|
}
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|