]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Handle SPACE_START trait for block areas.
authorFinn Bock <bckfnn@apache.org>
Thu, 29 Jan 2004 19:45:48 +0000 (19:45 +0000)
committerFinn Bock <bckfnn@apache.org>
Thu, 29 Jan 2004 19:45:48 +0000 (19:45 +0000)
PR: 25802.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197296 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/AbstractRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java
src/java/org/apache/fop/render/ps/PSRenderer.java

index bdc9248642816141fb71bd26fe22f2e6d80e5c3c..13b874379a8d076950d2e5ee3360f31a57032a60 100644 (file)
@@ -374,7 +374,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
     protected void renderRegion(RegionReference region) {
         List blocks = region.getBlocks();
 
-        renderBlocks(blocks);
+        renderBlocks(null, blocks);
 
     }
 
@@ -406,7 +406,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
     protected void renderBeforeFloat(BeforeFloat bf) {
         List blocks = bf.getChildAreas();
         if (blocks != null) {
-            renderBlocks(blocks);
+            renderBlocks(null, blocks);
             Block sep = bf.getSeparator();
             if (sep != null) {
                 renderBlock(sep);
@@ -426,7 +426,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
             if (sep != null) {
                 renderBlock(sep);
             }
-            renderBlocks(blocks);
+            renderBlocks(null, blocks);
         }
     }
 
@@ -471,7 +471,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         // the normal flow reference area contains stacked blocks
         List blocks = flow.getChildAreas();
         if (blocks != null) {
-            renderBlocks(blocks);
+            renderBlocks(null, blocks);
         }
     }
 
@@ -506,7 +506,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
 
             startVParea(ctm);
             handleBlockTraits(bv);
-            renderBlocks(children);
+            renderBlocks(bv, children);
             endVParea();
 
             // clip if necessary
@@ -514,16 +514,26 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
             currentIPPosition = saveIP;
             currentBPPosition = saveBP;
         } else {
-            renderBlocks(children);
+            // save position and offset
+            int saveIP = currentIPPosition;
+            int saveBP = currentBPPosition;
+
+            handleBlockTraits(bv);
+            renderBlocks(bv, children);
+
+            currentIPPosition = saveIP;
+            currentBPPosition = saveBP + bv.getHeight();
         }
     }
 
     /**
      * Renders a list of block areas.
      *
+     * @param parent  the parent block if the parent is a block, otherwise
+     *                a null value. 
      * @param blocks  The block areas
      */
