diff options
author | Peter Herweg <pherweg@apache.org> | 2006-02-19 16:56:45 +0000 |
---|---|---|
committer | Peter Herweg <pherweg@apache.org> | 2006-02-19 16:56:45 +0000 |
commit | 8a15784dc75cb0feff7bfc4b9e55ee11a4e7a26a (patch) | |
tree | faf311834cb49309e75a7f7c62c40fac35297610 /src/java/org/apache/fop/render/rtf | |
parent | dc83787f3b2d7a3c4ba3274a928529fec36b3feb (diff) | |
download | xmlgraphics-fop-8a15784dc75cb0feff7bfc4b9e55ee11a4e7a26a.tar.gz xmlgraphics-fop-8a15784dc75cb0feff7bfc4b9e55ee11a4e7a26a.zip |
added support for borders at fo:table; fixed a few checkstyle warnings
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@378923 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/rtf')
13 files changed, 142 insertions, 31 deletions
diff --git a/src/java/org/apache/fop/render/rtf/BorderAttributesConverter.java b/src/java/org/apache/fop/render/rtf/BorderAttributesConverter.java index 43adc449f..7517f86d0 100644 --- a/src/java/org/apache/fop/render/rtf/BorderAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/BorderAttributesConverter.java @@ -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,9 +34,15 @@ 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. * @param border The CommonBorderPaddingBackground object. diff --git a/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java b/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java index 1f287c83c..0eb1208dc 100755 --- a/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java +++ b/src/java/org/apache/fop/render/rtf/FOPRtfAttributes.java @@ -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; } } diff --git a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java index b326a7540..0f90b1b9a 100644 --- a/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java +++ b/src/java/org/apache/fop/render/rtf/FoUnitsConverter.java @@ -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) { diff --git a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java index c050e3813..03307c700 100644 --- a/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/ListAttributesConverter.java @@ -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 { diff --git a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java index 4d1cd0052..2b1af81fd 100644 --- a/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/PageAttributesConverter.java @@ -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(); diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 931baeb63..6e0c58be2 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -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()); diff --git a/src/java/org/apache/fop/render/rtf/SVGConverter.java b/src/java/org/apache/fop/render/rtf/SVGConverter.java index 255c85136..f8fb5f275 100644 --- a/src/java/org/apache/fop/render/rtf/SVGConverter.java +++ b/src/java/org/apache/fop/render/rtf/SVGConverter.java @@ -31,12 +31,18 @@ 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 * @return a byte array containing the JPEG image diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index f1e4b4e86..31527c645 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -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() { } diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index df6c0a1fe..5a5196906 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -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 diff --git a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java index 4ec8a3d36..6c2ca80ec 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfException.java @@ -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 */ diff --git a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java index a4e8a5dce..c2a8ef487 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/exceptions/RtfStructureException.java @@ -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 */ diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java index 2644124c1..d33ebdad4 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java @@ -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; + } } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java index 0a992559a..681ab9a82 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java @@ -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 |