diff --git a/docx-core/src/documents/elements/caps.rs b/docx-core/src/documents/elements/caps.rs new file mode 100644 index 0000000..8da7ba2 --- /dev/null +++ b/docx-core/src/documents/elements/caps.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize, Serializer}; + +// use crate::documents::BuildXML; +// use crate::xml_builder::*; + +#[derive(Debug, Clone, Deserialize, PartialEq)] +pub struct Caps { + val: bool, +} + +impl Caps { + pub fn new() -> Caps { + Default::default() + } + + pub fn disable(mut self) -> Caps { + self.val = false; + self + } +} + +impl Default for Caps { + fn default() -> Self { + Self { val: true } + } +} + +impl Serialize for Caps { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_bool(self.val) + } +} diff --git a/docx-core/src/documents/elements/mod.rs b/docx-core/src/documents/elements/mod.rs index 5f89397..40e5ffd 100644 --- a/docx-core/src/documents/elements/mod.rs +++ b/docx-core/src/documents/elements/mod.rs @@ -7,6 +7,7 @@ mod bold_cs; mod bookmark_end; mod bookmark_start; mod br; +mod caps; mod character_spacing; mod color; mod comment; @@ -127,6 +128,7 @@ pub use bold_cs::*; pub use bookmark_end::*; pub use bookmark_start::*; pub use br::*; +pub use caps::*; pub use character_spacing::*; pub use color::*; pub use comment::*; diff --git a/docx-core/src/documents/elements/run_property.rs b/docx-core/src/documents/elements/run_property.rs index a10e4e0..7503787 100644 --- a/docx-core/src/documents/elements/run_property.rs +++ b/docx-core/src/documents/elements/run_property.rs @@ -27,6 +27,8 @@ pub struct RunProperty { #[serde(skip_serializing_if = "Option::is_none")] pub bold_cs: Option, #[serde(skip_serializing_if = "Option::is_none")] + pub caps: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub italic: Option, #[serde(skip_serializing_if = "Option::is_none")] pub italic_cs: Option, @@ -96,6 +98,11 @@ impl RunProperty { self } + pub fn caps(mut self) -> RunProperty { + self.caps = Some(Caps::new()); + self + } + pub fn italic(mut self) -> RunProperty { self.italic = Some(Italic::new()); self.italic_cs = Some(ItalicCs::new()); diff --git a/docx-core/src/reader/run_property.rs b/docx-core/src/reader/run_property.rs index 5d8bda3..4a30017 100644 --- a/docx-core/src/reader/run_property.rs +++ b/docx-core/src/reader/run_property.rs @@ -72,6 +72,12 @@ impl ElementReader for RunProperty { } rp = rp.bold(); } + XMLElement::Caps => { + if !read_bool(&attributes) { + continue; + } + rp = rp.caps(); + } XMLElement::Highlight => rp = rp.highlight(attributes[0].value.clone()), XMLElement::Strike => { if !read_bool(&attributes) { diff --git a/docx-core/src/reader/xml_element.rs b/docx-core/src/reader/xml_element.rs index 0b8e2d5..05e277f 100644 --- a/docx-core/src/reader/xml_element.rs +++ b/docx-core/src/reader/xml_element.rs @@ -31,6 +31,7 @@ pub enum XMLElement { Highlight, VertAlign, Bold, + Caps, RunStyle, BoldCs, Break, @@ -259,6 +260,7 @@ impl FromStr for XMLElement { "rStyle" => Ok(XMLElement::RunStyle), "b" => Ok(XMLElement::Bold), "bCs" => Ok(XMLElement::BoldCs), + "caps" => Ok(XMLElement::Caps), "i" => Ok(XMLElement::Italic), "iCs" => Ok(XMLElement::ItalicCs), "vanish" => Ok(XMLElement::Vanish), @@ -498,6 +500,6 @@ impl FromStr for PicXMLElement { pub trait ElementReader { fn read(r: &mut EventReader, attrs: &[OwnedAttribute]) -> Result - where - Self: std::marker::Sized; + where + Self: std::marker::Sized; } diff --git a/docx-wasm/js/json/run.ts b/docx-wasm/js/json/run.ts index 726ccc3..f0566bd 100644 --- a/docx-wasm/js/json/run.ts +++ b/docx-wasm/js/json/run.ts @@ -42,6 +42,7 @@ export type RunPropertyJSON = { underline?: string | null; bold?: boolean | null; boldCs?: boolean | null; + caps?: boolean | null; italic?: boolean | null; italicCs?: boolean | null; vanish?: boolean | null; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 13356d8..97c18ed 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.278-rc16", + "version": "0.0.278-rc17", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index 2c3942c..94e4296 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -85769,6 +85769,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, }, "styleId": "FBOLDALLCAPITAL", "styleType": "character", @@ -121802,6 +121803,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, }, "styleId": "Caution", "styleType": "paragraph", @@ -122196,6 +122198,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, "sz": 32, "szCs": 32, }, @@ -122935,6 +122938,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, "characterSpacing": 5, "sz": 28, "szCs": 28, @@ -139316,6 +139320,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, "characterSpacing": 0, "color": "auto", "fonts": Object { @@ -140203,6 +140208,7 @@ Object { "runProperty": Object { "bold": false, "boldCs": false, + "caps": true, "italic": false, "italicCs": false, "underline": "single", @@ -142223,6 +142229,7 @@ Object { "runProperty": Object { "bold": false, "boldCs": false, + "caps": true, "italic": false, "italicCs": false, "underline": "single", @@ -142527,6 +142534,7 @@ Object { "runProperty": Object { "bold": false, "boldCs": false, + "caps": true, "italic": false, "italicCs": false, "underline": "single", @@ -142831,6 +142839,7 @@ Object { "runProperty": Object { "bold": false, "boldCs": false, + "caps": true, "italic": false, "italicCs": false, "underline": "single", @@ -147212,6 +147221,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, "characterSpacing": 0, "color": "auto", "fonts": Object { @@ -147851,6 +147861,7 @@ Object { "runProperty": Object { "bold": true, "boldCs": true, + "caps": true, "color": "000000", "fonts": Object { "ascii": "Times New Roman Bold",