Read text border (#262)

* fix: reader

* 0.0.176

* 0.0.177

* update
main
bokuweb 2021-03-24 18:00:17 +09:00 committed by GitHub
parent 298821cf90
commit 382dd33826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 41 deletions

View File

@ -172,6 +172,11 @@ impl Run {
self
}
pub fn text_border(mut self, b: TextBorder) -> Run {
self.run_property = self.run_property.text_border(b);
self
}
pub fn disable_italic(mut self) -> Run {
self.run_property = self.run_property.disable_italic();
self

View File

@ -16,9 +16,8 @@ pub struct BorderAttrs {
pub fn read_border(attrs: &[OwnedAttribute]) -> Result<BorderAttrs, ReaderError> {
let mut border_type = BorderType::Single;
let mut color = "000000".to_owned();
let mut size: Option<u32> = None;
let mut space: Option<u32> = None;
let mut size: Option<u32> = Some(4);
let mut space: Option<u32> = Some(0);
for a in attrs {
let local_name = &a.name.local_name;
if local_name == "color" {

View File

@ -80,6 +80,18 @@ impl ElementReader for Run {
let drawing = Drawing::read(r, &attributes)?;
run = run.add_drawing(drawing);
}
XMLElement::TextBorder => {
if let Ok(attr) = read_border(&attributes) {
let mut border = TextBorder::new()
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
border = border.size(size as usize);
};
run = run.text_border(border);
continue;
}
}
_ => {}
}
}

View File

@ -1,8 +1,9 @@
import { DrawingJSON } from "./drawing";
import { CommentRangeStartJSON, CommentRangeEndJSON } from "..";
import { BorderType } from "../border";
export type TextBorderJSON = {
borderType: string;
borderType: BorderType;
size: number;
space: number;
color: string;

View File

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

View File

@ -1002,7 +1002,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1011,14 +1011,14 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -1026,7 +1026,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -1451,7 +1451,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1467,7 +1467,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -1535,7 +1535,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1544,7 +1544,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -1559,7 +1559,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -1630,7 +1630,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1646,7 +1646,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -1654,7 +1654,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -1714,7 +1714,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1809,7 +1809,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1833,7 +1833,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -1893,7 +1893,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -1902,7 +1902,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -1917,7 +1917,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -1986,7 +1986,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -2072,7 +2072,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -2088,7 +2088,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -2096,7 +2096,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2156,7 +2156,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "bottom",
"size": 2,
"size": 4,
"space": 0,
},
"insideH": null,
@ -2180,7 +2180,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2249,7 +2249,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -2264,7 +2264,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2345,7 +2345,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -2353,7 +2353,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2431,7 +2431,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2500,7 +2500,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -2515,7 +2515,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2602,7 +2602,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "right",
"size": 2,
"size": 4,
"space": 0,
},
"tl2br": null,
@ -2610,7 +2610,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2694,7 +2694,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,
@ -2763,7 +2763,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "left",
"size": 2,
"size": 4,
"space": 0,
},
"right": Object {
@ -2778,7 +2778,7 @@ Object {
"borderType": "nil",
"color": "000000",
"position": "top",
"size": 2,
"size": 4,
"space": 0,
},
"tr2bl": null,