-    protected void renderBlocks(List blocks) {
+    protected void renderBlocks(Block parent, List blocks) {
         // the position of the containing block is used for
         // absolutely positioned areas
         int contBP = currentBPPosition;
@@ -575,7 +585,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
 
                 handleBlockTraits(block);
 
-                renderBlocks(children);
+                renderBlocks(block, children);
 
                 // absolute blocks do not effect the layout
                 currentBPPosition = saveBP;
@@ -586,7 +596,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
 
                 handleBlockTraits(block);
 
-                renderBlocks(children);
+                renderBlocks(block, children);
 
                 // stacked and relative blocks effect stacking
                 currentBPPosition = saveBP + block.getHeight();
@@ -649,7 +659,7 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         int saveBP = currentBPPosition;
 
         List blocks = cont.getBlocks();
-        renderBlocks(blocks);
+        renderBlocks(null, blocks);
         currentIPPosition = saveIP;
         currentBlockIPPosition = saveBlockIP;
         currentBPPosition = saveBP;
index 571f14a6e419336dba3fe6f84d49abb37c366756..de20910ed3f2e52df51486fe4d65918ad0026593 100644 (file)
@@ -504,15 +504,39 @@ public class PDFRenderer extends PrintRenderer {
     }
 
     /**
-     * @see org.apache.fop.render.AbstractRenderer#renderBlock(Block)
+     * @see org.apache.fop.render.AbstractRenderer#renderBlocks(Block, List)
      */
-    protected void renderBlock(Block block) {
-        int marginOffset = IPMarginOffset;
-        super.renderBlock(block);
-        // super.renderBlock() may render child blocks (with their own offsets)
-        // so need to restore (this parent's) IPMarginOffset when finished.
-        IPMarginOffset = marginOffset;
-       }
+    protected void renderBlocks(Block block, List blocks) {
+        int saveIPMargin = IPMarginOffset;
+        int saveBPMargin = BPMarginOffset;
+        if (block != null) {
+            Integer spaceStart = (Integer) block.getTrait(Trait.SPACE_START); 
+            if (spaceStart != null) {
+                IPMarginOffset += spaceStart.intValue();
+            }
+
+            Integer paddingStart = (Integer) block.getTrait(Trait.PADDING_START);
+            if (paddingStart != null) {
+                IPMarginOffset += paddingStart.intValue();
+            }
+            Integer paddingBefore= (Integer) block.getTrait(Trait.PADDING_BEFORE);
+            if (paddingBefore != null) {
+                BPMarginOffset += paddingBefore.intValue();
+            }
+
+            BorderProps borderStartWidth = (BorderProps) block.getTrait(Trait.BORDER_START);
+            if (borderStartWidth != null) {
+                IPMarginOffset += borderStartWidth.width;
+            }
+            BorderProps borderBeforeWidth = (BorderProps) block.getTrait(Trait.BORDER_BEFORE);
+            if (borderBeforeWidth != null) {
+                BPMarginOffset += borderBeforeWidth.width;
+            }
+        }
+        super.renderBlocks(block, blocks);
+        IPMarginOffset = saveIPMargin;
+        BPMarginOffset = saveBPMargin;
+    }
 
     /**
      * Handle the traits for a region
@@ -550,15 +574,23 @@ public class PDFRenderer extends PrintRenderer {
                /*  IPMarginOffset for a particular block = region border + 
          *  region padding + parent block padding + current block padding
          */
-        Integer paddingStart = (Integer) block.getTrait(Trait.PADDING_START);
-        if (paddingStart != null) {
-            IPMarginOffset += paddingStart.intValue();
-        }
 
         float startx = (currentIPPosition + IPMarginOffset) / 1000f;
         float starty = (currentBPPosition + BPMarginOffset) / 1000f;
+        float width = block.getWidth() / 1000f;
+
+        Integer spaceStart = (Integer) block.getTrait(Trait.SPACE_START); 
+        if (spaceStart != null) {
+            startx += spaceStart.floatValue() / 1000;
+            width -= spaceStart.floatValue() / 1000;
+        }
+        Integer spaceEnd = (Integer) block.getTrait(Trait.SPACE_END); 
+        if (spaceEnd != null) {
+            width -= spaceEnd.floatValue() / 1000;
+        }
+
         drawBackAndBorders(block, startx, starty,
-            block.getWidth() / 1000f, block.getHeight() / 1000f);
+            width, block.getHeight() / 1000f);
     }
 
     /**
@@ -730,7 +762,7 @@ public class PDFRenderer extends PrintRenderer {
 
             startVParea(ctm);
             handleBlockTraits(bv);
-            renderBlocks(children);
+            renderBlocks(bv, children);
             endVParea();
 
             if (bv.getClip()) {
@@ -780,7 +812,7 @@ public class PDFRenderer extends PrintRenderer {
                 startVParea(ctm);
             }
             handleBlockTraits(bv);
-            renderBlocks(children);
+            renderBlocks(bv, children);
             if (ctm != null) {
                 endVParea();
             }
@@ -836,8 +868,8 @@ public class PDFRenderer extends PrintRenderer {
      * @param ip the inline parent area
      */
     public void renderInlineParent(InlineParent ip) {
-        float start = currentBlockIPPosition / 1000f;
-        float top = (ip.getOffset() + currentBPPosition) / 1000f;
+        float start = (currentBlockIPPosition + IPMarginOffset) / 1000f;
+        float top = (ip.getOffset() + currentBPPosition + BPMarginOffset) / 1000f;
         float width = ip.getWidth() / 1000f;
         float height = ip.getHeight() / 1000f;
         drawBackAndBorders(ip, start, top, width, height);
@@ -1175,11 +1207,10 @@ public class PDFRenderer extends PrintRenderer {
         saveGraphicsState();
         currentStream.add(((float) w) + " 0 0 "
                           + ((float) -h) + " "
-                          + (((float) currentBlockIPPosition) / 1000f + x) + " "
-                          + (((float)(currentBPPosition + 1000 * h)) / 1000f
+                          + (((float) currentBlockIPPosition + IPMarginOffset) / 1000f + x) + " "
+                          + (((float)(currentBPPosition + BPMarginOffset + 1000 * h)) / 1000f
                           + y) + " cm\n" + "/Im" + xobj + " Do\n");
         restoreGraphicsState();
-
     }
 
     /**
index bc2062b7d987c1f210527d85b63811ff6a77edd4..724f5df069e0916a03dc08f9d0019667065a19df 100644 (file)
@@ -565,7 +565,7 @@ public class PSRenderer extends AbstractRenderer {
 
             startVParea(ctm);
             handleBlockTraits(bv);
-            renderBlocks(children);
+            renderBlocks(bv, children);
             endVParea();
 
             if (bv.getClip()) {
@@ -615,7 +615,7 @@ public class PSRenderer extends AbstractRenderer {
                 startVParea(ctm);
             }
             handleBlockTraits(bv);
-            renderBlocks(children);
+            renderBlocks(bv, children);
             if (ctm != null) {
                 endVParea();
             }