diff --git a/docx-core/src/documents/elements/run.rs b/docx-core/src/documents/elements/run.rs index d965650..3ad1f6d 100644 --- a/docx-core/src/documents/elements/run.rs +++ b/docx-core/src/documents/elements/run.rs @@ -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 diff --git a/docx-core/src/reader/attributes/border.rs b/docx-core/src/reader/attributes/border.rs index d20ba61..5c8f0e3 100644 --- a/docx-core/src/reader/attributes/border.rs +++ b/docx-core/src/reader/attributes/border.rs @@ -16,9 +16,8 @@ pub struct BorderAttrs { pub fn read_border(attrs: &[OwnedAttribute]) -> Result { let mut border_type = BorderType::Single; let mut color = "000000".to_owned(); - let mut size: Option = None; - let mut space: Option = None; - + let mut size: Option = Some(4); + let mut space: Option = Some(0); for a in attrs { let local_name = &a.name.local_name; if local_name == "color" { diff --git a/docx-core/src/reader/run.rs b/docx-core/src/reader/run.rs index 11b6fa5..5869e5d 100644 --- a/docx-core/src/reader/run.rs +++ b/docx-core/src/reader/run.rs @@ -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; + } + } _ => {} } } diff --git a/docx-wasm/js/json/run.ts b/docx-wasm/js/json/run.ts index 21fd60e..1a05311 100644 --- a/docx-wasm/js/json/run.ts +++ b/docx-wasm/js/json/run.ts @@ -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; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 3255a20..c9908bd 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -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 ", diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index eb83451..92ffa54 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -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,