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);
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);
RtfAttributes tblAttribs = tbl.getRtfAttributes();
RtfAttributes tblRowAttribs = new RtfAttributes();
RtfAttributes atts = TableAttributesConverter.convertRowAttributes(tr.properties,
- null, tbl.getHeaderAttribs());
+ tbl.getHeaderAttribs());
builderContext.pushContainer(tbl.newTableRow(atts));
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);
//////////////////////////////////////////////////
// @@ 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.
*
* @throws ConverterException On convertion error
*/
- static RtfAttributes convertCellAttributes(PropertyList props, PropertyList defProps)
+ static RtfAttributes convertCellAttributes(PropertyList props)
throws FOPException {
Property p;
RtfAttributes attrib = null;
- if (defProps != null) {
- attrib = convertCellAttributes(defProps, null);
- } else {
attrib = new RtfAttributes();
- }
boolean isBorderPresent = false;
* @throws ConverterException On convertion error
*/
static RtfAttributes convertRowAttributes(PropertyList props,
- PropertyList defProps, RtfAttributes rtfatts)
+ RtfAttributes rtfatts)
throws FOPException {
Property p;
RtfAttributes attrib = null;
- if (defProps != null) {
- attrib = convertRowAttributes(defProps, null, rtfatts);
- } else {
if (rtfatts == null) {
attrib = new RtfAttributes();
} else {
attrib = rtfatts;
- }
}
String attrValue;
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);
/** 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 */
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
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;
}
}
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
// 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();
*/
public class RtfTextrun extends RtfContainer {
+ private boolean bSuppressLastPar=false;
/** Class which represents the opening of a RTF group mark.*/
private class RtfOpenGroupMark extends RtfElement
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
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();