use crate::visual::Color;
use super::style::*;
pub const DEFAULT_CSS: &str = r##"/* liepress 内置默认样式表 */
body {
font-family: serif;
font-size: 10.5pt;
line-height: 1.5;
color: #000;
margin: 0;
text-align: left;
}
/* 标题 (h1-h6) */
h1 { font-size: 24pt; line-height: 1.2; font-weight: bold; margin-bottom: 12pt; }
h2 { font-size: 18pt; line-height: 1.2; font-weight: bold; margin-bottom: 10pt; }
h3 { font-size: 14pt; line-height: 1.2; font-weight: bold; margin-bottom: 8pt; }
h4 { font-size: 12pt; line-height: 1.2; font-weight: bold; margin-bottom: 6pt; }
h5 { font-size: 11pt; line-height: 1.2; font-weight: bold; margin-bottom: 6pt; }
h6 { font-size: 10.5pt; line-height: 1.2; font-weight: bold; margin-bottom: 6pt; }
/* 段落 */
p {
margin-top: 0;
margin-bottom: 12pt;
}
/* 代码块 */
pre {
font-family: monospace;
font-size: 9pt;
line-height: 1.5;
color: #333;
margin-top: 0;
margin-bottom: 12pt;
display: block;
}
/* 行内代码 */
code {
font-family: monospace;
font-size: 10.5pt;
color: #333;
display: inline;
}
/* 图片 */
img {
display: block;
object-fit: contain;
margin-top: 0;
margin-bottom: 12pt;
}
/* 列表容器 */
ul, ol {
margin-top: 0;
margin-bottom: 12pt;
display: block;
list-indent: 2em;
}
/* 列表项 */
li {
display: block;
margin-top: 0;
margin-bottom: 4pt;
}
/* 引用块 */
blockquote {
margin-top: 12pt;
margin-bottom: 12pt;
display: block;
}
/* 分隔线 */
hr {
margin-top: 18pt;
margin-bottom: 18pt;
display: block;
}
/* 居中容器 (center) */
center {
display: block;
text-align: center;
margin-top: 0;
margin-bottom: 0;
}
/* 行内容器 (span) */
span {
display: inline;
}
/* 表格 */
table {
display: block;
margin-top: 12pt;
margin-bottom: 12pt;
border-collapse: collapse;
table-header-background: #e8e8e8;
table-alt-row-background: #f8f8f8;
table-border-color: #b4b4b4;
table-border-width: 0.5pt;
table-cell-padding-horizontal: 4pt;
table-cell-padding-vertical: 2pt;
}
/* 加粗 */
strong {
font-weight: bold;
display: inline;
}
/* 斜体 */
em {
font-style: italic;
display: inline;
}
/* 链接 */
a {
color: #00f;
font-style: italic;
display: inline;
}
/* 删除线 */
del {
display: inline;
text-decoration: line-through;
}
/* 普通文本 */
span {
display: inline;
}
"##;
pub fn list_marker_style() -> Style {
Style {
font_family: vec![
"Source Han Serif SC".to_string(),
"Noto Sans SC".to_string(),
"serif".to_string(),
],
font_size_pt: 10.5,
font_weight: FontWeight::Normal,
font_style: FontStyle::Normal,
color: Color::new(0, 0, 0),
line_height_pt: 15.75,
letter_spacing: 0.0,
text_align: TextAlign::Right,
display: Display::Inline,
margin_top_pt: 0.0,
margin_bottom_pt: 0.0,
margin_left_pt: 0.0,
margin_right_pt: 0.0,
padding_top_pt: 0.0,
padding_bottom_pt: 0.0,
padding_left_pt: 0.0,
padding_right_pt: 0.0,
width: None,
height: None,
object_fit: ObjectFit::None,
background_color: None,
page_break_before: PageBreak::Auto,
page_break_after: PageBreak::Auto,
table_border_color: Color::new(180, 180, 180),
table_border_width_pt: 0.5,
table_cell_padding_h_pt: 4.0,
table_cell_padding_v_pt: 2.0,
table_header_bg: None,
table_alt_row_bg: None,
link_url: None,
text_decoration: TextDecoration::None,
list_indent_pt: None,
}
}
pub fn computed_style_to_text_style(style: &Style) -> crate::text::TextStyle {
use crate::text::TextAlign as TextAlign2;
let align = match style.text_align {
TextAlign::Left => TextAlign2::Left,
TextAlign::Center => TextAlign2::Center,
TextAlign::Right => TextAlign2::Right,
TextAlign::Justify => TextAlign2::Left, };
crate::text::TextStyle {
color: style.color,
font_family: style.font_family.clone(),
font_size: style.font_size_pt as f64,
font_weight: style.font_weight.as_str().to_string(),
font_style: style.font_style.as_str().to_string(),
align,
url: style.link_url.clone(),
decoration: style.text_decoration,
}
}
pub const LIST_INDENT_PT: f32 = 21.0;
pub fn calculate_list_indent(font_size_pt: f32) -> f32 {
font_size_pt * 2.0
}