/** convert xsl:fo attributes to RTF text attributes */
static RtfAttributes convertPageAttributes(SimplePageMaster pagemaster) {
FOPRtfAttributes attrib = new FOPRtfAttributes();
try {
RegionBA before = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_BEFORE);
RegionBody body = (RegionBody) pagemaster.getRegion(Constants.FO_REGION_BODY);
RegionBA after = (RegionBA) pagemaster.getRegion(Constants.FO_REGION_AFTER);
attrib.setTwips(RtfPage.PAGE_WIDTH, pagemaster.getPageWidth());
attrib.setTwips(RtfPage.PAGE_HEIGHT, pagemaster.getPageHeight());
//Sets the document level property
attrib.set(RtfPage.ITAP, "0");
Object widthRaw = attrib.getValue(RtfPage.PAGE_WIDTH);
Object heightRaw = attrib.getValue(RtfPage.PAGE_HEIGHT);
if ((widthRaw instanceof Integer) && (heightRaw instanceof Integer)
&& ((Integer) widthRaw).intValue() > ((Integer) heightRaw).intValue()) {
attrib.set(RtfPage.LANDSCAPE);
}
Length pageTop = pagemaster.getCommonMarginBlock().marginTop;
Length pageBottom = pagemaster.getCommonMarginBlock().marginBottom;
Length pageLeft = pagemaster.getCommonMarginBlock().marginLeft;
Length pageRight = pagemaster.getCommonMarginBlock().marginRight;
Length bodyTop = pageTop;
Length bodyBottom = pageBottom;
Length bodyLeft = pageLeft;
Length bodyRight = pageRight;
if (body != null) {
// Should perhaps be replaced by full reference-area handling.
CommonMarginBlock bodyMargin = body.getCommonMarginBlock();
bodyTop = (Length) NumericOp.addition(pageTop, bodyMargin.marginTop);
bodyBottom = (Length) NumericOp.addition(pageBottom, bodyMargin.marginBottom);
bodyLeft = (Length) NumericOp.addition(pageLeft, bodyMargin.marginLeft);
bodyRight = (Length) NumericOp.addition(pageRight, bodyMargin.marginRight);
}
attrib.setTwips(RtfPage.MARGIN_TOP, bodyTop);
attrib.setTwips(RtfPage.MARGIN_BOTTOM, bodyBottom);
attrib.setTwips(RtfPage.MARGIN_LEFT, bodyLeft);
attrib.setTwips(RtfPage.MARGIN_RIGHT, bodyRight);
//region-before attributes
Length beforeTop = pageTop;
if (before != null) {
beforeTop = (Length) NumericOp.addition(pageTop, before.getExtent());
}
attrib.setTwips(RtfPage.HEADERY, beforeTop);
//region-after attributes
Length afterBottom = pageBottom;
if (after != null) {
afterBottom = (Length) NumericOp.addition(pageBottom, after.getExtent());
}
attrib.setTwips(RtfPage.FOOTERY, afterBottom);
} catch (Exception e) {
log.error("Exception in convertPageAttributes: "
+ e.getMessage() + "- page attributes ignored");