public void resolve(final DocumentContext process,
final LayoutElement currentNode,
final StyleKey key)
{
final LayoutStyle layoutContext = currentNode.getLayoutStyle();
final CSSValue value = layoutContext.getValue(key);
if (value instanceof CSSConstant == false)
{
// fine, we're done here ...
return;
}
final CSSConstant constant = (CSSConstant) value;
// parent font size has been resolved already. Parent is the resolved font size of this element.
final LayoutOutputMetaData metaData = process.getOutputMetaData();
final int resolution = (int) metaData.getNumericFeatureValue(OutputProcessorFeature.DEVICE_RESOLUTION);
final CSSValue fontSizeValue = currentNode.getLayoutStyle().getValue(FontStyleKeys.FONT_SIZE);
final double fontSize = StyleSheetUtility.convertLengthToDouble(fontSizeValue, resolution);
if (RelativeFontSize.LARGER.equals(value))
{
final double scaleFactor = getScaleLargerFactor(fontSize);
layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, scaleFactor));
}
else if (RelativeFontSize.SMALLER.equals(value))
{
final double scaleFactor = getScaleSmallerFactor(fontSize);
layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PERCENTAGE, scaleFactor));
}
final CSSValue resolvedValue = lookupValue(constant);
if (resolvedValue != null)
{
layoutContext.setValue(key, resolvedValue);
return;
}
if (key.equals(FontStyleKeys.MAX_FONT_SIZE))
{
// there is no upper limit if the value is invalid
layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, Short.MAX_VALUE));
}
else
{
// there is no lower limit if the value is invalid
layoutContext.setValue(key, CSSNumericValue.createValue(CSSNumericType.PT, 0));
}
}