]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1. TraitSetter modified to provide padding properties for regions.
authorGlen Mazza <gmazza@apache.org>
Sun, 26 Oct 2003 19:29:14 +0000 (19:29 +0000)
committerGlen Mazza <gmazza@apache.org>
Sun, 26 Oct 2003 19:29:14 +0000 (19:29 +0000)
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.

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

src/java/org/apache/fop/layoutmgr/TraitSetter.java
src/java/org/apache/fop/render/pdf/PDFRenderer.java

index 017a7258c469b3b921ed83701d6d4d54e3fc2c46..6c0ff71e718479d3a637b0fe75edb3a6bb0a71ec 100644 (file)
@@ -148,6 +148,26 @@ public class TraitSetter {
         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) {
index ccbe28ba0deaf5c318fe4c315d35486ecea4ba2a..bc631660dc69276fbde51d91a7a0d156b043bb20 100644 (file)
@@ -226,6 +226,16 @@ public class PDFRenderer extends PrintRenderer {
      */
     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
      */
@@ -467,7 +477,6 @@ public class PDFRenderer extends PrintRenderer {
         this.pdfDoc.output(ostream);
     }
 
-
     /**
      * @see org.apache.fop.render.AbstractRenderer#startVParea(CTM)
      */
@@ -493,6 +502,21 @@ public class PDFRenderer extends PrintRenderer {
         currentState.pop();
     }
 
+    /**
+     * 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.
@@ -510,22 +534,35 @@ public class PDFRenderer extends PrintRenderer {
         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 @@ public class PDFRenderer extends PrintRenderer {
      * @see org.apache.fop.render.Renderer#renderCharacter(Character)
      */
     public void renderCharacter(Character ch) {
-
         super.renderCharacter(ch);
     }
 
@@ -875,9 +911,16 @@ public class PDFRenderer extends PrintRenderer {
             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;