use crate::model::MathNode;
pub type Rgb = [u8; 3];
#[derive(Debug, Default, Clone)]
pub struct FDoc {
pub sections: Vec<Section>,
pub parts: Vec<Vec<Block>>,
pub footnotes: Vec<(String, Vec<Block>)>,
pub footnote_separator: Option<Vec<Block>>,
pub footnote_notice: Option<Vec<Block>>,
pub endnotes: Vec<(String, Vec<Block>)>,
pub images: Vec<FImage>,
pub fonts: Vec<EmbeddedFont>,
pub font_kinds: std::collections::HashMap<String, FontKind>,
pub default_tab: f32,
pub title: Option<String>,
pub even_and_odd_headers: bool,
pub footnote_format: NumFormat,
pub endnote_format: NumFormat,
pub auto_hyphenation: bool,
pub compat_mode: u32,
pub no_expand_shift_return: bool,
pub add_paragraph_spacing: bool,
pub split_break_and_mark: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FontKind {
Sans,
Serif,
Mono,
Symbol,
}
#[derive(Debug, Clone)]
pub struct FImage {
pub data: Vec<u8>,
pub jpeg: bool,
pub bare: Option<Vec<u8>>,
pub texts: Vec<crate::word::metafile::MetaText>,
}
#[derive(Debug, Clone)]
pub struct EmbeddedFont {
pub family: String,
pub bold: bool,
pub italic: bool,
pub data: Vec<u8>,
}
#[derive(Debug, Clone, Default)]
pub struct Section {
pub page: PageSetup,
pub columns: Columns,
pub start: SectionStart,
pub headers: HeaderSet,
pub footers: HeaderSet,
pub title_page: bool,
pub page_number_start: Option<u32>,
pub page_number_format: NumFormat,
pub grid_pitch: Option<f32>,
pub blocks: Vec<Block>,
}
#[derive(Debug, Clone, Copy)]
pub struct PageSetup {
pub width: f32,
pub height: f32,
pub top: f32,
pub bottom: f32,
pub left: f32,
pub right: f32,
pub header: f32,
pub footer: f32,
pub gutter: f32,
}
impl Default for PageSetup {
fn default() -> Self {
PageSetup {
width: 612.0,
height: 792.0,
top: 72.0,
bottom: 72.0,
left: 72.0,
right: 72.0,
header: 36.0,
footer: 36.0,
gutter: 0.0,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct Columns {
pub widths: Vec<(f32, f32)>,
pub count: u32,
pub space: f32,
pub separator: bool,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum SectionStart {
#[default]
NextPage,
Continuous,
NextColumn,
OddPage,
EvenPage,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct HeaderSet {
pub default: Option<usize>,
pub first: Option<usize>,
pub even: Option<usize>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum NumFormat {
#[default]
Decimal,
DecimalZero,
LowerLetter,
UpperLetter,
LowerRoman,
UpperRoman,
Bullet,
None,
Chicago,
CardinalText,
OrdinalText,
Ordinal,
}
#[derive(Debug, Clone)]
pub enum Block {
Para(Box<Para>),
Table(Table),
}
#[derive(Debug, Clone, Default)]
pub struct Para {
pub style: String,
pub props: ParaProps,
pub mark: RunFmt,
pub number: Option<NumberMark>,
pub inlines: Vec<Inline>,
pub bookmarks: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct NumberMark {
pub text: String,
pub fmt: RunFmt,
pub suffix: NumberSuffix,
pub align: Align,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum NumberSuffix {
#[default]
Tab,
Space,
Nothing,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum Align {
#[default]
Left,
Center,
Right,
Both,
Distribute,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineSpacing {
Auto(f32),
Exact(f32),
AtLeast(f32),
}
impl Default for LineSpacing {
fn default() -> Self {
LineSpacing::Auto(1.0)
}
}
#[derive(Debug, Clone, Default)]
pub struct ParaProps {
pub align: Align,
pub left: f32,
pub right: f32,
pub first_line: f32,
pub before: f32,
pub after: f32,
pub before_auto: bool,
pub after_auto: bool,
pub line: LineSpacing,
pub contextual: bool,
pub keep_next: bool,
pub keep_lines: bool,
pub page_break_before: bool,
pub widow_control: bool,
pub tabs: Vec<TabStop>,
pub borders: ParaBorders,
pub shading: Option<Rgb>,
pub outline: Option<u8>,
pub bidi: bool,
pub snap_to_grid: bool,
pub suppress_hyphens: bool,
pub frame: Option<Frame>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Frame {
pub width: f32,
pub height: f32,
pub exact: bool,
pub anchor: Anchor,
}
impl Default for Frame {
fn default() -> Self {
let pos = |from| AnchorPos {
from,
align: None,
offset: 0.0,
};
Frame {
width: 0.0,
height: 0.0,
exact: false,
anchor: Anchor {
horizontal: pos(AnchorFrom::Column),
vertical: pos(AnchorFrom::Paragraph),
wrap: Wrap::Square,
behind: false,
dist: [0.0; 4],
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TabStop {
pub pos: f32,
pub kind: TabKind,
pub leader: Option<char>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TabKind {
Left,
Center,
Right,
Decimal,
Bar,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Border {
pub width: f32,
pub space: f32,
pub color: Rgb,
pub style: BorderStyle,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BorderStyle {
Single,
Double,
Dotted,
Dashed,
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub struct ParaBorders {
pub top: Option<Border>,
pub bottom: Option<Border>,
pub left: Option<Border>,
pub right: Option<Border>,
pub between: Option<Border>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum VertAlign {
#[default]
Baseline,
Super,
Sub,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Underline {
Single,
Words,
Double,
Thick,
Dotted,
Dashed,
Wave,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RunFmt {
pub font: String,
pub font_hansi: String,
pub font_east_asia: String,
pub font_cs: String,
pub size: f32,
pub size_cs: f32,
pub bold: bool,
pub italic: bool,
pub underline: Option<Underline>,
pub underline_color: Option<Rgb>,
pub strike: bool,
pub dstrike: bool,
pub color: Option<Rgb>,
pub highlight: Option<Rgb>,
pub shading: Option<Rgb>,
pub vert: VertAlign,
pub position: f32,
pub caps: bool,
pub small_caps: bool,
pub spacing: f32,
pub scale: f32,
pub kern_from: Option<f32>,
pub hidden: bool,
pub rtl: bool,
pub cs: bool,
pub href: Option<String>,
}
impl Default for RunFmt {
fn default() -> Self {
RunFmt {
font: "Times New Roman".into(),
font_hansi: "Times New Roman".into(),
font_east_asia: "Times New Roman".into(),
font_cs: "Times New Roman".into(),
size: 10.0,
size_cs: 10.0,
bold: false,
italic: false,
underline: None,
underline_color: None,
strike: false,
dstrike: false,
color: None,
highlight: None,
shading: None,
vert: VertAlign::Baseline,
position: 0.0,
caps: false,
small_caps: false,
spacing: 0.0,
scale: 100.0,
kern_from: None,
hidden: false,
rtl: false,
cs: false,
href: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BreakKind {
Line,
Page,
Column,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FieldKind {
PageRef(String),
Page,
NumPages,
SectionPages,
}
#[derive(Debug, Clone)]
pub enum Inline {
Text {
text: String,
fmt: RunFmt,
},
Tab {
fmt: RunFmt,
},
Break {
kind: BreakKind,
fmt: RunFmt,
},
Field {
kind: FieldKind,
fmt: RunFmt,
format: Option<NumFormat>,
},
Image {
index: Option<usize>,
width: f32,
height: f32,
anchor: Option<Anchor>,
fmt: RunFmt,
alt: String,
crop: [f32; 4],
},
Shape(Box<Shape>),
NoteRef {
endnote: bool,
id: String,
fmt: RunFmt,
},
NoteNumber {
fmt: RunFmt,
},
Math {
node: MathNode,
display: bool,
fmt: RunFmt,
},
}
#[derive(Debug, Clone)]
pub struct Shape {
pub width: f32,
pub height: f32,
pub anchor: Option<Anchor>,
pub fill: Option<Rgb>,
pub line: Option<Border>,
pub blocks: Vec<Block>,
pub insets: [f32; 4],
pub pictures: Vec<(usize, f32, f32, f32, f32)>,
pub auto_height: bool,
pub fmt: RunFmt,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Anchor {
pub horizontal: AnchorPos,
pub vertical: AnchorPos,
pub wrap: Wrap,
pub behind: bool,
pub dist: [f32; 4],
}
#[derive(Debug, Clone, PartialEq)]
pub struct AnchorPos {
pub from: AnchorFrom,
pub align: Option<AnchorAlign>,
pub offset: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnchorFrom {
Page,
Margin,
Column,
Character,
Paragraph,
Line,
StartMargin,
EndMargin,
InsideMargin,
OutsideMargin,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnchorAlign {
Start,
Center,
End,
Inside,
Outside,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Wrap {
None,
Square,
Tight,
TopBottom,
}
#[derive(Debug, Clone, Default)]
pub struct Table {
pub props: TableProps,
pub grid: Vec<f32>,
pub rows: Vec<Row>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum Width {
#[default]
Auto,
Pt(f32),
Pct(f32),
}
#[derive(Debug, Clone, Default)]
pub struct TableProps {
pub width: Width,
pub indent: f32,
pub align: Align,
pub fixed: bool,
pub cell_margins: [f32; 4],
pub borders: [Option<Border>; 6],
pub cell_spacing: f32,
pub float: Option<Anchor>,
}
#[derive(Debug, Clone, Default)]
pub struct Row {
pub height: Option<(f32, bool)>,
pub header: bool,
pub cant_split: bool,
pub grid_before: usize,
pub grid_after: usize,
pub cells: Vec<Cell>,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum VMerge {
#[default]
None,
Restart,
Continue,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum VAlign {
#[default]
Top,
Center,
Bottom,
}
#[derive(Debug, Clone, Default)]
pub struct Cell {
pub span: usize,
pub vmerge: VMerge,
pub width: Width,
pub borders: [Option<Border>; 4],
pub shading: Option<Rgb>,
pub margins: [f32; 4],
pub valign: VAlign,
pub blocks: Vec<Block>,
}
pub fn format_page(number: u32, format: &NumFormat) -> String {
match format {
NumFormat::Bullet | NumFormat::None => number.to_string(),
other => super::styles::format_number(number, other),
}
}