Skip to content

Commit

Permalink
Merge pull request libRocket#289 from Triang3l/patch-1
Browse files Browse the repository at this point in the history
Handle rem units in ElementUtilities::GetLineHeight
  • Loading branch information
dwimsey committed Nov 24, 2016
2 parents f164420 + 1d6cabf commit 40f43b9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Source/Core/ElementUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,18 @@ int ElementUtilities::GetFontSize(Element* element)
// Returns an element's line height, if it has a font defined.
int ElementUtilities::GetLineHeight(Element* element)
{
FontFaceHandle* font_face_handle = element->GetFontFaceHandle();
const Property* line_height_property = element->GetLineHeightProperty();

Element* font_element = element;
if (line_height_property->unit == Property::REM)
font_element = element->GetOwnerDocument();

FontFaceHandle* font_face_handle = font_element->GetFontFaceHandle();
if (font_face_handle == NULL)
return 0;

int line_height = font_face_handle->GetLineHeight();
float inch = element->GetRenderInterface()->GetPixelsPerInch();
const Property* line_height_property = element->GetLineHeightProperty();

switch (line_height_property->unit)
{
Expand All @@ -155,6 +160,7 @@ int ElementUtilities::GetLineHeight(Element* element)
ROCKET_UNUSED_SWITCH_ENUM(Property::RELATIVE_UNIT);
case Property::NUMBER:
case Property::EM:
case Property::REM:
// If the property is a straight number or an em measurement, then it scales the line height.
return Math::Round(line_height_property->value.Get< float >() * line_height);
case Property::PERCENT:
Expand Down

0 comments on commit 40f43b9

Please sign in to comment.