gmazza      2003/10/31 20:28:02

  Modified:    src/java/org/apache/fop/area Page.java
               src/java/org/apache/fop/layoutmgr PageLayoutManager.java
                        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
  Log:
  Layout changed to account for fo:region-body borders and padding when
  determining printable width and height for each page.
  
  Various method nitpicks also fixed.
  
  Revision  Changes    Path
  1.3       +2 -2      xml-fop/src/java/org/apache/fop/area/Page.java
  
  Index: Page.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/Page.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Page.java 27 Aug 2003 18:14:45 -0000      1.2
  +++ Page.java 1 Nov 2003 04:28:01 -0000       1.3
  @@ -83,7 +83,7 @@
        * @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 @@
        * @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) {
  
  
  
  1.21      +54 -8     xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java
  
  Index: PageLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/PageLayoutManager.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PageLayoutManager.java    12 Sep 2003 18:57:34 -0000      1.20
  +++ PageLayoutManager.java    1 Nov 2003 04:28:01 -0000       1.21
  @@ -67,6 +67,7 @@
   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.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 @@
           }
   
           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 @@
           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 @@
           //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 @@
              } 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;
              }
  
  
  
  1.7       +28 -27    xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java
  
  Index: TextLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TextLayoutManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TextLayoutManager.java    28 Oct 2003 04:22:13 -0000      1.6
  +++ TextLayoutManager.java    1 Nov 2003 04:28:01 -0000       1.7
  @@ -107,7 +107,7 @@
   
       /** 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 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 @@
           }
   
   
  -        /* 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 @@
                   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 @@
   
       /**
        * 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 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 @@
               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 @@
   
       /**
        * 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;
       }
   
   }
  
  
  
  1.17      +5 -5      xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java
  
  Index: AbstractRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/AbstractRenderer.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AbstractRenderer.java     28 Oct 2003 04:22:13 -0000      1.16
  +++ AbstractRenderer.java     1 Nov 2003 04:28:01 -0000       1.17
  @@ -298,15 +298,15 @@
           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);
       }
   
  
  
  
  1.21      +4 -4      xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java
  
  Index: PDFRenderer.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/pdf/PDFRenderer.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- PDFRenderer.java  28 Oct 2003 04:22:14 -0000      1.20
  +++ PDFRenderer.java  1 Nov 2003 04:28:01 -0000       1.21
  @@ -916,12 +916,12 @@
           //  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");
  
  
  
  1.11      +5 -5      xml-fop/src/java/org/apache/fop/tools/AreaTreeBuilder.java
  
  Index: AreaTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/tools/AreaTreeBuilder.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AreaTreeBuilder.java      28 Oct 2003 04:22:14 -0000      1.10
  +++ AreaTreeBuilder.java      1 Nov 2003 04:28:01 -0000       1.11
  @@ -383,19 +383,19 @@
               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);
               }
           }
   
  
  
  
  1.2       +4 -1      xml-fop/src/java/org/apache/fop/traits/MinOptMax.java
  
  Index: MinOptMax.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/traits/MinOptMax.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MinOptMax.java    28 Aug 2003 19:08:59 -0000      1.1
  +++ MinOptMax.java    1 Nov 2003 04:28:02 -0000       1.2
  @@ -157,5 +157,8 @@
           max -= op.min;
       }
   
  +    public String toString() {
  +        return "MinOptMax: min=" + min + "; opt=" + opt + "; max=" + max;
  +    }
   }
   
  
  
  
  1.7       +5 -5      xml-fop/src/java/org/apache/fop/util/CharUtilities.java
  
  Index: CharUtilities.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/util/CharUtilities.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CharUtilities.java        10 Oct 2003 15:56:57 -0000      1.6
  +++ CharUtilities.java        1 Nov 2003 04:28:02 -0000       1.7
  @@ -111,12 +111,12 @@
   
       /**
        * 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 @@
        * @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 @@
        * @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;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to