]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1. PDF block background rendering properly offset to account for region
authorGlen Mazza <gmazza@apache.org>
Sat, 1 Nov 2003 21:05:23 +0000 (21:05 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 1 Nov 2003 21:05:23 +0000 (21:05 +0000)
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

src/java/org/apache/fop/area/RegionViewport.java
src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java

index b4f5d5a85c2ffe230d63707a2e814497f34842f1..53ffa28e46d3aa9bf80441111e0ea86e42a8ccac 100644 (file)
@@ -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());
index 00899dc6e17ef2821401fb72da5443c86e29ec33..acc842778fe9d577812f3267cdc66afa414fffeb 100644 (file)
@@ -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);
index d950733725da83346027f90c8963301f172c3827..806ea0f958b679f28b4bad05a3efcc51c40a3376 100644 (file)
@@ -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);