diff options
Diffstat (limited to 'src/java/org/apache/fop/layoutmgr')
11 files changed, 187 insertions, 21 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java index 2c593fd02..1af26cb4d 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockContainerLayoutManager.java @@ -837,6 +837,8 @@ public class BlockContainerLayoutManager extends BlockStackingLayoutManager viewportBlockArea = null; referenceArea = null; resetSpaces(); + + getPSLM().notifyEndOfLayout(((BlockContainer)getFObj()).getId()); } /** diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index a303f18fd..4e6d3750a 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -395,6 +395,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager curBlockArea = null; resetSpaces(); + + // Notify end of block layout manager to the PSLM + getPSLM().notifyEndOfLayout(getBlockFO().getId()); } /** diff --git a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java index 783c6a604..9a812e016 100644 --- a/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java +++ b/src/java/org/apache/fop/layoutmgr/LayoutManagerMapping.java @@ -15,6 +15,7 @@ */ /* $Id$ */ + package org.apache.fop.layoutmgr; import java.util.ArrayList; @@ -45,6 +46,7 @@ import org.apache.fop.fo.flow.ListBlock; import org.apache.fop.fo.flow.ListItem; import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.PageNumberCitationLast; import org.apache.fop.fo.flow.RetrieveMarker; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableBody; @@ -73,6 +75,7 @@ import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; import org.apache.fop.layoutmgr.inline.InstreamForeignObjectLM; import org.apache.fop.layoutmgr.inline.LeaderLayoutManager; import org.apache.fop.layoutmgr.inline.PageNumberCitationLayoutManager; +import org.apache.fop.layoutmgr.inline.PageNumberCitationLastLayoutManager; import org.apache.fop.layoutmgr.inline.PageNumberLayoutManager; import org.apache.fop.layoutmgr.inline.TextLayoutManager; import org.apache.fop.layoutmgr.inline.WrapperLayoutManager; @@ -123,6 +126,8 @@ public class LayoutManagerMapping implements LayoutManagerMaker { makers.put(PageNumber.class, new PageNumberLayoutManagerMaker()); makers.put(PageNumberCitation.class, new PageNumberCitationLayoutManagerMaker()); + makers.put(PageNumberCitationLast.class, + new PageNumberCitationLastLayoutManagerMaker()); makers.put(Table.class, new TableLayoutManagerMaker()); makers.put(TableBody.class, new Maker()); makers.put(TableColumn.class, new Maker()); @@ -349,6 +354,12 @@ public class LayoutManagerMapping implements LayoutManagerMaker { } } + public static class PageNumberCitationLastLayoutManagerMaker extends Maker { + public void make(FONode node, List lms) { + lms.add(new PageNumberCitationLastLayoutManager((PageNumberCitationLast) node)); + } + } + public static class TableLayoutManagerMaker extends Maker { public void make(FONode node, List lms) { Table table = (Table) node; diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java index a410e1838..9c1693a59 100644 --- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java @@ -142,7 +142,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { curPage = makeNewPage(false, false); - addIDToPage(pageSeq.getId()); + Flow mainFlow = pageSeq.getMainFlow(); childFLM = getLayoutManagerMaker(). makeFlowLayoutManager(this, mainFlow); @@ -158,6 +158,10 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { * Finished the page-sequence and notifies everyone about it. */ public void finishPageSequence() { + if (!pageSeq.getId().equals("")) { + areaTreeHandler.signalIDProcessed(pageSeq.getId()); + } + pageSeq.getRoot().notifyPageSequenceFinished(currentPageNum, (currentPageNum - startPageNum) + 1); areaTreeHandler.notifyPageSequenceFinished(pageSeq, @@ -165,6 +169,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { log.debug("Ending layout"); } + private class PageBreaker extends AbstractBreaker { private PageSequenceLayoutManager pslm; @@ -563,6 +568,21 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { } /** + * This returns the last PageViewport that contains an id trait + * matching the idref argument, or null if no such PV exists. + * + * @param idref the idref trait needing to be resolved + * @return the last PageViewport that contains the ID trait + */ + public PageViewport getLastPVWithID(String idref) { + List list = areaTreeHandler.getPageViewportsContainingID(idref); + if (list != null && list.size() > 0) { + return (PageViewport) list.get(list.size() - 1); + } + return null; + } + + /** * Add an ID reference to the current page. * When adding areas the area adds its ID reference. * For the page layout manager it adds the id reference @@ -575,7 +595,35 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { areaTreeHandler.associateIDWithPageViewport(id, curPage.getPageViewport()); } } - + + /** + * Add an id reference of the layout manager in the AreaTreeHandler, + * if the id hasn't been resolved yet + * @param id the id to track + * @return a boolean indicating if the id has already been resolved + * TODO Maybe give this a better name + */ + public boolean associateLayoutManagerID(String id) { + if (log.isDebugEnabled()) { + log.debug("associateLayoutManagerID(" + id + ")"); + } + if (!areaTreeHandler.alreadyResolvedID(id)) { + areaTreeHandler.signalPendingID(id); + return false; + } else { + return true; + } + } + + /** + * Notify the areaTreeHandler that the LayoutManagers containing + * idrefs have finished creating areas + * @param id the id for which layout has finished + */ + public void notifyEndOfLayout(String id) { + areaTreeHandler.signalIDProcessed(id); + } + /** * Identify an unresolved area (one needing an idref to be * resolved, e.g. the internal-destination of an fo:basic-link) @@ -669,6 +717,8 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager { log.debug("[" + curPage.getPageViewport().getPageNumberString() + (bIsBlank ? "*" : "") + "]"); } + + addIDToPage(pageSeq.getId()); return curPage; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java new file mode 100644 index 000000000..f55c00fec --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLastLayoutManager.java @@ -0,0 +1,83 @@ +/* + * Copyright 2006 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.inline; + +import org.apache.fop.fo.flow.PageNumberCitationLast; +import org.apache.fop.area.PageViewport; +import org.apache.fop.area.Resolvable; +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.LayoutContext; +import org.apache.fop.layoutmgr.LayoutManager; + +/** + * LayoutManager for the fo:page-number-citation-last formatting object + */ +public class PageNumberCitationLastLayoutManager extends PageNumberCitationLayoutManager { + + private PageNumberCitationLast fobj; + + /** + * Constructor + * + * @param node the formatting object that creates this area + * @todo better retrieval of font info + */ + public PageNumberCitationLastLayoutManager(PageNumberCitationLast node) { + super(node); + fobj = node; + } + + /** @see org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager#get(LayoutContext) */ + public InlineArea get(LayoutContext context) { + curArea = getPageNumberCitationLastInlineArea(parentLM); + return curArea; + } + + /** + * if id can be resolved then simply return a word, otherwise + * return a resolvable area + */ + private InlineArea getPageNumberCitationLastInlineArea(LayoutManager parentLM) { + TextArea text = null; + resolved = false; + if (!getPSLM().associateLayoutManagerID(fobj.getRefId())) { + text = new UnresolvedPageNumber(fobj.getRefId(), font, UnresolvedPageNumber.LAST); + getPSLM().addUnresolvedArea(fobj.getRefId(), (Resolvable)text); + String str = "MMM"; // reserve three spaces for page number + int width = getStringWidth(str); + text.setIPD(width); + } else { + PageViewport page = getPSLM().getLastPVWithID(fobj.getRefId()); + String str = page.getPageNumberString(); + // get page string from parent, build area + text = new TextArea(); + int width = getStringWidth(str); + text.addWord(str, 0); + text.setIPD(width); + + resolved = true; + } + + updateTextAreaTraits(text); + + return text; + } +} diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java index 79c2d487d..729e9c939 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberCitationLayoutManager.java @@ -37,10 +37,11 @@ import org.apache.fop.layoutmgr.TraitSetter; public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { private PageNumberCitation fobj; - private Font font; + /** Font for the page-number-citation */ + protected Font font; - // whether the page referred to by the citation has been resolved yet - private boolean resolved = false; + /** Indicates whether the page referred to by the citation has been resolved yet */ + protected boolean resolved = false; /** * Constructor @@ -97,40 +98,45 @@ public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager { */ private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) { PageViewport page = getPSLM().getFirstPVWithID(fobj.getRefId()); - TextArea inline = null; + TextArea text = null; if (page != null) { String str = page.getPageNumberString(); // get page string from parent, build area - TextArea text = new TextArea(); - inline = text; + text = new TextArea(); int width = getStringWidth(str); text.addWord(str, 0); - inline.setIPD(width); - + text.setIPD(width); resolved = true; } else { resolved = false; - inline = new UnresolvedPageNumber(fobj.getRefId(), font); + text = new UnresolvedPageNumber(fobj.getRefId(), font); String str = "MMM"; // reserve three spaces for page number int width = getStringWidth(str); - inline.setIPD(width); - + text.setIPD(width); } - TraitSetter.setProducerID(inline, fobj.getId()); - inline.setBPD(font.getAscender() - font.getDescender()); - inline.setBaselineOffset(font.getAscender()); - TraitSetter.addFontTraits(inline, font); - inline.addTrait(Trait.COLOR, fobj.getColor()); - TraitSetter.addTextDecoration(inline, fobj.getTextDecoration()); + updateTextAreaTraits(text); - return inline; + return text; + } + + /** + * Updates the traits for the generated text area. + * @param text the text area + */ + protected void updateTextAreaTraits(TextArea text) { + TraitSetter.setProducerID(text, fobj.getId()); + text.setBPD(font.getAscender() - font.getDescender()); + text.setBaselineOffset(font.getAscender()); + TraitSetter.addFontTraits(text, font); + text.addTrait(Trait.COLOR, fobj.getColor()); + TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); } /** * @param str string to be measured * @return width (in millipoints ??) of the string */ - private int getStringWidth(String str) { + protected int getStringWidth(String str) { int width = 0; for (int count = 0; count < str.length(); count++) { width += font.getCharWidth(str.charAt(count)); diff --git a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java index e23639e0d..5704ae99d 100644 --- a/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/list/ListBlockLayoutManager.java @@ -207,6 +207,8 @@ public class ListBlockLayoutManager extends BlockStackingLayoutManager curBlockArea = null; resetSpaces(); + + getPSLM().notifyEndOfLayout(((ListBlock)getFObj()).getId()); } /** diff --git a/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java index 23ba4dd52..d894a0aeb 100644 --- a/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/list/ListItemContentLayoutManager.java @@ -171,6 +171,8 @@ public class ListItemContentLayoutManager extends BlockStackingLayoutManager { flush(); curBlockArea = null; + + getPSLM().notifyEndOfLayout(((AbstractListItemPart)getFObj()).getId()); } /** diff --git a/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java b/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java index d9bbd18f6..7f3794bb6 100644 --- a/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/list/ListItemLayoutManager.java @@ -535,6 +535,8 @@ public class ListItemLayoutManager extends BlockStackingLayoutManager curBlockArea = null; resetSpaces(); + + getPSLM().notifyEndOfLayout(((ListItem)getFObj()).getId()); } /** diff --git a/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java index 8ec1b8e16..61d2d3701 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java @@ -252,6 +252,8 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager //Space resolution SpaceResolver.resolveElementList(returnList); + getPSLM().notifyEndOfLayout(((TableCell)getFObj()).getId()); + setFinished(true); return returnList; } diff --git a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java index 83ac2a937..a50cf1317 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableLayoutManager.java @@ -20,6 +20,7 @@ package org.apache.fop.layoutmgr.table; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.flow.Table; +import org.apache.fop.fo.flow.TableFObj; import org.apache.fop.fo.flow.TableColumn; import org.apache.fop.fo.properties.TableColLength; import org.apache.fop.layoutmgr.BlockLevelLayoutManager; @@ -376,6 +377,8 @@ public class TableLayoutManager extends BlockStackingLayoutManager resetSpaces(); curBlockArea = null; + + getPSLM().notifyEndOfLayout(((Table)getFObj()).getId()); } /** |