fix: caps (#643)

* fix: caps

* fix: snaps

* published
main
bokuweb 2023-07-25 11:31:02 +09:00 committed by GitHub
parent b6d01b1930
commit 8aec069b83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 3 deletions

View File

@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_bool(self.val)
}
}

View File

@ -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::*;

View File

@ -27,6 +27,8 @@ pub struct RunProperty {
#[serde(skip_serializing_if = "Option::is_none")]
pub bold_cs: Option<BoldCs>,
#[serde(skip_serializing_if = "Option::is_none")]
pub caps: Option<Caps>,
#[serde(skip_serializing_if = "Option::is_none")]
pub italic: Option<Italic>,
#[serde(skip_serializing_if = "Option::is_none")]
pub italic_cs: Option<ItalicCs>,
@ -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());

View File

@ -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) {

View File

@ -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: Read>(r: &mut EventReader<R>, attrs: &[OwnedAttribute]) -> Result<Self, ReaderError>
where
Self: std::marker::Sized;
where
Self: std::marker::Sized;
}

View File

@ -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;

View File

@ -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 <bokuweb12@gmail.com>",

View File

@ -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",