bckfnn      2004/09/23 06:56:27

  Modified:    src/java/org/apache/fop/render AbstractRenderer.java
               src/java/org/apache/fop/render/pdf PDFRenderer.java
  Log:
  Calculate the margin offsets (border & padding), by increasing
  current[IB]PPosition, in AbstractRenderer instead of in PDFRenderer.
  
  Revision  Changes    Path
  1.36      +16 -4     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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- AbstractRenderer.java     22 Sep 2004 13:12:38 -0000      1.35
  +++ AbstractRenderer.java     23 Sep 2004 13:56:27 -0000      1.36
  @@ -47,6 +47,7 @@
   import org.apache.fop.area.RegionViewport;
   import org.apache.fop.area.RegionReference;
   import org.apache.fop.area.Title;
  +import org.apache.fop.area.Trait;
   import org.apache.fop.area.TreeExt;
   import org.apache.fop.area.inline.Container;
   import org.apache.fop.area.inline.ForeignObject;
  @@ -464,18 +465,29 @@
        */
       protected void renderBlocks(Block parent, List blocks) {
           int saveIP = currentIPPosition;
  +        int saveBP = currentBPPosition;
  +
  +        // Calculate the position of the content rectangle.
  +        if (parent != null) {
  +            currentBPPosition += parent.getBorderAndPaddingWidthBefore();
  +            currentIPPosition += parent.getBorderAndPaddingWidthStart();
  +            Integer spaceStart = (Integer) parent.getTrait(Trait.SPACE_START);
  +            if (spaceStart != null) {
  +                currentIPPosition += spaceStart.intValue();
  +            }
  +        }
           
           // the position of the containing block is used for
           // absolutely positioned areas
           int contBP = currentBPPosition;
           int contIP = currentIPPosition;
  -        containingBPPosition = contBP;
  -        containingIPPosition = contIP;
  +        containingBPPosition = currentBPPosition;
  +        containingIPPosition = currentIPPosition;
   
           for (int count = 0; count < blocks.size(); count++) {
               Object obj = blocks.get(count);
               if (obj instanceof Block) {
  -                currentIPPosition = saveIP;
  +                currentIPPosition = contIP;
                   containingBPPosition = contBP;
                   containingIPPosition = contIP;
                   renderBlock((Block) obj);
  @@ -485,7 +497,7 @@
                   // a line area is rendered from the top left position
                   // of the line, each inline object is offset from there
                   LineArea line = (LineArea) obj;
  -                currentIPPosition = saveIP + line.getStartIndent();
  +                currentIPPosition = contIP + line.getStartIndent();
                   renderLineArea(line);
                   currentBPPosition += line.getAllocBPD();
               }
  
  
  
  1.52      +21 -96    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.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- PDFRenderer.java  22 Sep 2004 20:22:15 -0000      1.51
  +++ PDFRenderer.java  23 Sep 2004 13:56:27 -0000      1.52
  @@ -199,18 +199,6 @@
       private StringBuffer wordAreaPDF = new StringBuffer();
   
       /**
  -     * 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 for
  -     * both the region and block.
  -     */
  -    protected int ipMarginOffset = 0;
  -
  -    /**
        * create the PDF renderer
        */
       public PDFRenderer() {
  @@ -481,41 +469,6 @@
       }
   
       /**
  -     * @see org.apache.fop.render.AbstractRenderer#renderBlocks(Block, List)
  -     */
  -    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
        * This is used to draw the traits for the given page region.
        * (See Sect. 6.4.1.2 of XSL-FO spec.)
  @@ -530,8 +483,8 @@
           float height = (float)(viewArea.getHeight() / 1000f);
   
           if (region.getRegion().getRegionClass() == FO_REGION_BODY) {
  -            bpMarginOffset = region.getBorderAndPaddingWidthBefore();
  -            ipMarginOffset = region.getBorderAndPaddingWidthStart();
  +            currentBPPosition = region.getBorderAndPaddingWidthBefore();
  +            currentIPPosition = region.getBorderAndPaddingWidthStart();
           }
           drawBackAndBorders(region, startx, starty, width, height);
       }
  @@ -545,12 +498,11 @@
        * @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
  -         */
  -
  -        float startx = (currentIPPosition + ipMarginOffset) / 1000f;
  -        float starty = (currentBPPosition + bpMarginOffset) / 1000f;
  +        int borderPaddingStart = block.getBorderAndPaddingWidthStart();
  +        int borderPaddingBefore = block.getBorderAndPaddingWidthBefore();
  +        
  +        float startx = currentIPPosition / 1000f;
  +        float starty = currentBPPosition / 1000f;
           float width = block.getIPD() / 1000f;
           float height = block.getBPD() / 1000f;
   
  @@ -558,39 +510,11 @@
           if (spaceStart != null) {
               startx += spaceStart.floatValue() / 1000;
           }
  -        BorderProps borderStart = (BorderProps) block.getTrait(Trait.BORDER_START);
  -        if (borderStart != null) {
  -            width += borderStart.width / 1000f;
  -        }
  -        Integer paddingStart = (Integer) block.getTrait(Trait.PADDING_START);
  -        if (paddingStart != null) {
  -            width += paddingStart.intValue() / 1000f;
  -        }
  -        BorderProps borderEnd = (BorderProps) block.getTrait(Trait.BORDER_END);
  -        if (borderEnd != null) {
  -            width += borderEnd.width / 1000f;
  -        }
  -        Integer paddingEnd = (Integer) block.getTrait(Trait.PADDING_END);
  -        if (paddingEnd != null) {
  -            width += paddingEnd.intValue() / 1000f;
  -        }
  -
  -        BorderProps borderBefore = (BorderProps) 
block.getTrait(Trait.BORDER_BEFORE);
  -        if (borderBefore != null) {
  -            height += borderBefore.width / 1000f;
  -        }
  -        Integer paddingBefore = (Integer) block.getTrait(Trait.PADDING_BEFORE);
  -        if (paddingBefore != null) {
  -            height += paddingBefore.intValue() / 1000f;
  -        }
  -        BorderProps borderAfter = (BorderProps) block.getTrait(Trait.BORDER_AFTER);
  -        if (borderAfter != null) {
  -            height += borderAfter.width / 1000f;
  -        }
  -        Integer paddingAfter = (Integer) block.getTrait(Trait.PADDING_AFTER);
  -        if (paddingAfter != null) {
  -            height += paddingAfter.intValue() / 1000f;
  -        }
  +
  +        width += borderPaddingStart / 1000f;
  +        width += block.getBorderAndPaddingWidthEnd() / 1000f;
  +        height += borderPaddingBefore / 1000f;
  +        height += block.getBorderAndPaddingWidthAfter() / 1000f;
   
           drawBackAndBorders(block, startx, starty,
               width, height);
  @@ -851,8 +775,8 @@
        * @param ip the inline parent area
        */
       public void renderInlineParent(InlineParent ip) {
  -        float start = (currentIPPosition + ipMarginOffset) / 1000f;
  -        float top = (ip.getOffset() + currentBPPosition + bpMarginOffset) / 1000f;
  +        float start = currentIPPosition / 1000f;
  +        float top = (ip.getOffset() + currentBPPosition) / 1000f;
           float width = ip.getIPD() / 1000f;
           float height = ip.getBPD() / 1000f;
           drawBackAndBorders(ip, start, top, width, height);
  @@ -918,8 +842,8 @@
           // word.getOffset() = only height of text itself
           // currentBlockIPPosition: 0 for beginning of line; nonzero
           //  where previous line area failed to take up entire allocated space
  -        int rx = currentIPPosition + ipMarginOffset;
  -        int bl = currentBPPosition + bpMarginOffset + ch.getOffset();
  +        int rx = currentIPPosition;
  +        int bl = currentBPPosition + ch.getOffset();
   
   /*        System.out.println("Text = " + ch.getTextArea() +
               "; text width: " + ch.getWidth() +
  @@ -990,8 +914,8 @@
           // word.getOffset() = only height of text itself
           // currentBlockIPPosition: 0 for beginning of line; nonzero
           //  where previous line area failed to take up entire allocated space
  -        int rx = currentIPPosition + ipMarginOffset;
  -        int bl = currentBPPosition + bpMarginOffset + text.getOffset();
  +        int rx = currentIPPosition;
  +        int bl = currentBPPosition + text.getOffset();
   
   /*        System.out.println("Text = " + text.getTextArea() +
               "; text width: " + text.getWidth() +
  @@ -1247,8 +1171,8 @@
           saveGraphicsState();
           currentStream.add(((float) w) + " 0 0 "
                             + ((float) -h) + " "
  -                          + (((float) currentIPPosition + ipMarginOffset) / 1000f + 
x) + " "
  -                          + (((float)(currentBPPosition + bpMarginOffset + 1000 * 
h)) / 1000f
  +                          + (((float) currentIPPosition) / 1000f + x) + " "
  +                          + (((float)(currentBPPosition + 1000 * h)) / 1000f
                             + y) + " cm\n" + "/Im" + xobj + " Do\n");
           restoreGraphicsState();
       }
  @@ -1308,6 +1232,7 @@
           float y = (currentBPPosition + viewport.getOffset()) / 1000f;
           float width = viewport.getIPD() / 1000f;
           float height = viewport.getBPD() / 1000f;
  +        // TODO: Calculate the border rect correctly. 
           drawBackAndBorders(viewport, x, y, width, height);
   
           if (viewport.getClip()) {
  
  
  

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

Reply via email to