deweese     2002/08/13 14:33:17

  Modified:    samples  mathMetal.svg
               sources/org/apache/batik/bridge SVGImageElementBridge.java
               sources/org/apache/batik/extension/svg
                        BatikMultiImageElementBridge.java
               sources/org/apache/batik/gvt ImageNode.java
                        RasterImageNode.java
               sources/org/apache/batik/gvt/font Glyph.java
               sources/org/apache/batik/gvt/renderer
                        StrokingTextPainter.java
               sources/org/apache/batik/gvt/text GlyphLayout.java
  Log:
  1) Image nodes now update bounds properly when changed via script.
  2) Text advances and scale factors are now properly calculated.
     (solves text-length bug just reported).  This of course sightly
     changes the rendering of all centered text.
  
  Revision  Changes    Path
  1.4       +3 -2      xml-batik/samples/mathMetal.svg
  
  Index: mathMetal.svg
  ===================================================================
  RCS file: /home/cvs/xml-batik/samples/mathMetal.svg,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- mathMetal.svg     7 Feb 2002 12:44:52 -0000       1.3
  +++ mathMetal.svg     13 Aug 2002 21:33:16 -0000      1.4
  @@ -398,7 +398,8 @@
       <image width="100%" height="100%" 
xlink:href="tests/resources/images/brushedMetal.jpg" filter="url(#tint)"/> 
   
       <use xlink:href="#graphics" fill="gray" filter="url(#shadow)"/> 
  -    <text text-anchor="middle" font-size="80" font-family="embedZeroHour" x="50%" 
y="120" fill="black" filter="url(#recessed)">MATH</text>
  +    <text text-anchor="middle" font-size="80" font-family="embedZeroHour" 
  +          x="50%" y="120" fill="black" filter="url(#recessed)">MATH</text>
       <use xlink:href="#formula" transform="translate(225 360) scale(.7)" 
fill="black" color="black" filter="url(#carved)"/> 
   
   </svg>
  
  
  
  1.50      +1 -2      
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.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- SVGImageElementBridge.java        9 Jul 2002 20:11:41 -0000       1.49
  +++ SVGImageElementBridge.java        13 Aug 2002 21:33:16 -0000      1.50
  @@ -289,7 +289,6 @@
           }
           node.setImage(img);
           Rectangle2D imgBounds = img.getBounds2D();
  -        node.setImageBounds(imgBounds);
           Rectangle2D bounds = getImageBounds(ctx, e);
   
           // create the implicit viewBox for the raster image. The viewBox for a
  
  
  
  1.5       +1 -2      
xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java
  
  Index: BatikMultiImageElementBridge.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BatikMultiImageElementBridge.java 22 May 2002 11:59:10 -0000      1.4
  +++ BatikMultiImageElementBridge.java 13 Aug 2002 21:33:16 -0000      1.5
  @@ -161,7 +161,6 @@
           b = getImageBounds(ctx, e);
   
           node.setImage(f);
  -        node.setImageBounds(imgB);
   
           float []vb = new float[4];
           vb[0] = 0;
  
  
  
  1.11      +2 -1      xml-batik/sources/org/apache/batik/gvt/ImageNode.java
  
  Index: ImageNode.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/ImageNode.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ImageNode.java    11 Jul 2002 12:35:29 -0000      1.10
  +++ ImageNode.java    13 Aug 2002 21:33:16 -0000      1.11
  @@ -87,6 +87,7 @@
           invalidateGeometryCache();
           if (count == 0) ensureCapacity(1);
           children[0] = newImage;
  +        ((AbstractGraphicsNode)newImage).setParent(this);
           count=1;
           fireGraphicsNodeChangeCompleted();
       }
  
  
  
  1.12      +6 -76     xml-batik/sources/org/apache/batik/gvt/RasterImageNode.java
  
  Index: RasterImageNode.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/RasterImageNode.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RasterImageNode.java      23 Jan 2002 14:14:08 -0000      1.11
  +++ RasterImageNode.java      13 Aug 2002 21:33:16 -0000      1.12
  @@ -32,27 +32,6 @@
       protected Filter image;
   
       /**
  -     * The Bounds of this image node.
  -     */
  -    protected Rectangle2D imageBounds;
  -
  -    /**
  -     * The transform that go from the image to the user coordinate system.
  -     */
  -    protected AffineTransform img2usr;
  -
  -    /**
  -     * The transform that go from the user to the image coordinate system.
  -     */
  -    protected AffineTransform usr2img;
  -
  -    /**
  -     * This flag indicates whether or not the affine transforms have been
  -     * computed.
  -     */
  -    protected boolean calcAffine = true;
  -
  -    /**
        * Constructs a new empty <tt>RasterImageNode</tt>.
        */
       public RasterImageNode() {}
  @@ -70,7 +49,6 @@
           fireGraphicsNodeChangeStarted();
           invalidateGeometryCache();
           this.image = newImage;
  -        calcAffine = true;
           fireGraphicsNodeChangeCompleted();
       }
   
  @@ -84,25 +62,12 @@
       }
   
       /**
  -     * Sets the bounds of this raster image node.
  -     *
  -     * @param newBounds the new bounds of this raster image node
  -     */
  -    public void setImageBounds(Rectangle2D newImageBounds) {
  -        fireGraphicsNodeChangeStarted();
  -        invalidateGeometryCache();
  -        this.imageBounds = newImageBounds;
  -        calcAffine = true;
  -        fireGraphicsNodeChangeCompleted();
  -    }
  -
  -    /**
        * Returns the bounds of this raster image node.
        *
        * @return the bounds of this raster image node
        */
       public Rectangle2D getImageBounds() {
  -        return (Rectangle2D) imageBounds.clone();
  +        return (Rectangle2D) image.getBounds2D().clone();
       }
   
       /**
  @@ -114,33 +79,6 @@
           return image;
       }
   
  -    /**
  -     * Updates bith the user->image and image->user transform.
  -     */
  -    protected void updateAffine() {
  -        
  -        float tx0 = image.getMinX();
  -        float ty0 = image.getMinY();
  -
  -        float sx  = (float)(imageBounds.getWidth() /image.getWidth());
  -        float sy  = (float)(imageBounds.getHeight()/image.getHeight());
  -
  -        float tx1 = (float)imageBounds.getX();
  -        float ty1 = (float)imageBounds.getY();
  -
  -        // Make the affine go from our src Img's coord system to
  -        // the device coord system, including scaling to our bounds.
  -        img2usr = AffineTransform.getTranslateInstance          ( tx1,  ty1);
  -        img2usr.concatenate(AffineTransform.getScaleInstance    ( sx ,  sy ));
  -        img2usr.concatenate(AffineTransform.getTranslateInstance(-tx0, -ty0));
  -
  -        usr2img = AffineTransform.getTranslateInstance          ( tx0,  ty0);
  -        usr2img.concatenate(AffineTransform.getScaleInstance    (1/sx, 1/sy));
  -        usr2img.concatenate(AffineTransform.getTranslateInstance(-tx1, -ty1));
  -
  -        calcAffine = false;
  -    }
  -
       //
       // Drawing methods
       //
  @@ -151,15 +89,7 @@
        * @param g2d the Graphics2D to use
        */
       public void primitivePaint(Graphics2D g2d) {
  -        if ((image == null) ||
  -            (imageBounds.getWidth()  == 0) ||
  -            (imageBounds.getHeight() == 0)) {
  -            return;
  -        }
  -
  -        if (calcAffine) {
  -            updateAffine();
  -        }
  +        if (image == null) return;
   
           GraphicsUtil.drawImage(g2d, image);
       }
  @@ -172,7 +102,7 @@
        * Returns the bounds of the area covered by this node's primitive paint.
        */
       public Rectangle2D getPrimitiveBounds() {
  -        return (Rectangle2D) imageBounds.clone();
  +        return image.getBounds2D();
       }
   
       /**
  @@ -181,13 +111,13 @@
        * masking, filtering or stroking, for example.
        */
       public Rectangle2D getGeometryBounds() {
  -        return (Rectangle2D) imageBounds.clone();
  +        return image.getBounds2D();
       }
   
       /**
        * Returns the outline of this node.
        */
       public Shape getOutline() {
  -        return (Rectangle2D) imageBounds.clone();
  +        return image.getBounds2D();
       }
   }
  
  
  
  1.10      +9 -5      xml-batik/sources/org/apache/batik/gvt/font/Glyph.java
  
  Index: Glyph.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/font/Glyph.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Glyph.java        12 Aug 2002 20:34:34 -0000      1.9
  +++ Glyph.java        13 Aug 2002 21:33:16 -0000      1.10
  @@ -250,10 +250,14 @@
        */
       public GVTGlyphMetrics getGlyphMetrics() {
           if (metrics == null) {
  -            metrics = new GVTGlyphMetrics(getHorizAdvX(), 
  -                                          getVertAdvY(),
  -                                          getGeometryBounds(), 
  -                                          GlyphMetrics.COMPONENT);
  +            Rectangle2D gb = getGeometryBounds();
  +            
  +            metrics = new GVTGlyphMetrics
  +                (getHorizAdvX(), getVertAdvY(),
  +                 new Rectangle2D.Double(gb.getX()-position.getX(),
  +                                        gb.getY()-position.getY(),
  +                                        gb.getWidth(),gb.getHeight()),
  +                 GlyphMetrics.COMPONENT);
           }
           return metrics;
       }
  
  
  
  1.38      +9 -9      
xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java
  
  Index: StrokingTextPainter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- StrokingTextPainter.java  12 Aug 2002 20:34:35 -0000      1.37
  +++ StrokingTextPainter.java  13 Aug 2002 21:33:16 -0000      1.38
  @@ -680,7 +680,8 @@
           GVTGlyphMetrics lastMetrics = 
               layout.getGlyphMetrics(layout.getGlyphCount()-1);
           Rectangle2D     lastBounds  = lastMetrics.getBounds2D();
  -        
  +        float lastW = (float)(lastBounds.getWidth()+lastBounds.getX());
  +        float lastH = (float)(lastBounds.getHeight()+lastBounds.getY());
           Point2D visualAdvance;
           
           if (!doAdjust) {
  @@ -688,9 +689,9 @@
               // System.out.println("LastBounds: " + lastBounds);
               // System.out.println("LastMetrics.hadv: " + 
lastMetrics.getHorizontalAdvance());
               visualAdvance = new Point2D.Float
  -            ((float)(chunk.advance.getX() + lastBounds.getWidth() -
  +            ((float)(chunk.advance.getX() + lastW -
                        lastMetrics.getHorizontalAdvance()),
  -             (float)(chunk.advance.getY() + lastBounds.getHeight() -
  +             (float)(chunk.advance.getY() + lastH -
                        lastMetrics.getVerticalAdvance()));
           } else {
               Point2D advance    = chunk.advance;
  @@ -702,22 +703,21 @@
               if (layout.isVertical()) {
                   if (lengthAdj == ADJUST_SPACING) {
                       yScale = (float)
  -                        ((length.floatValue()-lastBounds.getHeight())/
  +                        ((length.floatValue()-lastH)/
                            (advance.getY()-lastMetrics.getVerticalAdvance()));
                   } else {
                       double adv = (advance.getY()-
  -                                  lastMetrics.getVerticalAdvance() +
  -                                  lastBounds.getHeight());
  +                                  lastMetrics.getVerticalAdvance() + lastH);
                       yScale = (float)(length.floatValue()/adv);
                   }
                   visualAdvance = new Point2D.Float(0, length.floatValue());
               } else {
                   if (lengthAdj == ADJUST_SPACING) {
                       xScale = (float)
  -                        ((length.floatValue()-lastBounds.getWidth())/
  +                        ((length.floatValue()-lastW)/
                            (advance.getX()-lastMetrics.getHorizontalAdvance()));
                   } else {
  -                    double adv = (advance.getX() + lastBounds.getWidth() -
  +                    double adv = (advance.getX() + lastW -
                                     lastMetrics.getHorizontalAdvance());
                       xScale = (float)(length.floatValue()/adv);
                   }
  
  
  
  1.45      +4 -4      xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java
  
  Index: GlyphLayout.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- GlyphLayout.java  12 Aug 2002 20:34:35 -0000      1.44
  +++ GlyphLayout.java  13 Aug 2002 21:33:16 -0000      1.45
  @@ -1456,14 +1456,14 @@
           if ((xScale == 1) && (yScale==1)) 
               return;
   
  -        Rectangle2D bounds = gv.getGeometricBounds();
           AffineTransform scaleAT = 
               AffineTransform.getScaleInstance(xScale, yScale);
   
  -        float initX   = (float) bounds.getX();
  -        float initY   = (float) bounds.getY();
           int numGlyphs = gv.getNumGlyphs();
           float [] gp   = gv.getGlyphPositions(0, numGlyphs+1, null);
  +
  +        float initX   = (float) gp[0];
  +        float initY   = (float) gp[1];
           float dx = 0f;
           float dy = 0f;
           for (int i = 0; i <= numGlyphs; i++) {
  
  
  

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

Reply via email to