From bfe531f652d5ae10892b60531ae90b01e41885cd Mon Sep 17 00:00:00 2001 From: Glen Mazza Date: Sat, 1 Nov 2003 21:05:23 +0000 Subject: [PATCH] 1. PDF block background rendering properly offset to account for region borders and padding. 2. Helper methods added to RegionViewport for quickly determining region margins, useful for render.* and layoutmgr.* classes. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196977 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/area/RegionViewport.java | 87 +++++++++++++++++++ .../fop/layoutmgr/PageLayoutManager.java | 50 +---------- .../apache/fop/render/pdf/PDFRenderer.java | 33 ++----- 3 files changed, 97 insertions(+), 73 deletions(-) diff --git a/src/java/org/apache/fop/area/RegionViewport.java b/src/java/org/apache/fop/area/RegionViewport.java index b4f5d5a85..53ffa28e4 100644 --- a/src/java/org/apache/fop/area/RegionViewport.java +++ b/src/java/org/apache/fop/area/RegionViewport.java @@ -54,6 +54,8 @@ import java.awt.geom.Rectangle2D; 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. @@ -109,6 +111,91 @@ public class RegionViewport extends Area implements Cloneable { 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()); diff --git a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java index 00899dc6e..acc842778 100644 --- a/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -84,7 +84,6 @@ import org.apache.fop.fo.properties.CommonBorderAndPadding; 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; @@ -475,29 +474,8 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable 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; } @@ -735,29 +713,9 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable // 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); diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderer.java b/src/java/org/apache/fop/render/pdf/PDFRenderer.java index d95073372..806ea0f95 100644 --- a/src/java/org/apache/fop/render/pdf/PDFRenderer.java +++ b/src/java/org/apache/fop/render/pdf/PDFRenderer.java @@ -128,7 +128,7 @@ background pattern writing mode text decoration - */ +*/ /** * Renderer that renders areas to PDF @@ -511,10 +511,10 @@ public class PDFRenderer extends PrintRenderer { * @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); } /** @@ -537,29 +537,8 @@ public class PDFRenderer extends PrintRenderer { 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); -- 2.39.5