From 574180673417cfa343d31a278f7469f0876a73f4 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Wed, 29 Jan 2025 12:08:57 +0900 Subject: [PATCH] fix: level disable styles (#799) * fix: level disable styles * fix * fix * fix --- CHANGELOG.md | 3 +- Cargo.lock | 2 +- docx-core/src/documents/elements/level.rs | 20 ++++++++++ .../src/documents/elements/run_property.rs | 5 +++ docx-wasm/js/index.ts | 24 ++++++++++++ docx-wasm/js/level.ts | 20 ++++++++++ docx-wasm/js/run-property.ts | 39 ++++++++++++++++--- docx-wasm/package.json | 2 +- docx-wasm/src/level.rs | 20 ++++++++++ docx-wasm/src/run_property.rs | 15 +++++++ 10 files changed, 141 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5999c544b..df3598bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## @0.4.17 (26. Apr, 2024) @@ -57,7 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - escape author in del/ins. -## docx-wasm@0.0.278-rc19 (9. Aug, 2023) +## docx-wasm@0.0.278-rc19 (9. Aug, 20) - use i32 for line instead of u32. diff --git a/Cargo.lock b/Cargo.lock index 932f4977a..8168c0dce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "Inflector" diff --git a/docx-core/src/documents/elements/level.rs b/docx-core/src/documents/elements/level.rs index 677441176..0cc3881f8 100644 --- a/docx-core/src/documents/elements/level.rs +++ b/docx-core/src/documents/elements/level.rs @@ -94,11 +94,31 @@ impl Level { self } + pub fn disable_bold(mut self) -> Self { + self.run_property = self.run_property.disable_bold(); + self + } + pub fn italic(mut self) -> Self { self.run_property = self.run_property.italic(); self } + pub fn disable_italic(mut self) -> Self { + self.run_property = self.run_property.disable_italic(); + self + } + + pub fn strike(mut self) -> Self { + self.run_property = self.run_property.strike(); + self + } + + pub fn disable_strike(mut self) -> Self { + self.run_property = self.run_property.disable_strike(); + self + } + pub fn underline(mut self, line_type: impl Into) -> Self { self.run_property = self.run_property.underline(line_type); self diff --git a/docx-core/src/documents/elements/run_property.rs b/docx-core/src/documents/elements/run_property.rs index e6200d173..2a50720bd 100644 --- a/docx-core/src/documents/elements/run_property.rs +++ b/docx-core/src/documents/elements/run_property.rs @@ -119,6 +119,11 @@ impl RunProperty { self } + pub fn disable_strike(mut self) -> RunProperty { + self.strike = Some(Strike::new().disable()); + self + } + pub fn disable_italic(mut self) -> RunProperty { self.italic = Some(Italic::new().disable()); self.italic_cs = Some(ItalicCs::new().disable()); diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index 4b071f9b7..18d128450 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -298,6 +298,30 @@ export class Docx { level = level.italic(); } + if (l.runProperty._bold != null) { + if (l.runProperty._bold) { + level = level.bold(); + } else { + level = level.disable_bold(); + } + } + + if (l.runProperty._italic != null) { + if (l.runProperty._italic) { + level = level.italic(); + } else { + level = level.disable_italic(); + } + } + + if (l.runProperty._strike != null) { + if (l.runProperty._strike) { + level = level.strike(); + } else { + level = level.disable_strike(); + } + } + if (l.runProperty._size) { level = level.size(l.runProperty._size); } diff --git a/docx-wasm/js/level.ts b/docx-wasm/js/level.ts index c50ca7f6a..9d8955886 100644 --- a/docx-wasm/js/level.ts +++ b/docx-wasm/js/level.ts @@ -75,11 +75,31 @@ export class Level { return this; } + disableBold() { + this.runProperty.disableBold(); + return this; + } + italic() { this.runProperty.italic(); return this; } + disableItalic() { + this.runProperty.disableItalic(); + return this; + } + + strike() { + this.runProperty.strike(); + return this; + } + + disableStrike() { + this.runProperty.disableStrike(); + return this; + } + underline(type: string) { this.runProperty.underline(type); return this; diff --git a/docx-wasm/js/run-property.ts b/docx-wasm/js/run-property.ts index a0d8aca89..940906253 100644 --- a/docx-wasm/js/run-property.ts +++ b/docx-wasm/js/run-property.ts @@ -68,16 +68,31 @@ export class RunProperty { return this; } + disableBold() { + this._bold = false; + return this; + } + strike() { this._strike = true; return this; } + disableStrike() { + this._strike = false; + return this; + } + italic() { this._italic = true; return this; } + disableItalic() { + this._italic = false; + return this; + } + underline(type: string) { this._underline = type; return this; @@ -340,16 +355,28 @@ export const createRunProperty = (property: RunProperty): wasm.RunProperty => { } } - if (property._bold) { - target = target.bold(); + if (property._bold != null) { + if (property._bold) { + target = target.bold(); + } else { + target = target.disable_bold(); + } } - if (property._italic) { - target = target.italic(); + if (property._italic != null) { + if (property._italic) { + target = target.italic(); + } else { + target = target.disable_italic(); + } } - if (property._strike) { - target = target.strike(); + if (property._strike != null) { + if (property._strike) { + target = target.strike(); + } else { + target = target.disable_strike(); + } } if (property._underline) { diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 9b00b31cf..40dd21209 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.4.18-rc31", + "version": "0.4.18-rc34", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/level.rs b/docx-wasm/src/level.rs index 17024b2a4..5d336d4a0 100644 --- a/docx-wasm/src/level.rs +++ b/docx-wasm/src/level.rs @@ -62,11 +62,31 @@ impl Level { self } + pub fn disable_bold(mut self) -> Self { + self.0 = self.0.disable_bold(); + self + } + pub fn italic(mut self) -> Self { self.0 = self.0.italic(); self } + pub fn strike(mut self) -> Self { + self.0 = self.0.strike(); + self + } + + pub fn disable_strike(mut self) -> Self { + self.0 = self.0.disable_strike(); + self + } + + pub fn disable_italic(mut self) -> Self { + self.0 = self.0.disable_italic(); + self + } + pub fn underline(mut self, line_type: &str) -> Self { self.0 = self.0.underline(line_type); self diff --git a/docx-wasm/src/run_property.rs b/docx-wasm/src/run_property.rs index 16ad1ba04..7d027b64b 100644 --- a/docx-wasm/src/run_property.rs +++ b/docx-wasm/src/run_property.rs @@ -26,16 +26,31 @@ impl RunProperty { self } + pub fn disable_bold(mut self) -> Self { + self.0 = self.0.disable_bold(); + self + } + pub fn italic(mut self) -> Self { self.0 = self.0.italic(); self } + pub fn disable_italic(mut self) -> Self { + self.0 = self.0.disable_italic(); + self + } + pub fn strike(mut self) -> Self { self.0 = self.0.strike(); self } + pub fn disable_strike(mut self) -> Self { + self.0 = self.0.disable_strike(); + self + } + pub fn fonts(mut self, f: RunFonts) -> Self { self.0 = self.0.fonts(f.take()); self