Run level shading (#727)
* Initial Run-level Shading support: add Shading to RunChild * Initial Run-level Shading support: add Shading to RunPropertymain
parent
2c8638dcb0
commit
e04dc4a757
|
@ -40,6 +40,7 @@ pub enum RunChild {
|
||||||
// For reader
|
// For reader
|
||||||
InstrTextString(String),
|
InstrTextString(String),
|
||||||
FootnoteReference(FootnoteReference),
|
FootnoteReference(FootnoteReference),
|
||||||
|
Shading(Shading),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for RunChild {
|
impl Serialize for RunChild {
|
||||||
|
@ -131,6 +132,12 @@ impl Serialize for RunChild {
|
||||||
t.serialize_field("data", f)?;
|
t.serialize_field("data", f)?;
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
|
RunChild::Shading(ref f) => {
|
||||||
|
let mut t = serializer.serialize_struct("Shading", 2)?;
|
||||||
|
t.serialize_field("type", "shading")?;
|
||||||
|
t.serialize_field("data", f)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,6 +304,11 @@ impl Run {
|
||||||
.push(RunChild::FootnoteReference(footnote.into()));
|
.push(RunChild::FootnoteReference(footnote.into()));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shading(mut self, shading: Shading) -> Run {
|
||||||
|
self.run_property = self.run_property.shading(shading);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for Run {
|
impl BuildXML for Run {
|
||||||
|
@ -321,6 +333,7 @@ impl BuildXML for Run {
|
||||||
RunChild::DeleteInstrText(c) => b = b.add_child(c),
|
RunChild::DeleteInstrText(c) => b = b.add_child(c),
|
||||||
RunChild::InstrTextString(_) => unreachable!(),
|
RunChild::InstrTextString(_) => unreachable!(),
|
||||||
RunChild::FootnoteReference(c) => b = b.add_child(c),
|
RunChild::FootnoteReference(c) => b = b.add_child(c),
|
||||||
|
RunChild::Shading(s) => b = b.add_child(s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.close().build()
|
b.close().build()
|
||||||
|
@ -400,4 +413,13 @@ mod tests {
|
||||||
r#"{"type":"footnoteReference","data":{"id":1}}"#
|
r#"{"type":"footnoteReference","data":{"id":1}}"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_run_shading() {
|
||||||
|
let c = RunChild::Shading(Shading::new());
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::to_string(&c).unwrap(),
|
||||||
|
r#"{"type":"shading","data":{"shdType":"clear","color":"auto","fill":"FFFFFF"}}"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ pub struct RunProperty {
|
||||||
pub ins: Option<Insert>,
|
pub ins: Option<Insert>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub strike: Option<Strike>,
|
pub strike: Option<Strike>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub shading: Option<Shading>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunProperty {
|
impl RunProperty {
|
||||||
|
@ -154,6 +156,11 @@ impl RunProperty {
|
||||||
self.ins = Some(i);
|
self.ins = Some(i);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shading(mut self, s: Shading) -> Self {
|
||||||
|
self.shading = Some(s);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildXML for RunProperty {
|
impl BuildXML for RunProperty {
|
||||||
|
@ -180,6 +187,7 @@ impl BuildXML for RunProperty {
|
||||||
.add_optional_child(&self.vert_align)
|
.add_optional_child(&self.vert_align)
|
||||||
.add_optional_child(&self.character_spacing)
|
.add_optional_child(&self.character_spacing)
|
||||||
.add_optional_child(&self.style)
|
.add_optional_child(&self.style)
|
||||||
|
.add_optional_child(&self.shading)
|
||||||
.close()
|
.close()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -271,4 +279,19 @@ mod tests {
|
||||||
r#"<w:rPr><w:spacing w:val="20" /></w:rPr>"#
|
r#"<w:rPr><w:spacing w:val="20" /></w:rPr>"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_character_shading() {
|
||||||
|
let c = RunProperty::new().shading(
|
||||||
|
Shading::new()
|
||||||
|
.shd_type(ShdType::Clear)
|
||||||
|
.fill("FFFFFF")
|
||||||
|
.color("auto"),
|
||||||
|
);
|
||||||
|
let b = c.build();
|
||||||
|
assert_eq!(
|
||||||
|
str::from_utf8(&b).unwrap(),
|
||||||
|
r#"<w:rPr><w:shd w:val="clear" w:color="auto" w:fill="FFFFFF" /></w:rPr>"#
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue