gmazza      2003/10/26 11:29:14

  Modified:    src/java/org/apache/fop/layoutmgr TraitSetter.java
               src/java/org/apache/fop/render/pdf PDFRenderer.java
  Log:
  1. TraitSetter modified to provide padding properties for regions.
  2. PDFRenderer modified to take into account region borders and region padding
     when rendering text.  (Possibly temporary solution--may need to move code
     to base AbstractRenderer in future.)  Work incomplete--will need to also reduce
     line length accordingly to account for region borders and padding.
  
  Revision  Changes    Path
  1.3       +20 -0     xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java
  
  Index: TraitSetter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/TraitSetter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TraitSetter.java  12 Aug 2003 18:02:45 -0000      1.2
  +++ TraitSetter.java  26 Oct 2003 19:29:14 -0000      1.3
  @@ -148,6 +148,26 @@
           if (bps.width != 0) {
               curBlock.addTrait(Trait.BORDER_END, bps);
           }
  +        
  +        int padding = bordProps.getPadding(CommonBorderAndPadding.START, false);
  +        if (padding != 0) {
  +            curBlock.addTrait(Trait.PADDING_START, new java.lang.Integer(padding));
  +        }
  +        
  +        padding = bordProps.getPadding(CommonBorderAndPadding.END, false);
  +        if (padding != 0) {
  +            curBlock.addTrait(Trait.PADDING_END, new java.lang.Integer(padding));
  +        }
  +
  +        padding = bordProps.getPadding(CommonBorderAndPadding.BEFORE, false);
  +        if (padding != 0) {
  +            curBlock.addTrait(Trait.PADDING_BEFORE, new java.lang.Integer(padding));
  +        }
  +        
  +        padding = bordProps.getPadding(CommonBorderAndPadding.AFTER, false);
  +        if (padding != 0) {
  +            curBlock.addTrait(Trait.PADDING_AFTER, new java.lang.Integer(padding));
  +        }
       }
   
       private static BorderProps getBorderProps(CommonBorderAndPadding bordProps, int 
side) {
  
  
  
  1.19      +63 -20    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- PDFRenderer.java  21 Sep 2003 20:56:24 -0000      1.18
  +++ PDFRenderer.java  26 Oct 2003 19:29:14 -0000      1.19
  @@ -227,6 +227,16 @@
       private StringBuffer wordAreaPDF = new StringBuffer();
   
       /**
  +     * Offset for rendering text, taking into account borders and padding
  +     */
  +    protected int BPMarginOffset = 0;
  +
  +    /**
  +     * Offset for rendering text, taking into account borders and padding
  +     */
  +    protected int IPMarginOffset = 0;
  +
  +    /**
        * create the PDF renderer
        */
       public PDFRenderer() {
  @@ -467,7 +477,6 @@
           this.pdfDoc.output(ostream);
       }
   
  -
       /**
        * @see org.apache.fop.render.AbstractRenderer#startVParea(CTM)
        */
  @@ -494,6 +503,21 @@
       }
   
       /**
  +     * Handle block traits.
  +     * The block could be any sort of block with any positioning
  +     * so this should render the traits such as border and background
  +     * in its position.
  +     *
  +     * @param block the block to render the traits
  +     */
  +    protected void handleBlockTraits(Block block) {
  +        float startx = currentIPPosition / 1000f;
  +        float starty = currentBPPosition / 1000f;
  +        drawBackAndBorders(block, startx, starty,
  +                           block.getWidth() / 1000f, block.getHeight() / 1000f);
  +    }
  +
  +    /**
        * 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.)
  @@ -510,22 +534,35 @@
           Trait.Background back;
           back = (Trait.Background)region.getTrait(Trait.BACKGROUND);
           */
  -        drawBackAndBorders(region, startx, starty, width, height);
  -    }
   
  -    /**
  -     * Handle block traits.
  -     * The block could be any sort of block with any positioning
  -     * so this should render the traits such as border and background
  -     * in its position.
  -     *
  -     * @param block the block to render the traits
  -     */
  -    protected void handleBlockTraits(Block block) {
  -        float startx = currentIPPosition / 1000f;
  -        float starty = currentBPPosition / 1000f;
  -        drawBackAndBorders(block, startx, starty,
  -                           block.getWidth() / 1000f, block.getHeight() / 1000f);
  +        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();
  +            }
  +        }
  +
  +        drawBackAndBorders(region, startx, starty, width, height);
       }
   
       /**
  @@ -848,7 +885,6 @@
        * @see org.apache.fop.render.Renderer#renderCharacter(Character)
        */
       public void renderCharacter(Character ch) {
  -
           super.renderCharacter(ch);
       }
   
  @@ -875,9 +911,16 @@
               updateColor(ct, true, pdf);
           }
   
  -        int rx = currentBlockIPPosition;
  -        // int bl = pageHeight - currentBPPosition;
  -        int bl = currentBPPosition + word.getOffset();
  +        // 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 = currentBlockIPPosition + IPMarginOffset;
  +        int bl = currentBPPosition + BPMarginOffset + word.getOffset();
  +
  +/*      System.out.println("BlockIP Position: " + currentBlockIPPosition +
  +            "; currentBPPosition: " + currentBPPosition +
  +            "; offset: " + word.getOffset() +
  +            "; Word = " + word.getWord()); */
   
           // Set letterSpacing
           //float ls = fs.getLetterSpacing() / this.currentFontSize;
  
  
  

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

Reply via email to