2020-02-11 10:01:39 +02:00
|
|
|
use std::io::Read;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
use xml::attribute::OwnedAttribute;
|
|
|
|
use xml::reader::EventReader;
|
|
|
|
|
|
|
|
use crate::reader::ReaderError;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum XMLElement {
|
|
|
|
Body,
|
|
|
|
Paragraph,
|
|
|
|
Run,
|
|
|
|
RunProperty,
|
|
|
|
Color,
|
|
|
|
Underline,
|
|
|
|
Size,
|
|
|
|
SizeCs,
|
|
|
|
Vanish,
|
|
|
|
Italic,
|
|
|
|
ItalicCs,
|
|
|
|
Text,
|
|
|
|
Highlight,
|
|
|
|
Bold,
|
|
|
|
BoldCs,
|
|
|
|
Break,
|
|
|
|
Tab,
|
|
|
|
ParagraphStyle,
|
|
|
|
Indent,
|
2020-02-12 08:44:53 +02:00
|
|
|
Name,
|
2020-02-11 10:01:39 +02:00
|
|
|
Alignment,
|
|
|
|
NumberingProperty,
|
|
|
|
IndentLevel,
|
|
|
|
NumberingId,
|
|
|
|
Justification,
|
|
|
|
Insert,
|
|
|
|
Delete,
|
|
|
|
DeleteText,
|
|
|
|
BookmarkStart,
|
|
|
|
BookmarkEnd,
|
|
|
|
CommentRangeStart,
|
|
|
|
CommentRangeEnd,
|
2020-03-19 18:19:39 +02:00
|
|
|
VAlign,
|
2020-02-11 10:01:39 +02:00
|
|
|
Table,
|
|
|
|
TableProperty,
|
|
|
|
TableRow,
|
|
|
|
TableCell,
|
|
|
|
TableCellProperty,
|
|
|
|
TableCellWidth,
|
|
|
|
TableCellBorders,
|
|
|
|
TableVMerge,
|
|
|
|
TableGridSpan,
|
|
|
|
TableWidth,
|
|
|
|
TableIndent,
|
|
|
|
TableBorders,
|
|
|
|
Top,
|
|
|
|
Left,
|
|
|
|
Bottom,
|
|
|
|
InsideH,
|
|
|
|
TableCellMargin,
|
|
|
|
TableGrid,
|
|
|
|
GridCol,
|
2020-02-12 08:44:53 +02:00
|
|
|
Style,
|
|
|
|
BasedOn,
|
|
|
|
Next,
|
|
|
|
VertAlign,
|
|
|
|
Spacing,
|
|
|
|
Styles,
|
2020-02-12 09:03:11 +02:00
|
|
|
Relationship,
|
|
|
|
Relationships,
|
2020-02-12 12:19:38 +02:00
|
|
|
AbstractNumbering,
|
|
|
|
AbstractNumberingId,
|
2020-04-21 13:02:36 +03:00
|
|
|
LvlOverride,
|
|
|
|
StartOverride,
|
2020-02-12 12:19:38 +02:00
|
|
|
Level,
|
|
|
|
Numbering,
|
|
|
|
Num,
|
|
|
|
Start,
|
|
|
|
NumberFormat,
|
|
|
|
LevelText,
|
|
|
|
LevelJustification,
|
2020-02-26 13:26:32 +02:00
|
|
|
StyleLink,
|
|
|
|
NumStyleLink,
|
2020-04-07 04:24:56 +03:00
|
|
|
Drawing,
|
|
|
|
TxbxContent,
|
|
|
|
Pict,
|
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum McXMLElement {
|
|
|
|
AlternateContent,
|
|
|
|
Choice,
|
|
|
|
Fallback,
|
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum WpXMLElement {
|
|
|
|
Anchor,
|
|
|
|
SimplePos,
|
|
|
|
PositionH,
|
|
|
|
PosOffset,
|
|
|
|
PositionV,
|
|
|
|
Extent,
|
|
|
|
EffectExtent,
|
|
|
|
WrapNone,
|
|
|
|
DocProperty,
|
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum AXMLElement {
|
|
|
|
Graphic,
|
|
|
|
GraphicData,
|
|
|
|
Xfrm,
|
|
|
|
Off,
|
|
|
|
Ext,
|
|
|
|
PrstGeom,
|
|
|
|
SolidFill,
|
|
|
|
Ln,
|
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum WpsXMLElement {
|
|
|
|
Wsp,
|
|
|
|
CNvSpProperty,
|
|
|
|
SpProperty,
|
|
|
|
Style,
|
|
|
|
Txbx,
|
|
|
|
BodyPr,
|
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
pub enum VXMLElement {
|
|
|
|
Rect,
|
|
|
|
Stroke,
|
|
|
|
Fill,
|
|
|
|
TextBox,
|
2020-02-11 10:01:39 +02:00
|
|
|
Unsupported,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for XMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"body" => Ok(XMLElement::Body),
|
|
|
|
"p" => Ok(XMLElement::Paragraph),
|
|
|
|
"r" => Ok(XMLElement::Run),
|
|
|
|
"rPr" => Ok(XMLElement::RunProperty),
|
|
|
|
"color" => Ok(XMLElement::Color),
|
|
|
|
"t" => Ok(XMLElement::Text),
|
|
|
|
"sz" => Ok(XMLElement::Size),
|
|
|
|
"szCs" => Ok(XMLElement::SizeCs),
|
|
|
|
"u" => Ok(XMLElement::Underline),
|
|
|
|
"pStyle" => Ok(XMLElement::ParagraphStyle),
|
|
|
|
"highlight" => Ok(XMLElement::Highlight),
|
|
|
|
"b" => Ok(XMLElement::Bold),
|
|
|
|
"bCs" => Ok(XMLElement::BoldCs),
|
|
|
|
"i" => Ok(XMLElement::Italic),
|
|
|
|
"iCs" => Ok(XMLElement::ItalicCs),
|
|
|
|
"vanish" => Ok(XMLElement::Vanish),
|
|
|
|
"italic" => Ok(XMLElement::Italic),
|
2020-02-12 08:44:53 +02:00
|
|
|
"name" => Ok(XMLElement::Name),
|
2020-02-11 10:01:39 +02:00
|
|
|
"tab" => Ok(XMLElement::Tab),
|
|
|
|
"br" => Ok(XMLElement::Break),
|
|
|
|
"ind" => Ok(XMLElement::Indent),
|
|
|
|
"numPr" => Ok(XMLElement::NumberingProperty),
|
|
|
|
"ilvl" => Ok(XMLElement::IndentLevel),
|
|
|
|
"numId" => Ok(XMLElement::NumberingId),
|
|
|
|
"jc" => Ok(XMLElement::Justification),
|
|
|
|
"ins" => Ok(XMLElement::Insert),
|
|
|
|
"del" => Ok(XMLElement::Delete),
|
|
|
|
"delText" => Ok(XMLElement::DeleteText),
|
|
|
|
"bookmarkStart" => Ok(XMLElement::BookmarkStart),
|
|
|
|
"bookmarkEnd" => Ok(XMLElement::BookmarkEnd),
|
|
|
|
"commentRangeStart" => Ok(XMLElement::CommentRangeStart),
|
|
|
|
"commentRangeEnd" => Ok(XMLElement::CommentRangeEnd),
|
|
|
|
"tbl" => Ok(XMLElement::Table),
|
|
|
|
"tblPr" => Ok(XMLElement::TableProperty),
|
|
|
|
"tr" => Ok(XMLElement::TableRow),
|
|
|
|
"tc" => Ok(XMLElement::TableCell),
|
|
|
|
"tcPr" => Ok(XMLElement::TableCellProperty),
|
|
|
|
"tcW" => Ok(XMLElement::TableCellWidth),
|
|
|
|
"tcBorders" => Ok(XMLElement::TableCellBorders),
|
|
|
|
"vMerge" => Ok(XMLElement::TableVMerge),
|
|
|
|
"gridSpan" => Ok(XMLElement::TableGridSpan),
|
|
|
|
"tblW" => Ok(XMLElement::TableWidth),
|
|
|
|
"tblInd" => Ok(XMLElement::TableIndent),
|
|
|
|
"tblBorders" => Ok(XMLElement::TableBorders),
|
|
|
|
"top" => Ok(XMLElement::Top),
|
|
|
|
"left" => Ok(XMLElement::Left),
|
|
|
|
"bottom" => Ok(XMLElement::Bottom),
|
|
|
|
"insideH" => Ok(XMLElement::InsideH),
|
|
|
|
"tblCellMar" => Ok(XMLElement::TableCellMargin),
|
|
|
|
"tblGrid" => Ok(XMLElement::TableGrid),
|
|
|
|
"gridCol" => Ok(XMLElement::GridCol),
|
2020-02-12 08:44:53 +02:00
|
|
|
"style" => Ok(XMLElement::Style),
|
|
|
|
"basedOn" => Ok(XMLElement::BasedOn),
|
|
|
|
"next" => Ok(XMLElement::Next),
|
|
|
|
"vertAlign" => Ok(XMLElement::VertAlign),
|
|
|
|
"spacing" => Ok(XMLElement::Spacing),
|
|
|
|
"styles" => Ok(XMLElement::Styles),
|
2020-02-12 09:03:11 +02:00
|
|
|
"Relationships" => Ok(XMLElement::Relationships),
|
|
|
|
"Relationship" => Ok(XMLElement::Relationship),
|
2020-02-12 12:19:38 +02:00
|
|
|
"abstractNum" => Ok(XMLElement::AbstractNumbering),
|
|
|
|
"abstractNumId" => Ok(XMLElement::AbstractNumberingId),
|
|
|
|
"lvl" => Ok(XMLElement::Level),
|
|
|
|
"numbering" => Ok(XMLElement::Numbering),
|
|
|
|
"num" => Ok(XMLElement::Num),
|
|
|
|
"start" => Ok(XMLElement::Start),
|
|
|
|
"numFmt" => Ok(XMLElement::NumberFormat),
|
|
|
|
"lvlText" => Ok(XMLElement::LevelText),
|
|
|
|
"lvlJc" => Ok(XMLElement::LevelJustification),
|
2020-02-26 13:26:32 +02:00
|
|
|
"numStyleLink" => Ok(XMLElement::NumStyleLink),
|
|
|
|
"styleLink" => Ok(XMLElement::StyleLink),
|
2020-03-19 18:19:39 +02:00
|
|
|
"vAlign" => Ok(XMLElement::VAlign),
|
2020-04-07 04:24:56 +03:00
|
|
|
"drawing" => Ok(XMLElement::Drawing),
|
|
|
|
"txbxContent" => Ok(XMLElement::TxbxContent),
|
|
|
|
"pict" => Ok(XMLElement::Pict),
|
2020-04-21 13:02:36 +03:00
|
|
|
"lvlOverride" => Ok(XMLElement::LvlOverride),
|
|
|
|
"startOverride" => Ok(XMLElement::StartOverride),
|
2020-02-11 10:01:39 +02:00
|
|
|
_ => Ok(XMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 04:24:56 +03:00
|
|
|
impl FromStr for McXMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
2020-04-07 04:55:44 +03:00
|
|
|
"AlternateContent" => Ok(McXMLElement::AlternateContent),
|
|
|
|
"Choice" => Ok(McXMLElement::Choice),
|
|
|
|
"Fallback" => Ok(McXMLElement::Fallback),
|
2020-04-07 04:24:56 +03:00
|
|
|
_ => Ok(McXMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for WpXMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"anchor" => Ok(WpXMLElement::Anchor),
|
|
|
|
"simplePos" => Ok(WpXMLElement::SimplePos),
|
|
|
|
"positionH" => Ok(WpXMLElement::PositionH),
|
|
|
|
"posOffset" => Ok(WpXMLElement::PosOffset),
|
|
|
|
"positionV" => Ok(WpXMLElement::PositionV),
|
|
|
|
"extent" => Ok(WpXMLElement::Extent),
|
|
|
|
"effectExtent" => Ok(WpXMLElement::EffectExtent),
|
|
|
|
"wrapNone" => Ok(WpXMLElement::WrapNone),
|
|
|
|
"docPr" => Ok(WpXMLElement::DocProperty),
|
|
|
|
_ => Ok(WpXMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for AXMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"graphic" => Ok(AXMLElement::Graphic),
|
|
|
|
"graphicData" => Ok(AXMLElement::GraphicData),
|
|
|
|
"xfrm" => Ok(AXMLElement::Xfrm),
|
|
|
|
"off" => Ok(AXMLElement::Off),
|
|
|
|
"ext" => Ok(AXMLElement::Ext),
|
|
|
|
"prstGeom" => Ok(AXMLElement::PrstGeom),
|
|
|
|
"solidFill" => Ok(AXMLElement::SolidFill),
|
|
|
|
"ln" => Ok(AXMLElement::Ln),
|
|
|
|
_ => Ok(AXMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for WpsXMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"wsp" => Ok(WpsXMLElement::Wsp),
|
|
|
|
"cNvSpPr" => Ok(WpsXMLElement::CNvSpProperty),
|
|
|
|
"spPr" => Ok(WpsXMLElement::SpProperty),
|
|
|
|
"style" => Ok(WpsXMLElement::Style),
|
|
|
|
"txbx" => Ok(WpsXMLElement::Txbx),
|
|
|
|
"bodyPr" => Ok(WpsXMLElement::BodyPr),
|
|
|
|
_ => Ok(WpsXMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for VXMLElement {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
match s {
|
|
|
|
"rect" => Ok(VXMLElement::Rect),
|
|
|
|
"stroke" => Ok(VXMLElement::Stroke),
|
|
|
|
"fill" => Ok(VXMLElement::Fill),
|
|
|
|
"textbox" => Ok(VXMLElement::TextBox),
|
|
|
|
_ => Ok(VXMLElement::Unsupported),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-11 10:01:39 +02:00
|
|
|
pub trait ElementReader {
|
|
|
|
fn read<R: Read>(r: &mut EventReader<R>, attrs: &[OwnedAttribute]) -> Result<Self, ReaderError>
|
|
|
|
where
|
|
|
|
Self: std::marker::Sized;
|
|
|
|
}
|