Explorar el Código

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

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1026110 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Jeremias Maerki hace 13 años
padre
commit
0a3aa3b66c

+ 21
- 4
src/java/org/apache/fop/render/rtf/RTFHandler.java Ver fichero

@@ -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 FOEventHandler {
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 FOEventHandler {
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 FOEventHandler {
}
}

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) {

+ 39
- 0
src/java/org/apache/fop/render/rtf/TextAttributesConverter.java Ver fichero

@@ -35,6 +35,7 @@ import org.apache.fop.fo.flow.BlockContainer;
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

+ 99
- 34
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java Ver fichero

@@ -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.rtfdoc.RtfExternalGraphic;
* @author Peter Herweg, pherweg@web.de
*/
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 RtfContainer {

/** 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 RtfContainer {
}

/**
* 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 RtfContainer {
*
* @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 RtfContainer {
/**
* 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 RtfContainer {
* @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.

+ 3
- 0
status.xml Ver fichero

@@ -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>

Cargando…
Cancelar
Guardar