]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
block-containers improved/fixed. The following features are implemented and testcases...
authorJeremias Maerki <jeremias@apache.org>
Mon, 17 Jan 2005 10:38:02 +0000 (10:38 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 17 Jan 2005 10:38:02 +0000 (10:38 +0000)
left, right, top, bottom, width, height, block-progression-dimension (partial), inline-progression-dimension (partial), borders, padding, indents, reference-orientation.
autoheight works only for in-flow BCs ATM.

start-indent calculation fixed: uses inherited value if rules in 5.3.2 don't apply.

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

src/java/org/apache/fop/fo/properties/CorrespondingPropertyMaker.java
src/java/org/apache/fop/fo/properties/IndentPropertyMaker.java
src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java
src/java/org/apache/fop/render/AbstractRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java

index a3f0a422334b6cc35087e74cd20ba105b6ab5412..8603cc2eca9eeaeada2751b2c724d18924d9c202 100644 (file)
@@ -76,13 +76,14 @@ public class CorrespondingPropertyMaker {
         }
         
         PropertyList pList = getWMPropertyList(propertyList);
-        int correspondingId = pList.getWritingMode(lr_tb, rl_tb, tb_rl);
+        if (pList != null) {
+            int correspondingId = pList.getWritingMode(lr_tb, rl_tb, tb_rl);
         
-        if (pList.getExplicit(correspondingId) != null) {
-            return true;
-        } else {
-            return false;
-        }
+            if (pList.getExplicit(correspondingId) != null) {
+                return true;
+            }
+        } 
+        return false;
     }
     
     /**
index a3c03f1664e27a79f7361f930bf344a975a5031c..cad9c2e7adb98afe49835db70506392c6784ff33 100644 (file)
@@ -69,6 +69,9 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
      */
     public Property compute(PropertyList propertyList) throws PropertyException {
         PropertyList pList = getWMPropertyList(propertyList);
+        if (pList == null) {
+            return null;
+        }
         // Calculate the values as described in 5.3.2.
 
         Numeric padding = getCorresponding(paddingCorresponding, propertyList).getNumeric();
@@ -80,7 +83,14 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
         if (propertyList.getExplicitOrShorthand(marginProp) == null) {
             Property indent = propertyList.getExplicit(baseMaker.propId);
             if (indent == null) {
-                margin = new FixedLength(0);
+                //Neither start-indent nor margin is specified, use inherited
+                //margin = new FixedLength(0);
+                /*
+                Numeric v = new FixedLength(0);
+                v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric());
+                return (Property)v;
+                */
+                return null;
             } else {
                 margin = propertyList.getExplicit(baseMaker.propId).getNumeric();
                 margin = NumericOp.subtraction(margin, 
@@ -95,7 +105,9 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
         Numeric v = new FixedLength(0);
         if (!propertyList.getFObj().generatesReferenceAreas()) {
             // The inherited_value_of([start|end]-indent)
-            v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric());
+            //if (!propertyList.getParentFObj().generatesReferenceAreas()) {
+                v = NumericOp.addition(v, propertyList.getInherited(baseMaker.propId).getNumeric());
+            //}
         }
         // The corresponding absolute margin-[right|left}.
         v = NumericOp.addition(v, margin);
@@ -107,7 +119,11 @@ public class IndentPropertyMaker extends CorrespondingPropertyMaker {
     private Property getCorresponding(int[] corresponding, PropertyList propertyList)
                 throws PropertyException {
         PropertyList pList = getWMPropertyList(propertyList);
-        int wmcorr = pList.getWritingMode(corresponding[0], corresponding[1], corresponding[2]);
-        return propertyList.get(wmcorr);
+        if (pList != null) {
+            int wmcorr = pList.getWritingMode(corresponding[0], corresponding[1], corresponding[2]);
+            return propertyList.get(wmcorr);
+        } else {
+            return null;
+        }
     }
 }
index 7e98ee5adec165bf0d0f6bfbc57557bc2ea7d50a..84d1fa5f08bdae43615986fe16b0ab19fb653b7b 100644 (file)
 package org.apache.fop.layoutmgr;
 
 import java.util.List;
+import java.awt.Point;
 import java.awt.geom.Rectangle2D;
 
 import org.apache.fop.area.Area;
 import org.apache.fop.area.BlockViewport;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.PageViewport;
-import org.apache.fop.fo.Constants;
+import org.apache.fop.area.Trait;
 import org.apache.fop.fo.flow.BlockContainer;
 import org.apache.fop.fo.properties.CommonAbsolutePosition;
-import org.apache.fop.fo.properties.FixedLength;
 import org.apache.fop.area.CTM;
 import org.apache.fop.datatypes.FODimension;
 import org.apache.fop.datatypes.Length;
@@ -52,6 +52,8 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
     private boolean clip = false;
     private Length width;
     private Length height;
+    private int vpContentIPD;
+    private int vpContentBPD;
 
     // When viewport should grow with the content.
     private boolean autoHeight = true; 
@@ -67,6 +69,9 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
         fobj = node;
     }
     
+    /**
+     * @return the currently applicable page viewport
+     */
     protected PageViewport getPageViewport() {
         LayoutManager lm = this;
         while (lm != null && !(lm instanceof PageSequenceLayoutManager)) {
@@ -83,74 +88,14 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
      * @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties()
      */
     protected void initProperties() {
-        log.debug(fobj.getBlockProgressionDimension().getOptimum());
-        log.debug(fobj.getInlineProgressionDimension().getOptimum());
         abProps = fobj.getCommonAbsolutePosition();
-        log.debug(abProps);
-        
-        int iIndents = fobj.getCommonMarginBlock().startIndent.getValue();
-        iIndents += fobj.getCommonMarginBlock().endIndent.getValue();
-        int bIndents = fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false);
-
-        
-        if (abProps.absolutePosition == EN_ABSOLUTE && false) {
-            Rectangle2D rect = new Rectangle2D.Double(abProps.left.getValue(),
-                                abProps.top.getValue(), 
-                                abProps.right.getValue() - abProps.left.getValue(),
-                                abProps.bottom.getValue() - abProps.top.getValue());
-            relDims = new FODimension(0, 0);
-            absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(),
-                fobj.getWritingMode(), rect, relDims);
-        } else if (abProps.absolutePosition == EN_FIXED
-                || abProps.absolutePosition == EN_ABSOLUTE) {
-            Rectangle2D viewArea = getPageViewport().getViewArea();
-            double x = viewArea.getX() + abProps.left.getValue();
-            double y = viewArea.getY() + abProps.top.getValue();
-            double w = 0.0;
-            if (abProps.right.getEnum() == Constants.EN_AUTO) {
-                if (fobj.getWidth().getEnum() == Constants.EN_AUTO) {
-                    w = viewArea.getWidth() - x;
-                } else {
-                    if (fobj.getReferenceOrientation() % 180 == 0) {
-                        w = fobj.getInlineProgressionDimension().getOptimum().getLength().getValue();
-                    } else {
-                        w = fobj.getBlockProgressionDimension().getOptimum().getLength().getValue();
-                    }
-                }
-            } else {
-                w = viewArea.getWidth() - x - abProps.right.getValue();
-            }
-            double h = 0.0;
-            if (abProps.bottom.getEnum() == Constants.EN_AUTO) {
-                if (fobj.getHeight().getEnum() == Constants.EN_AUTO) {
-                    h = viewArea.getHeight() - y;
-                } else {
-                    if (fobj.getReferenceOrientation() % 180 == 0) {
-                        h = fobj.getBlockProgressionDimension().getOptimum().getLength().getValue();
-                    } else {
-                        h = fobj.getInlineProgressionDimension().getOptimum().getLength().getValue();
-                    }
-                }
-            } else {
-                h = viewArea.getHeight() - y - abProps.bottom.getValue();
-            }
-            log.debug("x=" + x + " y=" + y + " w=" + w + " h=" + h + " orient=" + fobj.getReferenceOrientation());
-            if (w != 0) {
-                this.width = new FixedLength((int)w);
-            }
-            if (h != 0) {
-                this.height = new FixedLength((int)h);
-            }
-            Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
-            relDims = new FODimension(0, 0);
-            absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(),
-                fobj.getWritingMode(), rect, relDims);
-        }
  
-        if (height == null) {
+        boolean rotated = (fobj.getReferenceOrientation() % 180 != 0);
+        if (rotated) {
+            height = fobj.getInlineProgressionDimension().getOptimum().getLength();
+            width = fobj.getBlockProgressionDimension().getOptimum().getLength();
+        } else {
             height = fobj.getBlockProgressionDimension().getOptimum().getLength();
-        }
-        if (width == null) {
             width = fobj.getInlineProgressionDimension().getOptimum().getLength();
         }
     }
@@ -159,6 +104,19 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
         return fobj.getInlineProgressionDimension().getOptimum().getLength().getValue();
     }
 
+    private int getSpaceBefore() {
+        return fobj.getCommonMarginBlock().spaceBefore
+                .getOptimum().getLength().getValue();
+    }
+    
+    private int getBPIndents() {
+        int indents = 0;
+        indents += fobj.getCommonMarginBlock().spaceBefore.getOptimum().getLength().getValue();
+        indents += fobj.getCommonMarginBlock().spaceAfter.getOptimum().getLength().getValue();
+        indents += fobj.getCommonBorderPaddingBackground().getBPPaddingAndBorder(false);
+        return indents;
+    }
+    
     private int getIPIndents() {
         int iIndents = 0;
         iIndents += fobj.getCommonMarginBlock().startIndent.getValue();
@@ -166,48 +124,83 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
         return iIndents;
     }
     
+    private boolean isAbsoluteOrFixed() {
+        return (abProps.absolutePosition == EN_ABSOLUTE) 
+                || (abProps.absolutePosition == EN_FIXED);
+    }
+
+    private boolean isFixed() {
+        return (abProps.absolutePosition == EN_FIXED);
+    }
+    
+    /**
+     * @see org.apache.fop.layoutmgr.LayoutManager#getNextBreakPoss(org.apache.fop.layoutmgr.LayoutContext)
+     */
     public BreakPoss getNextBreakPoss(LayoutContext context) {
 
-        if (abProps.absolutePosition == EN_ABSOLUTE) {
-            return getAbsoluteBreakPoss(context);
-        } else if (abProps.absolutePosition == EN_FIXED) {
+        if (isAbsoluteOrFixed()) {
             return getAbsoluteBreakPoss(context);
         }
 
+        boolean rotated = (fobj.getReferenceOrientation() % 180 != 0); //vals[0] == 0.0;
         referenceIPD = context.getRefIPD();
-        int bpd = context.getStackLimit().opt;
-        if (width.getEnum() != EN_AUTO) {
-            referenceIPD = width.getValue();
-        }
+        int maxbpd = context.getStackLimit().opt;
+        int allocBPD, allocIPD;
         if (height.getEnum() != EN_AUTO) {
-            bpd = height.getValue();
+            allocBPD = height.getValue(); //this is the content-height
+            allocBPD += getBPIndents();
+        } else {
+            allocBPD = maxbpd;
         }
-        int contentIPD = referenceIPD - getIPIndents();
+        if (width.getEnum() != EN_AUTO) {
+            allocIPD = width.getValue(); //this is the content-width
+            allocIPD += getIPIndents();
+        } else {
+            allocIPD = referenceIPD;
+        }
+
+        vpContentBPD = allocBPD - getBPIndents();
+        vpContentIPD = allocIPD - getIPIndents();
+        
+        double contentRectOffsetX = 0;
+        contentRectOffsetX += fobj.getCommonMarginBlock().startIndent.getValue();
+        double contentRectOffsetY = 0;
+        //contentRectOffsetY += fobj.getCommonMarginBlock().startIndent.getValue();
+        contentRectOffsetY += getSpaceBefore();
+        contentRectOffsetY += fobj.getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
+        contentRectOffsetY += fobj.getCommonBorderPaddingBackground().getPaddingBefore(false);
         
-        Rectangle2D rect = new Rectangle2D.Double(0, 0, contentIPD, bpd);
+        Rectangle2D rect = new Rectangle2D.Double(
+                contentRectOffsetX, contentRectOffsetY, 
+                vpContentIPD, vpContentBPD);
         relDims = new FODimension(0, 0);
         absoluteCTM = CTM.getCTMandRelDims(fobj.getReferenceOrientation(),
                 fobj.getWritingMode(), rect, relDims);
         double[] vals = absoluteCTM.toArray();
 
         MinOptMax stackLimit;
-        boolean rotated = vals[0] == 0.0;
         if (rotated) {
             // rotated 90 degrees
+            /*
             if (relDims.ipd > context.getRefIPD()) {
                 relDims.ipd = context.getRefIPD();
-            }
-            stackLimit = new MinOptMax(relDims.ipd);
+            }*/
+            //stackLimit = new MinOptMax(relDims.ipd);
+            /*
             if (width.getEnum() == EN_AUTO) {
                 relDims.bpd = context.getStackLimit().opt;
             }
             absoluteCTM = new CTM(vals[0], vals[1], vals[2], vals[3], 0, 0);
+            */
+            //absoluteCTM = new CTM(vals[0], vals[1], vals[2], vals[3], vals[5], vals[4]);
         } else {
+            /*
             if (vals[0] == -1.0) {
                 absoluteCTM = new CTM(vals[0], vals[1], vals[2], vals[3], 0, 0);
-            }
-            stackLimit = context.getStackLimit();
+            }*/
+            //stackLimit = context.getStackLimit();
         }
+        stackLimit = new MinOptMax(relDims.bpd);
 
         LayoutManager curLM; // currently active LM
 
@@ -216,10 +209,11 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
         // stackSize.add(spaceBefore);
         BreakPoss lastPos = null;
 
-        fobj.setLayoutDimension(PercentBase.BLOCK_IPD, contentIPD);
-        fobj.setLayoutDimension(PercentBase.BLOCK_BPD, bpd);
-        fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, contentIPD);
-        fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, bpd);
+        //TODO fix layout dimensions!
+        fobj.setLayoutDimension(PercentBase.BLOCK_IPD, allocIPD);
+        fobj.setLayoutDimension(PercentBase.BLOCK_BPD, allocBPD);
+        fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_IPD, relDims.ipd);
+        fobj.setLayoutDimension(PercentBase.REFERENCE_AREA_BPD, relDims.bpd);
 
         while ((curLM = getChildLM()) != null) {
             // Make break positions and return blocks!
@@ -230,7 +224,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
                 childLC.setStackLimit(
                   MinOptMax.subtract(stackLimit,
                                      stackSize));
-                childLC.setRefIPD(contentIPD);
+                childLC.setRefIPD(relDims.ipd);
 
             boolean over = false;
             while (!curLM.isFinished()) {
@@ -274,20 +268,94 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
             BreakPoss breakPoss;
             breakPoss = new BreakPoss(new LeafPosition(this,
                                                childBreaks.size() - 1));
-            breakPoss.setStackingSize(new MinOptMax(contentIPD));
+            breakPoss.setStackingSize(new MinOptMax(relDims.ipd));
             return breakPoss;
         }
         return null;
     }
 
