gmazza      2004/08/09 22:33:16

  Modified:    src/java/org/apache/fop/fo FObj.java
               src/java/org/apache/fop/fo/flow Block.java
                        PageNumberCitation.java RetrieveMarker.java
               src/java/org/apache/fop/layoutmgr AddLMVisitor.java
  Added:       src/java/org/apache/fop/layoutmgr
                        PageNumberCitationLayoutManager.java
  Log:
  1.) fo:retrieve marker layout initialization moved from AddLMVisitor to 
RetrieveMarker class.
  
  2.) New PageNumberCitationLayoutManager class created, layout logic imported from 
fo.flow.PageNumberCitation to this new class.
  
  3.) validateChildNode() implemented for fo:block.
  
  Revision  Changes    Path
  1.64      +9 -5      xml-fop/src/java/org/apache/fop/fo/FObj.java
  
  Index: FObj.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObj.java,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- FObj.java 8 Aug 2004 19:04:48 -0000       1.63
  +++ FObj.java 10 Aug 2004 05:33:15 -0000      1.64
  @@ -443,10 +443,6 @@
       }
   */    
   
  -    public String getName() {
  -        return null;
  -    }
  -
       /**
        * Convenience method for validity checking.  Checks if the
        * incoming node is a member of the "%block;" parameter entity
  @@ -541,8 +537,16 @@
       }
   
       /**
  +     * 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;
  
  
  
  1.32      +36 -8     xml-fop/src/java/org/apache/fop/fo/flow/Block.java
  
  Index: Block.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Block.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Block.java        8 Aug 2004 19:04:49 -0000       1.31
  +++ Block.java        10 Aug 2004 05:33:15 -0000      1.32
  @@ -23,7 +23,7 @@
   
   // 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.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 @@
     */
   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;
  @@ -139,6 +136,37 @@
             this.propertyList.get(PR_ORPHANS).getNumber().intValue();
   
           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);
  +        }
       }
   
       /**
  
  
  
  1.31      +12 -112   xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java
  
  Index: PageNumberCitation.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/PageNumberCitation.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- PageNumberCitation.java   8 Aug 2004 18:39:23 -0000       1.30
  +++ PageNumberCitation.java   10 Aug 2004 05:33:15 -0000      1.31
  @@ -26,26 +26,12 @@
   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 @@
       }
   
       /**
  -     * @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 @@
           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()
        */
  
  
  
  1.15      +21 -18    xml-fop/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
  
  Index: RetrieveMarker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/RetrieveMarker.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RetrieveMarker.java       8 Aug 2004 18:39:23 -0000       1.14
  +++ RetrieveMarker.java       10 Aug 2004 05:33:15 -0000      1.15
  @@ -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 @@
   // 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 @@
    * 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;
  @@ -51,15 +53,6 @@
       }
   
       /**
  -     * @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
        */
       protected void addProperties(Attributes attlist) throws SAXParseException {
  @@ -72,6 +65,15 @@
               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 @@
       }
   
       /**
  -     * 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 int getNameId() {
           return FO_RETRIEVE_MARKER;
       }
  -
   }
  
  
  
  1.52      +1 -8      xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java
  
  Index: AddLMVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/AddLMVisitor.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- AddLMVisitor.java 8 Aug 2004 17:52:35 -0000       1.51
  +++ AddLMVisitor.java 10 Aug 2004 05:33:15 -0000      1.52
  @@ -44,7 +44,6 @@
   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;
  @@ -227,12 +226,6 @@
                leaderArea = fa;
            }
            return leaderArea;
  -     }
  -
  -     public void serveRetrieveMarker(RetrieveMarker node) {
  -         RetrieveMarkerLayoutManager rmlm;
  -         rmlm = new RetrieveMarkerLayoutManager(node);
  -         currentLMList.add(rmlm);
        }
   
        public void serveCharacter(Character node) {
  
  
  
  1.1                  
xml-fop/src/java/org/apache/fop/layoutmgr/PageNumberCitationLayoutManager.java
  
  Index: PageNumberCitationLayoutManager.java
  ===================================================================
  /*
   * 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: PageNumberCitationLayoutManager.java,v 1.1 2004/08/10 05:33:15 gmazza Exp $ 
*/
  
  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;
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to