2. Centralized determination of generatesInlineAreas() from multiple FObj subclasses into fo.PropertySets BitSet object. 3. validateChildNode() implemented for fo:list-item. 4. fo:initial-property-set now extending FObj instead of ToBeImplementedElement; burden of implementation on individual FOInputHandler subclasses. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197882 13f79535-47bb-0310-9956-ffa450edef68tags/Root_Temp_KnuthStylePageBreaking
@@ -56,7 +56,7 @@ public interface Constants { | |||
int RENDER_RTF = 10; | |||
// element constants | |||
int FO_UNKNOWN = 0; // FObj base class | |||
int FO_UNKNOWN_NODE = 0; // FObj base class | |||
int FO_BASIC_LINK = 1; | |||
int FO_BIDI_OVERRIDE = 2; | |||
int FO_BLOCK = 3; |
@@ -112,13 +112,22 @@ public abstract class FONode { | |||
} | |||
/** | |||
* Returns the name of the object | |||
* @return the name of this object | |||
* Returns the name of the node | |||
* @return the name of this node | |||
*/ | |||
public String getName() { | |||
return null; | |||
} | |||
/** | |||
* Returns the Constants class integer value of this node | |||
* @return the integer enumeration of this FO (e.g., FO_ROOT) | |||
* if a formatting object, FO_UNKNOWN_NODE otherwise | |||
*/ | |||
public int getNameId() { | |||
return Constants.FO_UNKNOWN_NODE; | |||
} | |||
/** | |||
* Checks to make sure, during SAX processing of input document, that the | |||
* incoming node is valid for the this (parent) node (e.g., checking to |
@@ -488,6 +488,10 @@ public class FOText extends FObj { | |||
} | |||
/** | |||
* @todo rename somehow, there isn't an fo:text. | |||
* @todo see if should still be a subclass of FObj | |||
*/ | |||
public String getName() { | |||
return "fo:text"; | |||
} |
@@ -192,8 +192,8 @@ public class FObj extends FONode implements Constants { | |||
*/ | |||
protected void addChildNode(FONode child) { | |||
if (PropertySets.canHaveMarkers(getNameId()) && | |||
"fo:marker".equals(child.getName())) { | |||
addMarker((Marker) child); | |||
child.getNameId() == FO_MARKER) { | |||
addMarker((Marker) child); | |||
} else { | |||
if (childNodes == null) { | |||
childNodes = new ArrayList(); | |||
@@ -332,15 +332,6 @@ public class FObj extends FONode implements Constants { | |||
return false; | |||
} | |||
/** | |||
* Check if this formatting object generates inline areas. | |||
* | |||
* @return true if generates inline areas | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return true; | |||
} | |||
/** | |||
* Set writing mode for this FO. | |||
* Use that from the nearest ancestor, including self, which generates | |||
@@ -386,7 +377,7 @@ public class FObj extends FONode implements Constants { | |||
* the first child. | |||
* @param marker Marker to add. | |||
*/ | |||
public void addMarker(Marker marker) { | |||
protected void addMarker(Marker marker) { | |||
String mcname = marker.getMarkerClassName(); | |||
if (childNodes != null) { | |||
// check for empty childNodes | |||
@@ -541,21 +532,5 @@ public class FObj extends FONode implements Constants { | |||
} | |||
return -1; | |||
} | |||
/** | |||
* Returns the name of this FO (e.g., "fo:root"); | |||
* @return the name of the FO | |||
*/ | |||
public String getName() { | |||
return null; | |||
} | |||
/** | |||
* Returns the Constants class integer value of this formatting object | |||
* @return the integer enumeration of this FO (e.g., FO_ROOT) | |||
*/ | |||
public int getNameId() { | |||
return FO_UNKNOWN; | |||
} | |||
} | |||
@@ -19,7 +19,6 @@ | |||
package org.apache.fop.fo; | |||
// FOP | |||
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; |
@@ -27,6 +27,7 @@ public class PropertySets { | |||
private static short[][] mapping = null; | |||
private static BitSet can_have_markers = null; | |||
private static BitSet can_have_id = null; | |||
private static BitSet no_inline_areas = null; | |||
private Element[] elements = new Element[Constants.ELEMENT_COUNT+1]; | |||
private BitSet block_elems = new BitSet(); | |||
@@ -1085,6 +1086,30 @@ public class PropertySets { | |||
return can_have_id.get(elementId); | |||
} | |||
/** | |||
* Determines if the FO generates inline areas. Used only within flow.Block | |||
* for whitespace handling | |||
* @param elementId Constants enumeration ID of the FO (e.g., FO_ROOT) | |||
* @return true if id property is applicable, false otherwise | |||
* @todo see if more values need to be entered here (copied values over | |||
* from legacy code, list of FO's below probably incomplete) | |||
* @todo see if still needed (LM has a similar generatesInlineAreas() | |||
* method) | |||
*/ | |||
public static boolean generatesInlineAreas(int elementId) { | |||
if (no_inline_areas == null) { | |||
no_inline_areas = new BitSet(); | |||
no_inline_areas.set(Constants.FO_UNKNOWN_NODE); | |||
no_inline_areas.set(Constants.FO_BLOCK); | |||
no_inline_areas.set(Constants.FO_BLOCK_CONTAINER); | |||
no_inline_areas.set(Constants.FO_LIST_BLOCK); | |||
no_inline_areas.set(Constants.FO_LIST_ITEM); | |||
no_inline_areas.set(Constants.FO_TABLE); | |||
no_inline_areas.set(Constants.FO_TABLE_AND_CAPTION); | |||
} | |||
return !(no_inline_areas.get(elementId)); | |||
} | |||
/** | |||
* An object that represent the properties and contents of a fo element | |||
*/ |
@@ -32,6 +32,7 @@ import org.apache.fop.fo.CharIterator; | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.FObj; | |||
import org.apache.fop.fo.FObjMixed; | |||
import org.apache.fop.fo.PropertySets; | |||
import org.apache.fop.fo.RecursiveCharIterator; | |||
import org.apache.fop.layoutmgr.BlockLayoutManager; | |||
import org.apache.fop.fo.Constants; | |||
@@ -91,6 +92,7 @@ public class Block extends FObjMixed { | |||
/** | |||
* @param parent FONode that is the parent of this object | |||
* | |||
*/ | |||
public Block(FONode parent) { | |||
super(parent); | |||
@@ -175,13 +177,6 @@ public class Block extends FObjMixed { | |||
return this.span; | |||
} | |||
/** | |||
* @return false (Block cannot generate inline areas) | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FONode#addChildNode(FONode) | |||
*/ | |||
@@ -189,11 +184,12 @@ public class Block extends FObjMixed { | |||
// Handle whitespace based on values of properties | |||
// Handle a sequence of inline-producing child nodes in | |||
// one pass | |||
if (child instanceof FObj && ((FObj) child).generatesInlineAreas()) { | |||
if (firstInlineChild == null) { | |||
firstInlineChild = child; | |||
} | |||
// lastInlineChild = childNodes.size(); | |||
if (child instanceof FObj && ("fo:text".equals(child.getName()) | |||
|| PropertySets.generatesInlineAreas(child.getNameId()))) { | |||
if (firstInlineChild == null) { | |||
firstInlineChild = child; | |||
} | |||
// lastInlineChild = childNodes.size(); | |||
} else { | |||
// Handle whitespace in preceeding inline areas if any | |||
handleWhiteSpace(); |
@@ -75,13 +75,6 @@ public class BlockContainer extends FObj { | |||
return true; | |||
} | |||
/** | |||
* @return false (BlockContainer cannot generate inline areas) | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
} | |||
/** | |||
* @return the span for this object | |||
*/ | |||
@@ -98,6 +91,9 @@ public class BlockContainer extends FObj { | |||
list.add(blm); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#getName() | |||
*/ | |||
public String getName() { | |||
return "fo:block-container"; | |||
} |
@@ -59,6 +59,7 @@ public class ExternalGraphic extends FObj { | |||
/** | |||
* @see org.apache.fop.fo.FObj#addProperties | |||
* @todo switch method from image() to startImage()? | |||
*/ | |||
protected void addProperties(Attributes attlist) throws SAXParseException { | |||
super.addProperties(attlist); |
@@ -14,7 +14,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
/* $Id:$ */ | |||
package org.apache.fop.fo.flow; | |||
@@ -25,13 +25,12 @@ import org.xml.sax.SAXParseException; | |||
// FOP | |||
import org.apache.fop.fo.FONode; | |||
import org.apache.fop.fo.ToBeImplementedElement; | |||
import org.apache.fop.fo.FObj; | |||
/** | |||
* Class modelling the fo:initial-property-set object. See Sec. 6.6.4 of the | |||
* XSL-FO Standard. | |||
* Class modelling the fo:initial-property-set object. | |||
*/ | |||
public class InitialPropertySet extends ToBeImplementedElement { | |||
public class InitialPropertySet extends FObj { | |||
/** | |||
* @param parent FONode that is the parent of this object | |||
@@ -49,6 +48,9 @@ public class InitialPropertySet extends ToBeImplementedElement { | |||
invalidChildError(loc, nsURI, localName); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#getName() | |||
*/ | |||
public String getName() { | |||
return "fo:initial-property-set"; | |||
} |
@@ -113,15 +113,6 @@ public class InstreamForeignObject extends FObj { | |||
return yoffset; | |||
} | |||
/** | |||
* This flow object generates inline areas. | |||
* @see org.apache.fop.fo.FObj#generatesInlineAreas() | |||
* @return true | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return true; | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#addLayoutManager(List) | |||
*/ |
@@ -38,18 +38,6 @@ import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; | |||
*/ | |||
public class ListBlock extends FObj { | |||
private int align; | |||
private int alignLast; | |||
private int breakBefore; | |||
private int breakAfter; | |||
private int lineHeight; | |||
private int startIndent; | |||
private int endIndent; | |||
private int spaceBefore; | |||
private int spaceAfter; | |||
private int spaceBetweenListRows = 0; | |||
private ColorType backgroundColor; | |||
// used for child node validation | |||
private boolean hasListItem = false; | |||
@@ -65,22 +53,6 @@ public class ListBlock extends FObj { | |||
*/ | |||
protected void addProperties(Attributes attlist) throws SAXParseException { | |||
super.addProperties(attlist); | |||
this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); | |||
this.alignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); | |||
this.lineHeight = | |||
this.propertyList.get(PR_LINE_HEIGHT).getLength().getValue(); | |||
this.startIndent = | |||
this.propertyList.get(PR_START_INDENT).getLength().getValue(); | |||
this.endIndent = | |||
this.propertyList.get(PR_END_INDENT).getLength().getValue(); | |||
this.spaceBefore = | |||
this.propertyList.get(PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue(); | |||
this.spaceAfter = | |||
this.propertyList.get(PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue(); | |||
this.spaceBetweenListRows = 0; // not used at present | |||
this.backgroundColor = | |||
this.propertyList.get(PR_BACKGROUND_COLOR).getColorType(); | |||
getFOInputHandler().startList(this); | |||
} | |||
@@ -113,13 +85,6 @@ public class ListBlock extends FObj { | |||
getFOInputHandler().endList(this); | |||
} | |||
/** | |||
* @return false (ListBlock does not generate inline areas) | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#addLayoutManager(List) | |||
*/ | |||
@@ -128,6 +93,9 @@ public class ListBlock extends FObj { | |||
list.add(lm); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#getName() | |||
*/ | |||
public String getName() { | |||
return "fo:list-block"; | |||
} |
@@ -14,7 +14,7 @@ | |||
* limitations under the License. | |||
*/ | |||
/* $Id$ */ | |||
/* $Id:$ */ | |||
package org.apache.fop.fo.flow; | |||
@@ -23,6 +23,7 @@ import java.util.List; | |||
// XML | |||
import org.xml.sax.Attributes; | |||
import org.xml.sax.Locator; | |||
import org.xml.sax.SAXParseException; | |||
// FOP | |||
@@ -31,24 +32,13 @@ import org.apache.fop.fo.FObj; | |||
import org.apache.fop.layoutmgr.list.ListItemLayoutManager; | |||
/** | |||
* Class modelling the fo:list-item object. See Sec. 6.8.3 of the XSL-FO | |||
* Standard. | |||
* Class modelling the fo:list-item object. | |||
*/ | |||
public class ListItem extends FObj { | |||
private ListItemLabel label = null; | |||
private ListItemBody body = null; | |||
private int align; | |||
private int alignLast; | |||
private int breakBefore; | |||
private int breakAfter; | |||
private int lineHeight; | |||
private int startIndent; | |||
private int endIndent; | |||
private int spaceBefore; | |||
private int spaceAfter; | |||
/** | |||
* @param parent FONode that is the parent of this object | |||
*/ | |||
@@ -62,49 +52,68 @@ public class ListItem extends FObj { | |||
protected void addProperties(Attributes attlist) throws SAXParseException { | |||
super.addProperties(attlist); | |||
getFOInputHandler().startListItem(this); | |||
this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum(); | |||
this.alignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum(); | |||
this.lineHeight = | |||
this.propertyList.get(PR_LINE_HEIGHT).getLength().getValue(); | |||
this.spaceBefore = | |||
this.propertyList.get(PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue(); | |||
this.spaceAfter = | |||
this.propertyList.get(PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue(); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String) | |||
* XSL Content Model: marker* (list-item-label,list-item-body) | |||
*/ | |||
protected void validateChildNode(Locator loc, String nsURI, String localName) | |||
throws SAXParseException { | |||
if (nsURI == FO_URI && localName.equals("marker")) { | |||
if (label != null) { | |||
nodesOutOfOrderError(loc, "fo:marker", "fo:list-item-label"); | |||
} | |||
} else if (nsURI == FO_URI && localName.equals("list-item-label")) { | |||
if (label != null) { | |||
tooManyNodesError(loc, "fo:list-item-label"); | |||
} | |||
} else if (nsURI == FO_URI && localName.equals("list-item-body")) { | |||
if (label == null) { | |||
nodesOutOfOrderError(loc, "fo:list-item-label", "fo:list-item-body"); | |||
} else if (body != null) { | |||
tooManyNodesError(loc, "fo:list-item-body"); | |||
} | |||
} else { | |||
invalidChildError(loc, nsURI, localName); | |||
} | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FONode#addChildNode(FONode) | |||
* @todo see if can/should rely on base class for this | |||
* (i.e., add to childNodes instead) | |||
*/ | |||
public void addChildNode(FONode child) { | |||
if ("fo:list-item-label".equals(child.getName())) { | |||
label = (ListItemLabel)child; | |||
} else if ("fo:list-item-body".equals(child.getName())) { | |||
body = (ListItemBody)child; | |||
} else if ("fo:marker".equals(child.getName())) { | |||
// marker | |||
} else { | |||
// error | |||
int nameId = ((FObj)child).getNameId(); | |||
if (nameId == FO_LIST_ITEM_LABEL) { | |||
label = (ListItemLabel) child; | |||
} else if (nameId == FO_LIST_ITEM_BODY) { | |||
body = (ListItemBody) child; | |||
} else if (nameId == FO_MARKER) { | |||
addMarker((Marker) child); | |||
} | |||
} | |||
/** | |||
* @return false (ListItem cannot generate inline areas) | |||
* Make sure content model satisfied, if so then tell the | |||
* FOInputHandler that we are at the end of the flow. | |||
* @see org.apache.fop.fo.FONode#end | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
protected void endOfNode() throws SAXParseException { | |||
if (label == null || body == null) { | |||
missingChildElementError("marker* (list-item-label,list-item-body)"); | |||
} | |||
getFOInputHandler().endListItem(this); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#addLayoutManager(List) | |||
* @todo remove checks for non-nulls after validateChildNode() added | |||
*/ | |||
public void addLayoutManager(List list) { | |||
if (label != null && body != null) { | |||
ListItemLayoutManager blm = new ListItemLayoutManager(this); | |||
list.add(blm); | |||
} else { | |||
getLogger().error("list-item requires list-item-label and list-item-body"); | |||
} | |||
ListItemLayoutManager blm = new ListItemLayoutManager(this); | |||
list.add(blm); | |||
} | |||
public ListItemLabel getLabel() { | |||
@@ -115,11 +124,9 @@ public class ListItem extends FObj { | |||
return body; | |||
} | |||
protected void endOfNode() throws SAXParseException { | |||
super.endOfNode(); | |||
getFOInputHandler().endListItem(this); | |||
} | |||
/** | |||
* @see org.apache.fop.fo.FObj#getName() | |||
*/ | |||
public String getName() { | |||
return "fo:list-item"; | |||
} |
@@ -130,13 +130,6 @@ public class Table extends FObj { | |||
} | |||
} | |||
/** | |||
* @return false (Table does not generate inline areas) | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
} | |||
private ArrayList getColumns() { | |||
return columns; | |||
} |
@@ -36,12 +36,8 @@ public class TableAndCaption extends ToBeImplementedElement { | |||
} | |||
/** | |||
* @return false (TableAndCaption doesn't generate inline areas) | |||
* @see org.apache.fop.fo.FObj#getName() | |||
*/ | |||
public boolean generatesInlineAreas() { | |||
return false; | |||
} | |||
public String getName() { | |||
return "fo:table-and-caption"; | |||
} |
@@ -152,7 +152,7 @@ public class ConditionalPageMasterReference extends FObj { | |||
* Check that the parent is the right type of formatting object | |||
* repeatable-page-master-alternatives. | |||
* @param parent parent node | |||
* @throws FOPException If the parent is invalid | |||
* @throws SAXParseException If the parent is invalid | |||
*/ | |||
protected void validateParent(FONode parent) throws SAXParseException { | |||
if (parent.getName().equals("fo:repeatable-page-master-alternatives")) { |
@@ -68,7 +68,7 @@ public class StaticContent extends Flow { | |||
/** | |||
* flowname checking is more stringient for static content currently | |||
* @param name the flow-name to set | |||
* @throws FOPException for a missing flow name | |||
* @throws SAXParseException for a missing flow name | |||
*/ | |||
protected void setFlowName(String name) throws SAXParseException { | |||
if (name == null || name.equals("")) { |
@@ -85,6 +85,8 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { | |||
/** | |||
* @see org.apache.fop.layoutmgr.AbstractLayoutManager#initProperties() | |||
* @todo need to take into account somewhere the effects of fo:initial-property-set, | |||
* if defined for the block. | |||
*/ | |||
protected void initProperties() { | |||
PropertyManager pm = fobj.getPropertyManager(); |