import java.io.IOException;
import java.util.HashMap;
+import org.apache.fop.traits.BorderProps;
+
/**
* Region Viewport reference area.
* This area is the viewport for a region and contains a region area.
return viewArea;
}
+ /**
+ * Return the margin-before offset for printing text
+ * (sum of region border and padding)
+ *
+ * @return margin-before offset, in millipoints
+ */
+ public int getMarginBeforeWidth() {
+ int margin = 0;
+ BorderProps bps = (BorderProps) getTrait(Trait.BORDER_BEFORE);
+ if (bps != null) {
+ margin = bps.width;
+ }
+
+ Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE);
+ if (padWidth != null) {
+ margin += padWidth.intValue();
+ }
+
+ return margin;
+ }
+
+ /**
+ * Return the margin-after offset for printing text
+ * (sum of region border and padding)
+ *
+ * @return margin-after offset, in millipoints
+ */
+ public int getMarginAfterWidth() {
+ int margin = 0;
+
+ BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER);
+ if (bps != null) {
+ margin = bps.width;
+ }
+
+ Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER);
+ if (padWidth != null) {
+ margin += padWidth.intValue();
+ }
+
+ return margin;
+ }
+
+ /**
+ * Return the margin-start offset for printing text
+ * (sum of region border and padding)
+ *
+ * @return margin-start offset, in millipoints
+ */
+ public int getMarginStartWidth() {
+ int margin = 0;
+ BorderProps bps = (BorderProps) getTrait(Trait.BORDER_START);
+ if (bps != null) {
+ margin = bps.width;
+ }
+
+ Integer padWidth = (Integer) getTrait(Trait.PADDING_START);
+ if (padWidth != null) {
+ margin += padWidth.intValue();
+ }
+
+ return margin;
+ }
+
+ /**
+ * Return the margin-end offset for printing text
+ * (sum of region border and padding)
+ *
+ * @return margin-end offset, in millipoints
+ */
+ public int getMarginEndWidth() {
+ int margin = 0;
+ BorderProps bps = (BorderProps) getTrait(Trait.BORDER_END);
+ if (bps != null) {
+ margin = bps.width;
+ }
+
+ Integer padWidth = (Integer) getTrait(Trait.PADDING_END);
+ if (padWidth != null) {
+ margin += padWidth.intValue();
+ }
+
+ return margin;
+ }
+
private void writeObject(java.io.ObjectOutputStream out)
throws IOException {
out.writeFloat((float) viewArea.getX());
import org.apache.fop.fo.properties.CommonMarginBlock;
import org.apache.fop.fo.properties.Constants;
import org.apache.fop.fo.properties.Overflow;
-import org.apache.fop.traits.BorderProps;
import java.util.ArrayList;
import java.util.List;
RegionViewport rv = curPage.getPage().getRegionViewport(
Region.BODY_CODE);
curBody = (BodyRegion) rv.getRegion();
- flowBPD = (int) rv.getViewArea().getHeight();
-
- // adjust flowBPD for borders and padding
- BorderProps bps = (BorderProps) rv.getTrait(Trait.BORDER_BEFORE);
- if (bps != null) {
- flowBPD -= bps.width;
- }
-
- bps = (BorderProps) rv.getTrait(Trait.BORDER_AFTER);
- if (bps != null) {
- flowBPD -= bps.width;
- }
-
- java.lang.Integer padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_BEFORE);
- if (padWidth != null) {
- flowBPD -= padWidth.intValue();
- }
-
- padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_AFTER);
- if (padWidth != null) {
- flowBPD -= padWidth.intValue();
- }
-
+ flowBPD = (int) rv.getViewArea().getHeight() -
+ rv.getMarginBeforeWidth() - rv.getMarginAfterWidth();
return curPage;
}
// get Width or Height as IPD for span
RegionViewport rv = curPage.getPage().getRegionViewport(Region.BODY_CODE);
- int ipdWidth = (int) rv.getViewArea().getWidth();
-
- // adjust IPD for borders and padding
- BorderProps bps = (BorderProps) rv.getTrait(Trait.BORDER_START);
- if (bps != null) {
- ipdWidth -= bps.width;
- }
-
- bps = (BorderProps) rv.getTrait(Trait.BORDER_END);
- if (bps != null) {
- ipdWidth -= bps.width;
- }
-
- java.lang.Integer padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_START);
- if (padWidth != null) {
- ipdWidth -= padWidth.intValue();
- }
+ int ipdWidth = (int) rv.getViewArea().getWidth() -
+ rv.getMarginStartWidth() - rv.getMarginEndWidth();
- padWidth = (java.lang.Integer) rv.getTrait(Trait.PADDING_END);
- if (padWidth != null) {
- ipdWidth -= padWidth.intValue();
- }
-
curSpan.setIPD(ipdWidth);
//curSpan.setPosition(BPD, newpos);
curBody.getMainReference().addSpan(curSpan);
writing mode
text decoration
- */
+*/
/**
* Renderer that renders areas to PDF
* @param block the block to render the traits
*/
protected void handleBlockTraits(Block block) {
- float startx = currentIPPosition / 1000f;
- float starty = currentBPPosition / 1000f;
+ float startx = (currentIPPosition + IPMarginOffset)/ 1000f;
+ float starty = (currentBPPosition + BPMarginOffset)/ 1000f;
drawBackAndBorders(block, startx, starty,
- block.getWidth() / 1000f, block.getHeight() / 1000f);
+ block.getWidth() / 1000f, block.getHeight() / 1000f);
}
/**
if (region.getRegion().getRegionClass() == org.apache.fop.fo.pagination.Region.BODY_CODE)
{
- // need to collect vertical and horizontal offsets
- // for body-region (for rendering of text)
- BorderProps bps = (BorderProps) region.getTrait(Trait.BORDER_BEFORE);
- if (bps != null) {
- BPMarginOffset = bps.width;
- }
-
- bps = (BorderProps) region.getTrait(Trait.BORDER_START);
- if (bps != null) {
- IPMarginOffset = bps.width;
- }
-
- java.lang.Integer padWidth = (java.lang.Integer)
- region.getTrait(Trait.PADDING_BEFORE);
- if (padWidth != null) {
- BPMarginOffset += padWidth.intValue();
- }
-
- padWidth = (java.lang.Integer)
- region.getTrait(Trait.PADDING_START);
- if (padWidth != null) {
- IPMarginOffset += padWidth.intValue();
- }
+ BPMarginOffset = region.getMarginBeforeWidth();
+ IPMarginOffset = region.getMarginStartWidth();
}
drawBackAndBorders(region, startx, starty, width, height);