Author: jeremias
Date: Thu Oct 21 19:24:29 2010
New Revision: 1026110
URL: http://svn.apache.org/viewvc?rev=1026110&view=rev
Log:
Bugzilla #42600:
Added some support for break-before/-after for RTF output.
Submitted by: Maximilian Aster <maximilian.aster.at.boc-eu.com>
Changes to patch:
- Code style fixes
- Removed dependency from rtflib to FO Constants.
- Tried to implement even/odd/column breaks
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
xmlgraphics/fop/trunk/status.xml
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=1026110&r1=1026109&r2=1026110&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
Thu Oct 21 19:24:29 2010
@@ -80,11 +80,11 @@ import org.apache.fop.fo.flow.PageNumber
import org.apache.fop.fo.flow.PageNumberCitation;
import org.apache.fop.fo.flow.table.Table;
import org.apache.fop.fo.flow.table.TableBody;
-import org.apache.fop.fo.flow.table.TableFooter;
-import org.apache.fop.fo.flow.table.TablePart;
import org.apache.fop.fo.flow.table.TableCell;
import org.apache.fop.fo.flow.table.TableColumn;
+import org.apache.fop.fo.flow.table.TableFooter;
import org.apache.fop.fo.flow.table.TableHeader;
+import org.apache.fop.fo.flow.table.TablePart;
import org.apache.fop.fo.flow.table.TableRow;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
@@ -436,7 +436,8 @@ public class RTFHandler extends FOEventH
RtfTextrun textrun = container.getTextrun();
textrun.addParagraphBreak();
- textrun.popBlockAttributes();
+ int breakValue = toRtfBreakValue(bl.getBreakAfter());
+ textrun.popBlockAttributes(breakValue);
} catch (IOException ioe) {
handleIOTrouble(ioe);
@@ -488,7 +489,8 @@ public class RTFHandler extends FOEventH
RtfTextrun textrun = container.getTextrun();
textrun.addParagraphBreak();
- textrun.popBlockAttributes();
+ int breakValue = toRtfBreakValue(bl.getBreakAfter());
+ textrun.popBlockAttributes(breakValue);
} catch (IOException ioe) {
handleIOTrouble(ioe);
@@ -498,6 +500,21 @@ public class RTFHandler extends FOEventH
}
}
+ private int toRtfBreakValue(int foBreakValue) {
+ switch (foBreakValue) {
+ case Constants.EN_PAGE:
+ return RtfTextrun.BREAK_PAGE;
+ case Constants.EN_EVEN_PAGE:
+ return RtfTextrun.BREAK_EVEN_PAGE;
+ case Constants.EN_ODD_PAGE:
+ return RtfTextrun.BREAK_ODD_PAGE;
+ case Constants.EN_COLUMN:
+ return RtfTextrun.BREAK_COLUMN;
+ default:
+ return RtfTextrun.BREAK_NONE;
+ }
+ }
+
/** {...@inheritdoc} */
public void startTable(Table tbl) {
if (bDefer) {
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java?rev=1026110&r1=1026109&r2=1026110&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java
Thu Oct 21 19:24:29 2010
@@ -35,6 +35,7 @@ import org.apache.fop.fo.flow.BlockConta
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fo.flow.Leader;
import org.apache.fop.fo.flow.PageNumber;
+import org.apache.fop.fo.flow.table.TableCell;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.fo.properties.CommonFont;
import org.apache.fop.fo.properties.CommonMarginBlock;
@@ -80,10 +81,48 @@ final class TextAttributesConverter {
attrBlockMargin(fobj.getCommonMarginBlock(), attrib);
attrBlockTextAlign(fobj.getTextAlign(), attrib);
attrBorder(fobj.getCommonBorderPaddingBackground(), attrib, fobj);
+ attrBreak(fobj, attrib);
return attrib;
}
+ private static void attrBreak(Block fobj, FOPRtfAttributes attrib) {
+ int breakValue = fobj.getBreakBefore();
+ if (breakValue != Constants.EN_NONE) {
+ //"sect" Creates a new section and a page break,
+ //a simple page break with control word "page" caused
+ //some problems
+ boolean bHasTableCellParent = false;
+ FONode f = fobj;
+ while (f.getParent() != null) {
+ f = f.getParent();
+ if (f instanceof TableCell) {
+ bHasTableCellParent = true;
+ break;
+ }
+ }
+ if (!bHasTableCellParent) {
+ attrib.set("sect");
+ switch (breakValue) {
+ case Constants.EN_EVEN_PAGE:
+ attrib.set("sbkeven");
+ break;
+ case Constants.EN_ODD_PAGE:
+ attrib.set("sbkodd");
+ break;
+ case Constants.EN_COLUMN:
+ attrib.set("sbkcol");
+ break;
+ default:
+ attrib.set("sbkpage");
+ }
+ } else {
+ log.warn("Cannot create break-before for a block inside a
table.");
+ }
+ }
+ //Break after is handled in RtfCloseGroupMark
+ }
+
/**
* Converts all known text FO properties to RtfAttributes
* @param fobj FObj whose properties are to be converted
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java?rev=1026110&r1=1026109&r2=1026110&view=diff
==============================================================================
---
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
(original)
+++
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java
Thu Oct 21 19:24:29 2010
@@ -25,9 +25,10 @@ import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Stack;
-// FOP
-import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Class which contains a linear text run. It has methods to add attributes,
@@ -35,9 +36,26 @@ import org.apache.fop.render.rtf.rtflib.
* @author Peter Herweg, [email protected]
*/
public class RtfTextrun extends RtfContainer {
+
+ /** Constant for no page break */
+ public static final int BREAK_NONE = 0;
+ /** Constant for a normal page break */
+ public static final int BREAK_PAGE = 1;
+ /** Constant for a column break */
+ public static final int BREAK_COLUMN = 2;
+ /** Constant for a even page break */
+ public static final int BREAK_EVEN_PAGE = 3;
+ /** Constant for a odd page break */
+ public static final int BREAK_ODD_PAGE = 4;
+
private boolean bSuppressLastPar = false;
private RtfListItem rtfListItem;
+ /**
+ * logging instance
+ */
+ protected static Log log = LogFactory.getLog(RtfTextrun.class);
+
/** Manager for handling space-* property. */
private RtfSpaceManager rtfSpaceManager = new RtfSpaceManager();
@@ -68,10 +86,12 @@ public class RtfTextrun extends RtfConta
/** Class which represents the closing of a RTF group mark.*/
private class RtfCloseGroupMark extends RtfElement {
+ private int breakType = BREAK_NONE;
- RtfCloseGroupMark(RtfContainer parent, Writer w)
- throws IOException {
+ RtfCloseGroupMark(RtfContainer parent, Writer w, int breakType)
+ throws IOException {
super(parent, w);
+ this.breakType = breakType;
}
/**
@@ -82,11 +102,44 @@ public class RtfTextrun extends RtfConta
}
/**
- * write RTF code of all our children
+ * Returns the break type.
+ * @return the break type (BREAK_* constants)
+ */
+ public int getBreakType() {
+ return breakType;
+ }
+
+ /**
+ * Write RTF code of all our children.
* @throws IOException for I/O problems
*/
protected void writeRtfContent() throws IOException {
writeGroupMark(false);
+ boolean bHasTableCellParent =
this.getParentOfClass(RtfTableCell.class) != null;
+
+ //Unknown behavior when a table starts a new section,
+ //Word may crash
+ if (breakType != BREAK_NONE) {
+ if (!bHasTableCellParent) {
+ writeControlWord("sect");
+ /* The following modifiers don't seem to appear in the
right place */
+ switch (breakType) {
+ case BREAK_EVEN_PAGE:
+ writeControlWord("sbkeven");
+ break;
+ case BREAK_ODD_PAGE:
+ writeControlWord("sbkodd");
+ break;
+ case BREAK_COLUMN:
+ writeControlWord("sbkcol");
+ break;
+ default:
+ writeControlWord("sbkpage");
+ }
+ } else {
+ log.warn("Cannot create break-after for a paragraph inside
a table.");
+ }
+ }
}
}
@@ -135,8 +188,18 @@ public class RtfTextrun extends RtfConta
*
* @throws IOException for I/O problems
*/
+ private void addCloseGroupMark(int breakType) throws IOException {
+ RtfCloseGroupMark r = new RtfCloseGroupMark(this, writer, breakType);
+ }
+
+ /**
+ * Adds instance of <code>CloseGroupMark</code> as a child, but without a
break option.
+ * Inline attributes do not need that for example
+ *
+ * @throws IOException for I/O problems
+ */
private void addCloseGroupMark() throws IOException {
- RtfCloseGroupMark r = new RtfCloseGroupMark(this, writer);
+ RtfCloseGroupMark r = new RtfCloseGroupMark(this, writer, BREAK_NONE);
}
/**
@@ -155,14 +218,14 @@ public class RtfTextrun extends RtfConta
/**
* Pops block attributes, notifies all opened blocks about pushing block
* attributes, adds <code>CloseGroupMark</code> as a child.
- *
+ * @param breakType the break type
* @throws IOException for I/O problems
*/
- public void popBlockAttributes() throws IOException {
- rtfSpaceManager.popRtfSpaceSplitter();
- rtfSpaceManager.stopUpdatingSpaceBefore();
- addCloseGroupMark();
- }
+ public void popBlockAttributes(int breakType) throws IOException {
+ rtfSpaceManager.popRtfSpaceSplitter();
+ rtfSpaceManager.stopUpdatingSpaceBefore();
+ addCloseGroupMark(breakType);
+ }
/**
* Pushes inline attributes.
@@ -228,28 +291,30 @@ public class RtfTextrun extends RtfConta
* @throws IOException for I/O problems
*/
public void addParagraphBreak() throws IOException {
- // get copy of children list
- List children = getChildren();
-
- // delete all previous CloseGroupMark
- int deletedCloseGroupCount = 0;
-
- ListIterator lit = children.listIterator(children.size());
- while (lit.hasPrevious()
- && (lit.previous() instanceof RtfCloseGroupMark)) {
- lit.remove();
- deletedCloseGroupCount++;
- }
-
- if (children.size() != 0) {
- // add paragraph break and restore all deleted close group marks
- setChildren(children);
- new RtfParagraphBreak(this, writer);
- for (int i = 0; i < deletedCloseGroupCount; i++) {
- addCloseGroupMark();
- }
- }
- }
+ // get copy of children list
+ List children = getChildren();
+ Stack tmp = new Stack();
+
+ // delete all previous CloseGroupMark
+ int deletedCloseGroupCount = 0;
+
+ ListIterator lit = children.listIterator(children.size());
+ while (lit.hasPrevious()
+ && (lit.previous() instanceof RtfCloseGroupMark)) {
+ tmp.push(new
Integer(((RtfCloseGroupMark)lit.next()).getBreakType()));
+ lit.remove();
+ deletedCloseGroupCount++;
+ }
+
+ if (children.size() != 0) {
+ // add paragraph break and restore all deleted close group marks
+ setChildren(children);
+ new RtfParagraphBreak(this, writer);
+ for (int i = 0; i < deletedCloseGroupCount; i++) {
+ addCloseGroupMark(((Integer)tmp.pop()).intValue());
+ }
+ }
+ }
/**
* Inserts a leader.
Modified: xmlgraphics/fop/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1026110&r1=1026109&r2=1026110&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Thu Oct 21 19:24:29 2010
@@ -58,6 +58,9 @@
documents. Example: the fix of marks layering will be such a case when
it's done.
-->
<release version="FOP Trunk" date="TBD">
+ <action context="Renderers" dev="JM" type="add" fixes-bug="42600"
due-to="Maximilian Aster">
+ Added some support for break-before/-after for RTF output.
+ </action>
<action context="Renderers" dev="JM" type="add" fixes-bug="49379"
due-to="Peter Hancock">
Added ability to embed an external AFP page segment resource file (AFP
output only).
</action>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]