// FOP
import org.apache.fop.fo.FOInputHandler;
-import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.Renderer;
// SAX
/** The parent Driver object */
private Driver driver;
- /** The Font information relevant for this document */
- private FontInfo fontInfo;
-
/** The Renderer being used for this document */
protected Renderer renderer;
*/
public Document(Driver driver) {
this.driver = driver;
- this.fontInfo = new FontInfo();
- }
-
- /**
- * Retrieve the font information for this document
- * @return the FontInfo instance for this document
- */
- public FontInfo getFontInfo() {
- return this.fontInfo;
}
/**
/**
* Get the renderer for this document
- *
* @return the renderer for this document
*/
public Renderer getRenderer() {
}
currentDocument.renderer = renderer;
- foInputHandler = new FOTreeHandler(currentDocument, true);
-
- try {
- renderer.setupFontInfo(currentDocument.getFontInfo());
- // check that the "any,normal,400" font exists
- if (!currentDocument.getFontInfo().isSetupValid()) {
- throw new FOPException(
- "No default font defined by OutputConverter");
- }
- renderer.startRenderer(stream);
- } catch (IOException e) {
- throw new FOPException(e);
- }
+ foInputHandler = new FOTreeHandler(currentDocument, stream, true);
}
currentDocument.foInputHandler = foInputHandler;
import org.apache.fop.area.extensions.BookmarkData;
import org.apache.fop.fo.extensions.Outline;
import org.apache.fop.fo.extensions.Bookmarks;
+import org.apache.fop.render.Renderer;
import java.util.ArrayList;
import java.util.List;
/**
* Constructor.
*/
- public AreaTree () {
+ public AreaTree (Renderer renderer) {
+ // this.atModel = new CachedRenderPagesModel(renderer);
+ setTreeModel(new RenderPagesModel(renderer));
}
import org.apache.fop.fo.flow.TableRow;
import org.apache.fop.fo.pagination.Flow;
import org.apache.fop.fo.pagination.PageSequence;
+import org.apache.fop.fonts.FontInfo;
import org.apache.commons.logging.Log;
import org.xml.sax.SAXException;
*/
public Document doc = null;
+ /**
+ * The Font information relevant for this document
+ */
+ protected FontInfo fontInfo;
+
/**
* logging instance
*/
*/
public FOInputHandler(Document document) {
doc = document;
+ this.fontInfo = new FontInfo();
}
/**
return doc.getDriver();
}
+ /**
+ * Retrieve the font information for this document
+ * @return the FontInfo instance for this document
+ */
+ public FontInfo getFontInfo() {
+ return this.fontInfo;
+ }
+
/**
* This method is called to indicate the start of a new document run.
* @throws SAXException In case of a problem
// Java
import java.io.IOException;
+import java.io.OutputStream;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.fop.apps.Document;
import org.apache.fop.apps.FOPException;
import org.apache.fop.area.AreaTree;
-import org.apache.fop.area.RenderPagesModel;
import org.apache.fop.area.Title;
import org.apache.fop.fo.extensions.Bookmarks;
import org.apache.fop.fo.flow.BasicLink;
* Main constructor
* @param document the apps.Document implementation that governs this
* FO Tree
+ * @param OutputStream stream to use to output results of renderer
+ *
* @param store if true then use the store pages model and keep the
* area tree in memory
*/
- public FOTreeHandler(Document doc, boolean store) {
+ public FOTreeHandler(Document doc, OutputStream stream, boolean store) throws FOPException {
super(doc);
- areaTree = new AreaTree();
- // this.atModel = new CachedRenderPagesModel(renderer);
- areaTree.setTreeModel(new RenderPagesModel(doc.getRenderer()));
+ areaTree = new AreaTree(doc.getRenderer());
+
+ try {
+ doc.getRenderer().setupFontInfo(fontInfo);
+ // check that the "any,normal,400" font exists
+ if (!fontInfo.isSetupValid()) {
+ throw new FOPException(
+ "No default font defined by OutputConverter");
+ }
+ doc.getRenderer().startRenderer(stream);
+ } catch (IOException e) {
+ throw new FOPException(e);
+ }
if (collectStatistics) {
runtime = Runtime.getRuntime();
public void characters(char[] data, int start, int length) {
}
- /**
- * Get the font information for the layout handler.
- *
- * @return the font information
- */
- public Document getFontInfo() {
- return doc;
- }
-
/**
* Runs the formatting of this page sequence into the given area tree
*
if (textInfo == null) {
// Really only need one of these, but need to get fontInfo
// stored in propMgr for later use.
- propMgr.setFontInfo(getFOInputHandler().getDocument());
- textInfo = propMgr.getTextLayoutProps(getFOInputHandler().getDocument());
+ propMgr.setFontInfo(getFOInputHandler().getFontInfo());
+ textInfo = propMgr.getTextLayoutProps(getFOInputHandler().getFontInfo());
}
FOText ft = new FOText(data, start, length, textInfo, this);
package org.apache.fop.fo;
// FOP
-import org.apache.fop.apps.Document;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fonts.Font;
+import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.CommonBorderAndPadding;
import org.apache.fop.fo.properties.CommonMarginBlock;
public class PropertyManager implements Constants {
private PropertyList propertyList;
- private Document document = null;
+ private FontInfo fontInfo = null;
private Font fontState = null;
private CommonBorderAndPadding borderAndPadding = null;
private CommonHyphenation hyphProps = null;
}
/**
- * Sets the Document object telling the property manager which fonts are
+ * Sets the FontInfo object telling the property manager which fonts are
* available.
- * @param document apps.Document implementation containing font
- * information
+ * @param fontInfo FontInfo object
*/
- public void setFontInfo(Document document) {
- this.document = document;
+ public void setFontInfo(FontInfo fontInfo) {
+ this.fontInfo = fontInfo;
}
* information
* @return a FontState object
*/
- public Font getFontState(Document document) {
+ public Font getFontState(FontInfo fontInfo) {
if (fontState == null) {
- if (document == null) {
- document = this.document;
- } else if (this.document == null) {
- this.document = document;
+ if (fontInfo == null) {
+ fontInfo = this.fontInfo;
+ } else if (this.fontInfo == null) {
+ this.fontInfo = fontInfo;
}
/**@todo this is ugly. need to improve. */
// various kinds of keywords too
int fontSize = propertyList.get(PR_FONT_SIZE).getLength().getValue();
//int fontVariant = propertyList.get("font-variant").getEnum();
- String fname = document.getFontInfo().fontLookup(fontFamily, fontStyle,
+ String fname = fontInfo.fontLookup(fontFamily, fontStyle,
fontWeight);
- FontMetrics metrics = document.getFontInfo().getMetricsFor(fname);
+ FontMetrics metrics = fontInfo.getMetricsFor(fname);
fontState = new Font(fname, metrics, fontSize);
}
return fontState;
/**
* Constructs a TextInfo objects. If it was constructed before it is
* reused.
- * @param document apps.Document implementation containing list of
- * available fonts
+ * @param fontInfo FontInfo object containing list of available fonts
* @return a TextInfo object
*/
- public TextInfo getTextLayoutProps(Document document) {
+ public TextInfo getTextLayoutProps(FontInfo fontInfo) {
if (textInfo == null) {
textInfo = new TextInfo();
- textInfo.fs = getFontState(document);
+ textInfo.fs = getFontState(fontInfo);
textInfo.color = propertyList.get(PR_COLOR).getColorType();
textInfo.verticalAlign =
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
// XML
import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
// FOP
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FOTreeVisitor;
import org.apache.fop.apps.FOPException;
super(parent);
}
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ XSL/FOP Content Model: (title?,static-content*,flow)
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
+ if (nsURI == FOElementMapping.URI) {
+ if (localName.equals("title")) {
+ if (titleFO != null) {
+ tooManyNodesError(loc, "fo:title");
+ } else if (flowMap.size() > 0) {
+ nodesOutOfOrderError(loc, "fo:title", "fo:static-content");
+ } else if (mainFlow != null) {
+ nodesOutOfOrderError(loc, "fo:title", "fo:flow");
+ }
+ } else if (localName.equals("static-content")) {
+ if (mainFlow != null) {
+ nodesOutOfOrderError(loc, "fo:static-content", "fo:flow");
+ }
+ } else if (localName.equals("flow")) {
+ if (mainFlow != null) {
+ tooManyNodesError(loc, "fo:flow");
+ }
+ } else {
+ invalidChildError(loc, nsURI, localName);
+ }
+ } else {
+ invalidChildError(loc, nsURI, localName);
+ }
+ }
+
+ /**
+ * Signal end of this xml element.
+ * This passes the end page sequence to the structure handler
+ * so it can act upon that.
+ */
+ protected void end() {
+ if (mainFlow == null) {
+ missingChildElementError("(title?,static-content*,flow)");
+ }
+ try {
+ getFOInputHandler().endPageSequence(this);
+ } catch (FOPException fopex) {
+ getLogger().error("Error in PageSequence.end(): "
+ + fopex.getMessage(), fopex);
+ }
+ }
+
+ /**
+ * Validate the child being added and initialize internal variables.
+ * XSL content model for page-sequence:
+ * <pre>(title?,static-content*,flow)</pre>
+ *
+ * @param child The flow object child to be added to the PageSequence.
+ */
+ public void addChild(FONode child) {
+ try {
+ String childName = child.getName();
+ if (childName.equals("fo:title")) {
+ this.titleFO = (Title)child;
+ } else if (childName.equals("fo:flow")) {
+ this.mainFlow = (Flow)child;
+ String flowName = this.mainFlow.getFlowName();
+ if (flowMap.containsKey(flowName)) {
+ throw new FOPException("flow-name "
+ + flowName
+ + " is not unique within an fo:page-sequence");
+ }
+ if (!this.layoutMasterSet.regionNameExists(flowName)) {
+ getLogger().error("region-name '"
+ + flowName
+ + "' doesn't exist in the layout-master-set.");
+ }
+ // Don't add main flow to the flow map
+// addFlow(mainFlow);
+ startStructuredPageSequence();
+ super.addChild(child); // For getChildren
+ } else if (childName.equals("fo:static-content")) {
+ String flowName = ((StaticContent)child).getFlowName();
+ if (flowMap.containsKey(flowName)) {
+ throw new FOPException("flow-name " + flowName
+ + " is not unique within an fo:page-sequence");
+ }
+ if (!this.layoutMasterSet.regionNameExists(flowName)) {
+ throw new FOPException("region-name '" + flowName
+ + "' doesn't exist in the layout-master-set.");
+ }
+ flowMap.put(flowName, child);
+// addFlow((Flow)child);
+ startStructuredPageSequence();
+ }
+ } catch (FOPException fopex) {
+ getLogger().error("Error in PageSequence.addChild(): "
+ + fopex.getMessage(), fopex);
+ }
+ }
+
+
/**
* @see org.apache.fop.fo.FObj#addProperties
*/
// }
- /**
- * Validate the child being added and initialize internal variables.
- * XSL content model for page-sequence:
- * <pre>(title?,static-content*,flow)</pre>
- *
- * @param child The flow object child to be added to the PageSequence.
- */
- public void addChild(FONode child) {
- try {
- String childName = child.getName();
- if (childName.equals("fo:title")) {
- if (this.flowMap.size() > 0) {
- getLogger().warn("fo:title should be first in page-sequence");
- } else {
- this.titleFO = (Title)child;
- }
- } else if (childName.equals("fo:flow")) {
- if (this.mainFlow != null) {
- throw new FOPException("Only a single fo:flow permitted"
- + " per fo:page-sequence");
- } else {
- this.mainFlow = (Flow)child;
- String flowName = this.mainFlow.getFlowName();
- if (flowMap.containsKey(flowName)) {
- throw new FOPException("flow-name "
- + flowName
- + " is not unique within an fo:page-sequence");
- }
- if (!this.layoutMasterSet.regionNameExists(flowName)) {
- getLogger().error("region-name '"
- + flowName
- + "' doesn't exist in the layout-master-set.");
- }
- // Don't add main flow to the flow map
-// addFlow(mainFlow);
- startStructuredPageSequence();
- super.addChild(child); // For getChildren
- }
- } else if (childName.equals("fo:static-content")) {
- if (this.mainFlow != null) {
- throw new FOPException(childName
- + " must precede fo:flow; ignoring");
- }
- String flowName = ((StaticContent)child).getFlowName();
- if (flowMap.containsKey(flowName)) {
- throw new FOPException("flow-name " + flowName
- + " is not unique within an fo:page-sequence");
- }
- if (!this.layoutMasterSet.regionNameExists(flowName)) {
- getLogger().error("region-name '" + flowName
- + "' doesn't exist in the layout-master-set.");
- }
- flowMap.put(flowName, child);
-// addFlow((Flow)child);
- startStructuredPageSequence();
- } else {
- // Ignore it!
- getLogger().warn("FO '" + childName
- + "' not a legal page-sequence child.");
- return;
- }
- } catch (FOPException fopex) {
- getLogger().error("Error in PageSequence.addChild(): "
- + fopex.getMessage(), fopex);
- }
- }
-
/**
* Start the page-sequence logic in the Structured Handler
*/
}
}
- /**
- * Signal end of this xml element.
- * This passes the end page sequence to the structure handler
- * so it can act upon that.
- */
- protected void end() {
- try {
- getFOInputHandler().endPageSequence(this);
- } catch (FOPException fopex) {
- getLogger().error("Error in PageSequence.end(): "
- + fopex.getMessage(), fopex);
- }
- }
/**
* Initialize the current page number for the start of the page sequence.
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- Font fontState = propMgr.getFontState(getFOInputHandler().getDocument());
+ Font fontState = propMgr.getFontState(getFOInputHandler().getFontInfo());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
childLMiter = new BlockLMiter(this, childLMiter);
userAgent = inBlock.getUserAgent();
setBlockTextInfo(inBlock.getPropertyManager().getTextLayoutProps(
- inBlock.getFOInputHandler().getDocument()));
+ inBlock.getFOInputHandler().getFontInfo()));
}
private void setBlockTextInfo(TextInfo ti) {
public MIFHandler(Document doc, OutputStream os) {
super(doc);
outStream = os;
- FontSetup.setup(doc.getFontInfo(), null);
+ FontSetup.setup(fontInfo, null);
}
/**
bDefer = false;
bDeferredExecution = false;
iNestCount=0;
- FontSetup.setup(doc.getFontInfo(), null);
+ FontSetup.setup(fontInfo, null);
log.warn(ALPHA_WARNING);
}
}
rend.setLogger(logger);
- org.apache.fop.apps.Document doc = new org.apache.fop.apps.Document(null);
- rend.setupFontInfo(doc.getFontInfo());
+ FontInfo fontInfo = new FontInfo();
+ rend.setupFontInfo(fontInfo);
FOUserAgent ua = new FOUserAgent();
rend.setUserAgent(ua);
StorePagesModel sm = AreaTree.createStorePagesModel();
- TreeLoader tl = new TreeLoader(doc);
+ TreeLoader tl = new TreeLoader(rend, fontInfo);
tl.setLogger(logger);
tl.setTreeModel(sm);
try {
class TreeLoader {
private AreaTree areaTree;
private AreaTreeModel model;
- private org.apache.fop.apps.Document document;
+ private Renderer renderer;
+ private FontInfo fontInfo;
private Font currentFontState;
private Log logger = null;
- TreeLoader(org.apache.fop.apps.Document doc) {
- document = doc;
+ TreeLoader(Renderer renderer, FontInfo fontInfo) {
+ this.renderer = renderer;
+ this.fontInfo = fontInfo;
}
/**
Element root = null;
root = doc.getDocumentElement();
- areaTree = new AreaTree();
+ areaTree = new AreaTree(renderer);
areaTree.setTreeModel(model);
readAreaTree(root);
Character ch =
new Character(getString((Element) obj).charAt(0));
addTraits((Element) obj, ch);
- String fname = document.getFontInfo().fontLookup("sans-serif", "normal", Font.NORMAL);
- FontMetrics metrics = document.getFontInfo().getMetricsFor(fname);
+ String fname = fontInfo.fontLookup("sans-serif", "normal", Font.NORMAL);
+ FontMetrics metrics = fontInfo.getMetricsFor(fname);
currentFontState =
new Font(fname, metrics, 12000);
list.add(leader);
}
} else if (obj.getNodeName().equals("word")) {
- String fname = document.getFontInfo().fontLookup("sans-serif", "normal", Font.NORMAL);
- FontMetrics metrics = document.getFontInfo().getMetricsFor(fname);
+ String fname = fontInfo.fontLookup("sans-serif", "normal", Font.NORMAL);
+ FontMetrics metrics = fontInfo.getMetricsFor(fname);
currentFontState =
new Font(fname, metrics, 12000);
TextArea text = getText((Element) obj);