From 20c03ca3c9b9a0492cc780292f01c64aa3098b36 Mon Sep 17 00:00:00 2001 From: arved Date: Mon, 16 Jul 2001 10:46:14 +0000 Subject: [PATCH] AHS: initial marker support git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194356 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/flow/Marker.java | 85 +++++++++--- .../apache/fop/fo/flow/RetrieveMarker.java | 121 +++++++++++++++--- .../fop/fo/pagination/PageSequence.java | 6 +- src/org/apache/fop/fo/pagination/Root.java | 1 + src/org/apache/fop/layout/Area.java | 32 ++++- src/org/apache/fop/layout/AreaClass.java | 31 +++++ src/org/apache/fop/layout/Page.java | 11 ++ 7 files changed, 243 insertions(+), 44 deletions(-) create mode 100644 src/org/apache/fop/layout/AreaClass.java diff --git a/src/org/apache/fop/fo/flow/Marker.java b/src/org/apache/fop/fo/flow/Marker.java index fc86e16be..627d98542 100644 --- a/src/org/apache/fop/fo/flow/Marker.java +++ b/src/org/apache/fop/fo/flow/Marker.java @@ -1,4 +1,5 @@ -/*-- $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. @@ -9,30 +10,74 @@ package org.apache.fop.fo.flow; // 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; + } } diff --git a/src/org/apache/fop/fo/flow/RetrieveMarker.java b/src/org/apache/fop/fo/flow/RetrieveMarker.java index 9f1f35369..c1e092eae 100644 --- a/src/org/apache/fop/fo/flow/RetrieveMarker.java +++ b/src/org/apache/fop/fo/flow/RetrieveMarker.java @@ -1,4 +1,5 @@ -/*-- $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. @@ -9,30 +10,110 @@ package org.apache.fop.fo.flow; // 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; + } } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index d24b988f5..6e5cd65e8 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -241,8 +241,6 @@ public class PageSequence extends FObj { 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) && @@ -265,6 +263,10 @@ public class PageSequence extends FObj { } } + + // because of markers, do after fo:flow + formatStaticContent(areaTree); + MessageHandler.log("]"); areaTree.addPage(currentPage); this.pageCount++; // used for 'force-page-count' calculations diff --git a/src/org/apache/fop/fo/pagination/Root.java b/src/org/apache/fop/fo/pagination/Root.java index 9d5a8b899..14192eed1 100644 --- a/src/org/apache/fop/fo/pagination/Root.java +++ b/src/org/apache/fop/fo/pagination/Root.java @@ -48,6 +48,7 @@ public class Root extends FObj { this.name = "fo:root"; pageSequences = new Vector(); + if (parent != null) { throw new FOPException("root must be root element"); } diff --git a/src/org/apache/fop/layout/Area.java b/src/org/apache/fop/layout/Area.java index 247a04878..fc10ebf06 100644 --- a/src/org/apache/fop/layout/Area.java +++ b/src/org/apache/fop/layout/Area.java @@ -8,9 +8,11 @@ package org.apache.fop.layout; // 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 { @@ -46,12 +48,29 @@ 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(); } /** @@ -64,10 +83,12 @@ abstract public class Area extends Box { * 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) { @@ -340,4 +361,11 @@ abstract public class Area extends Box { 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)); + } } diff --git a/src/org/apache/fop/layout/AreaClass.java b/src/org/apache/fop/layout/AreaClass.java new file mode 100644 index 000000000..764fd6cca --- /dev/null +++ b/src/org/apache/fop/layout/AreaClass.java @@ -0,0 +1,31 @@ +/* $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 + "'"); + } +} + diff --git a/src/org/apache/fop/layout/Page.java b/src/org/apache/fop/layout/Page.java index fe1d16332..73c5b1ce6 100644 --- a/src/org/apache/fop/layout/Page.java +++ b/src/org/apache/fop/layout/Page.java @@ -38,10 +38,13 @@ public class Page { 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) { @@ -172,4 +175,12 @@ public class Page { } footnotes.addElement(fb); } + + public void registerMarker(Marker marker) { + markers.addElement(marker); + } + + public Vector getMarkers() { + return this.markers; + } } -- 2.39.5