git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197715 13f79535-47bb-0310-9956-ffa450edef68tags/Root_Temp_KnuthStylePageBreaking
@@ -29,7 +29,6 @@ import org.apache.fop.area.AreaTreeModel; | |||
import org.apache.fop.fo.FOInputHandler; | |||
import org.apache.fop.fo.FOTreeControl; | |||
import org.apache.fop.fo.extensions.Bookmarks; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.commons.logging.Log; | |||
@@ -55,8 +54,6 @@ public class Document implements FOTreeControl { | |||
/** The AreaTreeModel for the PageSequence being rendered. */ | |||
public AreaTreeModel atModel; | |||
private Bookmarks bookmarks = null; | |||
/** | |||
* The current set of id's in the FO tree. | |||
* This is used so we know if the FO tree contains duplicates. | |||
@@ -64,8 +61,8 @@ public class Document implements FOTreeControl { | |||
private Set idReferences = new HashSet(); | |||
/** | |||
* Structure handler used to notify structure events | |||
* such as start end element. | |||
* Structure handler used to notify structure | |||
* events such as start end element. | |||
*/ | |||
public FOInputHandler foInputHandler; | |||
@@ -103,23 +100,6 @@ public class Document implements FOTreeControl { | |||
return areaTree; | |||
} | |||
/** | |||
* Set the Bookmarks object for this Document | |||
* @param bookmarks the Bookmarks object containing the bookmarks for this | |||
* Document | |||
*/ | |||
public void setBookmarks(Bookmarks bookmarks) { | |||
this.bookmarks = bookmarks; | |||
} | |||
/** | |||
* Public accessor for the Bookmarks for this Document | |||
* @return the Bookmarks for this Document | |||
*/ | |||
public Bookmarks getBookmarks() { | |||
return bookmarks; | |||
} | |||
/** | |||
* Retuns the set of ID references. | |||
* @return the ID references |
@@ -21,6 +21,7 @@ package org.apache.fop.area; | |||
import org.apache.fop.apps.Document; | |||
import org.apache.fop.area.extensions.BookmarkData; | |||
import org.apache.fop.fo.extensions.Outline; | |||
import org.apache.fop.fo.extensions.Bookmarks; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -219,14 +220,15 @@ public class AreaTree { | |||
/** | |||
* Create the bookmark data in the area tree. | |||
*/ | |||
public void addBookmarksToAreaTree() { | |||
if (document.getBookmarks() == null) { | |||
public void addBookmarksToAreaTree(Bookmarks bookmarks) { | |||
if (bookmarks == null) { | |||
return; | |||
} | |||
document.getDriver().getLogger().debug("adding bookmarks to area tree"); | |||
BookmarkData data = new BookmarkData(); | |||
for (int count = 0; count < document.getBookmarks().getOutlines().size(); count++) { | |||
Outline out = (Outline)(document.getBookmarks().getOutlines()).get(count); | |||
for (int count = 0; count < bookmarks.getOutlines().size(); count++) { | |||
Outline out = (Outline)(bookmarks.getOutlines()).get(count); | |||
data.addSubData(createBookmarkData(out)); | |||
} | |||
addTreeExtension(data); |
@@ -25,12 +25,13 @@ import java.util.HashMap; | |||
* Element mapping class for all XSL-FO elements. | |||
*/ | |||
public class FOElementMapping extends ElementMapping { | |||
public static String URI = "http://www.w3.org/1999/XSL/Format"; | |||
/** | |||
* Basic constructor; inititializes the namespace URI for the fo: namespace | |||
*/ | |||
public FOElementMapping() { | |||
namespaceURI = "http://www.w3.org/1999/XSL/Format"; | |||
namespaceURI = URI; | |||
} | |||
/** |
@@ -31,6 +31,8 @@ import org.apache.commons.logging.Log; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.util.CharUtilities; | |||
import org.apache.fop.apps.FOUserAgent; | |||
import org.apache.fop.fo.extensions.ExtensionElementMapping; | |||
import org.apache.fop.fo.extensions.svg.SVGElementMapping; | |||
/** | |||
* base class for nodes in the XML tree | |||
@@ -198,13 +200,60 @@ public abstract class FONode { | |||
/** | |||
* Helper function to standardize the names of all namespace URI - local | |||
* name pairs in text messages. | |||
* For readability, using fo:, fox:, svg:, for those namespaces even | |||
* though that prefix may not have been chosen in the document. | |||
* @param namespaceURI URI of node found | |||
* (e.g., "http://www.w3.org/1999/XSL/Format") | |||
* @param localName local name of node, (e.g., "root" for "fo:root") | |||
* @return a string combining the two values | |||
* @return the prefix:localname, if fo/fox/svg, or a longer representation | |||
* with the unabbreviated URI otherwise. | |||
*/ | |||
public static String getNodeString(String namespaceURI, String localName) { | |||
return "(Namespace URI: \"" + namespaceURI + "\", Local Name: \"" + localName + "\")"; | |||
if (namespaceURI.equals(FOElementMapping.URI)) { | |||
return "fo:" + localName; | |||
} else if (namespaceURI.equals(ExtensionElementMapping.URI)) { | |||
return "fox:" + localName; | |||
} else if (namespaceURI.equals(SVGElementMapping.URI)) { | |||
return "svg:" + localName; | |||
} else | |||
return "(Namespace URI: \"" + namespaceURI + "\", " + | |||
"Local Name: \"" + localName + "\")"; | |||
} | |||
/** | |||
* Helper function to standardize "too many" error exceptions | |||
* (e.g., two fo:declarations within fo:root) | |||
* @param offendingNode incoming node that would cause a duplication. | |||
*/ | |||
protected void tooManyNodesError(String offendingNode) { | |||
throw new IllegalArgumentException( | |||
"Error: for " + getName() + ", only one " | |||
+ offendingNode + " may be declared."); | |||
} | |||
/** | |||
* Helper function to standardize "out of order" exceptions | |||
* (e.g., fo:layout-master-set appearing after fo:page-sequence) | |||
* @param tooLateNode string name of node that should be earlier in document | |||
* @param tooEarlyNode string name of node that should be later in document | |||
*/ | |||
protected void nodesOutOfOrderError(String tooLateNode, String tooEarlyNode) { | |||
throw new IllegalArgumentException( | |||
"Error: for " + getName() + ", " + tooLateNode | |||
+ " must be declared before " + tooEarlyNode + "."); | |||
} | |||
/** | |||
* Helper function to return "invalid child" exceptions | |||
* (e.g., fo:block appearing immediately under fo:root) | |||
* @param nsURI namespace URI of incoming invalid node | |||
* @param lName local name (i.e., no prefix) of incoming node | |||
*/ | |||
protected void invalidChildError(String nsURI, String lName) { | |||
throw new IllegalArgumentException( | |||
"Error: " + getNodeString(nsURI, lName) + | |||
" is not valid child element of " + getName() + "."); | |||
} | |||
} | |||
@@ -226,7 +226,8 @@ public class FOTreeBuilder extends DefaultHandler { | |||
// Check to ensure first node encountered is an fo:root | |||
if (rootFObj == null) { | |||
if (!namespaceURI.equals(FObj.FO_URI) || !localName.equals("root")) { | |||
if (!namespaceURI.equals(FOElementMapping.URI) | |||
|| !localName.equals("root")) { | |||
throw new SAXException(new IllegalArgumentException( | |||
"Error: First element must be fo:root formatting object")); | |||
} |
@@ -25,7 +25,6 @@ import java.util.Set; | |||
// FOP | |||
import org.apache.fop.apps.Driver; | |||
import org.apache.fop.fo.extensions.Bookmarks; | |||
import org.apache.fop.fonts.FontMetrics; | |||
import org.apache.fop.fonts.FontInfo; | |||
@@ -39,19 +38,6 @@ import org.apache.fop.fonts.FontInfo; | |||
*/ | |||
public interface FOTreeControl { | |||
/** | |||
* Sets the Bookmark object which encapsulates the bookmarks for the FO | |||
* Tree. | |||
* @param bookmarks the Bookmark object encapsulating the bookmarks for this | |||
* FO Tree. | |||
*/ | |||
void setBookmarks(Bookmarks bookmarks); | |||
/** | |||
* @return the Bookmark object encapsulating the bookmarks for the FO Tree. | |||
*/ | |||
Bookmarks getBookmarks(); | |||
/** | |||
* Returns the set of ID references found in the FO Tree. | |||
* @return the ID references |
@@ -205,7 +205,7 @@ public class FOTreeHandler extends FOInputHandler { | |||
} | |||
} | |||
getAreaTree().addBookmarksToAreaTree(); | |||
getAreaTree().addBookmarksToAreaTree(pageSequence.getRoot().getBookmarks()); | |||
formatPageSequence(pageSequence, getAreaTree()); | |||
} | |||
@@ -36,8 +36,6 @@ import org.xml.sax.Locator; | |||
* Base class for representation of formatting objects and their processing. | |||
*/ | |||
public class FObj extends FONode implements Constants { | |||
public static final String FO_URI = "http://www.w3.org/1999/XSL/Format"; | |||
public static PropertyMaker[] propertyListTable = null; | |||
/** Formatting properties for this fo element. */ | |||
@@ -125,10 +123,10 @@ public class FObj extends FONode implements Constants { | |||
PropertyList parentPL = null; | |||
if (parentFO != null) { | |||
parentPL = parentFO.getPropertiesForNamespace(FO_URI); | |||
parentPL = parentFO.getPropertiesForNamespace(FOElementMapping.URI); | |||
} | |||
propertyList = new PropertyList(this, parentPL, FO_URI, name); | |||
propertyList = new PropertyList(this, parentPL, FOElementMapping.URI, name); | |||
propertyList.addAttributesToList(attlist); | |||
propMgr = new PropertyManager(propertyList); | |||
setWritingMode(); |
@@ -20,6 +20,7 @@ package org.apache.fop.fo.extensions; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FOTreeVisitor; | |||
import org.apache.fop.fo.pagination.Root; | |||
import java.util.ArrayList; | |||
@@ -58,7 +59,7 @@ public class Bookmarks extends ExtensionObj { | |||
* the extension to the area tree. | |||
*/ | |||
public void end() { | |||
getFOTreeControl().setBookmarks(this); | |||
((Root) parent).setBookmarks(this); | |||
} | |||
public void acceptVisitor(FOTreeVisitor fotv) { |
@@ -29,12 +29,13 @@ import java.util.HashMap; | |||
* pdf bookmark extension. | |||
*/ | |||
public class ExtensionElementMapping extends ElementMapping { | |||
public static String URI = "http://xml.apache.org/fop/extensions"; | |||
/** | |||
* Constructor. | |||
*/ | |||
public ExtensionElementMapping() { | |||
namespaceURI = "http://xml.apache.org/fop/extensions"; | |||
namespaceURI = URI; | |||
} | |||
/** |
@@ -30,10 +30,11 @@ import org.apache.fop.fo.FONode; | |||
* of the http://xml.apache.org/batik/ext namespace. | |||
*/ | |||
public class BatikExtensionElementMapping extends ElementMapping { | |||
public static String URI = "http://xml.apache.org/batik/ext"; | |||
private boolean batikAvail = true; | |||
public BatikExtensionElementMapping() { | |||
namespaceURI = "http://xml.apache.org/batik/ext"; | |||
namespaceURI = URI; | |||
} | |||
protected void initialize() { |
@@ -33,10 +33,11 @@ import org.apache.batik.dom.svg.SVGDOMImplementation; | |||
* that create the SVG Document. | |||
*/ | |||
public class SVGElementMapping extends ElementMapping { | |||
public static String URI = SVGDOMImplementation.SVG_NAMESPACE_URI; | |||
private boolean batik = true; | |||
public SVGElementMapping() { | |||
namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI; | |||
namespaceURI = URI; | |||
} | |||
protected void initialize() { |
@@ -25,6 +25,9 @@ import java.util.List; | |||
import org.apache.fop.fo.FOTreeControl; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.FOElementMapping; | |||
import org.apache.fop.fo.extensions.ExtensionElementMapping; | |||
import org.apache.fop.fo.extensions.Bookmarks; | |||
import org.apache.fop.fo.FOTreeVisitor; | |||
/** | |||
@@ -33,7 +36,9 @@ import org.apache.fop.fo.FOTreeVisitor; | |||
public class Root extends FObj { | |||
private LayoutMasterSet layoutMasterSet; | |||
private Declarations declarations; | |||
private Bookmarks bookmarks = null; | |||
private List pageSequences; | |||
// temporary until above list populated | |||
private boolean pageSequenceFound = false; | |||
@@ -58,39 +63,46 @@ public class Root extends FObj { | |||
/** | |||
* @see org.apache.fop.fo.FONode#validateChildNode(String, String) | |||
XSL 1.0 Spec: (layout-master-set,declarations?,page-sequence+) | |||
FOP: (layout-master-set, declarations?, fox:bookmarks?, page-sequence+) | |||
*/ | |||
protected void validateChildNode(String namespaceURI, String localName) { | |||
if (namespaceURI == FObj.FO_URI) { | |||
protected void validateChildNode(String nsURI, String localName) { | |||
if (nsURI == FOElementMapping.URI) { | |||
if (localName.equals("layout-master-set")) { | |||
if (layoutMasterSet != null) { // only one fo:declarations | |||
throw new IllegalArgumentException("Error: Only one" + | |||
" fo:layout-master-set may be defined per fo:root"); | |||
if (layoutMasterSet != null) { | |||
tooManyNodesError("fo:layout-master-set"); | |||
} | |||
} else if (localName.equals("declarations")) { | |||
if (layoutMasterSet == null) { // must already have a l-m-s | |||
throw new IllegalArgumentException("Error:" + | |||
" fo:layout-master-set must be first child of" + | |||
" fo:root"); | |||
} else if (declarations != null) { // only one fo:declarations | |||
throw new IllegalArgumentException("Error: Only one" + | |||
" fo:declarations may be defined per fo:root"); | |||
} else if (pageSequenceFound) { // no page-seqs yet | |||
throw new IllegalArgumentException("Error: fo:declarations" + | |||
" must be defined before fo:page-sequence declarations"); | |||
if (layoutMasterSet == null) { | |||
nodesOutOfOrderError("fo:layout-master-set", "fo:declarations"); | |||
} else if (declarations != null) { | |||
tooManyNodesError("fo:declarations"); | |||
} else if (bookmarks != null) { | |||
nodesOutOfOrderError("fo:declarations", "fox:bookmarks"); | |||
} else if (pageSequenceFound) { | |||
nodesOutOfOrderError("fo:declarations", "fo:page-sequence"); | |||
} | |||
} else if (localName.equals("page-sequence")) { | |||
if (layoutMasterSet == null) { // must already have a l-m-s | |||
throw new IllegalArgumentException("Error:" + | |||
" fo:layout-master-set must be first child of fo:root"); | |||
if (layoutMasterSet == null) { | |||
nodesOutOfOrderError("fo:layout-master-set", "fo:page-sequence"); | |||
} else { | |||
pageSequenceFound = true; | |||
} | |||
} else | |||
throw new IllegalArgumentException("Error: Invalid child" + | |||
" node \"fo:" + localName + "\" of fo:root"); | |||
} else { | |||
invalidChildError(nsURI, localName); | |||
} | |||
} else if (nsURI.equals(ExtensionElementMapping.URI)) { | |||
if (!localName.equals("bookmarks")) { | |||
invalidChildError(nsURI, localName); | |||
} else if (layoutMasterSet == null) { | |||
nodesOutOfOrderError("fo:layout-master-set", "fox:bookmarks"); | |||
} else if (bookmarks != null) { | |||
tooManyNodesError("fox:bookmarks"); | |||
} else if (pageSequenceFound) { | |||
nodesOutOfOrderError("fox:bookmarks", "fo:page-sequence"); | |||
} | |||
} else { | |||
throw new IllegalArgumentException("Error: Invalid child node " + | |||
FONode.getNodeString(namespaceURI, localName) + " of fo:root"); | |||
invalidChildError(nsURI, localName); | |||
} | |||
} | |||
@@ -168,6 +180,22 @@ public class Root extends FObj { | |||
this.declarations = declarations; | |||
} | |||
/** | |||
* Set the Bookmarks object for this FO | |||
* @param bookmarks the Bookmarks object | |||
*/ | |||
public void setBookmarks(Bookmarks bookmarks) { | |||
this.bookmarks = bookmarks; | |||
} | |||
/** | |||
* Public accessor for the Bookmarks for this FO | |||
* @return the Bookmarks object | |||
*/ | |||
public Bookmarks getBookmarks() { | |||
return bookmarks; | |||
} | |||
/** | |||
* Sets the FOTreeControl that this Root is attached to | |||
* @param foTreeControl the FOTreeControl implementation to which this Root |