Ver Fonte

use dpi units

genius há 12 anos atrás
pai
commit
d0c2d60132
2 ficheiros alterados com 51 adições e 0 exclusões
  1. 17 0
      Source/Core/Decorator.cpp
  2. 34 0
      Source/Core/ElementStyle.cpp

+ 17 - 0
Source/Core/Decorator.cpp

@@ -119,6 +119,23 @@ float Decorator::ResolveProperty(const PropertyDictionary& properties, const Str
 
 
 	if (property->unit & Property::NUMBER || property->unit & Property::PX)
 	if (property->unit & Property::NUMBER || property->unit & Property::PX)
 		return property->value.Get< float >();
 		return property->value.Get< float >();
+    
+    // Values based on pixels-per-inch.
+	if (property->unit & Property::PPI_UNIT)
+	{
+		float inch = property->value.Get< float >() * GetRenderInterface()->GetPixelsPerInch();
+
+		if (property->unit & Property::INCH) // inch
+			return inch;
+		if (property->unit & Property::CM) // centimeter
+			return inch / 2.54f;
+		if (property->unit & Property::MM) // millimeter
+			return inch / 25.4f;
+		if (property->unit & Property::PT) // point
+			return inch / 72.0f;
+		if (property->unit & Property::PC) // pica
+			return inch / 6.0f;
+	}
 
 
 	ROCKET_ERROR;
 	ROCKET_ERROR;
 	return 0;
 	return 0;

+ 34 - 0
Source/Core/ElementStyle.cpp

@@ -362,6 +362,23 @@ float ElementStyle::ResolveProperty(const Property* property, float base_value)
 	{
 	{
 		return property->value.Get< float >();
 		return property->value.Get< float >();
 	}
 	}
+    
+        // 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 / 2.54f;
+		if (property->unit & Property::MM) // millimeter
+			return inch / 25.4f;
+		if (property->unit & Property::PT) // point
+			return inch / 72.0f;
+		if (property->unit & Property::PC) // pica
+			return inch / 6.0f;
+	}
 
 
 	// We're not a numeric property; return 0.
 	// We're not a numeric property; return 0.
 	return 0.0f;
 	return 0.0f;
@@ -411,6 +428,23 @@ float ElementStyle::ResolveProperty(const String& name, float base_value)
 	{
 	{
 		return property->value.Get< float >();
 		return property->value.Get< float >();
 	}
 	}
+    
+    // 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 / 2.54f;
+		if (property->unit & Property::MM) // millimeter
+			return inch / 25.4f;
+		if (property->unit & Property::PT) // point
+			return inch / 72.0f;
+		if (property->unit & Property::PC) // pica
+			return inch / 6.0f;
+	}
 
 
 	// We're not a numeric property; return 0.
 	// We're not a numeric property; return 0.
 	return 0.0f;
 	return 0.0f;