docx_reader/documents/elements/
table_cell.rsuse serde::ser::{SerializeStruct, Serializer};
use serde::Serialize;
use super::*;
use crate::types::*;
#[derive(Serialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct TableCell {
pub children: Vec<TableCellContent>,
pub property: TableCellProperty,
pub has_numbering: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TableCellContent {
Paragraph(Paragraph),
Table(Table),
StructuredDataTag(Box<StructuredDataTag>),
TableOfContents(Box<TableOfContents>),
}
impl Serialize for TableCellContent {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match *self {
TableCellContent::Paragraph(ref s) => {
let mut t = serializer.serialize_struct("Paragraph", 2)?;
t.serialize_field("type", "paragraph")?;
t.serialize_field("data", s)?;
t.end()
}
TableCellContent::Table(ref s) => {
let mut t = serializer.serialize_struct("Table", 2)?;
t.serialize_field("type", "table")?;
t.serialize_field("data", s)?;
t.end()
}
TableCellContent::StructuredDataTag(ref r) => {
let mut t = serializer.serialize_struct("StructuredDataTag", 2)?;
t.serialize_field("type", "structuredDataTag")?;
t.serialize_field("data", r)?;
t.end()
}
TableCellContent::TableOfContents(ref r) => {
let mut t = serializer.serialize_struct("TableOfContents", 2)?;
t.serialize_field("type", "tableOfContents")?;
t.serialize_field("data", r)?;
t.end()
}
}
}
}
impl TableCell {
pub fn new() -> TableCell {
Default::default()
}
pub fn add_paragraph(mut self, p: Paragraph) -> TableCell {
if p.has_numbering {
self.has_numbering = true
}
self.children.push(TableCellContent::Paragraph(p));
self
}
pub fn add_table_of_contents(mut self, t: TableOfContents) -> Self {
self.children
.push(TableCellContent::TableOfContents(Box::new(t)));
self
}
pub fn add_structured_data_tag(mut self, t: StructuredDataTag) -> Self {
self.children
.push(TableCellContent::StructuredDataTag(Box::new(t)));
self
}
pub fn add_table(mut self, t: Table) -> TableCell {
if t.has_numbering {
self.has_numbering = true
}
self.children.push(TableCellContent::Table(t));
self
}
pub fn vertical_merge(mut self, t: VMergeType) -> TableCell {
self.property = self.property.vertical_merge(t);
self
}
pub fn shading(mut self, s: Shading) -> TableCell {
self.property = self.property.shading(s);
self
}
pub fn vertical_align(mut self, t: VAlignType) -> TableCell {
self.property = self.property.vertical_align(t);
self
}
pub fn text_direction(mut self, t: TextDirectionType) -> TableCell {
self.property = self.property.text_direction(t);
self
}
pub fn grid_span(mut self, v: usize) -> TableCell {
self.property = self.property.grid_span(v);
self
}
pub fn width(mut self, v: usize, t: WidthType) -> TableCell {
self.property = self.property.width(v, t);
self
}
pub fn set_border(mut self, border: TableCellBorder) -> Self {
self.property = self.property.set_border(border);
self
}
pub fn set_borders(mut self, borders: TableCellBorders) -> Self {
self.property = self.property.set_borders(borders);
self
}
pub fn clear_border(mut self, position: TableCellBorderPosition) -> Self {
self.property = self.property.clear_border(position);
self
}
pub fn clear_all_border(mut self) -> Self {
self.property = self.property.clear_all_border();
self
}
}
impl Default for TableCell {
fn default() -> Self {
let property = TableCellProperty::new();
let children = vec![];
Self {
property,
children,
has_numbering: false,
}
}
}