parent
4dd483537a
commit
3c9615fc94
|
@ -21,6 +21,14 @@ pub struct RunFonts {
|
|||
east_asia: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
cs: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
ascii_theme: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
hi_ansi_theme: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
east_asia_theme: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
cs_theme: Option<String>,
|
||||
}
|
||||
|
||||
impl RunFonts {
|
||||
|
@ -47,6 +55,26 @@ impl RunFonts {
|
|||
self.cs = Some(f.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ascii_theme(mut self, f: impl Into<String>) -> Self {
|
||||
self.ascii_theme = Some(f.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn hi_ansi_theme(mut self, f: impl Into<String>) -> Self {
|
||||
self.hi_ansi_theme = Some(f.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn east_asia_theme(mut self, f: impl Into<String>) -> Self {
|
||||
self.east_asia_theme = Some(f.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cs_theme(mut self, f: impl Into<String>) -> Self {
|
||||
self.cs_theme = Some(f.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for RunFonts {
|
||||
|
@ -57,6 +85,10 @@ impl BuildXML for RunFonts {
|
|||
self.hi_ansi.as_ref(),
|
||||
self.cs.as_ref(),
|
||||
self.east_asia.as_ref(),
|
||||
self.ascii_theme.as_ref(),
|
||||
self.hi_ansi_theme.as_ref(),
|
||||
self.cs_theme.as_ref(),
|
||||
self.east_asia_theme.as_ref(),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
@ -14,17 +14,30 @@ fn read_run_fonts(attributes: &[OwnedAttribute]) -> Result<RunFonts, ReaderError
|
|||
let local_name = &a.name.local_name;
|
||||
match local_name.as_str() {
|
||||
"asciiTheme" => {
|
||||
f = f.ascii(&a.value);
|
||||
f = f.ascii_theme(&a.value);
|
||||
}
|
||||
"eastAsiaTheme" => {
|
||||
f = f.east_asia(&a.value);
|
||||
f = f.east_asia_theme(&a.value);
|
||||
}
|
||||
"hAnsiTheme" => {
|
||||
f = f.hi_ansi(&a.value);
|
||||
f = f.hi_ansi_theme(&a.value);
|
||||
}
|
||||
"cstheme" => {
|
||||
f = f.cs_theme(&a.value);
|
||||
}
|
||||
"ascii" => {
|
||||
f = f.ascii(&a.value);
|
||||
}
|
||||
"eastAsia" => {
|
||||
f = f.east_asia(&a.value);
|
||||
}
|
||||
"hAnsi" => {
|
||||
f = f.hi_ansi(&a.value);
|
||||
}
|
||||
"cs" => {
|
||||
f = f.cs(&a.value);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,17 @@ impl XMLBuilder {
|
|||
self.close()
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn run_fonts(
|
||||
mut self,
|
||||
ascii: Option<&String>,
|
||||
hi_ansi: Option<&String>,
|
||||
cs: Option<&String>,
|
||||
east_asia: Option<&String>,
|
||||
ascii_theme: Option<&String>,
|
||||
hi_ansi_theme: Option<&String>,
|
||||
cs_theme: Option<&String>,
|
||||
east_asia_theme: Option<&String>,
|
||||
) -> Self {
|
||||
let mut w = XmlEvent::start_element("w:rFonts");
|
||||
if let Some(ascii) = ascii {
|
||||
|
@ -43,6 +48,18 @@ impl XMLBuilder {
|
|||
if let Some(east_asia) = east_asia {
|
||||
w = w.attr("w:eastAsia", east_asia);
|
||||
}
|
||||
if let Some(ascii_theme) = ascii_theme {
|
||||
w = w.attr("w:asciiTheme", ascii_theme);
|
||||
}
|
||||
if let Some(hi_ansi_theme) = hi_ansi_theme {
|
||||
w = w.attr("w:hAnsiTheme", hi_ansi_theme);
|
||||
}
|
||||
if let Some(cs_theme) = cs_theme {
|
||||
w = w.attr("w:cstheme", cs_theme);
|
||||
}
|
||||
if let Some(east_asia_theme) = east_asia_theme {
|
||||
w = w.attr("w:eastAsiaTheme", east_asia_theme);
|
||||
}
|
||||
self.writer.write(w).expect(EXPECT_MESSAGE);
|
||||
self.close()
|
||||
}
|
||||
|
|
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -337,8 +337,10 @@ export class Docx {
|
|||
run = run.text_border(convertBorderType(borderType), size, space, color);
|
||||
}
|
||||
|
||||
const fonts = this.buildRunFonts(r.property.fonts);
|
||||
run = run.fonts(fonts);
|
||||
if (r.property.fonts) {
|
||||
const fonts = r.property.fonts.buildWasmObject();
|
||||
run = run.fonts(fonts);
|
||||
}
|
||||
|
||||
return run;
|
||||
}
|
||||
|
|
|
@ -11,10 +11,21 @@ export type TextBorderJSON = {
|
|||
color: string;
|
||||
};
|
||||
|
||||
export type RunFontsJSON = {
|
||||
ascii?: string;
|
||||
hiAnsi?: string;
|
||||
eastAsia?: string;
|
||||
cs?: string;
|
||||
asciiTheme?: string;
|
||||
hiAnsiTheme?: string;
|
||||
eastAsiaTheme?: string;
|
||||
csTheme?: string;
|
||||
};
|
||||
|
||||
export type RunPropertyJSON = {
|
||||
sz?: number | null;
|
||||
szCs?: number | null;
|
||||
fonts?: string | null;
|
||||
fonts?: RunFontsJSON | null;
|
||||
color?: string | null;
|
||||
highlight?: string | null;
|
||||
vertAlign?: VertAlignType | null;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as wasm from "./pkg";
|
||||
|
||||
import { Text } from "./text";
|
||||
import { DeleteText } from "./delete-text";
|
||||
import { Tab } from "./tab";
|
||||
|
@ -39,6 +41,10 @@ export class RunFonts {
|
|||
_hiAnsi?: string;
|
||||
_eastAsia?: string;
|
||||
_cs?: string;
|
||||
_asciiTheme?: string;
|
||||
_hiAnsiTheme?: string;
|
||||
_eastAsiaTheme?: string;
|
||||
_csTheme?: string;
|
||||
|
||||
ascii(f: string) {
|
||||
this._ascii = f;
|
||||
|
@ -59,6 +65,43 @@ export class RunFonts {
|
|||
this._eastAsia = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
asciiTheme(f: string) {
|
||||
this._asciiTheme = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
hiAnsiTheme(f: string) {
|
||||
this._hiAnsiTheme = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
csTheme(f: string) {
|
||||
this._csTheme = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
eastAsiaTheme(f: string) {
|
||||
this._eastAsia = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
buildWasmObject = () => {
|
||||
let f = wasm.createRunFonts();
|
||||
if (this?._ascii) {
|
||||
f = f.ascii(this._ascii);
|
||||
}
|
||||
if (this?._hiAnsi) {
|
||||
f = f.hi_ansi(this._hiAnsi);
|
||||
}
|
||||
if (this?._cs) {
|
||||
f = f.cs(this._cs);
|
||||
}
|
||||
if (this?._eastAsia) {
|
||||
f = f.east_asia(this._eastAsia);
|
||||
}
|
||||
return f;
|
||||
};
|
||||
}
|
||||
|
||||
export class Run {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.220",
|
||||
"version": "0.0.221",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue