You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2005/06/09 08:45:49 UTC

cvs commit: xml-fop/src/java/org/apache/fop/fo FObjMixed.java FOText.java

jeremias    2005/06/08 23:45:49

  Modified:    src/java/org/apache/fop/fo/flow Block.java Marker.java
                        Inline.java
               src/java/org/apache/fop/fo FObjMixed.java FOText.java
  Log:
  Improvement for FOText instance creation. The text is consolidated into single FOText nodes instead of multiple ones due to multiple SAX characters() calls. This fixes some of the layout engine tests that failed in certain environments.
  Submitted by: "Hock Szabolcs" <Hock.Szabolcs.at.t-online.co.hu>
  
  Revision  Changes    Path
  1.55      +2 -0      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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Block.java	18 Mar 2005 08:08:25 -0000	1.54
  +++ Block.java	9 Jun 2005 06:45:49 -0000	1.55
  @@ -174,6 +174,7 @@
        * @see org.apache.fop.fo.FONode#endOfNode
        */
       protected void endOfNode() throws FOPException {
  +        super.endOfNode();
           handleWhiteSpace();
           getFOEventHandler().endBlock(this);
       }
  @@ -330,6 +331,7 @@
        * @see org.apache.fop.fo.FONode#addChildNode(FONode)
        */
       public void addChildNode(FONode child) throws FOPException {
  +        flushText();
           // Handle whitespace based on values of properties
           // Handle a sequence of inline-producing child nodes in
           // one pass
  
  
  
  1.26      +4 -1      xml-fop/src/java/org/apache/fop/fo/flow/Marker.java
  
  Index: Marker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Marker.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Marker.java	13 May 2005 19:16:51 -0000	1.25
  +++ Marker.java	9 Jun 2005 06:45:49 -0000	1.26
  @@ -83,6 +83,7 @@
           return new MarkerPropertyList(this, parent);
       }
   
  +    /** @see org.apache.fop.fo.FONode#startOfNode() */
       protected void startOfNode() {
           FOEventHandler foEventHandler = getFOEventHandler(); 
           // Push a new property list maker which will make MarkerPropertyLists.
  @@ -96,7 +97,9 @@
           });
       }
   
  -    protected void endOfNode() {
  +    /** @see org.apache.fop.fo.FONode#endOfNode() */
  +    protected void endOfNode() throws FOPException {
  +        super.endOfNode();
           // Pop the MarkerPropertyList maker.
           getFOEventHandler().setPropertyListMaker(savePropertyListMaker);
           savePropertyListMaker = null;
  
  
  
  1.40      +1 -0      xml-fop/src/java/org/apache/fop/fo/flow/Inline.java
  
  Index: Inline.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Inline.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Inline.java	13 May 2005 19:16:51 -0000	1.39
  +++ Inline.java	9 Jun 2005 06:45:49 -0000	1.40
  @@ -117,6 +117,7 @@
        * @see org.apache.fop.fo.FONode#endOfNode
        */
       protected void endOfNode() throws FOPException {
  +        super.endOfNode();
           getFOEventHandler().endInline(this);
       }
   
  
  
  
  1.48      +36 -17    xml-fop/src/java/org/apache/fop/fo/FObjMixed.java
  
  Index: FObjMixed.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObjMixed.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- FObjMixed.java	1 Feb 2005 21:21:28 -0000	1.47
  +++ FObjMixed.java	9 Jun 2005 06:45:49 -0000	1.48
  @@ -28,6 +28,10 @@
    * It should not be instantiated directly.
    */
   public abstract class FObjMixed extends FObj {
  +    
  +    /** Represents accumulated, pending FO text. See flushText(). */
  +    protected FOText ft = null;
  +    
       /**
        * @param parent FONode that is the parent of this object
        */
  @@ -35,26 +39,41 @@
           super(parent);
       }
   
  -    /**
  -     * Adds characters
  -     * @param data array of characters containing text to be added
  -     * @param start starting array element to add
  -     * @param end ending array element to add
  -     * @param pList currently applicable PropertyList 
  -     * @param locator location in fo source file.
  -     * @throws FOPException if there's a problem during processing
  -     * @see org.apache.fop.fo.FONode#addCharacters(char[], int, int, org.apache.fop.fo.PropertyList, org.xml.sax.Locator)
  -     */
  +    /** @see org.apache.fop.fo.FONode */
       protected void addCharacters(char[] data, int start, int end,
                                    PropertyList pList,
                                    Locator locator) throws FOPException {
  -        FOText ft = new FOText(data, start, end, this);
  -        ft.setLocator(locator);
  -        ft.bind(pList);
  -        ft.startOfNode();
  -        
  -        getFOEventHandler().characters(ft.ca, ft.startIndex, ft.endIndex);
  -        addChildNode(ft);
  +        if (ft == null) {
  +            ft = new FOText(this);
  +            ft.setLocator(locator);
  +            ft.bind(pList);
  +        }
  +        ft.addCharacters(data, start, end, null, null);
  +    }
  +
  +    /** @see org.apache.fop.fo.FONode#endOfNode() */
  +    protected void endOfNode() throws FOPException {
  +        flushText();
  +        super.endOfNode();
  +    }
  +
  +    /**
  +     * Adds accumulated text as one FOText instance.
  +     * @throws FOPException if there is a problem during processing
  +     */
  +    protected void flushText() throws FOPException {
  +       if (ft != null) {
  +            FOText lft = ft;
  +            ft = null;
  +            lft.endOfNode();
  +            getFOEventHandler().characters(lft.ca, lft.startIndex, lft.endIndex);
  +            addChildNode(lft);
  +        }
  +    }
  +
  +    protected void addChildNode(FONode child) throws FOPException {
  +        flushText();
  +        super.addChildNode(child);
       }
   
       /**
  
  
  
  1.40      +24 -11    xml-fop/src/java/org/apache/fop/fo/FOText.java
  
  Index: FOText.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOText.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- FOText.java	27 May 2005 19:05:53 -0000	1.39
  +++ FOText.java	9 Jun 2005 06:45:49 -0000	1.40
  @@ -29,6 +29,7 @@
   import org.apache.fop.fo.properties.CommonTextDecoration;
   import org.apache.fop.fo.properties.Property;
   import org.apache.fop.fo.properties.SpaceProperty;
  +import org.xml.sax.Locator;
   
   /**
    * A text node (PCDATA) in the formatting object tree.
  @@ -88,21 +89,32 @@
       private static final int IS_WORD_CHAR_MAYBE = 2;
   
       /**
  -     *
  -     * @param chars array of chars which contains the text in this object (may
  -     * be a superset of the text in this object)
  -     * @param start starting index into char[] for the text in this object
  -     * @param end ending index into char[] for the text in this object
  +     * Creates a now FO text node.
        * @param parent FONode that is the parent of this object
        */
  -    public FOText(char[] chars, int start, int end, FONode parent) {
  +    public FOText(FONode parent) {
           super(parent);
  -        endIndex = end - start;
  -        this.ca = new char[endIndex];
  -        System.arraycopy(chars, start, ca, 0, endIndex);
  -//      System.out.println("->" + new String(ca) + "<-");
       }
   
  +    /** @see org.apache.fop.fo.FONode */
  +    protected void addCharacters(char[] data, int start, int end,
  +            PropertyList list, Locator locator) throws FOPException {
  +
  +        int length = end - start;
  +        int calength = 0;
  +        char[] nca = null;
  +        if (ca != null) {
  +            calength = ca.length;
  +            nca = new char[calength + length];
  +            System.arraycopy(ca, 0, nca, 0, calength);
  +        } else {
  +            nca = new char[length];
  +        }
  +        System.arraycopy(data, start, nca, calength, length);
  +        endIndex = nca.length;
  +        this.ca = nca;
  +     }
  +
       /**
        * @see org.apache.fop.fo.FObj#bind(PropertyList)
        */
  @@ -120,7 +132,8 @@
           textDecoration = pList.getTextDecorationProps();
       }
   
  -    protected void startOfNode() {
  +    /** @see org.apache.fop.fo.FONode#endOfNode() */
  +    protected void endOfNode() throws FOPException {
           textTransform();
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org