*/
private StyleBuilder produceImageStyle(final RenderableReplacedContentBox rc)
{
styleBuilder.clear(); // cuts down on object creation
final NumberFormat pointConverter = styleBuilder.getPointConverter();
final RenderableReplacedContent content = rc.getContent();
final long contentWidth = content.getContentWidth();
final long nodeWidth = rc.getWidth();
final long contentHeight = content.getContentHeight();
final long nodeHeight = rc.getHeight();
final StyleSheet styleSheet = rc.getStyleSheet();
if (styleSheet.getBooleanStyleProperty(ElementStyleKeys.SCALE))
{
if (styleSheet.getBooleanStyleProperty(ElementStyleKeys.KEEP_ASPECT_RATIO) &&
(contentWidth > 0 && contentHeight > 0))
{
final double scaleFactor = Math.min(nodeWidth / (double) contentWidth, nodeHeight / (double) contentHeight);
styleBuilder.append(WIDTH_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue((long) (contentWidth * scaleFactor)),
safariLengthFix)), PT_UNIT);
styleBuilder.append(HEIGHT_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue((long) (contentHeight * scaleFactor)),
safariLengthFix)), PT_UNIT);
}
else
{
styleBuilder.append(WIDTH_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(nodeWidth), safariLengthFix)), PT_UNIT);
styleBuilder.append(HEIGHT_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(nodeHeight), safariLengthFix)), PT_UNIT);
}
}
else
{
// for plain drawable content, there is no intrinsic-width or height, so we have to use the computed
// width and height instead.
if (contentWidth > nodeWidth || contentHeight > nodeHeight)
{
// There is clipping involved. The img-element does *not* receive a width or height property.
// the width and height is applied to an external DIV element instead.
return null;
}
if (contentWidth == 0 && contentHeight == 0)
{
// Drawable content has no intrinsic height or width, therefore we must not use the content size at all.
styleBuilder.append(WIDTH_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(nodeWidth), safariLengthFix)), PT_UNIT);
styleBuilder.append(HEIGHT_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(nodeHeight), safariLengthFix)), PT_UNIT);
}
else
{
final long width = Math.min(nodeWidth, contentWidth);
final long height = Math.min(nodeHeight, contentHeight);
styleBuilder.append(WIDTH_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(width), safariLengthFix)), PT_UNIT);
styleBuilder.append(HEIGHT_STYLE, pointConverter.format
(HtmlPrinter.fixLengthForSafari(StrictGeomUtility.toExternalValue(height), safariLengthFix)), PT_UNIT);
}
}
return styleBuilder;
}