Ignore:
Timestamp:
2013-06-11T01:01:28+02:00 (13 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/RadialGradient.java

    r4256 r6002  
    11/*
    2  * RadialGradient.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 January 26, 2004, 1:55 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.geom.*;
    32 import java.awt.*;
    33 
    34 import com.kitfox.svg.xml.*;
    35 import org.xml.sax.*;
    36 
    37 //import org.apache.batik.ext.awt.*;
    38 import com.kitfox.svg.batik.*;
    39 
     39import java.awt.Color;
     40import java.awt.Paint;
     41import java.awt.geom.AffineTransform;
     42import java.awt.geom.Point2D;
     43import java.awt.geom.Rectangle2D;
    4044
    4145/**
     
    4347 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4448 */
    45 public class RadialGradient extends Gradient {
     49public class RadialGradient extends Gradient
     50{
     51    public static final String TAG_NAME = "radialgradient";
    4652
    4753    float cx = 0.5f;
     
    5157    float r = 0.5f;
    5258
    53     /** Creates a new instance of RadialGradient */
    54     public RadialGradient() {
    55     }
    56 /*
    57     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    58     {
    59                 //Load style string
    60         super.loaderStartElement(helper, attrs, parent);
    61 
    62         String cx = attrs.getValue("cx");
    63         String cy = attrs.getValue("cy");
    64         String fx = attrs.getValue("fx");
    65         String fy = attrs.getValue("fy");
    66         String r = attrs.getValue("r");
    67 
    68         if (cx != null) this.cx = (float)XMLParseUtil.parseRatio(cx);
    69         if (cy != null) this.cy = (float)XMLParseUtil.parseRatio(cy);
    70         if (fx != null) this.fx = (float)XMLParseUtil.parseRatio(fx);
    71         if (fy != null) this.fy = (float)XMLParseUtil.parseRatio(fy);
    72         if (r != null) this.r = (float)XMLParseUtil.parseRatio(r);
    73     }
    74     */
    75 
    76     /*
    77     public void loaderEndElement(SVGLoaderHelper helper)
    78     {
    79         super.loaderEndElement(helper);
    80        
    81         build();
    82     }
     59    /**
     60     * Creates a new instance of RadialGradient
    8361     */
    84    
     62    public RadialGradient()
     63    {
     64    }
     65
     66    public String getTagName()
     67    {
     68        return TAG_NAME;
     69    }
     70
    8571    protected void build() throws SVGException
    8672    {
    8773        super.build();
    88        
     74
    8975        StyleAttribute sty = new StyleAttribute();
    90        
    91         if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
    92        
    93         if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
    94        
    95         if (getPres(sty.setName("fx"))) fx = sty.getFloatValueWithUnits();
    96        
    97         if (getPres(sty.setName("fy"))) fy = sty.getFloatValueWithUnits();
    98        
    99         if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits();
    100     }
    101    
     76
     77        if (getPres(sty.setName("cx")))
     78        {
     79            cx = sty.getFloatValueWithUnits();
     80        }
     81
     82        if (getPres(sty.setName("cy")))
     83        {
     84            cy = sty.getFloatValueWithUnits();
     85        }
     86
     87        if (getPres(sty.setName("fx")))
     88        {
     89            fx = sty.getFloatValueWithUnits();
     90        }
     91
     92        if (getPres(sty.setName("fy")))
     93        {
     94            fy = sty.getFloatValueWithUnits();
     95        }
     96
     97        if (getPres(sty.setName("r")))
     98        {
     99            r = sty.getFloatValueWithUnits();
     100        }
     101    }
     102
    102103    public Paint getPaint(Rectangle2D bounds, AffineTransform xform)
    103104    {
     
    117118        }
    118119
    119         com.kitfox.svg.batik.RadialGradientPaint paint;
    120 
    121         if (gradientUnits == GU_USER_SPACE_ON_USE)
     120        Paint paint;
     121        Point2D.Float pt1 = new Point2D.Float(cx, cy);
     122        Point2D.Float pt2 = new Point2D.Float(fx, fy);
     123        if (pt1.equals(pt2))
     124        {
     125            Color[] colors = getStopColors();
     126            paint = colors.length > 0 ? colors[0] : Color.black;
     127        } else if (gradientUnits == GU_USER_SPACE_ON_USE)
    122128        {
    123129            paint = new com.kitfox.svg.batik.RadialGradientPaint(
    124                 new Point2D.Float(cx, cy),
     130                pt1,
    125131                r,
    126                 new Point2D.Float(fx, fy),
     132                pt2,
    127133                getStopFractions(),
    128134                getStopColors(),
     
    130136                com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
    131137                gradientTransform);
    132         }
    133         else
     138        } else
    134139        {
    135140            AffineTransform viewXform = new AffineTransform();
     
    140145
    141146            paint = new com.kitfox.svg.batik.RadialGradientPaint(
    142                 new Point2D.Float(cx, cy),
     147                pt1,
    143148                r,
    144                 new Point2D.Float(fx, fy),
     149                pt2,
    145150                getStopFractions(),
    146151                getStopColors(),
     
    154159
    155160    /**
    156      * Updates all attributes in this diagram associated with a time event.
    157      * Ie, all attributes with track information.
     161     * Updates all attributes in this diagram associated with a time event. Ie,
     162     * all attributes with track information.
     163     *
    158164     * @return - true if this node has changed state as a result of the time
    159165     * update
     
    167173        StyleAttribute sty = new StyleAttribute();
    168174        boolean shapeChange = false;
    169        
     175
    170176        if (getPres(sty.setName("cx")))
    171177        {
     
    177183            }
    178184        }
    179        
     185
    180186        if (getPres(sty.setName("cy")))
    181187        {
     
    187193            }
    188194        }
    189        
     195
    190196        if (getPres(sty.setName("fx")))
    191197        {
     
    197203            }
    198204        }
    199        
     205
    200206        if (getPres(sty.setName("fy")))
    201207        {
     
    207213            }
    208214        }
    209        
     215
    210216        if (getPres(sty.setName("r")))
    211217        {
     
    217223            }
    218224        }
    219        
     225
    220226        return changeState;
    221227    }
Note: See TracChangeset for help on using the changeset viewer.