Skip to content

Commit

Permalink
LibWeb: Calculate font-size in NodeWidthStyle::apply_style()
Browse files Browse the repository at this point in the history
Previously, this made the same "everything is px" assumption as in
`StyleProperties::load_font()`, so I've replaced it with the calculation
from there.
  • Loading branch information
AtkinsSJ authored and awesomekling committed Aug 18, 2021
1 parent 8c39fee commit 3c54145
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Userland/Libraries/LibWeb/Layout/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
m_line_height = specified_style.line_height(*this);

{
// FIXME: This doesn't work right for relative font-sizes
auto length = specified_style.length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(10, CSS::Length::Type::Px));
m_font_size = length.raw_value();
constexpr int default_font_size = 10;
auto parent_font_size = parent() == nullptr ? default_font_size : parent()->font_size();
auto length = specified_style.length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(default_font_size, CSS::Length::Type::Px));
// FIXME: em sizes return 0 here, for some reason
m_font_size = length.resolved_or_zero(*this, parent_font_size).to_px(*this);
if (m_font_size == 0)
m_font_size = default_font_size;
}

auto bgimage = specified_style.property(CSS::PropertyID::BackgroundImage);
Expand Down

0 comments on commit 3c54145

Please sign in to comment.