public RtfTable newTable(ITableColumnsInfo tc) throws IOException;
/** close current table if any and start a new one
- * @param tc added by Boris Poudérous on july 2002 in order to process number-columns-spanned attribute
+ * @param tc added by Boris Poudérous on july 2002 in order to process number-columns-spanned attribute
**/
public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException;
}
private RtfParagraph m_para;
private RtfExternalGraphic m_externalGraphic;
private RtfTable m_table;
-
+
RtfAfterBeforeBase(RtfSection parent, Writer w, RtfAttributes attrs) throws IOException {
super((RtfContainer)parent,w,attrs);
m_attrib = attrs;
}
-
+
public RtfParagraph newParagraph() throws IOException {
closeAll();
m_para = new RtfParagraph(this,m_writer);
return m_para;
}
-
+
public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException {
closeAll();
m_para = new RtfParagraph(this,m_writer,attrs);
return m_para;
}
-
+
public RtfExternalGraphic newImage() throws IOException {
closeAll();
m_externalGraphic = new RtfExternalGraphic(this,m_writer);
return m_externalGraphic;
}
-
+
private void closeCurrentParagraph() throws IOException {
if(m_para!=null) m_para.close();
}
-
+
private void closeCurrentExternalGraphic() throws IOException {
if(m_externalGraphic!=null) m_externalGraphic.close();
}
-
+
private void closeCurrentTable() throws IOException {
if(m_table != null) m_table.close();
}
-
+
protected void writeRtfPrefix() throws IOException {
writeGroupMark(true);
writeMyAttributes();
}
-
+
/** must be implemented to write the header or footer attributes */
abstract protected void writeMyAttributes() throws IOException;
-
+
protected void writeRtfSuffix() throws IOException {
writeGroupMark(false);
}
-
+
public RtfAttributes getAttributes(){
return m_attrib;
}
-
+
public void closeAll() throws IOException {
closeCurrentParagraph();
closeCurrentExternalGraphic();
closeCurrentTable();
}
-
+
/** close current table if any and start a new one
- * @param tc added by Boris Poudérous on july 2002 in order to process number-columns-spanned attribute
+ * @param tc added by Boris Poudérous on july 2002 in order to process number-columns-spanned attribute
*/
public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException {
closeAll();
m_table = new RtfTable(this,m_writer,attrs,tc);
return m_table;
}
-
+
/** close current table if any and start a new one */
public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
closeAll();
*/
public class RtfContainer extends RtfElement {
- private LinkedList m_children; // 'final' removed by Boris Poudérous on 07/22/2002
+ private LinkedList m_children; // 'final' removed by Boris Poudérous on 07/22/2002
private RtfOptions m_options = new RtfOptions();
private RtfElement m_lastChild;
}
/**
- * Add by Boris Poudérous on 07/22/2002
+ * Add by Boris Poudérous on 07/22/2002
* Set the children list
*/
public boolean setChildren (List children)
final int DEFAULT_IDNUM = 0;
/** Parent table context
- * (added by Boris Poudérous on july 2002 in order to process nested tables)
+ * (added by Boris Poudérous on july 2002 in order to process nested tables)
*/
private ITableColumnsInfo parentITableColumnsInfo = null;
}
/** create an extra cell to hold content that comes after a nested table in a cell
- * Modified by Boris Poudérous in order to permit the extra cell to have the attributes of its parent cell
+ * Modified by Boris Poudérous in order to permit the extra cell to have the attributes of its parent cell
*/
RtfTableCell createExtraCell(int rowIndex,int xOffset,int cellWidth,RtfAttributes parentCellAttributes)
throws IOException {
// TODO should be merged with the cell that is above it
if(cellIndex==0 && pc.xOffset > 0) {
/**
- * Added by Boris Poudérous
+ * Added by Boris Poudérous
*/
// Add empty cells merged vertically with the cells above and with the same widths
// (BEFORE the cell that contains the nested table)
}
row.addChild(pc.cell);
- // Line added by Boris Poudérous
+ // Line added by Boris Poudérous
xOffsetOfLastPositionedCell = pc.xOffset + pc.cell.getCellWidth();
cellIndex++;
}
/**
- * Added by Boris Poudérous
+ * Added by Boris Poudérous
*/
// Add empty cells merged vertically with the cells above AFTER the cell that contains the nested table
// The cells added have the same widths than the cells above.
/**
* @return The table context of the parent table
- * Added by Boris Poudérous on july 2002 in order to process nested tables
+ * Added by Boris Poudérous on july 2002 in order to process nested tables
*/
public ITableColumnsInfo getParentITableColumnsInfo()
{
public static String RTF_FIELD = "field";
public static String RTF_FIELD_PAGE = "fldinst { PAGE }";
public static String RTF_FIELD_RESULT = "fldrslt";
-
+
/** Create an RTF paragraph as a child of given container with default attributes */
RtfPageNumber(IRtfPageNumberContainer parent, Writer w) throws IOException
{
super((RtfContainer)parent,w);
}
-
+
/** Create an RTF page number as a child of given paragraph,
* copying the paragraph attributes
*/
m_attrib.set(parent.getTextAttributes());
}
}
-
+
/** write our attributes and content */
protected void writeRtfContent() throws IOException
{
writeGroupMark(true);
writeControlWord(RTF_FIELD);
writeGroupMark(true);
- writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous
+ writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous
writeStarControlWord(RTF_FIELD_PAGE);
writeGroupMark(false);
writeGroupMark(true);
writeGroupMark(false);
writeGroupMark(false);
}
-
+
/** true if this element would generate no "useful" RTF content */
public boolean isEmpty()
{
return false;
}
}
-
+
\ No newline at end of file
this.id = id;
}
- /** Create an RTF page number citation as a child of given
+ /** Create an RTF page number citation as a child of given
* paragraph, copying its attributes */
RtfPageNumberCitation (RtfParagraph parent, Writer w, String id)
throws IOException
// Build page reference field
String pageRef = RTF_FIELD_PAGEREF_MODEL;
final int insertionIndex = pageRef.indexOf("}");
- pageRef =
- pageRef.substring(0,insertionIndex) + "\"" + id + "\"" + " "
+ pageRef =
+ pageRef.substring(0,insertionIndex) + "\"" + id + "\"" + " "
+ pageRef.substring(insertionIndex, pageRef.length())
;
id = null;
writeGroupMark(true);
writeControlWord(RTF_FIELD);
writeGroupMark(true);
- writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous
+ writeAttributes(m_attrib,RtfText.ATTR_NAMES); // Added by Boris Poudérous
writeStarControlWord(pageRef);
writeGroupMark(false);
writeGroupMark(true);
/** Model of an RTF paragraph, which can contain RTF text elements.
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
* @author Andreas Putz a.putz@skynamics.com
- * @author Boris Poudérous, boris.pouderous@free.fr
+ * @author Boris Poudérous, boris.pouderous@free.fr
*/
public class RtfParagraph extends RtfBookmarkContainerImpl
private RtfPageNumberCitation m_pageNumberCitation; // Line added by Boris POUDEROUS on 2002/07/09
private boolean m_keepn=false;
private boolean m_resetProperties=false;
-
+
/* needed for importing Rtf into FrameMaker
FrameMaker is not as forgiving as word in rtf
thus /pard/par must be written in a page break directly
also, this is just a hack to make FrameMaker import Jfor rtf
correctly */
private boolean writeForBreak = false;
-
+
/** Set of attributes that must be copied at the start of a paragraph */
private static final String [] PARA_ATTRIBUTES = { "intbl" };
-
+
/** Create an RTF paragraph as a child of given container with default attributes */
RtfParagraph(IRtfParagraphContainer parent, Writer w) throws IOException {
super((RtfContainer)parent,w);
}
-
+
/** Create an RTF paragraph as a child of given container with given attributes */
RtfParagraph(IRtfParagraphContainer parent, Writer w,RtfAttributes attr) throws IOException {
super((RtfContainer)parent,w,attr);
}
-
+
public String getText(){
return(m_text.getText());
}
-
+
/** Set the keepn attribute for this paragraph */
public void setKeepn() {
- this.m_keepn=true;
+ this.m_keepn=true;
}
-
+
/** Force reset properties */
public void setResetProperties() {
- this.m_resetProperties=true;
+ this.m_resetProperties=true;
}
-
+
/** IRtfTextContainer requirement: return a copy of our attributes */
public RtfAttributes getTextContainerAttributes() {
if(m_attrib == null) return null;
return (RtfAttributes)this.m_attrib.clone();
}
-
+
/** overridden to write our attributes before our content */
protected void writeRtfPrefix() throws IOException {
// collapse whitespace before writing out
} else {
new WhitespaceCollapser(this);
}
-
+
//Reset paragraph properties if needed
if(m_resetProperties) {
writeControlWord("pard");
}
-
+
// do not write text attributes here, they are handled
// by RtfText
writeAttributes(m_attrib,PARA_ATTRIBUTES);
if ( m_attrib.isSet( "intbl" ) && mustWriteAttributes() ) {
writeAttributes(m_attrib, RtfText.ALIGNMENT);
}
-
+
//Set keepn if needed (Keep paragraph with the next paragraph)
- if(m_keepn) writeControlWord("keepn");
-
+ if(m_keepn) writeControlWord("keepn");
+
// start a group for this paragraph and write our own attributes if needed
if(mustWriteGroupMark()) writeGroupMark(true);
-
-
+
+
if(mustWriteAttributes()) {
// writeAttributes(m_attrib, new String [] {"cs"});
// Added by Normand Masse
writeControlWord("pard\\par");
}
}
-
+
}
-
+
/** overridden to close paragraph */
protected void writeRtfSuffix() throws IOException {
// sometimes the end of paragraph mark must be suppressed in table cells
writeMark = ((RtfTableCell)m_parent).paragraphNeedsPar(this);
}
if(writeMark) {
- writeControlWord("par");
+ writeControlWord("par");
}
-
+
if(mustWriteGroupMark()) writeGroupMark(false);
-
-
+
+
}
-
+
/** close current text run if any and start a new one with default attributes
* @param str if not null, added to the RtfText created
*/
public RtfText newText(String str) throws IOException {
return newText(str,null);
}
-
+
/** close current text run if any and start a new one
* @param str if not null, added to the RtfText created
*/
m_text = new RtfText(this,m_writer,str,attr);
return m_text;
}
-
+
/** add a page break */
public void newPageBreak() throws IOException {
writeForBreak = true;
new RtfPageBreak(this,m_writer);
}
-
+
/** add a line break */
public void newLineBreak() throws IOException {
new RtfLineBreak(this,m_writer);
}
-
+
public RtfPageNumber newPageNumber()throws IOException {
m_pageNumber = new RtfPageNumber(this,m_writer);
return m_pageNumber;
}
-
+
/**
* Added by Boris POUDEROUS on 2002/07/09
*/
m_pageNumberCitation = new RtfPageNumberCitation(this,m_writer, id);
return m_pageNumberCitation;
}
-
+
/** Creates a new hyperlink. */
public RtfHyperLink newHyperLink(String str, RtfAttributes attr) throws IOException {
m_hyperlink = new RtfHyperLink(this, m_writer, str, attr);
return m_hyperlink;
}
-
+
/** start a new external graphic after closing all other elements */
public RtfExternalGraphic newImage() throws IOException {
closeAll();
m_externalGraphic = new RtfExternalGraphic(this,m_writer);
return m_externalGraphic;
}
-
+
private void closeCurrentText() throws IOException {
if(m_text != null) m_text.close();
}
-
+
private void closeCurrentHyperLink() throws IOException {
if(m_hyperlink != null) m_hyperlink.close();
}
-
+
private void closeAll() throws IOException {
closeCurrentText();
closeCurrentHyperLink();
}
-
+
/** depending on RtfOptions, do not emit any RTF for empty paragraphs */
protected boolean okToWriteRtf() {
boolean result = super.okToWriteRtf();
-
+
if(m_parent.getOptions().ignoreEmptyParagraphs() && getChildCount() == 0) {
// TODO should test that this is the last RtfParagraph in the cell instead
// of simply testing for last child??
result = false;
}
-
+
return result;
}
-
+
/** true if we must write our own (non-text) attributes in the RTF */
private boolean mustWriteAttributes() {
boolean writeAttributes = false;
}
return writeAttributes;
}
-
+
/** true if we must write a group mark around this paragraph
* TODO is this correct, study interaction with mustWriteAttributes() <-- On implementation i have noticed if the groupmark set, the format attributes are only for this content, i think this implementation is ok
*/
private boolean mustWriteGroupMark() {
return getChildCount() > 0;
}
-
+
/** get the attributes of our text */
public RtfAttributes getTextAttributes(){
if(m_text == null) return null;
}
/** start a new table after closing current paragraph, list and table
- * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002)
+ * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002)
*/
public RtfTable newTable(ITableColumnsInfo tc) throws IOException {
closeAll();
}
/** start a new table after closing current paragraph, list and table
- * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002)
+ * @param tc Table context used for number-columns-spanned attribute (added by Boris Poudérous on july 2002)
*/
public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException
{
m_before = new RtfBefore(this,m_writer,attrs);
return m_before;
}
-
+
/** IRtfAfterContainer */
public RtfAfter newAfter(RtfAttributes attrs) throws IOException {
closeAll();
private RtfTableRow m_row;
private int highestRow=0;
- /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
+ /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
private ITableColumnsInfo m_table_context;
/** Create an RTF element as a child of given container */
RtfTable(IRtfTableContainer parent, Writer w, ITableColumnsInfo tc) throws IOException
{
super((RtfContainer)parent,w);
- // Line added by Boris Poudérous on 07/22/2002
+ // Line added by Boris Poudérous on 07/22/2002
m_table_context = tc;
}
/** Create an RTF element as a child of given container
- * Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute
+ * Modified by Boris Poudérous in order to process 'number-columns-spanned' attribute
*/
RtfTable(IRtfTableContainer parent, Writer w, RtfAttributes attrs, ITableColumnsInfo tc) throws IOException
{
super((RtfContainer)parent,w,attrs);
- // Line added by Boris Poudérous on 07/22/2002
+ // Line added by Boris Poudérous on 07/22/2002
m_table_context = tc;
}
return (highestRow == id) ? true : false;
}
- /** Added by Boris Poudérous on 07/22/2002 */
+ /** Added by Boris Poudérous on 07/22/2002 */
public ITableColumnsInfo getITableColumnsInfo()
{
return this.m_table_context;
private RtfList m_list;
private RtfTable m_table;
private RtfExternalGraphic m_externalGraphic;
- private final RtfTableRow m_parentRow;
+ private final RtfTableRow m_parentRow;
private boolean set_center;
private boolean set_right;
private int id;
m_parentRow = parent;
m_cellWidth = cellWidth;
- /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
+ /** Added by Boris Poudérous on 07/22/2002 in order to process number-columns-spanned attribute */
// If the cell is spanned horizontally
if (attrs.getValue("number-columns-spanned") != null)
{
attrs.set("intbl");
m_paragraph = new RtfParagraph(this,m_writer,attrs);
-
+
if(m_paragraph.m_attrib.isSet("qc"))
{
set_center=true;
return m_table;
}
- /** start a new nested table after closing current paragraph, list and table */ // Modified by Boris Poudérous on 07/22/2002
+ /** start a new nested table after closing current paragraph, list and table */ // Modified by Boris Poudérous on 07/22/2002
public RtfTable newTable(RtfAttributes attrs, ITableColumnsInfo tc) throws IOException
{
closeAll();
- m_table = new RtfTable(this,m_writer, attrs, tc); // Added tc Boris Poudérous 07/22/2002
+ m_table = new RtfTable(this,m_writer, attrs, tc); // Added tc Boris Poudérous 07/22/2002
return m_table;
}
// word97 hangs if cell does not contain at least one "par" control word
// TODO this is what causes the extra spaces in nested table of test 004-spacing-in-tables.fo,
// but if is not here we generate invalid RTF for word97
-
+
if(set_center)
{
writeControlWord("qc");
if(e instanceof RtfTable) {
// nested table - render its cells in supplementary rows after current row,
// and put the remaining content of this cell in a new cell after nested table
- // Line added by Boris Poudérous
+ // Line added by Boris Poudérous
m_parentRow.getExtraRowSet().setParentITableColumnsInfo(((RtfTable)this.getParentOfClass(e.getClass())).getITableColumnsInfo());
extraRowIndex = m_parentRow.getExtraRowSet().addTable((RtfTable)e,extraRowIndex,m_widthOffset);
- // Boris Poudérous added the passing of the current cell attributes to the new cells (in order not to have cell without border for example)
+ // Boris Poudérous added the passing of the current cell attributes to the new cells (in order not to have cell without border for example)
extraCell = m_parentRow.getExtraRowSet().createExtraCell(extraRowIndex,m_widthOffset,this.getCellWidth(), m_attrib);
extraRowIndex++;