gmazza      2003/11/01 13:05:23

  Modified:    src/java/org/apache/fop/area RegionViewport.java
               src/java/org/apache/fop/layoutmgr PageLayoutManager.java
               src/java/org/apache/fop/render/pdf PDFRenderer.java
  Log:
  1.  PDF block background rendering properly offset to account for region
  borders and padding.
  2.  Helper methods added to RegionViewport for quickly determining region
  margins, useful for render.* and layoutmgr.* classes.
  
  Revision  Changes    Path
  1.2       +87 -0     xml-fop/src/java/org/apache/fop/area/RegionViewport.java
  
  Index: RegionViewport.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/area/RegionViewport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegionViewport.java       11 Mar 2003 13:05:27 -0000      1.1
  +++ RegionViewport.java       1 Nov 2003 21:05:23 -0000       1.2
  @@ -54,6 +54,8 @@
   import java.io.IOException;
   import java.util.HashMap;
   
  +import org.apache.fop.traits.BorderProps;
  +
   /**
    * Region Viewport reference area.
    * This area is the viewport for a region and contains a region area.
  @@ -107,6 +109,91 @@
        */
       public Rectangle2D getViewArea() {
           return viewArea;
  +    }
  +
  +    /**
  +     * Return the margin-before offset for printing text
  +     *  (sum of region border and padding)
  +     *
  +     * @return margin-before offset, in millipoints
  +     */
  +    public int getMarginBeforeWidth() {
  +        int margin = 0;
  +        BorderProps bps = (BorderProps) getTrait(Trait.BORDER_BEFORE);
  +        if (bps != null) {
  +            margin = bps.width;
  +        }
  +        
  +        Integer padWidth = (Integer) getTrait(Trait.PADDING_BEFORE);
  +        if (padWidth != null) {
  +            margin += padWidth.intValue();
  +        }
  +
  +        return margin;
  +    }
  +    
  +    /**
  +     * Return the margin-after offset for printing text
  +     *  (sum of region border and padding)
  +     *
  +     * @return margin-after offset, in millipoints
  +     */
  +    public int getMarginAfterWidth() {
  +        int margin = 0;
  +        
  +        BorderProps bps = (BorderProps) getTrait(Trait.BORDER_AFTER);
  +        if (bps != null) {
  +            margin = bps.width;
  +        }
  +        
  +        Integer padWidth = (Integer) getTrait(Trait.PADDING_AFTER);
  +        if (padWidth != null) {
  +            margin += padWidth.intValue();
  +        }
  +
  +        return margin;
  +    }
  +
  +    /**
  +     * Return the margin-start offset for printing text
  +     *  (sum of region border and padding)
  +     *
  +     * @return margin-start offset, in millipoints
  +     */
  +    public int getMarginStartWidth() {
  +        int margin = 0;
  +        BorderProps bps = (BorderProps) getTrait(Trait.BORDER_START);
  +        if (bps != null) {
  +            margin = bps.width;
  +        }
  +        
  +        Integer padWidth = (Integer) getTrait(Trait.PADDING_START);
  +        if (padWidth != null) {
  +            margin += padWidth.intValue();
  +        }
  +
  +        return margin;
  +    }
  +
  +    /**
  +     * Return the margin-end offset for printing text
  +     *  (sum of region border and padding)
  +     *
  +     * @return margin-end offset, in millipoints
  +     */
  +    public int getMarginEndWidth() {
  +        int margin = 0;
  +        BorderProps bps = (BorderProps) getTrait(Trait.BORDER_END);
  +        if (bps != null) {
  +            margin = bps.width;
  +        }
  +        
  +        Integer padWidth = (Integer) getTrait(Trait.PADDING_END);
  +        if (padWidth != null) {
  +            margin += padWidth.intValue();
  +        }
  +
  +        return margin;
       }
   
       private void writeObject(java.io.ObjectOutputStream out)
  
  
  
  1.22      +4 -46     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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PageLayoutManager.java    1 Nov 2003 04:28:01 -0000       1.21
  +++ PageLayoutManager.java    1 Nov 2003 21:05:23 -0000       1.22
  @@ -84,7 +84,6 @@
   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;
  @@ -475,29 +474,8 @@
           RegionViewport rv = curPage.getPage().getRegionViewport(
                       Region.BODY_CODE);
           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();
  -        }
  -
  +        flowBPD = (int) rv.getViewArea().getHeight() -
  +            rv.getMarginBeforeWidth() - rv.getMarginAfterWidth();
           return curPage;
       }
   
  @@ -735,29 +713,9 @@
           // get Width or Height as IPD for span
           
           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();
  -        }
  +        int ipdWidth = (int) rv.getViewArea().getWidth() -
  +            rv.getMarginStartWidth() - rv.getMarginEndWidth();
   
  -        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);
  
  
  
  1.22      +6 -27     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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- PDFRenderer.java  1 Nov 2003 04:28:01 -0000       1.21
  +++ PDFRenderer.java  1 Nov 2003 21:05:23 -0000       1.22
  @@ -128,7 +128,7 @@
   writing mode
   text decoration
   
  - */
  +*/
   
   /**
    * Renderer that renders areas to PDF
  @@ -511,10 +511,10 @@
        * @param block the block to render the traits
        */
       protected void handleBlockTraits(Block block) {
  -        float startx = currentIPPosition / 1000f;
  -        float starty = currentBPPosition / 1000f;
  +        float startx = (currentIPPosition + IPMarginOffset)/ 1000f;
  +        float starty = (currentBPPosition + BPMarginOffset)/ 1000f;
           drawBackAndBorders(block, startx, starty,
  -                           block.getWidth() / 1000f, block.getHeight() / 1000f);
  +            block.getWidth() / 1000f, block.getHeight() / 1000f);
       }
   
       /**
  @@ -537,29 +537,8 @@
   
           if (region.getRegion().getRegionClass() == 
org.apache.fop.fo.pagination.Region.BODY_CODE)
           {   
  -            // need to collect vertical and horizontal offsets
  -            // for body-region (for rendering of text)
  -            BorderProps bps = (BorderProps) region.getTrait(Trait.BORDER_BEFORE);
  -            if (bps != null) {
  -                BPMarginOffset = bps.width;
  -            }
  -                              
  -            bps = (BorderProps) region.getTrait(Trait.BORDER_START);
  -            if (bps != null) {
  -                IPMarginOffset = bps.width;
  -            }
  -            
  -            java.lang.Integer padWidth = (java.lang.Integer) 
  -                region.getTrait(Trait.PADDING_BEFORE);
  -            if (padWidth != null) {
  -                BPMarginOffset += padWidth.intValue();
  -            }
  -                              
  -            padWidth = (java.lang.Integer) 
  -                region.getTrait(Trait.PADDING_START);
  -            if (padWidth != null) {
  -                IPMarginOffset += padWidth.intValue();
  -            }
  +            BPMarginOffset = region.getMarginBeforeWidth();
  +            IPMarginOffset = region.getMarginStartWidth();
           }
   
           drawBackAndBorders(region, startx, starty, width, height);
  
  
  

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

Reply via email to