if (rawValue instanceof CSSNumericValue == false)
{
return 0;
}
final CSSNumericValue value = (CSSNumericValue) rawValue;
if (CSSNumericType.PT.equals(value.getType()))
{
return value.getValue();
}
if (CSSNumericType.PC.equals(value.getType()))
{
return (value.getValue() / 12.0d);
}
if (CSSNumericType.INCH.equals(value.getType()))
{
return (value.getValue() / 72.0d);
}
if (CSSNumericType.CM.equals(value.getType()))
{
return ((value.getValue() * 100 * 72.0d) / 254.0d);
}
if (CSSNumericType.MM.equals(value.getType()))
{
return ((value.getValue() * 10 * 72.0d) / 254.0d);
}
if (CSSNumericType.PX.equals(value.getType()))
{
// todo Read from a configuration file or so ..
if (resolution <= 0)
{
// we assume 72 pixel per inch ...
return value.getValue();
}
return value.getValue() * 72d / resolution;
}
if (baseElement != null)
{
if (CSSNumericType.EM.equals(value.getType()))
{
// base is the font-size
final CSSValue baseVal = baseElement.getLayoutStyle().getValue(FontStyleKeys.FONT_SIZE);
return value.getValue() * convertLengthToDouble(baseVal, resolution);
}
if (CSSNumericType.EX.equals(value.getType()))
{
// base is the parent font's x-height.
final CSSValue baseVal = baseElement.getLayoutStyle().getValue(FontStyleKeys.FONT_SIZE);
// todo: cheating for now: We assume a sensible default and do not ask the font system.
return value.getValue() * convertLengthToDouble(baseVal, resolution) * 0.58;
}
if (CSSNumericType.PERCENTAGE.equals(value.getType()))
{
final CSSValue baseVal = baseElement.getLayoutStyle().getValue(FontStyleKeys.FONT_SIZE);
return value.getValue() * convertLengthToDouble(baseVal, resolution) / 100d;
}
}
return 0;