1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
use crate::{ModelError};
use crate::font::Font;
use crate::text_document::Tab;
#[derive(Clone, PartialEq, Debug)]
pub enum Format {
FrameFormat(FrameFormat),
CharFormat(CharFormat),
BlockFormat(BlockFormat),
ImageFormat(ImageFormat),
}
pub(crate) trait IsFormat {
fn merge(&mut self, other_format: &Self) -> Result<Self, ModelError> where Self: Sized;
}
#[derive(Default, Clone, PartialEq, Debug)]
pub struct FrameFormat {
pub height: Option<usize>,
pub width: Option<usize>,
pub top_margin: Option<usize>,
pub bottom_margin: Option<usize>,
pub left_margin: Option<usize>,
pub right_margin: Option<usize>,
pub padding: Option<usize>,
pub border: Option<usize>,
pub position: Option<Position>,
}
impl FrameFormat {
pub fn new() -> Self {
FrameFormat {
..Default::default()
}
}
}
impl IsFormat for FrameFormat {
fn merge(&mut self, other_format: &Self) -> Result<Self, ModelError> where Self: Sized {
todo!()
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Position {
InFlow,
FloatLeft,
FloatRight,
}
#[derive(Default, Clone, PartialEq, Debug)]
pub struct CharFormat {
pub anchor_href: Option<String>,
pub anchor_names: Option<Vec<String>>,
pub is_anchor: Option<bool>,
pub font: Font,
pub tool_tip: Option<String>,
pub underline_style: Option<UnderlineStyle>,
pub vertical_alignment: Option<CharVerticalAlignment>,
}
impl CharFormat {
pub fn new() -> Self {
CharFormat {
..Default::default()
}
}
}
impl IsFormat for CharFormat {
fn merge(&mut self, other_format: &Self) -> Result<Self, ModelError> where Self: Sized {
todo!()
}
}
impl std::ops::Deref for CharFormat {
type Target = Font;
fn deref(&self) -> &Self::Target {
&self.font
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum CharVerticalAlignment {
AlignNormal,
AlignSuperScript,
AlignSubScript,
AlignMiddle,
AlignBottom,
AlignTop,
AlignBaseline,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum UnderlineStyle {
NoUnderline,
SingleUnderline,
DashUnderline,
DotLine,
DashDotLine,
DashDotDotLine,
WaveUnderline,
SpellCheckUnderline,
}
#[derive(Clone, PartialEq, Debug)]
pub struct BlockFormat {
pub alignment: Option<Alignment>,
pub top_margin: Option<usize>,
pub bottom_margin: Option<usize>,
pub left_margin: Option<usize>,
pub right_margin: Option<usize>,
pub heading_level: Option<u8>,
pub indent: Option<u8>,
pub text_indent: Option<usize>,
pub tab_positions: Option<Vec<Tab>>,
pub marker: Option<MarkerType>,
}
impl BlockFormat {
pub fn new() -> Self {
BlockFormat {
..Default::default()
}
}
}
impl IsFormat for BlockFormat {
fn merge(&mut self, other_format: &Self) -> Result<Self, ModelError> where Self: Sized {
todo!()
}
}
impl Default for BlockFormat {
fn default() -> Self {
Self {
alignment: Some(Alignment::AlignLeft),
top_margin: Default::default(),
bottom_margin: Default::default(),
left_margin: Default::default(),
right_margin: Default::default(),
heading_level: Default::default(),
indent: Default::default(),
text_indent: Default::default(),
tab_positions: Default::default(),
marker: Some(MarkerType::NoMarker),
}
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Alignment {
AlignLeft,
AlignRight,
AlignHCenter,
AlignJustify,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum MarkerType {
NoMarker,
Unchecked,
Checked,
}
#[derive(Default, Clone, PartialEq, Debug)]
pub struct ImageFormat {
char_format: CharFormat,
pub height: Option<usize>,
pub width: Option<usize>,
pub quality: Option<u8>,
pub name: Option<String>,
}
impl ImageFormat {
pub fn new() -> Self {
ImageFormat {
..Default::default()
}
}
}
impl IsFormat for ImageFormat {
fn merge(&mut self, other_format: &Self) -> Result<Self, ModelError> where Self: Sized {
todo!()
}
}
impl std::ops::Deref for ImageFormat {
type Target = CharFormat;
fn deref(&self) -> &Self::Target {
&self.char_format
}
}
pub(crate) trait FormattedElement<F: IsFormat> {
fn format(&self)-> F;
fn set_format(&self, format: &F) -> Result<(), ModelError>;
fn merge_format(&self, format: &F) -> Result<F, ModelError>;
}