Browse Source

Merge pull request #129 from SiPlus/patch-1

Restores PPI units, combined with PR #114.  Also needs fixes to work correctly as the current PPI is hard coded to 100 ppi which applies to pretty much nothing.  See issue #138.  Will be augmented int he future with density independent pixel units (DP) as defined in issue #139
David Wimsey 11 years ago
parent
commit
f22219c7d3
2 changed files with 39 additions and 9 deletions
  1. 17 0
      Source/Core/ElementStyle.cpp
  2. 22 9
      Source/Core/ElementUtilities.cpp

+ 17 - 0
Source/Core/ElementStyle.cpp

@@ -382,6 +382,23 @@ float ElementStyle::ResolveProperty(const Property* property, float base_value)
 			return inch / 6.0f;
 	}
 
+	// Values based on pixels-per-inch.
+	if (property->unit & Property::PPI_UNIT)
+	{
+		float inch = property->value.Get< float >() * element->GetRenderInterface()->GetPixelsPerInch();
+		
+		if (property->unit & Property::INCH) // inch
+			return inch;
+		if (property->unit & Property::CM) // centimeter
+			return inch * (1.0f / 2.54f);
+		if (property->unit & Property::MM) // millimeter
+			return inch * (1.0f / 25.4f);
+		if (property->unit & Property::PT) // point
+			return inch * (1.0f / 72.0f);
+		if (property->unit & Property::PC) // pica
+			return inch * (1.0f / 6.0f);
+	}
+
 	// We're not a numeric property; return 0.
 	return 0.0f;
 }

+ 22 - 9
Source/Core/ElementUtilities.cpp

@@ -141,20 +141,33 @@ int ElementUtilities::GetLineHeight(Element* element)
 		return 0;
 
 	int line_height = font_face_handle->GetLineHeight();
+	float inch = element->GetRenderInterface()->GetPixelsPerInch();
 	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);
-
-	// 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);
-
-	// 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 >());
+	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;
 }