1use json::{JsonValue, object};
2
3#[derive(Clone, Debug)]
4pub struct Head {
5 pub field: String,
6 pub title: String,
7 pub note: String,
8 pub width: i32,
9}
10
11impl Head {
12 pub fn new(field: &str, title: &str, note: &str, mut width: i32) -> Self {
13 if width == 0 {
14 width = 10;
15 }
16 Self {
17 field: field.to_string(),
18 title: title.to_string(),
19 note: note.to_string(),
20 width,
21 }
22 }
23}
24
25pub mod write;
26pub mod read;
27
28#[derive(Debug, Clone)]
29pub struct Cell {
30 pub value: String,
32 pub row: usize,
34 pub col: usize,
36 pub style: Style,
38 pub rowspan: usize,
40 pub colspan: usize,
42
43 pub is_image: bool,
45 pub image: String,
46 pub image_id: String,
47 pub image_from_col: u32,
48 pub image_from_col_off: usize,
49 pub image_from_row: u32,
50 pub image_from_row_off: usize,
51 pub image_to_col: u32,
52 pub image_to_col_off: usize,
53 pub image_to_row: u32,
54 pub image_to_row_off: usize,
55 pub image_n: String,
56 pub image_h: f64,
57 pub image_w: f64,
58
59 pub image_h_w: usize,
60 pub image_w_w: usize,
61
62 pub image_x: f64,
63 pub image_y: f64,
64
65 pub image_x_w: usize,
66 pub image_y_w: usize,
67 pub state: u8,
69}
70
71impl Default for Cell {
72 fn default() -> Self {
73 Self::new()
74 }
75}
76
77impl Cell {
78 pub fn new() -> Self {
79 Self {
80 value: "".to_string(),
81 image: "".to_string(),
82 image_id: "".to_string(),
83 image_from_col: 0,
84 image_from_col_off: 0,
85 image_from_row: 0,
86 image_from_row_off: 0,
87 image_to_col: 0,
88 image_to_col_off: 0,
89 image_to_row: 0,
90 image_to_row_off: 0,
91 image_n: "".to_string(),
92 image_h: 0.0,
93 image_w: 0.0,
94
95 image_h_w: 0,
96 image_w_w: 0,
97 image_x: 0.0,
98 image_y: 0.0,
99 image_x_w: 0,
100 row: 0,
101 col: 0,
102 style: Style {
103 height: 0.0,
104 width: 0.0,
105 font_size: 16.0,
106 background_color: "".to_string(),
107 text_align: "".to_string(),
108 vertical_align: "".to_string(),
109 text_wrap: "".to_string(),
110 font_family: "".to_string(),
111 font_weight: "".to_string(),
112 font_style: "".to_string(),
113 text_decoration: "".to_string(),
114 font_strike: "".to_string(),
115 color: "".to_string(),
116 border_top: "".to_string(),
117 border_right: "".to_string(),
118 border_bottom: "".to_string(),
119 border_left: "".to_string(),
120 },
121 rowspan: 1,
122 colspan: 1,
123 state: 1,
124 image_y_w: 0,
125 is_image: false,
126 }
127 }
128 pub fn json(self) -> JsonValue {
129 if self.is_image {
130 object! {
131 value:self.value,
132 row:self.row,
133 col:self.col,
134 rowspan:self.rowspan,
135 colspan:self.colspan,
136 style:self.style.json(),
137
138 is_image: self.is_image,
139 image: self.image.to_string(),
140 image_id:self.image_id,
141 image_n: self.image_n,
142 image_from_col: self.image_from_col,
143 image_from_col_off: self.image_from_col_off,
144 image_from_row: self.image_from_row,
145 image_from_row_off: self.image_from_row_off,
146
147 image_to_col: self.image_to_col,
148 image_to_col_off: self.image_to_col_off,
149 image_to_row: self.image_to_row,
150 image_to_row_off: self.image_to_row_off,
151 image_h: self.image_h/32743.37,
152 image_w: self.image_w/70823.0,
153
154 image_h_w: self.image_h_w,
155 image_w_w: self.image_w_w,
156
157 image_x_w: self.image_x_w,
158 image_y_w: self.image_y_w,
159
160 image_x: self.image_x/70823.0,
161 image_y: self.image_y/32743.37,
162 state: self.state,
163 }
164 } else {
165 object! {
166 value:self.value,
167 row:self.row,
168 col:self.col,
169 rowspan:self.rowspan,
170 colspan:self.colspan,
171 style:self.style.json(),
172
173 is_image: self.is_image,
174 state: self.state,
175 }
176 }
177 }
178}
179
180#[derive(Debug, Clone)]
181pub struct Style {
182 pub height: f64,
183 pub width: f64,
184 pub font_size: f64,
185 pub background_color: String,
186 pub text_align: String,
187 pub vertical_align: String,
189
190 pub text_wrap: String,
191 pub font_family: String,
193 font_weight: String,
195 font_style: String,
197 text_decoration: String,
199 pub font_strike: String,
201 pub color: String,
202
203 border_top: String,
204 border_right: String,
205 border_bottom: String,
206 border_left: String,
207}
208
209impl Style {
210 fn json(self) -> JsonValue {
211 let res = object! {
212 height:format!("{}",self.height*0.3612),
213 width:format!("{}",self.width*2.54),
214 "font-family":self.font_family,
215 "font-weight":self.font_weight,
216 "font-size":format!("{}",self.font_size),
217 "text-decoration":self.text_decoration,
218 "font-strike":self.font_strike,
219 color:self.color,
220 "vertical-align":self.vertical_align,
221 "text-wrap":self.text_wrap,
222 "text-align":self.text_align,
223 "border-top":self.border_top,
224 "border-right":self.border_right,
225 "border-bottom":self.border_bottom,
226 "border-left":self.border_left
227 };
228 let mut list = res.clone();
229 for (key, value) in res.entries() {
230 if value.is_empty() {
231 list.remove(key);
232 }
233 }
234 list
235 }
236}