boolean needBefore, boolean needAfter) {
// This method uses dummy large extents
// A later step fixes them.
SimplePageMaster spm = getFactory().createSimplePageMaster();
spm.setMasterName(masterName);
// dimensions.
// <w:pgSz w:w="12240" w:h="15840"/>
// <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
spm.setPageHeight( UnitsOfMeasurement.twipToBest(page.getPgSz().getH().intValue() ));
spm.setPageWidth( UnitsOfMeasurement.twipToBest(page.getPgSz().getW().intValue() ));
spm.setMarginLeft( UnitsOfMeasurement.twipToBest(page.getPgMar().getLeft().intValue() ) );
spm.setMarginRight( UnitsOfMeasurement.twipToBest(page.getPgMar().getRight().intValue()) );
/*
* Region before & after live in region body margins:
*
* Per http://www.w3.org/TR/xsl/#fo_region-body
*
* The body region should be sized and positioned within the fo:simple-page-master
* so that there is room for the areas returned by the flow that is assigned to the
* fo:region-body and for any desired side regions, that is, fo:region-before,
* fo:region-after, fo:region-start and fo:region-end's that are to be placed on the same page.
*
* These side regions are positioned within the content-rectangle of the page-reference-area.
* The margins on the fo:region-body are used to position the region-viewport-area for the
* fo:region-body and to leave space for the other regions that surround the fo:region-body.
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*
* The spacing between the last four regions and the fo:region-body is determined by subtracting
* the relevant extent trait on the side regions from the trait that corresponds to the "margin-x"
* property on the fo:region-body.
*/
RegionBody rb = getFactory().createRegionBody();
rb.setMarginLeft("0mm");
rb.setMarginRight("0mm");
float halfPageHeight = page.getPgSz().getH().intValue()/40; // convert from twips, then * 0.5
String halfPageHeightPts = halfPageHeight + "pt";
spm.setRegionBody(rb);
if (needBefore) {
//Header
RegionBefore rBefore = getFactory().createRegionBefore();
rBefore.setRegionName("xsl-region-before-"+appendRegionName);
spm.setRegionBefore(rBefore);
// Margin top on SPM is space between the page edge and the start of the header
int marginTopTwips
= page.getHeaderMargin();
spm.setMarginTop( UnitsOfMeasurement.twipToBest(marginTopTwips ) );
// Size header manually
rBefore.setExtent( halfPageHeightPts); // A4 portrait is 297mm high
// Leave room for this region in body margin
rb.setMarginTop(halfPageHeightPts);
} else {
// No header
spm.setMarginTop( UnitsOfMeasurement.twipToBest(page.getPgMar().getTop().intValue() ) );
}
if (needAfter) {
// Footer
RegionAfter rAfter = getFactory().createRegionAfter();
rAfter.setRegionName("xsl-region-after-"+appendRegionName);
spm.setRegionAfter(rAfter);
int marginBottomTwips= page.getFooterMargin();
spm.setMarginBottom( UnitsOfMeasurement.twipToBest(marginBottomTwips) );
// Size footer manually
rAfter.setExtent( halfPageHeightPts); // A4 portrait is 297mm high
// Leave room for this region in body margin
rb.setMarginBottom(halfPageHeightPts );
} else {
// No footer
spm.setMarginBottom( UnitsOfMeasurement.twipToBest(page.getPgMar().getBottom().intValue()) );
}
return spm;
}