update snaps (#266)

* update snaps

* update
main
bokuweb 2021-03-26 13:37:01 +09:00 committed by GitHub
parent e33f4b292d
commit 967170f6d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 851 additions and 21 deletions

View File

@ -209,6 +209,11 @@ impl Docx {
self
}
pub fn default_tab_stop(mut self, stop: usize) -> Self {
self.settings = self.settings.default_tab_stop(stop);
self
}
pub fn add_doc_var(mut self, name: &str, val: &str) -> Self {
self.settings = self.settings.add_doc_var(name, val);
self

View File

@ -24,6 +24,11 @@ impl Settings {
self
}
pub fn default_tab_stop(mut self, tab_stop: usize) -> Self {
self.default_tab_stop = DefaultTabStop::new(tab_stop);
self
}
pub fn add_doc_var(mut self, name: impl Into<String>, val: impl Into<String>) -> Self {
self.doc_vars.push(DocVar::new(name, val));
self
@ -33,7 +38,7 @@ impl Settings {
impl Default for Settings {
fn default() -> Self {
Self {
default_tab_stop: DefaultTabStop::new(709),
default_tab_stop: DefaultTabStop::new(840),
zoom: Zoom::new(100),
doc_id: None,
doc_vars: vec![],
@ -116,7 +121,7 @@ mod tests {
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:settings 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"><w:defaultTabStop w:val="709" /><w:zoom w:percent="100" /><w:compat>
<w:settings 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"><w:defaultTabStop w:val="840" /><w:zoom w:percent="100" /><w:compat>
<w:spaceForUL />
<w:balanceSingleByteDoubleByteWidth />
<w:doNotLeaveBackslashAlone />

View File

@ -41,6 +41,14 @@ impl FromXML for Settings {
}
}
}
XMLElement::DefaultTabStop => {
let val = attributes::read_val(&attributes);
if let Some(val) = val {
if let Ok(val) = f32::from_str(&val) {
settings = settings.default_tab_stop(val as usize);
}
}
}
_ => {}
}
}

View File

@ -116,6 +116,7 @@ pub enum XMLElement {
DocVar,
DocGrid,
DocDefaults,
DefaultTabStop,
RunPropertyDefault,
SectionProperty,
PageSize,
@ -292,6 +293,7 @@ impl FromStr for XMLElement {
"docDefaults" => Ok(XMLElement::DocDefaults),
"docGrid" => Ok(XMLElement::DocGrid),
"rPrDefault" => Ok(XMLElement::RunPropertyDefault),
"defaultTabStop" => Ok(XMLElement::DefaultTabStop),
_ => Ok(XMLElement::Unsupported),
}
}

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

@ -106,6 +106,11 @@ export class Docx {
return this;
}
defaultTabStop(stop: number) {
this.settings.defaultTabStop(stop);
return this;
}
createdAt(date: string) {
this.docProps.createdAt(date);
return this;
@ -717,6 +722,8 @@ export class Docx {
docx = docx.doc_id(this.settings._docId);
}
docx = docx.default_tab_stop(this.settings._defaultTabStop);
this.settings._docVars.forEach((v) => {
docx = docx.add_doc_var(v.name, v.val);
});

View File

@ -6,12 +6,18 @@ export type DocVar = {
export class Settings {
_docId: string | null = null;
_docVars: DocVar[] = [];
_defaultTabStop = 840;
docId(id: string) {
this._docId = id;
return this;
}
defaultTabStop(stop: number) {
this._defaultTabStop = stop;
return this;
}
addDocVar(name: string, val: string) {
this._docVars.push({ name, val });
return this;

View File

@ -1,6 +1,6 @@
{
"name": "docx-wasm",
"version": "0.0.181",
"version": "0.0.182",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>",

View File

@ -63,6 +63,11 @@ impl Docx {
self
}
pub fn default_tab_stop(mut self, stop: usize) -> Docx {
self.0 = self.0.default_tab_stop(stop);
self
}
pub fn page_size(mut self, w: u32, h: u32) -> Docx {
self.0 = self.0.page_size(w, h);
self

View File

@ -2914,7 +2914,7 @@ Object {
],
},
"settings": Object {
"defaultTabStop": 709,
"defaultTabStop": 840,
"docId": "E43E077A-3477-A242-BD53-4313974E06A2",
"docVars": Array [],
"zoom": 100,
@ -5332,7 +5332,7 @@ Object {
],
},
"settings": Object {
"defaultTabStop": 709,
"defaultTabStop": 840,
"docId": "10BE20B6-DCA9-7441-B548-606D7D9EDD92",
"docVars": Array [],
"zoom": 100,
@ -10448,7 +10448,7 @@ Object {
],
},
"settings": Object {
"defaultTabStop": 709,
"defaultTabStop": 840,
"docId": "C272B628-6DE8-264A-8734-9D2219FFD42F",
"docVars": Array [],
"zoom": 100,
@ -11517,7 +11517,7 @@ Object {
],
},
"settings": Object {
"defaultTabStop": 709,
"defaultTabStop": 840,
"docId": "9F52F717-3F03-584C-ACEF-96E0106FA905",
"docVars": Array [],
"zoom": 100,

792
test.json 100644
View File

@ -0,0 +1,792 @@
{
"contentType": {
"types": {
"/_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",
"/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/header1.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.header+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"
}
},
"rels": {
"rels": [
[
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties",
"rId1",
"docProps/core.xml"
],
[
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties",
"rId2",
"docProps/app.xml"
],
[
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"rId3",
"word/document.xml"
]
]
},
"documentRels": {
"hasComments": false,
"hasNumberings": false,
"imageIds": []
},
"docProps": {
"app": {},
"core": {
"config": {
"created": null,
"creator": null,
"description": null,
"language": null,
"lastModifiedBy": null,
"modified": null,
"revision": null,
"subject": null,
"title": null
}
}
},
"styles": {
"docDefaults": {
"runPropertyDefault": {
"runProperty": {
"sz": 21,
"szCs": 21,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
}
}
},
"styles": [
{
"styleId": "a",
"name": "Normal",
"styleType": "paragraph",
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"paragraphProperty": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"style": null,
"numberingProperty": null,
"alignment": "both",
"indent": null,
"lineHeight": null
},
"tableProperty": {
"width": {
"width": 0,
"widthType": "Auto"
},
"justification": "left",
"borders": {
"top": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "top",
"space": 0
},
"left": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "left",
"space": 0
},
"bottom": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "bottom",
"space": 0
},
"right": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "right",
"space": 0
},
"insideH": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideH",
"space": 0
},
"insideV": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideV",
"space": 0
}
},
"margins": {
"top": 55,
"left": 54,
"bottom": 55,
"right": 55
},
"indent": null,
"style": null,
"layout": null
},
"basedOn": null
},
{
"styleId": "a0",
"name": "Default Paragraph Font",
"styleType": "character",
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"paragraphProperty": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"style": null,
"numberingProperty": null,
"alignment": null,
"indent": null,
"lineHeight": null
},
"tableProperty": {
"width": {
"width": 0,
"widthType": "Auto"
},
"justification": "left",
"borders": {
"top": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "top",
"space": 0
},
"left": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "left",
"space": 0
},
"bottom": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "bottom",
"space": 0
},
"right": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "right",
"space": 0
},
"insideH": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideH",
"space": 0
},
"insideV": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideV",
"space": 0
}
},
"margins": {
"top": 55,
"left": 54,
"bottom": 55,
"right": 55
},
"indent": null,
"style": null,
"layout": null
},
"basedOn": null
},
{
"styleId": "a1",
"name": "Normal Table",
"styleType": "table",
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"paragraphProperty": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"style": null,
"numberingProperty": null,
"alignment": null,
"indent": null,
"lineHeight": null
},
"tableProperty": {
"width": {
"width": 0,
"widthType": "Auto"
},
"justification": "left",
"borders": {
"top": null,
"left": null,
"bottom": null,
"right": null,
"insideH": null,
"insideV": null
},
"margins": {
"top": 55,
"left": 54,
"bottom": 55,
"right": 55
},
"indent": null,
"style": null,
"layout": null
},
"basedOn": null
},
{
"styleId": "a2",
"name": "No List",
"styleType": "numbering",
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"paragraphProperty": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"style": null,
"numberingProperty": null,
"alignment": null,
"indent": null,
"lineHeight": null
},
"tableProperty": {
"width": {
"width": 0,
"widthType": "Auto"
},
"justification": "left",
"borders": {
"top": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "top",
"space": 0
},
"left": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "left",
"space": 0
},
"bottom": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "bottom",
"space": 0
},
"right": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "right",
"space": 0
},
"insideH": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideH",
"space": 0
},
"insideV": {
"borderType": "single",
"size": 2,
"color": "000000",
"position": "insideV",
"space": 0
}
},
"margins": {
"top": 55,
"left": 54,
"bottom": 55,
"right": 55
},
"indent": null,
"style": null,
"layout": null
},
"basedOn": null
}
]
},
"document": {
"children": [
{
"type": "paragraph",
"data": {
"id": "5064973E",
"children": [
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": {
"borderType": "single",
"size": 4,
"color": "auto",
"space": 0
}
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "H"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": {
"borderType": "single",
"size": 4,
"color": "auto",
"space": 0
}
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "ello"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": " "
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": true,
"boldCs": true,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "W"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": true,
"boldCs": true,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": {
"borderType": "single",
"size": 4,
"color": "auto",
"space": 0
}
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "o"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": {
"borderType": "single",
"size": 4,
"color": "auto",
"space": 0
}
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "rl"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "d!!!"
}
}
]
}
},
{
"type": "run",
"data": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"children": [
{
"type": "text",
"data": {
"preserveSpace": true,
"text": "===="
}
}
]
}
}
],
"property": {
"runProperty": {
"sz": null,
"szCs": null,
"color": null,
"highlight": null,
"underline": null,
"bold": null,
"boldCs": null,
"italic": null,
"italicCs": null,
"vanish": null,
"spacing": null,
"fonts": null,
"textBorder": null
},
"style": null,
"numberingProperty": null,
"alignment": null,
"indent": null,
"lineHeight": null
},
"hasNumbering": false
}
}
],
"sectionProperty": {
"pageSize": {
"w": 11900,
"h": 16840
},
"pageMargin": {
"top": 1985,
"left": 1701,
"bottom": 1701,
"right": 1701,
"header": 851,
"footer": 992,
"gutter": 0
},
"columns": 425,
"docGrid": {
"gridType": "lines",
"linePitch": 360,
"charSpace": null
},
"headerReference": {
"headerType": "default",
"id": "rId4"
},
"sectionType": null
},
"hasNumbering": false
},
"comments": {
"comments": []
},
"numberings": {
"abstractNums": [],
"numberings": []
},
"settings": {
"defaultTabStop": 709,
"zoom": 100,
"docId": "8E2D3E4C-6723-BC4B-A914-75D1ABCB0821",
"docVars": []
},
"fontTable": {},
"media": [],
"header": {
"children": []
},
"commentsExtended": {
"children": []
}
}