fix: bolf / italic (#245)

main
bokuweb 2021-03-16 17:41:36 +09:00 committed by GitHub
parent ef63278e1f
commit 93b9f9baca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 73 additions and 18 deletions

View File

@ -4,17 +4,24 @@ use crate::documents::BuildXML;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct Bold {} pub struct Bold {
val: bool,
}
impl Bold { impl Bold {
pub fn new() -> Bold { pub fn new() -> Bold {
Default::default() Default::default()
} }
pub fn disable(mut self) -> Bold {
self.val = false;
self
}
} }
impl Default for Bold { impl Default for Bold {
fn default() -> Self { fn default() -> Self {
Self {} Self { val: true }
} }
} }
@ -23,7 +30,7 @@ impl Serialize for Bold {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_bool(true) serializer.serialize_bool(self.val)
} }
} }

View File

@ -4,17 +4,23 @@ use crate::documents::BuildXML;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct BoldCs {} pub struct BoldCs {
val: bool,
}
impl BoldCs { impl BoldCs {
pub fn new() -> BoldCs { pub fn new() -> BoldCs {
Default::default() Default::default()
} }
pub fn disable(mut self) -> BoldCs {
self.val = false;
self
}
} }
impl Default for BoldCs { impl Default for BoldCs {
fn default() -> Self { fn default() -> Self {
Self {} Self { val: true }
} }
} }
@ -23,7 +29,7 @@ impl Serialize for BoldCs {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_bool(true) serializer.serialize_bool(self.val)
} }
} }

View File

@ -4,17 +4,24 @@ use crate::documents::BuildXML;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct Italic {} pub struct Italic {
val: bool,
}
impl Italic { impl Italic {
pub fn new() -> Italic { pub fn new() -> Italic {
Default::default() Default::default()
} }
pub fn disable(mut self) -> Self {
self.val = false;
self
}
} }
impl Default for Italic { impl Default for Italic {
fn default() -> Self { fn default() -> Self {
Self {} Self { val: true }
} }
} }
@ -23,7 +30,7 @@ impl Serialize for Italic {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_bool(true) serializer.serialize_bool(self.val)
} }
} }

View File

@ -4,17 +4,24 @@ use crate::documents::BuildXML;
use crate::xml_builder::*; use crate::xml_builder::*;
#[derive(Debug, Clone, Deserialize, PartialEq)] #[derive(Debug, Clone, Deserialize, PartialEq)]
pub struct ItalicCs {} pub struct ItalicCs {
val: bool,
}
impl ItalicCs { impl ItalicCs {
pub fn new() -> ItalicCs { pub fn new() -> ItalicCs {
Default::default() Default::default()
} }
pub fn disable(mut self) -> Self {
self.val = false;
self
}
} }
impl Default for ItalicCs { impl Default for ItalicCs {
fn default() -> Self { fn default() -> Self {
Self {} Self { val: true }
} }
} }
@ -23,7 +30,7 @@ impl Serialize for ItalicCs {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_bool(true) serializer.serialize_bool(self.val)
} }
} }

View File

@ -162,11 +162,21 @@ impl Run {
self self
} }
pub fn disable_bold(mut self) -> Run {
self.run_property = self.run_property.disable_bold();
self
}
pub fn italic(mut self) -> Run { pub fn italic(mut self) -> Run {
self.run_property = self.run_property.italic(); self.run_property = self.run_property.italic();
self self
} }
pub fn disable_italic(mut self) -> Run {
self.run_property = self.run_property.disable_italic();
self
}
pub fn underline(mut self, line_type: impl Into<String>) -> Run { pub fn underline(mut self, line_type: impl Into<String>) -> Run {
self.run_property = self.run_property.underline(line_type); self.run_property = self.run_property.underline(line_type);
self self

View File

@ -53,12 +53,24 @@ impl RunProperty {
self self
} }
pub fn disable_bold(mut self) -> RunProperty {
self.bold = Some(Bold::new().disable());
self.bold_cs = Some(BoldCs::new().disable());
self
}
pub fn italic(mut self) -> RunProperty { pub fn italic(mut self) -> RunProperty {
self.italic = Some(Italic::new()); self.italic = Some(Italic::new());
self.italic_cs = Some(ItalicCs::new()); self.italic_cs = Some(ItalicCs::new());
self self
} }
pub fn disable_italic(mut self) -> RunProperty {
self.italic = Some(Italic::new().disable());
self.italic_cs = Some(ItalicCs::new().disable());
self
}
pub fn underline(mut self, line_type: impl Into<String>) -> RunProperty { pub fn underline(mut self, line_type: impl Into<String>) -> RunProperty {
self.underline = Some(Underline::new(line_type)); self.underline = Some(Underline::new(line_type));
self self

View File

@ -44,6 +44,7 @@ impl ElementReader for Run {
// TODO: use RunProperty::read() // TODO: use RunProperty::read()
XMLElement::Bold => { XMLElement::Bold => {
if !read_bool(&attributes) { if !read_bool(&attributes) {
run = run.disable_bold();
continue; continue;
} }
run = run.bold(); run = run.bold();
@ -60,6 +61,7 @@ impl ElementReader for Run {
} }
XMLElement::Italic => { XMLElement::Italic => {
if !read_bool(&attributes) { if !read_bool(&attributes) {
run = run.disable_italic();
continue; continue;
} }
run = run.italic(); run = run.italic();
@ -221,6 +223,8 @@ mod tests {
run_property: RunProperty { run_property: RunProperty {
bold: Some(Bold::new()), bold: Some(Bold::new()),
bold_cs: Some(BoldCs::new()), bold_cs: Some(BoldCs::new()),
italic: Some(Italic::new().disable()),
italic_cs: Some(ItalicCs::new().disable()),
..RunProperty::default() ..RunProperty::default()
}, },
} }
@ -244,6 +248,8 @@ mod tests {
run_property: RunProperty { run_property: RunProperty {
bold: Some(Bold::new()), bold: Some(Bold::new()),
bold_cs: Some(BoldCs::new()), bold_cs: Some(BoldCs::new()),
italic: Some(Italic::new().disable()),
italic_cs: Some(ItalicCs::new().disable()),
..RunProperty::default() ..RunProperty::default()
}, },
} }

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