From ec76b9b0671c3e5a3be1970186292fe2fd9a3d89 Mon Sep 17 00:00:00 2001 From: Luca Furini Date: Tue, 17 May 2005 14:38:16 +0000 Subject: [PATCH] Footnote implementation: new files git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198638 13f79535-47bb-0310-9956-ffa450edef68 --- .../layoutmgr/FootnoteBodyLayoutManager.java | 88 +++++++++++++ .../fop/layoutmgr/FootnoteLayoutManager.java | 124 ++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java create mode 100644 src/java/org/apache/fop/layoutmgr/FootnoteLayoutManager.java diff --git a/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java new file mode 100644 index 000000000..9ba98048e --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/FootnoteBodyLayoutManager.java @@ -0,0 +1,88 @@ +/* + * Copyright 1999-2005 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.area.Area; +import org.apache.fop.fo.flow.FootnoteBody; + +import java.util.LinkedList; + +public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager { + + public FootnoteBodyLayoutManager(FootnoteBody body) { + super(body); + } + + public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { + LayoutManager childLM = null; + LayoutManager lastLM = null; + LayoutContext lc = new LayoutContext(0); + + // "unwrap" the NonLeafPositions stored in parentIter + // and put them in a new list; + LinkedList positionList = new LinkedList(); + Position pos; + boolean bSpaceBefore = false; + boolean bSpaceAfter = false; + while (parentIter.hasNext()) { + pos = (Position) parentIter.next(); + //log.trace("pos = " + pos.getClass().getName() + "; " + pos); + Position innerPosition = pos; + if (pos instanceof NonLeafPosition) { + innerPosition = ((NonLeafPosition) pos).getPosition(); + if (innerPosition.getLM() == this) { + // pos was created by this LM and was inside a penalty + // allowing or forbidding a page break + // nothing to do + //log.trace(" penalty"); + } else { + // innerPosition was created by another LM + positionList.add(innerPosition); + lastLM = innerPosition.getLM(); + //log.trace(" " + innerPosition.getClass().getName()); + } + } + } + + // the Positions in positionList were inside the elements + // created by the LineLM + StackingIter childPosIter = new StackingIter(positionList.listIterator()); + + while ((childLM = childPosIter.getNextChildLM()) != null) { + // set last area flag + lc.setFlags(LayoutContext.LAST_AREA, + (layoutContext.isLastArea() && childLM == lastLM)); + // Add the line areas to Area + childLM.addAreas(childPosIter, lc); + } + } + + public void addChildArea(Area childArea) { + childArea.setAreaClass(Area.CLASS_FOOTNOTE); + parentLM.addChildArea(childArea); + } + + /** + * convenience method that returns the FootnoteBody node + */ + protected FootnoteBody getFootnodeBodyFO() { + return (FootnoteBody) fobj; + } + +} diff --git a/src/java/org/apache/fop/layoutmgr/FootnoteLayoutManager.java b/src/java/org/apache/fop/layoutmgr/FootnoteLayoutManager.java new file mode 100644 index 000000000..378560537 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/FootnoteLayoutManager.java @@ -0,0 +1,124 @@ +/* + * Copyright 1999-2005 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.LinkedList; +import java.util.List; +import java.util.ListIterator; + +import org.apache.fop.fo.flow.Footnote; + +public class FootnoteLayoutManager extends AbstractLayoutManager + implements InlineLevelLayoutManager { + + private Footnote footnote; + private InlineStackingLayoutManager citationLM; + private FootnoteBodyLayoutManager bodyLM; + + /** + * Create a new footnote layout manager. + * @param node footnote to create the layout manager for + */ + public FootnoteLayoutManager(Footnote node) { + super(node); + footnote = node; + + // create an InlineStackingLM handling the fo:inline child of fo:footnote + citationLM = new InlineStackingLayoutManager(footnote.getFootnoteCitation()); + + // create a FootnoteBodyLM handling the fo:footnote-body child of fo:footnote + bodyLM = new FootnoteBodyLayoutManager(footnote.getFootnoteBody()); + } + + public boolean generatesInlineAreas() { + return true; + } + + public LinkedList getNextKnuthElements(LayoutContext context, + int alignment) { + // this is the only method that must be implemented: + // all other methods will never be called, as the returned elements + // contain Positions created by the citationLM, so its methods will + // be called instead + + // set the citationLM parent to be this LM's parent + citationLM.setParent(getParent()); + bodyLM.setParent(this); + + // get Knuth elements representing the footnote citation + LinkedList returnedList = new LinkedList(); + while (!citationLM.isFinished()) { + LinkedList partialList = citationLM.getNextKnuthElements(context, alignment); + if (partialList != null) { + returnedList.addAll(partialList); + } + } + setFinished(true); + + addAnchor(returnedList); + + return returnedList; + } + + private void addAnchor(LinkedList citationList) { + // find the last box in the sequence, and add a reference + // to the FootnoteBodyLM + ListIterator citationIterator = citationList.listIterator(citationList.size()); + KnuthInlineBox lastBox = null; + while (citationIterator.hasPrevious() && lastBox == null) { + KnuthElement element = (KnuthElement) citationIterator.previous(); + if (element instanceof KnuthInlineBox) { + lastBox = (KnuthInlineBox) element; + } + } + if (lastBox != null) { + lastBox.setFootnoteBodyLM(bodyLM); + } + } + + public List addALetterSpaceTo(List oldList) { + log.warn("null implementation of addALetterSpaceTo() called!"); + return oldList; + } + + public void getWordChars(StringBuffer sbChars, Position pos) { + log.warn("null implementation of getWordChars() called!"); + } + + public void hyphenate(Position pos, HyphContext hc) { + log.warn("null implementation of hyphenate called!"); + } + + public boolean applyChanges(List oldList) { + log.warn("null implementation of applyChanges() called!"); + return false; + } + + public LinkedList getChangedKnuthElements(List oldList, + int alignment) { + log.warn("null implementation of getChangeKnuthElement() called!"); + return null; + } + + public int getWordSpaceIPD() { + log.warn("null implementation of getWordSpaceIPD() called!"); + return 0; + } + +} -- 2.39.5