]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Layout changed to account for fo:region-body borders and padding when
authorGlen Mazza <gmazza@apache.org>
Sat, 1 Nov 2003 04:28:02 +0000 (04:28 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 1 Nov 2003 04:28:02 +0000 (04:28 +0000)
determining printable width and height for each page.

Various method nitpicks also fixed.

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

src/java/org/apache/fop/area/Page.java
src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
src/java/org/apache/fop/render/AbstractRenderer.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java
src/java/org/apache/fop/tools/AreaTreeBuilder.java
src/java/org/apache/fop/traits/MinOptMax.java
src/java/org/apache/fop/util/CharUtilities.java

index f5cda397f529280aee606a6255f656e6a904aed7..b55af90bc0507ab7fbb330425e38683832d2bb39 100644 (file)
@@ -83,7 +83,7 @@ public class Page implements Serializable, Cloneable {
      * @param areaclass the area class of the region to set
      * @param port the region viewport to set
      */
-    public void setRegion(int areaclass, RegionViewport port) {
+    public void setRegionViewport(int areaclass, RegionViewport port) {
         if (areaclass == Region.BEFORE_CODE) {
             regionBefore = port;
         } else if (areaclass == Region.START_CODE) {
@@ -103,7 +103,7 @@ public class Page implements Serializable, Cloneable {
      * @param areaclass the region area class
      * @return the region viewport or null if none
      */
-    public RegionViewport getRegion(int areaclass) {
+    public RegionViewport getRegionViewport(int areaclass) {
         if (areaclass == Region.BEFORE_CODE) {
             return regionBefore;
         } else if (areaclass == Region.START_CODE) {
index 9861423c553a855275c8c2836f28ca2c9e6d55a3..00899dc6e17ef2821401fb72da5443c86e29ec33 100644 (file)
@@ -67,6 +67,7 @@ import org.apache.fop.area.Span;
 import org.apache.fop.area.BeforeFloat;
 import org.apache.fop.area.Footnote;
 import org.apache.fop.area.Resolveable;
+import org.apache.fop.area.Trait;
 
 import org.apache.fop.datatypes.FODimension;
 
@@ -78,12 +79,12 @@ import org.apache.fop.fo.pagination.Region;
 import org.apache.fop.fo.properties.RetrieveBoundary;
 import org.apache.fop.fo.pagination.SimplePageMaster;
 import org.apache.fop.fo.pagination.StaticContent;
-
 import org.apache.fop.fo.properties.CommonBackground;
 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;
@@ -471,10 +472,32 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
         }
 
         curPage.setPageNumber(getCurrentPageNumber());
-        RegionViewport reg = curPage.getPage().getRegion(
+        RegionViewport rv = curPage.getPage().getRegionViewport(
                     Region.BODY_CODE);
-        curBody = (BodyRegion) reg.getRegion();
-        flowBPD = (int)reg.getViewArea().getHeight();
+        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();
+        }
+
         return curPage;
     }
 
@@ -486,7 +509,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
         if (flow == null) {
             return;
         }
-        RegionViewport reg = curPage.getPage().getRegion(regionClass);
+        RegionViewport reg = curPage.getPage().getRegionViewport(regionClass);
         reg.getRegion().setIPD((int)reg.getViewArea().getWidth());
         if (reg == null) {
             getLogger().error("no region viewport: shouldn't happen");
@@ -710,9 +733,32 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
         //else newpos = new MinOptMax();
         curSpan = new Span(numCols);
         // get Width or Height as IPD for span
-        curSpan.setIPD((int) curPage.getPage().getRegion(
-                          Region.BODY_CODE).getViewArea().getWidth());
+        
+        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();
+        }
+
+        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);
         createFlow();
@@ -803,7 +849,7 @@ public class PageLayoutManager extends AbstractLayoutManager implements Runnable
            } else {
                rvp.setRegion(makeRegionReferenceArea(r, rvp.getViewArea()));
            }
-           page.setRegion(r.getRegionClassCode(), rvp);
+           page.setRegionViewport(r.getRegionClassCode(), rvp);
            if (r.getRegionClassCode() == Region.BODY_CODE) {
                bHasBody = true;
            }
index d10be582fe0caafb5d9a04e1996ef57825ca5b3b..7b36f3b3bf222747db13c53e3172f0519951e100 100644 (file)
@@ -107,7 +107,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
 
     /** Start index of first character in this parent Area */
     private short iAreaStart = 0;
-    /** Start index of next "word" */
+    /** Start index of next TextArea */
     private short iNextStart = 0;
     /** Size since last makeArea call, except for last break */
     private MinOptMax ipdTotal;
@@ -187,7 +187,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
     public boolean canBreakBefore(LayoutContext context) {
         char c = chars[iNextStart];
         return ((c == NEWLINE)
-                || (textInfo.bWrap && (CharUtilities.isSpace(c)
+                || (textInfo.bWrap && (CharUtilities.isBreakableSpace(c)
                 || BREAK_CHARS.indexOf(c) >= 0)));
     }
 
@@ -296,10 +296,10 @@ public class TextLayoutManager extends AbstractLayoutManager {
         }
 
 
-        /* Start of this "word", plus any non-suppressed leading space.
+        /* Start of this TextArea, plus any non-suppressed leading space.
          * Collapse any remaining word-space with leading space from
          * ancestor FOs.
-         * Add up other leading space which is counted in the word IPD.
+         * Add up other leading space which is counted in the TextArea IPD.
          */
 
         SpaceSpecifier pendingSpace = new SpaceSpecifier(false);
@@ -375,7 +375,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
                 char c = chars[iNextStart];
                 if ((c == NEWLINE) || // Include any breakable white-space as break char
                         //  even if fixed width
-                        (textInfo.bWrap && (CharUtilities.isSpace(c)
+                        (textInfo.bWrap && (CharUtilities.isBreakableSpace(c)
                                             || BREAK_CHARS.indexOf(c) >= 0))) {
                     iFlags |= BreakPoss.CAN_BREAK_AFTER;
                     if (c != SPACE) {
@@ -464,7 +464,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
 
     /**
      * Generate and add areas to parent area.
-     * This can either generate an area for each "word" and each space, or
+     * This can either generate an area for each TextArea and each space, or
      * an area containing all text with a parameter controlling the size of
      * the word space. The latter is most efficient for PDF generation.
      * Set size of each area.
@@ -474,7 +474,7 @@ public class TextLayoutManager extends AbstractLayoutManager {
      */
     public void addAreas(PositionIterator posIter, LayoutContext context) {
         // Add word areas
-        AreaInfo ai = null ;
+        AreaInfo ai = null;
         int iStart = -1;
         int iWScount = 0;
 
@@ -508,24 +508,25 @@ public class TextLayoutManager extends AbstractLayoutManager {
             iAdjust = (int)((double)(ai.ipdArea.opt
                                      - ai.ipdArea.min) * dSpaceAdjust);
         }
-        // System.err.println("Text adjustment factor = " + dSpaceAdjust +
-        //    " total=" + iAdjust);
+//        System.err.println("\nText adjustment factor = " + dSpaceAdjust +
+//          " total=" + iAdjust + "; breakIndex = " + ai.iBreakIndex);
 
         // Make an area containing all characters between start and end.
         InlineArea word = null;
         int adjust = 0;
-        // ingnore newline character
+        
+        // ignore newline character
         if (chars[ai.iBreakIndex - 1] == NEWLINE) {
             adjust = 1;
         }
         String str = new String(chars, iStart, ai.iBreakIndex - iStart - adjust);
+
         if (" ".equals(str)) {
             word = new Space();
             word.setWidth(ai.ipdArea.opt + iAdjust);
         } else  {
-            TextArea t = createText(
-                      str,
-                      ai.ipdArea.opt + iAdjust, context.getBaseline());
+            TextArea t = createTextArea(str, ai.ipdArea.opt + iAdjust, 
+                context.getBaseline());
             if (iWScount > 0) {
                 //getLogger().error("Adjustment per word-space= " +
                 //                   iAdjust / iWScount);
@@ -560,27 +561,27 @@ public class TextLayoutManager extends AbstractLayoutManager {
 
     /**
      * Create an inline word area.
-     * This creates a Word and sets up the various attributes.
+     * This creates a TextArea and sets up the various attributes.
      *
-     * @param str the string for the word
-     * @param width the width that the word uses
+     * @param str the string for the TextArea
+     * @param width the width that the TextArea uses
      * @param base the baseline position
      * @return the new word area
      */
-    protected TextArea createText(String str, int width, int base) {
-        TextArea curWordArea = new TextArea();
-        curWordArea.setWidth(width);
-        curWordArea.setHeight(textInfo.fs.getAscender()
+    protected TextArea createTextArea(String str, int width, int base) {
+        TextArea textArea = new TextArea();
+        textArea.setWidth(width);
+        textArea.setHeight(textInfo.fs.getAscender()
                               - textInfo.fs.getDescender());
-        curWordArea.setOffset(textInfo.fs.getAscender());
-        curWordArea.setOffset(base);
+        textArea.setOffset(textInfo.fs.getAscender());
+        textArea.setOffset(base);
 
-        curWordArea.setTextArea(str);
-        curWordArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
-        curWordArea.addTrait(Trait.FONT_SIZE,
+        textArea.setTextArea(str);
+        textArea.addTrait(Trait.FONT_NAME, textInfo.fs.getFontName());
+        textArea.addTrait(Trait.FONT_SIZE,
                              new Integer(textInfo.fs.getFontSize()));
-        curWordArea.addTrait(Trait.COLOR, this.textInfo.color);
-        return curWordArea;
+        textArea.addTrait(Trait.COLOR, this.textInfo.color);
+        return textArea;
     }
 
 }
index d15895319f2938d6fd09099455be32cad11e7e7f..39e18e33bcbb7d3bbf92dd823c3ef44d3120fa55 100644 (file)
@@ -298,15 +298,15 @@ public abstract class AbstractRenderer extends AbstractLogEnabled
         decision is to have fo:region-body on top, hence it is rendered
         last here. */
         RegionViewport viewport;
-        viewport = page.getRegion(Region.BEFORE_CODE);
+        viewport = page.getRegionViewport(Region.BEFORE_CODE);
         renderRegionViewport(viewport);
-        viewport = page.getRegion(Region.START_CODE);
+        viewport = page.getRegionViewport(Region.START_CODE);
         renderRegionViewport(viewport);
-        viewport = page.getRegion(Region.END_CODE);
+        viewport = page.getRegionViewport(Region.END_CODE);
         renderRegionViewport(viewport);
-        viewport = page.getRegion(Region.AFTER_CODE);
+        viewport = page.getRegionViewport(Region.AFTER_CODE);
         renderRegionViewport(viewport);
-        viewport = page.getRegion(Region.BODY_CODE);
+        viewport = page.getRegionViewport(Region.BODY_CODE);
         renderRegionViewport(viewport);
     }
 
index 5fa8ecdcb5aae3a59999bd48d2f7dc5f5435ab77..d950733725da83346027f90c8963301f172c3827 100644 (file)
@@ -916,12 +916,12 @@ public class PDFRenderer extends PrintRenderer {
         //  where previous line area failed to take up entire allocated space
         int rx = currentBlockIPPosition + IPMarginOffset;
         int bl = currentBPPosition + BPMarginOffset + text.getOffset();
-
-/*      System.out.println("BlockIP Position: " + currentBlockIPPosition +
+/*
+        System.out.println("\nBlockIP Position: " + currentBlockIPPosition +
             "; currentBPPosition: " + currentBPPosition +
             "; offset: " + text.getOffset() +
-            "; Text = " + text.getTextArea()); */
-
+            "; Text = " + text.getTextArea());
+*/
         // Set letterSpacing
         //float ls = fs.getLetterSpacing() / this.currentFontSize;
         //pdf.append(ls).append(" Tc\n");
index d0fe8f973fbb9f4a9775f85dd176ea2e87b3cda7..2259f2f5bfdab20f4fbb30b61f89c326d352e7df 100644 (file)
@@ -383,19 +383,19 @@ class TreeLoader extends AbstractLogEnabled {
             Node obj = childs.item(i);
             if (obj.getNodeName().equals("regionBefore")) {
                 reg.setRegion(readRegion((Element) obj, Region.BEFORE_CODE));
-                page.setRegion(Region.BEFORE_CODE, reg);
+                page.setRegionViewport(Region.BEFORE_CODE, reg);
             } else if (obj.getNodeName().equals("regionStart")) {
                 reg.setRegion(readRegion((Element) obj, Region.START_CODE));
-                page.setRegion(Region.START_CODE, reg);
+                page.setRegionViewport(Region.START_CODE, reg);
             } else if (obj.getNodeName().equals("regionBody")) {
                 reg.setRegion(readRegion((Element) obj, Region.BODY_CODE));
-                page.setRegion(Region.BODY_CODE, reg);
+                page.setRegionViewport(Region.BODY_CODE, reg);
             } else if (obj.getNodeName().equals("regionEnd")) {
                 reg.setRegion(readRegion((Element) obj, Region.END_CODE));
-                page.setRegion(Region.END_CODE, reg);
+                page.setRegionViewport(Region.END_CODE, reg);
             } else if (obj.getNodeName().equals("regionAfter")) {
                 reg.setRegion(readRegion((Element) obj, Region.AFTER_CODE));
-                page.setRegion(Region.AFTER_CODE, reg);
+                page.setRegionViewport(Region.AFTER_CODE, reg);
             }
         }
 
index 114c4e03f7d43d5a1fd0136fb103e41997a82f69..d748628a7de7ff43d057a66b76a2102c9c55461a 100644 (file)
@@ -157,5 +157,8 @@ public class MinOptMax implements java.io.Serializable, Cloneable {
         max -= op.min;
     }
 
+    public String toString() {
+        return "MinOptMax: min=" + min + "; opt=" + opt + "; max=" + max;
+    }
 }
 
index c03c407ba398982382adc029cd6d09e12d076b80..c1ceb7c78917435582e78325a6f1cf177b3bc85e 100644 (file)
@@ -111,12 +111,12 @@ public class CharUtilities {
 
     /**
      * Helper method to determine if the character is a
-     * space with normal behaviour. Normal behaviour means that
+     * space with normal behavior. Normal behavior means that
      * it's not non-breaking.
      * @param c character to inspect
      * @return True if the character is a normal space
      */
-    public static boolean isSpace(char c) {
+    public static boolean isBreakableSpace(char c) {
         return (c == ' '
                || (c >= '\u2000' && c <= '\u200B'));
 //         c == '\u2000'                   // en quad
@@ -139,7 +139,7 @@ public class CharUtilities {
      * @param c character to check
      * @return True if the character is a nbsp
      */
-    public static boolean isNBSP(char c) {
+    public static boolean isNonBreakableSpace(char c) {
         return
             (c == '\u00A0'      // no-break space
             || c == '\u202F'    // narrow no-break space
@@ -153,7 +153,7 @@ public class CharUtilities {
      * @return True if the character represents any kind of space
      */
     public static boolean isAnySpace(char c) {
-        boolean ret = (isSpace(c) || isNBSP(c));
+        boolean ret = (isBreakableSpace(c) || isNonBreakableSpace(c));
         return ret;
     }
 }