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/Group.java

    r4256 r6002  
    11/*
    2  * Stop.java
     2 * SVG Salamander
     3 * Copyright (c) 2004, Mark McKay
     4 * All rights reserved.
    35 *
     6 * Redistribution and use in source and binary forms, with or
     7 * without modification, are permitted provided that the following
     8 * conditions are met:
    49 *
    5  *  The Salamander Project - 2D and 3D graphics libraries in Java
    6  *  Copyright (C) 2004 Mark McKay
     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.
    717 *
    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
     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 January 26, 2004, 1:56 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    3139import java.awt.Graphics2D;
    32 import java.awt.Rectangle;
    3340import java.awt.Shape;
    3441import java.awt.geom.AffineTransform;
     
    4047import java.util.List;
    4148
    42 
    4349/**
    4450 * @author Mark McKay
     
    4753public class Group extends ShapeElement
    4854{
    49 
     55    public static final String TAG_NAME = "group";
     56   
    5057    //Cache bounding box for faster clip testing
    5158    Rectangle2D boundingBox;
    5259    Shape cachedShape;
    5360
    54     //Cache clip bounds
    55     final Rectangle clipBounds = new Rectangle();
    56 
    57     /** Creates a new instance of Stop */
    58     public Group() {
    59     }
    60 
    61     /*
    62     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    63     {
    64         //Load style string
    65         super.loaderStartElement(helper, attrs, parent);
    66 
    67         //String transform = attrs.getValue("transform");
    68     }
    69      */
     61    /**
     62     * Creates a new instance of Stop
     63     */
     64    public Group()
     65    {
     66    }
     67
     68    public String getTagName()
     69    {
     70        return TAG_NAME;
     71    }
    7072
    7173    /**
     
    7678    {
    7779        super.loaderAddChild(helper, child);
    78 
    79 //        members.add(child);
    8080    }
    8181
    8282    protected boolean outsideClip(Graphics2D g) throws SVGException
    8383    {
    84         g.getClipBounds(clipBounds);
     84        Shape clip = g.getClip();
     85        if (clip == null)
     86        {
     87            return false;
     88        }
     89        //g.getClipBounds(clipBounds);
    8590        Rectangle2D rect = getBoundingBox();
    8691
    87 //if (rect == null)
    88 //{
    89 //    rect = getBoundingBox();
    90 //}
    91 
    92 //        if (rect.intersects(clipBounds))
    93         if (rect.intersects(clipBounds))
     92        if (clip.intersects(rect))
    9493        {
    9594            return false;
     
    107106            {
    108107                xform.inverseTransform(point, xPoint);
    109             }
    110             catch (NoninvertibleTransformException ex)
     108            } catch (NoninvertibleTransformException ex)
    111109            {
    112110                throw new SVGException(ex);
    113111            }
    114112        }
    115        
    116        
     113
     114
    117115        for (Iterator it = children.iterator(); it.hasNext();)
    118116        {
    119             SVGElement ele = (SVGElement)it.next();
    120             if (ele instanceof RenderableElement)
    121             {
    122                 RenderableElement rendEle = (RenderableElement)ele;
    123                
     117            SVGElement ele = (SVGElement) it.next();
     118            if (ele instanceof RenderableElement)
     119            {
     120                RenderableElement rendEle = (RenderableElement) ele;
     121
    124122                rendEle.pick(xPoint, boundingBox, retVec);
    125123            }
     
    134132            ltw.concatenate(xform);
    135133        }
    136        
    137        
     134
     135
    138136        for (Iterator it = children.iterator(); it.hasNext();)
    139137        {
    140             SVGElement ele = (SVGElement)it.next();
    141             if (ele instanceof RenderableElement)
    142             {
    143                 RenderableElement rendEle = (RenderableElement)ele;
    144                
     138            SVGElement ele = (SVGElement) it.next();
     139            if (ele instanceof RenderableElement)
     140            {
     141                RenderableElement rendEle = (RenderableElement) ele;
     142
    145143                rendEle.pick(pickArea, ltw, boundingBox, retVec);
    146144            }
     
    154152        if (getStyle(styleAttrib.setName("visibility")))
    155153        {
    156             if (!styleAttrib.getStringValue().equals("visible")) return;
    157         }
    158        
     154            if (!styleAttrib.getStringValue().equals("visible"))
     155            {
     156                return;
     157            }
     158        }
     159
    159160        //Do not process offscreen groups
    160161        boolean ignoreClip = diagram.ignoringClipHeuristic();
    161         if (!ignoreClip && outsideClip(g)) return;
     162        if (!ignoreClip && outsideClip(g))
     163        {
     164            return;
     165        }
    162166
    163167        beginLayer(g);
     
    165169        Iterator it = children.iterator();
    166170
    167         try
    168         {
    169             g.getClipBounds(clipBounds);
    170         }
    171         catch (Exception e)
    172         {
    173             //For some reason, getClipBounds can throw a null pointer exception for
    174             // some types of Graphics2D
    175             ignoreClip = true;
    176         }
    177 
     171//        try
     172//        {
     173//            g.getClipBounds(clipBounds);
     174//        }
     175//        catch (Exception e)
     176//        {
     177//            //For some reason, getClipBounds can throw a null pointer exception for
     178//            // some types of Graphics2D
     179//            ignoreClip = true;
     180//        }
     181
     182        Shape clip = g.getClip();
    178183        while (it.hasNext())
    179184        {
    180             SVGElement ele = (SVGElement)it.next();
    181             if (ele instanceof RenderableElement)
    182             {
    183                 RenderableElement rendEle = (RenderableElement)ele;
     185            SVGElement ele = (SVGElement) it.next();
     186            if (ele instanceof RenderableElement)
     187            {
     188                RenderableElement rendEle = (RenderableElement) ele;
    184189
    185190//                if (shapeEle == null) continue;
     
    188193                {
    189194                    //Skip if clipping area is outside our bounds
    190                     if (!ignoreClip && !rendEle.getBoundingBox().intersects(clipBounds))
     195                    if (!ignoreClip && clip != null
     196                        && !clip.intersects(rendEle.getBoundingBox()))
    191197                    {
    192198                        continue;
     
    201207    }
    202208
    203 
    204209    /**
    205210     * Retrieves the cached bounding box of this group
     
    207212    public Shape getShape()
    208213    {
    209         if (cachedShape == null) calcShape();
     214        if (cachedShape == null)
     215        {
     216            calcShape();
     217        }
    210218        return cachedShape;
    211219    }
     
    217225        for (Iterator it = children.iterator(); it.hasNext();)
    218226        {
    219             SVGElement ele = (SVGElement)it.next();
     227            SVGElement ele = (SVGElement) it.next();
    220228
    221229            if (ele instanceof ShapeElement)
    222230            {
    223                 ShapeElement shpEle = (ShapeElement)ele;
     231                ShapeElement shpEle = (ShapeElement) ele;
    224232                Shape shape = shpEle.getShape();
    225233                if (shape != null)
     
    238246    public Rectangle2D getBoundingBox() throws SVGException
    239247    {
    240         if (boundingBox == null) calcBoundingBox();
     248        if (boundingBox == null)
     249        {
     250            calcBoundingBox();
     251        }
    241252//        calcBoundingBox();
    242253        return boundingBox;
     
    245256    /**
    246257     * Recalculates the bounding box by taking the union of the bounding boxes
    247      * of all children.  Caches the result.
     258     * of all children. Caches the result.
    248259     */
    249260    public void calcBoundingBox() throws SVGException
     
    254265        for (Iterator it = children.iterator(); it.hasNext();)
    255266        {
    256             SVGElement ele = (SVGElement)it.next();
    257 
    258             if (ele instanceof RenderableElement)
    259             {
    260                 RenderableElement rendEle = (RenderableElement)ele;
     267            SVGElement ele = (SVGElement) it.next();
     268
     269            if (ele instanceof RenderableElement)
     270            {
     271                RenderableElement rendEle = (RenderableElement) ele;
    261272                Rectangle2D bounds = rendEle.getBoundingBox();
    262273                if (bounds != null)
    263274                {
    264                     if (retRect == null) retRect = bounds;
    265                     else retRect = retRect.createUnion(bounds);
     275                    if (retRect == null)
     276                    {
     277                        retRect = bounds;
     278                    } else
     279                    {
     280                        retRect = retRect.createUnion(bounds);
     281                    }
    266282                }
    267283            }
     
    274290
    275291        //If no contents, use degenerate rectangle
    276         if (retRect == null) retRect = new Rectangle2D.Float();
     292        if (retRect == null)
     293        {
     294            retRect = new Rectangle2D.Float();
     295        }
    277296
    278297        boundingBox = boundsToParent(retRect);
     
    287306        while (it.hasNext())
    288307        {
    289             SVGElement ele = (SVGElement)it.next();
     308            SVGElement ele = (SVGElement) it.next();
    290309            boolean updateVal = ele.updateTime(curTime);
    291310
     
    293312
    294313            //Update our shape if shape aware children change
    295             if (ele instanceof ShapeElement) cachedShape = null;
    296             if (ele instanceof RenderableElement) boundingBox = null;
     314            if (ele instanceof ShapeElement)
     315            {
     316                cachedShape = null;
     317            }
     318            if (ele instanceof RenderableElement)
     319            {
     320                boundingBox = null;
     321            }
    297322        }
    298323
Note: See TracChangeset for help on using the changeset viewer.