cvs commit: xml-fop/src/java/org/apache/fop/render/rtf RTFHandler.java
jeremias2004/04/04 04:12:29 Modified:src/java/org/apache/fop/apps InputHandler.java src/java/org/apache/fop/render/rtf RTFHandler.java Log: Ordinary Java code should never throw Error instances, use RuntimeException instead. That said, RuntimeException is equally suboptimal here. We should probably create an exception class like SAXException for the handler methods. Revision ChangesPath 1.11 +1 -1 xml-fop/src/java/org/apache/fop/apps/InputHandler.java Index: InputHandler.java === RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/InputHandler.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- InputHandler.java 16 Mar 2004 05:25:16 - 1.10 +++ InputHandler.java 4 Apr 2004 11:12:28 - 1.11 @@ -83,7 +83,7 @@ try { return new InputSource(new URL("file", null, path).toString()); } catch (java.net.MalformedURLException e) { -throw new Error("unexpected MalformedURLException"); +throw new RuntimeException("unexpected MalformedURLException"); } } 1.23 +39 -39xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java Index: RTFHandler.java === RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- RTFHandler.java 4 Apr 2004 06:29:44 - 1.22 +++ RTFHandler.java 4 Apr 2004 11:12:29 - 1.23 @@ -282,10 +282,10 @@ } } catch (IOException ioe) { log.error("startFlow: " + ioe.getMessage()); -throw new Error(ioe.getMessage()); +throw new RuntimeException(ioe.getMessage()); } catch (Exception e) { log.error("startFlow: " + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } } @@ -307,7 +307,7 @@ } } catch (Exception e) { log.error("endFlow: " + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } } @@ -344,10 +344,10 @@ } catch (IOException ioe) { // TODO could we throw Exception in all FOInputHandler events? log.error("startBlock: " + ioe.getMessage()); -throw new Error("IOException: " + ioe); +throw new RuntimeException("IOException: " + ioe); } catch (Exception e) { log.error("startBlock: " + e.getMessage()); -throw new Error("Exception: " + e); +throw new RuntimeException("Exception: " + e); } } @@ -390,10 +390,10 @@ } catch (IOException ioe) { log.error("startBlock:" + ioe.getMessage()); -throw new Error(ioe.getMessage()); +throw new RuntimeException(ioe.getMessage()); } catch (Exception e) { log.error("startBlock:" + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } } @@ -418,7 +418,7 @@ builderContext.pushContainer(tc.newTable(atts, tableContext)); } catch (Exception e) { log.error("startTable:" + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } builderContext.pushTableContext(tableContext); @@ -452,7 +452,7 @@ builderContext.getTableContext().setNextColumnRowSpanning(new Integer(0), null); } catch (Exception e) { log.error("startColumn: " + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } } @@ -513,13 +513,13 @@ textrun.pushAttributes(rtfAttr); } catch (IOException ioe) { log.error("startInline:" + ioe.getMessage()); -throw new Error(ioe.getMessage()); +throw new RuntimeException(ioe.getMessage()); } catch (FOPException fe) { log.error("startInline:" + fe.getMessage()); -throw new Error(fe.getMessage()); +throw new RuntimeException(fe.getMessage()); } catch (Exception e) { log.error("startInline:" + e.getMessage()); -throw new Error(e.getMessage()); +throw new RuntimeException(e.getMessage()); } } @@ -541,10 +541,10 @@ textrun.popAttributes(); } catc
cvs commit: xml-fop/src/java/org/apache/fop/render/rtf RTFHandler.java
gmazza 2004/04/03 22:29:44 Modified:src/java/org/apache/fop/fo FOText.java FObjMixed.java src/java/org/apache/fop/layoutmgr AddLMVisitor.java TextLayoutManager.java src/java/org/apache/fop/render/rtf RTFHandler.java Log: Another attempt at fixing the space removal issue. This method combines the long-standing previous method (the one that removed spaces between words correctly, at a cost of a leading extra space for the first FOText instance of an fo:block) with my later patch (which would fix the extra space issue but had problems with spaces between words). It appears to work well, but the fo:inline issues Simon brought up will still need further work. Revision ChangesPath 1.18 +73 -43xml-fop/src/java/org/apache/fop/fo/FOText.java Index: FOText.java === RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOText.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- FOText.java 12 Mar 2004 00:41:04 - 1.17 +++ FOText.java 4 Apr 2004 06:29:44 - 1.18 @@ -47,11 +47,21 @@ * The starting valid index of the ca array * to be processed. * + * This value is originally equal to 0, but becomes + * incremented during leading whitespace removal by the flow.Block class, + * via the TextCharIterator.remove() method below. + */ +public int startIndex = 0; + +/** + * The ending valid index of the ca array + * to be processed. + * * This value is originally equal to ca.length, but becomes - * incremented during whitespace removal by the flow.Block class, + * decremented during between-word whitespace removal by the flow.Block class, * via the TextCharIterator.remove() method below. */ -public int start = 0; +public int endIndex = 0; /** * The TextInfo object attached to the text @@ -100,9 +110,10 @@ */ public FOText(char[] chars, int start, int end, TextInfo ti, FONode parent) { super(parent); -int length = end - start; -this.ca = new char[length]; -System.arraycopy(chars, start, ca, 0, length); +endIndex = end - start; +this.ca = new char[endIndex]; +System.arraycopy(chars, start, ca, 0, endIndex); +// System.out.println("->" + new String(ca) + "<-"); textInfo = ti; createBlockPointers(); textTransform(); @@ -119,11 +130,11 @@ */ public boolean willCreateArea() { if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE -&& ca.length - start > 0) { +&& endIndex - startIndex > 0) { return true; } -for (int i = start; i < ca.length; i++) { +for (int i = startIndex; i < endIndex; i++) { char ch = ca[i]; if (!((ch == ' ') || (ch == '\n') @@ -142,37 +153,7 @@ return new TextCharIterator(); } -private class TextCharIterator extends AbstractCharIterator { -private int curIndex = 0; - -public boolean hasNext() { -return (curIndex < ca.length); -} - -public char nextChar() { -if (curIndex < ca.length) { -// Just a char class? Don't actually care about the value! -return ca[curIndex++]; -} else { -throw new NoSuchElementException(); -} -} - -public void remove() { -if (start < ca.length) { -start++; -} -} - -public void replaceChar(char c) { -if (curIndex > 0 && curIndex <= ca.length) { -ca[curIndex - 1] = c; -} -} - -} - -/** + /** * This method is run as part of the Constructor, to create xref pointers to * the previous FOText objects within the same Block */ @@ -214,7 +195,7 @@ if (textInfo.textTransform == TextTransform.NONE) { return; } -for (int i = 0; i < ca.length; i++) { +for (int i = 0; i < endIndex; i++) { ca[i] = charTransform(i); } } @@ -279,7 +260,7 @@ */ private char getRelativeCharInBlock(int i, int offset) { // The easy case is where the desired character is in the same FOText -if (((i + offset) >= 0) && ((i + offset) <= this.ca.length)) { +if (((i + offset) >= 0) && ((i + offset) <= this.endIndex)) { return ca[i + offset]; } // For now, we can't look at following FOText nodes @@
cvs commit: xml-fop/src/java/org/apache/fop/render/rtf RTFHandler.java
gmazza 2004/03/11 16:41:05 Modified:src/java/org/apache/fop/fo FOText.java FObjMixed.java src/java/org/apache/fop/layoutmgr AbstractLayoutManager.java AddLMVisitor.java TextLayoutManager.java src/java/org/apache/fop/render/rtf RTFHandler.java Log: Simplifications to FOText whitespace removal; fewer arraycopies performed. Revision ChangesPath 1.17 +18 -26xml-fop/src/java/org/apache/fop/fo/FOText.java Index: FOText.java === RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOText.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- FOText.java 7 Mar 2004 17:52:43 - 1.16 +++ FOText.java 12 Mar 2004 00:41:04 - 1.17 @@ -44,14 +44,14 @@ public char[] ca; /** - * The actual length of the text to be rendered within ca, - * starting from position 0 of the array. + * The starting valid index of the ca array + * to be processed. * - * This value is originally equal to ca.length, but becomes decremented - * during whitespace removal by the flow.Block class, via the - * TextCharIterator.remove() method below. + * This value is originally equal to ca.length, but becomes + * incremented during whitespace removal by the flow.Block class, + * via the TextCharIterator.remove() method below. */ -public int length; +public int start = 0; /** * The TextInfo object attached to the text @@ -100,7 +100,7 @@ */ public FOText(char[] chars, int start, int end, TextInfo ti, FONode parent) { super(parent); -length = end - start; +int length = end - start; this.ca = new char[length]; System.arraycopy(chars, start, ca, 0, length); textInfo = ti; @@ -119,11 +119,11 @@ */ public boolean willCreateArea() { if (textInfo.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE -&& length > 0) { +&& ca.length - start > 0) { return true; } -for (int i = 0; i < length; i++) { +for (int i = start; i < ca.length; i++) { char ch = ca[i]; if (!((ch == ' ') || (ch == '\n') @@ -146,11 +146,11 @@ private int curIndex = 0; public boolean hasNext() { -return (curIndex < length); +return (curIndex < ca.length); } public char nextChar() { -if (curIndex < length) { +if (curIndex < ca.length) { // Just a char class? Don't actually care about the value! return ca[curIndex++]; } else { @@ -159,25 +159,17 @@ } public void remove() { -if (curIndex > 0 && curIndex < length) { -// copy from curIndex to end to curIndex-1 -System.arraycopy(ca, curIndex, ca, curIndex - 1, - length - curIndex); -length--; -curIndex--; -} else if (curIndex == length) { -curIndex = --length; +if (start < ca.length) { +start++; } } - public void replaceChar(char c) { -if (curIndex > 0 && curIndex <= length) { +if (curIndex > 0 && curIndex <= ca.length) { ca[curIndex - 1] = c; } } - } /** @@ -239,7 +231,7 @@ * @return True if the character at this location is the start of a new * word. */ -public boolean isStartOfWord (int i) { +private boolean isStartOfWord(int i) { char prevChar = getRelativeCharInBlock(i, -1); /* All we are really concerned about here is of what type prevChar is. If inputChar is not part of a word, then the Java @@ -285,9 +277,9 @@ * @return the character in the offset position within the block; \u if * the offset points to an area outside of the block. */ -public char getRelativeCharInBlock(int i, int offset) { +private char getRelativeCharInBlock(int i, int offset) { // The easy case is where the desired character is in the same FOText -if (((i + offset) >= 0) && ((i + offset) <= this.length)) { +if (((i + offset) >= 0) && ((i + offset) <= this.ca.length)) { return ca[i + offset]; } // For now, we can't look at following FOText nodes @@ -345,7 +337,7 @@ * @param i the index into ca[] * @return char with transformed value */ -public char charTransfor
cvs commit: xml-fop/src/java/org/apache/fop/render/rtf RTFHandler.java
pherweg 2004/01/27 08:51:29 Modified:src/java/org/apache/fop/render/rtf RTFHandler.java Log: added support for white-space-treatment and linefeed-treatment by deferring the processing of some FOs until execution of endBlock Revision ChangesPath 1.15 +283 -1xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java Index: RTFHandler.java === RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/render/rtf/RTFHandler.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- RTFHandler.java 24 Jan 2004 16:09:48 - 1.14 +++ RTFHandler.java 27 Jan 2004 16:51:29 - 1.15 @@ -54,12 +54,14 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.util.Iterator; import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.EnumProperty; import org.apache.fop.fo.FOInputHandler; +import org.apache.fop.fo.FObj; import org.apache.fop.datatypes.FixedLength; import org.apache.fop.fo.flow.BasicLink; import org.apache.fop.fo.flow.Block; @@ -71,6 +73,7 @@ import org.apache.fop.fo.flow.Leader; import org.apache.fop.fo.flow.ListBlock; import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemLabel; import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableColumn; @@ -82,6 +85,7 @@ import org.apache.fop.fo.pagination.PageSequence; import org.apache.fop.fo.pagination.SimplePageMaster; import org.apache.fop.fo.Constants; +import org.apache.fop.fo.FOText; import org.apache.fop.fo.Property; import org.apache.fop.fo.LengthProperty; import org.apache.fop.fo.StringProperty; @@ -129,6 +133,12 @@ private final Logger log = new ConsoleLogger(); private RtfSection sect; private RtfDocumentArea docArea; +private int iNestCount; +private boolean bDefer; //true, if each called handler shall be + //processed at later time. +private boolean bDeferredExecution; //true, if currently called handler was not + //called while SAX parsing, but was called + //by invokeDeferredEvent. private boolean bPrevHeaderSpecified = false;//true, if there has been a //header in any page-sequence private boolean bPrevFooterSpecified = false;//true, if there has been a @@ -150,6 +160,9 @@ public RTFHandler(Document doc, OutputStream os) { super(doc); this.os = os; +bDefer = false; +bDeferredExecution = false; +iNestCount=0; FontSetup.setup(doc, null); log.warn(ALPHA_WARNING); } @@ -185,6 +198,10 @@ */ public void startPageSequence(PageSequence pageSeq) { try { +if (bDefer) { +return; +} + sect = docArea.newSection(); //read page size and margins, if specified @@ -218,6 +235,10 @@ * @see org.apache.fop.fo.FOInputHandler#endPageSequence(PageSequence) */ public void endPageSequence(PageSequence pageSeq) throws FOPException { +if (bDefer) { +return; +} + builderContext.popContainer(); } @@ -225,6 +246,10 @@ * @see org.apache.fop.fo.FOInputHandler#startFlow(Flow) */ public void startFlow(Flow fl) { +if (bDefer) { +return; +} + try { if (fl.getFlowName().equals("xsl-region-body")) { // if there is no header in current page-sequence but there has been @@ -300,6 +325,10 @@ * @see org.apache.fop.fo.FOInputHandler#endFlow(Flow) */ public void endFlow(Flow fl) { +if (bDefer) { +return; +} + try { if (fl.getFlowName().equals("xsl-region-body")) { //just do nothing @@ -318,6 +347,19 @@ * @see org.apache.fop.fo.FOInputHandler#startBlock(Block) */ public void startBlock(Block bl) { +++iNestCount; + +if (!bDeferredExecution) { +//If startBlock was called while SAX parsing, defer processing of this +//FO and all its elements until endBlock. This has to be done, because +//attributes (for example while-space-treatment, linefeed-treatment) +//are not available until endBlock. +bDefer = true; +} +if (bDefer) { +return;