Re fix numpr (#407)

* fix: numpr reader

* fix

* fix

* fix
main
bokuweb 2022-01-14 15:03:53 +09:00 committed by GitHub
parent c857def7ef
commit 87b0439ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 125 additions and 57 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ reg.json
docx-core/tests/output/*.docx
docx-wasm/*.tgz
docx-core/tests/output/*.json
test.json

View File

@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## docx-wasm@0.0.222, 223, 224, 225 (14. January, 2022)
- Fixed a typo `window_control` -> `widow_control`
- Fixed a numPr reader.
## docx-wasm@0.0.219, 220, 221 (6. January, 2022)
- [Internal]Support runFonts reader.

View File

@ -4,7 +4,7 @@ use std::fs::File;
use std::io::{Read, Write};
pub fn main() {
let mut file = File::open("./toc1.docx").unwrap();
let mut file = File::open("./ppr_del.docx").unwrap();
let mut buf = vec![];
file.read_to_end(&mut buf).unwrap();

View File

@ -25,6 +25,11 @@ impl NumberingProperty {
Default::default()
}
pub fn id(mut self, id: NumberingId) -> NumberingProperty {
self.id = Some(id);
self
}
pub fn add_num(mut self, id: NumberingId, level: IndentLevel) -> NumberingProperty {
self.id = Some(id);
self.level = Some(level);

View File

@ -230,8 +230,8 @@ impl Paragraph {
self
}
pub fn window_control(mut self, v: bool) -> Self {
self.property = self.property.window_control(v);
pub fn widow_control(mut self, v: bool) -> Self {
self.property = self.property.widow_control(v);
self
}

View File

@ -26,7 +26,7 @@ pub struct ParagraphProperty {
#[serde(skip_serializing_if = "Option::is_none")]
pub page_break_before: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub window_control: Option<bool>,
pub widow_control: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub outline_lvl: Option<OutlineLvl>,
pub tabs: Vec<Tab>,
@ -73,6 +73,11 @@ impl ParagraphProperty {
self
}
pub fn numbering_property(mut self, np: NumberingProperty) -> Self {
self.numbering_property = Some(np);
self
}
pub fn line_spacing(mut self, spacing: LineSpacing) -> Self {
self.line_spacing = Some(spacing);
self
@ -101,8 +106,8 @@ impl ParagraphProperty {
self
}
pub fn window_control(mut self, v: bool) -> Self {
self.window_control = Some(v);
pub fn widow_control(mut self, v: bool) -> Self {
self.widow_control = Some(v);
self
}
@ -161,9 +166,9 @@ fn inner_build(p: &ParagraphProperty) -> Vec<u8> {
}
}
if let Some(v) = p.window_control {
if let Some(v) = p.widow_control {
if v {
b = b.window_control()
b = b.widow_control()
}
}

View File

@ -35,8 +35,9 @@ impl ElementReader for NumberingProperty {
Ok(XmlEvent::EndElement { name, .. }) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
if e == XMLElement::NumberingProperty {
if id.is_none() || level.is_none() {
return Ok(NumberingProperty::new());
if level.is_none() {
return Ok(NumberingProperty::new()
.id(NumberingId::new(id.expect("should id exists"))));
}
let np = NumberingProperty::new().add_num(
NumberingId::new(id.unwrap()),

View File

@ -22,7 +22,6 @@ impl ElementReader for ParagraphProperty {
attributes, name, ..
}) => {
let e = XMLElement::from_str(&name.local_name).unwrap();
match e {
XMLElement::Indent => {
let (start, end, special, start_chars, hanging_chars, first_line_chars) =
@ -68,9 +67,8 @@ impl ElementReader for ParagraphProperty {
continue;
}
XMLElement::NumberingProperty => {
let num_pr = NumberingProperty::read(r, attrs)?;
if num_pr.id.is_some() && num_pr.level.is_some() {
p = p.numbering(num_pr.id.unwrap(), num_pr.level.unwrap());
if let Ok(num_pr) = NumberingProperty::read(r, attrs) {
p = p.numbering_property(num_pr);
}
continue;
}
@ -91,8 +89,8 @@ impl ElementReader for ParagraphProperty {
XMLElement::PageBreakBefore => {
p.page_break_before = Some(true);
}
XMLElement::WindowControl => {
p.window_control = Some(true);
XMLElement::WidowControl => {
p.widow_control = Some(true);
}
XMLElement::ParagraphPropertyChange => {
if let Ok(ppr_change) = ParagraphPropertyChange::read(r, attrs) {

View File

@ -48,7 +48,7 @@ pub enum XMLElement {
KeepNext,
KeepLines,
PageBreakBefore,
WindowControl,
WidowControl,
DivId,
Div,
DivsChild,
@ -344,7 +344,7 @@ impl FromStr for XMLElement {
"keepNext" => Ok(XMLElement::KeepNext),
"keepLines" => Ok(XMLElement::KeepLines),
"pageBreakBefore" => Ok(XMLElement::PageBreakBefore),
"windowControl" => Ok(XMLElement::WindowControl),
"widowControl" => Ok(XMLElement::WidowControl),
"headerReference" => Ok(XMLElement::HeaderReference),
"footerReference" => Ok(XMLElement::FooterReference),
"titlePg" => Ok(XMLElement::TitlePg),

View File

@ -431,7 +431,7 @@ impl XMLBuilder {
closed!(keep_next, "w:keepNext");
closed!(keep_lines, "w:keepLines");
closed!(page_break_before, "w:pageBreakBefore");
closed!(window_control, "w:windowControl");
closed!(widow_control, "w:widowControl");
/*
<w:lvlOverride w:ilvl="0">

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

@ -603,8 +603,8 @@ export class Docx {
paragraph = paragraph.page_break_before(true);
}
if (p.property.windowControl) {
paragraph = paragraph.window_control(true);
if (p.property.widowControl) {
paragraph = paragraph.widow_control(true);
}
return paragraph;

View File

@ -28,7 +28,7 @@ export type ParagraphPropertyJSON = {
keepNext?: boolean;
keepLines?: boolean;
pageBreakBefore?: boolean;
windowControl?: boolean;
widowControl?: boolean;
outlineLvl?: number | null;
paragraphPropertyChange?: {
author: string;

View File

@ -81,7 +81,7 @@ export type ParagraphProperty = {
keepNext: boolean;
keepLines: boolean;
pageBreakBefore: boolean;
windowControl: boolean;
widowControl: boolean;
};
export const createDefaultParagraphProperty = (): ParagraphProperty => {
@ -90,7 +90,7 @@ export const createDefaultParagraphProperty = (): ParagraphProperty => {
keepNext: false,
keepLines: false,
pageBreakBefore: false,
windowControl: false,
widowControl: false,
};
};
@ -184,8 +184,8 @@ export class Paragraph {
return this;
}
windowControl(v: boolean) {
this.property = { ...this.property, windowControl: v };
widowControl(v: boolean) {
this.property = { ...this.property, widowControl: v };
return this;
}

View File

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

View File

@ -137,8 +137,8 @@ impl Paragraph {
self
}
pub fn window_control(mut self, v: bool) -> Self {
self.0 = self.0.window_control(v);
pub fn widow_control(mut self, v: bool) -> Self {
self.0 = self.0.widow_control(v);
self
}
}

View File

@ -566,6 +566,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -1370,6 +1371,7 @@ Object {
},
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -1519,6 +1521,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -2913,6 +2916,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -3873,6 +3877,7 @@ Object {
"szCs": 22,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -3949,6 +3954,7 @@ Object {
"szCs": 18,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4038,6 +4044,7 @@ Object {
"szCs": 22,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4114,6 +4121,7 @@ Object {
"szCs": 18,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4202,6 +4210,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4277,6 +4286,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4365,6 +4375,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4440,6 +4451,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4528,6 +4540,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4603,6 +4616,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4678,6 +4692,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4766,6 +4781,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4841,6 +4857,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -4916,6 +4933,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5004,6 +5022,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5073,6 +5092,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5142,6 +5162,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5230,6 +5251,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5305,6 +5327,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5380,6 +5403,7 @@ Object {
"szCs": 20,
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -5559,6 +5583,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"fonts": Object {
@ -7338,6 +7363,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -11067,6 +11093,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -11172,6 +11199,10 @@ Object {
"line": 360,
"lineRule": "Exact",
},
"numberingProperty": Object {
"id": 1,
"level": null,
},
"outlineLvl": 0,
"runProperty": Object {},
"tabs": Array [],
@ -11408,6 +11439,7 @@ Object {
"outlineLvl": 2,
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"fonts": Object {
@ -11524,6 +11556,7 @@ Object {
"outlineLvl": 3,
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"fonts": Object {
@ -11643,6 +11676,7 @@ Object {
"outlineLvl": 4,
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"fonts": Object {
@ -11759,6 +11793,7 @@ Object {
"outlineLvl": 5,
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"fonts": Object {
@ -13066,14 +13101,20 @@ Object {
"start": 728,
"startChars": null,
},
"numberingProperty": Object {
"id": 1,
"level": null,
},
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
},
"runProperty": Object {
"fonts": Object {},
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -13490,6 +13531,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -14201,6 +14243,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -15227,6 +15270,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -16532,6 +16576,7 @@ Object {
"alignment": "left",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -16685,6 +16730,7 @@ Object {
},
},
"tabs": Array [],
"widowControl": true,
},
},
"type": "paragraph",
@ -17132,6 +17178,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",
@ -17223,6 +17270,10 @@ Object {
"name": "heading 1",
"paragraphProperty": Object {
"keepNext": true,
"numberingProperty": Object {
"id": 1,
"level": null,
},
"outlineLvl": 0,
"runProperty": Object {},
"tabs": Array [],
@ -18643,6 +18694,7 @@ Object {
"outlineLvl": 9,
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {
"bold": true,
@ -21713,6 +21765,7 @@ Object {
"alignment": "both",
"runProperty": Object {},
"tabs": Array [],
"widowControl": true,
},
"runProperty": Object {},
"styleId": "a",