From 6b45f31eeafdbcacb03a9bb7e5af3e022b5126a7 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Mon, 5 Oct 2020 16:19:05 +0900 Subject: [PATCH] fix: style run props bool value (#153) --- docx-core/examples/reader.rs | 12 +++++++++--- docx-core/src/reader/style.rs | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docx-core/examples/reader.rs b/docx-core/examples/reader.rs index d7e5a14..30f40af 100644 --- a/docx-core/examples/reader.rs +++ b/docx-core/examples/reader.rs @@ -1,10 +1,16 @@ use docx_rs::*; -use std::fs::*; -use std::io::Read; + +use std::fs::File; +use std::io::{Read, Write}; pub fn main() { - let mut file = File::open("./from_doc.docx").unwrap(); + let mut file = File::open("./style_test.docx").unwrap(); let mut buf = vec![]; file.read_to_end(&mut buf).unwrap(); dbg!(read_docx(&buf).unwrap().json()); + + let mut file = File::create("./test.json").unwrap(); + let res = read_docx(&buf).unwrap().json(); + file.write_all(res.as_bytes()).unwrap(); + file.flush().unwrap(); } diff --git a/docx-core/src/reader/style.rs b/docx-core/src/reader/style.rs index 401e3a7..00fafda 100644 --- a/docx-core/src/reader/style.rs +++ b/docx-core/src/reader/style.rs @@ -47,7 +47,12 @@ impl ElementReader for Style { continue; } // rPr - XMLElement::Bold => style = style.bold(), + XMLElement::Bold => { + if !read_bool(&attributes) { + continue; + } + style = style.bold(); + } XMLElement::Highlight => { style = style.highlight(attributes[0].value.clone()) } @@ -58,7 +63,12 @@ impl ElementReader for Style { XMLElement::Underline => { style = style.underline(&attributes[0].value.clone()) } - XMLElement::Italic => style = style.italic(), + XMLElement::Italic => { + if !read_bool(&attributes) { + continue; + } + style = style.italic(); + } XMLElement::Vanish => style = style.vanish(), _ => {} }