From: Glen Mazza Date: Sun, 8 Aug 2004 17:52:35 +0000 (+0000) Subject: Moved fo:page-number layout code from AddLMVisitor to new PageNumberLayoutManager... X-Git-Tag: Root_Temp_KnuthStylePageBreaking~629 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0b09e52cd836a838e3140ef8113532d3033433a1;p=xmlgraphics-fop.git Moved fo:page-number layout code from AddLMVisitor to new PageNumberLayoutManager class. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197860 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index bc7f065b6..678c77205 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -18,6 +18,9 @@ package org.apache.fop.fo.flow; +// Java +import java.util.List; + // XML import org.xml.sax.Attributes; import org.xml.sax.Locator; @@ -26,23 +29,15 @@ import org.xml.sax.SAXParseException; // FOP import org.apache.fop.datatypes.ColorType; import org.apache.fop.fo.FONode; -import org.apache.fop.layoutmgr.AddLMVisitor; import org.apache.fop.fo.FObj; -import org.apache.fop.fo.properties.CommonAccessibility; -import org.apache.fop.fo.properties.CommonAural; -import org.apache.fop.fo.properties.CommonBackground; -import org.apache.fop.fo.properties.CommonBorderAndPadding; -import org.apache.fop.fo.properties.CommonMarginInline; -import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.fonts.Font; -import org.apache.fop.fo.LMVisited; - +import org.apache.fop.layoutmgr.PageNumberLayoutManager; /** * Class modelling the fo:page-number object. See Sec. 6.6.10 of the XSL-FO * Standard. */ -public class PageNumber extends FObj implements LMVisited { +public class PageNumber extends FObj { /** FontState for this object */ protected Font fontState; @@ -77,42 +72,10 @@ public class PageNumber extends FObj implements LMVisited { } private void setup() { - - // Common Accessibility Properties - CommonAccessibility mAccProps = propMgr.getAccessibilityProps(); - - // Common Aural Properties - CommonAural mAurProps = propMgr.getAuralProps(); - - // Common Border, Padding, and Background Properties - CommonBorderAndPadding bap = propMgr.getBorderAndPadding(); - CommonBackground bProps = propMgr.getBackgroundProps(); - // Common Font Properties this.fontState = propMgr.getFontState(getFOInputHandler().getFontInfo()); - // Common Margin Properties-Inline - CommonMarginInline mProps = propMgr.getMarginInlineProps(); - - // Common Relative Position Properties - CommonRelativePosition mRelProps = - propMgr.getRelativePositionProps(); - - // this.propertyList.get("alignment-adjust"); - // this.propertyList.get("alignment-baseline"); - // this.propertyList.get("baseline-shift"); - // this.propertyList.get("dominant-baseline"); setupID(); - // this.propertyList.get("keep-with-next"); - // this.propertyList.get("keep-with-previous"); - // this.propertyList.get("letter-spacing"); - // this.propertyList.get("line-height"); - // this.propertyList.get("line-height-shift-adjustment"); - // this.propertyList.get("score-spaces"); - // this.propertyList.get("text-decoration"); - // this.propertyList.get("text-shadow"); - // this.propertyList.get("text-transform"); - // this.propertyList.get("word-spacing"); ColorType c = this.propertyList.get(PR_COLOR).getColorType(); this.red = c.getRed(); @@ -120,7 +83,6 @@ public class PageNumber extends FObj implements LMVisited { this.blue = c.getBlue(); this.wrapOption = this.propertyList.get(PR_WRAP_OPTION).getEnum(); - } /** @@ -134,17 +96,15 @@ public class PageNumber extends FObj implements LMVisited { getFOInputHandler().endPageNumber(this); } - public String getName() { - return "fo:page-number"; - } - /** - * This is a hook for the AddLMVisitor class to be able to access - * this object. - * @param aLMV the AddLMVisitor object that can access this object. + * @see org.apache.fop.fo.FObj#addLayoutManager(List) */ - public void acceptVisitor(AddLMVisitor aLMV) { - setup(); - aLMV.servePageNumber(this); + public void addLayoutManager(List list) { + PageNumberLayoutManager lm = new PageNumberLayoutManager(this); + list.add(lm); + } + + public String getName() { + return "fo:page-number"; } } diff --git a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java index 5411a4d18..a3bb2ecf0 100644 --- a/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java +++ b/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java @@ -32,7 +32,6 @@ import org.apache.fop.area.inline.Image; import org.apache.fop.area.inline.InlineArea; import org.apache.fop.area.inline.InlineParent; import org.apache.fop.area.inline.Space; -import org.apache.fop.area.inline.UnresolvedPageNumber; import org.apache.fop.area.inline.Viewport; import org.apache.fop.area.inline.TextArea; import org.apache.fop.datatypes.Length; @@ -45,7 +44,6 @@ import org.apache.fop.fo.flow.Character; import org.apache.fop.fo.flow.Inline; import org.apache.fop.fo.flow.InstreamForeignObject; import org.apache.fop.fo.flow.Leader; -import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fo.flow.RetrieveMarker; import org.apache.fop.fo.flow.Table; import org.apache.fop.fo.flow.TableAndCaption; @@ -417,43 +415,6 @@ public class AddLMVisitor { return areaCurrent; } - /** - * Overridden from FObj - * @param lms the list to which the layout manager(s) should be added - */ - public void servePageNumber(final PageNumber node) { - LayoutManager lm; - lm = new LeafNodeLayoutManager(node) { - public InlineArea get(LayoutContext context) { - // get page string from parent, build area - TextArea inline = new TextArea(); - String str = parentLM.getCurrentPageNumber(); - int width = 0; - for (int count = 0; count < str.length(); count++) { - width += node.getFontState().getCharWidth( - str.charAt(count)); - } - inline.setTextArea(str); - inline.setIPD(width); - inline.setHeight(node.getFontState().getAscender() - - node.getFontState().getDescender()); - inline.setOffset(node.getFontState().getAscender()); - - inline.addTrait(Trait.FONT_NAME, - node.getFontState().getFontName()); - inline.addTrait(Trait.FONT_SIZE, - new Integer(node.getFontState().getFontSize())); - - return inline; - } - - protected void offsetArea(LayoutContext context) { - curArea.setOffset(context.getBaseline()); - } - }; - currentLMList.add(lm); - } - public void serveTable(Table node) { TableLayoutManager tlm = new TableLayoutManager(node); ArrayList columns = node.getColumns(); diff --git a/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java new file mode 100644 index 000000000..b5bfc8462 --- /dev/null +++ b/src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java @@ -0,0 +1,68 @@ +/* + * Copyright 1999-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.fop.fo.flow.PageNumber; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.TextArea; +import org.apache.fop.area.Trait; +import org.apache.fop.fonts.Font; + +/** + * LayoutManager for the fo:basic-link formatting object + */ +public class PageNumberLayoutManager extends LeafNodeLayoutManager { + + Font font = null; + + /** + * Constructor + * + * @param node the fo:page-number formatting object that creates the area + * @todo better null checking of node, font + */ + public PageNumberLayoutManager(PageNumber node) { + super(node); + font = node.getFontState(); + } + + public InlineArea get(LayoutContext context) { + // get page string from parent, build area + TextArea inline = new TextArea(); + String str = parentLM.getCurrentPageNumber(); + int width = 0; + for (int count = 0; count < str.length(); count++) { + width += font.getCharWidth(str.charAt(count)); + } + inline.setTextArea(str); + inline.setIPD(width); + inline.setHeight(font.getAscender() - font.getDescender()); + inline.setOffset(font.getAscender()); + inline.addTrait(Trait.FONT_NAME, font.getFontName()); + inline.addTrait(Trait.FONT_SIZE, + new Integer(font.getFontSize())); + + return inline; + } + + protected void offsetArea(LayoutContext context) { + curArea.setOffset(context.getBaseline()); + } +} +