]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1.) Chris Bowditch's patch on padding-start implemented. (Changes were
authorGlen Mazza <gmazza@apache.org>
Mon, 24 Nov 2003 19:07:35 +0000 (19:07 +0000)
committerGlen Mazza <gmazza@apache.org>
Mon, 24 Nov 2003 19:07:35 +0000 (19:07 +0000)
extended to implement part of padding-end as well.)

2.) Switched from TOP/BOTTOM/LEFT/RIGHT to BEFORE/AFTER/START/END
in CommonBorderAndPadding--this is more appropriate for BlockLayout,
also the various places calling it already were either (1) commenting
on the need to switch to the above, or (2) placing the results of the
above functions using the former constants into variables emphasizing
the latter.

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

src/java/org/apache/fop/fo/InlineCharIterator.java
src/java/org/apache/fop/fo/flow/TableCell.java
src/java/org/apache/fop/fo/properties/CommonBorderAndPadding.java
src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java
src/java/org/apache/fop/layoutmgr/TraitSetter.java
src/java/org/apache/fop/render/AbstractRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java

index 065a831ed31f96ba4c4d7fee8d3b348041bd7b3a..9b0241b23693d5cb17b79f5a80443f253f2ec9ba 100644 (file)
@@ -71,11 +71,10 @@ public class InlineCharIterator extends RecursiveCharIterator {
 
 
     private void checkBoundaries(CommonBorderAndPadding bap) {
-        // TODO! use start and end in BAP!!
-        bStartBoundary = (bap.getBorderLeftWidth(false) > 0
-                       || bap.getPaddingLeft(false) > 0);
-        bEndBoundary = (bap.getBorderRightWidth(false) > 0
-                     || bap.getPaddingRight(false) > 0);
+        bStartBoundary = (bap.getBorderStartWidth(false) > 0
+                       || bap.getPaddingStart(false) > 0);
+        bEndBoundary = (bap.getBorderEndWidth(false) > 0
+                     || bap.getPaddingEnd(false) > 0);
     }
 
     /**
index c569c96835c101b40b15606c079953309b0f751a..1453a3228b67a849cda3ea2a538a5260a931f64b 100644 (file)
@@ -286,23 +286,19 @@ public class TableCell extends FObj {
              */
             int iSep = properties.get(
                     "border-separation.inline-progression-direction").getLength().getValue();
-            this.startAdjust = iSep / 2 + bp.getBorderLeftWidth(false)
-                               + bp.getPaddingLeft(false);
-            /*
-             * int contentOffset = iSep + bp.getBorderStartWidth(false) +
-             * bp.getPaddingStart(false);
-             */
+            this.startAdjust = iSep / 2 + bp.getBorderStartWidth(false)
+                               + bp.getPaddingStart(false);
+
             this.widthAdjust = startAdjust + iSep - iSep / 2
-                               + bp.getBorderRightWidth(false)
-                               + bp.getPaddingRight(false);
-            // bp.getBorderEndWidth(false) + bp.getPaddingEnd(false);
+                               + bp.getBorderEndWidth(false)
+                               + bp.getPaddingEnd(false);
+
             // Offset of content rectangle in the block-progression direction
             borderSeparation = properties.get(
                     "border-separation.block-progression-direction").getLength().getValue();
             this.beforeOffset = borderSeparation / 2
-                                + bp.getBorderTopWidth(false)
-                                + bp.getPaddingTop(false);
-            // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false);
+                                + bp.getBorderBeforeWidth(false)
+                                + bp.getPaddingBefore(false);
 
         } else {
             // System.err.println("Collapse borders");
@@ -355,16 +351,16 @@ public class TableCell extends FObj {
 
 
             /* ivan demakov */
-            int borderStart = bp.getBorderLeftWidth(false);
-            int borderEnd = bp.getBorderRightWidth(false);
-            int borderBefore = bp.getBorderTopWidth(false);
-            int borderAfter = bp.getBorderBottomWidth(false);
+            int borderStart = bp.getBorderStartWidth(false);
+            int borderEnd = bp.getBorderEndWidth(false);
+            int borderBefore = bp.getBorderBeforeWidth(false);
+            int borderAfter = bp.getBorderAfterWidth(false);
 
-            this.startAdjust = borderStart / 2 + bp.getPaddingLeft(false);
+            this.startAdjust = borderStart / 2 + bp.getPaddingStart(false);
 
             this.widthAdjust = startAdjust + borderEnd / 2
-                               + bp.getPaddingRight(false);
-            this.beforeOffset = borderBefore / 2 + bp.getPaddingTop(false);
+                               + bp.getPaddingEnd(false);
+            this.beforeOffset = borderBefore / 2 + bp.getPaddingBefore(false);
             // Half border height to fix overestimate of area size!
             this.borderHeight = (borderBefore + borderAfter) / 2;
         }
index c172bc04110515b742ee4377b8deb3ef79abd9f4..b332f2825d4b5920cd1a9bff3eea00f35947dca9 100644 (file)
@@ -64,11 +64,15 @@ public class CommonBorderAndPadding implements Cloneable {
     public static final int START = 2;
     public static final int END = 3;
 
+/*  TODO: need new definitions (below relations not always the same, 
+    also unsure if direct access of absolute properties needed; 
+    resolution of absolute & relative properties--Spec 5.3.1--can 
+    possibly be done within this class alone)
     public static final int TOP = BEFORE;
     public static final int BOTTOM = AFTER;
     public static final int LEFT = START;
     public static final int RIGHT = END;
-
+*/
     private static class ResolvedCondLength implements Cloneable {
         private int iLength; // Resolved length value
         private boolean bDiscard;
@@ -143,36 +147,36 @@ public class CommonBorderAndPadding implements Cloneable {
         borderInfo[side].mWidth.iLength = iLength;
     }
 
-    public int getBorderLeftWidth(boolean bDiscard) {
-        return getBorderWidth(LEFT, bDiscard);
+    public int getBorderStartWidth(boolean bDiscard) {
+        return getBorderWidth(START, bDiscard);
     }
 
-    public int getBorderRightWidth(boolean bDiscard) {
-        return getBorderWidth(RIGHT, bDiscard);
+    public int getBorderEndWidth(boolean bDiscard) {
+        return getBorderWidth(END, bDiscard);
     }
 
-    public int getBorderTopWidth(boolean bDiscard) {
-        return getBorderWidth(TOP, bDiscard);
+    public int getBorderBeforeWidth(boolean bDiscard) {
+        return getBorderWidth(BEFORE, bDiscard);
     }
 
-    public int getBorderBottomWidth(boolean bDiscard) {
-        return getBorderWidth(BOTTOM, bDiscard);
+    public int getBorderAfterWidth(boolean bDiscard) {
+        return getBorderWidth(AFTER, bDiscard);
     }
 
-    public int getPaddingLeft(boolean bDiscard) {
-        return getPadding(LEFT, bDiscard);
+    public int getPaddingStart(boolean bDiscard) {
+        return getPadding(START, bDiscard);
     }
 
-    public int getPaddingRight(boolean bDiscard) {
-        return getPadding(RIGHT, bDiscard);
+    public int getPaddingEnd(boolean bDiscard) {
+        return getPadding(END, bDiscard);
     }
 
-    public int getPaddingBottom(boolean bDiscard) {
-        return getPadding(BOTTOM, bDiscard);
+    public int getPaddingBefore(boolean bDiscard) {
+        return getPadding(BEFORE, bDiscard);
     }
 
-    public int getPaddingTop(boolean bDiscard) {
-        return getPadding(TOP, bDiscard);
+    public int getPaddingAfter(boolean bDiscard) {
+        return getPadding(AFTER, bDiscard);
     }
 
     public int getBorderWidth(int side, boolean bDiscard) {
@@ -211,11 +215,11 @@ public class CommonBorderAndPadding implements Cloneable {
     
     public String toString() {
         return "CommonBordersAndPadding (Before, After, Start, End):\n" +
-        "Borders: (" + getBorderTopWidth(false) + ", " + getBorderBottomWidth(false) + ", " +
-        getBorderLeftWidth(false) + ", " + getBorderRightWidth(false) + ")\n" +
+        "Borders: (" + getBorderBeforeWidth(false) + ", " + getBorderAfterWidth(false) + ", " +
+        getBorderStartWidth(false) + ", " + getBorderEndWidth(false) + ")\n" +
         "Border Colors: (" + getBorderColor(BEFORE) + ", " + getBorderColor(AFTER) + ", " +
         getBorderColor(START) + ", " + getBorderColor(END) + ")\n" +
-        "Padding: (" + getPaddingTop(false) + ", " + getPaddingBottom(false) + ", " +
-        getPaddingLeft(false) + ", " + getPaddingRight(false) + ")\n";
+        "Padding: (" + getPaddingBefore(false) + ", " + getPaddingAfter(false) + ", " +
+        getPaddingStart(false) + ", " + getPaddingEnd(false) + ")\n";
     }
 }
index 24f1efee6b23c07d17164853e4b2cef35cfe980d..83b7add6261dd9770d968b5c77170ef37bd69453 100644 (file)
@@ -190,6 +190,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager {
         LayoutProcessor curLM; // currently active LM
 
         int ipd = context.getRefIPD();
+        int iIndents = borderProps.getPaddingStart(false) 
+            + borderProps.getPaddingEnd(false);
+        ipd -= iIndents;
 
         MinOptMax stackSize = new MinOptMax();
 
index 6c0ff71e718479d3a637b0fe75edb3a6bb0a71ec..87975058dbf0f6eb7eba7c4fb939a9a02b21c23a 100644 (file)
@@ -132,19 +132,19 @@ public class TraitSetter {
      * @param bordProps border properties
      */
     public static void addBorders(Area curBlock, CommonBorderAndPadding bordProps) {
-        BorderProps bps = getBorderProps(bordProps, CommonBorderAndPadding.TOP);
+        BorderProps bps = getBorderProps(bordProps, CommonBorderAndPadding.BEFORE);
         if (bps.width != 0) {
             curBlock.addTrait(Trait.BORDER_BEFORE, bps);
         }
-        bps = getBorderProps(bordProps, CommonBorderAndPadding.BOTTOM);
+        bps = getBorderProps(bordProps, CommonBorderAndPadding.AFTER);
         if (bps.width != 0) {
             curBlock.addTrait(Trait.BORDER_AFTER, bps);
         }
-        bps = getBorderProps(bordProps, CommonBorderAndPadding.LEFT);
+        bps = getBorderProps(bordProps, CommonBorderAndPadding.START);
         if (bps.width != 0) {
             curBlock.addTrait(Trait.BORDER_START, bps);
         }
-        bps = getBorderProps(bordProps, CommonBorderAndPadding.RIGHT);
+        bps = getBorderProps(bordProps, CommonBorderAndPadding.END);
         if (bps.width != 0) {
             curBlock.addTrait(Trait.BORDER_END, bps);
         }
index 39e18e33bcbb7d3bbf92dd823c3ef44d3120fa55..c15b51e0298d49a84b1ca78648e8a9a421e21869 100644 (file)
@@ -474,6 +474,82 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         }
     }
 
+    /**
+     * Handle block traits.
+     * This method is called when the correct ip and bp posiiton is
+     * set. This should be overridden to draw border and background
+     * traits for the block area.
+     *
+     * @param block the block area
+     */
+    protected void handleBlockTraits(Block block) {
+        // draw border and background
+    }
+
+    /**
+     * Renders a block viewport.
+     *
+     * @param bv        The block viewport
+     * @param children  The children to render within the block viewport
+     */
+    protected void renderBlockViewport(BlockViewport bv, List children) {
+        // clip and position viewport if necessary
+        if (bv.getPositioning() == Block.ABSOLUTE) {
+            // save positions
+            int saveIP = currentIPPosition;
+            int saveBP = currentBPPosition;
+
+            CTM ctm = bv.getCTM();
+            currentIPPosition = 0;
+            currentBPPosition = 0;
+
+            startVParea(ctm);
+            handleBlockTraits(bv);
+            renderBlocks(children);
+            endVParea();
+
+            // clip if necessary
+
+            currentIPPosition = saveIP;
+            currentBPPosition = saveBP;
+        } else {
+            renderBlocks(children);
+        }
+    }
+
+    /**
+     * Renders a list of block areas.
+     *
+     * @param blocks  The block areas
+     */
+    protected void renderBlocks(List blocks) {
+        // the position of the containing block is used for
+        // absolutely positioned areas
+        int contBP = currentBPPosition;
+        int contIP = currentIPPosition;
+        containingBPPosition = contBP;
+        containingIPPosition = contIP;
+
+        for (int count = 0; count < blocks.size(); count++) {
+            Object obj = blocks.get(count);
+            if (obj instanceof Block) {
+                containingBPPosition = contBP;
+                containingIPPosition = contIP;
+                renderBlock((Block) obj);
+                containingBPPosition = contBP;
+                containingIPPosition = contIP;
+            } else {
+                // a line area is rendered from the top left position
+                // of the line, each inline object is offset from there
+                LineArea line = (LineArea) obj;
+                currentBlockIPPosition =
+                        currentIPPosition + line.getStartIndent();
+                renderLineArea(line);
+                currentBPPosition += line.getHeight();
+            }
+        }
+    }
+
     /**
      * Renders a block area.
      *
@@ -518,49 +594,6 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         }
     }
 
-    /**
-     * Handle block traits.
-     * This method is called when the correct ip and bp posiiton is
-     * set. This should be overridden to draw border and background
-     * traits for the block area.
-     *
-     * @param block the block area
-     */
-    protected void handleBlockTraits(Block block) {
-        // draw border and background
-    }
-
-    /**
-     * Renders a block viewport.
-     *
-     * @param bv        The block viewport
-     * @param children  The children to render within the block viewport
-     */
-    protected void renderBlockViewport(BlockViewport bv, List children) {
-        // clip and position viewport if necessary
-        if (bv.getPositioning() == Block.ABSOLUTE) {
-            // save positions
-            int saveIP = currentIPPosition;
-            int saveBP = currentBPPosition;
-
-            CTM ctm = bv.getCTM();
-            currentIPPosition = 0;
-            currentBPPosition = 0;
-
-            startVParea(ctm);
-            handleBlockTraits(bv);
-            renderBlocks(children);
-            endVParea();
-
-            // clip if necessary
-
-            currentIPPosition = saveIP;
-            currentBPPosition = saveBP;
-        } else {
-            renderBlocks(children);
-        }
-    }
-
     /**
      * Renders a line area. <p>
      *
@@ -667,39 +700,6 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         currentBlockIPPosition = saveIP + ip.getWidth();
     }
 
-    /**
-     * Renders a list of block areas.
-     *
-     * @param blocks  The block areas
-     */
-    protected void renderBlocks(List blocks) {
-        // the position of the containing block is used for
-        // absolutely positioned areas
-        int contBP = currentBPPosition;
-        int contIP = currentIPPosition;
-        containingBPPosition = contBP;
-        containingIPPosition = contIP;
-
-        for (int count = 0; count < blocks.size(); count++) {
-            Object obj = blocks.get(count);
-            if (obj instanceof Block) {
-                containingBPPosition = contBP;
-                containingIPPosition = contIP;
-                renderBlock((Block) obj);
-                containingBPPosition = contBP;
-                containingIPPosition = contIP;
-            } else {
-                // a line area is rendered from the top left position
-                // of the line, each inline object is offset from there
-                LineArea line = (LineArea) obj;
-                currentBlockIPPosition =
-                        currentIPPosition + line.getStartIndent();
-                renderLineArea(line);
-                currentBPPosition += line.getHeight();
-            }
-        }
-    }
-
     /**
      * Set the default xml handler for the given mime type.
      * @param mime MIME type
index 5ee316c0fe7bacad55b2503b5dd8bc3b0dc876cd..7327960fbe5db51b30b3d643de91b27559fae8b9 100644 (file)
@@ -227,12 +227,14 @@ public class PDFRenderer extends PrintRenderer {
     private StringBuffer wordAreaPDF = new StringBuffer();
 
     /**
-     * Offset for rendering text, taking into account borders and padding
+     * Offset for rendering text, taking into account borders and padding for
+     * both region and block.
      */
     protected int BPMarginOffset = 0;
 
     /**
-     * Offset for rendering text, taking into account borders and padding
+     * Offset for rendering text, taking into account borders and padding for 
+     * both the region and block.
      */
     protected int IPMarginOffset = 0;
 
@@ -503,19 +505,15 @@ public class PDFRenderer extends PrintRenderer {
     }
 
     /**
-     * Handle block traits.
-     * The block could be any sort of block with any positioning
-     * so this should render the traits such as border and background
-     * in its position.
-     *
-     * @param block the block to render the traits
+     * @see org.apache.fop.render.AbstractRenderer#renderBlock(Block)
      */
-    protected void handleBlockTraits(Block block) {
-        float startx = (currentIPPosition + IPMarginOffset)/ 1000f;
-        float starty = (currentBPPosition + BPMarginOffset)/ 1000f;
-        drawBackAndBorders(block, startx, starty,
-            block.getWidth() / 1000f, block.getHeight() / 1000f);
-    }
+    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;
+       }
 
     /**
      * Handle the traits for a region
@@ -531,9 +529,9 @@ public class PDFRenderer extends PrintRenderer {
         float width = (float)(viewArea.getWidth() / 1000f);
         float height = (float)(viewArea.getHeight() / 1000f);
 
-        if (region.getRegion().getRegionClass() 
+        if (region.getRegion().getRegionClass()
             == org.apache.fop.fo.pagination.Region.BODY_CODE)
-        {   
+        {
             BPMarginOffset = region.getBorderAndPaddingWidthBefore();
             IPMarginOffset = region.getBorderAndPaddingWidthStart();
         }
@@ -541,6 +539,29 @@ public class PDFRenderer extends PrintRenderer {
         drawBackAndBorders(region, startx, starty, width, height);
     }
 
+    /**
+     * Handle block traits.
+     * The block could be any sort of block with any positioning
+     * so this should render the traits such as border and background
+     * in its position.
+     *
+     * @param block the block to render the traits
+     */
+    protected void handleBlockTraits(Block block) {
+               /*  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;
+        drawBackAndBorders(block, startx, starty,
+            block.getWidth() / 1000f, block.getHeight() / 1000f);
+    }
+
     /**
      * Draw the background and borders.
      * This draws the background and border traits for an area given
@@ -888,7 +909,7 @@ public class PDFRenderer extends PrintRenderer {
         }
 
         // word.getOffset() = only height of text itself
-        // currentBlockIPPosition: 0 for beginning of line; nonzero 
+        // currentBlockIPPosition: 0 for beginning of line; nonzero
         //  where previous line area failed to take up entire allocated space
         int rx = currentBlockIPPosition + IPMarginOffset;
         int bl = currentBPPosition + BPMarginOffset + text.getOffset();