}
*/
- public String getName() {
- return null;
- }
-
/**
* Convenience method for validity checking. Checks if the
* incoming node is a member of the "%block;" parameter entity
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
+ * @return the integer enumeration of this FO (e.g., FO_ROOT)
*/
public int getNameId() {
return FO_UNKNOWN;
// XML
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
// FOP
import org.apache.fop.fo.RecursiveCharIterator;
import org.apache.fop.layoutmgr.BlockLayoutManager;
import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.properties.CommonAccessibility;
-import org.apache.fop.fo.properties.CommonAural;
-import org.apache.fop.fo.properties.CommonBackground;
-import org.apache.fop.fo.properties.CommonBorderAndPadding;
-import org.apache.fop.fo.properties.CommonHyphenation;
-import org.apache.fop.fo.properties.CommonMarginBlock;
-import org.apache.fop.fo.properties.CommonRelativePosition;
import org.apache.fop.util.CharUtilities;
/*
*/
public class Block extends FObjMixed {
+ // used for FO validation
+ private boolean blockOrInlineItemFound = false;
+ private boolean initialPropertySetFound = false;
+
private int align;
private int alignLast;
private int breakAfter;
getFOInputHandler().startBlock(this);
}
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ * XSL Content Model: marker* initial-property-set? (#PCDATA|%inline;|%block;)*
+ * Additionally: "An fo:bidi-override that is a descendant of an fo:leader
+ * or of the fo:inline child of an fo:footnote may not have block-level
+ * children, unless it has a nearer ancestor that is an
+ * fo:inline-container."
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName)
+ throws SAXParseException {
+ if (nsURI == FO_URI && localName.equals("marker")) {
+ if (blockOrInlineItemFound || initialPropertySetFound) {
+ nodesOutOfOrderError(loc, "fo:marker",
+ "initial-property-set? (#PCDATA|%inline;|%block;)");
+ }
+ } else if (nsURI == FO_URI && localName.equals("initial-property-set")) {
+ if (initialPropertySetFound) {
+ tooManyNodesError(loc, "fo:initial-property-set");
+ } else if (blockOrInlineItemFound) {
+ nodesOutOfOrderError(loc, "fo:initial-property-set",
+ "(#PCDATA|%inline;|%block;)");
+ } else {
+ initialPropertySetFound = true;
+ }
+ } else if (isBlockOrInlineItem(nsURI, localName)) {
+ blockOrInlineItemFound = true;
+ } else {
+ invalidChildError(loc, nsURI, localName);
+ }
+ }
+
/**
* @return span for this Block, in millipoints (??)
*/
import org.xml.sax.Locator;
import org.xml.sax.SAXParseException;
+// FOP
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.properties.CommonAccessibility;
-import org.apache.fop.fo.properties.CommonAural;
-import org.apache.fop.fo.properties.CommonBackground;
-import org.apache.fop.fo.properties.CommonBorderAndPadding;
-import org.apache.fop.fo.properties.CommonMarginInline;
-import org.apache.fop.fo.properties.CommonRelativePosition;
import org.apache.fop.fonts.Font;
-import org.apache.fop.layoutmgr.LayoutContext;
-import org.apache.fop.layoutmgr.LayoutManager;
-import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
-import org.apache.fop.layoutmgr.PositionIterator;
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Resolveable;
-import org.apache.fop.area.Trait;
-import org.apache.fop.area.inline.InlineArea;
-import org.apache.fop.area.inline.UnresolvedPageNumber;
-import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.layoutmgr.PageNumberCitationLayoutManager;
/**
* Class modelling the fo:page-number-citation object. See Sec. 6.6.11 of the
}
/**
- * @param str string to be measured
- * @return width (in millipoints ??) of the string
+ * @todo switch this method to addProperties()
*/
- public int getStringWidth(String str) {
- int width = 0;
- for (int count = 0; count < str.length(); count++) {
- width += fontState.getCharWidth(str.charAt(count));
- }
- return width;
- }
-
private void setup() {
-
- // Common Accessibility Properties
- CommonAccessibility mAccProps = propMgr.getAccessibilityProps();
-
- // Common Aural Properties
- CommonAural mAurProps = propMgr.getAuralProps();
-
- // Common Border, Padding, and Background Properties
- CommonBorderAndPadding bap = propMgr.getBorderAndPadding();
- CommonBackground bProps = propMgr.getBackgroundProps();
-
// Common Font Properties
this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo());
- // Common Margin Properties-Inline
- CommonMarginInline mProps = propMgr.getMarginInlineProps();
-
- // Common Relative Position Properties
- CommonRelativePosition mRelProps =
- propMgr.getRelativePositionProps();
-
setupID();
ColorType c = this.propertyList.get(PR_COLOR).getColorType();
return fontState;
}
- public String getName() {
- return "fo:page-number-citation";
- }
-
/**
* @see org.apache.fop.fo.FObj#addLayoutManager(List)
- * @todo create a subclass for LeafNodeLayoutManager, moving the formatting
- * logic to the layoutmgr package
*/
public void addLayoutManager(List list) {
setup();
- LayoutManager lm;
- lm = new LeafNodeLayoutManager(this) {
- public InlineArea get(LayoutContext context) {
- curArea = getPageNumberCitationInlineArea(parentLM);
- return curArea;
- }
-
- public void addAreas(PositionIterator posIter,
- LayoutContext context) {
- super.addAreas(posIter, context);
- if (getUnresolved()) {
- parentLM.addUnresolvedArea(getRefId(),
- (Resolveable) curArea);
- }
- }
-
- protected void offsetArea(LayoutContext context) {
- curArea.setOffset(context.getBaseline());
- }
- };
+ PageNumberCitationLayoutManager lm =
+ new PageNumberCitationLayoutManager(this);
list.add(lm);
}
-
- // if id can be resolved then simply return a word, otherwise
- // return a resolveable area
- public InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) {
- if (getRefId().equals("")) {
- getLogger().error("page-number-citation must contain \"ref-id\"");
- return null;
- }
- PageViewport page = parentLM.resolveRefID(getRefId());
- InlineArea inline = null;
- if (page != null) {
- String str = page.getPageNumber();
- // get page string from parent, build area
- TextArea text = new TextArea();
- inline = text;
- int width = getStringWidth(str);
- text.setTextArea(str);
- inline.setIPD(width);
- inline.setHeight(getFontState().getAscender()
- - getFontState().getDescender());
- inline.setOffset(getFontState().getAscender());
-
- inline.addTrait(Trait.FONT_NAME, getFontState().getFontName());
- inline.addTrait(Trait.FONT_SIZE,
- new Integer(getFontState().getFontSize()));
- setUnresolved(false);
- } else {
- setUnresolved(true);
- inline = new UnresolvedPageNumber(getRefId());
- String str = "MMM"; // reserve three spaces for page number
- int width = getStringWidth(str);
- inline.setIPD(width);
- inline.setHeight(getFontState().getAscender()
- - getFontState().getDescender());
- inline.setOffset(getFontState().getAscender());
-
- inline.addTrait(Trait.FONT_NAME, getFontState().getFontName());
- inline.addTrait(Trait.FONT_SIZE,
- new Integer(getFontState().getFontSize()));
- }
- return inline;
- }
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
+ public String getName() {
+ return "fo:page-number-citation";
+ }
+
/**
* @see org.apache.fop.fo.FObj#getNameId()
*/
package org.apache.fop.fo.flow;
+// Java
+import java.util.List;
+
// XML
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
// FOP
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObjMixed;
-import org.apache.fop.layoutmgr.AddLMVisitor;
-import org.apache.fop.fo.LMVisited;
+import org.apache.fop.layoutmgr.RetrieveMarkerLayoutManager;
/**
* This will create a layout manager that will retrieve
* a marker based on the information.
*/
-public class RetrieveMarker extends FObjMixed implements LMVisited {
+public class RetrieveMarker extends FObjMixed {
private String retrieveClassName;
private int retrievePosition;
super(parent);
}
- /**
- * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
- * XSL Content Model: empty
- */
- protected void validateChildNode(Locator loc, String nsURI, String localName)
- throws SAXParseException {
- invalidChildError(loc, nsURI, localName);
- }
-
/**
* @see org.apache.fop.fo.FObj#addProperties
*/
this.propertyList.get(PR_RETRIEVE_BOUNDARY).getEnum();
}
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ * XSL Content Model: empty
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName)
+ throws SAXParseException {
+ invalidChildError(loc, nsURI, localName);
+ }
+
public String getRetrieveClassName() {
return retrieveClassName;
}
}
/**
- * This is a hook for the AddLMVisitor class to be able to access
- * this object.
- * @param aLMV the AddLMVisitor object that can access this object.
+ * @see org.apache.fop.fo.FObj#addLayoutManager(List)
*/
- public void acceptVisitor(AddLMVisitor aLMV) {
- aLMV.serveRetrieveMarker(this);
+ public void addLayoutManager(List list) {
+ RetrieveMarkerLayoutManager lm = new RetrieveMarkerLayoutManager(this);
+ list.add(lm);
}
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:retrieve-marker";
}
public int getNameId() {
return FO_RETRIEVE_MARKER;
}
-
}
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
-import org.apache.fop.fo.flow.RetrieveMarker;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.flow.TableAndCaption;
import org.apache.fop.fo.flow.TableBody;
return leaderArea;
}
- public void serveRetrieveMarker(RetrieveMarker node) {
- RetrieveMarkerLayoutManager rmlm;
- rmlm = new RetrieveMarkerLayoutManager(node);
- currentLMList.add(rmlm);
- }
-
public void serveCharacter(Character node) {
InlineArea inline = getCharacterInlineArea(node);
if (inline != null) {
--- /dev/null
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.fo.flow.PageNumberCitation;
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.Resolveable;
+import org.apache.fop.area.Trait;
+import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.area.inline.UnresolvedPageNumber;
+import org.apache.fop.area.inline.TextArea;
+import org.apache.fop.fonts.Font;
+
+/**
+ * LayoutManager for the fo:basic-link formatting object
+ */
+public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {
+
+ PageNumberCitation pncNode;
+ Font font = null;
+
+ /**
+ * Constructor
+ *
+ * @param node the formatting object that creates this area
+ * @todo better null checking of node, font
+ * @todo see if cleaner way to remove redundant pncNode variable (already
+ * being stored as an FObj in base class)
+ */
+ public PageNumberCitationLayoutManager(PageNumberCitation node) {
+ super(node);
+ font = node.getFontState();
+ pncNode = node;
+ }
+
+ public InlineArea get(LayoutContext context) {
+ curArea = getPageNumberCitationInlineArea(parentLM);
+ return curArea;
+ }
+
+ public void addAreas(PositionIterator posIter, LayoutContext context) {
+ super.addAreas(posIter, context);
+ if (pncNode.getUnresolved()) {
+ parentLM.addUnresolvedArea(pncNode.getRefId(),
+ (Resolveable) curArea);
+ }
+ }
+
+ protected void offsetArea(LayoutContext context) {
+ curArea.setOffset(context.getBaseline());
+ }
+
+ /**
+ * if id can be resolved then simply return a word, otherwise
+ * return a resolveable area
+ * @todo move ref-id validation check to the FO class' addProperties().
+ */
+ private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) {
+ if (pncNode.getRefId().equals("")) {
+ fobj.getLogger().error("page-number-citation must contain \"ref-id\"");
+ return null;
+ }
+ PageViewport page = parentLM.resolveRefID(pncNode.getRefId());
+ InlineArea inline = null;
+ if (page != null) {
+ String str = page.getPageNumber();
+ // get page string from parent, build area
+ TextArea text = new TextArea();
+ inline = text;
+ int width = getStringWidth(str);
+ text.setTextArea(str);
+ inline.setIPD(width);
+ inline.setHeight(font.getAscender() - font.getDescender());
+ inline.setOffset(font.getAscender());
+
+ inline.addTrait(Trait.FONT_NAME, font.getFontName());
+ inline.addTrait(Trait.FONT_SIZE,
+ new Integer(font.getFontSize()));
+ pncNode.setUnresolved(false);
+ } else {
+ pncNode.setUnresolved(true);
+ inline = new UnresolvedPageNumber(pncNode.getRefId());
+ String str = "MMM"; // reserve three spaces for page number
+ int width = getStringWidth(str);
+ inline.setIPD(width);
+ inline.setHeight(font.getAscender() - font.getDescender());
+ inline.setOffset(font.getAscender());
+
+ inline.addTrait(Trait.FONT_NAME, font.getFontName());
+ inline.addTrait(Trait.FONT_SIZE, new Integer(font.getFontSize()));
+ }
+ return inline;
+ }
+
+ /**
+ * @param str string to be measured
+ * @return width (in millipoints ??) of the string
+ */
+ private int getStringWidth(String str) {
+ int width = 0;
+ for (int count = 0; count < str.length(); count++) {
+ width += font.getCharWidth(str.charAt(count));
+ }
+ return width;
+ }
+}
+