Support ppr default (#673)

* fix: ppr change

* fix: spacing

* feat: support pPrDefatul
main
bokuweb 2024-01-17 22:40:47 +09:00 committed by GitHub
parent 3c87e086cf
commit 76b2622dc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
53 changed files with 697 additions and 61 deletions

View File

@ -1,7 +1,7 @@
use serde::Serialize;
use crate::xml_builder::*;
use crate::{documents::BuildXML, RunProperty};
use crate::{xml_builder::*, LineSpacing, ParagraphProperty, ParagraphPropertyDefault};
use super::run_property_default::*;
use super::RunFonts;
@ -10,6 +10,7 @@ use super::RunFonts;
#[serde(rename_all = "camelCase")]
pub struct DocDefaults {
run_property_default: RunPropertyDefault,
paragraph_property_default: ParagraphPropertyDefault,
}
impl DocDefaults {
@ -32,17 +33,29 @@ impl DocDefaults {
self
}
pub fn line_spacing(mut self, spacing: LineSpacing) -> Self {
self.paragraph_property_default = self.paragraph_property_default.line_spacing(spacing);
self
}
pub(crate) fn run_property(mut self, p: RunProperty) -> Self {
self.run_property_default = self.run_property_default.run_property(p);
self
}
pub(crate) fn paragraph_property(mut self, p: ParagraphProperty) -> Self {
self.paragraph_property_default = self.paragraph_property_default.paragraph_property(p);
self
}
}
impl Default for DocDefaults {
fn default() -> Self {
let run_property_default = RunPropertyDefault::new();
let paragraph_property_default = ParagraphPropertyDefault::new();
DocDefaults {
run_property_default,
paragraph_property_default,
}
}
}
@ -52,6 +65,7 @@ impl BuildXML for DocDefaults {
let b = XMLBuilder::new();
b.open_doc_defaults()
.add_child(&self.run_property_default)
.add_child(&self.paragraph_property_default)
.close()
.build()
}
@ -71,7 +85,7 @@ mod tests {
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault></w:docDefaults>"#
r#"<w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault><w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault></w:docDefaults>"#
);
}
}

View File

@ -66,6 +66,7 @@ mod paragraph;
mod paragraph_borders;
mod paragraph_property;
mod paragraph_property_change;
mod paragraph_property_default;
mod paragraph_style;
mod pic;
mod q_format;
@ -189,6 +190,7 @@ pub use paragraph::*;
pub use paragraph_borders::*;
pub use paragraph_property::*;
pub use paragraph_property_change::*;
pub use paragraph_property_default::*;
pub use paragraph_style::*;
pub use pic::*;
pub use q_format::*;

View File

@ -0,0 +1,63 @@
use serde::Serialize;
use super::*;
use crate::documents::BuildXML;
use crate::xml_builder::*;
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ParagraphPropertyDefault {
paragraph_property: ParagraphProperty,
}
impl ParagraphPropertyDefault {
pub fn new() -> Self {
Default::default()
}
pub fn line_spacing(mut self, spacing: LineSpacing) -> Self {
self.paragraph_property = self.paragraph_property.line_spacing(spacing);
self
}
pub(crate) fn paragraph_property(mut self, p: ParagraphProperty) -> Self {
self.paragraph_property = p;
self
}
}
impl Default for ParagraphPropertyDefault {
fn default() -> Self {
let paragraph_property = ParagraphProperty::new();
ParagraphPropertyDefault { paragraph_property }
}
}
impl BuildXML for ParagraphPropertyDefault {
fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new();
b.open_paragraph_property_default()
.add_child(&self.paragraph_property)
.close()
.build()
}
}
mod tests {
#[allow(unused_imports)]
use super::*;
#[cfg(test)]
use pretty_assertions::assert_eq;
#[test]
fn test_build() {
let c = ParagraphPropertyDefault::new();
let b = c.build();
assert_eq!(
std::str::from_utf8(&b).unwrap(),
r#"<w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault>"#
);
}
}

View File

