vmote       2003/08/24 15:15:51

  Modified:    src/java/org/apache/fop/fo FObj.java
               src/java/org/apache/fop/fo/flow InstreamForeignObject.java
               src/java/org/apache/fop/layoutmgr AddLMVisitor.java
  Log:
  1. move fo/flow/InstreamForeignObject.getInlineArea() to 
layoutmgr/AddLMVisitor.getIFOInlineArea()
  2. remove unneeded field fo/flow/InstreamForeignObject.areaCurrent
  
  Revision  Changes    Path
  1.15      +2 -2      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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- FObj.java 22 Aug 2003 05:43:45 -0000      1.14
  +++ FObj.java 24 Aug 2003 22:15:51 -0000      1.15
  @@ -102,7 +102,7 @@
       /**
        * The children of this node.
        */
  -    protected ArrayList children = null;
  +    public ArrayList children = null;
   
       /**
        * Markers added to this element.
  @@ -372,7 +372,7 @@
           return null;
       }
   
  -    /**
  +   /**
        * Add the marker to this formatting object.
        * If this object can contain markers it checks that the marker
        * has a unique class-name for this object and that it is
  
  
  
  1.7       +2 -164    
xml-fop/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java
  
  Index: InstreamForeignObject.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- InstreamForeignObject.java        22 Aug 2003 06:27:34 -0000      1.6
  +++ InstreamForeignObject.java        24 Aug 2003 22:15:51 -0000      1.7
  @@ -50,20 +50,10 @@
    */
   package org.apache.fop.fo.flow;
   
  -// FOP
  -import java.awt.geom.Point2D;
  -import java.awt.geom.Rectangle2D;
  -
  -import org.apache.fop.area.inline.ForeignObject;
  -import org.apache.fop.area.inline.Viewport;
  -import org.apache.fop.datatypes.Length;
   import org.apache.fop.fo.FONode;
   import org.apache.fop.fo.FObj;
   import org.apache.fop.fo.FOTreeVisitor;
  -import org.apache.fop.fo.XMLObj;
   import org.apache.fop.fo.properties.DisplayAlign;
  -import org.apache.fop.fo.properties.Overflow;
  -import org.apache.fop.fo.properties.Scaling;
   import org.apache.fop.fo.properties.TextAlign;
   import org.w3c.dom.Document;
   
  @@ -74,8 +64,6 @@
    */
   public class InstreamForeignObject extends FObj {
   
  -    public Viewport areaCurrent;
  -
       /**
        * constructs an instream-foreign-object object (called by Maker).
        *
  @@ -85,157 +73,7 @@
           super(parent);
       }
   
  -    /**
  -     * Get the inline area created by this element.
  -     *
  -     * @return the viewport inline area
  -     */
  -    public Viewport getInlineArea() {
  -        if (children == null) {
  -            return areaCurrent;
  -        }
  -
  -        if (this.children.size() != 1) {
  -            // error
  -            return null;
  -        }
  -        FONode fo = (FONode)children.get(0);
  -        if (!(fo instanceof XMLObj)) {
  -            // error
  -            return null;
  -        }
  -        XMLObj child = (XMLObj)fo;
  -
  -        // viewport size is determined by block-progression-dimension
  -        // and inline-progression-dimension
  -
  -        // if replaced then use height then ignore block-progression-dimension
  -        //int h = this.properties.get("height").getLength().mvalue();
  -
  -        // use specified line-height then ignore dimension in height direction
  -        boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() 
!= null;
  -
  -        Length len;
  -
  -        int bpd = -1;
  -        int ipd = -1;
  -        boolean bpdauto = false;
  -        if (hasLH) {
  -            bpd = properties.get("line-height").getLength().getValue();
  -        } else {
  -            // this property does not apply when the line-height applies
  -            // isn't the block-progression-dimension always in the same
  -            // direction as the line height?
  -            len = properties.get("block-progression-dimension.optimum").getLength();
  -            if (!len.isAuto()) {
  -                bpd = len.getValue();
  -            } else {
  -                len = properties.get("height").getLength();
  -                if (!len.isAuto()) {
  -                    bpd = len.getValue();
  -                }
  -            }
  -        }
  -
  -        len = properties.get("inline-progression-dimension.optimum").getLength();
  -        if (!len.isAuto()) {
  -            ipd = len.getValue();
  -        } else {
  -            len = properties.get("width").getLength();
  -            if (!len.isAuto()) {
  -                ipd = len.getValue();
  -            }
  -        }
  -
  -        // if auto then use the intrinsic size of the content scaled
  -        // to the content-height and content-width
  -        int cwidth = -1;
  -        int cheight = -1;
  -        len = properties.get("content-width").getLength();
  -        if (!len.isAuto()) {
  -            /*if(len.scaleToFit()) {
  -                if(ipd != -1) {
  -                    cwidth = ipd;
  -                }
  -            } else {*/
  -            cwidth = len.getValue();
  -        }
  -        len = properties.get("content-height").getLength();
  -        if (!len.isAuto()) {
  -            /*if(len.scaleToFit()) {
  -                if(bpd != -1) {
  -                    cwidth = bpd;
  -                }
  -            } else {*/
  -            cheight = len.getValue();
  -        }
  -
  -        Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f,
  -                                          cheight == -1 ? -1 : cheight / 1000f);
  -        Point2D size = child.getDimension(csize);
  -        if (size == null) {
  -            // error
  -            return null;
  -        }
  -        if (cwidth == -1) {
  -            cwidth = (int)size.getX() * 1000;
  -        }
  -        if (cheight == -1) {
  -            cheight = (int)size.getY() * 1000;
  -        }
  -        int scaling = properties.get("scaling").getEnum();
  -        if (scaling == Scaling.UNIFORM) {
  -            // adjust the larger
  -            double rat1 = cwidth / (size.getX() * 1000f);
  -            double rat2 = cheight / (size.getY() * 1000f);
  -            if (rat1 < rat2) {
  -                // reduce cheight
  -                cheight = (int)(rat1 * size.getY() * 1000);
  -            } else {
  -                cwidth = (int)(rat2 * size.getX() * 1000);
  -            }
  -        }
  -
  -        if (ipd == -1) {
  -            ipd = cwidth;
  -        }
  -        if (bpd == -1) {
  -            bpd = cheight;
  -        }
  -
  -        boolean clip = false;
  -        if (cwidth > ipd || cheight > bpd) {
  -            int overflow = properties.get("overflow").getEnum();
  -            if (overflow == Overflow.HIDDEN) {
  -                clip = true;
  -            } else if (overflow == Overflow.ERROR_IF_OVERFLOW) {
  -                getLogger().error("Instream foreign object overflows the viewport: 
clipping");
  -                clip = true;
  -            }
  -        }
  -
  -        int xoffset = computeXOffset(ipd, cwidth);
  -        int yoffset = computeYOffset(bpd, cheight);
  -
  -        Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, 
cheight);
  -
  -        Document doc = child.getDOMDocument();
  -        String ns = child.getDocumentNamespace();
  -
  -        children = null;
  -        ForeignObject foreign = new ForeignObject(doc, ns);
  -
  -        areaCurrent = new Viewport(foreign);
  -        areaCurrent.setWidth(ipd);
  -        areaCurrent.setHeight(bpd);
  -        areaCurrent.setContentPosition(placement);
  -        areaCurrent.setClip(clip);
  -        areaCurrent.setOffset(0);
  -
  -        return areaCurrent;
  -    }
  -
  -    private int computeXOffset (int ipd, int cwidth) {
  +    public int computeXOffset (int ipd, int cwidth) {
           int xoffset = 0;
           int ta = properties.get("text-align").getEnum();
           switch (ta) {
  @@ -254,7 +92,7 @@
           return xoffset;
       }
   
  -    private int computeYOffset(int bpd, int cheight) {
  +    public int computeYOffset(int bpd, int cheight) {
           int yoffset = 0;
           int da = properties.get("display-align").getEnum();
           switch (da) {
  
  
  
  1.6       +165 -5    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AddLMVisitor.java 24 Aug 2003 19:22:59 -0000      1.5
  +++ AddLMVisitor.java 24 Aug 2003 22:15:51 -0000      1.6
  @@ -58,16 +58,21 @@
   import org.apache.fop.area.inline.InlineArea;
   import org.apache.fop.area.inline.InlineParent;
   import org.apache.fop.area.inline.FilledArea;
  +import org.apache.fop.area.inline.ForeignObject;
   import org.apache.fop.area.inline.Space;
   import org.apache.fop.area.inline.Word;
   import org.apache.fop.area.inline.Image;
   import org.apache.fop.area.inline.Viewport;
   
  +import org.apache.fop.datatypes.Length;
  +
   import org.apache.fop.fo.FOTreeVisitor;
   import org.apache.fop.fo.FObj;
   import org.apache.fop.fo.FObjMixed;
  +import org.apache.fop.fo.FONode;
   import org.apache.fop.fo.FOText;
   import org.apache.fop.fo.TextInfo;
  +import org.apache.fop.fo.XMLObj;
   import org.apache.fop.fo.flow.BidiOverride;
   import org.apache.fop.fo.flow.Inline;
   import org.apache.fop.fo.flow.BasicLink;
  @@ -93,6 +98,8 @@
   import org.apache.fop.fo.properties.LeaderPattern;
   import org.apache.fop.fo.properties.CommonBorderAndPadding;
   import org.apache.fop.fo.properties.CommonBackground;
  +import org.apache.fop.fo.properties.Overflow;
  +import org.apache.fop.fo.properties.Scaling;
   
   import org.apache.fop.layoutmgr.BidiLayoutManager;
   import org.apache.fop.layoutmgr.LayoutProcessor;
  @@ -108,6 +115,9 @@
   import java.util.List;
   import java.util.ListIterator;
   import java.util.ArrayList;
  +import java.awt.geom.Point2D;
  +import java.awt.geom.Rectangle2D;
  +
   import org.apache.fop.apps.*;
   
   /**
  @@ -457,16 +467,166 @@
        }
   
        public void serveVisitor(InstreamForeignObject node) {
  -         node.areaCurrent = node.getInlineArea();
  -         if (node.areaCurrent != null) {
  +         Viewport areaCurrent = getIFOInlineArea(node);
  +         if (areaCurrent != null) {
                LeafNodeLayoutManager lm = new LeafNodeLayoutManager();
                lm.setUserAgent(node.getUserAgent());
                lm.setFObj(node);
  -             lm.setCurrentArea(node.areaCurrent);
  +             lm.setCurrentArea(areaCurrent);
                lm.setAlignment(node.properties.get("vertical-align").getEnum());
  -             lm.setLead(node.areaCurrent.getHeight());
  +             lm.setLead(areaCurrent.getHeight());
                currentLMList.add(lm);
            }
  +     }
  +
  +     /**
  +      * Get the inline area created by this element.
  +      *
  +      * @return the viewport inline area
  +      */
  +     public Viewport getIFOInlineArea(InstreamForeignObject node) {
  +         if (node.getChildren() == null) {
  +             return null;
  +         }
  +
  +         if (node.children.size() != 1) {
  +             // error
  +             return null;
  +         }
  +         FONode fo = (FONode)node.children.get(0);
  +         if (!(fo instanceof XMLObj)) {
  +             // error
  +             return null;
  +         }
  +         XMLObj child = (XMLObj)fo;
  +
  +         // viewport size is determined by block-progression-dimension
  +         // and inline-progression-dimension
  +
  +         // if replaced then use height then ignore block-progression-dimension
  +         //int h = this.properties.get("height").getLength().mvalue();
  +
  +         // use specified line-height then ignore dimension in height direction
  +         boolean hasLH = false;//properties.get("line-height").getSpecifiedValue() 
!= null;
  +
  +         Length len;
  +
  +         int bpd = -1;
  +         int ipd = -1;
  +         boolean bpdauto = false;
  +         if (hasLH) {
  +             bpd = node.properties.get("line-height").getLength().getValue();
  +         } else {
  +             // this property does not apply when the line-height applies
  +             // isn't the block-progression-dimension always in the same
  +             // direction as the line height?
  +             len = 
node.properties.get("block-progression-dimension.optimum").getLength();
  +             if (!len.isAuto()) {
  +                 bpd = len.getValue();
  +             } else {
  +                 len = node.properties.get("height").getLength();
  +                 if (!len.isAuto()) {
  +                     bpd = len.getValue();
  +                 }
  +             }
  +         }
  +
  +         len = 
node.properties.get("inline-progression-dimension.optimum").getLength();
  +         if (!len.isAuto()) {
  +             ipd = len.getValue();
  +         } else {
  +             len = node.properties.get("width").getLength();
  +             if (!len.isAuto()) {
  +                 ipd = len.getValue();
  +             }
  +         }
  +
  +         // if auto then use the intrinsic size of the content scaled
  +         // to the content-height and content-width
  +         int cwidth = -1;
  +         int cheight = -1;
  +         len = node.properties.get("content-width").getLength();
  +         if (!len.isAuto()) {
  +             /*if(len.scaleToFit()) {
  +                 if(ipd != -1) {
  +                     cwidth = ipd;
  +                 }
  +             } else {*/
  +             cwidth = len.getValue();
  +         }
  +         len = node.properties.get("content-height").getLength();
  +         if (!len.isAuto()) {
  +             /*if(len.scaleToFit()) {
  +                 if(bpd != -1) {
  +                     cwidth = bpd;
  +                 }
  +             } else {*/
  +             cheight = len.getValue();
  +         }
  +
  +         Point2D csize = new Point2D.Float(cwidth == -1 ? -1 : cwidth / 1000f,
  +                                           cheight == -1 ? -1 : cheight / 1000f);
  +         Point2D size = child.getDimension(csize);
  +         if (size == null) {
  +             // error
  +             return null;
  +         }
  +         if (cwidth == -1) {
  +             cwidth = (int)size.getX() * 1000;
  +         }
  +         if (cheight == -1) {
  +             cheight = (int)size.getY() * 1000;
  +         }
  +         int scaling = node.properties.get("scaling").getEnum();
  +         if (scaling == Scaling.UNIFORM) {
  +             // adjust the larger
  +             double rat1 = cwidth / (size.getX() * 1000f);
  +             double rat2 = cheight / (size.getY() * 1000f);
  +             if (rat1 < rat2) {
  +                 // reduce cheight
  +                 cheight = (int)(rat1 * size.getY() * 1000);
  +             } else {
  +                 cwidth = (int)(rat2 * size.getX() * 1000);
  +             }
  +         }
  +
  +         if (ipd == -1) {
  +             ipd = cwidth;
  +         }
  +         if (bpd == -1) {
  +             bpd = cheight;
  +         }
  +
  +         boolean clip = false;
  +         if (cwidth > ipd || cheight > bpd) {
  +             int overflow = node.properties.get("overflow").getEnum();
  +             if (overflow == Overflow.HIDDEN) {
  +                 clip = true;
  +             } else if (overflow == Overflow.ERROR_IF_OVERFLOW) {
  +                 node.getLogger().error("Instream foreign object overflows the 
viewport: clipping");
  +                 clip = true;
  +             }
  +         }
  +
  +         int xoffset = node.computeXOffset(ipd, cwidth);
  +         int yoffset = node.computeYOffset(bpd, cheight);
  +
  +         Rectangle2D placement = new Rectangle2D.Float(xoffset, yoffset, cwidth, 
cheight);
  +
  +         org.w3c.dom.Document doc = child.getDOMDocument();
  +         String ns = child.getDocumentNamespace();
  +
  +         node.children = null;
  +         ForeignObject foreign = new ForeignObject(doc, ns);
  +
  +         Viewport areaCurrent = new Viewport(foreign);
  +         areaCurrent.setWidth(ipd);
  +         areaCurrent.setHeight(bpd);
  +         areaCurrent.setContentPosition(placement);
  +         areaCurrent.setClip(clip);
  +         areaCurrent.setOffset(0);
  +
  +         return areaCurrent;
        }
   
        public void serveVisitor(ListItem node) {
  
  
  

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

Reply via email to