From 49ffdc1d05cfa7ed4dd0abee7e8f7836b193e5ef Mon Sep 17 00:00:00 2001 From: Peter Herweg Date: Sun, 12 Feb 2006 19:24:08 +0000 Subject: [PATCH] Bugfix for Bug 38041: correct handling of different list-item-label's git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@377220 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/rtf/RTFHandler.java | 23 ++++++++- .../render/rtf/rtflib/rtfdoc/RtfElement.java | 2 +- .../fop/render/rtf/rtflib/rtfdoc/RtfList.java | 17 +++++-- .../render/rtf/rtflib/rtfdoc/RtfListItem.java | 47 ++++++++++++++++--- .../rtf/rtflib/rtfdoc/RtfListTable.java | 23 +++++---- .../render/rtf/rtflib/rtfdoc/RtfSection.java | 1 + 6 files changed, 92 insertions(+), 21 deletions(-) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index a2d0975ad..931baeb63 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -923,11 +923,30 @@ public class RTFHandler extends FOEventHandler { if (bDefer) { return; } - + // create an RtfListItem in the current RtfList try { - final RtfList list = (RtfList)builderContext.getContainer( + RtfList list = (RtfList)builderContext.getContainer( RtfList.class, true, this); + + /** + * If the current list already contains a list item, then close the + * list and open a new one, so every single list item gets its own + * list. This allows every item to have a different list label. + * If all the items would be in the same list, they had all the + * same label. + */ + //TODO: do this only, if the labels content <> previous labels content + if (list.getChildCount() > 0) { + this.endListBody(); + this.endList((ListBlock) li.getParent()); + this.startList((ListBlock) li.getParent()); + this.startListBody(); + + list = (RtfList)builderContext.getContainer( + RtfList.class, true, this); + } + builderContext.pushContainer(list.newListItem()); } catch (IOException ioe) { log.error("startList: " + ioe.getMessage()); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java index 9d66997ee..6e136b9e9 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfElement.java @@ -94,7 +94,7 @@ public abstract class RtfElement { * the RTF file itself (for easier debugging), not its content. * @throws IOException in case of an I/O problem */ - protected void newLine() throws IOException { + public void newLine() throws IOException { writer.write("\n"); } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java index 81993b973..9dbb9ef1a 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfList.java @@ -16,6 +16,7 @@ /* $Id$ */ +package org.apache.fop.render.rtf.rtflib.rtfdoc; /* * This file is part of the RTF library of the FOP project, which was originally @@ -24,8 +25,6 @@ * the FOP project. */ -package org.apache.fop.render.rtf.rtflib.rtfdoc; - import java.io.Writer; import java.io.IOException; import java.util.Date; @@ -44,7 +43,7 @@ public class RtfList extends RtfContainer { private RtfListStyle defaultListStyle; private Integer listTemplateId = null; private Integer listId = null; - static private Random listIdGenerator = new Random(0); + private static Random listIdGenerator = new Random(0); /** Create an RTF list as a child of given container with given attributes */ RtfList(RtfContainer parent, Writer w, RtfAttributes attr) throws IOException { @@ -77,10 +76,18 @@ public class RtfList extends RtfContainer { return item; } + /** + * Returns the Id of the list. + * @return Id of the list + */ public Integer getListId() { return listId; } + /** + * Returns the Id of the list template. + * @return Id of the list template + */ public Integer getListTemplateId() { return listTemplateId; } @@ -101,6 +108,10 @@ public class RtfList extends RtfContainer { return defaultListStyle; } + /** + * Returns true, if the list has a parent table. + * @return true, if the list has a parent table + */ public boolean getHasTableParent() { return hasTableParent; } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java index 7e4cb8930..574c6625d 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListItem.java @@ -16,6 +16,7 @@ /* $Id$ */ +package org.apache.fop.render.rtf.rtflib.rtfdoc; /* * This file is part of the RTF library of the FOP project, which was originally @@ -24,8 +25,6 @@ * the FOP project. */ -package org.apache.fop.render.rtf.rtflib.rtfdoc; - import java.io.Writer; import java.io.IOException; @@ -45,7 +44,9 @@ public class RtfListItem extends RtfContainer private RtfListStyle listStyle; private int number = 0; - /** special RtfParagraph that writes list item setup code before its content */ + /** + * special RtfParagraph that writes list item setup code before its content + */ private class RtfListItemParagraph extends RtfParagraph { RtfListItemParagraph(RtfListItem rli, RtfAttributes attrs) @@ -59,20 +60,39 @@ public class RtfListItem extends RtfContainer } } + /** + * special RtfTextrun that is used as list item label + */ public class RtfListItemLabel extends RtfTextrun implements IRtfTextrunContainer { private RtfListItem rtfListItem; + /** + * Constructs the RtfListItemLabel + * @param item The RtfListItem the label belongs to + * @throws IOException Thrown when an IO-problem occurs + */ public RtfListItemLabel(RtfListItem item) throws IOException { super(null, item.writer, null); rtfListItem = item; } + /** + * Returns the current RtfTextrun object. + * Opens a new one if necessary. + * @return The RtfTextrun object + * @throws IOException Thrown when an IO-problem occurs + */ public RtfTextrun getTextrun() throws IOException { return this; } + /** + * Sets the content of the list item label. + * @param s Content of the list item label. + * @throws IOException Thrown when an IO-problem occurs + */ public void addString(String s) throws IOException { final String label = s.trim(); @@ -94,7 +114,7 @@ public class RtfListItem extends RtfContainer * Close current paragraph if any and start a new one * @param attrs attributes of new paragraph * @return new RtfParagraph - * @throws IOException for I/O problems + * @throws IOException Thrown when an IO-problem occurs */ public RtfParagraph newParagraph(RtfAttributes attrs) throws IOException { if (paragraph != null) { @@ -107,7 +127,7 @@ public class RtfListItem extends RtfContainer /** * Close current paragraph if any and start a new one with default attributes * @return new RtfParagraph - * @throws IOException for I/O problems + * @throws IOException Thrown when an IO-problem occurs */ public RtfParagraph newParagraph() throws IOException { return newParagraph(null); @@ -119,6 +139,12 @@ public class RtfListItem extends RtfContainer parentList = parent; } + + /** + * Get the current textrun. + * @return current RtfTextrun object + * @throws IOException Thrown when an IO-problem occurs + */ public RtfTextrun getTextrun() throws IOException { RtfTextrun textrun = RtfTextrun.getTextrun(this, writer, null); textrun.setRtfListItem(this); @@ -147,8 +173,11 @@ public class RtfListItem extends RtfContainer writeControlWord("pard"); } - writeOneAttribute(RtfText.LEFT_INDENT_FIRST, "360"); //attrib.getValue(RtfListTable.LIST_INDENT)); - writeOneAttribute(RtfText.LEFT_INDENT_BODY, attrib.getValue(RtfText.LEFT_INDENT_BODY)); + writeOneAttribute(RtfText.LEFT_INDENT_FIRST, + "360"); //attrib.getValue(RtfListTable.LIST_INDENT)); + + writeOneAttribute(RtfText.LEFT_INDENT_BODY, + attrib.getValue(RtfText.LEFT_INDENT_BODY)); // group for list setup info writeGroupMark(true); @@ -210,6 +239,10 @@ public class RtfListItem extends RtfContainer return parentList; } + /** + * Returns the list number + * @return list number + */ public int getNumber() { return number; } diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java index 974032269..a9df180b1 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfListTable.java @@ -16,6 +16,7 @@ /* $Id$ */ +package org.apache.fop.render.rtf.rtflib.rtfdoc; /* * This file is part of the RTF library of the FOP project, which was originally @@ -24,8 +25,6 @@ * the FOP project. */ -package org.apache.fop.render.rtf.rtflib.rtfdoc; - import java.util.LinkedList; import java.util.Iterator; import java.io.Writer; @@ -111,6 +110,7 @@ public class RtfListTable extends RtfContainer { /** * Add List * @param list RtfList to add + * @return number of lists in the table after adding */ public int addList(RtfList list) { if (lists == null) { @@ -127,21 +127,25 @@ public class RtfListTable extends RtfContainer { * @throws IOException for I/O problems */ public void writeRtfContent() throws IOException { + newLine(); if (lists != null) { //write '\listtable' - writeGroupMark(true); - writeStarControlWordNS(LIST_TABLE); + writeGroupMark(true); + writeStarControlWordNS(LIST_TABLE); + newLine(); for (Iterator it = lists.iterator(); it.hasNext();) { final RtfList list = (RtfList)it.next(); writeListTableEntry(list); + newLine(); } writeGroupMark(false); - + + newLine(); //write '\listoveridetable' - writeGroupMark(true); + writeGroupMark(true); writeStarControlWordNS(LIST_OVR_TABLE); int z = 1; - + newLine(); for (Iterator it = styles.iterator(); it.hasNext();) { final RtfListStyle style = (RtfListStyle)it.next(); @@ -155,9 +159,11 @@ public class RtfListTable extends RtfContainer { writeGroupMark(false); writeGroupMark(false); + newLine(); } writeGroupMark(false); + newLine(); } } @@ -204,8 +210,9 @@ public class RtfListTable extends RtfContainer { } /** - * Change list style + * Add list style * @param ls ListStyle to set + * @return number of styles after adding */ public int addRtfListStyle(RtfListStyle ls) { styles.add(ls); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java index b46d42703..5f9d4d52c 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java @@ -181,6 +181,7 @@ implements */ protected void writeRtfPrefix() throws IOException { writeAttributes(attrib, RtfPage.PAGE_ATTR); + newLine(); writeControlWord("sectd"); } -- 2.39.5