]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added support for borders at fo:table; fixed a few checkstyle warnings
authorPeter Herweg <pherweg@apache.org>
Sun, 19 Feb 2006 16:56:45 +0000 (16:56 +0000)
committerPeter Herweg <pherweg@apache.org>
Sun, 19 Feb 2006 16:56:45 +0000 (16:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@378923 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/java/org/apache/fop/render/rtf/BorderAttributesConverter.java
src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java
src/java/org/apache/fop/render/rtf/FoUnitsConverter.java
src/java/org/apache/fop/render/rtf/ListAttributesConverter.java
src/java/org/apache/fop/render/rtf/PageAttributesConverter.java
src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/SVGConverter.java
src/java/org/apache/fop/render/rtf/TableAttributesConverter.java
src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java
src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java

index 43adc449f3b90e627dfc3c9fc2dc2b44d064ef62..7517f86d031cf0aa8d810186e28726bf70bbcd1a 100644 (file)
@@ -16,6 +16,7 @@
 
 /* $Id$ */
 
+package org.apache.fop.render.rtf;
 
 /*
  * This file is part of the RTF library of the FOP project, which was originally
@@ -24,8 +25,6 @@
  * the FOP project.
  */
 
-package org.apache.fop.render.rtf;
-
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.IBorderAttributes;
@@ -35,8 +34,14 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
 /** Constants for RTF border attribute names, and a static method for converting
  *  fo attribute strings. */
 
-public class BorderAttributesConverter {
+public final class BorderAttributesConverter {
 
+    /**
+     * Constructor is private, because it's just a utility class.
+     */
+    private BorderAttributesConverter() {
+    }
+    
     /**
      * Create a border control word in attributes, with border properties 
      * as specified in color, style and width.
index 1f287c83cc919e48bc088ec9f9396be4bdcb997d..0eb1208dca14cdb88256be442686b887123d7347 100755 (executable)
@@ -63,12 +63,18 @@ public class FOPRtfAttributes extends RtfAttributes {
         return this;
     }
 
+    /**
+     * Set an attribute that has a Color value.
+     * @param name name of attribute
+     * @param color value of attribute
+     * @return this (which now contains the new entry)
+     */
     public RtfAttributes set(String name, ColorType color) {
         int redComponent = ColorTypeProperty.convertChannelToInteger (color.getRed());
         int greenComponent = ColorTypeProperty.convertChannelToInteger (color.getGreen());
         int blueComponent = ColorTypeProperty.convertChannelToInteger (color.getBlue());
         set(name, RtfColorTable.getInstance().getColorNumber(
-                redComponent,greenComponent, blueComponent).intValue());
+                redComponent, greenComponent, blueComponent).intValue());
         return this;
     }
 }
index b326a7540b30ce771f43b7ea2ce35243f953a4e9..0f90b1b9a1dda9530dd42bd6ad8151d7d42ce26d 100644 (file)
@@ -35,7 +35,7 @@ import org.apache.fop.apps.FOPException;
  *  for the JFOR project and is now integrated into FOP.
  */
 
