Browse Source

Add inches to line height

SiPlus 11 years ago
parent
commit
31a279dd75
2 changed files with 23 additions and 10 deletions
  1. 1 1
      Source/Core/ElementStyle.cpp
  2. 22 9
      Source/Core/ElementUtilities.cpp

+ 1 - 1
Source/Core/ElementStyle.cpp

@@ -368,7 +368,7 @@ float ElementStyle::ResolveProperty(const Property* property, float base_value)
 	{
 	{
 		float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
 		float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
 		
 		
-		if (property->unit & Property::IN) // inch
+		if (property->unit & Property::INCH) // inch
 			return inch;
 			return inch;
 		if (property->unit & Property::CM) // centimeter
 		if (property->unit & Property::CM) // centimeter
 			return inch * (1.0f / 2.54f);
 			return inch * (1.0f / 2.54f);

+ 22 - 9
Source/Core/ElementUtilities.cpp

@@ -141,20 +141,33 @@ int ElementUtilities::GetLineHeight(Element* element)
 		return 0;
 		return 0;
 
 
 	int line_height = font_face_handle->GetLineHeight();
 	int line_height = font_face_handle->GetLineHeight();
+	float inch = element->GetRenderInterface()->GetPixelsPerInch();
 	const Property* line_height_property = element->GetLineHeightProperty();
 	const Property* line_height_property = element->GetLineHeightProperty();
 
 
-	// If the property is a straight number or an em measurement, then it scales the line height.
-	if (line_height_property->unit == Property::NUMBER ||
-		line_height_property->unit == Property::EM)
+	switch (line_height_property->unit)
+	{
+	case Property::NUMBER:
+	case Property::EM:
+		// 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);
 		return Math::Round(line_height_property->value.Get< float >() * line_height);
-
-	// If the property is a percentage, then it scales the line height.
-	else if (line_height_property->unit == Property::PERCENT)
+	case Property::PERCENT:
+		// If the property is a percentage, then it scales the line height.
 		return Math::Round(line_height_property->value.Get< float >() * line_height * 0.01f);
 		return Math::Round(line_height_property->value.Get< float >() * line_height * 0.01f);
-
-	// Otherwise, we're a px measurement.
-	else if (line_height_property->unit == Property::PX)
+	case Property::PX:
+		// A px measurement.
 		return Math::Round(line_height_property->value.Get< float >());
 		return Math::Round(line_height_property->value.Get< float >());
+	case Property::INCH:
+		// Values based on pixels-per-inch.
+		return Math::Round(line_height_property->value.Get< float >() * inch);
+	case Property::CM:
+		return Math::Round(line_height_property->value.Get< float >() * inch * (1.0f / 2.54f));
+	case Property::MM:
+		return Math::Round(line_height_property->value.Get< float >() * inch * (1.0f / 25.4f));
+	case Property::PT:
+		return Math::Round(line_height_property->value.Get< float >() * inch * (1.0f / 72.0f));
+	case Property::PC:
+		return Math::Round(line_height_property->value.Get< float >() * inch * (1.0f / 6.0f));
+	}
 
 
 	return 0;
 	return 0;
 }
 }