tkormann    01/08/21 08:03:24

  Modified:    sources/org/apache/batik/bridge SVGImageElementBridge.java
               sources/org/apache/batik/swing/gvt GVTTreeRenderer.java
  Log:
  - bug fix. When loading multiple documents on the command line, an
  InteruptedExcetpion occured sometimes.
  
  - bug fix. 'preserveAspectRatio', 'viewBox' and 'clip' now works properly on
  the<image> element.
  
  Some additional tests have to be done.
  - fix imageViewbox (raster images)
  - add a new test for SVG image and preserveAspectRatio and viewBox
  - add a new test for testing clip on SVG images and raster images
  
  Revision  Changes    Path
  1.23      +67 -36    
xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java
  
  Index: SVGImageElementBridge.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- SVGImageElementBridge.java        2001/08/07 17:28:21     1.22
  +++ SVGImageElementBridge.java        2001/08/21 15:03:24     1.23
  @@ -14,6 +14,7 @@
   import java.awt.color.ICC_Profile;
   import java.awt.geom.AffineTransform;
   import java.awt.geom.Rectangle2D;
  +import java.awt.geom.Rectangle2D;
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  @@ -22,6 +23,7 @@
   import org.apache.batik.dom.svg.SVGOMDocument;
   import org.apache.batik.dom.util.XLinkSupport;
   import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
  +import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit;
   import org.apache.batik.ext.awt.image.renderable.Filter;
   import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
   import org.apache.batik.gvt.CompositeGraphicsNode;
  @@ -43,7 +45,7 @@
    * Bridge class for the &lt;image> element.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Thierry Kormann</a>
  - * @version $Id: SVGImageElementBridge.java,v 1.22 2001/08/07 17:28:21 deweese Exp $
  + * @version $Id: SVGImageElementBridge.java,v 1.23 2001/08/21 15:03:24 tkormann Exp 
