feat: Support sym (#625)
parent
fbbca22783
commit
160fac91b7
|
@ -82,6 +82,7 @@ mod strike;
|
||||||
mod structured_data_tag;
|
mod structured_data_tag;
|
||||||
mod structured_data_tag_property;
|
mod structured_data_tag_property;
|
||||||
mod style;
|
mod style;
|
||||||
|
mod sym;
|
||||||
mod sz;
|
mod sz;
|
||||||
mod sz_cs;
|
mod sz_cs;
|
||||||
mod tab;
|
mod tab;
|
||||||
|
@ -201,6 +202,7 @@ pub use strike::*;
|
||||||
pub use structured_data_tag::*;
|
pub use structured_data_tag::*;
|
||||||
pub use structured_data_tag_property::*;
|
pub use structured_data_tag_property::*;
|
||||||
pub use style::*;
|
pub use style::*;
|
||||||
|
pub use sym::*;
|
||||||
pub use sz::*;
|
pub use sz::*;
|
||||||
pub use sz_cs::*;
|
pub use sz_cs::*;
|
||||||
pub use tab::*;
|
pub use tab::*;
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl Default for Run {
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum RunChild {
|
pub enum RunChild {
|
||||||
Text(Text),
|
Text(Text),
|
||||||
|
Sym(Sym),
|
||||||
DeleteText(DeleteText),
|
DeleteText(DeleteText),
|
||||||
Tab(Tab),
|
Tab(Tab),
|
||||||
Break(Break),
|
Break(Break),
|
||||||
|
@ -52,6 +53,12 @@ impl Serialize for RunChild {
|
||||||
t.serialize_field("data", s)?;
|
t.serialize_field("data", s)?;
|
||||||
t.end()
|
t.end()
|
||||||
}
|
}
|
||||||
|
RunChild::Sym(ref s) => {
|
||||||
|
let mut t = serializer.serialize_struct("Sym", 2)?;
|
||||||
|
t.serialize_field("type", "sym")?;
|
||||||
|
t.serialize_field("data", s)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
RunChild::DeleteText(ref s) => {
|
RunChild::DeleteText(ref s) => {
|
||||||
let mut t = serializer.serialize_struct("DeleteText", 2)?;
|
let mut t = serializer.serialize_struct("DeleteText", 2)?;
|
||||||
t.serialize_field("type", "deleteText")?;
|
t.serialize_field("type", "deleteText")?;
|
||||||
|
@ -202,6 +209,11 @@ impl Run {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_sym(mut self, sym: Sym) -> Run {
|
||||||
|
self.children.push(RunChild::Sym(sym));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn style(mut self, style_id: &str) -> Self {
|
pub fn style(mut self, style_id: &str) -> Self {
|
||||||
self.run_property = self.run_property.style(style_id);
|
self.run_property = self.run_property.style(style_id);
|
||||||
self
|
self
|
||||||
|
@ -280,6 +292,7 @@ impl BuildXML for Run {
|
||||||
for c in &self.children {
|
for c in &self.children {
|
||||||
match c {
|
match c {
|
||||||
RunChild::Text(t) => b = b.add_child(t),
|
RunChild::Text(t) => b = b.add_child(t),
|
||||||
|
RunChild::Sym(t) => b = b.add_child(t),
|
||||||
RunChild::DeleteText(t) => b = b.add_child(t),
|
RunChild::DeleteText(t) => b = b.add_child(t),
|
||||||
RunChild::Tab(t) => b = b.add_child(t),
|
RunChild::Tab(t) => b = b.add_child(t),
|
||||||
RunChild::Break(t) => b = b.add_child(t),
|
RunChild::Break(t) => b = b.add_child(t),
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::documents::BuildXML;
|
||||||
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Sym {
|
||||||
|
pub font: String,
|
||||||
|
pub char: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sym {
|
||||||
|
pub fn new(font: impl Into<String>, char: impl Into<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
font: font.into(),
|
||||||
|
char: char.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl BuildXML for Sym {
|
||||||
|
fn build(&self) -> Vec<u8> {
|
||||||
|
let b = XMLBuilder::new();
|
||||||
|
b.sym(&self.font, &self.char).build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for Sym {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let mut t = serializer.serialize_struct("Sym", 1)?;
|
||||||
|
t.serialize_field("font", &self.font)?;
|
||||||
|
t.serialize_field("char", &self.char)?;
|
||||||
|
t.end()
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,6 +71,14 @@ impl ElementReader for Run {
|
||||||
XMLElement::Tab => {
|
XMLElement::Tab => {
|
||||||
run = run.add_tab();
|
run = run.add_tab();
|
||||||
}
|
}
|
||||||
|
XMLElement::Sym => {
|
||||||
|
if let Some(font) = read(&attributes, "font") {
|
||||||
|
if let Some(char) = read(&attributes, "char") {
|
||||||
|
let sym = Sym::new(font, char);
|
||||||
|
run = run.add_sym(sym);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
XMLElement::RunProperty => {
|
XMLElement::RunProperty => {
|
||||||
let p = RunProperty::read(r, &attributes)?;
|
let p = RunProperty::read(r, &attributes)?;
|
||||||
run = run.set_property(p);
|
run = run.set_property(p);
|
||||||
|
|
|
@ -35,6 +35,7 @@ pub enum XMLElement {
|
||||||
BoldCs,
|
BoldCs,
|
||||||
Break,
|
Break,
|
||||||
Tab,
|
Tab,
|
||||||
|
Sym,
|
||||||
ParagraphStyle,
|
ParagraphStyle,
|
||||||
ParagraphPropertyChange,
|
ParagraphPropertyChange,
|
||||||
RunPropertyChange,
|
RunPropertyChange,
|
||||||
|
@ -370,6 +371,7 @@ impl FromStr for XMLElement {
|
||||||
"marRight" => Ok(XMLElement::MarginRight),
|
"marRight" => Ok(XMLElement::MarginRight),
|
||||||
"marTop" => Ok(XMLElement::MarginTop),
|
"marTop" => Ok(XMLElement::MarginTop),
|
||||||
"marBottom" => Ok(XMLElement::MarginBottom),
|
"marBottom" => Ok(XMLElement::MarginBottom),
|
||||||
|
"sym" => Ok(XMLElement::Sym),
|
||||||
"webSettings" => Ok(XMLElement::WebSettings),
|
"webSettings" => Ok(XMLElement::WebSettings),
|
||||||
"keepNext" => Ok(XMLElement::KeepNext),
|
"keepNext" => Ok(XMLElement::KeepNext),
|
||||||
"keepLines" => Ok(XMLElement::KeepLines),
|
"keepLines" => Ok(XMLElement::KeepLines),
|
||||||
|
|
|
@ -342,6 +342,7 @@ impl XMLBuilder {
|
||||||
closed!(tab_with_pos, "w:tab", "w:val", "w:pos");
|
closed!(tab_with_pos, "w:tab", "w:val", "w:pos");
|
||||||
|
|
||||||
closed!(br, "w:br", "w:type");
|
closed!(br, "w:br", "w:type");
|
||||||
|
closed!(sym, "w:sym", "w:font", "w:char");
|
||||||
closed!(zoom, "w:zoom", "w:percent");
|
closed!(zoom, "w:zoom", "w:percent");
|
||||||
closed_with_usize!(default_tab_stop, "w:defaultTabStop");
|
closed_with_usize!(default_tab_stop, "w:defaultTabStop");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue