(at table and block). Submitted By: Peter Herweg <pherweg@web.de> git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196999 13f79535-47bb-0310-9956-ffa450edef68pull/30/head
@@ -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); | |||
@@ -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; |
@@ -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); |
@@ -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 |
@@ -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; | |||
} | |||
} |
@@ -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(); |
@@ -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(); |