$
    */
   public class SVGImageElementBridge extends AbstractGraphicsNodeBridge {
   
  @@ -60,12 +62,12 @@
       }
   
       /**
  -     * Creates a graphics node using the specified BridgeContext and
  -     * for the specified element.
  +     * Creates a graphics node using the specified BridgeContext and for the
  +     * specified element.
        *
        * @param ctx the bridge context to use
        * @param e the element that describes the graphics node to build
  -     * @return a graphics node that represents the specified element
  +     * @return a graphics node that represents the specified element 
        */
       public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
   
  @@ -87,7 +89,6 @@
           URL baseURL = ((SVGOMDocument)svgDoc).getURLObject();
           ParsedURL purl = new ParsedURL(baseURL, uriStr);
   
  -
           // try to load an SVG document
           DocumentLoader loader = ctx.getDocumentLoader();
           URIResolver resolver = new URIResolver(svgDoc, loader);
  @@ -99,8 +100,8 @@
               }
           } catch (BridgeException ex) {
               throw ex;
  -        } catch (Exception ex) { 
  -            /* Nothing to do */ 
  +        } catch (Exception ex) {
  +            /* Nothing to do */
           }
   
           if (node == null) {
  @@ -148,19 +149,18 @@
       }
   
       /**
  -     * Returns a GraphicsNode that represents an raster image in JPEG
  -     * or PNG format.
  +     * Returns a GraphicsNode that represents an raster image in JPEG or PNG
  +     * format.
        *
        * @param ctx the bridge context
        * @param e the image element
  -     * @param uriStr the uri of the image
  +     * @param uriStr the uri of the image 
        */
       protected static GraphicsNode createRasterImageNode(BridgeContext ctx,
                                                           Element       e,
                                                           ParsedURL     purl) {
  +
           RasterImageNode node = new RasterImageNode();
  -        // create the image
  -        Rectangle2D bounds = getImageBounds(ctx, e);
   
           ImageTagRegistry reg = ImageTagRegistry.getRegistry();
           Filter           img = reg.readURL(purl, extractColorSpace(e, ctx));
  @@ -171,8 +171,11 @@
               return createSVGImageNode(ctx, e, errDoc);
           }
           node.setImage(img);
  +     node.setImageBounds(img.getBounds2D());
  +        Rectangle2D bounds = getImageBounds(ctx, e);
  +
  +     initializeViewport(ctx, e, node, bounds);
   
  -        node.setImageBounds(bounds);
           return node;
       }
   
  @@ -205,39 +208,67 @@
           svgElement.setAttributeNS(null, SVG_HEIGHT_ATTRIBUTE,
                                     String.valueOf(bounds.getHeight()));
   
  -        AffineTransform at
  -            = ViewBox.getPreserveAspectRatioTransform(svgElement,
  -                                                      (float)bounds.getWidth(),
  -                                                      (float)bounds.getHeight());
  -        at.preConcatenate(AffineTransform.getTranslateInstance(bounds.getX(),
  -                                                               bounds.getY()));
  -        result.setTransform(at);
  -
           GraphicsNode node = ctx.getGVTBuilder().build(ctx, svgElement);
           result.getChildren().add(node);
   
  -        /*
  -        // resolve x, y, width, height and preserveAspectRatio on image
  +     initializeViewport(ctx, element, result, bounds);
   
  -        Rectangle2D bounds = getImageBounds(ctx, element);
  +        return result;
  +    }
  +
  +    /**
  +     * Initializes according to the specified element, the specified graphics
  +     * node with the specified bounds. This method takes into account the
  +     * 'viewBox', 'preserveAspectRatio', and 'clip' properties. According to
  +     * those properties, a AffineTransform and a clip is set.
  +     *
  +     * @param ctx the bridge context
  +     * @param e the image element that defines the properties
  +     * @param node the graphics node
  +     * @param bounds the bounds of the image element 
  +     */
  +    protected static void initializeViewport(BridgeContext ctx,
  +                                          Element e,
  +                                          GraphicsNode node,
  +                                          Rectangle2D bounds) {
  +     
  +        // 'viewBox' and 'preserveAspectRatio'
           float x = (float)bounds.getX();
           float y = (float)bounds.getY();
           float w = (float)bounds.getWidth();
           float h = (float)bounds.getHeight();
           AffineTransform at
  -            = ViewBox.getPreserveAspectRatioTransform(element, w, h);
  +            = ViewBox.getPreserveAspectRatioTransform(e, w, h);
           at.preConcatenate(AffineTransform.getTranslateInstance(x, y));
  -        result.setTransform(at);
  -        try {
  -            at = at.createInverse(); // clip in user space
  -            Filter filter = new GraphicsNodeRable8Bit
  -                (node, ctx.getGraphicsNodeRenderContext());
  -            Shape clip = at.createTransformedShape
  -                (new Rectangle2D.Float(x, y, w, h));
  -            result.setClip(new ClipRable8Bit(filter, clip));
  -        } catch (java.awt.geom.NoninvertibleTransformException ex) {}
  -        */
  -        return result;
  +        node.setTransform(at);
  +
  +        // 'overflow' and 'clip'
  +        Shape clip = null;
  +        if (CSSUtilities.convertOverflow(e)) { // overflow:hidden
  +            float [] offsets = CSSUtilities.convertClip(e);
  +            if (offsets == null) { // clip:auto
  +                clip = new Rectangle2D.Float(x, y, w, h);
  +            } else { // clip:rect(<x> <y> <w> <h>)
  +                // offsets[0] = top
  +                // offsets[1] = right
  +                // offsets[2] = bottom
  +                // offsets[3] = left
  +                clip = new Rectangle2D.Float(x+offsets[3],
  +                                             y+offsets[0],
  +                                             w-offsets[1],
  +                                             h-offsets[2]);
  +            }
  +        }
  +
  +        if (clip != null) {
  +         try {
  +             at = at.createInverse(); // clip in user space
  +             Filter filter = new GraphicsNodeRable8Bit
  +                 (node, ctx.getGraphicsNodeRenderContext());
  +             clip = at.createTransformedShape(clip);
  +             node.setClip(new ClipRable8Bit(filter, clip));
  +         } catch (java.awt.geom.NoninvertibleTransformException ex) {}
  +     }
       }
   
       /**
  
  
  
  1.5       +5 -1      
xml-batik/sources/org/apache/batik/swing/gvt/GVTTreeRenderer.java
  
  Index: GVTTreeRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/GVTTreeRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GVTTreeRenderer.java      2001/07/05 06:07:31     1.4
  +++ GVTTreeRenderer.java      2001/08/21 15:03:24     1.5
  @@ -27,7 +27,7 @@
    * a GVT tree.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Stephane Hillion</a>
  - * @version $Id: GVTTreeRenderer.java,v 1.4 2001/07/05 06:07:31 bella Exp $
  + * @version $Id: GVTTreeRenderer.java,v 1.5 2001/08/21 15:03:24 tkormann Exp $
    */
   public class GVTTreeRenderer extends Thread {
   
  @@ -114,6 +114,10 @@
               // This error was reported to happen when the rendering
               // is interrupted with JDK1.3.0rc1 Solaris.
           } catch (InterruptedBridgeException e) {
  +            // this sometimes happens with SVG Fonts since the glyphs are
  +            // not built till the rendering stage
  +            fireFailedEvent();
  +        } catch (InterruptedException e) {
               // this sometimes happens with SVG Fonts since the glyphs are
               // not built till the rendering stage
               fireFailedEvent();
  
  
  

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

Reply via email to