if (styleBuilder == null)
{
styleBuilder = new StyleBuilder();
}
final StyleSheet styleSheet = box.getStyleSheet();
final Color textColor = (Color) styleSheet.getStyleProperty(ElementStyleKeys.PAINT);
final Color backgroundColor = (Color) styleSheet.getStyleProperty(ElementStyleKeys.BACKGROUND_COLOR);
styleBuilder.clear();
if (includeBorder)
{
if (backgroundColor != null)
{
styleBuilder.append("background-color", HtmlColors.getColorString(backgroundColor));
}
final BoxDefinition boxDefinition = box.getBoxDefinition();
final Border border = boxDefinition.getBorder();
final BorderEdge top = border.getTop();
if (top != null)
{
styleBuilder.appendRaw("border-top", styleBuilder.printEdgeAsCSS(top));
}
final BorderEdge left = border.getLeft();
if (left != null)
{
styleBuilder.appendRaw("border-left", styleBuilder.printEdgeAsCSS(left));
}
final BorderEdge bottom = border.getBottom();
if (bottom != null)
{
styleBuilder.appendRaw("border-bottom", styleBuilder.printEdgeAsCSS(bottom));
}
final BorderEdge right = border.getRight();
if (right != null)
{
styleBuilder.appendRaw("border-right", styleBuilder.printEdgeAsCSS(right));
}
final long paddingTop = boxDefinition.getPaddingTop();
final long paddingLeft = boxDefinition.getPaddingLeft();
final long paddingBottom = boxDefinition.getPaddingBottom();
final long paddingRight = boxDefinition.getPaddingRight();
if (paddingTop > 0)
{
styleBuilder.append("padding-top", styleBuilder.getPointConverter().format
(fixLengthForSafari(StrictGeomUtility.toExternalValue(paddingTop), fixLength)), "pt");
}
if (paddingLeft > 0)
{
styleBuilder.append("padding-left", styleBuilder.getPointConverter().format
(fixLengthForSafari(StrictGeomUtility.toExternalValue(paddingLeft), fixLength)), "pt");
}
if (paddingBottom > 0)
{
styleBuilder.append("padding-bottom", styleBuilder.getPointConverter().format
(fixLengthForSafari(StrictGeomUtility.toExternalValue(paddingBottom), fixLength)), "pt");
}
if (paddingRight > 0)
{
styleBuilder.append("padding-right", styleBuilder.getPointConverter().format
(fixLengthForSafari(StrictGeomUtility.toExternalValue(paddingRight), fixLength)), "pt");
}
}
if (textColor != null)
{
styleBuilder.append("color", HtmlColors.getColorString(textColor));
}
styleBuilder.appendRaw("font-family", translateFontFamily(box));
styleBuilder.append("font-size", styleBuilder.getPointConverter().format
(fixLengthForSafari(styleSheet.getDoubleStyleProperty(TextStyleKeys.FONTSIZE, 0), fixLength)), "pt");
if (styleSheet.getBooleanStyleProperty(TextStyleKeys.BOLD))
{
styleBuilder.append("font-weight", "bold");
}
else
{
styleBuilder.append("font-weight", "normal");
}
if (styleSheet.getBooleanStyleProperty(TextStyleKeys.ITALIC))
{
styleBuilder.append("font-style", "italic");
}
else
{
styleBuilder.append("font-style", "normal");
}
final boolean underlined = styleSheet.getBooleanStyleProperty(TextStyleKeys.UNDERLINED);
final boolean strikeThrough = styleSheet.getBooleanStyleProperty(TextStyleKeys.STRIKETHROUGH);
if (underlined && strikeThrough)
{
styleBuilder.append("text-decoration", "underline line-through");
}
else if (strikeThrough)
{
styleBuilder.append("text-decoration", "line-through");
}
if (underlined)
{
styleBuilder.append("text-decoration", "underline");
}
else
{
styleBuilder.append("text-decoration", "none");
}
final ElementAlignment align = (ElementAlignment) styleSheet.getStyleProperty(ElementStyleKeys.ALIGNMENT);
styleBuilder.append("text-align", translateHorizontalAlignment(align));
final double wordSpacing = styleSheet.getDoubleStyleProperty(TextStyleKeys.WORD_SPACING, 0);
styleBuilder.append("word-spacing", styleBuilder.getPointConverter().format
(fixLengthForSafari(wordSpacing, fixLength)), "pt");
final double minLetterSpacing = styleSheet.getDoubleStyleProperty(TextStyleKeys.X_MIN_LETTER_SPACING, 0);
final double maxLetterSpacing = styleSheet.getDoubleStyleProperty(TextStyleKeys.X_MAX_LETTER_SPACING, 0);
styleBuilder.append("letter-spacing", styleBuilder.getPointConverter().format
(fixLengthForSafari(Math.min(minLetterSpacing, maxLetterSpacing), fixLength)), "pt");
if (includeWhitespaceCollapse)
{
final WhitespaceCollapse wsCollapse = (WhitespaceCollapse)
styleSheet.getStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE);
if (WhitespaceCollapse.PRESERVE.equals(wsCollapse))
{
if (useWhitespacePreWrap)
{
// this style does not work for IE6 and IE7, but heck, in that case they just behave as if normal mode is