private void configureStyle(final javax.swing.text.Element textElement, final Element result)
{
final HTMLDocument htmlDocument = (HTMLDocument) textElement.getDocument();
final StyleSheet sheet = htmlDocument.getStyleSheet();
final AttributeSet attr = computeStyle(textElement, sheet);
parseBorderAndBackgroundStyle(result, sheet, attr);
parseBoxStyle(result, attr);
final Font font = sheet.getFont(attr);
if (font != null)
{
result.getStyle().setStyleProperty(TextStyleKeys.FONT, font.getFamily());
result.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, new Integer(font.getSize()));
result.getStyle().setBooleanStyleProperty(TextStyleKeys.ITALIC, font.isItalic());
result.getStyle().setBooleanStyleProperty(TextStyleKeys.BOLD, font.isBold());
}
final Object letterSpacing = attr.getAttribute(CSS.Attribute.LETTER_SPACING);
if (letterSpacing != null)
{
result.getStyle().setStyleProperty
(TextStyleKeys.X_OPTIMUM_LETTER_SPACING, parseLength(String.valueOf(letterSpacing)));
}
final Object wordSpacing = attr.getAttribute(CSS.Attribute.WORD_SPACING);
if (wordSpacing != null)
{
result.getStyle().setStyleProperty
(TextStyleKeys.WORD_SPACING, parseLength(String.valueOf(wordSpacing)));
}
final Object lineHeight = attr.getAttribute(CSS.Attribute.LINE_HEIGHT);
if (lineHeight != null)
{
result.getStyle().setStyleProperty
(TextStyleKeys.LINEHEIGHT, parseLength(String.valueOf(lineHeight)));
}
final Object textAlign = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
if (textAlign != null)
{
try
{
result.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT,
ReportParserUtil.parseHorizontalElementAlignment(String.valueOf(textAlign), null));
}
catch (ParseException e)
{
// ignore ..
}
}
final Object textDecoration = attr.getAttribute(CSS.Attribute.TEXT_DECORATION);
if (textDecoration != null)
{
final String[] strings = StringUtils.split(String.valueOf(textDecoration));
result.getStyle().setStyleProperty(TextStyleKeys.STRIKETHROUGH, Boolean.FALSE);
result.getStyle().setStyleProperty(TextStyleKeys.UNDERLINED, Boolean.FALSE);
for (int i = 0; i < strings.length; i++)
{
final String value = strings[i];
if ("line-through".equals(value))
{
result.getStyle().setStyleProperty(TextStyleKeys.STRIKETHROUGH, Boolean.TRUE);
}
if ("underline".equals(value))
{
result.getStyle().setStyleProperty(TextStyleKeys.UNDERLINED, Boolean.TRUE);
}
}
}
final Object valign = attr.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
if (valign != null)
{
final VerticalTextAlign valignValue = VerticalTextAlign.valueOf(String.valueOf(valign));
result.getStyle().setStyleProperty(TextStyleKeys.VERTICAL_TEXT_ALIGNMENT, valignValue);
try
{
result.getStyle().setStyleProperty(ElementStyleKeys.VALIGNMENT,
ReportParserUtil.parseVerticalElementAlignment(String.valueOf(valign), null));
}
catch (ParseException e)
{
// ignore ..
}
}
final Object whitespaceText = attr.getAttribute(CSS.Attribute.WHITE_SPACE);
if (whitespaceText != null)
{
final String value = String.valueOf(whitespaceText);
if ("pre".equals(value))
{
result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE);
result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE);
}
else if ("nowrap".equals(value))
{
result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS);
result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE);
}
else
{
result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.COLLAPSE);
result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.WRAP);
}
}
else
{
result.getStyle().setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.COLLAPSE);
result.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.WRAP);
}
final Object alignAttribute = attr.getAttribute(HTML.Attribute.ALIGN);
if (alignAttribute != null)
{
try
{
result.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT,
ReportParserUtil.parseHorizontalElementAlignment(String.valueOf(alignAttribute), null));
}
catch (ParseException e)
{
// ignore ..
}
}
final Object titleAttribute = attr.getAttribute(HTML.Attribute.TITLE);
if (titleAttribute != null)
{
result.setAttribute(AttributeNames.Html.NAMESPACE, AttributeNames.Html.TITLE,
String.valueOf(titleAttribute));
}
final Object textIndentStyle = attr.getAttribute(CSS.Attribute.TEXT_INDENT);
if (textIndentStyle != null)
{
result.getStyle().setStyleProperty
(TextStyleKeys.FIRST_LINE_INDENT, parseLength(String.valueOf(textIndentStyle)));
}