}
}
private void buildStyle(final RenderBox box, final StyleBuilder builder)
{
final LayoutContext layoutContext = box.getLayoutContext();
if (layoutContext == null)
{
// this is either the logical page box or one of the direct anchestors
// of said box.
return;
}
final FontSpecification fs = layoutContext.getFontSpecification();
final double fontSize = fs.getFontSize();
builder.append(FontStyleKeys.FONT_SIZE, toPointString(fontSize), "pt");
builder.append(FontStyleKeys.FONT_FAMILY, fs.getFontFamily());
builder.append(FontStyleKeys.FONT_WEIGHT,
layoutContext.getValue(FontStyleKeys.FONT_WEIGHT));
builder.append(FontStyleKeys.FONT_STYLE,
layoutContext.getValue(FontStyleKeys.FONT_STYLE));
builder.append(TextStyleKeys.TEXT_ALIGN, layoutContext.getValue(TextStyleKeys.TEXT_ALIGN));
builder.append(TextStyleKeys.TEXT_ALIGN_LAST, layoutContext.getValue(TextStyleKeys.TEXT_ALIGN_LAST));
final NodeLayoutProperties nlp = box.getNodeLayoutProperties();
//final BoxLayoutProperties blp = box.getBoxLayoutProperties();
final ComputedLayoutProperties sblp = box.getComputedLayoutProperties();
builder.append(LineStyleKeys.VERTICAL_ALIGN, nlp.getVerticalAlignment());
if (sblp.getPaddingTop() > 0 ||
sblp.getPaddingLeft() > 0 ||
sblp.getPaddingBottom() > 0 ||
sblp.getPaddingRight() > 0)
{
if (sblp.getPaddingTop() > 0 || assumeZeroPaddings == false)
{
builder.append(BoxStyleKeys.PADDING_TOP,
toPointString(sblp.getPaddingTop()), "pt");
}
if (sblp.getPaddingLeft() > 0 || assumeZeroPaddings == false)
{
builder.append(BoxStyleKeys.PADDING_LEFT,
toPointString(sblp.getPaddingLeft()), "pt");
}
if (sblp.getPaddingBottom() > 0 || assumeZeroPaddings == false)
{
builder.append(BoxStyleKeys.PADDING_BOTTOM,
toPointString(sblp.getPaddingBottom()), "pt");
}
if (sblp.getPaddingRight() > 0 || assumeZeroPaddings == false)
{
builder.append(BoxStyleKeys.PADDING_RIGHT,
toPointString(sblp.getPaddingRight()), "pt");
}
}
else if (assumeZeroPaddings == false)
{
builder.append("padding", false, "0");
}
if (sblp.getMarginLeft() != 0 ||
sblp.getMarginRight() != 0 ||
sblp.getMarginTop() != 0 ||
sblp.getMarginBottom() != 0)
{
if (sblp.getMarginLeft() > 0 || assumeZeroMargins == false)
{
builder.append(BoxStyleKeys.MARGIN_LEFT,
toPointString(sblp.getMarginLeft()), "pt");
}
if (sblp.getMarginRight() > 0 || assumeZeroMargins == false)
{
builder.append(BoxStyleKeys.MARGIN_RIGHT,
toPointString(sblp.getMarginRight()), "pt");
}
if (sblp.getMarginTop() > 0 || assumeZeroMargins == false)
{
builder.append(BoxStyleKeys.MARGIN_TOP,
toPointString(sblp.getMarginTop()), "pt");
}
if (sblp.getMarginBottom() > 0 || assumeZeroMargins == false)
{
builder.append(BoxStyleKeys.MARGIN_BOTTOM,
toPointString(sblp.getMarginBottom()), "pt");
}
}
else if (assumeZeroMargins == false)
{
builder.append("margin", false, "0");
}
final String bgColor = toColorString(layoutContext.getValue
(BorderStyleKeys.BACKGROUND_COLOR));
if (bgColor != null)
{
builder.append(BorderStyleKeys.BACKGROUND_COLOR, bgColor);
}
final String fgColor = toColorString(layoutContext.getValue(ColorStyleKeys.COLOR));
if (fgColor != null)
{
builder.append(ColorStyleKeys.COLOR, fgColor);
}
if (sblp.getBorderTop() > 0 || sblp.getBorderLeft() > 0 ||
sblp.getBorderBottom() > 0 || sblp.getBorderRight() > 0)
{
if (sblp.getBorderTop() > 0)
{
builder.append(BorderStyleKeys.BORDER_TOP_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_TOP_COLOR));
builder.append(BorderStyleKeys.BORDER_TOP_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_TOP_STYLE));
builder.append(BorderStyleKeys.BORDER_TOP_WIDTH, toPointString(sblp.getBorderTop()), "pt");
}
else if (assumeZeroBorders == false)
{
builder.append(BorderStyleKeys.BORDER_TOP_STYLE, BorderStyle.NONE);
}
if (sblp.getBorderLeft() > 0)
{
builder.append(BorderStyleKeys.BORDER_LEFT_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_LEFT_COLOR));
builder.append(BorderStyleKeys.BORDER_LEFT_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_LEFT_STYLE));
builder.append(BorderStyleKeys.BORDER_LEFT_WIDTH, toPointString(sblp.getBorderLeft()), "pt");
}
else if (assumeZeroBorders == false)
{
builder.append(BorderStyleKeys.BORDER_LEFT_STYLE, BorderStyle.NONE);
}
if (sblp.getBorderBottom() > 0)
{
builder.append(BorderStyleKeys.BORDER_BOTTOM_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_BOTTOM_COLOR));
builder.append(BorderStyleKeys.BORDER_BOTTOM_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_BOTTOM_STYLE));
builder.append(BorderStyleKeys.BORDER_BOTTOM_WIDTH, toPointString(sblp.getBorderBottom()), "pt");
}
else if (assumeZeroBorders == false)
{
builder.append(BorderStyleKeys.BORDER_BOTTOM_STYLE, BorderStyle.NONE);
}
if (sblp.getBorderRight() > 0)
{
builder.append(BorderStyleKeys.BORDER_RIGHT_COLOR, layoutContext.getValue(BorderStyleKeys.BORDER_RIGHT_COLOR));
builder.append(BorderStyleKeys.BORDER_RIGHT_STYLE, layoutContext.getValue(BorderStyleKeys.BORDER_RIGHT_STYLE));
builder.append(BorderStyleKeys.BORDER_RIGHT_WIDTH, toPointString(sblp.getBorderRight()), "pt");
}
else if (assumeZeroBorders == false)
{
builder.append(BorderStyleKeys.BORDER_RIGHT_STYLE, BorderStyle.NONE);