use json::{JsonValue, object};
#[derive(Clone, Debug)]
pub struct Head {
pub field: String,
pub title: String,
pub note: String,
pub width: i32,
}
impl Head {
pub fn new(field: &str, title: &str, note: &str, mut width: i32) -> Self {
if width == 0 {
width = 10;
}
Self {
field: field.to_string(),
title: title.to_string(),
note: note.to_string(),
width,
}
}
}
pub mod write;
pub mod read;
#[derive(Debug, Clone)]
pub struct Cell {
pub value: String,
pub row: usize,
pub col: usize,
pub style: Style,
pub rowspan: usize,
pub colspan: usize,
pub is_image: bool,
pub image: String,
pub image_from_col: u32,
pub image_from_col_off: usize,
pub image_from_row: u32,
pub image_from_row_off: usize,
pub image_to_col: u32,
pub image_to_col_off: usize,
pub image_to_row: u32,
pub image_to_row_off: usize,
pub image_n: String,
pub image_h: f64,
pub image_w: f64,
pub image_h_w: usize,
pub image_w_w: usize,
pub image_x: f64,
pub image_y: f64,
pub image_x_w: usize,
pub image_y_w: usize,
pub state: u8,
}
impl Cell {
pub fn default() -> Self {
Self {
value: "".to_string(),
image: "".to_string(),
image_from_col: 0,
image_from_col_off: 0,
image_from_row: 0,
image_from_row_off: 0,
image_to_col: 0,
image_to_col_off: 0,
image_to_row: 0,
image_to_row_off: 0,
image_n: "".to_string(),
image_h: 0.0,
image_w: 0.0,
image_h_w: 0,
image_w_w: 0,
image_x: 0.0,
image_y: 0.0,
image_x_w: 0,
row: 0,
col: 0,
style: Style {
height: 0.0,
width: 0.0,
font_size: 16.0,
background_color: "".to_string(),
text_align: "".to_string(),
vertical_align: "".to_string(),
text_wrap: "".to_string(),
font_family: "".to_string(),
font_weight: "".to_string(),
font_style: "".to_string(),
text_decoration: "".to_string(),
font_strike: "".to_string(),
color: "".to_string(),
border_top: "".to_string(),
border_right: "".to_string(),
border_bottom: "".to_string(),
border_left: "".to_string(),
},
rowspan: 1,
colspan: 1,
state: 1,
image_y_w: 0,
is_image: false,
}
}
pub fn json(self) -> JsonValue {
if self.is_image {
object! {
value:self.value,
row:self.row,
col:self.col,
rowspan:self.rowspan,
colspan:self.colspan,
style:self.style.json(),
is_image: self.is_image,
image: self.image.to_string(),
image_n: self.image_n,
image_from_col: self.image_from_col,
image_from_col_off: self.image_from_col_off,
image_from_row: self.image_from_row,
image_from_row_off: self.image_from_row_off,
image_to_col: self.image_to_col,
image_to_col_off: self.image_to_col_off,
image_to_row: self.image_to_row,
image_to_row_off: self.image_to_row_off,
image_h: self.image_h/32743.37,
image_w: self.image_w/70823.0,
image_h_w: self.image_h_w,
image_w_w: self.image_w_w,
image_x_w: self.image_x_w,
image_y_w: self.image_y_w,
image_x: self.image_x/70823.0,
image_y: self.image_y/32743.37,
state: self.state,
}
} else {
object! {
value:self.value,
row:self.row,
col:self.col,
rowspan:self.rowspan,
colspan:self.colspan,
style:self.style.json(),
is_image: self.is_image,
state: self.state,
}
}
}
}
#[derive(Debug, Clone)]
pub struct Style {
pub height: f64,
pub width: f64,
pub font_size: f64,
pub background_color: String,
pub text_align: String,
pub vertical_align: String,
pub text_wrap: String,
pub font_family: String,
font_weight: String,
font_style: String,
text_decoration: String,
pub font_strike: String,
pub color: String,
border_top: String,
border_right: String,
border_bottom: String,
border_left: String,
}
impl Style {
fn json(self) -> JsonValue {
let res = object! {
height:format!("{}",self.height*0.3612),
width:format!("{}",self.width*2.54),
"font-family":self.font_family,
"font-weight":self.font_weight,
"font-size":format!("{}",self.font_size),
"text-decoration":self.text_decoration,
"font-strike":self.font_strike,
color:self.color,
"vertical-align":self.vertical_align,
"text-wrap":self.text_wrap,
"text-align":self.text_align,
"border-top":self.border_top,
"border-right":self.border_right,
"border-bottom":self.border_bottom,
"border-left":self.border_left
};
let mut list = res.clone();
for (key, value) in res.entries() {
if value.is_empty() {
list.remove(key);
}
}
list
}
}