-/*-- $Id$ --
+/*-- $Id$-- */
+/*
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.fo.flow.*;
import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.AreaTree;
+import org.apache.fop.layout.*;
+import org.apache.fop.datatypes.*;
import org.apache.fop.apps.FOPException;
-/**
- */
-public class Marker extends ToBeImplementedElement {
+public class Marker extends FObjMixed {
+
+ private String markerClassName;
+ private Area registryArea;
+
+ public static class Maker extends FObj.Maker {
+ public FObj make(FObj parent, PropertyList propertyList) throws FOPException {
+ return new Marker(parent, propertyList);
+ }
+ }
+
+ public static FObj.Maker maker() {
+ return new Marker.Maker();
+ }
- public static class Maker extends FObj.Maker {
- public FObj make(FObj parent,
- PropertyList propertyList) throws FOPException {
- return new Marker(parent, propertyList);
- }
- }
+ public Marker(FObj parent, PropertyList propertyList) {
+ super(parent, propertyList);
+ this.name = "fo:marker";
+
+ // do check to see that 'this' is under fo:flow
+
+ this.markerClassName = this.properties.get("marker-class-name").getString();
+
+ // check to ensure that no other marker with same parent
+ // has this 'marker-class-name' is in addMarker() method
+ try {
+ parent.addMarker(this);
+ } catch (FOPException fopex) {
+ MessageHandler.error("marker cannot be added to '" + parent + "'");
+ }
+ }
- public static FObj.Maker maker() {
- return new Marker.Maker();
- }
+ public Status layout(Area area) throws FOPException {
+ // no layout action desired
+ this.registryArea = area;
+ area.getPage().registerMarker(this);
+ // System.out.println("Marker being registered in area '" + area + "'");
+ return new Status(Status.OK);
+ }
- protected Marker(FObj parent,
- PropertyList propertyList) throws FOPException {
- super(parent, propertyList);
- this.name = "fo:marker";
- }
+ public Status layoutMarker(Area area) throws FOPException {
+ if (this.marker == START)
+ this.marker = 0;
+
+ int numChildren = this.children.size();
+ for (int i = this.marker; i < numChildren; i++) {
+ FONode fo = (FONode) children.elementAt(i);
+
+ Status status;
+ if ((status = fo.layout(area)).isIncomplete()) {
+ this.marker = i;
+ return status;
+ }
+ }
+
+ return new Status(Status.OK);
+ }
+ public String getMarkerClassName() {
+ return markerClassName;
+ }
+
+ public Area getRegistryArea() {
+ return registryArea;
+ }
}
-/*-- $Id$ --
+/*-- $Id$-- */
+/*
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.messaging.MessageHandler;
-import org.apache.fop.fo.flow.*;
import org.apache.fop.fo.properties.*;
-import org.apache.fop.layout.AreaTree;
+import org.apache.fop.layout.*;
+import org.apache.fop.datatypes.*;
import org.apache.fop.apps.FOPException;
-/**
- */
-public class RetrieveMarker extends ToBeImplementedElement {
+// Java
+import java.util.Vector;
+
+public class RetrieveMarker extends FObjMixed {
- public static class Maker extends FObj.Maker {
- public FObj make(FObj parent,
- PropertyList propertyList) throws FOPException {
- return new RetrieveMarker(parent, propertyList);
- }
- }
+ private String retrieveClassName;
+ private int retrievePosition;
+ private int retrieveBoundary;
+
+ public static class Maker extends FObj.Maker {
+ public FObj make(FObj parent, PropertyList propertyList) throws FOPException {
+ return new RetrieveMarker(parent, propertyList);
+ }
+ }
- public static FObj.Maker maker() {
- return new RetrieveMarker.Maker();
- }
+ public static FObj.Maker maker() {
+ return new RetrieveMarker.Maker();
+ }
- protected RetrieveMarker(FObj parent,
- PropertyList propertyList) throws FOPException {
- super(parent, propertyList);
- this.name = "fo:retrieve-marker";
- }
+ public RetrieveMarker(FObj parent, PropertyList propertyList) {
+ super(parent, propertyList);
+ this.name = "fo:retrieve-marker";
+
+ this.retrieveClassName = this.properties.get("retrieve-class-name").getString();
+ this.retrievePosition = this.properties.get("retrieve-position").getEnum();
+ this.retrieveBoundary = this.properties.get("retrieve-boundary").getEnum();
+ }
+ public Status layout(Area area) throws FOPException {
+ // locate qualifying areas by 'marker-class-name' and
+ // 'retrieve-boundary'. Initially we will always check
+ // the containing page
+ Page containingPage = area.getPage();
+ Marker bestMarker = searchPage(containingPage);
+
+ // if marker not yet found, and 'retrieve-boundary' permits,
+ // search forward by Page
+ /* insert code for searching forward by Page, if allowed */
+
+ Status status = new Status(Status.AREA_FULL_NONE);
+ if (null != bestMarker) {
+ // System.out.println("Laying out marker in area '" + area + "'");
+ status = bestMarker.layoutMarker(area);
+ }
+
+ return status;
+ }
+
+ private Marker searchPage(Page page) throws FOPException {
+ Vector pageMarkers = page.getMarkers();
+ if (pageMarkers.isEmpty())
+ return null;
+
+ // search forward if 'first-starting-within-page' or
+ // 'first-including-carryover'
+ Marker fallback = null;
+ if (retrievePosition == RetrievePosition.FIC) {
+ for (int c = 0; c < pageMarkers.size(); c++) {
+ Marker currentMarker = (Marker)pageMarkers.elementAt(c);
+ if (currentMarker.getMarkerClassName().equals(retrieveClassName))
+ return currentMarker;
+ }
+
+ } else if (retrievePosition == RetrievePosition.FSWP) {
+ for (int c = 0; c < pageMarkers.size(); c++) {
+ Marker currentMarker = (Marker)pageMarkers.elementAt(c);
+ if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+ if (currentMarker.getRegistryArea().isFirst)
+ return currentMarker;
+ else if (null == fallback)
+ fallback = currentMarker;
+ }
+ }
+
+ } else if (retrievePosition == RetrievePosition.LSWP) {
+ for (int c = pageMarkers.size(); c > 0; c--) {
+ Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
+ if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+ if (currentMarker.getRegistryArea().isFirst)
+ return currentMarker;
+ else if (null == fallback)
+ fallback = currentMarker;
+ }
+ }
+
+ } else if (retrievePosition == RetrievePosition.LEWP) {
+ for (int c = pageMarkers.size(); c > 0; c--) {
+ Marker currentMarker = (Marker)pageMarkers.elementAt(c-1);
+ if (currentMarker.getMarkerClassName().equals(retrieveClassName)) {
+ if (currentMarker.getRegistryArea().isLast)
+ return currentMarker;
+ else if (null == fallback)
+ fallback = currentMarker;
+ }
+ }
+
+ } else {
+ throw new FOPException("Illegal 'retrieve-position' value");
+ }
+ return fallback;
+ }
}
MessageHandler.log(" [" + currentPageNumber);
- formatStaticContent(areaTree);
-
if ((status.getCode() == Status.FORCE_PAGE_BREAK_EVEN) &&
((currentPageNumber % 2) == 1)) {
} else if ( (status.getCode() == Status.FORCE_PAGE_BREAK_ODD) &&
}
}
+
+ // because of markers, do after fo:flow
+ formatStaticContent(areaTree);
+
MessageHandler.log("]");
areaTree.addPage(currentPage);
this.pageCount++; // used for 'force-page-count' calculations
this.name = "fo:root";
pageSequences = new Vector();
+
if (parent != null) {
throw new FOPException("root must be root element");
}
// FOP
import org.apache.fop.datatypes.*;
+import org.apache.fop.fo.flow.Marker;
// Java
import java.util.Vector;
+import java.util.Hashtable;
abstract public class Area extends Box {
private IDReferences idReferences;
+ protected Vector markers;
+
+ // as defined in Section 6.1.1
+ public org.apache.fop.fo.FObj generatedBy; // corresponds to 'generated-by' trait
+ protected Hashtable returnedBy;
+
+ // as defined in Section 6.1.1
+ protected String areaClass;
+
+ // as defined in Section 4.2.2
+ public boolean isFirst = false;
+ public boolean isLast = false;
+
/* author : Seshadri G
** the fo which created it */
+ // This is deprecated and should be phased out in
+ // favour of using 'generatedBy'
public org.apache.fop.fo.FObj foCreator;
public Area (FontState fontState) {
- setFontState(fontState);
+ setFontState(fontState);
+ this.markers = new Vector();
+ this.returnedBy = new Hashtable();
}
/**
* for this Area (its allocation rectangle)
*/
public Area (FontState fontState, int allocationWidth, int maxHeight) {
- setFontState(fontState);
+ setFontState(fontState);
this.allocationWidth = allocationWidth;
this.contentRectangleWidth = allocationWidth;
this.maxHeight = maxHeight;
+ this.markers = new Vector();
+ this.returnedBy = new Hashtable();
}
private void setFontState(FontState fontState) {
return bp;
}
+ public void addMarkers(Vector markers) {
+ markers.addAll(markers);
+ }
+
+ public void addLineagePair(org.apache.fop.fo.FObj fo, int areaPosition) {
+ returnedBy.put(fo, new Integer(areaPosition));
+ }
}
--- /dev/null
+/* $Id$
+ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * For details on use and redistribution please refer to the
+ * LICENSE file included with these sources.
+ */
+
+package org.apache.fop.layout;
+
+import org.apache.fop.apps.FOPException;
+
+public class AreaClass {
+ public static String UNASSIGNED = "unassigned";
+
+ public static String XSL_NORMAL = "xsl-normal";
+ public static String XSL_ABSOLUTE = "xsl-absolute";
+ public static String XSL_FOOTNOTE = "xsl-footnote";
+ public static String XSL_SIDE_FLOAT = "xsl-side-float";
+ public static String XSL_BEFORE_FLOAT = "xsl-before-float";
+
+ // checker method
+ public static String setAreaClass(String areaClass)
+ throws FOPException {
+ if (areaClass.equals(XSL_NORMAL) || areaClass.equals(XSL_ABSOLUTE) ||
+ areaClass.equals(XSL_FOOTNOTE) || areaClass.equals(XSL_SIDE_FLOAT) ||
+ areaClass.equals(XSL_BEFORE_FLOAT))
+ return areaClass;
+ else
+ throw new FOPException("Unknown area class '" + areaClass + "'");
+ }
+}
+
private Vector footnotes = null;
+ private Vector markers = null;
+
Page(AreaTree areaTree, int height, int width) {
this.areaTree = areaTree;
this.height = height;
this.width = width;
+ markers = new Vector();
}
public void setNumber(int number) {
}
footnotes.addElement(fb);
}
+
+ public void registerMarker(Marker marker) {
+ markers.addElement(marker);
+ }
+
+ public Vector getMarkers() {
+ return this.markers;
+ }
}