Fix bold and italic (#263)

* fix: bold and italic

* use RunProperty::read

* fix

* fix: style rPr reader

* 0.0.179

* fix: snaps
main
bokuweb 2021-03-24 22:49:32 +09:00 committed by GitHub
parent 382dd33826
commit ef612ee1ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 66 deletions

View File

@ -196,6 +196,11 @@ impl Run {
self.run_property = self.run_property.fonts(f); self.run_property = self.run_property.fonts(f);
self self
} }
pub(crate) fn set_property(mut self, p: RunProperty) -> Run {
self.run_property = p;
self
}
} }
impl BuildXML for Run { impl BuildXML for Run {

View File

@ -41,32 +41,10 @@ impl ElementReader for Run {
XMLElement::Tab => { XMLElement::Tab => {
run = run.add_tab(); run = run.add_tab();
} }
// TODO: use RunProperty::read() XMLElement::RunProperty => {
XMLElement::Bold => { let p = RunProperty::read(r, &attributes)?;
if !read_bool(&attributes) { run = run.set_property(p);
run = run.disable_bold();
continue;
} }
run = run.bold();
}
XMLElement::Highlight => {
run = run.highlight(attributes[0].value.clone())
}
XMLElement::Color => run = run.color(attributes[0].value.clone()),
XMLElement::Size => {
run = run.size(usize::from_str(&attributes[0].value)?)
}
XMLElement::Underline => {
run = run.underline(&attributes[0].value.clone())
}
XMLElement::Italic => {
if !read_bool(&attributes) {
run = run.disable_italic();
continue;
}
run = run.italic();
}
XMLElement::Vanish => run = run.vanish(),
XMLElement::Text => text_state = TextState::Text, XMLElement::Text => text_state = TextState::Text,
XMLElement::DeleteText => text_state = TextState::Delete, XMLElement::DeleteText => text_state = TextState::Delete,
XMLElement::Break => { XMLElement::Break => {
@ -80,18 +58,6 @@ impl ElementReader for Run {
let drawing = Drawing::read(r, &attributes)?; let drawing = Drawing::read(r, &attributes)?;
run = run.add_drawing(drawing); 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

@ -22,6 +22,7 @@ impl ElementReader for RunProperty {
match e { match e {
XMLElement::Bold => { XMLElement::Bold => {
if !read_bool(&attributes) { if !read_bool(&attributes) {
rp = rp.disable_bold();
continue; continue;
} }
rp = rp.bold(); rp = rp.bold();
@ -40,6 +41,7 @@ impl ElementReader for RunProperty {
XMLElement::Underline => rp = rp.underline(&attributes[0].value.clone()), XMLElement::Underline => rp = rp.underline(&attributes[0].value.clone()),
XMLElement::Italic => { XMLElement::Italic => {
if !read_bool(&attributes) { if !read_bool(&attributes) {
rp = rp.disable_italic();
continue; continue;
} }
rp = rp.italic(); rp = rp.italic();

View File

@ -53,29 +53,10 @@ impl ElementReader for Style {
continue; continue;
} }
// rPr // rPr
XMLElement::Bold => { XMLElement::RunProperty => {
if !read_bool(&attributes) { let p = RunProperty::read(r, &attributes)?;
continue; style.run_property = p;
} }
style = style.bold();
}
XMLElement::Highlight => {
style = style.highlight(attributes[0].value.clone())
}
XMLElement::Color => style = style.color(attributes[0].value.clone()),
XMLElement::Size => {
style = style.size(usize::from_str(&attributes[0].value)?)
}
XMLElement::Underline => {
style = style.underline(&attributes[0].value.clone())
}
XMLElement::Italic => {
if !read_bool(&attributes) {
continue;
}
style = style.italic();
}
XMLElement::Vanish => style = style.vanish(),
XMLElement::TableProperty => { XMLElement::TableProperty => {
if let Ok(p) = TableProperty::read(r, &attributes) { if let Ok(p) = TableProperty::read(r, &attributes) {
style = style.table_property(p); style = style.table_property(p);

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

View File

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