fix: bolf / italic (#245)
parent
ef63278e1f
commit
93b9f9baca
|
@ -4,17 +4,24 @@ use crate::documents::BuildXML;
|
|||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct Bold {}
|
||||
pub struct Bold {
|
||||
val: bool,
|
||||
}
|
||||
|
||||
impl Bold {
|
||||
pub fn new() -> Bold {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn disable(mut self) -> Bold {
|
||||
self.val = false;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Bold {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { val: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +30,7 @@ impl Serialize for Bold {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_bool(true)
|
||||
serializer.serialize_bool(self.val)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,23 @@ use crate::documents::BuildXML;
|
|||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct BoldCs {}
|
||||
pub struct BoldCs {
|
||||
val: bool,
|
||||
}
|
||||
|
||||
impl BoldCs {
|
||||
pub fn new() -> BoldCs {
|
||||
Default::default()
|
||||
}
|
||||
pub fn disable(mut self) -> BoldCs {
|
||||
self.val = false;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BoldCs {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { val: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +29,7 @@ impl Serialize for BoldCs {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_bool(true)
|
||||
serializer.serialize_bool(self.val)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,24 @@ use crate::documents::BuildXML;
|
|||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct Italic {}
|
||||
pub struct Italic {
|
||||
val: bool,
|
||||
}
|
||||
|
||||
impl Italic {
|
||||
pub fn new() -> Italic {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn disable(mut self) -> Self {
|
||||
self.val = false;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Italic {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { val: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +30,7 @@ impl Serialize for Italic {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_bool(true)
|
||||
serializer.serialize_bool(self.val)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,24 @@ use crate::documents::BuildXML;
|
|||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
pub struct ItalicCs {}
|
||||
pub struct ItalicCs {
|
||||
val: bool,
|
||||
}
|
||||
|
||||
impl ItalicCs {
|
||||
pub fn new() -> ItalicCs {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn disable(mut self) -> Self {
|
||||
self.val = false;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ItalicCs {
|
||||
fn default() -> Self {
|
||||
Self {}
|
||||
Self { val: true }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +30,7 @@ impl Serialize for ItalicCs {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_bool(true)
|
||||
serializer.serialize_bool(self.val)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,11 +162,21 @@ impl Run {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn disable_bold(mut self) -> Run {
|
||||
self.run_property = self.run_property.disable_bold();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn italic(mut self) -> Run {
|
||||
self.run_property = self.run_property.italic();
|
||||
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 {
|
||||
self.run_property = self.run_property.underline(line_type);
|
||||
self
|
||||
|
|
|
@ -53,12 +53,24 @@ impl RunProperty {
|
|||
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 {
|
||||
self.italic = Some(Italic::new());
|
||||
self.italic_cs = Some(ItalicCs::new());
|
||||
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 {
|
||||
self.underline = Some(Underline::new(line_type));
|
||||
self
|
||||
|
|
|
@ -44,6 +44,7 @@ impl ElementReader for Run {
|
|||
// TODO: use RunProperty::read()
|
||||
XMLElement::Bold => {
|
||||
if !read_bool(&attributes) {
|
||||
run = run.disable_bold();
|
||||
continue;
|
||||
}
|
||||
run = run.bold();
|
||||
|
@ -60,6 +61,7 @@ impl ElementReader for Run {
|
|||
}
|
||||
XMLElement::Italic => {
|
||||
if !read_bool(&attributes) {
|
||||
run = run.disable_italic();
|
||||
continue;
|
||||
}
|
||||
run = run.italic();
|
||||
|
@ -221,6 +223,8 @@ mod tests {
|
|||
run_property: RunProperty {
|
||||
bold: Some(Bold::new()),
|
||||
bold_cs: Some(BoldCs::new()),
|
||||
italic: Some(Italic::new().disable()),
|
||||
italic_cs: Some(ItalicCs::new().disable()),
|
||||
..RunProperty::default()
|
||||
},
|
||||
}
|
||||
|
@ -244,6 +248,8 @@ mod tests {
|
|||
run_property: RunProperty {
|
||||
bold: Some(Bold::new()),
|
||||
bold_cs: Some(BoldCs::new()),
|
||||
italic: Some(Italic::new().disable()),
|
||||
italic_cs: Some(ItalicCs::new().disable()),
|
||||
..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
Loading…
Reference in New Issue