Skip to content

Commit

Permalink
fix: level disable styles (#799)
Browse files Browse the repository at this point in the history
* fix: level disable styles

* fix

* fix

* fix
  • Loading branch information
bokuweb authored Jan 29, 2025
1 parent 462239a commit 5741806
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!--
- Support `TC`
- Update `Level` styles.
-->

## @0.4.17 (26. Apr, 2024)
Expand Down Expand Up @@ -57,7 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- escape author in del/ins.

## [email protected] (9. Aug, 2023)
## [email protected] (9. Aug, 20)

- use i32 for line instead of u32.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions docx-core/src/documents/elements/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Self {
self.run_property = self.run_property.underline(line_type);
self
Expand Down
5 changes: 5 additions & 0 deletions docx-core/src/documents/elements/run_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
24 changes: 24 additions & 0 deletions docx-wasm/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions docx-wasm/js/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 33 additions & 6 deletions docx-wasm/js/run-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion docx-wasm/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down
20 changes: 20 additions & 0 deletions docx-wasm/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions docx-wasm/src/run_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5741806

Please sign in to comment.