diff options
Diffstat (limited to 'src/java/org/apache/fop/layoutmgr')
6 files changed, 492 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 09edee56f..84f5a90d1 100644 --- a/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -23,6 +23,7 @@ import org.apache.fop.fo.FONode; import org.apache.fop.area.Area; import org.apache.fop.area.Resolvable; import org.apache.fop.area.PageViewport; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.RetrieveMarker; import org.apache.fop.fo.flow.Marker; @@ -360,6 +361,16 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants } /** + * Delegate getAreaTreeHandler to the parent layout manager. + * + * @see org.apache.fop.layoutmgr.LayoutManager + * @return the AreaTreeHandler object. + */ + public AreaTreeHandler getAreaTreeHandler() { + return parentLM.getAreaTreeHandler(); + } + + /** * Convenience method: preload a number of child LMs * @param size the requested number of child LMs * @return the list with the preloaded child LMs @@ -384,7 +395,8 @@ public abstract class AbstractLayoutManager implements LayoutManager, Constants rm.bindMarker(marker); foNode = rm; } - foNode.addLayoutManager(newLMs); + getAreaTreeHandler().getLayoutManagerMaker(). + makeLayoutManagers(foNode, newLMs); } } return newLMs; diff --git a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java index adc25fd74..79c1ab6d7 100644 --- a/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/ContentLayoutManager.java @@ -23,6 +23,7 @@ import org.apache.fop.fo.FObj; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.Marker; import org.apache.fop.area.Area; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.Resolvable; import org.apache.fop.area.PageViewport; @@ -44,6 +45,7 @@ import org.apache.commons.logging.LogFactory; */ public class ContentLayoutManager implements InlineLevelLayoutManager { private FOUserAgent userAgent; + private AreaTreeHandler areaTreeHandler; private Area holder; private int stackSize; private LayoutManager parentLM; @@ -257,6 +259,31 @@ public class ContentLayoutManager implements InlineLevelLayoutManager { } /** + * Set the AreaTreeHandler. + * This is used by the PageSequenceLM for the Title, + * because it does not set itself as the parentLM. + * @param areaTreeHandler the area tree handler to add pages to + */ + public void setAreaTreeHandler(AreaTreeHandler areaTreeHandler) { + this.areaTreeHandler = areaTreeHandler; + } + + /** + * Either areaTreeHandler or parentLM should not be null. + * If areaTreeHandler is null, + * delegate getAreaTreeHandler to the parent layout manager. + * + * @see org.apache.fop.layoutmgr.LayoutManager + * @return the AreaTreeHandler object. + */ + public AreaTreeHandler getAreaTreeHandler() { + if (areaTreeHandler == null) { + areaTreeHandler = parentLM.getAreaTreeHandler(); + } + return areaTreeHandler; + } + + /** * @see org.apache.fop.layoutmgr.LayoutManager#preLoadNext */ public boolean preLoadNext(int pos) { diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManager.java b/src/java/org/apache/fop/layoutmgr/LayoutManager.java index bdc25e605..6291a058b 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManager.java @@ -26,6 +26,7 @@ import org.apache.fop.fo.flow.Marker; import org.apache.fop.area.Area; import org.apache.fop.area.Resolvable; import org.apache.fop.area.PageViewport; +import org.apache.fop.area.AreaTreeHandler; import org.apache.fop.fo.FObj; /** @@ -212,6 +213,11 @@ public interface LayoutManager { Marker retrieveMarker(String name, int pos, int boundary); /** + * @return the AreaTreeHandler object. + */ + AreaTreeHandler getAreaTreeHandler(); + + /** * Load next child LMs, up to child LM index pos * @param pos index up to which child LMs are requested * @return if requested index does exist diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java new file mode 100644 index 000000000..4da081c08 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMaker.java @@ -0,0 +1,32 @@ +/* + * Copyright 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 java.util.List; +import org.apache.fop.fo.FONode; + +public interface LayoutManagerMaker { + + public void makeLayoutManagers(FONode node, List lms); + + public LayoutManager makeLayoutManager(FONode node); + + public LayoutManager makeLayoutManager(FONode node, boolean checkLength); + +} + diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java new file mode 100644 index 000000000..40dd6d93a --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java @@ -0,0 +1,387 @@ +/* + * Copyright 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.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Iterator; + +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.FObj; +import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.XMLObj; +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.fo.flow.BidiOverride; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.InlineLevel; +import org.apache.fop.fo.flow.InlineContainer; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.RetrieveMarker; +import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableBody; +import org.apache.fop.fo.flow.TableCell; +import org.apache.fop.fo.flow.TableColumn; +import org.apache.fop.fo.flow.TableFooter; +import org.apache.fop.fo.flow.TableHeader; +import org.apache.fop.fo.flow.TableRow; +import org.apache.fop.fo.flow.Wrapper; +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.fo.pagination.Title; + +import org.apache.fop.layoutmgr.list.Item; +import org.apache.fop.layoutmgr.list.ListBlockLayoutManager; +import org.apache.fop.layoutmgr.list.ListItemLayoutManager; +import org.apache.fop.layoutmgr.table.Body; +import org.apache.fop.layoutmgr.table.Cell; +import org.apache.fop.layoutmgr.table.Column; +import org.apache.fop.layoutmgr.table.Row; +import org.apache.fop.layoutmgr.table.TableLayoutManager; + +/** + * The default class for creating layout managers. + */ +public class LayoutManagerMapping implements LayoutManagerMaker { + + /** logging instance */ + protected static Log log = LogFactory.getLog(LayoutManagerMapping.class); + + /** The map of LayoutManagerMakers */ + private Map makers = new HashMap(); + + public LayoutManagerMapping() { + initialize(); + } + + /** + * Initializes the set of maker objects associated with this LayoutManagerMapping + */ + private void initialize() { + makers.put(FOText.class, new FOTextLayoutManagerMaker()); + makers.put(FObjMixed.class, new Maker()); + makers.put(BidiOverride.class, new BidiOverrideLayoutManagerMaker()); + makers.put(Inline.class, new InlineLayoutManagerMaker()); + makers.put(Footnote.class, new FootnodeLayoutManagerMaker()); + makers.put(InlineContainer.class, + new InlineContainerLayoutManagerMaker()); + makers.put(BasicLink.class, new BasicLinkLayoutManagerMaker()); + makers.put(Block.class, new BlockLayoutManagerMaker()); + makers.put(Leader.class, new LeaderLayoutManagerMaker()); + makers.put(RetrieveMarker.class, new WrapperLayoutManagerMaker()); + makers.put(Character.class, new CharacterLayoutManagerMaker()); + makers.put(ExternalGraphic.class, + new ExternalGraphicLayoutManagerMaker()); + makers.put(BlockContainer.class, + new BlockContainerLayoutManagerMaker()); + makers.put(ListItem.class, new ListItemLayoutManagerMaker()); + makers.put(ListBlock.class, new ListBlockLayoutManagerMaker()); + makers.put(InstreamForeignObject.class, + new InstreamForeignObjectLayoutManagerMaker()); + makers.put(PageNumber.class, new PageNumberLayoutManagerMaker()); + makers.put(PageNumberCitation.class, + new PageNumberCitationLayoutManagerMaker()); + makers.put(PageSequence.class, new PageSequenceLayoutManagerMaker()); + makers.put(Table.class, new TableLayoutManagerMaker()); + makers.put(TableBody.class, new TableBodyLayoutManagerMaker()); + makers.put(TableColumn.class, new TableColumnLayoutManagerMaker()); + makers.put(TableRow.class, new TableRowLayoutManagerMaker()); + makers.put(TableCell.class, new TableCellLayoutManagerMaker()); + makers.put(TableFooter.class, new TableBodyLayoutManagerMaker()); + makers.put(TableHeader.class, new TableBodyLayoutManagerMaker()); + makers.put(Flow.class, new FlowLayoutManagerMaker()); + makers.put(StaticContent.class, new StaticContentLayoutManagerMaker()); + makers.put(Wrapper.class, new WrapperLayoutManagerMaker()); + makers.put(Title.class, new InlineLayoutManagerMaker()); + } + + public void makeLayoutManagers(FONode node, List lms) { + Maker maker = (Maker) makers.get(node.getClass()); + if (maker == null) { + log.error("No LayoutManager maker for class " + node.getClass()); + } else { + maker.make(node, lms); + } + } + + public LayoutManager makeLayoutManager(FONode node) { + return makeLayoutManager(node, false); + } + + public LayoutManager makeLayoutManager(FONode node, boolean checkLength) { + List lms = new ArrayList(); + makeLayoutManagers(node, lms); + LayoutManager lm = null; + if (checkLength && lms.size() != 1) { + log.error("More than 1 LayoutManager for class " + + node.getClass() + + "; 1 was requested"); + } else if (lms.size() != 0) { + lm = (LayoutManager) lms.get(0); + } + return lm; + } + + public static class Maker { + public void make(FONode node, List lms) { + // no layout manager + return; + } + } + + public static class FOTextLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + FOText foText = (FOText) node; + if (foText.endIndex - foText.startIndex > 0) { + lms.add(new TextLayoutManager(foText)); + } + } + } + + /* + public static class FObjMixedLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + if (node.getChildNodes() != null) { + InlineStackingLayoutManager lm; + lm = new InlineStackingLayoutManager((FObjMixed) node); + lms.add(lm); + } + } + } + */ + + public static class BidiOverrideLayoutManagerMaker extends Maker { + // public static class BidiOverrideLayoutManagerMaker extends FObjMixedLayoutManagerMaker { + public void make(BidiOverride node, List lms) { + if (false) { + // this is broken; it does nothing + // it should make something like an InlineStackingLM + super.make(node, lms); + } else { + ArrayList childList = new ArrayList(); + // this is broken; it does nothing + // it should make something like an InlineStackingLM + super.make(node, childList); + for (int count = childList.size() - 1; count >= 0; count--) { + LayoutManager lm = (LayoutManager) childList.get(count); + if (lm.generatesInlineAreas()) { + LayoutManager blm = new BidiLayoutManager + (node, (InlineLayoutManager) lm); + lms.add(blm); + } else { + lms.add(lm); + } + } + } + } + } + + public static class InlineLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + if (node.getChildNodes() != null) { + lms.add(new InlineLayoutManager((InlineLevel) node)); + } + } + } + + public static class FootnodeLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + Inline citation = ((Footnote) node).getInlineFO(); + if (citation != null) { + lms.add(new InlineLayoutManager(citation)); + } + } + } + + public static class InlineContainerLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + ArrayList childList = new ArrayList(); + super.make(node, childList); + lms.add(new ICLayoutManager((InlineContainer) node, childList)); + } + } + + public static class BasicLinkLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new BasicLinkLayoutManager((BasicLink) node)); + } + } + + public static class BlockLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new BlockLayoutManager((Block) node)); + } + } + + public static class LeaderLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new LeaderLayoutManager((Leader) node)); + } + } + + public static class CharacterLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new CharacterLayoutManager((Character) node)); + } + } + + public static class ExternalGraphicLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + ExternalGraphic eg = (ExternalGraphic) node; + if (!eg.getSrc().equals("")) { + lms.add(new ExternalGraphicLayoutManager(eg)); + } + } + } + + public static class BlockContainerLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new BlockContainerLayoutManager((BlockContainer) node)); + } + } + + public static class ListItemLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new ListItemLayoutManager((ListItem) node)); + } + } + + public static class ListBlockLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new ListBlockLayoutManager((ListBlock) node)); + } + } + + public static class InstreamForeignObjectLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new InstreamForeignObjectLM((InstreamForeignObject) node)); + } + } + + public static class PageNumberLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new PageNumberLayoutManager((PageNumber) node)); + } + } + + public static class PageNumberCitationLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new PageNumberCitationLayoutManager((PageNumberCitation) node)); + } + } + + public static class PageSequenceLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new PageSequenceLayoutManager((PageSequence) node)); + } + } + + public static class TableLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + Table table = (Table) node; + TableLayoutManager tlm = new TableLayoutManager(table); + ArrayList columns = table.getColumns(); + if (columns != null) { + ArrayList columnLMs = new ArrayList(); + ListIterator iter = columns.listIterator(); + while (iter.hasNext()) { + columnLMs.add(new Column((TableColumn) node)); + } + tlm.setColumns(columnLMs); + } + if (table.getTableHeader() != null) { + tlm.setTableHeader(new Body(table.getTableHeader())); + } + if (table.getTableFooter() != null) { + tlm.setTableFooter(new Body(table.getTableFooter())); + } + lms.add(tlm); + } + } + + public static class TableBodyLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new Body((TableBody) node)); + } + + } + + public static class TableColumnLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new Column((TableColumn) node)); + } + } + + public static class TableRowLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new Row((TableRow) node)); + } + } + + public static class TableCellLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new Cell((TableCell) node)); + } + } + + public static class FlowLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new FlowLayoutManager((Flow) node)); + } + } + + public static class StaticContentLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new StaticContentLayoutManager((StaticContent) node)); + } + } + + public class WrapperLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + Iterator baseIter; + baseIter = node.getChildNodes(); + if (baseIter == null) { + return; + } + while (baseIter.hasNext()) { + FONode child = (FONode) baseIter.next(); + makeLayoutManagers(child, lms); + } + } + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index 74ceb0745..2d5515e08 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -128,20 +128,35 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { * This is the top level layout manager. * It is created by the PageSequence FO. * - * @param areaTree the area tree to add pages to * @param pageseq the page sequence fo */ - public PageSequenceLayoutManager(AreaTreeHandler areaTreeHandler, PageSequence pageseq) { + public PageSequenceLayoutManager(PageSequence pageseq) { super(pageseq); fobj = pageseq; - this.areaTreeHandler = areaTreeHandler; - areaTreeModel = areaTreeHandler.getAreaTreeModel(); if (fobj.getPageSequenceMaster() != null) { fobj.getPageSequenceMaster().reset(); } } /** + * Set the AreaTreeHandler + * @param areaTreeHandler the area tree handler to add pages to + */ + public void setAreaTreeHandler(AreaTreeHandler areaTreeHandler) { + this.areaTreeHandler = areaTreeHandler; + areaTreeModel = areaTreeHandler.getAreaTreeModel(); + } + + /** + * @see org.apache.fop.layoutmgr.LayoutManager + * @return the AreaTreeHandler object + */ + public AreaTreeHandler getAreaTreeHandler() { + return areaTreeHandler; + } + + + /** * Set the page counting for this page sequence. * This sets the initial page number and the page number formatter. * @@ -174,6 +189,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { ContentLayoutManager clm = new ContentLayoutManager(title); clm.setUserAgent(foTitle.getUserAgent()); + clm.setAreaTreeHandler(areaTreeHandler); // use special layout manager to add the inline areas // to the Title. @@ -891,12 +907,14 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { */ private StaticContentLayoutManager getStaticContentLayoutManager(StaticContent sc) { StaticContentLayoutManager lm = - (StaticContentLayoutManager)staticContentLMs.get(sc.getFlowName()); - if (lm != null) { - return lm; + (StaticContentLayoutManager) + staticContentLMs.get(sc.getFlowName()); + if (lm == null) { + lm = (StaticContentLayoutManager) + getAreaTreeHandler().getLayoutManagerMaker(). + makeLayoutManager(sc); + staticContentLMs.put(sc.getFlowName(), lm); } - lm = new StaticContentLayoutManager(sc); - staticContentLMs.put(sc.getFlowName(), lm); return lm; } } |