diff --git a/docx-core/src/documents/elements/mod.rs b/docx-core/src/documents/elements/mod.rs index 071ffa8..0462cf5 100644 --- a/docx-core/src/documents/elements/mod.rs +++ b/docx-core/src/documents/elements/mod.rs @@ -9,6 +9,7 @@ mod bookmark_start; mod br; mod character_spacing; mod color; +mod run_style; mod comment; mod comment_extended; mod comment_range_end; @@ -136,6 +137,7 @@ pub use doc_var::*; pub use drawing::*; pub use fld_char::*; pub use font::*; +pub use run_style::*; pub use font_scheme::*; pub use footer_reference::*; pub use grid_span::*; diff --git a/docx-core/src/documents/elements/run.rs b/docx-core/src/documents/elements/run.rs index 1c91ac8..6af7b1d 100644 --- a/docx-core/src/documents/elements/run.rs +++ b/docx-core/src/documents/elements/run.rs @@ -165,6 +165,11 @@ impl Run { self } + pub fn style(mut self, style_id: &str) -> Self { + self.run_property = self.run_property.style(style_id); + self + } + pub fn size(mut self, size: usize) -> Run { self.run_property = self.run_property.size(size); self diff --git a/docx-core/src/documents/elements/run_property.rs b/docx-core/src/documents/elements/run_property.rs index b9a9ab5..2b75902 100644 --- a/docx-core/src/documents/elements/run_property.rs +++ b/docx-core/src/documents/elements/run_property.rs @@ -5,9 +5,11 @@ use crate::documents::BuildXML; use crate::types::*; use crate::xml_builder::*; -#[derive(Debug, Clone, Serialize, PartialEq)] +#[derive(Debug, Clone, Serialize, PartialEq, Default)] #[serde(rename_all = "camelCase")] pub struct RunProperty { + #[serde(skip_serializing_if = "Option::is_none")] + pub style: Option, #[serde(skip_serializing_if = "Option::is_none")] pub sz: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -49,6 +51,11 @@ impl RunProperty { Default::default() } + pub fn style(mut self, style_id: &str) -> Self { + self.style = Some(RunStyle::new(style_id)); + self + } + pub fn size(mut self, size: usize) -> RunProperty { self.sz = Some(Sz::new(size)); self.sz_cs = Some(SzCs::new(size)); @@ -135,30 +142,6 @@ impl RunProperty { } } -impl Default for RunProperty { - fn default() -> Self { - Self { - color: None, - sz: None, - sz_cs: None, - highlight: None, - vert_align: None, - underline: None, - bold: None, - bold_cs: None, - italic: None, - italic_cs: None, - vanish: None, - fonts: None, - character_spacing: None, - text_border: None, - del: None, - ins: None, - strike: None, - } - } -} - impl BuildXML for RunProperty { fn build(&self) -> Vec { let b = XMLBuilder::new(); diff --git a/docx-core/src/documents/elements/run_style.rs b/docx-core/src/documents/elements/run_style.rs new file mode 100644 index 0000000..0f69c05 --- /dev/null +++ b/docx-core/src/documents/elements/run_style.rs @@ -0,0 +1,57 @@ +use serde::{Serialize, Serializer}; + +use crate::documents::BuildXML; +use crate::xml_builder::*; + +#[derive(Debug, Clone, PartialEq)] +pub struct RunStyle { + pub val: String, +} + +impl Default for RunStyle { + fn default() -> Self { + RunStyle { + val: "Normal".to_owned(), + } + } +} + +impl RunStyle { + pub fn new(val: impl Into) -> RunStyle { + RunStyle { val: val.into() } + } +} + +impl BuildXML for RunStyle { + fn build(&self) -> Vec { + XMLBuilder::new().run_style(&self.val).build() + } +} + +impl Serialize for RunStyle { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.val) + } +} + +#[cfg(test)] +mod tests { + + use super::*; + #[cfg(test)] + use pretty_assertions::assert_eq; + use std::str; + + #[test] + fn test_r_style() { + let c = RunStyle::new("Heading"); + let b = c.build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#""# + ); + } +} diff --git a/docx-core/src/reader/run_property.rs b/docx-core/src/reader/run_property.rs index 1f6eb64..df8af7b 100644 --- a/docx-core/src/reader/run_property.rs +++ b/docx-core/src/reader/run_property.rs @@ -60,6 +60,11 @@ impl ElementReader for RunProperty { }) => { let e = XMLElement::from_str(&name.local_name).unwrap(); match e { + XMLElement::RunStyle => { + if let Some(v) = read_val(&attributes) { + rp = rp.style(&v); + } + } XMLElement::Bold => { if !read_bool(&attributes) { rp = rp.disable_bold(); diff --git a/docx-core/src/reader/xml_element.rs b/docx-core/src/reader/xml_element.rs index c7292dd..8b436a1 100644 --- a/docx-core/src/reader/xml_element.rs +++ b/docx-core/src/reader/xml_element.rs @@ -29,6 +29,7 @@ pub enum XMLElement { Highlight, VertAlign, Bold, + RunStyle, BoldCs, Break, Tab, @@ -235,6 +236,7 @@ impl FromStr for XMLElement { "pStyle" => Ok(XMLElement::ParagraphStyle), "pPrChange" => Ok(XMLElement::ParagraphPropertyChange), "highlight" => Ok(XMLElement::Highlight), + "rStyle" => Ok(XMLElement::RunStyle), "b" => Ok(XMLElement::Bold), "bCs" => Ok(XMLElement::BoldCs), "i" => Ok(XMLElement::Italic), diff --git a/docx-core/src/xml_builder/elements.rs b/docx-core/src/xml_builder/elements.rs index c9e7d58..cfa87ec 100644 --- a/docx-core/src/xml_builder/elements.rs +++ b/docx-core/src/xml_builder/elements.rs @@ -149,6 +149,8 @@ impl XMLBuilder { closed_with_str!(vert_align, "w:vertAlign"); // i.e. closed_with_str!(paragraph_style, "w:pStyle"); + // i.e. + closed_with_str!(run_style, "w:rStyle"); // i.e. closed_with_usize!(sz, "w:sz"); // i.e. diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index b2af19c..edbe463 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -5956,6 +5956,1411 @@ Object { } `; +exports[`reader should read font docx 1`] = ` +Object { + "comments": Object { + "comments": Array [], + }, + "commentsExtended": Object { + "children": Array [], + }, + "contentType": Object { + "custom_xml_count": 1, + "footer_count": 0, + "header_count": 0, + "types": Object { + "/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml", + "/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml", + "/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml", + "/docProps/custom.xml": "application/vnd.openxmlformats-officedocument.custom-properties+xml", + "/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml", + "/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml", + "/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml", + "/word/document.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", + "/word/fontTable.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml", + "/word/numbering.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", + "/word/settings.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", + "/word/styles.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", + }, + "web_extension_count": 1, + }, + "customItemProps": Array [], + "customItemRels": Array [], + "customItems": Array [], + "docProps": Object { + "app": Object {}, + "core": Object { + "config": Object { + "created": null, + "creator": null, + "description": null, + "language": null, + "lastModifiedBy": null, + "modified": null, + "revision": null, + "subject": null, + "title": null, + }, + }, + "custom": Object { + "properties": Object {}, + }, + }, + "document": Object { + "children": Array [ + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "preserveSpace": true, + "text": "こんにちは", + }, + "type": "text", + }, + ], + "runProperty": Object { + "fonts": Object { + "ascii": "筑紫B丸ゴシック レギュラー", + "eastAsia": "筑紫B丸ゴシック レギュラー", + "hiAnsi": "筑紫B丸ゴシック レギュラー", + "hint": "eastAsia", + }, + }, + }, + "type": "run", + }, + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "preserveSpace": true, + "text": " ", + }, + "type": "text", + }, + ], + "runProperty": Object { + "fonts": Object { + "hint": "eastAsia", + }, + }, + }, + "type": "run", + }, + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "preserveSpace": true, + "text": "世界", + }, + "type": "text", + }, + ], + "runProperty": Object { + "fonts": Object { + "ascii": "ヒラギノ丸ゴ ProN W4", + "eastAsia": "ヒラギノ丸ゴ ProN W4", + "hiAnsi": "ヒラギノ丸ゴ ProN W4", + "hint": "eastAsia", + }, + }, + }, + "type": "run", + }, + ], + "hasNumbering": false, + "id": "18937B0B", + "property": Object { + "runProperty": Object { + "fonts": Object { + "ascii": "ヒラギノ丸ゴ ProN W4", + "eastAsia": "ヒラギノ丸ゴ ProN W4", + "hiAnsi": "ヒラギノ丸ゴ ProN W4", + }, + }, + "tabs": Array [], + }, + }, + "type": "paragraph", + }, + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "4866A1EA", + "property": Object { + "runProperty": Object { + "fonts": Object { + "ascii": "ヒラギノ丸ゴ ProN W4", + "eastAsia": "ヒラギノ丸ゴ ProN W4", + "hiAnsi": "ヒラギノ丸ゴ ProN W4", + }, + }, + "tabs": Array [], + }, + }, + "type": "paragraph", + }, + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "children": Array [ + Object { + "data": Object { + "preserveSpace": true, + "text": "こんにちは世界", + }, + "type": "text", + }, + ], + "runProperty": Object { + "fonts": Object { + "hint": "eastAsia", + }, + "style": "test", + }, + }, + "type": "run", + }, + ], + "hasNumbering": false, + "id": "558ED852", + "property": Object { + "runProperty": Object { + "style": "test", + }, + "style": "a4", + "tabs": Array [], + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "sectionProperty": Object { + "columns": 425, + "docGrid": Object { + "charSpace": null, + "gridType": "lines", + "linePitch": 360, + }, + "pageMargin": Object { + "bottom": 1701, + "footer": 992, + "gutter": 0, + "header": 851, + "left": 1701, + "right": 1701, + "top": 1985, + }, + "pageSize": Object { + "h": 16840, + "orient": null, + "w": 11900, + }, + "titlePg": false, + }, + }, + "documentRels": Object { + "customXmlCount": 0, + "footerCount": 0, + "hasComments": false, + "hasNumberings": false, + "headerCount": 0, + "imageIds": Array [], + }, + "fontTable": Object {}, + "media": Array [], + "numberings": Object { + "abstractNums": Array [], + "numberings": Array [], + }, + "rels": Object { + "rels": Array [ + Array [ + "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", + "rId1", + "docProps/core.xml", + ], + Array [ + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", + "rId2", + "docProps/app.xml", + ], + Array [ + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", + "rId3", + "word/document.xml", + ], + Array [ + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", + "rId4", + "docProps/custom.xml", + ], + ], + }, + "settings": Object { + "defaultTabStop": 840, + "docId": "4A9883C0-7AEC-574E-926D-DA6DB000DD90", + "docVars": Array [], + "evenAndOddHeaders": false, + "zoom": 100, + }, + "styles": Object { + "docDefaults": Object { + "runPropertyDefault": Object { + "runProperty": Object { + "fonts": Object { + "asciiTheme": "minorHAnsi", + "csTheme": "minorBidi", + "eastAsiaTheme": "minorEastAsia", + "hiAnsiTheme": "minorHAnsi", + }, + "sz": 21, + "szCs": 21, + }, + }, + }, + "styles": Array [ + Object { + "basedOn": null, + "name": "Normal", + "paragraphProperty": Object { + "alignment": "both", + "runProperty": Object {}, + "tabs": Array [], + "widowControl": true, + }, + "runProperty": Object {}, + "styleId": "a", + "styleType": "paragraph", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "Default Paragraph Font", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object {}, + "styleId": "a0", + "styleType": "character", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "Normal Table", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object {}, + "styleId": "a1", + "styleType": "table", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "top": null, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "No List", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object {}, + "styleId": "a2", + "styleType": "numbering", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": "a0", + "name": "Subtle Emphasis", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object { + "color": "404040", + "italic": true, + "italicCs": true, + }, + "styleId": "a3", + "styleType": "character", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": "a", + "name": "Subtitle", + "paragraphProperty": Object { + "alignment": "center", + "outlineLvl": 1, + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object { + "sz": 24, + "szCs": 24, + }, + "styleId": "a4", + "styleType": "paragraph", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": "a0", + "name": "副題 (文字)", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object { + "sz": 24, + "szCs": 24, + }, + "styleId": "a5", + "styleType": "character", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": "a3", + "name": "test", + "paragraphProperty": Object { + "runProperty": Object {}, + "tabs": Array [], + }, + "runProperty": Object { + "color": "404040", + "fonts": Object { + "eastAsia": "MS Pゴシック", + }, + "italic": true, + "italicCs": true, + }, + "styleId": "test", + "styleType": "character", + "tableCellProperty": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": null, + }, + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "layout": null, + "margins": Object { + "bottom": Object { + "val": 0, + "widthType": "DXA", + }, + "left": Object { + "val": 55, + "widthType": "DXA", + }, + "right": Object { + "val": 55, + "widthType": "DXA", + }, + "top": Object { + "val": 0, + "widthType": "DXA", + }, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + ], + }, + "taskpanes": null, + "taskpanesRels": Object { + "rels": Array [], + }, + "themes": Array [ + Object { + "fontSchema": Object { + "majorFont": Object { + "cs": "", + "ea": "", + "fonts": Array [ + Object { + "script": "Jpan", + "typeface": "游ゴシック Light", + }, + Object { + "script": "Hang", + "typeface": "맑은 고딕", + }, + Object { + "script": "Hans", + "typeface": "等线 Light", + }, + Object { + "script": "Hant", + "typeface": "新細明體", + }, + Object { + "script": "Arab", + "typeface": "Times New Roman", + }, + Object { + "script": "Hebr", + "typeface": "Times New Roman", + }, + Object { + "script": "Thai", + "typeface": "Angsana New", + }, + Object { + "script": "Ethi", + "typeface": "Nyala", + }, + Object { + "script": "Beng", + "typeface": "Vrinda", + }, + Object { + "script": "Gujr", + "typeface": "Shruti", + }, + Object { + "script": "Khmr", + "typeface": "MoolBoran", + }, + Object { + "script": "Knda", + "typeface": "Tunga", + }, + Object { + "script": "Guru", + "typeface": "Raavi", + }, + Object { + "script": "Cans", + "typeface": "Euphemia", + }, + Object { + "script": "Cher", + "typeface": "Plantagenet Cherokee", + }, + Object { + "script": "Yiii", + "typeface": "Microsoft Yi Baiti", + }, + Object { + "script": "Tibt", + "typeface": "Microsoft Himalaya", + }, + Object { + "script": "Thaa", + "typeface": "MV Boli", + }, + Object { + "script": "Deva", + "typeface": "Mangal", + }, + Object { + "script": "Telu", + "typeface": "Gautami", + }, + Object { + "script": "Taml", + "typeface": "Latha", + }, + Object { + "script": "Syrc", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Orya", + "typeface": "Kalinga", + }, + Object { + "script": "Mlym", + "typeface": "Kartika", + }, + Object { + "script": "Laoo", + "typeface": "DokChampa", + }, + Object { + "script": "Sinh", + "typeface": "Iskoola Pota", + }, + Object { + "script": "Mong", + "typeface": "Mongolian Baiti", + }, + Object { + "script": "Viet", + "typeface": "Times New Roman", + }, + Object { + "script": "Uigh", + "typeface": "Microsoft Uighur", + }, + Object { + "script": "Geor", + "typeface": "Sylfaen", + }, + Object { + "script": "Armn", + "typeface": "Arial", + }, + Object { + "script": "Bugi", + "typeface": "Leelawadee UI", + }, + Object { + "script": "Bopo", + "typeface": "Microsoft JhengHei", + }, + Object { + "script": "Java", + "typeface": "Javanese Text", + }, + Object { + "script": "Lisu", + "typeface": "Segoe UI", + }, + Object { + "script": "Mymr", + "typeface": "Myanmar Text", + }, + Object { + "script": "Nkoo", + "typeface": "Ebrima", + }, + Object { + "script": "Olck", + "typeface": "Nirmala UI", + }, + Object { + "script": "Osma", + "typeface": "Ebrima", + }, + Object { + "script": "Phag", + "typeface": "Phagspa", + }, + Object { + "script": "Syrn", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Syrj", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Syre", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Sora", + "typeface": "Nirmala UI", + }, + Object { + "script": "Tale", + "typeface": "Microsoft Tai Le", + }, + Object { + "script": "Talu", + "typeface": "Microsoft New Tai Lue", + }, + Object { + "script": "Tfng", + "typeface": "Ebrima", + }, + ], + "latin": "游ゴシック Light", + }, + "minorFont": Object { + "cs": "", + "ea": "", + "fonts": Array [ + Object { + "script": "Jpan", + "typeface": "游明朝", + }, + Object { + "script": "Hang", + "typeface": "맑은 고딕", + }, + Object { + "script": "Hans", + "typeface": "等线", + }, + Object { + "script": "Hant", + "typeface": "新細明體", + }, + Object { + "script": "Arab", + "typeface": "Arial", + }, + Object { + "script": "Hebr", + "typeface": "Arial", + }, + Object { + "script": "Thai", + "typeface": "Cordia New", + }, + Object { + "script": "Ethi", + "typeface": "Nyala", + }, + Object { + "script": "Beng", + "typeface": "Vrinda", + }, + Object { + "script": "Gujr", + "typeface": "Shruti", + }, + Object { + "script": "Khmr", + "typeface": "DaunPenh", + }, + Object { + "script": "Knda", + "typeface": "Tunga", + }, + Object { + "script": "Guru", + "typeface": "Raavi", + }, + Object { + "script": "Cans", + "typeface": "Euphemia", + }, + Object { + "script": "Cher", + "typeface": "Plantagenet Cherokee", + }, + Object { + "script": "Yiii", + "typeface": "Microsoft Yi Baiti", + }, + Object { + "script": "Tibt", + "typeface": "Microsoft Himalaya", + }, + Object { + "script": "Thaa", + "typeface": "MV Boli", + }, + Object { + "script": "Deva", + "typeface": "Mangal", + }, + Object { + "script": "Telu", + "typeface": "Gautami", + }, + Object { + "script": "Taml", + "typeface": "Latha", + }, + Object { + "script": "Syrc", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Orya", + "typeface": "Kalinga", + }, + Object { + "script": "Mlym", + "typeface": "Kartika", + }, + Object { + "script": "Laoo", + "typeface": "DokChampa", + }, + Object { + "script": "Sinh", + "typeface": "Iskoola Pota", + }, + Object { + "script": "Mong", + "typeface": "Mongolian Baiti", + }, + Object { + "script": "Viet", + "typeface": "Arial", + }, + Object { + "script": "Uigh", + "typeface": "Microsoft Uighur", + }, + Object { + "script": "Geor", + "typeface": "Sylfaen", + }, + Object { + "script": "Armn", + "typeface": "Arial", + }, + Object { + "script": "Bugi", + "typeface": "Leelawadee UI", + }, + Object { + "script": "Bopo", + "typeface": "Microsoft JhengHei", + }, + Object { + "script": "Java", + "typeface": "Javanese Text", + }, + Object { + "script": "Lisu", + "typeface": "Segoe UI", + }, + Object { + "script": "Mymr", + "typeface": "Myanmar Text", + }, + Object { + "script": "Nkoo", + "typeface": "Ebrima", + }, + Object { + "script": "Olck", + "typeface": "Nirmala UI", + }, + Object { + "script": "Osma", + "typeface": "Ebrima", + }, + Object { + "script": "Phag", + "typeface": "Phagspa", + }, + Object { + "script": "Syrn", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Syrj", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Syre", + "typeface": "Estrangelo Edessa", + }, + Object { + "script": "Sora", + "typeface": "Nirmala UI", + }, + Object { + "script": "Tale", + "typeface": "Microsoft Tai Le", + }, + Object { + "script": "Talu", + "typeface": "Microsoft New Tai Lue", + }, + Object { + "script": "Tfng", + "typeface": "Ebrima", + }, + ], + "latin": "游明朝", + }, + }, + }, + ], + "webExtensions": Array [], + "webSettings": Object { + "divs": Array [], + }, +} +`; + exports[`reader should read footer docx 1`] = ` Object { "comments": Object { @@ -12558,7 +13963,9 @@ Object { Object { "data": Object { "children": Array [], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -13103,7 +14510,9 @@ Object { Object { "data": Object { "children": Array [], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -13339,7 +14748,9 @@ Object { Object { "data": Object { "children": Array [], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -23468,6 +24879,7 @@ Object { "ascii": "Arial", "hiAnsi": "Arial", }, + "style": "a9", "sz": 20, "szCs": 20, }, @@ -23491,6 +24903,7 @@ Object { "ascii": "Arial", "hiAnsi": "Arial", }, + "style": "a9", "sz": 20, "szCs": 20, }, @@ -23514,6 +24927,7 @@ Object { "ascii": "Arial", "hiAnsi": "Arial", }, + "style": "a9", "sz": 20, "szCs": 20, }, @@ -23537,6 +24951,7 @@ Object { "ascii": "Arial", "hiAnsi": "Arial", }, + "style": "a9", "sz": 20, "szCs": 20, }, @@ -23560,6 +24975,7 @@ Object { "ascii": "Arial", "hiAnsi": "Arial", }, + "style": "a9", "sz": 20, "szCs": 20, }, @@ -43653,7 +45069,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -43689,7 +45107,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -43825,7 +45245,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -43859,7 +45281,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -43993,7 +45417,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -44029,7 +45455,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -44165,7 +45593,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, @@ -44199,7 +45629,9 @@ Object { "type": "text", }, ], - "runProperty": Object {}, + "runProperty": Object { + "style": "a5", + }, }, "type": "run", }, diff --git a/docx-wasm/test/index.test.js b/docx-wasm/test/index.test.js index 94b3b91..1147d8d 100644 --- a/docx-wasm/test/index.test.js +++ b/docx-wasm/test/index.test.js @@ -118,6 +118,12 @@ describe("reader", () => { const json = w.readDocx(buffer); expect(json).toMatchSnapshot(); }); + + test("should read font docx", () => { + const buffer = readFileSync("../fixtures/font/font.docx"); + const json = w.readDocx(buffer); + expect(json).toMatchSnapshot(); + }); }); describe("writer", () => { diff --git a/fixtures/font/font.docx b/fixtures/font/font.docx new file mode 100644 index 0000000..a8d6ad2 Binary files /dev/null and b/fixtures/font/font.docx differ