-class FoUnitsConverter {
+final class FoUnitsConverter {
     private static final FoUnitsConverter INSTANCE = new FoUnitsConverter();
 
     /** points to twips: 1 twip is 1/20 of a point */
@@ -124,14 +124,14 @@ class FoUnitsConverter {
     /** convert a font size given in points like "12pt" */
     int convertFontSize(String size) throws FOPException {
         size = size.trim();
-        final String FONT_SUFFIX = "pt";
-        if (!size.endsWith(FONT_SUFFIX)) {
+        final String sFONTSUFFIX = "pt";
+        if (!size.endsWith(sFONTSUFFIX)) {
             throw new FOPException("Invalid font size '" + size + "', must end with '"
-                                   + FONT_SUFFIX + "'");
+                                   + sFONTSUFFIX + "'");
         }
 
         float result = 0;
-        size = size.substring(0, size.length() - FONT_SUFFIX.length());
+        size = size.substring(0, size.length() - sFONTSUFFIX.length());
         try {
             result = (Float.valueOf(size).floatValue());
         } catch (Exception e) {
index c050e38136884a825750e7c238ae50c76c1dda50..03307c7001f6ca16275a3be48afcc021d26f4644 100644 (file)
@@ -36,9 +36,20 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
 /**
  * Provides methods to convert list attributes to RtfAttributes.
  */
-public class ListAttributesConverter {
+public final class ListAttributesConverter {
     
+    /**
+     * Constructor is private, because it's just a utility class.
+     */
+    private ListAttributesConverter() {
+    }
     
+    /**
+     * Reads an FO object's properties and adds returns them as RtfAttributes.
+     * @param fobj FO object
+     * @return RtfAttributes object which contains the read values.
+     * @throws FOPException Thrown when an IO-problem occurs.
+     */
     static RtfAttributes convertAttributes(ListBlock fobj)
     throws FOPException {
         
index 4d1cd0052825385601f6f74d1843c9d7a4e55422..2b1af81fd813e157f8207c467a57a620a3f27b9e 100644 (file)
@@ -16,7 +16,6 @@
 
 /* $Id$ */
 
-
 package org.apache.fop.render.rtf;
 
 import org.apache.commons.logging.Log;
@@ -37,10 +36,16 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage;
  *  @author Peter Herweg, pherweg@web.de
  */
 
-class PageAttributesConverter {
+final class PageAttributesConverter {
 
     private static Log log = new SimpleLog("FOP/RTF");
 
+    /**
+     * Constructor is private, because it's just a utility class.
+     */
+    private PageAttributesConverter() {
+    }
+    
     /** convert xsl:fo attributes to RTF text attributes */
     static RtfAttributes convertPageAttributes(SimplePageMaster pagemaster) {
         FOPRtfAttributes attrib = new FOPRtfAttributes();
index 931baeb63146bc3191e31900451c9226c5d19b23..6e0c58be2175f3b00f5d3d410a9cd51f4414c54f 100644 (file)
@@ -63,6 +63,7 @@ import org.apache.fop.fo.pagination.PageSequenceMaster;
 import org.apache.fop.fo.pagination.Region;
 import org.apache.fop.fo.pagination.SimplePageMaster;
 import org.apache.fop.fo.pagination.StaticContent;
+import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FOText;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes;
@@ -497,13 +498,30 @@ public class RTFHandler extends FOEventHandler {
         TableContext tableContext = new TableContext(builderContext);
 
         try {
-            RtfAttributes atts
-                = TableAttributesConverter.convertTableAttributes(tbl);
-
             final IRtfTableContainer tc
                 = (IRtfTableContainer)builderContext.getContainer(
-                    IRtfTableContainer.class, true, null);
-            builderContext.pushContainer(tc.newTable(atts, tableContext));
+                        IRtfTableContainer.class, true, null);
+            
+            RtfAttributes atts
+                = TableAttributesConverter.convertTableAttributes(tbl);
+            
+            RtfTable table = tc.newTable(atts, tableContext);
+            
+            CommonBorderPaddingBackground border = tbl.getCommonBorderPaddingBackground();
+            RtfAttributes borderAttributes = new RtfAttributes();
+                    
+            BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.BEFORE,
+                    borderAttributes, ITableAttributes.CELL_BORDER_TOP);
+            BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.AFTER,
+                    borderAttributes, ITableAttributes.CELL_BORDER_BOTTOM);
+            BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.START,
+                    borderAttributes, ITableAttributes.CELL_BORDER_LEFT);
+            BorderAttributesConverter.makeBorder(border, CommonBorderPaddingBackground.END,
+                    borderAttributes,  ITableAttributes.CELL_BORDER_RIGHT);
+            
+            table.setBorderAttributes(borderAttributes);
+            
+            builderContext.pushContainer(table);
         } catch (Exception e) {
             log.error("startTable:" + e.getMessage());
             throw new RuntimeException(e.getMessage());
index 255c85136b4fa95dcd5a9d472f7297dacc1da5dd..f8fb5f27528c41c0c824daddeba08a834d2f4797 100644 (file)
@@ -31,11 +31,17 @@ import org.apache.fop.image.XMLImage;
 /**
  * Helper class for converting SVG to bitmap images.
  */
-public class SVGConverter {
+public final class SVGConverter {
 
     /** logger instance */
     private static Log log = LogFactory.getLog(SVGConverter.class);
 
+    /**
+     * Constructor is private, because it's just a utility class.
+     */
+    private SVGConverter() {
+    }
+    
     /**
      * Converts a SVG image to a JPEG bitmap.
      * @param image the SVG image
index f1e4b4e86c28c05702c22d863d3a7129f3249321..31527c64509aa18b0e9ffc18bd51d31c5aecd554 100644 (file)
@@ -48,7 +48,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
  * Provides methods to convert the attributes to RtfAttributes.
  */
 
-public class TableAttributesConverter {
+public final class TableAttributesConverter {
 
     private static Log log = new SimpleLog("FOP/RTF");
 
@@ -57,7 +57,7 @@ public class TableAttributesConverter {
     //////////////////////////////////////////////////
 
     /**
-     * Constructor.
+     * Constructor is private, because it's just a utility class.
      */
     private TableAttributesConverter() {
     }
index df6c0a1fe0cb4ad26a986df641eb7d556dae47ab..5a51969069d3f7e54a2f072ba39863f125f891a2 100644 (file)
@@ -50,7 +50,13 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
  *  @author Chris Scott
  *  @author rmarra
  */
-class TextAttributesConverter {
+final class TextAttributesConverter {
+    
+    /**
+     * Constructor is private, because it's just a utility class.
+     */
+    private TextAttributesConverter() {
+    }
     
     /**
      * Converts all known text FO properties to RtfAttributes
index 4ec8a3d36e18fcc695befd56097399fe1e2b62a0..6c2ca80ec68477f719113cd5fea009633e5e7bba 100644 (file)
@@ -16,6 +16,7 @@
 
 /* $Id$ */
 
+package org.apache.fop.render.rtf.rtflib.exceptions;
 
 /*
  * This file is part of the RTF library of the FOP project, which was originally
@@ -24,8 +25,6 @@
  * the FOP project.
  */
 
-package org.apache.fop.render.rtf.rtflib.exceptions;
-
 /**  Base class for rtflib exceptions.
  *  @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
  */
index a4e8a5dce4022217a25d43da148bbd7be90d0745..c2a8ef487f95003e4ee91be2dfb93934c5ec7b3e 100644 (file)
@@ -16,6 +16,7 @@
 
 /* $Id$ */
 
+package org.apache.fop.render.rtf.rtflib.exceptions;
 
 /*
  * This file is part of the RTF library of the FOP project, which was originally
@@ -24,8 +25,6 @@
  * the FOP project.
  */
 
-package org.apache.fop.render.rtf.rtflib.exceptions;
-
 /**  Thrown when a method call would lead to an invalid RTF document structure.
  *  @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
  */
index 2644124c19c42dc75494839711bb4830d0afedda..d33ebdad43c9387f80761c8f376b241756a4e56a 100644 (file)
@@ -36,6 +36,7 @@ public class RtfTable extends RtfContainer {
     private RtfTableRow row;
     private int highestRow = 0;
     private Boolean isNestedTable = null;
+    private RtfAttributes borderAttributes = null;
 
     /** Added by Boris Poudérous on 07/22/2002 in order to process
      *  number-columns-spanned attribute */
@@ -209,4 +210,20 @@ public class RtfTable extends RtfContainer {
 
         return null;  
     }
+
+    /**
+     * Sets the RtfAttributes for the borders of the table.
+     * @param attributes Border attributes of the table.
+     */
+    public void setBorderAttributes(RtfAttributes attributes) {
+        borderAttributes = attributes;
+    }
+    
+    /**
+     * Returns the RtfAttributes for the borders of the table.
+     * @return Border attributes of the table.
+     */
+    public RtfAttributes getBorderAttributes() {
+        return borderAttributes;
+    }
 }
index 0a992559a73189763dd8b894157eb121809459d2..681ab9a8210080aff92e64f39f1d4554f21474f5 100644 (file)
@@ -186,42 +186,81 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes {
             xPos = ((Integer)leftIndent).intValue();
         }
         
+        RtfAttributes tableBorderAttributes = getTable().getBorderAttributes();
+        
         int index = 0;
         for (Iterator it = getChildren().iterator(); it.hasNext();) {
             final RtfElement e = (RtfElement)it.next();
             if (e instanceof RtfTableCell) {
-                // Added by Normand Masse
+                
+                RtfTableCell rtfcell = (RtfTableCell)e;
+                
                 // Adjust the cell's display attributes so the table's/row's borders
                 // are drawn properly.
-                RtfTableCell rtfcell = (RtfTableCell)e;
+                
+                // get border attributes from table
+                if (index == 0) {
+                    if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_LEFT)) {
+                        rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_LEFT,
+                            (RtfAttributes) tableBorderAttributes.getValue(
+                                    ITableAttributes.CELL_BORDER_LEFT));
+                    }
+                }
+
+                if (index == this.getChildCount() - 1) {
+                    if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_RIGHT)) {
+                        rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_RIGHT,
+                            (RtfAttributes) tableBorderAttributes.getValue(
+                                    ITableAttributes.CELL_BORDER_RIGHT));
+                    }
+                }
+
+                if (isFirstRow()) {
+                    if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_TOP)) {
+                        rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
+                            (RtfAttributes) (RtfAttributes) tableBorderAttributes.getValue(
+                                    ITableAttributes.CELL_BORDER_TOP));
+                    }
+                }
+
+                if ((parentTable != null) && (parentTable.isHighestRow(id))) {
+                    if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_BOTTOM)) {
+                        rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_BOTTOM,
+                            (RtfAttributes) tableBorderAttributes.getValue(
+                                    ITableAttributes.CELL_BORDER_BOTTOM));
+                    }
+                }
+                
+                // get border attributes from row
                 if (index == 0) {
                     if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_LEFT)) {
                         rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_LEFT,
-                            (String)attrib.getValue(ITableAttributes.ROW_BORDER_LEFT));
+                            (String) attrib.getValue(ITableAttributes.ROW_BORDER_LEFT));
                     }
                 }
 
                 if (index == this.getChildCount() - 1) {
                     if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_RIGHT)) {
                         rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_RIGHT,
-                            (String)attrib.getValue(ITableAttributes.ROW_BORDER_RIGHT));
+                            (String) attrib.getValue(ITableAttributes.ROW_BORDER_RIGHT));
                     }
                 }
 
                 if (isFirstRow()) {
                     if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_TOP)) {
                         rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
-                            (String)attrib.getValue(ITableAttributes.ROW_BORDER_TOP));
+                            (String) attrib.getValue(ITableAttributes.ROW_BORDER_TOP));
                     }
                 }
 
                 if ((parentTable != null) && (parentTable.isHighestRow(id))) {
                     if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_BOTTOM)) {
                         rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_BOTTOM,
-                            (String)attrib.getValue(ITableAttributes.ROW_BORDER_BOTTOM));
+                            (String) attrib.getValue(ITableAttributes.ROW_BORDER_BOTTOM));
                     }
                 }
 
+                // write cell's definition
                 xPos = rtfcell.writeCellDef(xPos);
             }
           index++; // Added by Boris POUDEROUS on 2002/07/02