+    private Point getAbsOffset() {
+        int x = 0;
+        int y = 0;
+        if (abProps.left.getEnum() != EN_AUTO) {
+            x = abProps.left.getValue();
+        }
+        if (abProps.top.getEnum() != EN_AUTO) {
+            y = abProps.top.getValue();
+        }
+        return new Point(x, y);
+    }
+    
+    /**
+     * Generate and return the next break possibility for absolutely positioned
+     * block-containers.
+     * @param context LayoutContext to work with
+     * @return the next break position
+     * @see org.apache.fop.layoutmgr.LayoutManager#getNextBreakPoss(org.apache.fop.layoutmgr.LayoutContext)
+     */
     public BreakPoss getAbsoluteBreakPoss(LayoutContext context) {
 
         LayoutManager curLM ; // currently active LM
 
         MinOptMax stackSize = new MinOptMax();
 
-        int ipd = relDims.ipd;
+        Point offset = getAbsOffset();
+        int allocBPD, allocIPD;
+        if (height.getEnum() != EN_AUTO) {
+            allocBPD = height.getValue(); //this is the content-height
+            allocBPD += getBPIndents();
+        } else {
+            allocBPD = 0;
+            if (abProps.bottom.getEnum() != EN_AUTO) {
+                if (isFixed()) {
+                    allocBPD = (int)getPageViewport().getViewArea().getHeight();
+                } else {
+                    allocBPD = context.getStackLimit().opt; 
+                }
+                allocBPD -= offset.y;
+                if (abProps.bottom.getEnum() != EN_AUTO) {
+                    allocBPD -= abProps.bottom.getValue();
+                }
+            }
+        }
+        if (width.getEnum() != EN_AUTO) {
+            allocIPD = width.getValue(); //this is the content-width
+            allocIPD += getIPIndents();
+        } else {
+            if (isFixed()) {
+                allocIPD = (int)getPageViewport().getViewArea().getWidth(); 
+            } else {
+                allocIPD = context.getRefIPD();
+            }
+            if (abProps.left.getEnum() != EN_AUTO) {
+                allocIPD -= abProps.left.getValue();
+            }
+            if (abProps.right.getEnum() != EN_AUTO) {
+                allocIPD -= abProps.right.getValue();
+            }
+        }
 
+        vpContentBPD = allocBPD - getBPIndents();
+        vpContentIPD = allocIPD - getIPIndents();
+        
+        double contentRectOffsetX = offset.getX();
+        contentRectOffsetX += fobj.getCommonMarginBlock().startIndent.getValue();
+        double contentRectOffsetY = offset.getY();
+        contentRectOffsetY += getSpaceBefore();
+        contentRectOffsetY += fobj.getCommonBorderPaddingBackground().getBorderBeforeWidth(false);
+        contentRectOffsetY += fobj.getCommonBorderPaddingBackground().getPaddingBefore(false);
+        
+        Rectangle2D rect = new Rectangle2D.Double(
+                contentRectOffsetX, contentRectOffsetY, 
+                vpContentIPD, vpContentBPD);
+        relDims = new FODimension(0, 0);
+        absoluteCTM = CTM.getCTMandRelDims(
+                fobj.getReferenceOrientation(),
+                fobj.getWritingMode(), 
+                rect, relDims);
+        //referenceIPD = relDims.ipd + getIPIndents();
+
+        
         while ((curLM = getChildLM()) != null) {
             // Make break positions and return blocks!
             // Set up a LayoutContext
@@ -295,7 +363,7 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
 
             LayoutContext childLC = new LayoutContext(0);
             childLC.setStackLimit(new MinOptMax(1000000));
-            childLC.setRefIPD(ipd);
+            childLC.setRefIPD(relDims.ipd);
 
             while (!curLM.isFinished()) {
                 if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
@@ -364,26 +432,41 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
     public Area getParentArea(Area childArea) {
         if (curBlockArea == null) {
             viewportBlockArea = new BlockViewport();
+            viewportBlockArea.addTrait(Trait.IS_VIEWPORT_AREA, Boolean.TRUE);
             TraitSetter.addBorders(viewportBlockArea, fobj.getCommonBorderPaddingBackground());
             TraitSetter.addBackground(viewportBlockArea, fobj.getCommonBorderPaddingBackground());
+            TraitSetter.addMargins(viewportBlockArea, null, 
+                    fobj.getCommonBorderPaddingBackground(),
+                    fobj.getCommonMarginBlock());
             
+            viewportBlockArea.setCTM(absoluteCTM);
+            viewportBlockArea.setIPD(vpContentIPD);
+            viewportBlockArea.setBPD(vpContentBPD);
+            viewportBlockArea.setClip(clip);
+            viewportBlockArea.addTrait(Trait.SPACE_BEFORE, new Integer(getSpaceBefore()));
+
             if (abProps.absolutePosition == EN_ABSOLUTE 
                     || abProps.absolutePosition == EN_FIXED) {
-                viewportBlockArea.setXOffset(abProps.left.getValue());
-                viewportBlockArea.setYOffset(abProps.top.getValue());
-                viewportBlockArea.setIPD(width.getValue());
-                viewportBlockArea.setBPD(height.getValue());
-
-                viewportBlockArea.setCTM(absoluteCTM);
-                viewportBlockArea.setClip(clip);
+                Point offset = getAbsOffset();
+                viewportBlockArea.setXOffset(offset.x);
+                viewportBlockArea.setYOffset(offset.y);
                 autoHeight = false;
             } else {
-                double[] vals = absoluteCTM.toArray();
+                //double[] vals = absoluteCTM.toArray();
+                boolean rotated = (fobj.getReferenceOrientation() % 180 != 0); //vals[0] == 0.0;
+                if (rotated) {
+                    autoHeight = false;
+                } else {
+                    autoHeight = (height.getEnum() == EN_AUTO);
+                    if (autoHeight) {
+                        viewportBlockArea.setBPD(0);
+                    }
+                }
+                /*
                 boolean rotated = vals[0] == 0.0;
                 if (rotated) {
-                    viewportBlockArea.setIPD(relDims.ipd);
-                    viewportBlockArea.setBPD(relDims.bpd);
-                    viewportBlockArea.setCTM(absoluteCTM);
+                    viewportBlockArea.setIPD(vpContentIPD);
+                    viewportBlockArea.setBPD(vpContentBPD);
                     viewportBlockArea.setClip(clip);
                     autoHeight = false;
                 } else if (vals[0] == -1.0) {
@@ -394,7 +477,6 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
                         viewportBlockArea.setBPD(relDims.bpd);
                         autoHeight = false;
                     }
-                    viewportBlockArea.setCTM(absoluteCTM);
                     viewportBlockArea.setClip(clip);
                 } else {
                     viewportBlockArea.setIPD(relDims.ipd);
@@ -402,10 +484,11 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager {
                         viewportBlockArea.setBPD(relDims.bpd);
                         autoHeight = false;
                     }
-                }
+                }*/
             }
 
             curBlockArea = new Block();
+            curBlockArea.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
 
             if (abProps.absolutePosition == EN_ABSOLUTE) {
                 viewportBlockArea.setPositioning(Block.ABSOLUTE);
index ccad318836c810ab3a7bca5566479a6fd4c26b74..25db6080bc3f51699c3aaf97fa63635c3aabfe3c 100644 (file)
@@ -466,7 +466,7 @@ public abstract class AbstractRenderer
         int saveBP = currentBPPosition;
 
         // Calculate the position of the content rectangle.
-        if (parent != null) {
+        if (parent != null && !Boolean.TRUE.equals(parent.getTrait(Trait.IS_VIEWPORT_AREA))) {
             currentBPPosition += parent.getBorderAndPaddingWidthBefore();
             /* This is unnecessary now as we're going to use the *-indent traits
             currentIPPosition += parent.getBorderAndPaddingWidthStart();
index 223ebdd815dafe3b090cf9a71679250c1f2c84e3..01c21e8b9a03630793cc2499d26c8cf59714f83e 100644 (file)
@@ -675,6 +675,11 @@ public class PDFRenderer extends PrintRenderer {
         String saveFontName = currentFontName;
 
         CTM ctm = bv.getCTM();
+        int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
+        int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
+        float x,y;
+        x = (float)(bv.getXOffset() + containingIPPosition) / 1000f;
+        y = (float)(bv.getYOffset() + containingBPPosition) / 1000f;
 
         if (bv.getPositioning() == Block.ABSOLUTE
                 || bv.getPositioning() == Block.FIXED) {
@@ -684,28 +689,30 @@ public class PDFRenderer extends PrintRenderer {
             ctm = tempctm.multiply(ctm);
             getLogger().debug("tempctm=" + tempctm + " ctm=" + ctm);
 
-            float x,y;
-            x = (float)(bv.getXOffset() + containingIPPosition) / 1000f;
-            y = (float)(bv.getYOffset() + containingBPPosition) / 1000f;
+            //This is the content-rect
             float width = (float)bv.getIPD() / 1000f;
             float height = (float)bv.getBPD() / 1000f;
             getLogger().debug("renderBlockViewport: x=" + x + " y=" + y + " width=" + width + " height=" + height);
             
-            int borderPaddingStart = bv.getBorderAndPaddingWidthStart();
-            int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore();
-
+            //Adjust for spaces (from margin or indirectly by start-indent etc.
             Integer spaceStart = (Integer) bv.getTrait(Trait.SPACE_START);
             if (spaceStart != null) {
                 x += spaceStart.floatValue() / 1000;
             }
+            Integer spaceBefore = (Integer) bv.getTrait(Trait.SPACE_BEFORE);
+            if (spaceBefore != null) {
+                y += spaceBefore.floatValue() / 1000;
+            }
 
-            width += borderPaddingStart / 1000f;
-            width += bv.getBorderAndPaddingWidthEnd() / 1000f;
-            height += borderPaddingBefore / 1000f;
-            height += bv.getBorderAndPaddingWidthAfter() / 1000f;
+            float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f;
+            float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f;
 
-            drawBackAndBorders(bv, x, y, widthheight);
+            drawBackAndBorders(bv, x, y, width + bpwidth, height + bpheight);
 
+            //Now adjust for border/padding
+            x += borderPaddingStart / 1000f;
+            y += borderPaddingBefore / 1000f;
+            
             if (bv.getClip()) {
                 saveGraphicsState();
                 clip(x, y, width, height);
@@ -729,6 +736,17 @@ public class PDFRenderer extends PrintRenderer {
             currentBPPosition = saveBP;
         } else {
 
+            Integer spaceBefore = (Integer)bv.getTrait(Trait.SPACE_BEFORE);
+            if (spaceBefore != null) {
+                currentBPPosition += spaceBefore.intValue();
+            }
+
+            //borders and background in the old coordinate system
+            handleBlockTraits(bv);
+
+            CTM tempctm = new CTM(containingIPPosition, currentBPPosition + containingBPPosition);
+            ctm = tempctm.multiply(ctm);
+            /*
             if (ctm != null) {
                 double[] vals = ctm.toArray();
                 //boolean aclock = vals[2] == 1.0;
@@ -737,21 +755,25 @@ public class PDFRenderer extends PrintRenderer {
                 } else if (vals[0] == -1.0) {
                     ctm = ctm.translate(-saveIP - bv.getIPD(), -saveBP - bv.getBPD());
                 } else {
-                    ctm = ctm.translate(saveBP, saveIP - bv.getIPD());
+                    //ctm = ctm.translate(saveBP, saveIP - bv.getIPD());
+                    //ctm = ctm.translate(saveIP, saveBP);
                 }
             }
+            ctm = new CTM().translate(saveIP, saveBP).multiply(ctm);
+            */
+            
+            //Now adjust for border/padding
+            x += borderPaddingStart / 1000f;
+            y += borderPaddingBefore / 1000f;
 
             // clip if necessary
             if (bv.getClip()) {
                 saveGraphicsState();
-                float x = (float)bv.getXOffset() / 1000f;
-                float y = (float)bv.getYOffset() / 1000f;
                 float width = (float)bv.getIPD() / 1000f;
                 float height = (float)bv.getBPD() / 1000f;
                 clip(x, y, width, height);
             }
 
-            handleBlockTraits(bv);
             if (ctm != null) {
                 startVParea(ctm);
                 currentIPPosition = 0;