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/01/03 14:06:27 UTC

cvs commit: xml-fop/src/java/org/apache/fop/fo FObj.java IntrinsicSizeAccess.java

jeremias    2005/01/03 05:06:27

  Modified:    src/java/org/apache/fop/fo/flow ExternalGraphic.java
                        InstreamForeignObject.java
               src/java/org/apache/fop/datatypes PercentBase.java
                        LengthBase.java
               src/java/org/apache/fop/fo FObj.java
  Removed:     src/java/org/apache/fop/fo IntrinsicSizeAccess.java
  Log:
  Access to intrinsic image size for eg/ifo through getLayoutDimension() instead of through separate interface.
  Added a todo item about replacing the use of propertyList along with a reference to the related post on fop-dev.
  Made the LayoutDimension keys a subclass of Avalon Framework's Enum to make the thing more debugger-friendly and more type-safe.
  
  Revision  Changes    Path
  1.51      +16 -7     xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java
  
  Index: ExternalGraphic.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/ExternalGraphic.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- ExternalGraphic.java	28 Dec 2004 18:03:12 -0000	1.50
  +++ ExternalGraphic.java	3 Jan 2005 13:06:27 -0000	1.51
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -18,16 +18,13 @@
   
   package org.apache.fop.fo.flow;
   
  -// Java
  -import java.util.List;
  -
   import org.xml.sax.Locator;
   
   import org.apache.fop.apps.FOPException;
   import org.apache.fop.datatypes.Length;
  +import org.apache.fop.datatypes.PercentBase;
   import org.apache.fop.fo.FONode;
   import org.apache.fop.fo.FObj;
  -import org.apache.fop.fo.IntrinsicSizeAccess;
   import org.apache.fop.fo.PropertyList;
   import org.apache.fop.fo.ValidationException;
   import org.apache.fop.fo.properties.CommonAccessibility;
  @@ -39,14 +36,13 @@
   import org.apache.fop.fo.properties.LengthRangeProperty;
   import org.apache.fop.image.FopImage;
   import org.apache.fop.image.ImageFactory;
  -import org.apache.fop.layoutmgr.ExternalGraphicLayoutManager;
   
   /**
    * External graphic formatting object.
    * This FO node handles the external graphic. It creates an image
    * inline area that can be added to the area tree.
    */
  -public class ExternalGraphic extends FObj implements IntrinsicSizeAccess {
  +public class ExternalGraphic extends FObj {
       
       // The value of properties relevant for fo:external-graphic.
       private CommonAccessibility commonAccessibility;
  @@ -272,6 +268,19 @@
           return FO_EXTERNAL_GRAPHIC;
       }
   
  +    /**
  +     * @see org.apache.fop.fo.FObj#getLayoutDimension(org.apache.fop.datatypes.PercentBase.DimensionType)
  +     */
  +    public Number getLayoutDimension(PercentBase.LayoutDimension key) {
  +        if (key == PercentBase.IMAGE_INTRINSIC_WIDTH) {
  +            return new Integer(getIntrinsicWidth());
  +        } else if (key == PercentBase.IMAGE_INTRINSIC_HEIGHT) {
  +            return new Integer(getIntrinsicHeight());
  +        } else {
  +            return super.getLayoutDimension(key);
  +        }
  +    }
  +    
       /**
        * Preloads the image so the intrinsic size is available.
        */
  
  
  
  1.39      +16 -3     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- InstreamForeignObject.java	28 Dec 2004 18:03:12 -0000	1.38
  +++ InstreamForeignObject.java	3 Jan 2005 13:06:27 -0000	1.39
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -24,9 +24,9 @@
   
   import org.apache.fop.apps.FOPException;
   import org.apache.fop.datatypes.Length;
  +import org.apache.fop.datatypes.PercentBase;
   import org.apache.fop.fo.FONode;
   import org.apache.fop.fo.FObj;
  -import org.apache.fop.fo.IntrinsicSizeAccess;
   import org.apache.fop.fo.PropertyList;
   import org.apache.fop.fo.ValidationException;
   import org.apache.fop.fo.XMLObj;
  @@ -43,7 +43,7 @@
    * This is an atomic inline object that contains
    * xml data.
    */
  -public class InstreamForeignObject extends FObj implements IntrinsicSizeAccess {
  +public class InstreamForeignObject extends FObj {
       
       // The value of properties relevant for fo:instream-foreign-object.
       private CommonAccessibility commonAccessibility;
  @@ -285,6 +285,19 @@
           return FO_INSTREAM_FOREIGN_OBJECT;
       }
   
  +    /**
  +     * @see org.apache.fop.fo.FObj#getLayoutDimension(org.apache.fop.datatypes.PercentBase.DimensionType)
  +     */
  +    public Number getLayoutDimension(PercentBase.LayoutDimension key) {
  +        if (key == PercentBase.IMAGE_INTRINSIC_WIDTH) {
  +            return new Integer(getIntrinsicWidth());
  +        } else if (key == PercentBase.IMAGE_INTRINSIC_HEIGHT) {
  +            return new Integer(getIntrinsicHeight());
  +        } else {
  +            return super.getLayoutDimension(key);
  +        }
  +    }
  +    
       /**
        * Preloads the image so the intrinsic size is available.
        */
  
  
  
  1.6       +42 -9     xml-fop/src/java/org/apache/fop/datatypes/PercentBase.java
  
  Index: PercentBase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/datatypes/PercentBase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PercentBase.java	28 Oct 2004 10:00:19 -0000	1.5
  +++ PercentBase.java	3 Jan 2005 13:06:27 -0000	1.6
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -18,6 +18,7 @@
   
   package org.apache.fop.datatypes;
   
  +import org.apache.avalon.framework.Enum;
   import org.apache.fop.fo.expr.PropertyException;
   
   /**
  @@ -25,19 +26,51 @@
    * computations
    */
   public interface PercentBase {
  -    static Integer TABLE_UNITS = new Integer(1);
  -    static Integer BLOCK_IPD = new Integer(2);
  -    static Integer BLOCK_BPD = new Integer(3);
  -    static Integer REFERENCE_AREA_IPD = new Integer(4);
  -    static Integer REFERENCE_AREA_BPD = new Integer(5);
       
  +    //Types of values to store in layoutDimension on FObj
  +    
  +    /** table units */
  +    LayoutDimension TABLE_UNITS = new LayoutDimension("table-units");
  +    /** Block IPD */
  +    LayoutDimension BLOCK_IPD = new LayoutDimension("block-ipd");
  +    /** Block BPD */
  +    LayoutDimension BLOCK_BPD = new LayoutDimension("block-bpd");
  +    /** Reference Area IPD */
  +    LayoutDimension REFERENCE_AREA_IPD = new LayoutDimension("reference-area-ipd");
  +    /** Reference Area BPD */
  +    LayoutDimension REFERENCE_AREA_BPD = new LayoutDimension("reference-area-bpd");
  +    /** Intrinsic width of an image or foreign-object */ 
  +    LayoutDimension IMAGE_INTRINSIC_WIDTH = new LayoutDimension("image-intrinsic-width");
  +    /** Intrinsic height of an image or foreign-object */ 
  +    LayoutDimension IMAGE_INTRINSIC_HEIGHT = new LayoutDimension("image-intrinsic-heigth");
  +    
  +    /**
  +     * Determines whether a numeric property is created or one with a percentage
  +     * base.
  +     * @return 0 for length, 1 for percentage
  +     */
       int getDimension();
  +    
       double getBaseValue();
   
       /**
  -     * @return the integer size of the object (this will be used as the base to
  -     * which a percentage will be applied to compute the length of the
  -     * referencing item)
  +     * @return the integer size in millipoints of the object (this will be used 
  +     * as the base to which a percentage will be applied to compute the length 
  +     * of the referencing item)
  +     * @throws PropertyException if a problem occurs during evaluation of this
  +     *     value.
        */
       int getBaseLength() throws PropertyException;
  +    
  +    /** Enum class for dimension types. */
  +    public class LayoutDimension extends Enum {
  +        
  +        /**
  +         * Constructor to add a new named item.
  +         * @param name Name of the item.
  +         */
  +        protected LayoutDimension(String name) {
  +            super(name);
  +        }
  +    }
   }
  
  
  
  1.10      +8 -7      xml-fop/src/java/org/apache/fop/datatypes/LengthBase.java
  
  Index: LengthBase.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/datatypes/LengthBase.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LengthBase.java	28 Dec 2004 18:03:12 -0000	1.9
  +++ LengthBase.java	3 Jan 2005 13:06:27 -0000	1.10
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -20,7 +20,6 @@
   
   import org.apache.fop.fo.Constants;
   import org.apache.fop.fo.FObj;
  -import org.apache.fop.fo.IntrinsicSizeAccess;
   import org.apache.fop.fo.PropertyList;
   import org.apache.fop.fo.expr.PropertyException;
   
  @@ -114,10 +113,10 @@
           return 1.0;
       }
   
  -    /**
  -     * @return the base length (in millipoints ??) of this object
  -     */
  +    /** @see org.apache.fop.datatypes.PercentBase#getBaseLength() */
       public int getBaseLength() throws PropertyException {
  +        //TODO Don't use propertyList here
  +        //See http://nagoya.apache.org/eyebrowse/ReadMsg?listName=fop-dev@xml.apache.org&msgNo=10342
           switch (iBaseType) {
           case FONTSIZE:
               return propertyList.get(Constants.PR_FONT_SIZE).getLength().getValue();
  @@ -134,9 +133,11 @@
               //return (((fo != null) && (fo instanceof FObj)) ? ((FObj)fo).getContentWidth() : 0);
               return 0;
           case IMAGE_INTRINSIC_WIDTH:
  -            return ((IntrinsicSizeAccess)propertyList.getFObj()).getIntrinsicWidth();
  +            return propertyList.getFObj()
  +                .getLayoutDimension(PercentBase.IMAGE_INTRINSIC_WIDTH).intValue();
           case IMAGE_INTRINSIC_HEIGHT:
  -            return ((IntrinsicSizeAccess)propertyList.getFObj()).getIntrinsicHeight();
  +            return propertyList.getFObj()
  +                .getLayoutDimension(PercentBase.IMAGE_INTRINSIC_HEIGHT).intValue();
           case CUSTOM_BASE:
               //log.debug("!!! LengthBase.getBaseLength() called on CUSTOM_BASE type !!!");
               return 0;
  
  
  
  1.89      +13 -10    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.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- FObj.java	2 Jan 2005 20:42:50 -0000	1.88
  +++ FObj.java	3 Jan 2005 13:06:27 -0000	1.89
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 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.
  @@ -26,6 +26,7 @@
   import java.util.Set;
   
   import org.apache.fop.apps.FOPException;
  +import org.apache.fop.datatypes.PercentBase;
   import org.apache.fop.fo.flow.Marker;
   import org.apache.fop.fo.properties.PropertyMaker;
   import org.xml.sax.Attributes;
  @@ -76,11 +77,12 @@
           }
           
           if (propertyListTable == null) {
  -            propertyListTable = new PropertyMaker[Constants.PROPERTY_COUNT+1];
  +            propertyListTable = new PropertyMaker[Constants.PROPERTY_COUNT + 1];
               PropertyMaker[] list = FOPropertyMapping.getGenericMappings();
               for (int i = 1; i < list.length; i++) {
  -                if (list[i] != null)
  -                    propertyListTable[i] = list[i]; 
  +                if (list[i] != null) {
  +                    propertyListTable[i] = list[i];
  +                }
               }
           }
       }
  @@ -111,7 +113,8 @@
       /**
        * Create a default property list for this element. 
        */
  -    protected PropertyList createPropertyList(PropertyList parent, FOEventHandler foEventHandler) throws FOPException {
  +    protected PropertyList createPropertyList(PropertyList parent, 
  +                    FOEventHandler foEventHandler) throws FOPException {
           return foEventHandler.getPropertyListMaker().make(this, parent);
       }
   
  @@ -186,8 +189,8 @@
        * @param key the Layout dimension, from PercentBase.
        * @param dimension The layout length.
        */
  -    public void setLayoutDimension(Integer key, int dimension) {
  -        if (layoutDimension == null){
  +    public void setLayoutDimension(PercentBase.LayoutDimension key, int dimension) {
  +        if (layoutDimension == null) {
               layoutDimension = new HashMap();
           }
           layoutDimension.put(key, new Integer(dimension));
  @@ -198,8 +201,8 @@
        * @param key the Layout dimension, from PercentBase.
        * @param dimension The layout length.
        */
  -    public void setLayoutDimension(Integer key, float dimension) {
  -        if (layoutDimension == null){
  +    public void setLayoutDimension(PercentBase.LayoutDimension key, float dimension) {
  +        if (layoutDimension == null) {
               layoutDimension = new HashMap();
           }
           layoutDimension.put(key, new Float(dimension));
  @@ -210,7 +213,7 @@
        * @param key The layout dimension key.
        * @return the length.
        */
  -    public Number getLayoutDimension(Integer key) {
  +    public Number getLayoutDimension(PercentBase.LayoutDimension key) {
           if (layoutDimension != null) {
               Number result = (Number) layoutDimension.get(key);
               if (result != null) {
  
  
  

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


Re: cvs commit: xml-fop/src/java/org/apache/fop/fo FObj.java IntrinsicSizeAccess.java

Posted by Glen Mazza <gr...@yahoo.com>.
+1!  Ausgezeichnet!  Danke...

Glen

--- Jeremias Maerki <de...@greenmail.ch> wrote:

> Sorry, I'm so used to using A-F Enums that I didn't
> think about that.
> I've fixed this and hope that you can agree with my
> change now.
> 


Re: cvs commit: xml-fop/src/java/org/apache/fop/fo FObj.java IntrinsicSizeAccess.java

Posted by Jeremias Maerki <de...@greenmail.ch>.
Sorry, I'm so used to using A-F Enums that I didn't think about that.
I've fixed this and hope that you can agree with my change now.

On 03.01.2005 14:51:00 Glen Mazza wrote:
> Jeremias,
> 
> Would you please elaborate on the need for this?  I
> want to make sure that adding an additional dependency
> on the Avalon project is passing a cost-benefit
> analysis here.
> 
> We're not a fluffy hi-level word processing system
> --we are a very low-level application (like a
> compiler), that is in turn will be integrated into
> other applications.  Therefore we have to be careful
> not to include gratuitous linkages to other libraries.
>  (That we already--currently--use Avalon for
> configuration does not excuse us from this principle. 
> Linkages should be kept at a minimum.  For example, we
> had an option of using Commons Configuration instead
> of Avalon.  Now, if we do so, we're still required to
> keep Avalon just because of your change below.)
> 
> What is lost if we don't link to Avalon here?  How
> often have we failed by relying on Java variables? 
> How come Xalan and Xerces can work without Avalon
> variables but FOP can't?
> 
> Also, why is the Cocoon Team in error for trying to
> detach themselves from Avalon[1]?  Why are those 15
> committers wrong?
> 
> I'm -1 (veto) on this change.
> 
> Glen
> 
> [1]
> http://marc.theaimsgroup.com/?t=108004833700001&r=1&w=2
> 
> --- jeremias@apache.org wrote:
> >
> >   Made the LayoutDimension keys a subclass of Avalon
> > Framework's Enum to make the thing more
> > debugger-friendly and more type-safe.
> >   



Jeremias Maerki


Re: cvs commit: xml-fop/src/java/org/apache/fop/fo FObj.java IntrinsicSizeAccess.java

Posted by Glen Mazza <gr...@yahoo.com>.
Jeremias,

Would you please elaborate on the need for this?  I
want to make sure that adding an additional dependency
on the Avalon project is passing a cost-benefit
analysis here.

We're not a fluffy hi-level word processing system
--we are a very low-level application (like a
compiler), that is in turn will be integrated into
other applications.  Therefore we have to be careful
not to include gratuitous linkages to other libraries.
 (That we already--currently--use Avalon for
configuration does not excuse us from this principle. 
Linkages should be kept at a minimum.  For example, we
had an option of using Commons Configuration instead
of Avalon.  Now, if we do so, we're still required to
keep Avalon just because of your change below.)

What is lost if we don't link to Avalon here?  How
often have we failed by relying on Java variables? 
How come Xalan and Xerces can work without Avalon
variables but FOP can't?

Also, why is the Cocoon Team in error for trying to
detach themselves from Avalon[1]?  Why are those 15
committers wrong?

I'm -1 (veto) on this change.

Glen

[1]
http://marc.theaimsgroup.com/?t=108004833700001&r=1&w=2

--- jeremias@apache.org wrote:
>
>   Made the LayoutDimension keys a subclass of Avalon
> Framework's Enum to make the thing more
> debugger-friendly and more type-safe.
>