]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Moved fo:page-number layout code from AddLMVisitor to new PageNumberLayoutManager...
authorGlen Mazza <gmazza@apache.org>
Sun, 8 Aug 2004 17:52:35 +0000 (17:52 +0000)
committerGlen Mazza <gmazza@apache.org>
Sun, 8 Aug 2004 17:52:35 +0000 (17:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197860 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/flow/PageNumber.java
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
src/java/org/apache/fop/layoutmgr/PageNumberLayoutManager.java [new file with mode: 0644]

index bc7f065b6f1c7e520b0d714c4796c0dd97975a53..678c77205f46050a8859926dda403638b1a884e8 100644 (file)
@@ -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";
     }
 }
index 5411a4d189365651045965cee2fef72082fcef9a..a3bb2ecf0d60334337bc690d5746e8e1466f2b9b 100644 (file)
@@ -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 (file)
index 0000000..b5bfc84
--- /dev/null
@@ -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());
+    }
+}
+