Ignore:
Timestamp:
2013-06-11T01:01:28+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8742 - update svgsalamander to release 0.1.18+patch (fix bug SVGSALAMANDER-26) -> allow to open more SVG files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/ImageSVG.java

    r4256 r6002  
    11/*
    2  * Font.java
    3  *
    4  *
    5  *  The Salamander Project - 2D and 3D graphics libraries in Java
    6  *  Copyright (C) 2004 Mark McKay
    7  *
    8  *  This library is free software; you can redistribute it and/or
    9  *  modify it under the terms of the GNU Lesser General Public
    10  *  License as published by the Free Software Foundation; either
    11  *  version 2.1 of the License, or (at your option) any later version.
    12  *
    13  *  This library is distributed in the hope that it will be useful,
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    16  *  Lesser General Public License for more details.
    17  *
    18  *  You should have received a copy of the GNU Lesser General Public
    19  *  License along with this library; if not, write to the Free Software
    20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    21  *
    22  *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
    23  *  projects can be found at http://www.kitfox.com
     2 * SVG Salamander
     3 * Copyright (c) 2004, Mark McKay
     4 * All rights reserved.
     5 *
     6 * Redistribution and use in source and binary forms, with or
     7 * without modification, are permitted provided that the following
     8 * conditions are met:
     9 *
     10 *   - Redistributions of source code must retain the above
     11 *     copyright notice, this list of conditions and the following
     12 *     disclaimer.
     13 *   - Redistributions in binary form must reproduce the above
     14 *     copyright notice, this list of conditions and the following
     15 *     disclaimer in the documentation and/or other materials
     16 *     provided with the distribution.
     17 *
     18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     29 * OF THE POSSIBILITY OF SUCH DAMAGE.
     30 *
     31 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
     32 * projects can be found at http://www.kitfox.com
    2433 *
    2534 * Created on February 20, 2004, 10:00 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.app.data.Handler;
    31 import com.kitfox.svg.xml.*;
    32 
    33 import java.awt.*;
    34 import java.awt.geom.*;
    35 import java.awt.image.*;
    36 import java.net.*;
     39import com.kitfox.svg.xml.StyleAttribute;
     40import java.awt.AlphaComposite;
     41import java.awt.Composite;
     42import java.awt.Graphics2D;
     43import java.awt.geom.AffineTransform;
     44import java.awt.geom.Point2D;
     45import java.awt.geom.Rectangle2D;
     46import java.awt.image.BufferedImage;
     47import java.net.URI;
     48import java.net.URL;
    3749import java.util.List;
     50import java.util.logging.Level;
     51import java.util.logging.Logger;
    3852
    3953/**
    40  * Implements an embedded font.
    41  *
    42  * SVG specification: http://www.w3.org/TR/SVG/fonts.html
     54 * Implements an image.
    4355 *
    4456 * @author Mark McKay
     
    4759public class ImageSVG extends RenderableElement
    4860{
     61    public static final String TAG_NAME = "image";
     62   
    4963    float x = 0f;
    5064    float y = 0f;
    5165    float width = 0f;
    5266    float height = 0f;
    53 
    5467//    BufferedImage href = null;
    5568    URL imageSrc = null;
    56 
    5769    AffineTransform xform;
    5870    Rectangle2D bounds;
    5971
    60     /** Creates a new instance of Font */
     72    /**
     73     * Creates a new instance of Font
     74     */
    6175    public ImageSVG()
    6276    {
    6377    }
    64    
     78
     79    public String getTagName()
     80    {
     81        return TAG_NAME;
     82    }
     83
    6584    protected void build() throws SVGException
    6685    {
    6786        super.build();
    68        
     87
    6988        StyleAttribute sty = new StyleAttribute();
    70        
    71         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    72 
    73         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    74 
    75         if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
    76 
    77         if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
    78 
    79         try {
     89
     90        if (getPres(sty.setName("x")))
     91        {
     92            x = sty.getFloatValueWithUnits();
     93        }
     94
     95        if (getPres(sty.setName("y")))
     96        {
     97            y = sty.getFloatValueWithUnits();
     98        }
     99
     100        if (getPres(sty.setName("width")))
     101        {
     102            width = sty.getFloatValueWithUnits();
     103        }
     104
     105        if (getPres(sty.setName("height")))
     106        {
     107            height = sty.getFloatValueWithUnits();
     108        }
     109
     110        try
     111        {
    80112            if (getPres(sty.setName("xlink:href")))
    81113            {
     
    84116                {
    85117                    imageSrc = new URL(null, src.toASCIIString(), new Handler());
    86                 }
    87                 else
    88                 {
    89                     try {
     118                } else
     119                {
     120                    try
     121                    {
    90122                        imageSrc = src.toURL();
    91                     }
    92                     catch (Exception e)
     123                    } catch (Exception e)
    93124                    {
    94                         e.printStackTrace();
     125                        Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     126                            "Could not parse xlink:href", e);
     127//                        e.printStackTrace();
    95128                        imageSrc = null;
    96129                    }
    97130                }
    98131            }
    99         }
    100         catch (Exception e)
     132        } catch (Exception e)
    101133        {
    102134            throw new SVGException(e);
     
    104136
    105137        diagram.getUniverse().registerImage(imageSrc);
    106        
     138
    107139        //Set widths if not set
    108140        BufferedImage img = diagram.getUniverse().getImage(imageSrc);
     
    113145            return;
    114146        }
    115        
    116         if (width == 0) width = img.getWidth();
    117         if (height == 0) height = img.getHeight();
    118        
     147
     148        if (width == 0)
     149        {
     150            width = img.getWidth();
     151        }
     152        if (height == 0)
     153        {
     154            height = img.getHeight();
     155        }
     156
    119157        //Determine image xform
    120158        xform = new AffineTransform();
     
    123161        xform.translate(this.x, this.y);
    124162        xform.scale(this.width / img.getWidth(), this.height / img.getHeight());
    125        
     163
    126164        bounds = new Rectangle2D.Float(this.x, this.y, this.width, this.height);
    127165    }
    128    
    129    
    130    
    131     public float getX() { return x; }
    132     public float getY() { return y; }
    133     public float getWidth() { return width; }
    134     public float getHeight() { return height; }
     166
     167    public float getX()
     168    {
     169        return x;
     170    }
     171
     172    public float getY()
     173    {
     174        return y;
     175    }
     176
     177    public float getWidth()
     178    {
     179        return width;
     180    }
     181
     182    public float getHeight()
     183    {
     184        return height;
     185    }
    135186
    136187    void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException
     
    155206        if (getStyle(styleAttrib.setName("visibility")))
    156207        {
    157             if (!styleAttrib.getStringValue().equals("visible")) return;
    158         }
    159        
     208            if (!styleAttrib.getStringValue().equals("visible"))
     209            {
     210                return;
     211            }
     212        }
     213
    160214        beginLayer(g);
    161        
     215
    162216        float opacity = 1f;
    163217        if (getStyle(styleAttrib.setName("opacity")))
     
    165219            opacity = styleAttrib.getRatioValue();
    166220        }
    167        
    168         if (opacity <= 0) return;
     221
     222        if (opacity <= 0)
     223        {
     224            return;
     225        }
    169226
    170227        Composite oldComp = null;
    171        
     228
    172229        if (opacity < 1)
    173230        {
     
    176233            g.setComposite(comp);
    177234        }
    178        
     235
    179236        BufferedImage img = diagram.getUniverse().getImage(imageSrc);
    180         if (img == null) return;
    181        
     237        if (img == null)
     238        {
     239            return;
     240        }
     241
    182242        AffineTransform curXform = g.getTransform();
    183243        g.transform(xform);
    184        
     244
    185245        g.drawImage(img, 0, 0, null);
    186        
     246
    187247        g.setTransform(curXform);
    188         if (oldComp != null) g.setComposite(oldComp);
    189        
     248        if (oldComp != null)
     249        {
     250            g.setComposite(oldComp);
     251        }
     252
    190253        finishLayer(g);
    191254    }
    192    
     255
    193256    public Rectangle2D getBoundingBox()
    194257    {
     
    197260
    198261    /**
    199      * Updates all attributes in this diagram associated with a time event.
    200      * Ie, all attributes with track information.
     262     * Updates all attributes in this diagram associated with a time event. Ie,
     263     * all attributes with track information.
     264     *
    201265     * @return - true if this node has changed state as a result of the time
    202266     * update
     
    210274        StyleAttribute sty = new StyleAttribute();
    211275        boolean shapeChange = false;
    212        
     276
    213277        if (getPres(sty.setName("x")))
    214278        {
     
    220284            }
    221285        }
    222        
     286
    223287        if (getPres(sty.setName("y")))
    224288        {
     
    230294            }
    231295        }
    232        
     296
    233297        if (getPres(sty.setName("width")))
    234298        {
     
    240304            }
    241305        }
    242        
     306
    243307        if (getPres(sty.setName("height")))
    244308        {
     
    250314            }
    251315        }
    252        
    253         try {
     316
     317        try
     318        {
    254319            if (getPres(sty.setName("xlink:href")))
    255320            {
    256321                URI src = sty.getURIValue(getXMLBase());
    257                 URL newVal = src.toURL();
    258                
     322
     323                URL newVal;
     324                if ("data".equals(src.getScheme()))
     325                {
     326                    newVal = new URL(null, src.toASCIIString(), new Handler());
     327                } else
     328                {
     329                    newVal = src.toURL();
     330                }
     331
    259332                if (!newVal.equals(imageSrc))
    260333                {
     
    263336                }
    264337            }
    265         }
    266         catch (IllegalArgumentException ie)
    267         {
    268             new Exception("Image provided with illegal value for href: \"" + sty.getStringValue() + '"', ie).printStackTrace();
    269         }
    270         catch (Exception e)
    271         {
    272             e.printStackTrace();
    273         }
    274 
    275        
     338        } catch (IllegalArgumentException ie)
     339        {
     340            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     341                "Image provided with illegal value for href: \""
     342                + sty.getStringValue() + '"', ie);
     343        } catch (Exception e)
     344        {
     345            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     346                "Could not parse xlink:href", e);
     347        }
     348
     349
    276350        if (shapeChange)
    277351        {
     
    303377//            return true;
    304378        }
    305        
     379
    306380        return changeState || shapeChange;
    307381    }
Note: See TracChangeset for help on using the changeset viewer.