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

    r4256 r6002  
    11/*
    2  * SVGRoot.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 18, 2004, 5:33 PM
     
    3039import com.kitfox.svg.xml.NumberWithUnits;
    3140import com.kitfox.svg.xml.StyleAttribute;
    32 import java.awt.geom.*;
    33 import java.awt.*;
     41import com.kitfox.svg.xml.StyleSheet;
     42import java.awt.Graphics2D;
     43import java.awt.Rectangle;
     44import java.awt.Shape;
     45import java.awt.geom.AffineTransform;
     46import java.awt.geom.Rectangle2D;
    3447
    3548/**
     
    4154public class SVGRoot extends Group
    4255{
     56    public static final String TAG_NAME = "svg";
     57
    4358    NumberWithUnits x;
    4459    NumberWithUnits y;
     
    4661    NumberWithUnits height;
    4762
    48    
    49 //    final Rectangle2D.Float viewBox = new Rectangle2D.Float();
    5063    Rectangle2D.Float viewBox = null;
    5164
     
    7083    final Rectangle2D.Float clipRect = new Rectangle2D.Float();
    7184
     85    private StyleSheet styleSheet;
     86   
    7287    /** Creates a new instance of SVGRoot */
    7388    public SVGRoot()
    7489    {
    7590    }
    76 /*
    77     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    78     {
    79                 //Load style string
    80         super.loaderStartElement(helper, attrs, parent);
    81 
    82         x = XMLParseUtil.parseNumberWithUnits(attrs.getValue("x"));
    83         y = XMLParseUtil.parseNumberWithUnits(attrs.getValue("y"));
    84         width = XMLParseUtil.parseNumberWithUnits(attrs.getValue("width"));
    85         height = XMLParseUtil.parseNumberWithUnits(attrs.getValue("height"));
    86 
    87         String viewBox = attrs.getValue("viewBox");
    88         float[] coords = XMLParseUtil.parseFloatList(viewBox);
    89 
    90         if (coords == null)
    91         {
    92             //this.viewBox.setRect(0, 0, width.getValue(), height.getValue());
    93             this.viewBox = null;
    94         }
    95         else
    96         {
    97             this.viewBox = new Rectangle2D.Float(coords[0], coords[1], coords[2], coords[3]);
    98         }
    99 
    100         String par = attrs.getValue("preserveAspectRatio");
    101         if (par != null)
    102         {
    103             String[] parList = XMLParseUtil.parseStringList(par);
    104 
    105             if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; }
    106             else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; }
    107             else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; }
    108             else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; }
    109             else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; }
    110             else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; }
    111             else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; }
    112             else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; }
    113             else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; }
    114             else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
    115 
    116             if (parList[1].equals("meet")) parSpecifier = PS_MEET;
    117             else if (parList[1].equals("slice")) parSpecifier = PS_SLICE;
    118         }
    119 
    120         build();
    121     }
    122 */
     91
     92    public String getTagName()
     93    {
     94        return TAG_NAME;
     95    }
    12396   
    12497    public void build() throws SVGException
     
    128101        StyleAttribute sty = new StyleAttribute();
    129102       
    130         if (getPres(sty.setName("x"))) x = sty.getNumberWithUnits();
    131        
    132         if (getPres(sty.setName("y"))) y = sty.getNumberWithUnits();
    133        
    134         if (getPres(sty.setName("width"))) width = sty.getNumberWithUnits();
    135        
    136         if (getPres(sty.setName("height"))) height = sty.getNumberWithUnits();
     103        if (getPres(sty.setName("x")))
     104        {
     105            x = sty.getNumberWithUnits();
     106        }
     107       
     108        if (getPres(sty.setName("y")))
     109        {
     110            y = sty.getNumberWithUnits();
     111        }
     112       
     113        if (getPres(sty.setName("width")))
     114        {
     115            width = sty.getNumberWithUnits();
     116        }
     117       
     118        if (getPres(sty.setName("height")))
     119        {
     120            height = sty.getNumberWithUnits();
     121        }
    137122       
    138123        if (getPres(sty.setName("viewBox")))
     
    157142            else if (contains(preserve, "xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
    158143
    159             if (contains(preserve, "meet")) parSpecifier = PS_MEET;
    160             else if (contains(preserve, "slice")) parSpecifier = PS_SLICE;
    161            
    162             /*
    163             String[] parList = sty.getStringList();
    164 
    165             if (parList[0].equals("none")) { parAlignX = PA_X_NONE; parAlignY = PA_Y_NONE; }
    166             else if (parList[0].equals("xMinYMin")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MIN; }
    167             else if (parList[0].equals("xMidYMin")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MIN; }
    168             else if (parList[0].equals("xMaxYMin")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MIN; }
    169             else if (parList[0].equals("xMinYMid")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MID; }
    170             else if (parList[0].equals("xMidYMid")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MID; }
    171             else if (parList[0].equals("xMaxYMid")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MID; }
    172             else if (parList[0].equals("xMinYMax")) { parAlignX = PA_X_MIN; parAlignY = PA_Y_MAX; }
    173             else if (parList[0].equals("xMidYMax")) { parAlignX = PA_X_MID; parAlignY = PA_Y_MAX; }
    174             else if (parList[0].equals("xMaxYMax")) { parAlignX = PA_X_MAX; parAlignY = PA_Y_MAX; }
    175 
    176             if (parList[1].equals("meet")) parSpecifier = PS_MEET;
    177             else if (parList[1].equals("slice")) parSpecifier = PS_SLICE;
    178              */
     144            if (contains(preserve, "meet"))
     145            {
     146                parSpecifier = PS_MEET;
     147            }
     148            else if (contains(preserve, "slice"))
     149            {
     150                parSpecifier = PS_SLICE;
     151            }
    179152        }
    180153       
     
    185158    {
    186159        return (text.indexOf(find) != -1);
     160    }
     161
     162    public SVGRoot getRoot()
     163    {
     164        return this;
    187165    }
    188166   
     
    195173        {
    196174            defaultBounds = getBoundingBox();
    197         } catch (SVGException ex)
     175        }
     176        catch (SVGException ex)
    198177        {
    199178            defaultBounds= new Rectangle2D.Float();
     
    213192                ww = StyleAttribute.convertUnitsToPixels(width.getUnits(), width.getValue());
    214193            }
    215 //            setAttribute("x", AnimationElement.AT_XML, "" + xx);
    216 //            setAttribute("width", AnimationElement.AT_XML, "" + ww);
    217194        }
    218195        else if (viewBox != null)
     
    273250            viewXform.translate(-viewBox.x, -viewBox.y);
    274251        }
    275 
    276        
    277         //For now, treat all preserveAspectRatio as 'none'
    278 //        viewXform.setToTranslation(viewBox.x, viewBox.y);
    279 //        viewXform.scale(clipRect.width / viewBox.width, clipRect.height / viewBox.height);
    280 //        viewXform.translate(-clipRect.x, -clipRect.y);
    281252    }
    282253
     
    393364    }
    394365
     366    /**
     367     * @return the styleSheet
     368     */
     369    public StyleSheet getStyleSheet()
     370    {
     371        if (styleSheet == null)
     372        {
     373            for (int i = 0; i < getNumChildren(); ++i)
     374            {
     375                SVGElement ele = getChild(i);
     376                if (ele instanceof Style)
     377                {
     378                    return ((Style)ele).getStyleSheet();
     379                }
     380            }
     381        }
     382       
     383        return styleSheet;
     384    }
     385
     386    /**
     387     * @param styleSheet the styleSheet to set
     388     */
     389    public void setStyleSheet(StyleSheet styleSheet)
     390    {
     391        this.styleSheet = styleSheet;
     392    }
     393
    395394}
Note: See TracChangeset for help on using the changeset viewer.