2019-11-07 06:57:58 +02:00
|
|
|
use super::{Color, Sz};
|
2019-11-06 12:17:49 +02:00
|
|
|
use crate::documents::BuildXML;
|
|
|
|
use crate::xml_builder::*;
|
|
|
|
|
2019-11-07 11:45:03 +02:00
|
|
|
#[derive(Debug)]
|
2019-11-06 12:17:49 +02:00
|
|
|
pub struct RunProperty {
|
|
|
|
sz: Option<Sz>,
|
2019-11-07 06:57:58 +02:00
|
|
|
color: Option<Color>,
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl RunProperty {
|
|
|
|
pub fn new() -> RunProperty {
|
2019-11-07 06:57:58 +02:00
|
|
|
Default::default()
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-07 06:57:58 +02:00
|
|
|
pub fn add_sz(mut self, sz: usize) -> RunProperty {
|
|
|
|
self.sz = Some(Sz::new(sz));
|
2019-11-06 12:17:49 +02:00
|
|
|
self
|
|
|
|
}
|
2019-11-07 06:57:58 +02:00
|
|
|
|
|
|
|
pub fn add_color(mut self, color: &str) -> RunProperty {
|
|
|
|
self.color = Some(Color::new(color));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RunProperty {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
sz: None,
|
|
|
|
color: None,
|
|
|
|
}
|
|
|
|
}
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BuildXML for RunProperty {
|
|
|
|
fn build(&self) -> Vec<u8> {
|
|
|
|
let b = XMLBuilder::new();
|
2019-11-07 06:57:58 +02:00
|
|
|
b.open_run_property()
|
|
|
|
.add_optional_child(&self.sz)
|
|
|
|
.add_optional_child(&self.color)
|
|
|
|
.close()
|
|
|
|
.build()
|
2019-11-06 12:17:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use std::str;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_build() {
|
2019-11-07 06:57:58 +02:00
|
|
|
let c = RunProperty::new().add_sz(10).add_color("FFFFFF");
|
2019-11-06 12:17:49 +02:00
|
|
|
let b = c.build();
|
|
|
|
assert_eq!(
|
|
|
|
str::from_utf8(&b).unwrap(),
|
2019-11-07 06:57:58 +02:00
|
|
|
r#"<w:rPr><w:sz w:val="10" /><w:color w:val="FFFFFF" /></w:rPr>"#
|
2019-11-06 12:17:49 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|