2. AreaTree now takes a Renderer as a constructor, handles RenderPagesModel initialization. 3. FontInfo object moved from Driver/Document to fo.FOInputHandler. 4. getFontState/getFontInfo now take a fontInfo object directly instead of a apps.Document. 5. validity checking added to PageSequence.java git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197734 13f79535-47bb-0310-9956-ffa450edef68tags/Root_Temp_KnuthStylePageBreaking
@@ -20,7 +20,6 @@ package org.apache.fop.apps; | |||
// FOP | |||
import org.apache.fop.fo.FOInputHandler; | |||
import org.apache.fop.fonts.FontInfo; | |||
import org.apache.fop.render.Renderer; | |||
// SAX | |||
@@ -35,9 +34,6 @@ public class Document { | |||
/** 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; | |||
@@ -53,15 +49,6 @@ public class Document { | |||
*/ | |||
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; | |||
} | |||
/** | |||
@@ -74,7 +61,6 @@ public class Document { | |||
/** | |||
* Get the renderer for this document | |||
* | |||
* @return the renderer for this document | |||
*/ | |||
public Renderer getRenderer() { |
@@ -488,19 +488,7 @@ public class Driver { | |||
} | |||
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; | |||
@@ -21,6 +21,7 @@ package org.apache.fop.area; | |||
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; | |||
@@ -67,7 +68,9 @@ public class AreaTree { | |||
/** | |||
* Constructor. | |||
*/ | |||
public AreaTree () { | |||
public AreaTree (Renderer renderer) { | |||
// this.atModel = new CachedRenderPagesModel(renderer); | |||
setTreeModel(new RenderPagesModel(renderer)); | |||
} | |||
@@ -45,6 +45,7 @@ import org.apache.fop.fo.flow.TableCell; | |||
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; | |||
@@ -67,6 +68,11 @@ public abstract class FOInputHandler { | |||
*/ | |||
public Document doc = null; | |||
/** | |||
* The Font information relevant for this document | |||
*/ | |||
protected FontInfo fontInfo; | |||
/** | |||
* logging instance | |||
*/ | |||
@@ -85,6 +91,7 @@ public abstract class FOInputHandler { | |||
*/ | |||
public FOInputHandler(Document document) { | |||
doc = document; | |||
this.fontInfo = new FontInfo(); | |||
} | |||
/** | |||
@@ -127,6 +134,14 @@ public abstract class FOInputHandler { | |||
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 |
@@ -20,6 +20,7 @@ package org.apache.fop.fo; | |||
// Java | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.util.HashSet; | |||
import java.util.Iterator; | |||
@@ -30,7 +31,6 @@ import org.xml.sax.SAXException; | |||
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; | |||
@@ -104,15 +104,27 @@ public class FOTreeHandler extends FOInputHandler { | |||
* 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(); | |||
@@ -482,15 +494,6 @@ public class FOTreeHandler extends FOInputHandler { | |||
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 | |||
* |
@@ -46,8 +46,8 @@ public class FObjMixed extends FObj { | |||
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); |
@@ -19,9 +19,9 @@ | |||
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; | |||
@@ -45,7 +45,7 @@ import org.xml.sax.Attributes; | |||
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; | |||
@@ -71,13 +71,12 @@ public class PropertyManager implements Constants { | |||
} | |||
/** | |||
* 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; | |||
} | |||
@@ -88,12 +87,12 @@ public class PropertyManager implements Constants { | |||
* 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. */ | |||
@@ -122,9 +121,9 @@ public class PropertyManager implements Constants { | |||
// 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; | |||
@@ -458,14 +457,13 @@ public class PropertyManager implements Constants { | |||
/** | |||
* 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 = |
@@ -66,7 +66,7 @@ public class Leader extends FObjMixed { | |||
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(); |
@@ -77,7 +77,7 @@ public class PageNumber extends FObj { | |||
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(); |
@@ -82,7 +82,7 @@ public class PageNumberCitation extends FObj { | |||
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(); |
@@ -23,10 +23,12 @@ import java.util.HashMap; | |||
// 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; | |||
@@ -130,6 +132,103 @@ public class PageSequence extends FObj { | |||
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 | |||
*/ | |||
@@ -220,73 +319,6 @@ public class PageSequence extends FObj { | |||
// } | |||
/** | |||
* 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 | |||
*/ | |||
@@ -297,19 +329,6 @@ public class PageSequence extends FObj { | |||
} | |||
} | |||
/** | |||
* 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. |
@@ -59,7 +59,7 @@ public class Title extends FObjMixed { | |||
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(); |
@@ -74,7 +74,7 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { | |||
childLMiter = new BlockLMiter(this, childLMiter); | |||
userAgent = inBlock.getUserAgent(); | |||
setBlockTextInfo(inBlock.getPropertyManager().getTextLayoutProps( | |||
inBlock.getFOInputHandler().getDocument())); | |||
inBlock.getFOInputHandler().getFontInfo())); | |||
} | |||
private void setBlockTextInfo(TextInfo ti) { |
@@ -75,7 +75,7 @@ public class MIFHandler extends FOInputHandler { | |||
public MIFHandler(Document doc, OutputStream os) { | |||
super(doc); | |||
outStream = os; | |||
FontSetup.setup(doc.getFontInfo(), null); | |||
FontSetup.setup(fontInfo, null); | |||
} | |||
/** |
@@ -131,7 +131,7 @@ public class RTFHandler extends FOInputHandler { | |||
bDefer = false; | |||
bDeferredExecution = false; | |||
iNestCount=0; | |||
FontSetup.setup(doc.getFontInfo(), null); | |||
FontSetup.setup(fontInfo, null); | |||
log.warn(ALPHA_WARNING); | |||
} | |||
@@ -160,13 +160,13 @@ public class AreaTreeBuilder { | |||
} | |||
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 { | |||
@@ -238,12 +238,14 @@ public class AreaTreeBuilder { | |||
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; | |||
} | |||
/** | |||
@@ -271,7 +273,7 @@ class TreeLoader { | |||
Element root = null; | |||
root = doc.getDocumentElement(); | |||
areaTree = new AreaTree(); | |||
areaTree = new AreaTree(renderer); | |||
areaTree.setTreeModel(model); | |||
readAreaTree(root); | |||
@@ -558,8 +560,8 @@ class TreeLoader { | |||
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); | |||
@@ -583,8 +585,8 @@ class TreeLoader { | |||
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); |