]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
1.) fo:retrieve marker layout initialization moved from AddLMVisitor to RetrieveMarke...
authorGlen Mazza <gmazza@apache.org>
Tue, 10 Aug 2004 05:33:15 +0000 (05:33 +0000)
committerGlen Mazza <gmazza@apache.org>
Tue, 10 Aug 2004 05:33:15 +0000 (05:33 +0000)
2.) New PageNumberCitationLayoutManager class created, layout logic imported from fo.flow.PageNumberCitation to this new class.

3.) validateChildNode() implemented for fo:block.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197863 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FObj.java
src/java/org/apache/fop/fo/flow/Block.java
src/java/org/apache/fop/fo/flow/PageNumberCitation.java
src/java/org/apache/fop/fo/flow/RetrieveMarker.java
src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java [new file with mode: 0644]

index 5c6f671960f91d291a9a1551f57c2636d62dd254..ec12e84d50ea5590296d1c368cd55b2e16924132 100644 (file)
@@ -443,10 +443,6 @@ public class FObj extends FONode implements Constants {
     }
 */    
 
-    public String getName() {
-        return null;
-    }
-
     /**
      * Convenience method for validity checking.  Checks if the
      * incoming node is a member of the "%block;" parameter entity
@@ -540,9 +536,17 @@ public class FObj extends FONode implements Constants {
         return -1;
     }
 
+    /**
+     * Returns the name of this FO (e.g., "fo:root");
+     * @return the name of the FO
+     */
+    public String getName() {
+        return null;
+    }
+
     /**
      * Returns the Constants class integer value of this formatting object
-     * @return the integer enumeration of this FO
+     * @return the integer enumeration of this FO (e.g., FO_ROOT)
      */
     public int getNameId() {
         return FO_UNKNOWN;
index 01e0f18cd4b330af242b8668cfdbe511901bec14..8839fc9d04f888b8d413be1baecb670b0c17c5e1 100644 (file)
@@ -23,7 +23,7 @@ import java.util.List;
 
 // XML
 import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+import org.xml.sax.Locator;
 import org.xml.sax.SAXParseException;
 
 // FOP
@@ -35,13 +35,6 @@ import org.apache.fop.fo.FObjMixed;
 import org.apache.fop.fo.RecursiveCharIterator;
 import org.apache.fop.layoutmgr.BlockLayoutManager;
 import org.apache.fop.fo.Constants;
-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.CommonHyphenation;
-import org.apache.fop.fo.properties.CommonMarginBlock;
-import org.apache.fop.fo.properties.CommonRelativePosition;
 import org.apache.fop.util.CharUtilities;
 
 /*
@@ -63,6 +56,10 @@ import org.apache.fop.util.CharUtilities;
   */
 public class Block extends FObjMixed {
 
+    // used for FO validation
+    private boolean blockOrInlineItemFound = false;
+    private boolean initialPropertySetFound = false;
+
     private int align;
     private int alignLast;
     private int breakAfter;
@@ -141,6 +138,37 @@ public class Block extends FObjMixed {
         getFOInputHandler().startBlock(this);
     }
 
+    /**
+     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+     * XSL Content Model: marker* initial-property-set? (#PCDATA|%inline;|%block;)*
+     * Additionally: "An fo:bidi-override that is a descendant of an fo:leader
+     *  or of the fo:inline child of an fo:footnote may not have block-level
+     *  children, unless it has a nearer ancestor that is an 
+     *  fo:inline-container."
+     */
+    protected void validateChildNode(Locator loc, String nsURI, String localName) 
+        throws SAXParseException {
+        if (nsURI == FO_URI && localName.equals("marker")) {
+            if (blockOrInlineItemFound || initialPropertySetFound) {
+               nodesOutOfOrderError(loc, "fo:marker", 
+                    "initial-property-set? (#PCDATA|%inline;|%block;)");
+            }
+        } else if (nsURI == FO_URI && localName.equals("initial-property-set")) {
+            if (initialPropertySetFound) {
+                tooManyNodesError(loc, "fo:initial-property-set");
+            } else if (blockOrInlineItemFound) {
+                nodesOutOfOrderError(loc, "fo:initial-property-set", 
+                    "(#PCDATA|%inline;|%block;)");
+            } else {
+                initialPropertySetFound = true;
+            }
+        } else if (isBlockOrInlineItem(nsURI, localName)) {
+            blockOrInlineItemFound = true;
+        } else {
+            invalidChildError(loc, nsURI, localName);
+        }
+    }
+
     /**
      * @return span for this Block, in millipoints (??)
      */
index 6195bf3bd4c93626bc43bf903941c124a55c7ff2..9249d34614551a25b10ad87fd314baba2b6274bf 100644 (file)
@@ -26,26 +26,12 @@ import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXParseException;
 
+// FOP
 import org.apache.fop.datatypes.ColorType;
 import org.apache.fop.fo.FONode;
 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.layoutmgr.LayoutContext;          
-import org.apache.fop.layoutmgr.LayoutManager;          
-import org.apache.fop.layoutmgr.LeafNodeLayoutManager;          
-import org.apache.fop.layoutmgr.PositionIterator;
-import org.apache.fop.area.PageViewport;        
-import org.apache.fop.area.Resolveable;         
-import org.apache.fop.area.Trait;       
-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.PageNumberCitationLayoutManager;
 
 /**
  * Class modelling the fo:page-number-citation object. See Sec. 6.6.11 of the
@@ -83,39 +69,12 @@ public class PageNumberCitation extends FObj {
     }
 
     /**
-     * @param str string to be measured
-     * @return width (in millipoints ??) of the string
+     * @todo switch this method to addProperties()
      */
-    public int getStringWidth(String str) {
-        int width = 0;
-        for (int count = 0; count < str.length(); count++) {
-            width += fontState.getCharWidth(str.charAt(count));
-        }
-        return width;
-    }
-
     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();
-
         setupID();
 
         ColorType c = this.propertyList.get(PR_COLOR).getColorType();
@@ -148,82 +107,23 @@ public class PageNumberCitation extends FObj {
         return fontState;
     }
 
-    public String getName() {
-        return "fo:page-number-citation";
-    }
-
     /**
      * @see org.apache.fop.fo.FObj#addLayoutManager(List)
-     * @todo create a subclass for LeafNodeLayoutManager, moving the formatting
-     *  logic to the layoutmgr package
      */
     public void addLayoutManager(List list) {   
         setup();
-        LayoutManager lm;
-        lm = new LeafNodeLayoutManager(this) {
-                 public InlineArea get(LayoutContext context) {
-                     curArea = getPageNumberCitationInlineArea(parentLM);
-                     return curArea;
-                 }
-    
-                 public void addAreas(PositionIterator posIter,
-                                      LayoutContext context) {
-                     super.addAreas(posIter, context);
-                     if (getUnresolved()) {
-                         parentLM.addUnresolvedArea(getRefId(),
-                                                    (Resolveable) curArea);
-                     }
-                 }
-    
-                 protected void offsetArea(LayoutContext context) {
-                     curArea.setOffset(context.getBaseline());
-                 }
-             };
+        PageNumberCitationLayoutManager lm = 
+            new PageNumberCitationLayoutManager(this);
         list.add(lm);   
     }
-
-     // if id can be resolved then simply return a word, otherwise
-     // return a resolveable area
-     public InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) {
-         if (getRefId().equals("")) {
-             getLogger().error("page-number-citation must contain \"ref-id\"");
-             return null;
-         }
-         PageViewport page = parentLM.resolveRefID(getRefId());
-         InlineArea inline = null;
-         if (page != null) {
-             String str = page.getPageNumber();
-             // get page string from parent, build area
-             TextArea text = new TextArea();
-             inline = text;
-             int width = getStringWidth(str);
-             text.setTextArea(str);
-             inline.setIPD(width);
-             inline.setHeight(getFontState().getAscender()
-                              - getFontState().getDescender());
-             inline.setOffset(getFontState().getAscender());
-
-             inline.addTrait(Trait.FONT_NAME, getFontState().getFontName());
-             inline.addTrait(Trait.FONT_SIZE,
-                             new Integer(getFontState().getFontSize()));
-             setUnresolved(false);
-         } else {
-             setUnresolved(true);
-             inline = new UnresolvedPageNumber(getRefId());
-             String str = "MMM"; // reserve three spaces for page number
-             int width = getStringWidth(str);
-             inline.setIPD(width);
-             inline.setHeight(getFontState().getAscender()
-                              - getFontState().getDescender());
-             inline.setOffset(getFontState().getAscender());
-
-             inline.addTrait(Trait.FONT_NAME, getFontState().getFontName());
-             inline.addTrait(Trait.FONT_SIZE,
-                             new Integer(getFontState().getFontSize()));
-         }
-         return inline;
-     }
      
+    /**
+     * @see org.apache.fop.fo.FObj#getName()
+     */
+    public String getName() {
+        return "fo:page-number-citation";
+    }
+
     /**
      * @see org.apache.fop.fo.FObj#getNameId()
      */
index d3f1cc96dd2b066fae0832c9813656060c099126..041e0cff6151015a57e73c35784de302afb2fac8 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,8 +29,7 @@ import org.xml.sax.SAXParseException;
 // FOP
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObjMixed;
-import org.apache.fop.layoutmgr.AddLMVisitor;
-import org.apache.fop.fo.LMVisited;
+import org.apache.fop.layoutmgr.RetrieveMarkerLayoutManager;
 
 
 /**
@@ -35,7 +37,7 @@ import org.apache.fop.fo.LMVisited;
  * This will create a layout manager that will retrieve
  * a marker based on the information.
  */
-public class RetrieveMarker extends FObjMixed implements LMVisited {
+public class RetrieveMarker extends FObjMixed {
 
     private String retrieveClassName;
     private int retrievePosition;
@@ -50,15 +52,6 @@ public class RetrieveMarker extends FObjMixed implements LMVisited {
         super(parent);
     }
 
-    /**
-     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
-     * XSL Content Model: empty
-     */
-    protected void validateChildNode(Locator loc, String nsURI, String localName) 
-        throws SAXParseException {
-            invalidChildError(loc, nsURI, localName);
-    }
-
     /**
      * @see org.apache.fop.fo.FObj#addProperties
      */
@@ -72,6 +65,15 @@ public class RetrieveMarker extends FObjMixed implements LMVisited {
             this.propertyList.get(PR_RETRIEVE_BOUNDARY).getEnum();
     }
 
+    /**
+     * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+     * XSL Content Model: empty
+     */
+    protected void validateChildNode(Locator loc, String nsURI, String localName) 
+        throws SAXParseException {
+            invalidChildError(loc, nsURI, localName);
+    }
+
     public String getRetrieveClassName() {
         return retrieveClassName;
     }
@@ -85,14 +87,16 @@ public class RetrieveMarker extends FObjMixed implements LMVisited {
     }
 
     /**
-     * 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) {
-        aLMV.serveRetrieveMarker(this);
+    public void addLayoutManager(List list) {   
+        RetrieveMarkerLayoutManager lm = new RetrieveMarkerLayoutManager(this);
+        list.add(lm);
     }
 
+    /**
+     * @see org.apache.fop.fo.FObj#getName()
+     */
     public String getName() {
         return "fo:retrieve-marker";
     }
@@ -103,5 +107,4 @@ public class RetrieveMarker extends FObjMixed implements LMVisited {
     public int getNameId() {
         return FO_RETRIEVE_MARKER;
     }
-
 }
index a3bb2ecf0d60334337bc690d5746e8e1466f2b9b..475f14f3c9911b311ba8d07d781dc36cc2505a88 100644 (file)
@@ -44,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.RetrieveMarker;
 import org.apache.fop.fo.flow.Table;
 import org.apache.fop.fo.flow.TableAndCaption;
 import org.apache.fop.fo.flow.TableBody;
@@ -229,12 +228,6 @@ public class AddLMVisitor {
          return leaderArea;
      }
 
-     public void serveRetrieveMarker(RetrieveMarker node) {
-         RetrieveMarkerLayoutManager rmlm;
-         rmlm = new RetrieveMarkerLayoutManager(node);
-         currentLMList.add(rmlm);
-     }
-
      public void serveCharacter(Character node) {
          InlineArea inline = getCharacterInlineArea(node);
          if (inline != null) {
diff --git a/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java
new file mode 100644 (file)
index 0000000..364f111
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * 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.PageNumberCitation;
+import org.apache.fop.area.PageViewport;
+import org.apache.fop.area.Resolveable;
+import org.apache.fop.area.Trait;
+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.fonts.Font;
+
+/**
+ * LayoutManager for the fo:basic-link formatting object
+ */
+public class PageNumberCitationLayoutManager extends LeafNodeLayoutManager {
+
+    PageNumberCitation pncNode;
+    Font font = null;
+    
+    /**
+     * Constructor
+     *
+     * @param node the formatting object that creates this area
+     * @todo better null checking of node, font
+     * @todo see if cleaner way to remove redundant pncNode variable (already
+     *  being stored as an FObj in base class)
+     */
+    public PageNumberCitationLayoutManager(PageNumberCitation node) {
+        super(node);
+        font = node.getFontState();
+        pncNode = node;
+    }
+
+    public InlineArea get(LayoutContext context) {
+        curArea = getPageNumberCitationInlineArea(parentLM);
+        return curArea;
+    }
+    
+    public void addAreas(PositionIterator posIter, LayoutContext context) {
+        super.addAreas(posIter, context);
+        if (pncNode.getUnresolved()) {
+            parentLM.addUnresolvedArea(pncNode.getRefId(),
+                (Resolveable) curArea);
+        }
+    }
+    
+    protected void offsetArea(LayoutContext context) {
+        curArea.setOffset(context.getBaseline());
+    }
+
+    /**
+     * if id can be resolved then simply return a word, otherwise
+     * return a resolveable area
+     * @todo move ref-id validation check to the FO class' addProperties().
+     */
+    private InlineArea getPageNumberCitationInlineArea(LayoutManager parentLM) {
+        if (pncNode.getRefId().equals("")) {
+            fobj.getLogger().error("page-number-citation must contain \"ref-id\"");
+            return null;
+        }
+        PageViewport page = parentLM.resolveRefID(pncNode.getRefId());
+        InlineArea inline = null;
+        if (page != null) {
+            String str = page.getPageNumber();
+            // get page string from parent, build area
+            TextArea text = new TextArea();
+            inline = text;
+            int width = getStringWidth(str);
+            text.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()));
+            pncNode.setUnresolved(false);
+        } else {
+            pncNode.setUnresolved(true);
+            inline = new UnresolvedPageNumber(pncNode.getRefId());
+            String str = "MMM"; // reserve three spaces for page number
+            int width = getStringWidth(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;
+    }
+    
+    /**
+     * @param str string to be measured
+     * @return width (in millipoints ??) of the string
+     */
+    private int getStringWidth(String str) {
+        int width = 0;
+        for (int count = 0; count < str.length(); count++) {
+            width += font.getCharWidth(str.charAt(count));
+        }
+        return width;
+    }
+}
+