From 3415cc316ddd8a44514553b582f2bd162831b204 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Sat, 8 Nov 2003 19:31:41 +0000 Subject: [PATCH] RTF: Add support for number-rows-spanned, height (at table-row) and margin-left (at table and block). Submitted By: Peter Herweg git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196999 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/rtf/RTFHandler.java | 13 ++++--- .../render/rtf/TableAttributesConverter.java | 39 ++++++++++++++----- .../render/rtf/TextAttributesConverter.java | 2 +- .../rtf/rtflib/rtfdoc/ITableAttributes.java | 3 +- .../rtf/rtflib/rtfdoc/RtfTableCell.java | 8 +++- .../render/rtf/rtflib/rtfdoc/RtfTableRow.java | 12 ++++++ .../render/rtf/rtflib/rtfdoc/RtfTextrun.java | 14 ++++++- 7 files changed, 71 insertions(+), 20 deletions(-) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index ef2df1947..3ef09ab21 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -372,9 +372,11 @@ public class RTFHandler extends FOInputHandler { public void startTable(Table tbl) { // create an RtfTable in the current table container TableContext tableContext = new TableContext(builderContext); - RtfAttributes atts = new RtfAttributes(); try { + RtfAttributes atts = + TableAttributesConverter.convertTableAttributes(tbl.properties); + final IRtfTableContainer tc = (IRtfTableContainer)builderContext.getContainer(IRtfTableContainer.class, true, null); @@ -499,7 +501,7 @@ public class RTFHandler extends FOInputHandler { public void startBody(TableBody tb) { try { RtfAttributes atts = TableAttributesConverter.convertRowAttributes (tb.properties, - null, null); + null); RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this); tbl.setHeaderAttribs(atts); @@ -534,7 +536,7 @@ public class RTFHandler extends FOInputHandler { RtfAttributes tblAttribs = tbl.getRtfAttributes(); RtfAttributes tblRowAttribs = new RtfAttributes(); RtfAttributes atts = TableAttributesConverter.convertRowAttributes(tr.properties, - null, tbl.getHeaderAttribs()); + tbl.getHeaderAttribs()); builderContext.pushContainer(tbl.newTableRow(atts)); @@ -577,13 +579,12 @@ public class RTFHandler extends FOInputHandler { float width = tctx.getColumnWidth(); // create an RtfTableCell in the current RtfTableRow - RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties, - null); + RtfAttributes atts = TableAttributesConverter.convertCellAttributes(tc.properties); RtfTableCell cell = row.newTableCell((int)width, atts); //process number-rows-spanned attribute Property p = null; - if ((p = tc.properties.get("number-rows-spanned")) != null && false) { + if ((p = tc.properties.get("number-rows-spanned")) != null) { // Start vertical merge cell.setVMerge(RtfTableCell.MERGE_START); diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 3a08ee0c0..650851e4b 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -104,7 +104,34 @@ public class TableAttributesConverter { ////////////////////////////////////////////////// // @@ Static converter methods ////////////////////////////////////////////////// + /** + * Converts table-only attributes to rtf attributes. + * + * @param attrs Given attributes + * @param defaultAttributes Default rtf attributes + * + * @return All valid rtf attributes together + * + * @throws ConverterException On convertion error + */ + static RtfAttributes convertTableAttributes(PropertyList properties) + throws FOPException { + RtfAttributes attrib = new RtfAttributes(); + LengthProperty lengthProp=null; + // margin-left + lengthProp=(LengthProperty)properties.get("margin-left"); + if (lengthProp != null) { + Float f = new Float(lengthProp.getLength().getValue() / 1000f); + final String sValue = f.toString() + "pt"; + + attrib.set( + ITableAttributes.ATTR_ROW_LEFT_INDENT, + (int)FoUnitsConverter.getInstance().convertToTwips(sValue)); + } + + return attrib; + } /** * Converts cell attributes to rtf attributes. @@ -115,7 +142,7 @@ public class TableAttributesConverter { * * @throws ConverterException On convertion error */ - static RtfAttributes convertCellAttributes(PropertyList props, PropertyList defProps) + static RtfAttributes convertCellAttributes(PropertyList props) throws FOPException { Property p; @@ -124,11 +151,7 @@ public class TableAttributesConverter { RtfAttributes attrib = null; - if (defProps != null) { - attrib = convertCellAttributes(defProps, null); - } else { attrib = new RtfAttributes(); - } boolean isBorderPresent = false; @@ -269,7 +292,7 @@ public class TableAttributesConverter { * @throws ConverterException On convertion error */ static RtfAttributes convertRowAttributes(PropertyList props, - PropertyList defProps, RtfAttributes rtfatts) + RtfAttributes rtfatts) throws FOPException { Property p; @@ -278,14 +301,10 @@ public class TableAttributesConverter { RtfAttributes attrib = null; - if (defProps != null) { - attrib = convertRowAttributes(defProps, null, rtfatts); - } else { if (rtfatts == null) { attrib = new RtfAttributes(); } else { attrib = rtfatts; - } } String attrValue; diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index be4d79cf4..d8b8e0fab 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -266,7 +266,7 @@ class TextAttributesConverter { String sValue = f.toString() + "pt"; rtfAttr.set( - RtfText.LEFT_INDENT_BODY, + RtfText.RIGHT_INDENT_BODY, (int)FoUnitsConverter.getInstance().convertToTwips(sValue)); } else { rtfAttr.set(RtfText.RIGHT_INDENT_BODY, 0); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java index e85afc511..f46109b93 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableAttributes.java @@ -74,6 +74,7 @@ public interface ITableAttributes { /** half the space between the cells of a table row in twips */ public static final String ATTR_RTF_15_TRGAPH = "trgaph"; + public static final String ATTR_ROW_LEFT_INDENT = "trleft"; // RTF 1.6 Row and table attributes /** table row padding, top */ @@ -103,7 +104,7 @@ public interface ITableAttributes { ATTR_ROW_PADDING_BOTTOM, ATTR_ROW_U_PADDING_BOTTOM, ATTR_ROW_PADDING_LEFT, ATTR_ROW_U_PADDING_LEFT, ATTR_ROW_PADDING_RIGHT, ATTR_ROW_U_PADDING_RIGHT, - ATTR_RTF_15_TRGAPH + ATTR_RTF_15_TRGAPH, ATTR_ROW_LEFT_INDENT }; // Cell attributes diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java index f84b5c970..de11831ed 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java @@ -481,6 +481,12 @@ implements IRtfParagraphContainer, IRtfListContainer, IRtfTableContainer, RtfAttributes attrs = new RtfAttributes(); attrs.set("intbl"); - return RtfTextrun.getTextrun(this, writer, attrs); + RtfTextrun textrun=RtfTextrun.getTextrun(this, writer, attrs); + + //Suppress the very last \par, because the closing \cell applies the + //paragraph attributes. + textrun.setSuppressLastPar(true); + + return textrun; } } 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 5be8d50f0..d2031927d 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 @@ -184,6 +184,12 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes { writeAttributes(attrib, ITableAttributes.CELL_BORDER); writeAttributes(attrib, BorderAttributesConverter.BORDERS); + if(attrib.isSet(ITableAttributes.ROW_HEIGHT)) { + writeOneAttribute( + ITableAttributes.ROW_HEIGHT, + attrib.getValue(ITableAttributes.ROW_HEIGHT)); + } + /** * Added by Boris POUDEROUS on 07/02/2002 * in order to get the indexes of the cells preceding a cell that @@ -227,6 +233,12 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes { // write X positions of our cells int xPos = 0; + + final Object leftIndent = attrib.getValue(ITableAttributes.ATTR_ROW_LEFT_INDENT); + if (leftIndent != null) { + xPos = ((Integer)leftIndent).intValue(); + } + index = 0; // Line added by Boris POUDEROUS on 07/02/2002 for (Iterator it = getChildren().iterator(); it.hasNext();) { final RtfElement e = (RtfElement)it.next(); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java index 7a12202c2..aae0190d8 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java @@ -70,6 +70,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic; */ public class RtfTextrun extends RtfContainer { + private boolean bSuppressLastPar=false; /** Class which represents the opening of a RTF group mark.*/ private class RtfOpenGroupMark extends RtfElement @@ -203,6 +204,15 @@ public class RtfTextrun extends RtfContainer { return textrun; } + /** + * specify, if the last paragraph control word (\par) should be suppressed. + * @param bSuppress true, if the last \par should be suppressed + * @throws IOException for I/O problems + */ + public void setSuppressLastPar(boolean bSuppress) { + bSuppressLastPar=bSuppress; + } + /** * write RTF code of all our children * @throws IOException for I/O problems @@ -269,7 +279,9 @@ public class RtfTextrun extends RtfContainer { boolean bHide=false; bHide=bRtfParagraphBreak; bHide=bHide && - (bPrevPar || bFirst || (bLast && lastParagraphBreak!=null && e==lastParagraphBreak) ); + (bPrevPar || bFirst || + (bSuppressLastPar && bLast && lastParagraphBreak!=null && e==lastParagraphBreak) + ); if( !bHide) { e.writeRtf(); -- 2.39.5