Skip to content

Commit

Permalink
feat: use relative font size (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoISnoTarget authored Apr 12, 2024
1 parent 32619ff commit 3cef713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/interpreter/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ pub enum HeaderType {
}

impl HeaderType {
pub fn text_size(&self) -> f32 {
match &self {
Self::H1 => 32.,
Self::H2 => 24.,
Self::H3 => 18.72,
Self::H4 => 16.,
Self::H5 => 13.28,
Self::H6 => 10.72,
// https://html.spec.whatwg.org/multipage/rendering.html#sections-and-headings
pub fn size_multiplier(&self) -> f32 {
match self {
HeaderType::H1 => 2.0,
HeaderType::H2 => 1.5,
HeaderType::H3 => 1.17,
HeaderType::H4 => 1.0,
HeaderType::H5 => 0.83,
HeaderType::H6 => 0.67,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl HtmlInterpreter {
}
for elem in self.state.element_stack.iter().rev() {
if let InterpreterElement::Header(header) = elem {
self.current_textbox.font_size = header.ty.text_size();
self.current_textbox.font_size *= header.ty.size_multiplier();
text = text.make_bold(true);
break;
}
Expand Down

0 comments on commit 3cef713

Please sign in to comment.