@ -468,6 +468,11 @@ impl Docx {
self
}
pub fn default_line_spacing(mut self, spacing: LineSpacing) -> Self {
self.styles = self.styles.default_line_spacing(spacing);
self
}
pub fn taskpanes(mut self) -> Self {
self.taskpanes = Some(Taskpanes::new());
self.rels = self.rels.add_taskpanes_rel();

View File

@ -32,6 +32,11 @@ impl Styles {
self
}
pub fn default_line_spacing(mut self, spacing: LineSpacing) -> Self {
self.doc_defaults = self.doc_defaults.line_spacing(spacing);
self
}
pub fn default_fonts(mut self, font: RunFonts) -> Self {
self.doc_defaults = self.doc_defaults.fonts(font);
self
@ -99,18 +104,27 @@ mod tests {
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:styles xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault></w:docDefaults><w:style w:type="paragraph" w:styleId="Normal"><w:name w:val="Normal" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type="paragraph" w:styleId="Title"><w:name w:val="TitleName" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style></w:styles>"#
r#"<w:styles xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault><w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault></w:docDefaults><w:style w:type="paragraph" w:styleId="Normal"><w:name w:val="Normal" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type="paragraph" w:styleId="Title"><w:name w:val="TitleName" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style></w:styles>"#
);
}
#[test]
fn test_table_style(){
let c =
Styles::new().add_style(Style::new("Table", StyleType::Table).name("Table Style").table_property(TableProperty::new().set_margins(TableCellMargins::new().margin_left(108, WidthType::Dxa).margin_right(108,WidthType::Dxa))));
fn test_table_style() {
let c = Styles::new().add_style(
Style::new("Table", StyleType::Table)
.name("Table Style")
.table_property(
TableProperty::new().set_margins(
TableCellMargins::new()
.margin_left(108, WidthType::Dxa)
.margin_right(108, WidthType::Dxa),
),
),
);
let b = c.build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:styles xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault></w:docDefaults><w:style w:type="paragraph" w:styleId="Normal"><w:name w:val="Normal" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type="table" w:styleId="Table"><w:name w:val="Table Style" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:tcPr /><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
r#"<w:styles xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" mc:Ignorable="w14 w15"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault><w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault></w:docDefaults><w:style w:type="paragraph" w:styleId="Normal"><w:name w:val="Normal" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type="table" w:styleId="Table"><w:name w:val="Table Style" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:tcPr /><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:left w:w="108" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />

View File

@ -24,6 +24,11 @@ impl ElementReader for DocDefaults {
doc_defaults = doc_defaults.run_property(run_pr);
continue;
}
if let XMLElement::ParagraphProperty = e {
let paragraph_pr = ParagraphProperty::read(r, &attributes)?;
doc_defaults = doc_defaults.paragraph_property(paragraph_pr);
continue;
}
}
Ok(XmlEvent::EndElement { name, .. }) => {
let e = XMLElement::from_str(&name.local_name).unwrap();

View File

@ -127,6 +127,7 @@ impl XMLBuilder {
open!(open_run_property, "w:rPr");
open!(open_paragraph_borders, "w:pBdr");
open!(open_run_property_default, "w:rPrDefault");
open!(open_paragraph_property_default, "w:pPrDefault");
// i.e. <w:qFormat ... >
closed!(q_format, "w:qFormat");
// i.e. <w:p ... >

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,9 @@
import { LineSpacing, ParagraphProperty } from "./paragraph-property";
import { RunProperty, RunFonts } from "./run";
export class DocDefaults {
runProperty: RunProperty;
paragraphProperty: ParagraphProperty;
size(size: number) {
this.runProperty = { ...this.runProperty, size };
@ -17,4 +19,9 @@ export class DocDefaults {
this.runProperty = { ...this.runProperty, characterSpacing };
return this;
}
lineSpacing(lineSpacing: LineSpacing) {
this.paragraphProperty = { ...this.paragraphProperty, lineSpacing };
return this;
}
}

View File

@ -1,5 +1,5 @@
import { Paragraph } from "./paragraph";
import { ParagraphProperty } from "./paragraph-property";
import { LineSpacing, ParagraphProperty } from "./paragraph-property";
import { Table } from "./table";
import { TableOfContents } from "./table-of-contents";
import { RunFonts } from "./run";
@ -197,6 +197,11 @@ export class Docx {
return this;
}
defaultLineSpacing(spacing: LineSpacing) {
this.styles.defaultLineSpacing(spacing);
return this;
}
taskpanes() {
this._taskpanes = true;
return this;
@ -536,21 +541,34 @@ export class Docx {
}
if (this.styles?.docDefaults) {
if (this.styles.docDefaults.runProperty?.fonts) {
const fonts = this.buildRunFonts(
this.styles.docDefaults.runProperty.fonts
);
docx = docx.default_fonts(fonts);
if (this.styles.docDefaults.runProperty) {
if (this.styles.docDefaults.runProperty.fonts) {
const fonts = this.buildRunFonts(
this.styles.docDefaults.runProperty.fonts
);
docx = docx.default_fonts(fonts);
}
if (this.styles.docDefaults.runProperty.size) {
docx = docx.default_size(this.styles.docDefaults.runProperty.size);
}
if (this.styles.docDefaults.runProperty.characterSpacing) {
docx = docx.default_spacing(
this.styles.docDefaults.runProperty.characterSpacing
);
}
}
if (this.styles.docDefaults.runProperty?.size) {
docx = docx.default_size(this.styles.docDefaults.runProperty.size);
}
if (this.styles.docDefaults.runProperty?.characterSpacing) {
docx = docx.default_spacing(
this.styles.docDefaults.runProperty.characterSpacing
);
if (this.styles.docDefaults.paragraphProperty) {
if (this.styles.docDefaults.paragraphProperty.lineSpacing) {
const spacing = this.buildLineSpacing(
this.styles.docDefaults.paragraphProperty
);
if (spacing) {
docx = docx.default_line_spacing(spacing);
}
}
}
}

View File

@ -22,6 +22,9 @@ export type StylesJSON = {
runPropertyDefault: {
runProperty: RunPropertyJSON;
};
paragraphPropertyDefault: {
paragraphProperty: ParagraphPropertyJSON;
};
};
styles: StyleJSON[];
};

View File

@ -42,9 +42,7 @@ export class Style {
this._styleType = type;
this._name = "";
this._runProperty = {};
this._tableProperty = {
cellMargins: createDefaultTableCellMargins(),
};
this._tableProperty = { cellMargins: createDefaultTableCellMargins() };
this._runProperty = createDefaultRunProperty();
this._paragraphProperty = createDefaultParagraphProperty();
this._basedOn = null;
@ -291,6 +289,7 @@ export class Style {
buildWasmObject = () => {
const styleType = this.buildStyleType();
let s = wasm.createStyle(this._styleId, styleType);
if (this._name) {

View File

@ -1,6 +1,7 @@
import { Style } from "./style";
import { DocDefaults } from "./doc-defaults";
import { RunFonts } from "./run";
import { LineSpacing } from "./paragraph-property";
export class Styles {
styles: Style[] = [];
@ -20,4 +21,9 @@ export class Styles {
this.docDefaults.characterSpacing(spacing);
return this;
}
defaultLineSpacing(spacing: LineSpacing) {
this.docDefaults.lineSpacing(spacing);
return this;
}
}

View File

@ -14,6 +14,7 @@
"tsc:node": "tsc -p tsconfig.node.json --sourcemap",
"tsc": "run-s tsc:*",
"test": "npm run build && tsc && jest",
"jest": "tsc && jest",
"build": "run-s tsrs copy:bindings wasm-pack tsc",
"serve": "webpack-dev-server --open --config webpack.dev.js",
"copy": "cpy 'dist/node/pkg/package.json' 'dist/web/pkg'",

View File

@ -158,6 +158,11 @@ impl Docx {
self
}
pub fn default_line_spacing(mut self, spacing: LineSpacing) -> Self {
self.0.styles = self.0.styles.default_line_spacing(spacing.take());
self
}
pub fn taskpanes(mut self) -> Self {
self.0 = self.0.taskpanes();
self

View File

@ -590,6 +590,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -1454,6 +1460,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {},
},
@ -1545,6 +1557,269 @@ Object {
}
`;
exports[`reader should read default line spacing 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": "Hello ",
},
"type": "text",
},
],
"runProperty": Object {},
},
"type": "run",
},
],
"hasNumbering": false,
"id": "00000001",
"property": Object {
"lineSpacing": Object {
"after": 0,
"afterLines": 400,
"before": 100,
"line": 100,
},
"runProperty": Object {},
"tabs": Array [],
},
},
"type": "paragraph",
},
],
"hasNumbering": false,
"sectionProperty": Object {
"columns": 1,
"pageMargin": Object {
"bottom": 1701,
"footer": 992,
"gutter": 0,
"header": 851,
"left": 1701,
"right": 1701,
"top": 1985,
},
"pageSize": Object {
"h": 16838,
"orient": null,
"w": 11906,
},
"space": 425,
"textDirection": "lrTb",
"titlePg": false,
},
},
"documentRels": Object {
"customXmlCount": 0,
"footerCount": 0,
"hasComments": false,
"hasNumberings": false,
"headerCount": 0,
"hyperlinks": Array [],
"images": Array [],
},
"fontTable": Object {},
"hyperlinks": Array [],
"images": Array [],
"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 {
"adjustLineHeightInTable": false,
"defaultTabStop": 840,
"docId": null,
"docVars": Array [],
"evenAndOddHeaders": false,
"zoom": 100,
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"lineSpacing": Object {
"after": 0,
"afterLines": 400,
"before": 100,
"line": 100,
},
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {},
},
},
"styles": Array [
Object {
"basedOn": null,
"name": "Normal",
"next": null,
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
"runProperty": Object {},
"styleId": "Normal",
"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,
},
},
"justification": "left",
"width": Object {
"width": 0,
"widthType": "auto",
},
},
},
],
},
"taskpanes": null,
"taskpanesRels": Object {
"rels": Array [],
},
"themes": Array [],
"webExtensions": Array [],
"webSettings": Object {
"divs": Array [],
},
}
`;
exports[`reader should read del_in_ins docx 1`] = `
Object {
"comments": Object {
@ -2715,6 +2990,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -4261,6 +4542,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -5569,6 +5856,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -5934,6 +6227,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -7258,6 +7557,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -10280,6 +10585,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -11172,6 +11483,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -12805,6 +13122,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -14359,6 +14682,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -20127,6 +20456,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {},
},
@ -22964,6 +23299,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {},
},
@ -24144,6 +24485,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -26342,6 +26689,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -28099,6 +28452,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -29949,6 +30308,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -32467,6 +32832,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -87879,6 +88250,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -109549,6 +109926,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -115710,6 +116093,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -125450,6 +125839,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -136626,6 +137021,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -137647,6 +138048,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -139021,6 +139428,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -142492,6 +142905,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -146150,6 +146569,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -147171,6 +147596,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -157690,6 +158121,12 @@ Object {
},
"styles": Object {
"docDefaults": Object {
"paragraphPropertyDefault": Object {
"paragraphProperty": Object {
"runProperty": Object {},
"tabs": Array [],
},
},
"runPropertyDefault": Object {
"runProperty": Object {
"fonts": Object {
@ -162243,6 +162680,31 @@ exports[`writer should write default font 3`] = `
</w:num></w:numbering>"
`;
exports[`writer should write default line spacing 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
<Relationship Id=\\"rId1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\\" Target=\\"styles.xml\\" />
<Relationship Id=\\"rId2\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\\" Target=\\"fontTable.xml\\" />
<Relationship Id=\\"rId3\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\\" Target=\\"settings.xml\\" />
<Relationship Id=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
</Relationships>"
`;
exports[`writer should write default line spacing 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:document xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w10=\\"urn:schemas-microsoft-com:office:word\\" xmlns:wp=\\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\\" xmlns:wps=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\\" xmlns:wpg=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\\" xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:wp14=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 wp14\\">
<w:body><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /><w:spacing w:before=\\"100\\" w:after=\\"0\\" w:afterLines=\\"400\\" w:line=\\"100\\" /></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Hello </w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1985\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"1701\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:cols w:space=\\"425\\" w:num=\\"1\\" />
</w:sectPr></w:body>
</w:document>"
`;
exports[`writer should write default line spacing 3`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:numbering xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\"><w:abstractNum w:abstractNumId=\\"1\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"420\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"1\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%2)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"840\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"2\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%3\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1260\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"3\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%4.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1680\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"4\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%5)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2100\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"5\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%6\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2520\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"6\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%7.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2940\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"7\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%8)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3360\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"8\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%9\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3780\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl></w:abstractNum><w:num w:numId=\\"1\\">
<w:abstractNumId w:val=\\"1\\" />
</w:num></w:numbering>"
`;
exports[`writer should write deleted ToC 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
@ -162988,7 +163450,7 @@ exports[`writer should write style 2`] = `
`;
exports[`writer should write style 3`] = `
"<w:styles xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 w15\\"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault></w:docDefaults><w:style w:type=\\"paragraph\\" w:styleId=\\"Normal\\"><w:name w:val=\\"Normal\\" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"paragraph\\" w:styleId=\\"Heading1\\"><w:name w:val=\\"Heading 1\\" /><w:rPr /><w:pPr><w:rPr /><w:jc w:val=\\"center\\" /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"character\\" w:styleId=\\"Run\\"><w:name w:val=\\"Run test\\" /><w:rPr><w:b /><w:bCs /></w:rPr><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"table\\" w:styleId=\\"Table\\"><w:name w:val=\\"Table 1\\" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:tcPr /><w:tblPr><w:tblW w:w=\\"0\\" w:type=\\"dxa\\" /><w:jc w:val=\\"center\\" /><w:tblBorders><w:top w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:left w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:bottom w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:right w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideH w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideV w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tblBorders><w:tblCellMar>
"<w:styles xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 w15\\"><w:docDefaults><w:rPrDefault><w:rPr /></w:rPrDefault><w:pPrDefault><w:pPr><w:rPr /></w:pPr></w:pPrDefault></w:docDefaults><w:style w:type=\\"paragraph\\" w:styleId=\\"Normal\\"><w:name w:val=\\"Normal\\" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"paragraph\\" w:styleId=\\"Heading1\\"><w:name w:val=\\"Heading 1\\" /><w:rPr /><w:pPr><w:rPr /><w:jc w:val=\\"center\\" /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"character\\" w:styleId=\\"Run\\"><w:name w:val=\\"Run test\\" /><w:rPr><w:b /><w:bCs /></w:rPr><w:pPr><w:rPr /></w:pPr><w:qFormat /></w:style><w:style w:type=\\"table\\" w:styleId=\\"Table\\"><w:name w:val=\\"Table 1\\" /><w:rPr /><w:pPr><w:rPr /></w:pPr><w:tcPr /><w:tblPr><w:tblW w:w=\\"0\\" w:type=\\"dxa\\" /><w:jc w:val=\\"center\\" /><w:tblBorders><w:top w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:left w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:bottom w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:right w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideH w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideV w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tblBorders><w:tblCellMar>
<w:top w:w=\\"0\\" w:type=\\"dxa\\" />
<w:left w:w=\\"55\\" w:type=\\"dxa\\" />
<w:bottom w:w=\\"0\\" w:type=\\"dxa\\" />

View File

@ -190,6 +190,12 @@ describe("reader", () => {
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
test("should read default line spacing", () => {
const buffer = readFileSync("../fixtures/default_line_spacing/default_line_spacing.docx");
const json = w.readDocx(buffer);
expect(json).toMatchSnapshot();
});
});
describe("writer", () => {
@ -975,4 +981,29 @@ describe("writer", () => {
}
writeFileSync("../output/js/style.docx", buffer);
});
test("should write default line spacing", () => {
const spacing = new w.LineSpacing()
.before(100)
.after(0)
.line(100)
.afterLines(400);
const p = new w.Paragraph()
.addRun(new w.Run().addText("Hello "))
.lineSpacing(spacing);
const buffer = new w.Docx()
.defaultLineSpacing(spacing)
.addParagraph(p)
.build();
writeFileSync("../output/js/default_line_spacing.docx", buffer);
const z = new Zip(Buffer.from(buffer));
for (const e of z.getEntries()) {
if (e.entryName.match(/document.xml|numbering.xml/)) {
expect(z.readAsText(e)).toMatchSnapshot();
}
}
});
});