Attached is the “cvs diff” for all 22 files changed. Also attached (in the zip file) is a test XSLFO file (mca.fo) and a pdf output run with my modified code. The test files are in a zip file since they’d be too large (together) to send (mailer-daemon limits to 100k).
Notes on the changes:
These files just have a "mayContainMarker()" method added:
src/org/apache/fop/fo/flow/Table.java src/org/apache/fop/fo/flow/TableAndCaption.java src/org/apache/fop/fo/flow/TableBody.java src/org/apache/fop/fo/flow/TableCaption.java src/org/apache/fop/fo/flow/TableCell.java src/org/apache/fop/fo/flow/TableFooter.java src/org/apache/fop/fo/flow/TableHeader.java src/org/apache/fop/fo/flow/ListItem.java src/org/apache/fop/fo/flow/ListItemLabel.java src/org/apache/fop/fo/flow/ListItemBody.java src/org/apache/fop/fo/flow/ListBlock.java src/org/apache/fop/fo/flow/Inline.java src/org/apache/fop/fo/flow/Flow.java src/org/apache/fop/fo/flow/Block.java src/org/apache/fop/fo/flow/BidiOverride.java
For src/org/apache/fop/fo/flow/RetrieveMarker.java 1. I cleaned the layout() method a bit. Just efficiencies--no bug fixes. 2. Deleted the "locatePreviousPage()" method. Again, just an efficiency edit. 3. In the "searchPage()" method I relaxed the search on the current page for the desired marker. Please correct me if I'm wrong, but the spec appears to say the "is-first" and "is-last" positional attributes are preferences and not exclusionary. So for example if we can't find a marker that's first but we can find the marker somewhere else on the page then return what we can, not "null/not found." I believe that's what the XSLFO spec intends but I could very well be wrong.
For src/org/apache/fop/fo/flow/Marker.java 1. Removed the method "mayPrecedeMarker()" since it is no longer used. If markers can contain markers (and it doesn't appear that they can) then we need to add a "mayContainMarker() {return true;}" method.
For src/org/apache/fop/fo/flow/AbstractTableBody.java 1. In the loop in the "layaout()" method where we process all child nodes I added a test for marker children. If the child node is a marker just call its layout method and continue to the next child node.
For src/org/apache/fop/apps/StreamRenderer.java 1. We need to keep a list of all pages. If a marker is referenced on a later page we need to be able to retrieve the marker value. We were using the page queue for this but as pages are rendered they're removed from the queue--not good if that removes a page with a marker we'll need later. So I added an ArrayList called "pagesList" to hold this list. This might need to be optimized to only save markers from previous pages but we also need to know things like page sequence so for now just save the entire page. 2. In the "queuePage()" method we also add the page to our list of pages with markers if the page has markers (obviously...). 3. In the "getPreviousPage()" method we switch from using the queued pages list to the "pagesWithMarkersList" list.
For src/org/apache/fop/fo/FObj.java 1. Added a method "addChild()" which checks if the child node to be added is a marker, and if it is checks that it can be added. 2. Cleaned up and added a javadoc header for the method "addMarker()." Just an efficiency change--no bug fix.
For src/org/apache/fop/fo/FONode.java 1. This is the base class where we defined the "mayContainMarker()" method. The inherited behavior for all nodes is "cannot contain markers," or "false." Any node which can have markers as its initial children overrides this to return "true."
for src/org/apache/fop/fo/FOText.java 1. Commented out the "mayPrecedeMarker()" method, since it's no longer used. I didn't delete it because I want to keep it around just in case. I still need a test case which involves both Markers and FOText nodes.
Comments, criticisms, and feedback are encouraged.
-- Mark C. Allman -- Allman Professional Consulting, Inc. -- www.allmanpc.com, 617-947-4263
|
cvs diff -b -B src/org/apache/fop/apps/StreamRenderer.java Index: src/org/apache/fop/apps/StreamRenderer.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/apps/Attic/StreamRenderer.java,v retrieving revision 1.6.2.8 diff -b -B -r1.6.2.8 StreamRenderer.java 88a89,95 > > /** > * List of pages we've received > */ > private ArrayList pagesList = new ArrayList(); > > 231a239,243 > > > // (MCA) add this page to our list of pages > pagesList.add(page); > 332c344,357 < public Page getPreviousPage(Page current, boolean isWithinPageSequence, --- > /** > * Get the previous report page relative to the specified "current" page > * > * @param current page to start search from > * @param isWithinPageSequence true to limit search to current page sequence > * @param isFirstCall true if "current" parameter is the current page > * @return the previous page relative to the passed-in "current" page, > * null if the previous page cannot be determined > * > * (MCA) use the pagesList ArrayList instead of the renderQueue, since the > * renderQueue may be emptied as pages are rendered. > */ > public Page getPreviousPage(Page current, > boolean isWithinPageSequence, 333a359,363 > > // if this is the first call into the getPreviousPage then the page > // at the end of the pagesList is the previous page we're after. > // Return it if either we're not restricted to "within page sequence" > // or the page sequence values are equal. 335c365 < int pageIndex = renderQueue.size(); --- > int pageIndex = pagesList.size(); 337,338c367 < Page previousPage = ((RenderQueueEntry)renderQueue < .get(pageIndex - 1)).getPage(); --- > Page previousPage = (Page)pagesList.get(pageIndex - 1); 345,348c374,380 < } else { < for (int pageIndex=renderQueue.size()-1;pageIndex>0;pageIndex--) { < Page page = ((RenderQueueEntry)renderQueue < .get(pageIndex)).getPage(); --- > } > else { > // look for our page in the list of pages. If we find it then get > // the previous page and return it if either we're not restricted > // to "within page sequence" or the page sequence values are equal > for (int pageIndex = pagesList.size()-1; pageIndex > 0; pageIndex--) { > Page page = (Page)pagesList.get(pageIndex); 350,351c382 < Page previousPage = ((RenderQueueEntry)renderQueue < .get(pageIndex - 1)).getPage(); --- > Page previousPage = (Page)pagesList.get(pageIndex - 1);
cvs diff -b -B src/org/apache/fop/fo/FONode.java Index: src/org/apache/fop/fo/FONode.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/FONode.java,v retrieving revision 1.21.2.8 diff -b -B -r1.21.2.8 FONode.java 206c206,213 < public boolean mayPrecedeMarker() { --- > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true if this FO object permits fo:marker as initial children > */ > public boolean mayContainMarker() { cvs diff -b -B src/org/apache/fop/fo/FOText.java Index: src/org/apache/fop/fo/FOText.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/FOText.java,v retrieving revision 1.24.2.6 diff -b -B -r1.24.2.6 FOText.java 66,75c66,77 < public boolean mayPrecedeMarker() { < for (int i = 0; i < ca.length; i++) { < char ch = ca[i]; < if ((ch != ' ') || (ch != '\n') || (ch != '\r') < || (ch != '\t')) { // whitespace < return true; < } < } < return false; < } --- > > // public boolean mayPrecedeMarker() { > // for (int i = 0; i < ca.length; i++) { > // char ch = ca[i]; > // if ((ch != ' ') || (ch != '\n') || (ch != '\r') > // || (ch != '\t')) { // whitespace > // return true; > // } > // } > // return false; > // } > cvs diff -b -B src/org/apache/fop/fo/FObj.java Index: src/org/apache/fop/fo/FObj.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/FObj.java,v retrieving revision 1.20.2.6 diff -b -B -r1.20.2.6 FObj.java 154,160c154,179 < public void addMarker(Marker marker) throws FOPException { < String mcname = marker.getMarkerClassName(); < if (children != null) { < for (int i = 0; i < children.size(); i++) { < FONode child = (FONode)children.get(i); < if (!child.mayPrecedeMarker()) { < throw new FOPException("A fo:marker must be an initial child of '" --- > /** > * (MCA) Override FONode addChild() method to put in a check > * for Marker nodes. Some FObj subclasses permit Markers > * ("fo:marker") as initial children. This method first checks > * to be sure they're allowed and that they're initial child nodes. > * If either test fails then a message is logged and the marker is > * ignored. > * > * @param child node to add to this formatting object node. > */ > protected void addChild(FONode child) { > > // is the child node a fo:marker node? > if (child instanceof Marker) { > // does this formatting object permit Marker child nodes? > if (!mayContainMarker()) { > log.error("A fo:marker cannot be a child of '" > + getName()+"'"); > return; > } > > // if there are child nodes then the last one added must be a > // marker, else the marker being added isn't an "initial child" > else if (children != null && !children.isEmpty() && > !(children.get(children.size() - 1) instanceof Marker) ) { > log.error("A fo:marker must be an initial child of '" 161a181 > return; 163a184,185 > > super.addChild(child); 165c187,200 < if (markers==null) { --- > > > /** > * (MCA) Add a marker to our collection if we don't already > * have one for the marker's class name (the > * "marker-class-name" attrubite value) > * > * @param marker the Marker to add to our list > */ > public void addMarker(Marker marker) throws FOPException { > > String mcName = marker.getMarkerClassName(); > > if (markers == null) { 167,169c202,205 < markers.put(mcname, marker); < } else if (!markers.containsKey(mcname) ) { < markers.put(mcname, marker); --- > } > > if (!markers.containsKey(mcName) ) { > markers.put(mcName, marker); 172c208 < + mcname --- > + mcName cvs diff -b -B src/org/apache/fop/fo/flow/AbstractTableBody.java Index: src/org/apache/fop/fo/flow/AbstractTableBody.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Attic/AbstractTableBody.java,v retrieving revision 1.1.2.6 diff -b -B -r1.1.2.6 AbstractTableBody.java 140a141,148 > > // (MCA) if this child node is a Marker then just call its layout > // method and skip everything else > if (child instanceof Marker) { > ((Marker)child).layout(area); > continue; > } > cvs diff -b -B src/org/apache/fop/fo/flow/BidiOverride.java Index: src/org/apache/fop/fo/flow/BidiOverride.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/BidiOverride.java,v retrieving revision 1.4.2.2 diff -b -B -r1.4.2.2 BidiOverride.java 65a66,76 > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/Block.java Index: src/org/apache/fop/fo/flow/Block.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Block.java,v retrieving revision 1.41.2.13 diff -b -B -r1.41.2.13 Block.java 307a308,317 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/Flow.java Index: src/org/apache/fop/fo/flow/Flow.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Flow.java,v retrieving revision 1.24.2.3 diff -b -B -r1.24.2.3 Flow.java 52a53,63 > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/Inline.java Index: src/org/apache/fop/fo/flow/Inline.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Inline.java,v retrieving revision 1.8.2.7 diff -b -B -r1.8.2.7 Inline.java 75a76,86 > } > > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/ListBlock.java Index: src/org/apache/fop/fo/flow/ListBlock.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/ListBlock.java,v retrieving revision 1.21.2.6 diff -b -B -r1.21.2.6 ListBlock.java 175a176,185 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/ListItem.java Index: src/org/apache/fop/fo/flow/ListItem.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/ListItem.java,v retrieving revision 1.16.2.5 diff -b -B -r1.16.2.5 ListItem.java 183a184,193 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/ListItemBody.java Index: src/org/apache/fop/fo/flow/ListItemBody.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/ListItemBody.java,v retrieving revision 1.11.2.4 diff -b -B -r1.11.2.4 ListItemBody.java 77a78,87 > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/ListItemLabel.java Index: src/org/apache/fop/fo/flow/ListItemLabel.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/ListItemLabel.java,v retrieving revision 1.11.2.4 diff -b -B -r1.11.2.4 ListItemLabel.java 68a69,78 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/Marker.java Index: src/org/apache/fop/fo/flow/Marker.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Marker.java,v retrieving revision 1.6.2.5 diff -b -B -r1.6.2.5 Marker.java 87,89d86 < public boolean mayPrecedeMarker() { < return true; < } cvs diff -b -B src/org/apache/fop/fo/flow/RetrieveMarker.java Index: src/org/apache/fop/fo/flow/RetrieveMarker.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/RetrieveMarker.java,v retrieving revision 1.6.2.6 diff -b -B -r1.6.2.6 RetrieveMarker.java 64d65 < // System.out.println("Null bestMarker and searching..."); 68,69c69,76 < Page previousPage = locatePreviousPage(currentPage, < retrieveBoundary, --- > > // (MCA) a separate method (the old "locatePreviousPage() > // method) isn't really needed--just call what that called > Page previousPage = > currentPage.getAreaTree().getPreviousPage( > currentPage, > retrieveBoundary != > RetrieveBoundary.DOCUMENT, 79c87,88 < } else { --- > } > else { 84c93 < int status = Status.OK; --- > 89,90c98,102 < status = bestMarker.layoutMarker(area); < return status; --- > > > // (MCA) don't need a separate "status" integer to just return what > // "layoutMarker()" returns > return bestMarker.layoutMarker(area); 97d109 < // System.out.println("No markers on page"); 113a126,132 > > // (MCA) The spec says that "isFirst" or "isLast" is a preference, so > // we relax these loops to get a Marker instance if the names match and > // to get the preferred Marker if it exists and the "retrievePosition" > // indicates a preference > Marker markerToReturn = null; > int i = 0; 115,116c134,137 < for (int c = 0; c < pageMarkers.size(); c++) { < Marker currentMarker = (Marker)pageMarkers.get(c); --- > > while( markerToReturn == null && i < pageMarkers.size()) { > > Marker currentMarker = (Marker)pageMarkers.get(i); 118c139,142 < return currentMarker; --- > markerToReturn = currentMarker; > } > > i++; 121,122c145,147 < } else if (retrievePosition == RetrievePosition.FSWP) { < for (int i = 0; i < pageMarkers.size(); i++) { --- > else if (retrievePosition == RetrievePosition.FSWP) { > > for (i = 0; i < pageMarkers.size(); i++) { 125,126c150,151 < if (currentMarker.getRegistryArea().isFirst()) { < return currentMarker; --- > if (markerToReturn == null) { > markerToReturn = currentMarker; 127a153,154 > else if (currentMarker.getRegistryArea().isFirst()) { > markerToReturn = currentMarker; 130,132c157,162 < } else if (retrievePosition == RetrievePosition.LSWP) { < for (int i = pageMarkers.size(); i > 0; i--) { < Marker currentMarker = (Marker)pageMarkers.get(i - 1); --- > } > } > else if (retrievePosition == RetrievePosition.LSWP) { > > for (i = pageMarkers.size() - 1; i >= 0; i--) { > Marker currentMarker = (Marker)pageMarkers.get(i); 134,135c164,165 < if (currentMarker.getRegistryArea().isFirst()) { < return currentMarker; --- > if (markerToReturn == null) { > markerToReturn = currentMarker; 136a167,168 > else if (currentMarker.getRegistryArea().isFirst()) { > markerToReturn = currentMarker; 138a171,173 > } > } > else if (retrievePosition == RetrievePosition.LEWP) { 140,142c175,176 < } else if (retrievePosition == RetrievePosition.LEWP) { < for (int c = pageMarkers.size(); c > 0; c--) { < Marker currentMarker = (Marker)pageMarkers.get(c - 1); --- > for (i = pageMarkers.size() - 1; i >= 0; i--) { > Marker currentMarker = (Marker)pageMarkers.get(i); 144,145c178,179 < if (currentMarker.getRegistryArea().isLast()) { < return currentMarker; --- > if (markerToReturn == null) { > markerToReturn = currentMarker; 146a181,182 > else if (currentMarker.getRegistryArea().isLast()) { > markerToReturn = currentMarker; 149,151d184 < < } else { < throw new FOPException("Illegal 'retrieve-position' value"); 153c186,188 < return null; --- > } > else { > throw new FOPException("Illegal 'retrieve-position' value"); 156,162c191 < private Page locatePreviousPage(Page page, int retrieveBoundary, < boolean isFirstCall) { < boolean pageWithinSequence = true; < if (retrieveBoundary == RetrieveBoundary.DOCUMENT) < pageWithinSequence = false; < return page.getAreaTree().getPreviousPage(page, pageWithinSequence, < isFirstCall); --- > return markerToReturn; cvs diff -b -B src/org/apache/fop/fo/flow/Table.java Index: src/org/apache/fop/fo/flow/Table.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/Table.java,v retrieving revision 1.39.2.8 diff -b -B -r1.39.2.8 Table.java 566a567,576 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/TableAndCaption.java Index: src/org/apache/fop/fo/flow/TableAndCaption.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableAndCaption.java,v retrieving revision 1.4.2.2 diff -b -B -r1.4.2.2 TableAndCaption.java 66a67,78 > > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/TableBody.java Index: src/org/apache/fop/fo/flow/TableBody.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableBody.java,v retrieving revision 1.38.2.7 diff -b -B -r1.38.2.7 TableBody.java 36a37,46 > } > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since fo:table-body permits fo:marker as initial children > */ > public boolean mayContainMarker() { > return true; cvs diff -b -B src/org/apache/fop/fo/flow/TableCaption.java Index: src/org/apache/fop/fo/flow/TableCaption.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableCaption.java,v retrieving revision 1.4.2.2 diff -b -B -r1.4.2.2 TableCaption.java 64a65,75 > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/TableCell.java Index: src/org/apache/fop/fo/flow/TableCell.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableCell.java,v retrieving revision 1.39.2.8 diff -b -B -r1.39.2.8 TableCell.java 481a482,491 > > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } cvs diff -b -B src/org/apache/fop/fo/flow/TableFooter.java Index: src/org/apache/fop/fo/flow/TableFooter.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableFooter.java,v retrieving revision 1.3.2.4 diff -b -B -r1.3.2.4 TableFooter.java 47a48,57 > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } > cvs diff -b -B src/org/apache/fop/fo/flow/TableHeader.java Index: src/org/apache/fop/fo/flow/TableHeader.java =================================================================== RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/fo/flow/TableHeader.java,v retrieving revision 1.2.2.4 diff -b -B -r1.2.2.4 TableHeader.java 38a39,48 > /** > * (MCA) > * Does this formatting object allow markers as initial children? > * > * @return true, since this formatted object permits fo:marker as initial >children > */ > public boolean mayContainMarker() { > return true; > } >
markerSumbitFiles.zip
Description: Zip compressed data
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]