parent
16aa7cb3c6
commit
921b0f1057
|
@ -105,6 +105,7 @@ mod table_row;
|
|||
mod table_row_property;
|
||||
mod table_style;
|
||||
mod table_width;
|
||||
mod tabs;
|
||||
mod text;
|
||||
mod text_border;
|
||||
mod text_box;
|
||||
|
@ -227,6 +228,7 @@ pub use table_row::*;
|
|||
pub use table_row_property::*;
|
||||
pub use table_style::*;
|
||||
pub use table_width::*;
|
||||
pub use tabs::*;
|
||||
pub use text::*;
|
||||
pub use text_border::*;
|
||||
pub use text_box::*;
|
||||
|
|
|
@ -2,9 +2,9 @@ use serde::Serialize;
|
|||
|
||||
use super::*;
|
||||
use crate::documents::BuildXML;
|
||||
use crate::ParagraphBorderPosition;
|
||||
use crate::types::{AlignmentType, SpecialIndentType};
|
||||
use crate::xml_builder::*;
|
||||
use crate::ParagraphBorderPosition;
|
||||
|
||||
#[derive(Serialize, Debug, Clone, PartialEq, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
use crate::Tab;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||
pub struct Tabs {
|
||||
pub tabs: Vec<Tab>,
|
||||
}
|
||||
|
||||
impl Tabs {
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
pub fn add_tab(mut self, t: Tab) -> Self {
|
||||
self.tabs.push(t);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for Tabs {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let mut b = XMLBuilder::new();
|
||||
for t in self.tabs.iter() {
|
||||
b = b.tab(t.val, t.leader, t.pos);
|
||||
}
|
||||
b.build()
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ mod shape;
|
|||
mod structured_data_tag;
|
||||
mod style;
|
||||
mod styles;
|
||||
mod tab;
|
||||
mod table;
|
||||
mod table_borders;
|
||||
mod table_cell;
|
||||
|
@ -52,6 +53,7 @@ mod table_cell_margins;
|
|||
mod table_cell_property;
|
||||
mod table_property;
|
||||
mod table_row;
|
||||
mod tabs;
|
||||
mod text_box_content;
|
||||
mod theme;
|
||||
mod web_settings;
|
||||
|
|
|
@ -110,6 +110,13 @@ impl ElementReader for ParagraphProperty {
|
|||
p.section_property = Some(sp);
|
||||
}
|
||||
}
|
||||
XMLElement::Tabs => {
|
||||
if let Ok(tabs) = Tabs::read(r, &attributes) {
|
||||
for t in tabs.tabs {
|
||||
p = p.add_tab(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
|
||||
use xml::attribute::OwnedAttribute;
|
||||
use xml::reader::{EventReader, XmlEvent};
|
||||
|
||||
use crate::types::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn read_custom_tab_stop_type(attributes: &[OwnedAttribute]) -> Result<TabValueType, ReaderError> {
|
||||
for a in attributes {
|
||||
let local_name = &a.name.local_name;
|
||||
if local_name == "val" {
|
||||
let v = a.value.to_owned();
|
||||
if let Ok(t) = TabValueType::from_str(&v) {
|
||||
return Ok(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ReaderError::TypeError(crate::TypeError::FromStrError))
|
||||
}
|
||||
|
||||
fn read_custom_tab_stop_leader(
|
||||
attributes: &[OwnedAttribute],
|
||||
) -> Result<TabLeaderType, ReaderError> {
|
||||
for a in attributes {
|
||||
let local_name = &a.name.local_name;
|
||||
if local_name == "leader" {
|
||||
let v = a.value.to_owned();
|
||||
if let Ok(t) = TabLeaderType::from_str(&v) {
|
||||
return Ok(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ReaderError::TypeError(crate::TypeError::FromStrError))
|
||||
}
|
||||
|
||||
fn read_custom_tab_stop_pos(attributes: &[OwnedAttribute]) -> Result<f32, ReaderError> {
|
||||
for a in attributes {
|
||||
let local_name = &a.name.local_name;
|
||||
if local_name == "pos" {
|
||||
let v = a.value.to_owned();
|
||||
if let Ok(t) = f32::from_str(&v) {
|
||||
return Ok(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(ReaderError::TypeError(crate::TypeError::FromStrError))
|
||||
}
|
||||
|
||||
impl ElementReader for Tab {
|
||||
fn read<R: Read>(
|
||||
r: &mut EventReader<R>,
|
||||
attrs: &[OwnedAttribute],
|
||||
) -> Result<Self, ReaderError> {
|
||||
let mut tab = Tab::new();
|
||||
if let Ok(t) = read_custom_tab_stop_type(attrs) {
|
||||
tab = tab.val(t);
|
||||
}
|
||||
if let Ok(pos) = read_custom_tab_stop_pos(attrs) {
|
||||
tab = tab.pos(pos as usize);
|
||||
}
|
||||
if let Ok(leader) = read_custom_tab_stop_leader(attrs) {
|
||||
tab = tab.leader(leader);
|
||||
}
|
||||
loop {
|
||||
let e = r.next();
|
||||
match e {
|
||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||
if e == XMLElement::Tab {
|
||||
return Ok(tab);
|
||||
}
|
||||
}
|
||||
Err(_) => return Err(ReaderError::XMLReadError),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
|
||||
use xml::attribute::OwnedAttribute;
|
||||
use xml::reader::{EventReader, XmlEvent};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ElementReader for Tabs {
|
||||
fn read<R: Read>(
|
||||
r: &mut EventReader<R>,
|
||||
_attrs: &[OwnedAttribute],
|
||||
) -> Result<Self, ReaderError> {
|
||||
let mut tabs = Tabs::new();
|
||||
loop {
|
||||
let e = r.next();
|
||||
match e {
|
||||
Ok(XmlEvent::StartElement {
|
||||
attributes, name, ..
|
||||
}) => {
|
||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||
if e == XMLElement::Tab {
|
||||
if let Ok(t) = Tab::read(r, &attributes) {
|
||||
tabs = tabs.add_tab(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||
if e == XMLElement::Tabs {
|
||||
return Ok(tabs);
|
||||
}
|
||||
}
|
||||
Err(_) => return Err(ReaderError::XMLReadError),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ pub enum XMLElement {
|
|||
BoldCs,
|
||||
Break,
|
||||
Tab,
|
||||
Tabs,
|
||||
Sym,
|
||||
ParagraphStyle,
|
||||
ParagraphPropertyChange,
|
||||
|
@ -268,6 +269,7 @@ impl FromStr for XMLElement {
|
|||
"italic" => Ok(XMLElement::Italic),
|
||||
"name" => Ok(XMLElement::Name),
|
||||
"tab" => Ok(XMLElement::Tab),
|
||||
"tabs" => Ok(XMLElement::Tabs),
|
||||
"br" => Ok(XMLElement::Break),
|
||||
"ind" => Ok(XMLElement::Indent),
|
||||
"numPr" => Ok(XMLElement::NumberingProperty),
|
||||
|
|
|
@ -2,6 +2,7 @@ pub mod alignment_type;
|
|||
pub mod border_position;
|
||||
pub mod border_type;
|
||||
pub mod break_type;
|
||||
pub mod character_spacing_values;
|
||||
pub mod doc_grid_type;
|
||||
pub mod drawing_position;
|
||||
pub mod emu;
|
||||
|
@ -28,12 +29,12 @@ pub mod vert_align_type;
|
|||
pub mod vertical_align_type;
|
||||
pub mod vertical_merge_type;
|
||||
pub mod width_type;
|
||||
pub mod character_spacing_values;
|
||||
|
||||
pub use alignment_type::*;
|
||||
pub use border_position::*;
|
||||
pub use border_type::*;
|
||||
pub use break_type::*;
|
||||
pub use character_spacing_values::*;
|
||||
pub use doc_grid_type::*;
|
||||
pub use drawing_position::*;
|
||||
pub use emu::*;
|
||||
|
@ -60,4 +61,3 @@ pub use vert_align_type::*;
|
|||
pub use vertical_align_type::*;
|
||||
pub use vertical_merge_type::*;
|
||||
pub use width_type::*;
|
||||
pub use character_spacing_values::*;
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -26,6 +26,23 @@ export type HyperlinkChildJSON =
|
|||
| BookmarkStartJSON
|
||||
| BookmarkEndJSON;
|
||||
|
||||
export type CustomTabStopType =
|
||||
| "bar"
|
||||
| "center"
|
||||
| "clear"
|
||||
| "decimal"
|
||||
| "end"
|
||||
| "right"
|
||||
| "num"
|
||||
| "start"
|
||||
| "left";
|
||||
|
||||
export type CustomTabStopJSON = {
|
||||
val: CustomTabStopType | null;
|
||||
leader: string | null;
|
||||
pos: number | null;
|
||||
};
|
||||
|
||||
export type NumberingPropertyJSON = {
|
||||
id: number | null;
|
||||
level: number | null;
|
||||
|
@ -58,6 +75,7 @@ export type ParagraphPropertyJSON = {
|
|||
property: ParagraphPropertyJSON;
|
||||
};
|
||||
sectionProperty?: SectionPropertyJSON;
|
||||
tabs: CustomTabStopJSON[];
|
||||
};
|
||||
|
||||
export type ParagraphJSON = {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue