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;
}
/**
- * 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
}
+ /**
+ * @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";
}
*/
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();
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
* 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
}
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;
- }
}
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;
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();
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
*/
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;
/**
* @param parent FONode that is the parent of this object
+ *
*/
public Block(FONode parent) {
super(parent);
return this.span;
}
- /**
- * @return false (Block cannot generate inline areas)
- */
- public boolean generatesInlineAreas() {
- return false;
- }
-
/**
* @see org.apache.fop.fo.FONode#addChildNode(FONode)
*/
// 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();
return true;
}
- /**
- * @return false (BlockContainer cannot generate inline areas)
- */
- public boolean generatesInlineAreas() {
- return false;
- }
-
/**
* @return the span for this object
*/
list.add(blm);
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:block-container";
}
/**
* @see org.apache.fop.fo.FObj#addProperties
+ * @todo switch method from image() to startImage()?
*/
protected void addProperties(Attributes attlist) throws SAXParseException {
super.addProperties(attlist);
* limitations under the License.
*/
-/* $Id$ */
+/* $Id:$ */
package org.apache.fop.fo.flow;
// 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
invalidChildError(loc, nsURI, localName);
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:initial-property-set";
}
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)
*/
*/
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;
*/
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);
}
getFOInputHandler().endList(this);
}
- /**
- * @return false (ListBlock does not generate inline areas)
- */
- public boolean generatesInlineAreas() {
- return false;
- }
-
/**
* @see org.apache.fop.fo.FObj#addLayoutManager(List)
*/
list.add(lm);
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:list-block";
}
* limitations under the License.
*/
-/* $Id$ */
+/* $Id:$ */
package org.apache.fop.fo.flow;
// XML
import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
// FOP
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
*/
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() {
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";
}
}
}
- /**
- * @return false (Table does not generate inline areas)
- */
- public boolean generatesInlineAreas() {
- return false;
- }
-
private ArrayList getColumns() {
return columns;
}
}
/**
- * @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";
}
* 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")) {
/**
* 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("")) {
/**
* @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();