Changeset 6002 in josm for trunk/src/com


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

Location:
trunk/src/com/kitfox/svg
Files:
3 added
2 deleted
85 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/A.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
     
    2938
    3039import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    3240import java.net.URI;
    3341
     
    3644 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3745 */
    38 public class A extends Group {
     46public class A extends Group
     47{
     48    public static final String TAG_NAME = "a";
    3949
    4050    URI href;
     
    4252
    4353    /** Creates a new instance of Stop */
    44     public A() {
     54    public A()
     55    {
    4556    }
    46 /*
    47     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     57
     58    public String getTagName()
    4859    {
    49                 //Load style string
    50         super.loaderStartElement(helper, attrs, parent);
    51 
    52         String offset = attrs.getValue("offset");
    53         this.offset = (float)XMLParseUtil.parseRatio(offset);
    54 
    55         buildStop();
     60        return TAG_NAME;
    5661    }
    57     */
    5862   
    5963    protected void build() throws SVGException
  • trunk/src/com/kitfox/svg/Circle.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3846 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3947 */
    40 public class Circle extends ShapeElement 
     48public class Circle extends ShapeElement
    4149{
    4250
     51    public static final String TAG_NAME = "circle";
    4352    float cx = 0f;
    4453    float cy = 0f;
    4554    float r = 0f;
    46 
    47 
    4855    Ellipse2D.Float circle = new Ellipse2D.Float();
    4956
    50     /** Creates a new instance of Rect */
    51     public Circle() {
     57    /**
     58     * Creates a new instance of Rect
     59     */
     60    public Circle()
     61    {
    5262    }
    53 /*
    54     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     63
     64    public String getTagName()
    5565    {
    56                 //Load style string
    57         super.loaderStartElement(helper, attrs, parent);
     66        return TAG_NAME;
     67    }
    5868
    59         String cx = attrs.getValue("cx");
    60         String cy = attrs.getValue("cy");
    61         String r = attrs.getValue("r");
    62 
    63         this.cx = XMLParseUtil.parseFloat(cx);
    64         this.cy = XMLParseUtil.parseFloat(cy);
    65         this.r = XMLParseUtil.parseFloat(r);
    66 
    67         build();
    68        
    69         //setBounds(this.cx - this.r, this.cy - this.r, this.r * 2.0, this.r * 2.0);
    70     }
    71 */
    72     /*
    73     public void loaderEndElement(SVGLoaderHelper helper)
    74     {
    75 //        super.loaderEndElement(helper);
    76 
    77 //        build();
    78     }
    79      */
    80    
    8169    protected void build() throws SVGException
    8270    {
    8371        super.build();
    84        
     72
    8573        StyleAttribute sty = new StyleAttribute();
    86        
    87         if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
    88        
    89         if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
    90        
    91         if (getPres(sty.setName("r"))) r = sty.getFloatValueWithUnits();
    92        
     74
     75        if (getPres(sty.setName("cx")))
     76        {
     77            cx = sty.getFloatValueWithUnits();
     78        }
     79
     80        if (getPres(sty.setName("cy")))
     81        {
     82            cy = sty.getFloatValueWithUnits();
     83        }
     84
     85        if (getPres(sty.setName("r")))
     86        {
     87            r = sty.getFloatValueWithUnits();
     88        }
     89
    9390        circle.setFrame(cx - r, cy - r, r * 2f, r * 2f);
    9491    }
     
    112109
    113110    /**
    114      * Updates all attributes in this diagram associated with a time event.
    115      * Ie, all attributes with track information.
     111     * Updates all attributes in this diagram associated with a time event. Ie,
     112     * all attributes with track information.
     113     *
    116114     * @return - true if this node has changed state as a result of the time
    117115     * update
     
    125123        StyleAttribute sty = new StyleAttribute();
    126124        boolean shapeChange = false;
    127        
     125
    128126        if (getPres(sty.setName("cx")))
    129127        {
     
    135133            }
    136134        }
    137        
     135
    138136        if (getPres(sty.setName("cy")))
    139137        {
     
    145143            }
    146144        }
    147        
     145
    148146        if (getPres(sty.setName("r")))
    149147        {
     
    155153            }
    156154        }
    157        
     155
    158156        if (shapeChange)
    159157        {
     
    162160//            return true;
    163161        }
    164        
     162
    165163        return changeState || shapeChange;
    166164    }
    167    
    168165}
    169 
    170 
    171 
  • trunk/src/com/kitfox/svg/ClipPath.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
     
    3745 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3846 */
    39 public class ClipPath extends SVGElement 
     47public class ClipPath extends SVGElement
    4048{
    4149
     50    public static final String TAG_NAME = "clippath";
    4251    public static final int CP_USER_SPACE_ON_USE = 0;
    4352    public static final int CP_OBJECT_BOUNDING_BOX = 1;
    44 
    4553    int clipPathUnits = CP_USER_SPACE_ON_USE;
    4654
    47     /** Creates a new instance of Stop */
    48     public ClipPath() {
     55    /**
     56     * Creates a new instance of Stop
     57     */
     58    public ClipPath()
     59    {
    4960    }
    50 /*
    51     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     61
     62    public String getTagName()
    5263    {
    53                 //Load style string
    54         super.loaderStartElement(helper, attrs, parent);
     64        return TAG_NAME;
     65    }
    5566
    56         String clipPathUnits = attrs.getValue("clipPathUnits");
    57 
    58         if (clipPathUnits.equals("objectBoundingBox")) this.clipPathUnits = CP_OBJECT_BOUNDING_BOX;
    59 
    60     }
    61 */
    6267    /**
    6368     * Called after the start element but before the end element to indicate
     
    6671    public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
    6772    {
    68                 super.loaderAddChild(helper, child);
    69 
    70 //        if (child instanceof ShapeElement) members.add(child);
     73        super.loaderAddChild(helper, child);
    7174    }
    7275
    73     /*
    74     public void loaderEndElement(SVGLoaderHelper helper)
    75     {
    76 //        super.loaderEndElement(helper);
    77 
    78 //        build();
    79     }
    80     */
    81    
    8276    protected void build() throws SVGException
    8377    {
    8478        super.build();
    85        
     79
    8680        StyleAttribute sty = new StyleAttribute();
    87        
     81
    8882        clipPathUnits = (getPres(sty.setName("clipPathUnits"))
    89             && sty.getStringValue().equals("objectBoundingBox")) 
    90             ? CP_OBJECT_BOUNDING_BOX 
     83            && sty.getStringValue().equals("objectBoundingBox"))
     84            ? CP_OBJECT_BOUNDING_BOX
    9185            : CP_USER_SPACE_ON_USE;
    9286    }
    93    
     87
    9488    public int getClipPathUnits()
    9589    {
     
    9993    public Shape getClipPathShape()
    10094    {
    101         if (children.size() == 0) return null;
    102         if (children.size() == 1) return ((ShapeElement)children.get(0)).getShape();
     95        if (children.isEmpty())
     96        {
     97            return null;
     98        }
     99        if (children.size() == 1)
     100        {
     101            return ((ShapeElement) children.get(0)).getShape();
     102        }
    103103
    104104        Area clipArea = null;
    105105        for (Iterator it = children.iterator(); it.hasNext();)
    106106        {
    107             ShapeElement se = (ShapeElement)it.next();
     107            ShapeElement se = (ShapeElement) it.next();
    108108
    109109            if (clipArea == null)
    110110            {
    111111                Shape shape = se.getShape();
    112                 if (shape != null) clipArea = new Area(se.getShape());
     112                if (shape != null)
     113                {
     114                    clipArea = new Area(se.getShape());
     115                }
    113116                continue;
    114117            }
    115118
    116119            Shape shape = se.getShape();
    117             if (shape != null) clipArea.intersect(new Area(shape));
     120            if (shape != null)
     121            {
     122                clipArea.intersect(new Area(shape));
     123            }
    118124        }
    119125
     
    122128
    123129    /**
    124      * Updates all attributes in this diagram associated with a time event.
    125      * Ie, all attributes with track information.
     130     * Updates all attributes in this diagram associated with a time event. Ie,
     131     * all attributes with track information.
     132     *
    126133     * @return - true if this node has changed state as a result of the time
    127134     * update
     
    129136    public boolean updateTime(double curTime) throws SVGException
    130137    {
    131 //        if (trackManager.getNumTracks() == 0) return false;
    132 
    133138        //Get current values for parameters
    134139        StyleAttribute sty = new StyleAttribute();
    135140        boolean shapeChange = false;
    136141
    137        
     142
    138143        if (getPres(sty.setName("clipPathUnits")))
    139144        {
    140145            String newUnitsStrn = sty.getStringValue();
    141146            int newUnits = newUnitsStrn.equals("objectBoundingBox")
    142                 ? CP_OBJECT_BOUNDING_BOX 
     147                ? CP_OBJECT_BOUNDING_BOX
    143148                : CP_USER_SPACE_ON_USE;
    144                
     149
    145150            if (newUnits != clipPathUnits)
    146151            {
  • trunk/src/com/kitfox/svg/Defs.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
    30 import java.awt.*;
    31 import java.awt.geom.*;
    32 import java.util.*;
    33 
    34 import com.kitfox.svg.xml.*;
    35 import org.xml.sax.*;
     38import java.util.Iterator;
    3639
    3740/**
     
    4245{
    4346
    44     /** Creates a new instance of Stop */
    45     public Defs() {
     47    public static final String TAG_NAME = "defs";
     48
     49    /**
     50     * Creates a new instance of Stop
     51     */
     52    public Defs()
     53    {
     54    }
     55
     56    public String getTagName()
     57    {
     58        return TAG_NAME;
    4659    }
    4760
     
    5265    public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
    5366    {
    54                 super.loaderAddChild(helper, child);
     67        super.loaderAddChild(helper, child);
    5568
    5669//        members.add(child);
     
    6275        for (Iterator it = children.iterator(); it.hasNext();)
    6376        {
    64             SVGElement ele = (SVGElement)it.next();
     77            SVGElement ele = (SVGElement) it.next();
    6578            stateChange = stateChange || ele.updateTime(curTime);
    6679        }
    67        
     80
    6881        return super.updateTime(curTime) || stateChange;
    6982    }
  • trunk/src/com/kitfox/svg/Desc.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 September 19, 2004, 1:56 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3442 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3543 */
    36 public class Desc extends SVGElement {
     44public class Desc extends SVGElement
     45{
    3746
     47    public static final String TAG_NAME = "desc";
    3848    StringBuffer text = new StringBuffer();
    3949
    40     /** Creates a new instance of Stop */
    41     public Desc() {
     50    /**
     51     * Creates a new instance of Stop
     52     */
     53    public Desc()
     54    {
     55    }
     56
     57    public String getTagName()
     58    {
     59        return TAG_NAME;
    4260    }
    4361
     
    5068    }
    5169
    52     public String getText() { return text.toString(); }
    53    
     70    public String getText()
     71    {
     72        return text.toString();
     73    }
     74
    5475    public boolean updateTime(double curTime)
    5576    {
  • trunk/src/com/kitfox/svg/Ellipse.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import com.kitfox.svg.xml.*;
    32 import org.xml.sax.*;
    33 
    34 import java.awt.*;
    35 import java.awt.geom.*;
     39import java.awt.Graphics2D;
     40import java.awt.Shape;
     41import java.awt.geom.Ellipse2D;
     42import java.awt.geom.Rectangle2D;
    3643
    3744/**
     
    3946 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4047 */
    41 public class Ellipse extends ShapeElement {
     48public class Ellipse extends ShapeElement
     49{
    4250
     51    public static final String TAG_NAME = "ellipse";
    4352    float cx = 0.0f;
    4453    float cy = 0.0f;
    4554    float rx = 0.0f;
    4655    float ry = 0.0f;
    47 
    4856    Ellipse2D.Float ellipse = new Ellipse2D.Float();
    4957
    50     /** Creates a new instance of Rect */
    51     public Ellipse() {
     58    /**
     59     * Creates a new instance of Rect
     60     */
     61    public Ellipse()
     62    {
    5263    }
    53 /*
    54     protected void init(String idIn, Style parentStyle, String cx, String cy, String rx, String ry) {
    55         super.init(idIn, parentStyle);
    5664
    57         this.cx = parseDouble(cx);
    58         this.cy = parseDouble(cy);
    59         this.rx = parseDouble(rx);
    60         this.ry = parseDouble(ry);
     65    public String getTagName()
     66    {
     67        return TAG_NAME;
     68    }
    6169
    62         setBounds(this.cx - this.rx, this.cy - this.ry, this.rx * 2.0, this.ry * 2.0);
    63     }
    64 */
    65     /*
    66     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    67     {
    68                 //Load style string
    69         super.loaderStartElement(helper, attrs, parent);
    70 
    71         String cx = attrs.getValue("cx");
    72         String cy = attrs.getValue("cy");
    73         String rx = attrs.getValue("rx");
    74         String ry = attrs.getValue("ry");
    75 
    76         this.cx = XMLParseUtil.parseDouble(cx);
    77         this.cy = XMLParseUtil.parseDouble(cy);
    78         this.rx = XMLParseUtil.parseDouble(rx);
    79         this.ry = XMLParseUtil.parseDouble(ry);
    80 
    81         build();
    82     }
    83     */
    84    
    85     /*
    86     public void loaderEndElement(SVGLoaderHelper helper)
    87     {
    88         super.loaderEndElement(helper);
    89 
    90         build();
    91     }
    92      */
    93    
    9470    protected void build() throws SVGException
    9571    {
    9672        super.build();
    97        
     73
    9874        StyleAttribute sty = new StyleAttribute();
    99        
    100         if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
    101        
    102         if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
    103        
    104         if (getPres(sty.setName("rx"))) rx = sty.getFloatValueWithUnits();
    105        
    106         if (getPres(sty.setName("ry"))) ry = sty.getFloatValueWithUnits();
    107        
     75
     76        if (getPres(sty.setName("cx")))
     77        {
     78            cx = sty.getFloatValueWithUnits();
     79        }
     80
     81        if (getPres(sty.setName("cy")))
     82        {
     83            cy = sty.getFloatValueWithUnits();
     84        }
     85
     86        if (getPres(sty.setName("rx")))
     87        {
     88            rx = sty.getFloatValueWithUnits();
     89        }
     90
     91        if (getPres(sty.setName("ry")))
     92        {
     93            ry = sty.getFloatValueWithUnits();
     94        }
     95
    10896        ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f);
    10997    }
     
    125113        return boundsToParent(includeStrokeInBounds(ellipse.getBounds2D()));
    126114    }
    127    
     115
    128116    /**
    129      * Updates all attributes in this diagram associated with a time event.
    130      * Ie, all attributes with track information.
     117     * Updates all attributes in this diagram associated with a time event. Ie,
     118     * all attributes with track information.
     119     *
    131120     * @return - true if this node has changed state as a result of the time
    132121     * update
     
    140129        StyleAttribute sty = new StyleAttribute();
    141130        boolean shapeChange = false;
    142        
     131
    143132        if (getPres(sty.setName("cx")))
    144133        {
     
    150139            }
    151140        }
    152        
     141
    153142        if (getPres(sty.setName("cy")))
    154143        {
     
    160149            }
    161150        }
    162        
     151
    163152        if (getPres(sty.setName("rx")))
    164153        {
     
    170159            }
    171160        }
    172        
     161
    173162        if (getPres(sty.setName("ry")))
    174163        {
     
    180169            }
    181170        }
    182        
     171
    183172        if (shapeChange)
    184173        {
     
    187176//            return true;
    188177        }
    189        
     178
    190179        return changeState || shapeChange;
    191180    }
  • trunk/src/com/kitfox/svg/FeDistantLight.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    32 import java.awt.geom.*;
    33 import java.net.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.xml.*;
    37 import org.xml.sax.*;
    3839
    3940/**
     
    4142 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4243 */
    43 public class FeDistantLight extends FeLight 
     44public class FeDistantLight extends FeLight
    4445{
     46
     47    public static final String TAG_NAME = "fedistantlight";
    4548    float azimuth = 0f;
    4649    float elevation = 0f;
    47    
    4850
    49     /** Creates a new instance of FillElement */
    50     public FeDistantLight() {
     51    /**
     52     * Creates a new instance of FillElement
     53     */
     54    public FeDistantLight()
     55    {
    5156    }
    5257
    53    
     58    public String getTagName()
     59    {
     60        return TAG_NAME;
     61    }
     62
    5463    protected void build() throws SVGException
    5564    {
    5665        super.build();
    57        
     66
    5867        StyleAttribute sty = new StyleAttribute();
    5968        String strn;
    60        
    61         if (getPres(sty.setName("azimuth"))) azimuth = sty.getFloatValueWithUnits();
    62        
    63         if (getPres(sty.setName("elevation"))) elevation = sty.getFloatValueWithUnits();
     69
     70        if (getPres(sty.setName("azimuth")))
     71        {
     72            azimuth = sty.getFloatValueWithUnits();
     73        }
     74
     75        if (getPres(sty.setName("elevation")))
     76        {
     77            elevation = sty.getFloatValueWithUnits();
     78        }
    6479    }
    6580
    66     public float getAzimuth() { return azimuth; }
    67     public float getElevation() { return elevation; }
    68    
     81    public float getAzimuth()
     82    {
     83        return azimuth;
     84    }
     85
     86    public float getElevation()
     87    {
     88        return elevation;
     89    }
     90
    6991    public boolean updateTime(double curTime) throws SVGException
    7092    {
     
    7496        StyleAttribute sty = new StyleAttribute();
    7597        boolean stateChange = false;
    76        
     98
    7799        if (getPres(sty.setName("azimuth")))
    78100        {
     
    84106            }
    85107        }
    86        
     108
    87109        if (getPres(sty.setName("elevation")))
    88110        {
     
    94116            }
    95117        }
    96        
     118
    97119        return stateChange;
    98120    }
    99121}
    100 
  • trunk/src/com/kitfox/svg/FeLight.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    29 
    30 import java.awt.*;
    31 import java.awt.geom.*;
    32 import java.net.*;
    33 import java.util.*;
    34 
    35 import com.kitfox.svg.xml.*;
    36 import org.xml.sax.*;
    3737
    3838/**
     
    4040 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4141 */
    42 abstract public class FeLight extends FilterEffects 
     42abstract public class FeLight extends FilterEffects
    4343{
    4444
    45     /** Creates a new instance of FillElement */
    46     public FeLight() {
     45    public static final String TAG_NAME = "feLight";
     46
     47    /**
     48     * Creates a new instance of FillElement
     49     */
     50    public FeLight()
     51    {
    4752    }
    4853
     54    public String getTagName()
     55    {
     56        return TAG_NAME;
     57    }
    4958}
    50 
  • trunk/src/com/kitfox/svg/FePointLight.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    32 import java.awt.geom.*;
    33 import java.net.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.xml.*;
    37 import org.xml.sax.*;
    3839
    3940/**
     
    4142 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4243 */
    43 public class FePointLight extends FeLight 
     44public class FePointLight extends FeLight
    4445{
     46
     47    public static final String TAG_NAME = "fepointlight";
    4548    float x = 0f;
    4649    float y = 0f;
    4750    float z = 0f;
    48    
    4951
    50     /** Creates a new instance of FillElement */
    51     public FePointLight() {
     52    /**
     53     * Creates a new instance of FillElement
     54     */
     55    public FePointLight()
     56    {
    5257    }
    5358
    54    
     59    public String getTagName()
     60    {
     61        return TAG_NAME;
     62    }
     63
    5564    protected void build() throws SVGException
    5665    {
    5766        super.build();
    58        
     67
    5968        StyleAttribute sty = new StyleAttribute();
    6069        String strn;
    61        
    62         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    63        
    64         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    65        
    66         if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits();
     70
     71        if (getPres(sty.setName("x")))
     72        {
     73            x = sty.getFloatValueWithUnits();
     74        }
     75
     76        if (getPres(sty.setName("y")))
     77        {
     78            y = sty.getFloatValueWithUnits();
     79        }
     80
     81        if (getPres(sty.setName("z")))
     82        {
     83            z = sty.getFloatValueWithUnits();
     84        }
    6785    }
    6886
    69     public float getX() { return x; }
    70     public float getY() { return y; }
    71     public float getZ() { return z; }
    72    
     87    public float getX()
     88    {
     89        return x;
     90    }
     91
     92    public float getY()
     93    {
     94        return y;
     95    }
     96
     97    public float getZ()
     98    {
     99        return z;
     100    }
     101
    73102    public boolean updateTime(double curTime) throws SVGException
    74103    {
     
    78107        StyleAttribute sty = new StyleAttribute();
    79108        boolean stateChange = false;
    80        
     109
    81110        if (getPres(sty.setName("x")))
    82111        {
     
    88117            }
    89118        }
    90        
     119
    91120        if (getPres(sty.setName("y")))
    92121        {
     
    98127            }
    99128        }
    100        
     129
    101130        if (getPres(sty.setName("z")))
    102131        {
     
    108137            }
    109138        }
    110        
     139
    111140        return stateChange;
    112141    }
    113142}
    114 
  • trunk/src/com/kitfox/svg/FeSpotLight.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    32 import java.awt.geom.*;
    33 import java.net.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.xml.*;
    37 import org.xml.sax.*;
    3839
    3940/**
     
    4142 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4243 */
    43 public class FeSpotLight extends FeLight 
     44public class FeSpotLight extends FeLight
    4445{
     46
     47    public static final String TAG_NAME = "fespotlight";
    4548    float x = 0f;
    4649    float y = 0f;
     
    5154    float specularComponent = 0f;
    5255    float limitingConeAngle = 0f;
    53    
    54 
    55     /** Creates a new instance of FillElement */
    56     public FeSpotLight() {
    57     }
    58 
    59    
     56
     57    /**
     58     * Creates a new instance of FillElement
     59     */
     60    public FeSpotLight()
     61    {
     62    }
     63
     64    public String getTagName()
     65    {
     66        return TAG_NAME;
     67    }
     68
    6069    protected void build() throws SVGException
    6170    {
    6271        super.build();
    63        
     72
    6473        StyleAttribute sty = new StyleAttribute();
    6574        String strn;
    66        
    67         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    68         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    69         if (getPres(sty.setName("z"))) z = sty.getFloatValueWithUnits();
    70         if (getPres(sty.setName("pointsAtX"))) pointsAtX = sty.getFloatValueWithUnits();
    71         if (getPres(sty.setName("pointsAtY"))) pointsAtY = sty.getFloatValueWithUnits();
    72         if (getPres(sty.setName("pointsAtZ"))) pointsAtZ = sty.getFloatValueWithUnits();
    73         if (getPres(sty.setName("specularComponent"))) specularComponent = sty.getFloatValueWithUnits();
    74         if (getPres(sty.setName("limitingConeAngle"))) limitingConeAngle = sty.getFloatValueWithUnits();
    75     }
    76 
    77     public float getX() { return x; }
    78     public float getY() { return y; }
    79     public float getZ() { return z; }
    80     public float getPointsAtX() { return pointsAtX; }
    81     public float getPointsAtY() { return pointsAtY; }
    82     public float getPointsAtZ() { return pointsAtZ; }
    83     public float getSpecularComponent() { return specularComponent; }
    84     public float getLimitingConeAngle() { return limitingConeAngle; }
    85    
     75
     76        if (getPres(sty.setName("x")))
     77        {
     78            x = sty.getFloatValueWithUnits();
     79        }
     80        if (getPres(sty.setName("y")))
     81        {
     82            y = sty.getFloatValueWithUnits();
     83        }
     84        if (getPres(sty.setName("z")))
     85        {
     86            z = sty.getFloatValueWithUnits();
     87        }
     88        if (getPres(sty.setName("pointsAtX")))
     89        {
     90            pointsAtX = sty.getFloatValueWithUnits();
     91        }
     92        if (getPres(sty.setName("pointsAtY")))
     93        {
     94            pointsAtY = sty.getFloatValueWithUnits();
     95        }
     96        if (getPres(sty.setName("pointsAtZ")))
     97        {
     98            pointsAtZ = sty.getFloatValueWithUnits();
     99        }
     100        if (getPres(sty.setName("specularComponent")))
     101        {
     102            specularComponent = sty.getFloatValueWithUnits();
     103        }
     104        if (getPres(sty.setName("limitingConeAngle")))
     105        {
     106            limitingConeAngle = sty.getFloatValueWithUnits();
     107        }
     108    }
     109
     110    public float getX()
     111    {
     112        return x;
     113    }
     114
     115    public float getY()
     116    {
     117        return y;
     118    }
     119
     120    public float getZ()
     121    {
     122        return z;
     123    }
     124
     125    public float getPointsAtX()
     126    {
     127        return pointsAtX;
     128    }
     129
     130    public float getPointsAtY()
     131    {
     132        return pointsAtY;
     133    }
     134
     135    public float getPointsAtZ()
     136    {
     137        return pointsAtZ;
     138    }
     139
     140    public float getSpecularComponent()
     141    {
     142        return specularComponent;
     143    }
     144
     145    public float getLimitingConeAngle()
     146    {
     147        return limitingConeAngle;
     148    }
     149
    86150    public boolean updateTime(double curTime) throws SVGException
    87151    {
     
    91155        StyleAttribute sty = new StyleAttribute();
    92156        boolean stateChange = false;
    93        
     157
    94158        if (getPres(sty.setName("x")))
    95159        {
     
    101165            }
    102166        }
    103        
     167
    104168        if (getPres(sty.setName("y")))
    105169        {
     
    111175            }
    112176        }
    113        
     177
    114178        if (getPres(sty.setName("z")))
    115179        {
     
    121185            }
    122186        }
    123        
     187
    124188        if (getPres(sty.setName("pointsAtX")))
    125189        {
     
    131195            }
    132196        }
    133        
     197
    134198        if (getPres(sty.setName("pointsAtY")))
    135199        {
     
    141205            }
    142206        }
    143        
     207
    144208        if (getPres(sty.setName("pointsAtZ")))
    145209        {
     
    151215            }
    152216        }
    153        
     217
    154218        if (getPres(sty.setName("specularComponent")))
    155219        {
     
    161225            }
    162226        }
    163        
     227
    164228        if (getPres(sty.setName("limitingConeAngle")))
    165229        {
     
    171235            }
    172236        }
    173        
     237
    174238        return stateChange;
    175239    }
    176240}
    177 
  • trunk/src/com/kitfox/svg/FillElement.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3543 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3644 */
    37 abstract public class FillElement extends SVGElement {
    38 
    39     /** Creates a new instance of FillElement */
    40     public FillElement() {
     45abstract public class FillElement extends SVGElement
     46{
     47    /**
     48     * Creates a new instance of FillElement
     49     */
     50    public FillElement()
     51    {
    4152    }
    4253
    4354    /**
    44      * Requests the paint defined by this element.  Passes in information
    45      * to allow paint to be customized
     55     * Requests the paint defined by this element. Passes in information to
     56     * allow paint to be customized
     57     *
    4658     * @param bounds - bounding box of shape being rendered
    47      * @param xform - The current transformation that the shape is being rendered
    48      * under.
     59     * @param xform - The current transformation that the shape is being
     60     * rendered under.
    4961     */
    5062    abstract public Paint getPaint(Rectangle2D bounds, AffineTransform xform);
  • trunk/src/com/kitfox/svg/Filter.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    30 import java.awt.geom.*;
    31 import java.net.*;
    32 import java.util.*;
    33 
    34 import com.kitfox.svg.xml.*;
     38import com.kitfox.svg.xml.StyleAttribute;
     39import java.awt.geom.Point2D;
     40import java.net.URI;
     41import java.net.URL;
     42import java.util.ArrayList;
    3543
    3644/**
     
    3846 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3947 */
    40 public class Filter extends SVGElement 
     48public class Filter extends SVGElement
    4149{
     50
     51    public static final String TAG_NAME = "filter";
    4252    public static final int FU_OBJECT_BOUNDING_BOX = 0;
    4353    public static final int FU_USER_SPACE_ON_USE = 1;
    44 
    4554    protected int filterUnits = FU_OBJECT_BOUNDING_BOX;
    46    
    4755    public static final int PU_OBJECT_BOUNDING_BOX = 0;
    4856    public static final int PU_USER_SPACE_ON_USE = 1;
    49 
    5057    protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX;
    51    
    5258    float x = 0f;
    5359    float y = 0f;
    5460    float width = 1f;
    5561    float height = 1f;
    56    
    5762    Point2D filterRes = new Point2D.Double();
    58    
    5963    URL href = null;
    60 
    6164    final ArrayList filterEffects = new ArrayList();
    6265
    63     /** Creates a new instance of FillElement */
    64     public Filter() {
     66    /**
     67     * Creates a new instance of FillElement
     68     */
     69    public Filter()
     70    {
     71    }
     72
     73    public String getTagName()
     74    {
     75        return TAG_NAME;
    6576    }
    6677
     
    7889        }
    7990    }
    80    
     91
    8192    protected void build() throws SVGException
    8293    {
    8394        super.build();
    84        
     95
    8596        StyleAttribute sty = new StyleAttribute();
    8697        String strn;
    87        
     98
    8899        if (getPres(sty.setName("filterUnits")))
    89100        {
    90101            strn = sty.getStringValue().toLowerCase();
    91             if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
    92             else filterUnits = FU_OBJECT_BOUNDING_BOX;
     102            if (strn.equals("userspaceonuse"))
     103            {
     104                filterUnits = FU_USER_SPACE_ON_USE;
     105            } else
     106            {
     107                filterUnits = FU_OBJECT_BOUNDING_BOX;
     108            }
    93109        }
    94110
     
    96112        {
    97113            strn = sty.getStringValue().toLowerCase();
    98             if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
    99             else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
    100         }
    101 
    102         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    103 
    104         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    105 
    106         if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
    107 
    108         if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
    109 
    110         try {
     114            if (strn.equals("userspaceonuse"))
     115            {
     116                primitiveUnits = PU_USER_SPACE_ON_USE;
     117            } else
     118            {
     119                primitiveUnits = PU_OBJECT_BOUNDING_BOX;
     120            }
     121        }
     122
     123        if (getPres(sty.setName("x")))
     124        {
     125            x = sty.getFloatValueWithUnits();
     126        }
     127
     128        if (getPres(sty.setName("y")))
     129        {
     130            y = sty.getFloatValueWithUnits();
     131        }
     132
     133        if (getPres(sty.setName("width")))
     134        {
     135            width = sty.getFloatValueWithUnits();
     136        }
     137
     138        if (getPres(sty.setName("height")))
     139        {
     140            height = sty.getFloatValueWithUnits();
     141        }
     142
     143        try
     144        {
    111145            if (getPres(sty.setName("xlink:href")))
    112146            {
     
    114148                href = src.toURL();
    115149            }
    116         }
    117         catch (Exception e)
     150        } catch (Exception e)
    118151        {
    119152            throw new SVGException(e);
     
    122155    }
    123156
    124     public float getX() { return x; }
    125     public float getY() { return y; }
    126     public float getWidth() { return width; }
    127     public float getHeight() { return height; }
    128    
     157    public float getX()
     158    {
     159        return x;
     160    }
     161
     162    public float getY()
     163    {
     164        return y;
     165    }
     166
     167    public float getWidth()
     168    {
     169        return width;
     170    }
     171
     172    public float getHeight()
     173    {
     174        return height;
     175    }
     176
    129177    public boolean updateTime(double curTime) throws SVGException
    130178    {
     
    134182        StyleAttribute sty = new StyleAttribute();
    135183        boolean stateChange = false;
    136        
     184
    137185        if (getPres(sty.setName("x")))
    138186        {
     
    144192            }
    145193        }
    146        
     194
    147195        if (getPres(sty.setName("y")))
    148196        {
     
    154202            }
    155203        }
    156        
     204
    157205        if (getPres(sty.setName("width")))
    158206        {
     
    164212            }
    165213        }
    166        
     214
    167215        if (getPres(sty.setName("height")))
    168216        {
     
    174222            }
    175223        }
    176        
    177         try {
     224
     225        try
     226        {
    178227            if (getPres(sty.setName("xlink:href")))
    179228            {
    180229                URI src = sty.getURIValue(getXMLBase());
    181230                URL newVal = src.toURL();
    182                
     231
    183232                if (!newVal.equals(href))
    184233                {
     
    187236                }
    188237            }
    189         }
    190         catch (Exception e)
     238        } catch (Exception e)
    191239        {
    192240            throw new SVGException(e);
     
    197245            int newVal;
    198246            String strn = sty.getStringValue().toLowerCase();
    199             if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
    200             else newVal = FU_OBJECT_BOUNDING_BOX;
     247            if (strn.equals("userspaceonuse"))
     248            {
     249                newVal = FU_USER_SPACE_ON_USE;
     250            } else
     251            {
     252                newVal = FU_OBJECT_BOUNDING_BOX;
     253            }
    201254            if (newVal != filterUnits)
    202255            {
     
    210263            int newVal;
    211264            String strn = sty.getStringValue().toLowerCase();
    212             if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
    213             else newVal = PU_OBJECT_BOUNDING_BOX;
     265            if (strn.equals("userspaceonuse"))
     266            {
     267                newVal = PU_USER_SPACE_ON_USE;
     268            } else
     269            {
     270                newVal = PU_OBJECT_BOUNDING_BOX;
     271            }
    214272            if (newVal != filterUnits)
    215273            {
     
    219277        }
    220278
    221        
    222        
     279
     280
    223281        return stateChange;
    224282    }
    225283}
    226 
  • trunk/src/com/kitfox/svg/FilterEffects.java

    r4256 r6002  
    11/*
    2  * FillElement.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 March 18, 2004, 6:52 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    32 import java.awt.geom.*;
    33 import java.net.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.xml.*;
    37 import org.xml.sax.*;
     39import java.net.URI;
     40import java.net.URL;
    3841
    3942/**
     
    4144 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4245 */
    43 public class FilterEffects extends SVGElement 
     46public class FilterEffects extends SVGElement
    4447{
     48    public static final String TAG_NAME = "filtereffects";
     49   
    4550    public static final int FP_SOURCE_GRAPHIC = 0;
    4651    public static final int FP_SOURCE_ALPHA = 1;
     
    5055    public static final int FP_STROKE_PAINT = 5;
    5156    public static final int FP_CUSTOM = 5;
    52 
    5357    private int filterPrimitiveTypeIn;
    5458    private String filterPrimitiveRefIn;
    55    
    56    
    5759    float x = 0f;
    5860    float y = 0f;
    5961    float width = 1f;
    6062    float height = 1f;
    61    
    6263    String result = "defaultFilterName";
    63    
    64    
    65    
    6664    URL href = null;
    6765
    68 
    69     /** Creates a new instance of FillElement */
    70     public FilterEffects() {
     66    /**
     67     * Creates a new instance of FillElement
     68     */
     69    public FilterEffects()
     70    {
     71    }
     72
     73    public String getTagName()
     74    {
     75        return TAG_NAME;
    7176    }
    7277
     
    8489        }
    8590    }
    86    
     91
    8792    protected void build() throws SVGException
    8893    {
    8994        super.build();
    90        
     95
    9196        StyleAttribute sty = new StyleAttribute();
    9297        String strn;
    9398        /*
    94         if (getPres(sty.setName("filterUnits")))
    95         {
    96             strn = sty.getStringValue().toLowerCase();
    97             if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
    98             else filterUnits = FU_OBJECT_BOUNDING_BOX;
    99         }
    100 
    101         if (getPres(sty.setName("primitiveUnits")))
    102         {
    103             strn = sty.getStringValue().toLowerCase();
    104             if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
    105             else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
    106         }
    107 
    108         if (getPres(sty.setName("x"))) x = sty.getFloatValue();
    109 
    110         if (getPres(sty.setName("y"))) y = sty.getFloatValue();
    111 
    112         if (getPres(sty.setName("width"))) width = sty.getFloatValue();
    113 
    114         if (getPres(sty.setName("height"))) height = sty.getFloatValue();
    115 
    116         try {
    117             if (getPres(sty.setName("xlink:href")))
    118             {
    119                 URI src = sty.getURIValue(getXMLBase());
    120                 href = src.toURL();
    121             }
    122         }
    123         catch (Exception e)
    124         {
    125             throw new SVGException(e);
    126         }
    127 */
    128     }
    129 
    130     public float getX() { return x; }
    131     public float getY() { return y; }
    132     public float getWidth() { return width; }
    133     public float getHeight() { return height; }
    134    
     99         if (getPres(sty.setName("filterUnits")))
     100         {
     101         strn = sty.getStringValue().toLowerCase();
     102         if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
     103         else filterUnits = FU_OBJECT_BOUNDING_BOX;
     104         }
     105
     106         if (getPres(sty.setName("primitiveUnits")))
     107         {
     108         strn = sty.getStringValue().toLowerCase();
     109         if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
     110         else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
     111         }
     112
     113         if (getPres(sty.setName("x"))) x = sty.getFloatValue();
     114
     115         if (getPres(sty.setName("y"))) y = sty.getFloatValue();
     116
     117         if (getPres(sty.setName("width"))) width = sty.getFloatValue();
     118
     119         if (getPres(sty.setName("height"))) height = sty.getFloatValue();
     120
     121         try {
     122         if (getPres(sty.setName("xlink:href")))
     123         {
     124         URI src = sty.getURIValue(getXMLBase());
     125         href = src.toURL();
     126         }
     127         }
     128         catch (Exception e)
     129         {
     130         throw new SVGException(e);
     131         }
     132         */
     133    }
     134
     135    public float getX()
     136    {
     137        return x;
     138    }
     139
     140    public float getY()
     141    {
     142        return y;
     143    }
     144
     145    public float getWidth()
     146    {
     147        return width;
     148    }
     149
     150    public float getHeight()
     151    {
     152        return height;
     153    }
     154
    135155    public boolean updateTime(double curTime) throws SVGException
    136156    {
     
    140160        StyleAttribute sty = new StyleAttribute();
    141161        boolean stateChange = false;
    142        
     162
    143163        if (getPres(sty.setName("x")))
    144164        {
     
    150170            }
    151171        }
    152        
     172
    153173        if (getPres(sty.setName("y")))
    154174        {
     
    160180            }
    161181        }
    162        
     182
    163183        if (getPres(sty.setName("width")))
    164184        {
     
    170190            }
    171191        }
    172        
     192
    173193        if (getPres(sty.setName("height")))
    174194        {
     
    180200            }
    181201        }
    182        
    183         try {
     202
     203        try
     204        {
    184205            if (getPres(sty.setName("xlink:href")))
    185206            {
    186207                URI src = sty.getURIValue(getXMLBase());
    187208                URL newVal = src.toURL();
    188                
     209
    189210                if (!newVal.equals(href))
    190211                {
     
    193214                }
    194215            }
    195         }
    196         catch (Exception e)
     216        } catch (Exception e)
    197217        {
    198218            throw new SVGException(e);
     
    200220
    201221        /*
    202         if (getPres(sty.setName("filterUnits")))
    203         {
    204             int newVal;
    205             String strn = sty.getStringValue().toLowerCase();
    206             if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
    207             else newVal = FU_OBJECT_BOUNDING_BOX;
    208             if (newVal != filterUnits)
    209             {
    210                 filterUnits = newVal;
    211                 stateChange = true;
    212             }
    213         }
    214 
    215         if (getPres(sty.setName("primitiveUnits")))
    216         {
    217             int newVal;
    218             String strn = sty.getStringValue().toLowerCase();
    219             if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
    220             else newVal = PU_OBJECT_BOUNDING_BOX;
    221             if (newVal != filterUnits)
    222             {
    223                 primitiveUnits = newVal;
    224                 stateChange = true;
    225             }
    226         }
    227 
    228         */
    229        
     222         if (getPres(sty.setName("filterUnits")))
     223         {
     224         int newVal;
     225         String strn = sty.getStringValue().toLowerCase();
     226         if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
     227         else newVal = FU_OBJECT_BOUNDING_BOX;
     228         if (newVal != filterUnits)
     229         {
     230         filterUnits = newVal;
     231         stateChange = true;
     232         }
     233         }
     234
     235         if (getPres(sty.setName("primitiveUnits")))
     236         {
     237         int newVal;
     238         String strn = sty.getStringValue().toLowerCase();
     239         if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
     240         else newVal = PU_OBJECT_BOUNDING_BOX;
     241         if (newVal != filterUnits)
     242         {
     243         primitiveUnits = newVal;
     244         stateChange = true;
     245         }
     246         }
     247
     248         */
     249
    230250        return stateChange;
    231251    }
    232252}
    233 
  • trunk/src/com/kitfox/svg/Font.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.xml.StyleAttribute;
    31 import com.kitfox.svg.xml.*;
    32 import org.xml.sax.*;
    33 
    34 import java.util.*;
     39import java.util.HashMap;
    3540
    3641/**
     
    4449public class Font extends SVGElement
    4550{
     51
     52    public static final String TAG_NAME = "font";
    4653    int horizOriginX = 0;
    4754    int horizOriginY = 0;
     
    5057    int vertOriginY = -1;  //Defaults to font's ascent
    5158    int vertAdvY = -1;  //Defaults to one 'em'.  See font-face
    52 
    5359    FontFace fontFace = null;
    5460    MissingGlyph missingGlyph = null;
    5561    final HashMap glyphs = new HashMap();
    5662
    57     /** Creates a new instance of Font */
     63    /**
     64     * Creates a new instance of Font
     65     */
    5866    public Font()
    5967    {
    6068    }
    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 horizOriginX = attrs.getValue("horiz-origin-x");
    68         String horizOriginY = attrs.getValue("horiz-origin-y");
    69         String horizAdvX = attrs.getValue("horiz-adv-x");
    70         String vertOriginX = attrs.getValue("vert-origin-x");
    71         String vertOriginY = attrs.getValue("vert-origin-y");
    72         String vertAdvY = attrs.getValue("vert-adv-y");
    73 
    74         if (horizOriginX != null) this.horizOriginX = XMLParseUtil.parseInt(horizOriginX);
    75         if (horizOriginY != null) this.horizOriginY = XMLParseUtil.parseInt(horizOriginY);
    76         if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX);
    77         if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX);
    78         if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY);
    79         if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY);
    80 
    81     }
    82 */
     69
     70    public String getTagName()
     71    {
     72        return TAG_NAME;
     73    }
     74
    8375    /**
    8476     * Called after the start element but before the end element to indicate
     
    8779    public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
    8880    {
    89                 super.loaderAddChild(helper, child);
     81        super.loaderAddChild(helper, child);
    9082
    9183        if (child instanceof Glyph)
    9284        {
    93             glyphs.put(((Glyph)child).getUnicode(), child);
    94         }
    95         else if (child instanceof MissingGlyph)
    96         {
    97             missingGlyph = (MissingGlyph)child;
    98         }
    99         else if (child instanceof FontFace)
    100         {
    101             fontFace = (FontFace)child;
     85            glyphs.put(((Glyph) child).getUnicode(), child);
     86        } else if (child instanceof MissingGlyph)
     87        {
     88            missingGlyph = (MissingGlyph) child;
     89        } else if (child instanceof FontFace)
     90        {
     91            fontFace = (FontFace) child;
    10292        }
    10393    }
     
    10898
    10999        //build();
    110        
     100
    111101        helper.universe.registerFont(this);
    112102    }
    113    
     103
    114104    protected void build() throws SVGException
    115105    {
    116106        super.build();
    117        
     107
    118108        StyleAttribute sty = new StyleAttribute();
    119        
    120         if (getPres(sty.setName("horiz-origin-x"))) horizOriginX = sty.getIntValue();
    121        
    122         if (getPres(sty.setName("horiz-origin-y"))) horizOriginY = sty.getIntValue();
    123        
    124         if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue();
    125        
    126         if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue();
    127        
    128         if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue();
    129        
    130         if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue();
    131     }
    132    
    133     public FontFace getFontFace() { return fontFace; }
     109
     110        if (getPres(sty.setName("horiz-origin-x")))
     111        {
     112            horizOriginX = sty.getIntValue();
     113        }
     114
     115        if (getPres(sty.setName("horiz-origin-y")))
     116        {
     117            horizOriginY = sty.getIntValue();
     118        }
     119
     120        if (getPres(sty.setName("horiz-adv-x")))
     121        {
     122            horizAdvX = sty.getIntValue();
     123        }
     124
     125        if (getPres(sty.setName("vert-origin-x")))
     126        {
     127            vertOriginX = sty.getIntValue();
     128        }
     129
     130        if (getPres(sty.setName("vert-origin-y")))
     131        {
     132            vertOriginY = sty.getIntValue();
     133        }
     134
     135        if (getPres(sty.setName("vert-adv-y")))
     136        {
     137            vertAdvY = sty.getIntValue();
     138        }
     139    }
     140
     141    public FontFace getFontFace()
     142    {
     143        return fontFace;
     144    }
    134145
    135146    public MissingGlyph getGlyph(String unicode)
    136147    {
    137         Glyph retVal = (Glyph)glyphs.get(unicode);
    138         if (retVal == null) return missingGlyph;
     148        Glyph retVal = (Glyph) glyphs.get(unicode);
     149        if (retVal == null)
     150        {
     151            return missingGlyph;
     152        }
    139153        return retVal;
    140154    }
    141155
    142     public int getHorizOriginX() { return horizOriginX; }
    143     public int getHorizOriginY() { return horizOriginY; }
    144     public int getHorizAdvX() { return horizAdvX; }
     156    public int getHorizOriginX()
     157    {
     158        return horizOriginX;
     159    }
     160
     161    public int getHorizOriginY()
     162    {
     163        return horizOriginY;
     164    }
     165
     166    public int getHorizAdvX()
     167    {
     168        return horizAdvX;
     169    }
    145170
    146171    public int getVertOriginX()
    147172    {
    148         if (vertOriginX != -1) return vertOriginX;
     173        if (vertOriginX != -1)
     174        {
     175            return vertOriginX;
     176        }
    149177        vertOriginX = getHorizAdvX() / 2;
    150178        return vertOriginX;
     
    153181    public int getVertOriginY()
    154182    {
    155         if (vertOriginY != -1) return vertOriginY;
     183        if (vertOriginY != -1)
     184        {
     185            return vertOriginY;
     186        }
    156187        vertOriginY = fontFace.getAscent();
    157188        return vertOriginY;
     
    160191    public int getVertAdvY()
    161192    {
    162         if (vertAdvY != -1) return vertAdvY;
     193        if (vertAdvY != -1)
     194        {
     195            return vertAdvY;
     196        }
    163197        vertAdvY = fontFace.getUnitsPerEm();
    164198        return vertAdvY;
    165199    }
    166    
     200
    167201    /**
    168      * Updates all attributes in this diagram associated with a time event.
    169      * Ie, all attributes with track information.
     202     * Updates all attributes in this diagram associated with a time event. Ie,
     203     * all attributes with track information.
     204     *
    170205     * @return - true if this node has changed state as a result of the time
    171206     * update
     
    176211        return false;
    177212        /*
    178         if (trackManager.getNumTracks() == 0) return false;
    179        
    180         //Get current values for parameters
    181         StyleAttribute sty = new StyleAttribute();
    182         boolean stateChange = false;
    183        
    184         if (getPres(sty.setName("horiz-origin-x")))
    185         {
    186             int newVal = sty.getIntValue();
    187             if (newVal != horizOriginX)
    188             {
    189                 horizOriginX = newVal;
    190                 stateChange = true;
    191             }
    192         }
    193        
    194         if (getPres(sty.setName("horiz-origin-y")))
    195         {
    196             int newVal = sty.getIntValue();
    197             if (newVal != horizOriginY)
    198             {
    199                 horizOriginY = newVal;
    200                 stateChange = true;
    201             }
    202         }
    203        
    204         if (getPres(sty.setName("horiz-adv-x")))
    205         {
    206             int newVal = sty.getIntValue();
    207             if (newVal != horizAdvX)
    208             {
    209                 horizAdvX = newVal;
    210                 stateChange = true;
    211             }
    212         }
    213        
    214         if (getPres(sty.setName("vert-origin-x")))
    215         {
    216             int newVal = sty.getIntValue();
    217             if (newVal != vertOriginX)
    218             {
    219                 vertOriginX = newVal;
    220                 stateChange = true;
    221             }
    222         }
    223        
    224         if (getPres(sty.setName("vert-origin-y")))
    225         {
    226             int newVal = sty.getIntValue();
    227             if (newVal != vertOriginY)
    228             {
    229                 vertOriginY = newVal;
    230                 stateChange = true;
    231             }
    232         }
    233        
    234         if (getPres(sty.setName("vert-adv-y")))
    235         {
    236             int newVal = sty.getIntValue();
    237             if (newVal != vertAdvY)
    238             {
    239                 vertAdvY = newVal;
    240                 stateChange = true;
    241             }
    242         }
    243        
    244         return shapeChange;
    245         */
     213         if (trackManager.getNumTracks() == 0) return false;
     214       
     215         //Get current values for parameters
     216         StyleAttribute sty = new StyleAttribute();
     217         boolean stateChange = false;
     218       
     219         if (getPres(sty.setName("horiz-origin-x")))
     220         {
     221         int newVal = sty.getIntValue();
     222         if (newVal != horizOriginX)
     223         {
     224         horizOriginX = newVal;
     225         stateChange = true;
     226         }
     227         }
     228       
     229         if (getPres(sty.setName("horiz-origin-y")))
     230         {
     231         int newVal = sty.getIntValue();
     232         if (newVal != horizOriginY)
     233         {
     234         horizOriginY = newVal;
     235         stateChange = true;
     236         }
     237         }
     238       
     239         if (getPres(sty.setName("horiz-adv-x")))
     240         {
     241         int newVal = sty.getIntValue();
     242         if (newVal != horizAdvX)
     243         {
     244         horizAdvX = newVal;
     245         stateChange = true;
     246         }
     247         }
     248       
     249         if (getPres(sty.setName("vert-origin-x")))
     250         {
     251         int newVal = sty.getIntValue();
     252         if (newVal != vertOriginX)
     253         {
     254         vertOriginX = newVal;
     255         stateChange = true;
     256         }
     257         }
     258       
     259         if (getPres(sty.setName("vert-origin-y")))
     260         {
     261         int newVal = sty.getIntValue();
     262         if (newVal != vertOriginY)
     263         {
     264         vertOriginY = newVal;
     265         stateChange = true;
     266         }
     267         }
     268       
     269         if (getPres(sty.setName("vert-adv-y")))
     270         {
     271         int newVal = sty.getIntValue();
     272         if (newVal != vertAdvY)
     273         {
     274         vertAdvY = newVal;
     275         stateChange = true;
     276         }
     277         }
     278       
     279         return shapeChange;
     280         */
    246281    }
    247282}
  • trunk/src/com/kitfox/svg/FontFace.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.xml.StyleAttribute;
    31 import com.kitfox.svg.xml.*;
    32 import org.xml.sax.*;
    33 
    34 import java.awt.geom.*;
    35 import java.awt.*;
    36 
    3739
    3840/**
     
    4648public class FontFace extends SVGElement
    4749{
     50
     51    public static final String TAG_NAME = "fontface";
    4852    String fontFamily;
    49 
    50     /** Em size of coordinate system font is defined in */
     53    /**
     54     * Em size of coordinate system font is defined in
     55     */
    5156    int unitsPerEm = 1000;
    52 
    5357    int ascent = -1;
    5458    int descent = -1;
    5559    int accentHeight = -1;
    56 
    5760    int underlinePosition = -1;
    5861    int underlineThickness = -1;
     
    6265    int overlineThickness = -1;
    6366
    64     /** Creates a new instance of Font */
     67    /**
     68     * Creates a new instance of Font
     69     */
    6570    public FontFace()
    6671    {
    6772    }
    68 /*
    69     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    70     {
    71                 //Load style string
    72         super.loaderStartElement(helper, attrs, parent);
    73 
    74         fontFamily = attrs.getValue("font-family");
    75 
    76         String unitsPerEm = attrs.getValue("units-per-em");
    77         String ascent = attrs.getValue("ascent");
    78         String descent = attrs.getValue("descent");
    79         String accentHeight = attrs.getValue("accent-height");
    80 
    81         String underlinePosition = attrs.getValue("underline-position");
    82         String underlineThickness = attrs.getValue("underline-thickness");
    83         String strikethroughPosition = attrs.getValue("strikethrough-position");
    84         String strikethroughThickness = attrs.getValue("strikethrough-thickness");
    85         String overlinePosition = attrs.getValue("overline-position");
    86         String overlineThickness = attrs.getValue("overline-thickness");
    87 
    88 
    89         if (unitsPerEm != null) this.unitsPerEm = XMLParseUtil.parseInt(unitsPerEm);
    90         if (ascent != null) this.ascent = XMLParseUtil.parseInt(ascent);
    91         if (descent != null) this.descent = XMLParseUtil.parseInt(descent);
    92         if (accentHeight != null) this.accentHeight = XMLParseUtil.parseInt(accentHeight);
    93 
    94         if (underlinePosition != null) this.underlinePosition = XMLParseUtil.parseInt(underlinePosition);
    95         if (underlineThickness != null) this.underlineThickness = XMLParseUtil.parseInt(underlineThickness);
    96         if (strikethroughPosition != null) this.strikethroughPosition = XMLParseUtil.parseInt(strikethroughPosition);
    97         if (strikethroughThickness != null) this.strikethroughThickness = XMLParseUtil.parseInt(strikethroughThickness);
    98         if (overlinePosition != null) this.overlinePosition = XMLParseUtil.parseInt(overlinePosition);
    99         if (overlineThickness != null) this.overlineThickness = XMLParseUtil.parseInt(overlineThickness);
    100 
    101 //        unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm);
    102     }
    103   */ 
    104     /*
    105     public void loaderEndElement(SVGLoaderHelper helper)
    106     {
    107         super.loaderEndElement(helper);
    108 
    109         build();
    110        
    111 //        unitFontXform.setToScale(1.0 / (double)unitsPerEm, 1.0 / (double)unitsPerEm);
    112     }
    113      */
    114    
     73
     74    public String getTagName()
     75    {
     76        return TAG_NAME;
     77    }
     78
    11579    protected void build() throws SVGException
    11680    {
    11781        super.build();
    118        
     82
    11983        StyleAttribute sty = new StyleAttribute();
    120        
    121         if (getPres(sty.setName("font-family"))) fontFamily = sty.getStringValue();
    122        
    123         if (getPres(sty.setName("units-per-em"))) unitsPerEm = sty.getIntValue();
    124         if (getPres(sty.setName("ascent"))) ascent = sty.getIntValue();
    125         if (getPres(sty.setName("descent"))) descent = sty.getIntValue();
    126         if (getPres(sty.setName("accent-height"))) accentHeight = sty.getIntValue();
    127 
    128         if (getPres(sty.setName("underline-position"))) underlinePosition = sty.getIntValue();
    129         if (getPres(sty.setName("underline-thickness"))) underlineThickness = sty.getIntValue();
    130         if (getPres(sty.setName("strikethrough-position"))) strikethroughPosition = sty.getIntValue();
    131         if (getPres(sty.setName("strikethrough-thickenss"))) strikethroughThickness = sty.getIntValue();
    132         if (getPres(sty.setName("overline-position"))) overlinePosition = sty.getIntValue();
    133         if (getPres(sty.setName("overline-thickness"))) overlineThickness = sty.getIntValue();
    134     }
    135 
    136 
    137     public String getFontFamily() { return fontFamily; }
    138 
    139     public int getUnitsPerEm() { return unitsPerEm; }
     84
     85        if (getPres(sty.setName("font-family")))
     86        {
     87            fontFamily = sty.getStringValue();
     88        }
     89
     90        if (getPres(sty.setName("units-per-em")))
     91        {
     92            unitsPerEm = sty.getIntValue();
     93        }
     94        if (getPres(sty.setName("ascent")))
     95        {
     96            ascent = sty.getIntValue();
     97        }
     98        if (getPres(sty.setName("descent")))
     99        {
     100            descent = sty.getIntValue();
     101        }
     102        if (getPres(sty.setName("accent-height")))
     103        {
     104            accentHeight = sty.getIntValue();
     105        }
     106
     107        if (getPres(sty.setName("underline-position")))
     108        {
     109            underlinePosition = sty.getIntValue();
     110        }
     111        if (getPres(sty.setName("underline-thickness")))
     112        {
     113            underlineThickness = sty.getIntValue();
     114        }
     115        if (getPres(sty.setName("strikethrough-position")))
     116        {
     117            strikethroughPosition = sty.getIntValue();
     118        }
     119        if (getPres(sty.setName("strikethrough-thickenss")))
     120        {
     121            strikethroughThickness = sty.getIntValue();
     122        }
     123        if (getPres(sty.setName("overline-position")))
     124        {
     125            overlinePosition = sty.getIntValue();
     126        }
     127        if (getPres(sty.setName("overline-thickness")))
     128        {
     129            overlineThickness = sty.getIntValue();
     130        }
     131    }
     132
     133    public String getFontFamily()
     134    {
     135        return fontFamily;
     136    }
     137
     138    public int getUnitsPerEm()
     139    {
     140        return unitsPerEm;
     141    }
    140142
    141143    public int getAscent()
    142144    {
    143145        if (ascent == -1)
    144             ascent = unitsPerEm - ((Font)parent).getVertOriginY();
     146        {
     147            ascent = unitsPerEm - ((Font) parent).getVertOriginY();
     148        }
    145149        return ascent;
    146150    }
     
    149153    {
    150154        if (descent == -1)
    151             descent = ((Font)parent).getVertOriginY();
     155        {
     156            descent = ((Font) parent).getVertOriginY();
     157        }
    152158        return descent;
    153159    }
     
    156162    {
    157163        if (accentHeight == -1)
     164        {
    158165            accentHeight = getAscent();
     166        }
    159167        return accentHeight;
    160168    }
     
    163171    {
    164172        if (underlinePosition == -1)
     173        {
    165174            underlinePosition = unitsPerEm * 5 / 6;
     175        }
    166176        return underlinePosition;
    167177    }
     
    170180    {
    171181        if (underlineThickness == -1)
     182        {
    172183            underlineThickness = unitsPerEm / 20;
     184        }
    173185        return underlineThickness;
    174186    }
     
    177189    {
    178190        if (strikethroughPosition == -1)
     191        {
    179192            strikethroughPosition = unitsPerEm * 3 / 6;
     193        }
    180194        return strikethroughPosition;
    181195    }
     
    184198    {
    185199        if (strikethroughThickness == -1)
     200        {
    186201            strikethroughThickness = unitsPerEm / 20;
     202        }
    187203        return strikethroughThickness;
    188204    }
     
    191207    {
    192208        if (overlinePosition == -1)
     209        {
    193210            overlinePosition = unitsPerEm * 5 / 6;
     211        }
    194212        return overlinePosition;
    195213    }
     
    198216    {
    199217        if (overlineThickness == -1)
     218        {
    200219            overlineThickness = unitsPerEm / 20;
     220        }
    201221        return overlineThickness;
    202222    }
    203    
     223
    204224    /**
    205      * Updates all attributes in this diagram associated with a time event.
    206      * Ie, all attributes with track information.
     225     * Updates all attributes in this diagram associated with a time event. Ie,
     226     * all attributes with track information.
     227     *
    207228     * @return - true if this node has changed state as a result of the time
    208229     * update
  • trunk/src/com/kitfox/svg/Glyph.java

    r4256 r6002  
    11/*
    2  * Font.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 February 20, 2004, 10:00 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import com.kitfox.svg.xml.*;
    32 import org.xml.sax.*;
    33 
    34 import java.awt.*;
    35 import java.awt.geom.*;
    36 import java.util.*;
    37 
    38 import com.kitfox.svg.pathcmd.*;
    39 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
    4039
    4140/**
     
    4948public class Glyph extends MissingGlyph
    5049{
     50
     51    public static final String TAG_NAME = "missingglyph";
    5152    /**
    52      * One or more characters indicating the unicode sequence that denotes
    53      * this glyph.
     53     * One or more characters indicating the unicode sequence that denotes this
     54     * glyph.
    5455     */
    5556    String unicode;
    5657
    57     /** Creates a new instance of Font */
     58    /**
     59     * Creates a new instance of Font
     60     */
    5861    public Glyph()
    5962    {
    6063    }
    61 /*
    62     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     64
     65    public String getTagName()
    6366    {
    64                 //Load style string
    65         super.loaderStartElement(helper, attrs, parent);
     67        return TAG_NAME;
     68    }
    6669
    67         //Get unicode sequence that maps to this glyph
    68         unicode = attrs.getValue("unicode");
    69     }
    70 */
    71     /*
    72     public void loaderEndElement(SVGLoaderHelper helper)
    73     {
    74         super.loaderEndElement(helper);
    75 
    76         build();
    77     }
    78      */
    79    
    8070    protected void build() throws SVGException
    8171    {
    8272        super.build();
    83        
     73
    8474        StyleAttribute sty = new StyleAttribute();
    85        
    86         if (getPres(sty.setName("unicode"))) unicode = sty.getStringValue();
     75
     76        if (getPres(sty.setName("unicode")))
     77        {
     78            unicode = sty.getStringValue();
     79        }
    8780    }
    88    
    89     public String getUnicode() { return unicode; }
    90    
     81
     82    public String getUnicode()
     83    {
     84        return unicode;
     85    }
     86
    9187    /**
    92      * Updates all attributes in this diagram associated with a time event.
    93      * Ie, all attributes with track information.
     88     * Updates all attributes in this diagram associated with a time event. Ie,
     89     * all attributes with track information.
     90     *
    9491     * @return - true if this node has changed state as a result of the time
    9592     * update
  • trunk/src/com/kitfox/svg/Gradient.java

    r4256 r6002  
    11/*
    2  * Gradient.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, 3:25 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    30 import java.net.*;
    31 import java.util.*;
    32 import java.awt.geom.*;
    33 import java.awt.*;
    34 
    35 import com.kitfox.svg.xml.*;
     38import com.kitfox.svg.xml.StyleAttribute;
     39import java.awt.Color;
     40import java.awt.geom.AffineTransform;
     41import java.net.URI;
     42import java.util.ArrayList;
     43import java.util.Iterator;
     44import java.util.logging.Level;
     45import java.util.logging.Logger;
    3646
    3747/**
     
    4151abstract public class Gradient extends FillElement
    4252{
    43 
     53    public static final String TAG_NAME = "gradient";
     54   
    4455    public static final int SM_PAD = 0;
    4556    public static final int SM_REPEAT = 1;
    4657    public static final int SM_REFLECT = 2;
    47 
    4858    int spreadMethod = SM_PAD;
    49 
    5059    public static final int GU_OBJECT_BOUNDING_BOX = 0;
    5160    public static final int GU_USER_SPACE_ON_USE = 1;
    52 
    5361    protected int gradientUnits = GU_OBJECT_BOUNDING_BOX;
    54 
    5562    //Either this gradient contains a list of stops, or it will take it's
    5663    // stops from the referenced gradient
    5764    ArrayList stops = new ArrayList();
    5865    URI stopRef = null;
    59 //    Gradient stopRef = null;
    60 
    6166    protected AffineTransform gradientTransform = null;
    62 
     67   
    6368    //Cache arrays of stop values here
    6469    float[] stopFractions;
    6570    Color[] stopColors;
    6671
    67     /** Creates a new instance of Gradient */
    68     public Gradient() {
    69     }
    70    
     72    /**
     73     * Creates a new instance of Gradient
     74     */
     75    public Gradient()
     76    {
     77    }
     78
     79    public String getTagName()
     80    {
     81        return TAG_NAME;
     82    }
     83
    7184    /**
    7285     * Called after the start element but before the end element to indicate
     
    7790        super.loaderAddChild(helper, child);
    7891
    79         if (!(child instanceof Stop)) return;
    80         appendStop((Stop)child);
     92        if (!(child instanceof Stop))
     93        {
     94            return;
     95        }
     96        appendStop((Stop) child);
    8197    }
    8298
     
    84100    {
    85101        super.build();
    86        
     102
    87103        StyleAttribute sty = new StyleAttribute();
    88104        String strn;
    89        
     105
    90106        if (getPres(sty.setName("spreadMethod")))
    91107        {
    92108            strn = sty.getStringValue().toLowerCase();
    93             if (strn.equals("repeat")) spreadMethod = SM_REPEAT;
    94             else if (strn.equals("reflect")) spreadMethod = SM_REFLECT;
    95             else spreadMethod = SM_PAD;
     109            if (strn.equals("repeat"))
     110            {
     111                spreadMethod = SM_REPEAT;
     112            } else if (strn.equals("reflect"))
     113            {
     114                spreadMethod = SM_REFLECT;
     115            } else
     116            {
     117                spreadMethod = SM_PAD;
     118            }
    96119        }
    97120
     
    99122        {
    100123            strn = sty.getStringValue().toLowerCase();
    101             if (strn.equals("userspaceonuse")) gradientUnits = GU_USER_SPACE_ON_USE;
    102             else gradientUnits = GU_OBJECT_BOUNDING_BOX;
    103         }
    104 
    105         if (getPres(sty.setName("gradientTransform"))) gradientTransform = parseTransform(sty.getStringValue());
     124            if (strn.equals("userspaceonuse"))
     125            {
     126                gradientUnits = GU_USER_SPACE_ON_USE;
     127            } else
     128            {
     129                gradientUnits = GU_OBJECT_BOUNDING_BOX;
     130            }
     131        }
     132
     133        if (getPres(sty.setName("gradientTransform")))
     134        {
     135            gradientTransform = parseTransform(sty.getStringValue());
     136        }
    106137        //If we still don't have one, set it to identity
    107         if (gradientTransform == null) gradientTransform = new AffineTransform();
    108 
    109        
     138        if (gradientTransform == null)
     139        {
     140            gradientTransform = new AffineTransform();
     141        }
     142
     143
    110144        //Check to see if we're using our own stops or referencing someone else's
    111145        if (getPres(sty.setName("xlink:href")))
    112146        {
    113             try {
     147            try
     148            {
    114149                stopRef = sty.getURIValue(getXMLBase());
    115150//System.err.println("Gradient: " + sty.getStringValue() + ", " + getXMLBase() + ", " + src);
    116151//                URI src = getXMLBase().resolve(href);
    117152//                stopRef = (Gradient)diagram.getUniverse().getElement(src);
    118             }
    119             catch (Exception e)
     153            } catch (Exception e)
    120154            {
    121155                throw new SVGException("Could not resolve relative URL in Gradient: " + sty.getStringValue() + ", " + getXMLBase(), e);
     
    123157        }
    124158    }
    125    
     159
    126160    public float[] getStopFractions()
    127161    {
    128162        if (stopRef != null)
    129163        {
    130             Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
     164            Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
    131165            return grad.getStopFractions();
    132166        }
    133167
    134         if (stopFractions != null) return stopFractions;
     168        if (stopFractions != null)
     169        {
     170            return stopFractions;
     171        }
    135172
    136173        stopFractions = new float[stops.size()];
     
    138175        for (Iterator it = stops.iterator(); it.hasNext();)
    139176        {
    140             Stop stop = (Stop)it.next();
     177            Stop stop = (Stop) it.next();
    141178            float val = stop.offset;
    142             if (idx != 0 && val < stopFractions[idx - 1]) val = stopFractions[idx - 1];
     179            if (idx != 0 && val < stopFractions[idx - 1])
     180            {
     181                val = stopFractions[idx - 1];
     182            }
    143183            stopFractions[idx++] = val;
    144184        }
     
    151191        if (stopRef != null)
    152192        {
    153             Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
     193            Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
    154194            return grad.getStopColors();
    155195        }
    156196
    157         if (stopColors != null) return stopColors;
     197        if (stopColors != null)
     198        {
     199            return stopColors;
     200        }
    158201
    159202        stopColors = new Color[stops.size()];
     
    161204        for (Iterator it = stops.iterator(); it.hasNext();)
    162205        {
    163             Stop stop = (Stop)it.next();
     206            Stop stop = (Stop) it.next();
    164207            int stopColorVal = stop.color.getRGB();
    165             Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int)(stop.opacity * 255), 0, 255));
     208            Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255));
    166209            stopColors[idx++] = stopColor;
    167210        }
     
    169212        return stopColors;
    170213    }
    171    
     214
    172215    public void setStops(Color[] colors, float[] fractions)
    173216    {
     
    176219            throw new IllegalArgumentException();
    177220        }
    178        
     221
    179222        this.stopColors = colors;
    180223        this.stopFractions = fractions;
    181224        stopRef = null;
    182225    }
    183    
     226
    184227    private int clamp(int val, int min, int max)
    185228    {
    186         if (val < min) return min;
    187         if (val > max) return max;
     229        if (val < min)
     230        {
     231            return min;
     232        }
     233        if (val > max)
     234        {
     235            return max;
     236        }
    188237        return val;
    189238    }
    190    
     239
    191240    public void setStopRef(URI grad)
    192241    {
     
    200249
    201250    /**
    202      * Updates all attributes in this diagram associated with a time event.
    203      * Ie, all attributes with track information.
     251     * Updates all attributes in this diagram associated with a time event. Ie,
     252     * all attributes with track information.
     253     *
    204254     * @return - true if this node has changed state as a result of the time
    205255     * update
     
    214264        boolean shapeChange = false;
    215265        String strn;
    216        
     266
    217267
    218268        if (getPres(sty.setName("spreadMethod")))
     
    220270            int newVal;
    221271            strn = sty.getStringValue().toLowerCase();
    222             if (strn.equals("repeat")) newVal = SM_REPEAT;
    223             else if (strn.equals("reflect")) newVal = SM_REFLECT;
    224             else newVal = SM_PAD;
     272            if (strn.equals("repeat"))
     273            {
     274                newVal = SM_REPEAT;
     275            } else if (strn.equals("reflect"))
     276            {
     277                newVal = SM_REFLECT;
     278            } else
     279            {
     280                newVal = SM_PAD;
     281            }
    225282            if (spreadMethod != newVal)
    226283            {
     
    229286            }
    230287        }
    231        
     288
    232289        if (getPres(sty.setName("gradientUnits")))
    233290        {
    234291            int newVal;
    235292            strn = sty.getStringValue().toLowerCase();
    236             if (strn.equals("userspaceonuse")) newVal = GU_USER_SPACE_ON_USE;
    237             else newVal = GU_OBJECT_BOUNDING_BOX;
     293            if (strn.equals("userspaceonuse"))
     294            {
     295                newVal = GU_USER_SPACE_ON_USE;
     296            } else
     297            {
     298                newVal = GU_OBJECT_BOUNDING_BOX;
     299            }
    238300            if (newVal != gradientUnits)
    239301            {
     
    253315        }
    254316
    255        
     317
    256318        //Check to see if we're using our own stops or referencing someone else's
    257319        if (getPres(sty.setName("xlink:href")))
    258320        {
    259             try {
     321            try
     322            {
    260323                URI newVal = sty.getURIValue(getXMLBase());
    261324                if ((newVal == null && stopRef != null) || !newVal.equals(stopRef))
     
    264327                    stateChange = true;
    265328                }
    266             }
    267             catch (Exception e)
    268             {
    269                 e.printStackTrace();
    270             }
    271         }
    272        
     329            } catch (Exception e)
     330            {
     331                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     332                    "Could not parse xlink:href", e);
     333            }
     334        }
     335
    273336        //Check stops, if any
    274337        for (Iterator it = stops.iterator(); it.hasNext();)
    275338        {
    276             Stop stop = (Stop)it.next();
     339            Stop stop = (Stop) it.next();
    277340            if (stop.updateTime(curTime))
    278341            {
     
    282345            }
    283346        }
    284        
     347
    285348        return stateChange;
    286349    }
    287 
    288350}
  • 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
  • trunk/src/com/kitfox/svg/Hkern.java

    r4256 r6002  
    11/*
    2  * Font.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 February 20, 2004, 10:00 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3644public class Hkern extends SVGElement
    3745{
     46
     47    public static final String TAG_NAME = "hkern";
    3848    String u1;
    3949    String u2;
    4050    int k;
    4151
     52    public String getTagName()
     53    {
     54        return TAG_NAME;
     55    }
    4256
    4357    protected void build() throws SVGException
     
    4963
    5064        //Read glyph spacing info
    51         if (getPres(sty.setName("u1"))) u1 = sty.getStringValue();
     65        if (getPres(sty.setName("u1")))
     66        {
     67            u1 = sty.getStringValue();
     68        }
    5269
    53         if (getPres(sty.setName("u2"))) u2 = sty.getStringValue();
     70        if (getPres(sty.setName("u2")))
     71        {
     72            u2 = sty.getStringValue();
     73        }
    5474
    55         if (getPres(sty.setName("k"))) k = sty.getIntValue();
     75        if (getPres(sty.setName("k")))
     76        {
     77            k = sty.getIntValue();
     78        }
    5679    }
    5780
     
    6184        return false;
    6285    }
    63    
    64    
    6586}
  • 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    }
  • trunk/src/com/kitfox/svg/Line.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3846 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3947 */
    40 public class Line extends ShapeElement {
    41 
     48public class Line extends ShapeElement
     49{
     50    public static final String TAG_NAME = "line";
     51   
    4252    float x1 = 0f;
    4353    float y1 = 0f;
    4454    float x2 = 0f;
    4555    float y2 = 0f;
     56    Line2D.Float line;
    4657
    47     Line2D.Float line;
    48 //    RectangularShape rect;
    49 
    50     /** Creates a new instance of Rect */
    51     public Line() {
     58    /**
     59     * Creates a new instance of Rect
     60     */
     61    public Line()
     62    {
    5263    }
    5364
    54     /*
    55     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     65    public String getTagName()
    5666    {
    57                 //Load style string
    58         super.loaderStartElement(helper, attrs, parent);
     67        return TAG_NAME;
     68    }
    5969
    60         String x1 = attrs.getValue("x1");
    61         String y1 = attrs.getValue("y1");
    62         String x2 = attrs.getValue("x2");
    63         String y2 = attrs.getValue("y2");
    64 
    65         this.x1 = XMLParseUtil.parseFloat(x1);
    66         this.y1 = XMLParseUtil.parseFloat(y1);
    67         this.x2 = XMLParseUtil.parseFloat(x2);
    68         this.y2 = XMLParseUtil.parseFloat(y2);
    69 
    70         build();
    71     }
    72 */
    7370    protected void build() throws SVGException
    7471    {
    7572        super.build();
    76        
     73
    7774        StyleAttribute sty = new StyleAttribute();
    78        
    79         if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits();
    8075
    81         if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits();
     76        if (getPres(sty.setName("x1")))
     77        {
     78            x1 = sty.getFloatValueWithUnits();
     79        }
    8280
    83         if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits();
     81        if (getPres(sty.setName("y1")))
     82        {
     83            y1 = sty.getFloatValueWithUnits();
     84        }
    8485
    85         if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits();
     86        if (getPres(sty.setName("x2")))
     87        {
     88            x2 = sty.getFloatValueWithUnits();
     89        }
     90
     91        if (getPres(sty.setName("y2")))
     92        {
     93            y2 = sty.getFloatValueWithUnits();
     94        }
    8695
    8796        line = new Line2D.Float(x1, y1, x2, y2);
    8897    }
    89    
    9098
    9199    public void render(Graphics2D g) throws SVGException
     
    107115
    108116    /**
    109      * Updates all attributes in this diagram associated with a time event.
    110      * Ie, all attributes with track information.
     117     * Updates all attributes in this diagram associated with a time event. Ie,
     118     * all attributes with track information.
     119     *
    111120     * @return - true if this node has changed state as a result of the time
    112121     * update
     
    120129        StyleAttribute sty = new StyleAttribute();
    121130        boolean shapeChange = false;
    122        
     131
    123132        if (getPres(sty.setName("x1")))
    124133        {
     
    164173        {
    165174            build();
    166 //            line = new Line2D.Float(x1, y1, x2, y2);
    167 //            return true;
    168175        }
    169        
     176
    170177        return changeState || shapeChange;
    171178    }
  • trunk/src/com/kitfox/svg/LinearGradient.java

    r4256 r6002  
    11/*
    2  * LinearGradient.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:54 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 LinearGradient extends Gradient {
    46 
     49public class LinearGradient extends Gradient
     50{
     51    public static final String TAG_NAME = "lineargradient";
     52   
    4753    float x1 = 0f;
    4854    float y1 = 0f;
     
    5056    float y2 = 0f;
    5157
    52     /** Creates a new instance of LinearGradient */
    53     public LinearGradient() {
    54     }
    55 /*
    56     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    57     {
    58                 //Load style string
    59         super.loaderStartElement(helper, attrs, parent);
    60 
    61         String x1 = attrs.getValue("x1");
    62         String x2 = attrs.getValue("x2");
    63         String y1 = attrs.getValue("y1");
    64         String y2 = attrs.getValue("y2");
    65 
    66         if (x1 != null) this.x1 = (float)XMLParseUtil.parseRatio(x1);
    67         if (y1 != null) this.y1 = (float)XMLParseUtil.parseRatio(y1);
    68         if (x2 != null) this.x2 = (float)XMLParseUtil.parseRatio(x2);
    69         if (y2 != null) this.y2 = (float)XMLParseUtil.parseRatio(y2);
    70     }
    71 */
    72     /*
    73     public void loaderEndElement(SVGLoaderHelper helper)
    74     {
    75         super.loaderEndElement(helper);
    76        
    77         build();
    78     }
    79     */
    80    
     58    /**
     59     * Creates a new instance of LinearGradient
     60     */
     61    public LinearGradient()
     62    {
     63    }
     64
     65    public String getTagName()
     66    {
     67        return TAG_NAME;
     68    }
     69
    8170    protected void build() throws SVGException
    8271    {
    8372        super.build();
    84        
     73
    8574        StyleAttribute sty = new StyleAttribute();
    86        
    87         if (getPres(sty.setName("x1"))) x1 = sty.getFloatValueWithUnits();
    88        
    89         if (getPres(sty.setName("y1"))) y1 = sty.getFloatValueWithUnits();
    90        
    91         if (getPres(sty.setName("x2"))) x2 = sty.getFloatValueWithUnits();
    92        
    93         if (getPres(sty.setName("y2"))) y2 = sty.getFloatValueWithUnits();
    94     }
    95    
     75
     76        if (getPres(sty.setName("x1")))
     77        {
     78            x1 = sty.getFloatValueWithUnits();
     79        }
     80
     81        if (getPres(sty.setName("y1")))
     82        {
     83            y1 = sty.getFloatValueWithUnits();
     84        }
     85
     86        if (getPres(sty.setName("x2")))
     87        {
     88            x2 = sty.getFloatValueWithUnits();
     89        }
     90
     91        if (getPres(sty.setName("y2")))
     92        {
     93            y2 = sty.getFloatValueWithUnits();
     94        }
     95    }
     96
    9697    public Paint getPaint(Rectangle2D bounds, AffineTransform xform)
    9798    {
     
    111112        }
    112113
    113         com.kitfox.svg.batik.LinearGradientPaint paint;
    114         if (gradientUnits == GU_USER_SPACE_ON_USE)
    115         {
    116 //            paint = new LinearGradientPaint(x1, y1, x2, y2, getStopFractions(), getStopColors(), method);
     114        Paint paint;
     115        Point2D.Float pt1 = new Point2D.Float(x1, y1);
     116        Point2D.Float pt2 = new Point2D.Float(x2, y2);
     117        if (pt1.equals(pt2))
     118        {
     119            Color[] colors = getStopColors();
     120            paint = colors.length > 0 ? colors[0] : Color.black;
     121        } else if (gradientUnits == GU_USER_SPACE_ON_USE)
     122        {
    117123            paint = new com.kitfox.svg.batik.LinearGradientPaint(
    118                 new Point2D.Float(x1, y1),
    119                 new Point2D.Float(x2, y2),
     124                pt1,
     125                pt2,
    120126                getStopFractions(),
    121127                getStopColors(),
    122128                method,
    123129                com.kitfox.svg.batik.MultipleGradientPaint.SRGB,
    124                 gradientTransform);
    125         }
    126         else
     130                gradientTransform == null
     131                ? new AffineTransform()
     132                : gradientTransform);
     133        } else
    127134        {
    128135            AffineTransform viewXform = new AffineTransform();
    129136            viewXform.translate(bounds.getX(), bounds.getY());
    130            
     137
    131138            //This is a hack to get around shapes that have a width or height of 0.  Should be close enough to the true answer.
    132             double width = bounds.getWidth();
    133             double height = bounds.getHeight();
    134             if (width == 0) width = 1;
    135             if (height == 0) height = 1;
     139            double width = Math.max(1, bounds.getWidth());
     140            double height = Math.max(1, bounds.getHeight());
    136141            viewXform.scale(width, height);
    137142
    138             viewXform.concatenate(gradientTransform);
     143            if (gradientTransform != null)
     144            {
     145                viewXform.concatenate(gradientTransform);
     146            }
    139147
    140148            paint = new com.kitfox.svg.batik.LinearGradientPaint(
    141                 new Point2D.Float(x1, y1),
    142                 new Point2D.Float(x2, y2),
     149                pt1,
     150                pt2,
    143151                getStopFractions(),
    144152                getStopColors(),
     
    150158        return paint;
    151159    }
    152    
     160
    153161    /**
    154      * Updates all attributes in this diagram associated with a time event.
    155      * Ie, all attributes with track information.
     162     * Updates all attributes in this diagram associated with a time event. Ie,
     163     * all attributes with track information.
     164     *
    156165     * @return - true if this node has changed state as a result of the time
    157166     * update
     
    165174        StyleAttribute sty = new StyleAttribute();
    166175        boolean shapeChange = false;
    167        
     176
    168177        if (getPres(sty.setName("x1")))
    169178        {
  • trunk/src/com/kitfox/svg/Marker.java

    r4256 r6002  
    11/*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
     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
    433 */
    5 
    634package com.kitfox.svg;
    735
     
    2149public class Marker extends Group
    2250{
     51    public static final String TAG_NAME = "marker";
     52   
    2353    AffineTransform viewXform;
    2454    AffineTransform markerXform;
    2555    Rectangle2D viewBox;
    26 
    2756    float refX;
    2857    float refY;
     
    3059    float markerHeight = 3;
    3160    float orient = Float.NaN;
     61    boolean markerUnitsStrokeWidth = true; //if set to false 'userSpaceOnUse' is assumed
     62
     63    public String getTagName()
     64    {
     65        return TAG_NAME;
     66    }
    3267
    3368    protected void build() throws SVGException
     
    3772        StyleAttribute sty = new StyleAttribute();
    3873
    39         if (getPres(sty.setName("refX"))) refX = sty.getFloatValueWithUnits();
    40         if (getPres(sty.setName("refY"))) refY = sty.getFloatValueWithUnits();
    41         if (getPres(sty.setName("markerWidth"))) markerWidth = sty.getFloatValueWithUnits();
    42         if (getPres(sty.setName("markerHeight"))) markerHeight = sty.getFloatValueWithUnits();
     74        if (getPres(sty.setName("refX")))
     75        {
     76            refX = sty.getFloatValueWithUnits();
     77        }
     78        if (getPres(sty.setName("refY")))
     79        {
     80            refY = sty.getFloatValueWithUnits();
     81        }
     82        if (getPres(sty.setName("markerWidth")))
     83        {
     84            markerWidth = sty.getFloatValueWithUnits();
     85        }
     86        if (getPres(sty.setName("markerHeight")))
     87        {
     88            markerHeight = sty.getFloatValueWithUnits();
     89        }
    4390
    4491        if (getPres(sty.setName("orient")))
     
    4794            {
    4895                orient = Float.NaN;
    49             }
    50             else
     96            } else
    5197            {
    5298                orient = sty.getFloatValue();
     
    63109        {
    64110            viewBox = new Rectangle(0, 0, 1, 1);
     111        }
     112
     113        if (getPres(sty.setName("markerUnits")))
     114        {
     115            String markerUnits = sty.getStringValue();
     116            if (markerUnits != null && markerUnits.equals("userSpaceOnUse"))
     117            {
     118                markerUnitsStrokeWidth = false;
     119            }
    65120        }
    66121
     
    78133    protected boolean outsideClip(Graphics2D g) throws SVGException
    79134    {
    80         g.getClipBounds(clipBounds);
     135        Shape clip = g.getClip();
    81136        Rectangle2D rect = super.getBoundingBox();
    82         if (rect.intersects(clipBounds))
     137        if (clip == null || clip.intersects(rect))
    83138        {
    84139            return false;
     
    104159
    105160        g.translate(pos.x, pos.y);
    106         g.scale(strokeWidth, strokeWidth);
     161        if (markerUnitsStrokeWidth)
     162        {
     163            g.scale(strokeWidth, strokeWidth);
     164        }
     165
    107166        g.rotate(Math.atan2(pos.dy, pos.dx));
    108167
     
    127186
    128187    /**
    129      * Updates all attributes in this diagram associated with a time event.
    130      * Ie, all attributes with track information.
     188     * Updates all attributes in this diagram associated with a time event. Ie,
     189     * all attributes with track information.
     190     *
    131191     * @return - true if this node has changed state as a result of the time
    132192     * update
     
    139199        return changeState;
    140200    }
    141 
     201   
    142202    //--------------------------------
    143203    public static final int MARKER_START = 0;
     
    147207    public static class MarkerPos
    148208    {
     209
    149210        int type;
    150211        double x;
     
    165226    public static class MarkerLayout
    166227    {
     228
    167229        private ArrayList markerList = new ArrayList();
    168230        boolean started = false;
     
    174236            double[] coords = new double[6];
    175237            for (PathIterator it = shape.getPathIterator(null);
    176                     !it.isDone(); it.next())
     238                !it.isDone(); it.next())
    177239            {
    178240                switch (it.currentSegment(coords))
     
    202264                        double x = coords[2];
    203265                        double y = coords[3];
     266
     267
     268                        //Best in tangent
     269                        if (px != k0x || py != k0y)
     270                        {
     271                            markerIn(px, py, k0x - px, k0y - py);
     272                        } else
     273                        {
     274                            markerIn(px, py, x - px, y - py);
     275                        }
     276
     277                        //Best out tangent
     278                        if (x != k0x || y != k0y)
     279                        {
     280                            markerOut(x, y, x - k0x, y - k0y);
     281                        } else
     282                        {
     283                            markerOut(x, y, x - px, y - py);
     284                        }
     285
    204286                        markerIn(px, py, k0x - px, k0y - py);
    205287                        markerOut(x, y, x - k0x, y - k0y);
     
    216298                        double x = coords[4];
    217299                        double y = coords[5];
    218                         markerIn(px, py, k0x - px, k0y - py);
    219                         markerOut(x, y, x - k1x, y - k1y);
     300
     301                        //Best in tangent
     302                        if (px != k0x || py != k0y)
     303                        {
     304                            markerIn(px, py, k0x - px, k0y - py);
     305                        } else if (px != k1x || py != k1y)
     306                        {
     307                            markerIn(px, py, k1x - px, k1y - py);
     308                        } else
     309                        {
     310                            markerIn(px, py, x - px, y - py);
     311                        }
     312
     313                        //Best out tangent
     314                        if (x != k1x || y != k1y)
     315                        {
     316                            markerOut(x, y, x - k1x, y - k1y);
     317                        } else if (x != k0x || y != k0y)
     318                        {
     319                            markerOut(x, y, x - k0x, y - k0y);
     320                        } else
     321                        {
     322                            markerOut(x, y, x - px, y - py);
     323                        }
    220324                        px = x;
    221325                        py = y;
     
    227331            for (int i = 1; i < markerList.size(); ++i)
    228332            {
    229                 MarkerPos prev = (MarkerPos)markerList.get(i - 1);
    230                 MarkerPos cur = (MarkerPos)markerList.get(i);
     333                MarkerPos prev = (MarkerPos) markerList.get(i - 1);
     334                MarkerPos cur = (MarkerPos) markerList.get(i);
    231335
    232336                if (cur.type == MARKER_START)
     
    235339                }
    236340            }
    237             MarkerPos last = (MarkerPos)markerList.get(markerList.size() - 1);
     341            MarkerPos last = (MarkerPos) markerList.get(markerList.size() - 1);
    238342            last.type = MARKER_END;
    239343        }
  • trunk/src/com/kitfox/svg/Metadata.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 September 19, 2004, 1:56 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038/**
    31  * Does not hold any information.  Included to allow metadata tag to be parsed.
     39 * Does not hold any information. Included to allow metadata tag to be parsed.
    3240 *
    3341 * @author Mark McKay
    3442 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3543 */
    36 public class Metadata extends SVGElement 
     44public class Metadata extends SVGElement
    3745{
    38     /** Creates a new instance of Stop */
    39     public Metadata() {
     46    public static final String TAG_NAME = "metadata";
     47
     48    /**
     49     * Creates a new instance of Stop
     50     */
     51    public Metadata()
     52    {
     53    }
     54
     55    public String getTagName()
     56    {
     57        return TAG_NAME;
    4058    }
    4159
  • trunk/src/com/kitfox/svg/MissingGlyph.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
    30 import com.kitfox.svg.xml.*;
    31 
    32 import java.awt.*;
    33 import java.awt.geom.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.pathcmd.*;
    37 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
     38import com.kitfox.svg.pathcmd.BuildHistory;
     39import com.kitfox.svg.pathcmd.PathCommand;
     40import com.kitfox.svg.xml.StyleAttribute;
     41import java.awt.Graphics2D;
     42import java.awt.Shape;
     43import java.awt.geom.AffineTransform;
     44import java.awt.geom.GeneralPath;
     45import java.awt.geom.Rectangle2D;
     46import java.util.Iterator;
    3847
    3948/**
     
    4756public class MissingGlyph extends ShapeElement
    4857{
     58    public static final String TAG_NAME = "missingglyph";
     59   
    4960    //We may define a path
    50 //    ExtendedGeneralPath path = null;
    5161    Shape path = null;
    52 
    5362    //Alternately, we may have child graphical elements
    54 
    5563    int horizAdvX = -1;  //Inherits font's value if not set
    5664    int vertOriginX = -1;  //Inherits font's value if not set
     
    5866    int vertAdvY = -1;  //Inherits font's value if not set
    5967
    60     /** Creates a new instance of Font */
     68    /**
     69     * Creates a new instance of Font
     70     */
    6171    public MissingGlyph()
    6272    {
    6373    }
    64 /*
    65     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    66     {
    67                 //Load style string
    68         super.loaderStartElement(helper, attrs, parent);
     74
     75    public String getTagName()
     76    {
     77        return TAG_NAME;
     78    }
     79
     80    /**
     81     * Called after the start element but before the end element to indicate
     82     * each child tag that has been processed
     83     */
     84    public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
     85    {
     86        super.loaderAddChild(helper, child);
     87    }
     88
     89    protected void build() throws SVGException
     90    {
     91        super.build();
     92
     93        StyleAttribute sty = new StyleAttribute();
     94
     95        String commandList = "";
     96        if (getPres(sty.setName("d")))
     97        {
     98            commandList = sty.getStringValue();
     99        }
     100
    69101
    70102        //If glyph path was specified, calculate it
    71         String commandList = attrs.getValue("d");
    72103        if (commandList != null)
    73104        {
    74             StyleAttribute atyleAttrib = getStyle("fill-rule");
    75             String fillRule = (atyleAttrib == null) ? "nonzero" : atyleAttrib.getStringValue();
     105            String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
    76106
    77107            PathCommand[] commands = parsePathList(commandList);
    78108
    79 //            ExtendedGeneralPath buildPath = new ExtendedGeneralPath(
    80109            GeneralPath buildPath = new GeneralPath(
    81110                fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
     
    98127
    99128        //Read glyph spacing info
    100         String horizAdvX = attrs.getValue("horiz-adv-x");
    101         String vertOriginX = attrs.getValue("vert-origin-x");
    102         String vertOriginY = attrs.getValue("vert-origin-y");
    103         String vertAdvY = attrs.getValue("vert-adv-y");
    104 
    105         if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX);
    106         if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX);
    107         if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY);
    108         if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY);
    109 
    110     }
    111 */
    112     /**
    113      * Called after the start element but before the end element to indicate
    114      * each child tag that has been processed
    115      */
    116     public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
    117     {
    118         super.loaderAddChild(helper, child);
    119     }
    120 
    121    
    122     protected void build() throws SVGException
    123     {
    124         super.build();
    125        
    126         StyleAttribute sty = new StyleAttribute();
    127        
    128         String commandList = "";
    129         if (getPres(sty.setName("d"))) commandList = sty.getStringValue();
    130 
    131    
    132         //If glyph path was specified, calculate it
    133         if (commandList != null)
    134         {
    135 //            StyleAttribute atyleAttrib = getStyle("fill-rule");
    136             String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
    137 
    138             PathCommand[] commands = parsePathList(commandList);
    139 
    140 //            ExtendedGeneralPath buildPath = new ExtendedGeneralPath(
    141             GeneralPath buildPath = new GeneralPath(
    142                 fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
    143                 commands.length);
    144 
    145             BuildHistory hist = new BuildHistory();
    146 
    147             for (int i = 0; i < commands.length; i++)
    148             {
    149                 PathCommand cmd = commands[i];
    150                 cmd.appendPath(buildPath, hist);
    151             }
    152 
    153             //Reflect glyph path to put it in user coordinate system
    154             AffineTransform at = new AffineTransform();
    155             at.scale(1, -1);
    156             path = at.createTransformedShape(buildPath);
    157         }
    158 
    159 
    160         //Read glyph spacing info
    161         if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue();
    162 
    163         if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue();
    164 
    165         if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue();
    166 
    167         if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue();
     129        if (getPres(sty.setName("horiz-adv-x")))
     130        {
     131            horizAdvX = sty.getIntValue();
     132        }
     133
     134        if (getPres(sty.setName("vert-origin-x")))
     135        {
     136            vertOriginX = sty.getIntValue();
     137        }
     138
     139        if (getPres(sty.setName("vert-origin-y")))
     140        {
     141            vertOriginY = sty.getIntValue();
     142        }
     143
     144        if (getPres(sty.setName("vert-adv-y")))
     145        {
     146            vertAdvY = sty.getIntValue();
     147        }
    168148    }
    169149
     
    177157        //Do not push or pop stack
    178158
    179         if (path != null) renderShape(g, path);
    180        
     159        if (path != null)
     160        {
     161            renderShape(g, path);
     162        }
     163
    181164        Iterator it = children.iterator();
    182165        while (it.hasNext())
    183166        {
    184             SVGElement ele = (SVGElement)it.next();
     167            SVGElement ele = (SVGElement) it.next();
    185168            if (ele instanceof RenderableElement)
    186169            {
    187                 ((RenderableElement)ele).render(g);
     170                ((RenderableElement) ele).render(g);
    188171            }
    189172        }
     
    195178    {
    196179        if (horizAdvX == -1)
    197             horizAdvX = ((Font)parent).getHorizAdvX();
     180        {
     181            horizAdvX = ((Font) parent).getHorizAdvX();
     182        }
    198183        return horizAdvX;
    199184    }
     
    202187    {
    203188        if (vertOriginX == -1)
     189        {
    204190            vertOriginX = getHorizAdvX() / 2;
     191        }
    205192        return vertOriginX;
    206193    }
     
    209196    {
    210197        if (vertOriginY == -1)
    211             vertOriginY = ((Font)parent).getFontFace().getAscent();
     198        {
     199            vertOriginY = ((Font) parent).getFontFace().getAscent();
     200        }
    212201        return vertOriginY;
    213202    }
     
    216205    {
    217206        if (vertAdvY == -1)
    218             vertAdvY = ((Font)parent).getFontFace().getUnitsPerEm();
     207        {
     208            vertAdvY = ((Font) parent).getFontFace().getUnitsPerEm();
     209        }
    219210        return vertAdvY;
    220211
     
    223214    public Shape getShape()
    224215    {
    225         if (path != null) return shapeToParent(path);
     216        if (path != null)
     217        {
     218            return shapeToParent(path);
     219        }
    226220        return null;
    227221    }
     
    229223    public Rectangle2D getBoundingBox() throws SVGException
    230224    {
    231         if (path != null) return boundsToParent(includeStrokeInBounds(path.getBounds2D()));
     225        if (path != null)
     226        {
     227            return boundsToParent(includeStrokeInBounds(path.getBounds2D()));
     228        }
    232229        return null;
    233230    }
    234231
    235232    /**
    236      * Updates all attributes in this diagram associated with a time event.
    237      * Ie, all attributes with track information.
     233     * Updates all attributes in this diagram associated with a time event. Ie,
     234     * all attributes with track information.
     235     *
    238236     * @return - true if this node has changed state as a result of the time
    239237     * update
  • trunk/src/com/kitfox/svg/Path.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import java.awt.*;
    32 import java.awt.geom.*;
    33 
    34 import com.kitfox.svg.pathcmd.*;
    35 import com.kitfox.svg.xml.*;
    36 import org.xml.sax.*;
     39import java.awt.Graphics2D;
     40import java.awt.Shape;
     41import java.awt.geom.GeneralPath;
     42import java.awt.geom.Rectangle2D;
    3743
    3844//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
    39 
    4045/**
    4146 * @author Mark McKay
    4247 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4348 */
    44 public class Path extends ShapeElement {
     49public class Path extends ShapeElement
     50{
    4551
     52    public static final String TAG_NAME = "path";
    4653//    PathCommand[] commands = null;
    47 
    4854    int fillRule = GeneralPath.WIND_NON_ZERO;
    4955    String d = "";
     
    5157    GeneralPath path;
    5258
    53     /** Creates a new instance of Rect */
    54     public Path() {
     59    /**
     60     * Creates a new instance of Rect
     61     */
     62    public Path()
     63    {
    5564    }
    5665
    57     /*
    58     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     66    public String getTagName()
    5967    {
    60                 //Load style string
    61         super.loaderStartElement(helper, attrs, parent);
     68        return TAG_NAME;
     69    }
    6270
    63         StyleAttribute styleAttrib = getStyle("fill-rule");
    64         String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();
    65        
    66         String d = attrs.getValue("d");
    67         path = buildPath(d, fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO);
    68     }
    69     */
    70    
    7171    protected void build() throws SVGException
    7272    {
    7373        super.build();
    74        
     74
    7575        StyleAttribute sty = new StyleAttribute();
    76        
    77    
    78         String fillRuleStrn  = (getStyle(sty.setName("fill-rule"))) ? sty.getStringValue() : "nonzero";
     76
     77
     78        String fillRuleStrn = (getStyle(sty.setName("fill-rule"))) ? sty.getStringValue() : "nonzero";
    7979        fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
    80        
    81 //        String d = "";
    82         if (getPres(sty.setName("d"))) d = sty.getStringValue();
    8380
    84 //System.err.println(d);
    85        
     81        if (getPres(sty.setName("d")))
     82        {
     83            d = sty.getStringValue();
     84        }
     85
    8686        path = buildPath(d, fillRule);
    87        
    88 //System.err.println(d);
    8987    }
    90    
     88
    9189    public void render(Graphics2D g) throws SVGException
    9290    {
     
    107105
    108106    /**
    109      * Updates all attributes in this diagram associated with a time event.
    110      * Ie, all attributes with track information.
     107     * Updates all attributes in this diagram associated with a time event. Ie,
     108     * all attributes with track information.
     109     *
    111110     * @return - true if this node has changed state as a result of the time
    112111     * update
     
    120119        StyleAttribute sty = new StyleAttribute();
    121120        boolean shapeChange = false;
    122        
     121
    123122        if (getStyle(sty.setName("fill-rule")))
    124123        {
    125             int newVal = sty.getStringValue().equals("evenodd") 
    126                 ? GeneralPath.WIND_EVEN_ODD 
     124            int newVal = sty.getStringValue().equals("evenodd")
     125                ? GeneralPath.WIND_EVEN_ODD
    127126                : GeneralPath.WIND_NON_ZERO;
    128127            if (newVal != fillRule)
     
    132131            }
    133132        }
    134        
     133
    135134        if (getPres(sty.setName("d")))
    136135        {
     
    142141            }
    143142        }
    144        
     143
    145144        if (shapeChange)
    146145        {
     
    149148//            return true;
    150149        }
    151        
     150
    152151        return changeState || shapeChange;
    153152    }
  • trunk/src/com/kitfox/svg/PatternSVG.java

    r4256 r6002  
    11/*
    2  * Gradient.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, 3:25 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     38import com.kitfox.svg.pattern.PatternPaint;
    3039import com.kitfox.svg.xml.StyleAttribute;
    31 import java.net.*;
    32 import java.util.*;
    33 import java.awt.geom.*;
    34 import java.awt.*;
    35 import java.awt.image.*;
    36 
    37 import com.kitfox.svg.pattern.*;
    38 import com.kitfox.svg.xml.*;
    39 import org.xml.sax.*;
     40import java.awt.Graphics2D;
     41import java.awt.Paint;
     42import java.awt.RenderingHints;
     43import java.awt.TexturePaint;
     44import java.awt.geom.AffineTransform;
     45import java.awt.geom.Point2D;
     46import java.awt.geom.Rectangle2D;
     47import java.awt.image.BufferedImage;
     48import java.net.URI;
     49import java.util.Iterator;
     50import java.util.logging.Level;
     51import java.util.logging.Logger;
    4052
    4153/**
     
    4355 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4456 */
    45 public class PatternSVG extends FillElement {
    46 
     57public class PatternSVG extends FillElement
     58{
     59    public static final String TAG_NAME = "pattern";
     60   
    4761    public static final int GU_OBJECT_BOUNDING_BOX = 0;
    4862    public static final int GU_USER_SPACE_ON_USE = 1;
    49 
    5063    int gradientUnits = GU_OBJECT_BOUNDING_BOX;
    51 
    5264    float x;
    5365    float y;
    5466    float width;
    5567    float height;
    56 
    5768    AffineTransform patternXform = new AffineTransform();
    5869    Rectangle2D.Float viewBox;
    59 
    6070    Paint texPaint;
    6171
    62     /** Creates a new instance of Gradient */
    63     public PatternSVG() {
    64     }
    65 /*
    66     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    67     {
    68                 //Load style string
    69         super.loaderStartElement(helper, attrs, parent);
    70 
    71         String href = attrs.getValue("xlink:href");
    72         //If we have a link to another pattern, initialize ourselves with it's values
    73         if (href != null)
    74         {
    75 //System.err.println("Gradient.loaderStartElement() href '" + href + "'");
    76             try {
    77                 URI src = getXMLBase().resolve(href);
    78 //                URL url = srcUrl.toURL();
    79 //                URL url = new URL(helper.docRoot, href);
    80                 PatternSVG patSrc = (PatternSVG)helper.universe.getElement(src);
    81 
    82                 gradientUnits = patSrc.gradientUnits;
    83                 x = patSrc.x;
    84                 y = patSrc.y;
    85                 width = patSrc.width;
    86                 height = patSrc.height;
    87                 viewBox = patSrc.viewBox;
    88                 patternXform.setTransform(patSrc.patternXform);
    89                 members.addAll(patSrc.members);
    90             }
    91             catch (Exception e)
    92             {
    93                 e.printStackTrace();
    94             }
    95         }
    96 
    97 
    98         String gradientUnits = attrs.getValue("gradientUnits");
    99 
    100         if (gradientUnits != null)
    101         {
    102             if (gradientUnits.toLowerCase().equals("userspaceonuse")) this.gradientUnits = GU_USER_SPACE_ON_USE;
    103             else this.gradientUnits = GU_OBJECT_BOUNDING_BOX;
    104         }
    105 
    106         String patternTransform = attrs.getValue("patternTransform");
    107         if (patternTransform != null)
    108         {
    109             patternXform = parseTransform(patternTransform);
    110         }
    111 
    112         String x = attrs.getValue("x");
    113         String y = attrs.getValue("y");
    114         String width = attrs.getValue("width");
    115         String height = attrs.getValue("height");
    116 
    117         if (x != null) this.x = XMLParseUtil.parseFloat(x);
    118         if (y != null) this.y = XMLParseUtil.parseFloat(y);
    119         if (width != null) this.width = XMLParseUtil.parseFloat(width);
    120         if (height != null) this.height = XMLParseUtil.parseFloat(height);
    121 
    122         String viewBoxStrn = attrs.getValue("viewBox");
    123         if (viewBoxStrn != null)
    124         {
    125             float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);
    126             viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
    127         }
    128     }
    129   */ 
     72    /**
     73     * Creates a new instance of Gradient
     74     */
     75    public PatternSVG()
     76    {
     77    }
     78
     79    public String getTagName()
     80    {
     81        return TAG_NAME;
     82    }
     83
    13084    /**
    13185     * Called after the start element but before the end element to indicate
     
    13589    {
    13690        super.loaderAddChild(helper, child);
    137 
    138 //        members.add(child);
    139     }
    140    
     91    }
     92
    14193    protected void build() throws SVGException
    14294    {
    14395        super.build();
    144        
     96
    14597        StyleAttribute sty = new StyleAttribute();
    146        
    147                 //Load style string
     98
     99        //Load style string
    148100        String href = null;
    149         if (getPres(sty.setName("xlink:href"))) href = sty.getStringValue();
     101        if (getPres(sty.setName("xlink:href")))
     102        {
     103            href = sty.getStringValue();
     104        }
    150105        //String href = attrs.getValue("xlink:href");
    151106        //If we have a link to another pattern, initialize ourselves with it's values
     
    153108        {
    154109//System.err.println("Gradient.loaderStartElement() href '" + href + "'");
    155             try {
     110            try
     111            {
    156112                URI src = getXMLBase().resolve(href);
    157                 PatternSVG patSrc = (PatternSVG)diagram.getUniverse().getElement(src);
     113                PatternSVG patSrc = (PatternSVG) diagram.getUniverse().getElement(src);
    158114
    159115                gradientUnits = patSrc.gradientUnits;
     
    165121                patternXform.setTransform(patSrc.patternXform);
    166122                children.addAll(patSrc.children);
     123            } catch (Exception e)
     124            {
     125                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     126                    "Could not parse xlink:href", e);
    167127            }
    168             catch (Exception e)
    169             {
    170                 e.printStackTrace();
    171             }
    172128        }
    173129
    174130        String gradientUnits = "";
    175         if (getPres(sty.setName("gradientUnits"))) gradientUnits = sty.getStringValue().toLowerCase();
    176         if (gradientUnits.equals("userspaceonuse")) this.gradientUnits = GU_USER_SPACE_ON_USE;
    177         else this.gradientUnits = GU_OBJECT_BOUNDING_BOX;
     131        if (getPres(sty.setName("gradientUnits")))
     132        {
     133            gradientUnits = sty.getStringValue().toLowerCase();
     134        }
     135        if (gradientUnits.equals("userspaceonuse"))
     136        {
     137            this.gradientUnits = GU_USER_SPACE_ON_USE;
     138        } else
     139        {
     140            this.gradientUnits = GU_OBJECT_BOUNDING_BOX;
     141        }
    178142
    179143        String patternTransform = "";
    180         if (getPres(sty.setName("patternTransform"))) patternTransform = sty.getStringValue();
     144        if (getPres(sty.setName("patternTransform")))
     145        {
     146            patternTransform = sty.getStringValue();
     147        }
    181148        patternXform = parseTransform(patternTransform);
    182149
    183        
    184         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    185        
    186         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    187        
    188         if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
    189        
    190         if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
    191        
     150
     151        if (getPres(sty.setName("x")))
     152        {
     153            x = sty.getFloatValueWithUnits();
     154        }
     155
     156        if (getPres(sty.setName("y")))
     157        {
     158            y = sty.getFloatValueWithUnits();
     159        }
     160
     161        if (getPres(sty.setName("width")))
     162        {
     163            width = sty.getFloatValueWithUnits();
     164        }
     165
     166        if (getPres(sty.setName("height")))
     167        {
     168            height = sty.getFloatValueWithUnits();
     169        }
     170
    192171        if (getPres(sty.setName("viewBox")))
    193172        {
     
    195174            viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
    196175        }
    197            
     176
    198177        preparePattern();
    199178    }
    200    
    201 /*
    202     public void loaderEndElement(SVGLoaderHelper helper)
    203     {
    204         build();
    205     }
    206     */
    207 
     179
     180    /*
     181     public void loaderEndElement(SVGLoaderHelper helper)
     182     {
     183     build();
     184     }
     185     */
    208186    protected void preparePattern() throws SVGException
    209187    {
    210188        //For now, treat all fills as UserSpaceOnUse.  Otherwise, we'll need
    211189        // a different paint for every object.
    212         int tileWidth = (int)width;
    213         int tileHeight = (int)height;
     190        int tileWidth = (int) width;
     191        int tileHeight = (int) height;
    214192
    215193        float stretchX = 1f, stretchY = 1f;
     
    217195        {
    218196            //Scale our source tile so that we can have nice sampling from it.
    219             float xlateX = (float)patternXform.getTranslateX();
    220             float xlateY = (float)patternXform.getTranslateY();
     197            float xlateX = (float) patternXform.getTranslateX();
     198            float xlateY = (float) patternXform.getTranslateY();
    221199
    222200            Point2D.Float pt = new Point2D.Float(), pt2 = new Point2D.Float();
     
    226204            pt2.x -= xlateX;
    227205            pt2.y -= xlateY;
    228             stretchX = (float)Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width;
     206            stretchX = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / width;
    229207
    230208            pt.setLocation(height, 0);
     
    232210            pt2.x -= xlateX;
    233211            pt2.y -= xlateY;
    234             stretchY = (float)Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height;
     212            stretchY = (float) Math.sqrt(pt2.x * pt2.x + pt2.y * pt2.y) * 1.5f / height;
    235213
    236214            tileWidth *= stretchX;
     
    238216        }
    239217
    240         if (tileWidth == 0 || tileHeight == 0) 
     218        if (tileWidth == 0 || tileHeight == 0)
    241219        {
    242220            //Use defaults if tile has degenerate size
    243221            return;
    244222        }
    245        
     223
    246224        BufferedImage buf = new BufferedImage(tileWidth, tileHeight, BufferedImage.TYPE_INT_ARGB);
    247225        Graphics2D g = buf.createGraphics();
     
    251229        for (Iterator it = children.iterator(); it.hasNext();)
    252230        {
    253             SVGElement ele = (SVGElement)it.next();
     231            SVGElement ele = (SVGElement) it.next();
    254232            if (ele instanceof RenderableElement)
    255233            {
     
    259237                {
    260238                    xform.translate(-x, -y);
    261                 }
    262                 else
     239                } else
    263240                {
    264241                    xform.scale(tileWidth / viewBox.width, tileHeight / viewBox.height);
     
    267244
    268245                g.setTransform(xform);
    269                 ((RenderableElement)ele).render(g);
     246                ((RenderableElement) ele).render(g);
    270247            }
    271248        }
     
    280257        {
    281258            texPaint = new TexturePaint(buf, new Rectangle2D.Float(x, y, width, height));
    282         }
    283         else
     259        } else
    284260        {
    285261            patternXform.scale(1 / stretchX, 1 / stretchY);
     
    294270
    295271    /**
    296      * Updates all attributes in this diagram associated with a time event.
    297      * Ie, all attributes with track information.
     272     * Updates all attributes in this diagram associated with a time event. Ie,
     273     * all attributes with track information.
     274     *
    298275     * @return - true if this node has changed state as a result of the time
    299276     * update
  • trunk/src/com/kitfox/svg/Polygon.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    3139import com.kitfox.svg.xml.XMLParseUtil;
    32 import java.awt.geom.*;
    33 import java.awt.*;
    34 
    35 import com.kitfox.svg.xml.*;
    36 import org.xml.sax.*;
     40import java.awt.Graphics2D;
     41import java.awt.Shape;
     42import java.awt.geom.GeneralPath;
     43import java.awt.geom.Rectangle2D;
    3744
    3845/**
     
    4047 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4148 */
    42 public class Polygon extends ShapeElement {
     49public class Polygon extends ShapeElement
     50{
     51    public static final String TAG_NAME = "polygon";
    4352
    4453    int fillRule = GeneralPath.WIND_NON_ZERO;
    4554    String pointsStrn = "";
    46 //    float[] points = null;
    4755    GeneralPath path;
    4856
    49     /** Creates a new instance of Rect */
    50     public Polygon() {
     57    /**
     58     * Creates a new instance of Rect
     59     */
     60    public Polygon()
     61    {
    5162    }
    52 /*
    53     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     63
     64    public String getTagName()
    5465    {
    55                 //Load style string
    56         super.loaderStartElement(helper, attrs, parent);
     66        return TAG_NAME;
     67    }
    5768
    58 
    59         points = XMLParseUtil.parseFloatList(attrs.getValue("points"));
    60 
    61         build();
    62     }
    63 */
    64 /*
    65     public void build()
    66     {
    67         StyleAttribute styleAttrib = getStyle("fill-rule");
    68         String fillRule = (styleAttrib == null) ? "nonzero" : styleAttrib.getStringValue();
    69 
    70         path = new GeneralPath(
    71             fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO,
    72             points.length / 2);
    73 
    74         path.moveTo(points[0], points[1]);
    75         for (int i = 2; i < points.length; i += 2)
    76         {
    77             path.lineTo(points[i], points[i + 1]);
    78         }
    79         path.closePath();
    80     }
    81 */
    82    
    83 //static int yyyyy = 0;
    84    
    8569    protected void build() throws SVGException
    8670    {
    8771        super.build();
    88        
     72
    8973        StyleAttribute sty = new StyleAttribute();
    90        
    91         if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue();
    92        
     74
     75        if (getPres(sty.setName("points")))
     76        {
     77            pointsStrn = sty.getStringValue();
     78        }
     79
    9380        String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
    9481        fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
     
    9683        buildPath();
    9784    }
    98    
     85
    9986    protected void buildPath()
    10087    {
     
    10996        path.closePath();
    11097    }
    111    
     98
    11299    public void render(Graphics2D g) throws SVGException
    113100    {
     
    116103        finishLayer(g);
    117104    }
    118 
    119105
    120106    public Shape getShape()
     
    128114    }
    129115
    130 
    131116    /**
    132      * Updates all attributes in this diagram associated with a time event.
    133      * Ie, all attributes with track information.
     117     * Updates all attributes in this diagram associated with a time event. Ie,
     118     * all attributes with track information.
     119     *
    134120     * @return - true if this node has changed state as a result of the time
    135121     * update
     
    143129        StyleAttribute sty = new StyleAttribute();
    144130        boolean shapeChange = false;
    145        
     131
    146132        if (getStyle(sty.setName("fill-rule")))
    147133        {
    148             int newVal = sty.getStringValue().equals("evenodd") 
    149                 ? GeneralPath.WIND_EVEN_ODD 
     134            int newVal = sty.getStringValue().equals("evenodd")
     135                ? GeneralPath.WIND_EVEN_ODD
    150136                : GeneralPath.WIND_NON_ZERO;
    151137            if (newVal != fillRule)
     
    155141            }
    156142        }
    157        
     143
    158144        if (getPres(sty.setName("points")))
    159145        {
     
    165151            }
    166152        }
    167        
    168        
     153
     154
    169155        if (shapeChange)
    170156        {
     
    173159//            return true;
    174160        }
    175        
     161
    176162        return changeState || shapeChange;
    177163    }
  • trunk/src/com/kitfox/svg/Polyline.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    30 import java.awt.geom.*;
    31 import java.awt.*;
    32 
    33 import com.kitfox.svg.xml.*;
     38import com.kitfox.svg.xml.StyleAttribute;
     39import com.kitfox.svg.xml.XMLParseUtil;
     40import java.awt.Graphics2D;
     41import java.awt.Shape;
     42import java.awt.geom.GeneralPath;
     43import java.awt.geom.Rectangle2D;
    3444
    3545/**
     
    3747 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3848 */
    39 public class Polyline extends ShapeElement {
    40 
     49public class Polyline extends ShapeElement
     50{
     51    public static final String TAG_NAME = "polyline";
     52   
    4153    int fillRule = GeneralPath.WIND_NON_ZERO;
    4254    String pointsStrn = "";
    43 //    float[] points = null;
    4455    GeneralPath path;
    4556
    46     /** Creates a new instance of Rect */
    47     public Polyline() {
     57    /**
     58     * Creates a new instance of Rect
     59     */
     60    public Polyline()
     61    {
    4862    }
    4963
    50     /*
    51     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     64    public String getTagName()
    5265    {
    53                 //Load style string
    54         super.loaderStartElement(helper, attrs, parent);
    55 
    56 
    57         points = XMLParseUtil.parseFloatList(attrs.getValue("points"));
    58 
    59         build();
     66        return TAG_NAME;
    6067    }
    61     */
    6268
    6369    public void build() throws SVGException
    6470    {
    6571        super.build();
    66        
     72
    6773        StyleAttribute sty = new StyleAttribute();
    68        
    69         if (getPres(sty.setName("points"))) pointsStrn = sty.getStringValue();
    70        
     74
     75        if (getPres(sty.setName("points")))
     76        {
     77            pointsStrn = sty.getStringValue();
     78        }
     79
    7180        String fillRuleStrn = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero";
    7281        fillRule = fillRuleStrn.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO;
     
    7483        buildPath();
    7584    }
    76    
     85
    7786    protected void buildPath()
    7887    {
     
    105114
    106115    /**
    107      * Updates all attributes in this diagram associated with a time event.
    108      * Ie, all attributes with track information.
     116     * Updates all attributes in this diagram associated with a time event. Ie,
     117     * all attributes with track information.
     118     *
    109119     * @return - true if this node has changed state as a result of the time
    110120     * update
     
    118128        StyleAttribute sty = new StyleAttribute();
    119129        boolean shapeChange = false;
    120        
     130
    121131        if (getStyle(sty.setName("fill-rule")))
    122132        {
    123             int newVal = sty.getStringValue().equals("evenodd") 
    124                 ? GeneralPath.WIND_EVEN_ODD 
     133            int newVal = sty.getStringValue().equals("evenodd")
     134                ? GeneralPath.WIND_EVEN_ODD
    125135                : GeneralPath.WIND_NON_ZERO;
    126136            if (newVal != fillRule)
     
    130140            }
    131141        }
    132        
     142
    133143        if (getPres(sty.setName("points")))
    134144        {
     
    140150            }
    141151        }
    142        
    143        
     152
     153
    144154        if (shapeChange)
    145155        {
     
    148158//            return true;
    149159        }
    150        
     160
    151161        return changeState || shapeChange;
    152162    }
  • 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    }
  • trunk/src/com/kitfox/svg/Rect.java

    r4256 r6002  
    11/*
    2  * Rect.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, 5:25 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 
    32 import java.awt.*;
    33 import java.awt.geom.*;
     39import java.awt.Graphics2D;
     40import java.awt.Shape;
     41import java.awt.geom.Rectangle2D;
     42import java.awt.geom.RectangularShape;
     43import java.awt.geom.RoundRectangle2D;
    3444import java.io.IOException;
    3545import java.io.ObjectInputStream;
     
    4050 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4151 */
    42 public class Rect extends ShapeElement {
     52public class Rect extends ShapeElement
     53{
     54    public static final String TAG_NAME = "rect";
    4355
    4456    float x = 0f;
     
    4860    float rx = 0f;
    4961    float ry = 0f;
    50 
    5162    RectangularShape rect;
    5263
    53     /** Creates a new instance of Rect */
    54     public Rect() {
    55     }
    56 
    57     private void writeObject(ObjectOutputStream out) throws IOException   
     64    /**
     65     * Creates a new instance of Rect
     66     */
     67    public Rect()
     68    {
     69    }
     70
     71    public String getTagName()
     72    {
     73        return TAG_NAME;
     74    }
     75
     76    private void writeObject(ObjectOutputStream out) throws IOException
    5877    {
    5978        out.writeFloat(x);
     
    6483        out.writeFloat(ry);
    6584    }
    66    
     85
    6786    private void readObject(ObjectInputStream in) throws IOException
    6887    {
     
    7392        rx = in.readFloat();
    7493        ry = in.readFloat();
    75        
     94
    7695        if (rx == 0f && ry == 0f)
    7796        {
    7897            rect = new Rectangle2D.Float(x, y, width, height);
    79         }
    80         else
     98        } else
    8199        {
    82100            rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
    83101        }
    84102    }
    85    
     103
    86104    /*
    87     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    88     {
    89                 //Load style string
    90         super.loaderStartElement(helper, attrs, parent);
    91 
    92         String x = attrs.getValue("x");
    93         String y = attrs.getValue("y");
    94         String width = attrs.getValue("width");
    95         String height = attrs.getValue("height");
    96         String rx = attrs.getValue("rx");
    97         String ry = attrs.getValue("ry");
    98 
    99         if (rx == null) rx = ry;
    100         if (ry == null) ry = rx;
    101 
    102         this.x = XMLParseUtil.parseFloat(x);
    103         this.y = XMLParseUtil.parseFloat(y);
    104         this.width = XMLParseUtil.parseFloat(width);
    105         this.height = XMLParseUtil.parseFloat(height);
    106         if (rx != null)
    107         {
    108             this.rx = XMLParseUtil.parseFloat(rx);
    109             this.ry = XMLParseUtil.parseFloat(ry);
    110         }
    111 
    112         build();
    113 //        setBounds(this.x, this.y, this.width, this.height);
    114     }
    115 */
    116    
     105     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     106     {
     107     //Load style string
     108     super.loaderStartElement(helper, attrs, parent);
     109
     110     String x = attrs.getValue("x");
     111     String y = attrs.getValue("y");
     112     String width = attrs.getValue("width");
     113     String height = attrs.getValue("height");
     114     String rx = attrs.getValue("rx");
     115     String ry = attrs.getValue("ry");
     116
     117     if (rx == null) rx = ry;
     118     if (ry == null) ry = rx;
     119
     120     this.x = XMLParseUtil.parseFloat(x);
     121     this.y = XMLParseUtil.parseFloat(y);
     122     this.width = XMLParseUtil.parseFloat(width);
     123     this.height = XMLParseUtil.parseFloat(height);
     124     if (rx != null)
     125     {
     126     this.rx = XMLParseUtil.parseFloat(rx);
     127     this.ry = XMLParseUtil.parseFloat(ry);
     128     }
     129
     130     build();
     131     //        setBounds(this.x, this.y, this.width, this.height);
     132     }
     133     */
    117134    protected void build() throws SVGException
    118135    {
    119136        super.build();
    120        
     137
    121138        StyleAttribute sty = new StyleAttribute();
    122        
     139
    123140//        SVGElement parent = this.getParent();
    124141//        if (parent instanceof RenderableElement)
     
    128145//            bounds = null;
    129146//        }
    130        
    131        
    132         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    133        
    134         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    135        
    136         if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
    137        
    138         if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
     147
     148
     149        if (getPres(sty.setName("x")))
     150        {
     151            x = sty.getFloatValueWithUnits();
     152        }
     153
     154        if (getPres(sty.setName("y")))
     155        {
     156            y = sty.getFloatValueWithUnits();
     157        }
     158
     159        if (getPres(sty.setName("width")))
     160        {
     161            width = sty.getFloatValueWithUnits();
     162        }
     163
     164        if (getPres(sty.setName("height")))
     165        {
     166            height = sty.getFloatValueWithUnits();
     167        }
    139168
    140169        boolean rxSet = false;
    141         if (getPres(sty.setName("rx"))) { rx = sty.getFloatValueWithUnits(); rxSet = true; }
    142        
     170        if (getPres(sty.setName("rx")))
     171        {
     172            rx = sty.getFloatValueWithUnits();
     173            rxSet = true;
     174        }
     175
    143176        boolean rySet = false;
    144         if (getPres(sty.setName("ry"))) { ry = sty.getFloatValueWithUnits(); rySet = true; }
    145        
    146         if (!rxSet) rx = ry;
    147         if (!rySet) ry = rx;
    148 
    149        
     177        if (getPres(sty.setName("ry")))
     178        {
     179            ry = sty.getFloatValueWithUnits();
     180            rySet = true;
     181        }
     182
     183        if (!rxSet)
     184        {
     185            rx = ry;
     186        }
     187        if (!rySet)
     188        {
     189            ry = rx;
     190        }
     191
     192
    150193        if (rx == 0f && ry == 0f)
    151194        {
    152195            rect = new Rectangle2D.Float(x, y, width, height);
    153         }
    154         else
     196        } else
    155197        {
    156198            rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
     
    176218
    177219    /**
    178      * Updates all attributes in this diagram associated with a time event.
    179      * Ie, all attributes with track information.
     220     * Updates all attributes in this diagram associated with a time event. Ie,
     221     * all attributes with track information.
     222     *
    180223     * @return - true if this node has changed state as a result of the time
    181224     * update
     
    189232        StyleAttribute sty = new StyleAttribute();
    190233        boolean shapeChange = false;
    191        
     234
    192235        if (getPres(sty.setName("x")))
    193236        {
     
    263306//            return true;
    264307        }
    265        
     308
    266309        return changeState || shapeChange;
    267310    }
  • trunk/src/com/kitfox/svg/RenderableElement.java

    r4256 r6002  
    11/*
    2  * BoundedElement.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, 9:00 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3846import java.util.List;
    3947
    40 
    41 
    4248/**
    4349 * Maintains bounding box for this element
     
    4652 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4753 */
    48 abstract public class RenderableElement extends TransformableElement 
     54abstract public class RenderableElement extends TransformableElement
    4955{
    50 
    5156    AffineTransform cachedXform = null;
     57   
    5258    Shape cachedClip = null;
    53    
    5459    public static final int VECTOR_EFFECT_NONE = 0;
    5560    public static final int VECTOR_EFFECT_NON_SCALING_STROKE = 1;
    5661    int vectorEffect;
    5762
    58     /** Creates a new instance of BoundedElement */
    59     public RenderableElement() {
     63    /**
     64     * Creates a new instance of BoundedElement
     65     */
     66    public RenderableElement()
     67    {
    6068    }
    6169
     
    6876    {
    6977        super.build();
    70        
     78
    7179        StyleAttribute sty = new StyleAttribute();
    72        
     80
    7381        if (getPres(sty.setName("vector-effect")))
    7482        {
     
    7684            {
    7785                vectorEffect = VECTOR_EFFECT_NON_SCALING_STROKE;
    78             }
    79             else
     86            } else
    8087            {
    8188                vectorEffect = VECTOR_EFFECT_NONE;
    8289            }
    83         }
    84         else
     90        } else
    8591        {
    8692            vectorEffect = VECTOR_EFFECT_NONE;
    8793        }
    8894    }
    89    
     95
    9096    abstract public void render(Graphics2D g) throws SVGException;
    91    
     97
    9298    abstract void pick(Point2D point, boolean boundingBox, List retVec) throws SVGException;
    93    
     99
    94100    abstract void pick(Rectangle2D pickArea, AffineTransform ltw, boolean boundingBox, List retVec) throws SVGException;
    95    
     101
    96102    abstract public Rectangle2D getBoundingBox() throws SVGException;
    97 /*
    98     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    99     {
    100         super.loaderStartElement(helper, attrs, parent);
    101     }
    102 */
     103    /*
     104     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     105     {
     106     super.loaderStartElement(helper, attrs, parent);
     107     }
     108     */
     109
    103110    /**
    104111     * Pushes transform stack, transforms to local coordinates and sets up
     
    114121
    115122        StyleAttribute styleAttrib = new StyleAttribute();
    116        
     123
    117124        //Get clipping path
    118125//        StyleAttribute styleAttrib = getStyle("clip-path", false);
    119126        Shape clipPath = null;
    120127        int clipPathUnits = ClipPath.CP_USER_SPACE_ON_USE;
    121         if (getStyle(styleAttrib.setName("clip-path")))
     128        if (getStyle(styleAttrib.setName("clip-path"), false)
     129             && !"none".equals(styleAttrib.getStringValue()))
    122130        {
    123131            URI uri = styleAttrib.getURIValue(getXMLBase());
    124132            if (uri != null)
    125133            {
    126                 ClipPath ele = (ClipPath)diagram.getUniverse().getElement(uri);
     134                ClipPath ele = (ClipPath) diagram.getUniverse().getElement(uri);
    127135                clipPath = ele.getClipPathShape();
    128136                clipPathUnits = ele.getClipPathUnits();
     
    135143            if (clipPathUnits == ClipPath.CP_OBJECT_BOUNDING_BOX && (this instanceof ShapeElement))
    136144            {
    137                 Rectangle2D rect = ((ShapeElement)this).getBoundingBox();
     145                Rectangle2D rect = ((ShapeElement) this).getBoundingBox();
    138146                AffineTransform at = new AffineTransform();
    139147                at.scale(rect.getWidth(), rect.getHeight());
     
    142150
    143151            cachedClip = g.getClip();
    144             Area newClip = new Area(cachedClip);
    145             newClip.intersect(new Area(clipPath));
    146             g.setClip(newClip);
     152            if (cachedClip == null)
     153            {
     154                g.setClip(clipPath);
     155            } else
     156            {
     157                Area newClip = new Area(cachedClip);
     158                newClip.intersect(new Area(clipPath));
     159                g.setClip(newClip);
     160            }
    147161        }
    148162    }
    149163
    150164    /**
    151      * Restores transform and clipping values to the way they were before
    152      * this layer was drawn.
     165     * Restores transform and clipping values to the way they were before this
     166     * layer was drawn.
    153167     */
    154168    protected void finishLayer(Graphics2D g)
     
    164178        }
    165179    }
    166 
    167180}
  • trunk/src/com/kitfox/svg/SVGCache.java

    r4256 r6002  
    11/*
    2  * SVGUniverseSingleton.java
     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
    333 *
    434 * Created on April 2, 2005, 1:54 AM
  • trunk/src/com/kitfox/svg/SVGDiagram.java

    r4256 r6002  
    11/*
    2  * SVGDiagram.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:04 PM
     
    3847import java.util.HashMap;
    3948import java.util.List;
     49import java.util.logging.Level;
     50import java.util.logging.Logger;
    4051
    4152
     
    203214    {
    204215        this.root = root;
     216        root.setDiagram(this);
    205217    }
    206218
     
    239251            } catch (SVGException ex)
    240252            {
    241                 ex.printStackTrace();
     253                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     254                    "Could not build document", ex);
    242255            }
    243256        }
  • trunk/src/com/kitfox/svg/SVGDisplayPanel.java

    r4256 r6002  
    11/*
    2  * SVGDisplayPanel.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, 12:29 PM
     
    3140import java.awt.*;
    3241import java.awt.geom.*;
     42import java.util.logging.Level;
     43import java.util.logging.Logger;
    3344
    3445/**
     
    124135            catch (SVGException e)
    125136            {
    126                 e.printStackTrace();
     137                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     138                    "Could not render diagram", e);
    127139            }
    128140        }
  • trunk/src/com/kitfox/svg/SVGElement.java

    r4256 r6002  
    11/*
    2  * SVGElement.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:59 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    30 import java.util.*;
    31 import java.util.regex.*;
    32 import java.net.*;
    33 import java.awt.geom.*;
    34 
    35 import org.xml.sax.*;
    36 import com.kitfox.svg.pathcmd.*;
    37 import com.kitfox.svg.xml.*;
     38import com.kitfox.svg.pathcmd.Arc;
     39import com.kitfox.svg.pathcmd.BuildHistory;
     40import com.kitfox.svg.pathcmd.Cubic;
     41import com.kitfox.svg.pathcmd.CubicSmooth;
     42import com.kitfox.svg.pathcmd.Horizontal;
     43import com.kitfox.svg.pathcmd.LineTo;
     44import com.kitfox.svg.pathcmd.MoveTo;
     45import com.kitfox.svg.pathcmd.PathCommand;
     46import com.kitfox.svg.pathcmd.Quadratic;
     47import com.kitfox.svg.pathcmd.QuadraticSmooth;
     48import com.kitfox.svg.pathcmd.Terminal;
     49import com.kitfox.svg.pathcmd.Vertical;
     50import com.kitfox.svg.xml.StyleAttribute;
     51import com.kitfox.svg.xml.StyleSheet;
     52import com.kitfox.svg.xml.XMLParseUtil;
     53import java.awt.geom.AffineTransform;
     54import java.awt.geom.GeneralPath;
    3855import java.io.Serializable;
     56import java.net.URI;
     57import java.util.ArrayList;
     58import java.util.Collections;
     59import java.util.HashMap;
     60import java.util.HashSet;
     61import java.util.Iterator;
     62import java.util.LinkedList;
     63import java.util.List;
     64import java.util.Set;
     65import java.util.regex.Matcher;
     66import java.util.regex.Pattern;
     67import org.xml.sax.Attributes;
     68import org.xml.sax.SAXException;
     69
    3970
    4071/**
     
    4475abstract public class SVGElement implements Serializable
    4576{
     77
    4678    public static final long serialVersionUID = 0;
    47    
    4879    public static final String SVG_NS = "http://www.w3.org/2000/svg";
    49    
    5080    protected SVGElement parent = null;
    51    
    5281    protected final ArrayList children = new ArrayList();
    53    
    5482    protected String id = null;
    5583    /**
    56      * CSS class.  Used for applying style sheet information.
     84     * CSS class. Used for applying style sheet information.
    5785     */
    5886    protected String cssClass = null;
    59    
    6087    /**
    6188     * Styles defined for this elemnt via the <b>style</b> attribute.
    6289     */
    6390    protected final HashMap inlineStyles = new HashMap();
    64    
    65     /**
    66      * Presentation attributes set for this element.  Ie, any attribute other
     91    /**
     92     * Presentation attributes set for this element. Ie, any attribute other
    6793     * than the <b>style</b> attribute.
    6894     */
    6995    protected final HashMap presAttribs = new HashMap();
    70    
    7196    /**
    7297     * A list of presentation attributes to not include in the presentation
     
    7499     */
    75100    protected static final Set ignorePresAttrib;
     101
    76102    static
    77103    {
     
    81107//        set.add("style");
    82108//        set.add("xml:base");
    83        
     109
    84110        ignorePresAttrib = Collections.unmodifiableSet(set);
    85111    }
    86    
    87     /**
    88      * This element may override the URI we resolve against with an
    89      * xml:base attribute.  If so, a copy is placed here.  Otherwise, we defer
    90      * to our parent for the reolution base
     112    /**
     113     * This element may override the URI we resolve against with an xml:base
     114     * attribute. If so, a copy is placed here. Otherwise, we defer to our
     115     * parent for the reolution base
    91116     */
    92117    protected URI xmlBase = null;
    93    
    94118    /**
    95119     * The diagram this element belongs to
    96120     */
    97121    protected SVGDiagram diagram;
    98     /**
    99      * Link to the universe we reside in
    100      */
    101 //    protected SVGUniverse universe;
    102    
    103122    boolean dirty = true;
    104123
    105 //    public static final Matcher adobeId = Pattern.compile("(.*)_1_").matcher("");
    106 //    static final String fpNumRe = "[-+]?((\\d+)|(\\d*\\.\\d+))([-+]?[eE]\\d+)?";
    107    
    108     /** Creates a new instance of SVGElement */
     124    /**
     125     * Creates a new instance of SVGElement
     126     */
    109127    public SVGElement()
    110128    {
    111129        this(null, null, null);
    112130    }
    113    
     131
    114132    public SVGElement(String id, SVGElement parent)
    115133    {
    116134        this(id, null, parent);
    117135    }
    118    
     136
    119137    public SVGElement(String id, String cssClass, SVGElement parent)
    120138    {
     
    123141        this.parent = parent;
    124142    }
    125    
     143
     144    abstract public String getTagName();
     145
    126146    public SVGElement getParent()
    127147    {
    128148        return parent;
    129149    }
    130    
     150
    131151    void setParent(SVGElement parent)
    132152    {
    133153        this.parent = parent;
    134154    }
    135    
     155
    136156    /**
    137157     * @return an ordered list of nodes from the root of the tree to this node
     
    139159    public List getPath(List retVec)
    140160    {
    141         if (retVec == null) retVec = new ArrayList();
    142        
     161        if (retVec == null)
     162        {
     163            retVec = new ArrayList();
     164        }
     165
    143166        if (parent != null)
    144167        {
     
    146169        }
    147170        retVec.add(this);
    148        
     171
    149172        return retVec;
    150173    }
    151    
    152     /**
    153      * @param retVec - A list to add all children to.  If null, a new list is
     174
     175    /**
     176     * @param retVec - A list to add all children to. If null, a new list is
    154177     * created and children of this group are added.
    155178     *
     
    158181    public List getChildren(List retVec)
    159182    {
    160         if (retVec == null) retVec = new ArrayList();
    161        
     183        if (retVec == null)
     184        {
     185            retVec = new ArrayList();
     186        }
     187
    162188        retVec.addAll(children);
    163        
     189
    164190        return retVec;
    165191    }
    166    
     192
    167193    /**
    168194     * @param id - Id of svg element to return
     
    173199        for (Iterator it = children.iterator(); it.hasNext();)
    174200        {
    175             SVGElement ele = (SVGElement)it.next();
     201            SVGElement ele = (SVGElement) it.next();
    176202            String eleId = ele.getId();
    177             if (eleId != null && eleId.equals(id)) return ele;
    178         }
    179        
     203            if (eleId != null && eleId.equals(id))
     204            {
     205                return ele;
     206            }
     207        }
     208
    180209        return null;
    181210    }
    182    
    183     /**
    184      * Searches children for given element.  If found, returns index of child.
     211
     212    /**
     213     * Searches children for given element. If found, returns index of child.
    185214     * Otherwise returns -1.
    186215     */
     
    189218        return children.indexOf(child);
    190219    }
    191    
     220
    192221    /**
    193222     * Swaps 2 elements in children.
     223     *
    194224     * @i index of first
    195225     * @j index of second
     
    203233            return;
    204234        }
    205        
     235
    206236        Object temp = children.get(i);
    207237        children.set(i, children.get(j));
     
    209239        build();
    210240    }
    211    
    212     /**
    213      * Called during SAX load process to notify that this tag has begun the process
    214      * of being loaded
     241
     242    /**
     243     * Called during SAX load process to notify that this tag has begun the
     244     * process of being loaded
     245     *
    215246     * @param attrs - Attributes of this tag
    216      * @param helper - An object passed to all SVG elements involved in this build
    217      * process to aid in sharing information.
     247     * @param helper - An object passed to all SVG elements involved in this
     248     * build process to aid in sharing information.
    218249     */
    219250    public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) throws SAXException
     
    222253        this.parent = parent;
    223254        this.diagram = helper.diagram;
    224        
     255
    225256        this.id = attrs.getValue("id");
    226257        if (this.id != null && !this.id.equals(""))
     
    228259            diagram.setElement(this.id, this);
    229260        }
    230        
     261
    231262        String className = attrs.getValue("class");
    232263        this.cssClass = (className == null || className.equals("")) ? null : className;
    233264        //docRoot = helper.docRoot;
    234265        //universe = helper.universe;
    235        
     266
    236267        //Parse style string, if any
    237268        String style = attrs.getValue("style");
     
    240271            HashMap map = XMLParseUtil.parseStyle(style, inlineStyles);
    241272        }
    242        
     273
    243274        String base = attrs.getValue("xml:base");
    244275        if (base != null && !base.equals(""))
     
    247278            {
    248279                xmlBase = new URI(base);
    249             }
    250             catch (Exception e)
     280            } catch (Exception e)
    251281            {
    252282                throw new SAXException(e);
    253283            }
    254284        }
    255        
     285
    256286        //Place all other attributes into the presentation attribute list
    257287        int numAttrs = attrs.getLength();
     
    259289        {
    260290            String name = attrs.getQName(i);
    261             if (ignorePresAttrib.contains(name)) continue;
     291            if (ignorePresAttrib.contains(name))
     292            {
     293                continue;
     294            }
    262295            String value = attrs.getValue(i);
    263            
     296
    264297            presAttribs.put(name, new StyleAttribute(name, value));
    265298        }
    266299    }
    267    
     300
    268301    /**
    269302     * @return a set of Strings that corespond to CSS attributes on this element
     
    273306        return inlineStyles.keySet();
    274307    }
    275    
     308
    276309    /**
    277310     * @return a set of Strings that corespond to XML attributes on this element
     
    281314        return presAttribs.keySet();
    282315    }
    283    
     316
    284317    /**
    285318     * Called after the start element but before the end element to indicate
     
    292325        child.setDiagram(diagram);
    293326    }
    294    
    295     private void setDiagram(SVGDiagram diagram)
     327
     328    protected void setDiagram(SVGDiagram diagram)
    296329    {
    297330        this.diagram = diagram;
     
    299332        for (Iterator it = children.iterator(); it.hasNext();)
    300333        {
    301             SVGElement ele = (SVGElement)it.next();
     334            SVGElement ele = (SVGElement) it.next();
    302335            ele.setDiagram(diagram);
    303336        }
    304337    }
    305    
     338
    306339    public void removeChild(SVGElement child) throws SVGElementException
    307340    {
     
    310343            throw new SVGElementException(this, "Element does not contain child " + child);
    311344        }
    312        
     345
    313346        children.remove(child);
    314347    }
    315    
     348
    316349    /**
    317350     * Called during load process to add text scanned within a tag
     
    320353    {
    321354    }
    322    
    323     /**
    324      * Called to indicate that this tag and the tags it contains have been completely
    325      * processed, and that it should finish any load processes.
     355
     356    /**
     357     * Called to indicate that this tag and the tags it contains have been
     358     * completely processed, and that it should finish any load processes.
    326359     */
    327360    public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException
    328361    {
    329         try
    330         {
    331             build();
    332         }
    333         catch (SVGException se)
    334         {
    335             throw new SVGParseException(se);
    336         }
    337     }
    338    
    339     /**
    340      * Called by internal processes to rebuild the geometry of this node
    341      * from it's presentation attributes, style attributes and animated tracks.
     362//        try
     363//        {
     364//            build();
     365//        }
     366//        catch (SVGException se)
     367//        {
     368//            throw new SVGParseException(se);
     369//        }
     370    }
     371
     372    /**
     373     * Called by internal processes to rebuild the geometry of this node from
     374     * it's presentation attributes, style attributes and animated tracks.
    342375     */
    343376    protected void build() throws SVGException
    344377    {
    345378        StyleAttribute sty = new StyleAttribute();
    346        
     379
    347380        if (getPres(sty.setName("id")))
    348381        {
     
    355388            }
    356389        }
    357         if (getPres(sty.setName("class"))) cssClass = sty.getStringValue();
    358         if (getPres(sty.setName("xml:base"))) xmlBase = sty.getURIValue();
    359     }
    360    
     390        if (getPres(sty.setName("class")))
     391        {
     392            cssClass = sty.getStringValue();
     393        }
     394        if (getPres(sty.setName("xml:base")))
     395        {
     396            xmlBase = sty.getURIValue();
     397        }
     398
     399        //Build children
     400        for (int i = 0; i < children.size(); ++i)
     401        {
     402            SVGElement ele = (SVGElement) children.get(i);
     403            ele.build();
     404        }
     405    }
     406
    361407    public URI getXMLBase()
    362408    {
    363         return xmlBase != null ? xmlBase :
    364             (parent != null ? parent.getXMLBase() : diagram.getXMLBase());
    365     }
    366 
    367     /**
    368      * @return the id assigned to this node.  Null if no id explicitly set.
     409        return xmlBase != null ? xmlBase
     410            : (parent != null ? parent.getXMLBase() : diagram.getXMLBase());
     411    }
     412
     413    /**
     414     * @return the id assigned to this node. Null if no id explicitly set.
    369415     */
    370416    public String getId()
    371417    {
    372         return id;
    373     }
    374    
    375    
     418        return id;
     419    }
    376420    LinkedList contexts = new LinkedList();
    377    
    378     /**
    379      * Hack to allow nodes to temporarily change their parents.  The Use tag will
     421
     422    /**
     423     * Hack to allow nodes to temporarily change their parents. The Use tag will
    380424     * need this so it can alter the attributes that a particular node uses.
    381425     */
     
    387431    protected SVGElement popParentContext()
    388432    {
    389         return (SVGElement)contexts.removeLast();
    390     }
    391    
     433        return (SVGElement) contexts.removeLast();
     434    }
     435
    392436    protected SVGElement getParentContext()
    393437    {
    394         return contexts.isEmpty() ? null : (SVGElement)contexts.getLast();
    395     }
    396    
     438        return contexts.isEmpty() ? null : (SVGElement) contexts.getLast();
     439    }
     440
     441    public SVGRoot getRoot()
     442    {
     443        return parent == null ? null : parent.getRoot();
     444    }
     445
    397446    /*
    398447     * Returns the named style attribute.  Checks for inline styles first, then
     
    408457        return getStyle(attrib, true);
    409458    }
    410    
    411     /**
    412      * Copies the current style into the passed style attribute.  Checks for
    413      * inline styles first, then internal and extranal style sheets, and
    414      * finally checks for presentation attributes.  Recursively checks parents.
    415      * @param attrib - Attribute to write style data to.  Must have it's name
    416      * set to the name of the style being queried.
    417      * @param recursive - If true and this object does not contain the
    418      * named style attribute, checks attributes of parents abck to root until
    419      * one found.
     459
     460    /**
     461     * Copies the current style into the passed style attribute. Checks for
     462     * inline styles first, then internal and extranal style sheets, and finally
     463     * checks for presentation attributes. Recursively checks parents.
     464     *
     465     * @param attrib - Attribute to write style data to. Must have it's name set
     466     * to the name of the style being queried.
     467     * @param recursive - If true and this object does not contain the named
     468     * style attribute, checks attributes of parents back to root until one
     469     * found.
    420470     */
    421471    public boolean getStyle(StyleAttribute attrib, boolean recursive) throws SVGException
    422472    {
    423473        String styName = attrib.getName();
    424        
     474
    425475        //Check for local inline styles
    426476        StyleAttribute styAttr = (StyleAttribute)inlineStyles.get(styName);
    427        
     477
    428478        attrib.setStringValue(styAttr == null ? "" : styAttr.getStringValue());
    429        
     479
    430480        //Return if we've found a non animated style
    431         if (styAttr != null) return true;
    432        
    433        
    434        
    435         //Implement style sheet lookup later
    436        
     481        if (styAttr != null)
     482        {
     483            return true;
     484        }
     485
     486
    437487        //Check for presentation attribute
    438488        StyleAttribute presAttr = (StyleAttribute)presAttribs.get(styName);
    439        
     489
    440490        attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
    441        
     491
    442492        //Return if we've found a presentation attribute instead
    443         if (presAttr != null) return true;
    444        
    445        
     493        if (presAttr != null)
     494        {
     495            return true;
     496        }
     497
     498        //Check for style sheet
     499        SVGRoot root = getRoot();
     500        if (root != null)
     501        {
     502            StyleSheet ss = root.getStyleSheet();
     503            if (ss != null)
     504            {
     505                return ss.getStyle(attrib, getTagName(), cssClass);
     506            }
     507        }
     508
    446509        //If we're recursive, check parents
    447510        if (recursive)
    448511        {
    449512            SVGElement parentContext = getParentContext();
    450             if (parentContext != null) return parentContext.getStyle(attrib, true);
    451             if (parent != null) return parent.getStyle(attrib, true);
    452         }
    453        
     513            if (parentContext != null)
     514            {
     515                return parentContext.getStyle(attrib, true);
     516            }
     517            if (parent != null)
     518            {
     519                return parent.getStyle(attrib, true);
     520            }
     521        }
     522
    454523        //Unsuccessful reading style attribute
    455524        return false;
    456525    }
    457    
    458     /**
    459      * @return the raw style value of this attribute.  Does not take the
    460      * presentation value or animation into consideration.  Used by animations
    461      * to determine the base to animate from.
     526
     527    /**
     528     * @return the raw style value of this attribute. Does not take the
     529     * presentation value or animation into consideration. Used by animations to
     530     * determine the base to animate from.
    462531     */
    463532    public StyleAttribute getStyleAbsolute(String styName)
    464533    {
    465534        //Check for local inline styles
    466         return (StyleAttribute)inlineStyles.get(styName);
    467     }
    468    
     535        return (StyleAttribute) inlineStyles.get(styName);
     536    }
     537
    469538    /**
    470539     * Copies the presentation attribute into the passed one.
     540     *
    471541     * @return - True if attribute was read successfully
    472542     */
     
    474544    {
    475545        String presName = attrib.getName();
    476        
     546
    477547        //Make sure we have a coresponding presentation attribute
    478         StyleAttribute presAttr = (StyleAttribute)presAttribs.get(presName);
    479        
     548        StyleAttribute presAttr = (StyleAttribute) presAttribs.get(presName);
     549
    480550        //Copy presentation value directly
    481551        attrib.setStringValue(presAttr == null ? "" : presAttr.getStringValue());
    482        
     552
    483553        //Return if we found presentation attribute
    484         if (presAttr != null) return true;
    485        
     554        if (presAttr != null)
     555        {
     556            return true;
     557        }
     558
    486559        return false;
    487560    }
    488    
    489     /**
    490      * @return the raw presentation value of this attribute.  Ignores any
    491      * modifications applied by style attributes or animation.  Used by
     561
     562    /**
     563     * @return the raw presentation value of this attribute. Ignores any
     564     * modifications applied by style attributes or animation. Used by
    492565     * animations to determine the starting point to animate from
    493566     */
     
    495568    {
    496569        //Check for local inline styles
    497         return (StyleAttribute)presAttribs.get(styName);
    498     }
    499    
     570        return (StyleAttribute) presAttribs.get(styName);
     571    }
     572
    500573    static protected AffineTransform parseTransform(String val) throws SVGException
    501574    {
    502575        final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");
    503        
     576
    504577        AffineTransform retXform = new AffineTransform();
    505        
     578
    506579        matchExpression.reset(val);
    507580        while (matchExpression.find())
     
    509582            retXform.concatenate(parseSingleTransform(matchExpression.group()));
    510583        }
    511        
     584
    512585        return retXform;
    513586    }
    514    
     587
    515588    static public AffineTransform parseSingleTransform(String val) throws SVGException
    516589    {
    517590        final Matcher matchWord = Pattern.compile("[-.\\w]+").matcher("");
    518        
     591
    519592        AffineTransform retXform = new AffineTransform();
    520        
     593
    521594        matchWord.reset(val);
    522595        if (!matchWord.find())
     
    525598            return retXform;
    526599        }
    527        
     600
    528601        String function = matchWord.group().toLowerCase();
    529        
     602
    530603        LinkedList termList = new LinkedList();
    531604        while (matchWord.find())
     
    533606            termList.add(matchWord.group());
    534607        }
    535        
    536        
     608
     609
    537610        double[] terms = new double[termList.size()];
    538611        Iterator it = termList.iterator();
     
    540613        while (it.hasNext())
    541614        {
    542             terms[count++] = XMLParseUtil.parseDouble((String)it.next());
    543         }
    544        
     615            terms[count++] = XMLParseUtil.parseDouble((String) it.next());
     616        }
     617
    545618        //Calculate transformation
    546619        if (function.equals("matrix"))
    547620        {
    548621            retXform.setTransform(terms[0], terms[1], terms[2], terms[3], terms[4], terms[5]);
    549         }
    550         else if (function.equals("translate"))
    551         {
    552             retXform.setToTranslation(terms[0], terms[1]);
    553         }
    554         else if (function.equals("scale"))
     622        } else if (function.equals("translate"))
     623        {
     624            if (terms.length == 1)
     625            {
     626                retXform.setToTranslation(terms[0], 0);
     627            } else
     628            {
     629                retXform.setToTranslation(terms[0], terms[1]);
     630            }
     631        } else if (function.equals("scale"))
    555632        {
    556633            if (terms.length > 1)
     634            {
    557635                retXform.setToScale(terms[0], terms[1]);
    558             else
     636            } else
     637            {
    559638                retXform.setToScale(terms[0], terms[0]);
    560         }
    561         else if (function.equals("rotate"))
     639            }
     640        } else if (function.equals("rotate"))
    562641        {
    563642            if (terms.length > 2)
     643            {
    564644                retXform.setToRotation(Math.toRadians(terms[0]), terms[1], terms[2]);
    565             else
     645            } else
     646            {
    566647                retXform.setToRotation(Math.toRadians(terms[0]));
    567         }
    568         else if (function.equals("skewx"))
     648            }
     649        } else if (function.equals("skewx"))
    569650        {
    570651            retXform.setToShear(Math.toRadians(terms[0]), 0.0);
    571         }
    572         else if (function.equals("skewy"))
     652        } else if (function.equals("skewy"))
    573653        {
    574654            retXform.setToShear(0.0, Math.toRadians(terms[0]));
    575         }
    576         else
     655        } else
    577656        {
    578657            throw new SVGException("Unknown transform type");
    579658        }
    580        
     659
    581660        return retXform;
    582661    }
    583    
     662
    584663    static protected float nextFloat(LinkedList l)
    585664    {
    586         String s = (String)l.removeFirst();
     665        String s = (String) l.removeFirst();
    587666        return Float.parseFloat(s);
    588667    }
    589    
     668
    590669    static protected PathCommand[] parsePathList(String list)
    591670    {
    592671        final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
    593        
     672
    594673        //Tokenize
    595674        LinkedList tokens = new LinkedList();
     
    598677            tokens.addLast(matchPathCmd.group());
    599678        }
    600        
    601        
     679
     680
    602681        boolean defaultRelative = false;
    603682        LinkedList cmdList = new LinkedList();
     
    605684        while (tokens.size() != 0)
    606685        {
    607             String curToken = (String)tokens.removeFirst();
     686            String curToken = (String) tokens.removeFirst();
    608687            char initChar = curToken.charAt(0);
    609             if ((initChar >= 'A' && initChar <='Z') || (initChar >= 'a' && initChar <='z'))
     688            if ((initChar >= 'A' && initChar <= 'Z') || (initChar >= 'a' && initChar <= 'z'))
    610689            {
    611690                curCmd = initChar;
    612             }
    613             else
     691            } else
    614692            {
    615693                tokens.addFirst(curToken);
    616694            }
    617            
     695
    618696            PathCommand cmd = null;
    619            
     697
    620698            switch (curCmd)
    621699            {
     
    648726                case 'A':
    649727                    cmd = new Arc(false, nextFloat(tokens), nextFloat(tokens),
    650                             nextFloat(tokens),
    651                             nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
    652                             nextFloat(tokens), nextFloat(tokens));
     728                        nextFloat(tokens),
     729                        nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
     730                        nextFloat(tokens), nextFloat(tokens));
    653731                    break;
    654732                case 'a':
    655733                    cmd = new Arc(true, nextFloat(tokens), nextFloat(tokens),
    656                             nextFloat(tokens),
    657                             nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
    658                             nextFloat(tokens), nextFloat(tokens));
     734                        nextFloat(tokens),
     735                        nextFloat(tokens) == 1f, nextFloat(tokens) == 1f,
     736                        nextFloat(tokens), nextFloat(tokens));
    659737                    break;
    660738                case 'Q':
    661739                    cmd = new Quadratic(false, nextFloat(tokens), nextFloat(tokens),
    662                             nextFloat(tokens), nextFloat(tokens));
     740                        nextFloat(tokens), nextFloat(tokens));
    663741                    break;
    664742                case 'q':
    665743                    cmd = new Quadratic(true, nextFloat(tokens), nextFloat(tokens),
    666                             nextFloat(tokens), nextFloat(tokens));
     744                        nextFloat(tokens), nextFloat(tokens));
    667745                    break;
    668746                case 'T':
     
    674752                case 'C':
    675753                    cmd = new Cubic(false, nextFloat(tokens), nextFloat(tokens),
    676                             nextFloat(tokens), nextFloat(tokens),
    677                             nextFloat(tokens), nextFloat(tokens));
     754                        nextFloat(tokens), nextFloat(tokens),
     755                        nextFloat(tokens), nextFloat(tokens));
    678756                    break;
    679757                case 'c':
    680758                    cmd = new Cubic(true, nextFloat(tokens), nextFloat(tokens),
    681                             nextFloat(tokens), nextFloat(tokens),
    682                             nextFloat(tokens), nextFloat(tokens));
     759                        nextFloat(tokens), nextFloat(tokens),
     760                        nextFloat(tokens), nextFloat(tokens));
    683761                    break;
    684762                case 'S':
    685763                    cmd = new CubicSmooth(false, nextFloat(tokens), nextFloat(tokens),
    686                             nextFloat(tokens), nextFloat(tokens));
     764                        nextFloat(tokens), nextFloat(tokens));
    687765                    break;
    688766                case 's':
    689767                    cmd = new CubicSmooth(true, nextFloat(tokens), nextFloat(tokens),
    690                             nextFloat(tokens), nextFloat(tokens));
     768                        nextFloat(tokens), nextFloat(tokens));
    691769                    break;
    692770                case 'Z':
     
    697775                    throw new RuntimeException("Invalid path element");
    698776            }
    699            
     777
    700778            cmdList.add(cmd);
    701779            defaultRelative = cmd.isRelative;
    702780        }
    703        
     781
    704782        PathCommand[] retArr = new PathCommand[cmdList.size()];
    705783        cmdList.toArray(retArr);
    706784        return retArr;
    707785    }
    708    
     786
    709787    static protected GeneralPath buildPath(String text, int windingRule)
    710788    {
    711789        PathCommand[] commands = parsePathList(text);
    712        
     790
    713791        int numKnots = 2;
    714792        for (int i = 0; i < commands.length; i++)
     
    716794            numKnots += commands[i].getNumKnotsAdded();
    717795        }
    718        
    719        
     796
     797
    720798        GeneralPath path = new GeneralPath(windingRule, numKnots);
    721        
     799
    722800        BuildHistory hist = new BuildHistory();
    723        
     801
    724802        for (int i = 0; i < commands.length; i++)
    725803        {
     
    727805            cmd.appendPath(path, hist);
    728806        }
    729        
     807
    730808        return path;
    731809    }
    732    
    733    
    734    
    735     /**
    736      * Updates all attributes in this diagram associated with a time event.
    737      * Ie, all attributes with track information.
     810
     811    /**
     812     * Updates all attributes in this diagram associated with a time event. Ie,
     813     * all attributes with track information.
     814     *
    738815     * @return - true if this node has changed state as a result of the time
    739816     * update
     
    748825    public SVGElement getChild(int i)
    749826    {
    750         return (SVGElement)children.get(i);
    751     }
    752    
     827        return (SVGElement) children.get(i);
     828    }
     829
     830    public double lerp(double t0, double t1, double alpha)
     831    {
     832        return (1 - alpha) * t0 + alpha * t1;
     833    }
    753834}
  • trunk/src/com/kitfox/svg/SVGElementException.java

    r4256 r6002  
    11/*
    2  * SVGException.java
     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
    333 *
    434 * Created on May 12, 2005, 11:32 PM
    5  *
    6  * To change this template, choose Tools | Options and locate the template under
    7  * the Source Creation and Management node. Right-click the template and choose
    8  * Open. You can then make changes to the template in the Source Editor.
    935 */
    1036
  • trunk/src/com/kitfox/svg/SVGException.java

    r4256 r6002  
    11/*
    2  * SVGException.java
     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
    333 *
    434 * Created on May 12, 2005, 11:32 PM
    5  *
    6  * To change this template, choose Tools | Options and locate the template under
    7  * the Source Creation and Management node. Right-click the template and choose
    8  * Open. You can then make changes to the template in the Source Editor.
    935 */
    1036
  • trunk/src/com/kitfox/svg/SVGLoader.java

    r4256 r6002  
    11/*
    2  * SVGLoader.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:09 PM
     
    3342import org.xml.sax.*;
    3443import org.xml.sax.helpers.DefaultHandler;
     44
     45import java.util.logging.Level;
     46import java.util.logging.Logger;
    3547
    3648/**
     
    186198        catch (Exception e)
    187199        {
    188             e.printStackTrace();
     200            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     201                "Could not load", e);
    189202            throw new SAXException(e);
    190203        }
     
    222235
    223236            SVGElement parent = null;
    224             if (buildStack.size() != 0) parent = (SVGElement)buildStack.getLast();
     237            if (buildStack.size() != 0)
     238            {
     239                parent = (SVGElement)buildStack.getLast();
     240            }
    225241            //else loadRoot = (SVGElement)svgEle;
    226242
    227             if (parent != null) parent.loaderAddChild(helper, svgEle);
    228             else diagram.setRoot((SVGRoot)svgEle);
     243            if (parent != null)
     244            {
     245                parent.loaderAddChild(helper, svgEle);
     246            }
     247            else
     248            {
     249                diagram.setRoot((SVGRoot)svgEle);
     250            }
    229251
    230252        }
    231253        catch (Exception e)
    232254        {
    233 e.printStackTrace();
     255            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     256                "Could not parse", e);
    234257            throw new SAXException(e);
    235258        }
  • trunk/src/com/kitfox/svg/SVGLoaderHelper.java

    r4256 r6002  
    11/*
    2  * SVGLoaderHelper.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 February 18, 2004, 5:37 PM
     
    4756
    4857    public final URI xmlBase;
    49 
     58   
    5059    /** Creates a new instance of SVGLoaderHelper */
    5160    public SVGLoaderHelper(URI xmlBase, SVGUniverse universe, SVGDiagram diagram)
    5261    {
    53         /*
    54         URI docURI = null;
    55         try
    56         {
    57             docURI = new URI(docRoot.toString());
    58         }
    59         catch (Exception e)
    60         {
    61             e.printStackTrace();
    62         }
    63          */
    64        
    6562        this.xmlBase = xmlBase;
    66 //        this.docRoot = docURI;
    6763        this.universe = universe;
    6864        this.diagram = diagram;
  • trunk/src/com/kitfox/svg/SVGParseException.java

    r4256 r6002  
    11/*
    2  * SVGException.java
     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
    333 *
    434 * Created on May 12, 2005, 11:32 PM
    5  *
    6  * To change this template, choose Tools | Options and locate the template under
    7  * the Source Creation and Management node. Right-click the template and choose
    8  * Open. You can then make changes to the template in the Source Editor.
    935 */
    1036
  • 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}
  • trunk/src/com/kitfox/svg/SVGUniverse.java

    r4256 r6002  
    11/*
    2  * SVGUniverse.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 February 18, 2004, 11:43 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3644import java.io.ByteArrayInputStream;
    3745import java.io.ByteArrayOutputStream;
    38 import java.io.File;
    3946import java.io.IOException;
    4047import java.io.InputStream;
     
    4653import java.net.MalformedURLException;
    4754import java.net.URI;
     55import java.net.URISyntaxException;
    4856import java.net.URL;
    4957import java.net.URLConnection;
     
    5159import java.util.HashMap;
    5260import java.util.Iterator;
     61import java.util.logging.Level;
     62import java.util.logging.Logger;
    5363import java.util.zip.GZIPInputStream;
    5464import javax.imageio.ImageIO;
     
    6171
    6272/**
    63  * Many SVG files can be loaded at one time.  These files will quite likely
    64  * need to reference one another.  The SVG universe provides a container for
    65  * all these files and the means for them to relate to each other.
     73 * Many SVG files can be loaded at one time. These files will quite likely need
     74 * to reference one another. The SVG universe provides a container for all these
     75 * files and the means for them to relate to each other.
    6676 *
    6777 * @author Mark McKay
     
    7080public class SVGUniverse implements Serializable
    7181{
     82
    7283    public static final long serialVersionUID = 0;
    73    
    7484    transient private PropertyChangeSupport changes = new PropertyChangeSupport(this);
    75    
    76     /**
    77      * Maps document URIs to their loaded SVG diagrams.  Note that URIs for
     85    /**
     86     * Maps document URIs to their loaded SVG diagrams. Note that URIs for
    7887     * documents loaded from URLs will reflect their URLs and URIs for documents
    7988     * initiated from streams will have the scheme <i>svgSalamander</i>.
    8089     */
    8190    final HashMap loadedDocs = new HashMap();
    82    
    8391    final HashMap loadedFonts = new HashMap();
    84    
    8592    final HashMap loadedImages = new HashMap();
    86    
    8793    public static final String INPUTSTREAM_SCHEME = "svgSalamander";
    88    
    89     /**
    90      * Current time in this universe.  Used for resolving attributes that
    91      * are influenced by track information.  Time is in milliseconds.  Time
    92      * 0 coresponds to the time of 0 in each member diagram.
     94    /**
     95     * Current time in this universe. Used for resolving attributes that are
     96     * influenced by track information. Time is in milliseconds. Time 0
     97     * coresponds to the time of 0 in each member diagram.
    9398     */
    9499    protected double curTime = 0.0;
    95    
    96100    private boolean verbose = false;
    97 
    98101    //Cache reader for efficiency
    99102    XMLReader cachedReader;
    100    
    101     /** Creates a new instance of SVGUniverse */
     103
     104    /**
     105     * Creates a new instance of SVGUniverse
     106     */
    102107    public SVGUniverse()
    103108    {
    104109    }
    105    
     110
    106111    public void addPropertyChangeListener(PropertyChangeListener l)
    107112    {
    108113        changes.addPropertyChangeListener(l);
    109114    }
    110    
     115
    111116    public void removePropertyChangeListener(PropertyChangeListener l)
    112117    {
    113118        changes.removePropertyChangeListener(l);
    114119    }
    115    
     120
    116121    /**
    117122     * Release all loaded SVG document from memory
     
    123128        loadedImages.clear();
    124129    }
    125    
     130
    126131    /**
    127132     * Returns the current animation time in milliseconds.
    128133     */
    129134    public double getCurTime()
    130     { 
    131         return curTime; 
    132     }
    133    
     135    {
     136        return curTime;
     137    }
     138
    134139    public void setCurTime(double curTime)
    135140    {
    136141        double oldTime = this.curTime;
    137         this.curTime = curTime; 
     142        this.curTime = curTime;
    138143        changes.firePropertyChange("curTime", new Double(oldTime), new Double(curTime));
    139144    }
    140    
     145
    141146    /**
    142147     * Updates all time influenced style and presentation attributes in all SVG
     
    147152        for (Iterator it = loadedDocs.values().iterator(); it.hasNext();)
    148153        {
    149             SVGDiagram dia = (SVGDiagram)it.next();
     154            SVGDiagram dia = (SVGDiagram) it.next();
    150155            dia.updateTime(curTime);
    151156        }
    152157    }
    153    
     158
    154159    /**
    155160     * Called by the Font element to let the universe know that a font has been
     
    160165        loadedFonts.put(font.getFontFace().getFontFamily(), font);
    161166    }
    162    
     167
    163168    public Font getDefaultFont()
    164169    {
    165170        for (Iterator it = loadedFonts.values().iterator(); it.hasNext();)
    166171        {
    167             return (Font)it.next();
     172            return (Font) it.next();
    168173        }
    169174        return null;
    170175    }
    171    
     176
    172177    public Font getFont(String fontName)
    173178    {
    174         return (Font)loadedFonts.get(fontName);
     179        return (Font) loadedFonts.get(fontName);
    175180    }
    176181
     
    188193            {
    189194                content = content.substring(6);
    190                 try {
     195                try
     196                {
    191197                    byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
    192198                    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
     
    209215
    210216                    return url;
    211                 } catch (IOException ex) {
    212                     ex.printStackTrace();
     217                } catch (IOException ex)
     218                {
     219                    Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     220                        "Could not decode inline image", ex);
    213221                }
    214222            }
    215223            return null;
    216         }
    217         else
    218         {
    219             try {
     224        } else
     225        {
     226            try
     227            {
    220228                URL url = imageURI.toURL();
    221229                registerImage(url);
    222230                return url;
    223             } catch (MalformedURLException ex) {
    224                 ex.printStackTrace();
     231            } catch (MalformedURLException ex)
     232            {
     233                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     234                    "Bad url", ex);
    225235            }
    226236            return null;
     
    230240    void registerImage(URL imageURL)
    231241    {
    232         if (loadedImages.containsKey(imageURL)) return;
    233        
     242        if (loadedImages.containsKey(imageURL))
     243        {
     244            return;
     245        }
     246
    234247        SoftReference ref;
    235248        try
     
    240253                SVGIcon icon = new SVGIcon();
    241254                icon.setSvgURI(imageURL.toURI());
    242                
     255
    243256                BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    244257                Graphics2D g = img.createGraphics();
     
    246259                g.dispose();
    247260                ref = new SoftReference(img);
    248             }
    249             else
     261            } else
    250262            {
    251263                BufferedImage img = ImageIO.read(imageURL);
     
    253265            }
    254266            loadedImages.put(imageURL, ref);
    255         }
    256         catch (Exception e)
    257         {
    258             System.err.println("Could not load image: " + imageURL);
    259             e.printStackTrace();
    260         }
    261     }
    262    
     267        } catch (Exception e)
     268        {
     269            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     270                "Could not load image: " + imageURL, e);
     271        }
     272    }
     273
    263274    BufferedImage getImage(URL imageURL)
    264275    {
    265         SoftReference ref = (SoftReference)loadedImages.get(imageURL);
    266         if (ref == null) return null;
    267        
    268         BufferedImage img = (BufferedImage)ref.get();
     276        SoftReference ref = (SoftReference) loadedImages.get(imageURL);
     277        if (ref == null)
     278        {
     279            return null;
     280        }
     281
     282        BufferedImage img = (BufferedImage) ref.get();
    269283        //If image was cleared from memory, reload it
    270284        if (img == null)
     
    273287            {
    274288                img = ImageIO.read(imageURL);
    275             }
    276             catch (Exception e)
    277             { e.printStackTrace(); }
     289            } catch (Exception e)
     290            {
     291                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     292                    "Could not load image", e);
     293            }
    278294            ref = new SoftReference(img);
    279295            loadedImages.put(imageURL, ref);
    280296        }
    281        
     297
    282298        return img;
    283299    }
    284    
    285     /**
    286      * Returns the element of the document at the given URI.  If the document
    287      * is not already loaded, it will be.
     300
     301    /**
     302     * Returns the element of the document at the given URI. If the document is
     303     * not already loaded, it will be.
    288304     */
    289305    public SVGElement getElement(URI path)
     
    291307        return getElement(path, true);
    292308    }
    293    
     309
    294310    public SVGElement getElement(URL path)
    295311    {
     
    298314            URI uri = new URI(path.toString());
    299315            return getElement(uri, true);
    300         }
    301         catch (Exception e)
    302         {
    303             e.printStackTrace();
     316        } catch (Exception e)
     317        {
     318            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     319                "Could not parse url " + path, e);
    304320        }
    305321        return null;
    306322    }
    307    
    308     /**
    309      * Looks up a href within our universe.  If the href refers to a document that
    310      * is not loaded, it will be loaded.  The URL #target will then be checked
    311      * against the SVG diagram's index and the coresponding element returned.
    312      * If there is no coresponding index, null is returned.
     323
     324    /**
     325     * Looks up a href within our universe. If the href refers to a document
     326     * that is not loaded, it will be loaded. The URL #target will then be
     327     * checked against the SVG diagram's index and the coresponding element
     328     * returned. If there is no coresponding index, null is returned.
    313329     */
    314330    public SVGElement getElement(URI path, boolean loadIfAbsent)
     
    318334            //Strip fragment from URI
    319335            URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null);
    320            
    321             SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);
     336
     337            SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
    322338            if (dia == null && loadIfAbsent)
    323339            {
     
    325341//javax.swing.JOptionPane.showMessageDialog(null, xmlBase.toString());
    326342                URL url = xmlBase.toURL();
    327                
     343
    328344                loadSVG(url, false);
    329                 dia = (SVGDiagram)loadedDocs.get(xmlBase);
    330                 if (dia == null) return null;
    331             }
    332            
     345                dia = (SVGDiagram) loadedDocs.get(xmlBase);
     346                if (dia == null)
     347                {
     348                    return null;
     349                }
     350            }
     351
    333352            String fragment = path.getFragment();
    334353            return fragment == null ? dia.getRoot() : dia.getElement(fragment);
    335         }
    336         catch (Exception e)
    337         {
    338             e.printStackTrace();
    339             return null;
    340         }
    341     }
    342    
     354        } catch (Exception e)
     355        {
     356            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     357                "Could not parse path " + path, e);
     358            return null;
     359        }
     360    }
     361
    343362    public SVGDiagram getDiagram(URI xmlBase)
    344363    {
    345364        return getDiagram(xmlBase, true);
    346365    }
    347    
    348     /**
    349      * Returns the diagram that has been loaded from this root.  If diagram is
     366
     367    /**
     368     * Returns the diagram that has been loaded from this root. If diagram is
    350369     * not already loaded, returns null.
    351370     */
    352371    public SVGDiagram getDiagram(URI xmlBase, boolean loadIfAbsent)
    353372    {
    354         if (xmlBase == null) return null;
    355 
    356         SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);
    357         if (dia != null || !loadIfAbsent) return dia;
    358        
     373        if (xmlBase == null)
     374        {
     375            return null;
     376        }
     377
     378        SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
     379        if (dia != null || !loadIfAbsent)
     380        {
     381            return dia;
     382        }
     383
    359384        //Load missing diagram
    360385        try
     
    372397            }
    373398
    374            
     399
    375400            loadSVG(url, false);
    376             dia = (SVGDiagram)loadedDocs.get(xmlBase);
     401            dia = (SVGDiagram) loadedDocs.get(xmlBase);
    377402            return dia;
    378         }
    379         catch (Exception e)
    380         {
    381             e.printStackTrace();
    382         }
    383        
     403        } catch (Exception e)
     404        {
     405            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     406                "Could not parse", e);
     407        }
     408
    384409        return null;
    385410    }
    386    
    387     /**
    388      * Wraps input stream in a BufferedInputStream.  If it is detected that this
     411
     412    /**
     413     * Wraps input stream in a BufferedInputStream. If it is detected that this
    389414     * input stream is GZIPped, also wraps in a GZIPInputStream for inflation.
    390      * 
     415     *
    391416     * @param is Raw input stream
    392417     * @return Uncompressed stream of SVG data
     
    406431            GZIPInputStream iis = new GZIPInputStream(bin);
    407432            return iis;
    408         }
    409         else
     433        } else
    410434        {
    411435            //Plain text
     
    413437        }
    414438    }
    415    
     439
    416440    public URI loadSVG(URL docRoot)
    417441    {
    418442        return loadSVG(docRoot, false);
    419443    }
    420    
     444
    421445    /**
    422446     * Loads an SVG file and all the files it references from the URL provided.
    423447     * If a referenced file already exists in the SVG universe, it is not
    424448     * reloaded.
     449     *
    425450     * @param docRoot - URL to the location where this SVG file can be found.
    426451     * @param forceLoad - if true, ignore cached diagram and reload
     
    432457        {
    433458            URI uri = new URI(docRoot.toString());
    434             if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    435            
     459            if (loadedDocs.containsKey(uri) && !forceLoad)
     460            {
     461                return uri;
     462            }
     463
    436464            InputStream is = docRoot.openStream();
    437465            return loadSVG(uri, new InputSource(createDocumentInputStream(is)));
    438         }
    439         catch (Throwable t)
    440         {
    441             t.printStackTrace();
    442         }
    443        
     466        } catch (URISyntaxException ex)
     467        {
     468            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     469                "Could not parse", ex);
     470        } catch (IOException e)
     471        {
     472            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     473                "Could not parse", e);
     474        }
     475
    444476        return null;
    445477    }
    446    
    447    
     478
    448479    public URI loadSVG(InputStream is, String name) throws IOException
    449480    {
    450481        return loadSVG(is, name, false);
    451482    }
    452    
     483
    453484    public URI loadSVG(InputStream is, String name, boolean forceLoad) throws IOException
    454485    {
    455486        URI uri = getStreamBuiltURI(name);
    456         if (uri == null) return null;
    457         if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    458        
     487        if (uri == null)
     488        {
     489            return null;
     490        }
     491        if (loadedDocs.containsKey(uri) && !forceLoad)
     492        {
     493            return uri;
     494        }
     495
    459496        return loadSVG(uri, new InputSource(createDocumentInputStream(is)));
    460497    }
    461    
     498
    462499    public URI loadSVG(Reader reader, String name)
    463500    {
    464501        return loadSVG(reader, name, false);
    465502    }
    466    
     503
    467504    /**
    468505     * This routine allows you to create SVG documents from data streams that
    469      * may not necessarily have a URL to load from.  Since every SVG document
    470      * must be identified by a unique URL, Salamander provides a method to
    471      * fake this for streams by defining it's own protocol - svgSalamander -
    472      * for SVG documents without a formal URL.
     506     * may not necessarily have a URL to load from. Since every SVG document
     507     * must be identified by a unique URL, Salamander provides a method to fake
     508     * this for streams by defining it's own protocol - svgSalamander - for SVG
     509     * documents without a formal URL.
    473510     *
    474511     * @param reader - A stream containing a valid SVG document
    475      * @param name - <p>A unique name for this document.  It will be used to
     512     * @param name - <p>A unique name for this document. It will be used to
    476513     * construct a unique URI to refer to this document and perform resolution
    477      * with relative URIs within this document.</p>
    478      * <p>For example, a name of "/myScene" will produce the URI
    479      * svgSalamander:/myScene.  "/maps/canada/toronto" will produce
    480      * svgSalamander:/maps/canada/toronto.  If this second document then
    481      * contained the href "../uk/london", it would resolve by default to
    482      * svgSalamander:/maps/uk/london.  That is, SVG Salamander defines the
    483      * URI scheme svgSalamander for it's own internal use and uses it
    484      * for uniquely identfying documents loaded by stream.</p>
    485      * <p>If you need to link to documents outside of this scheme, you can
    486      * either supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)")
    487      * or put the xml:base attribute in a tag to change the defaultbase
    488      * URIs are resolved against</p>
    489      * <p>If a name does not start with the character '/', it will be automatically
    490      * prefixed to it.</p>
     514     * with relative URIs within this document.</p> <p>For example, a name of
     515     * "/myScene" will produce the URI svgSalamander:/myScene.
     516     * "/maps/canada/toronto" will produce svgSalamander:/maps/canada/toronto.
     517     * If this second document then contained the href "../uk/london", it would
     518     * resolve by default to svgSalamander:/maps/uk/london. That is, SVG
     519     * Salamander defines the URI scheme svgSalamander for it's own internal use
     520     * and uses it for uniquely identfying documents loaded by stream.</p> <p>If
     521     * you need to link to documents outside of this scheme, you can either
     522     * supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)") or
     523     * put the xml:base attribute in a tag to change the defaultbase URIs are
     524     * resolved against</p> <p>If a name does not start with the character '/',
     525     * it will be automatically prefixed to it.</p>
    491526     * @param forceLoad - if true, ignore cached diagram and reload
    492527     *
     
    498533        //Synthesize URI for this stream
    499534        URI uri = getStreamBuiltURI(name);
    500         if (uri == null) return null;
    501         if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    502        
     535        if (uri == null)
     536        {
     537            return null;
     538        }
     539        if (loadedDocs.containsKey(uri) && !forceLoad)
     540        {
     541            return uri;
     542        }
     543
    503544        return loadSVG(uri, new InputSource(reader));
    504545    }
    505    
     546
    506547    /**
    507548     * Synthesize a URI for an SVGDiagram constructed from a stream.
     549     *
    508550     * @param name - Name given the document constructed from a stream.
    509551     */
    510552    public URI getStreamBuiltURI(String name)
    511553    {
    512         if (name == null || name.length() == 0) return null;
    513        
    514         if (name.charAt(0) != '/') name = '/' + name;
    515        
     554        if (name == null || name.length() == 0)
     555        {
     556            return null;
     557        }
     558
     559        if (name.charAt(0) != '/')
     560        {
     561            name = '/' + name;
     562        }
     563
    516564        try
    517565        {
    518566            //Dummy URL for SVG documents built from image streams
    519567            return new URI(INPUTSTREAM_SCHEME, name, null);
    520         }
    521         catch (Exception e)
    522         {
    523             e.printStackTrace();
    524             return null;
    525         }
    526     }
    527    
     568        } catch (Exception e)
     569        {
     570            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     571                "Could not parse", e);
     572            return null;
     573        }
     574    }
     575
    528576    private XMLReader getXMLReaderCached() throws SAXException
    529577    {
     
    534582        return cachedReader;
    535583    }
    536    
    537 //    protected URI loadSVG(URI xmlBase, InputStream is)
     584
    538585    protected URI loadSVG(URI xmlBase, InputSource is)
    539586    {
    540587        // Use an instance of ourselves as the SAX event handler
    541588        SVGLoader handler = new SVGLoader(xmlBase, this, verbose);
    542        
     589
    543590        //Place this docment in the universe before it is completely loaded
    544591        // so that the load process can refer to references within it's current
    545592        // document
    546 //System.err.println("SVGUniverse: loading dia " + xmlBase);
    547593        loadedDocs.put(xmlBase, handler.getLoadedDiagram());
    548        
    549         // Use the default (non-validating) parser
    550 //        SAXParserFactory factory = SAXParserFactory.newInstance();
    551 //        factory.setValidating(false);
    552 //        factory.setNamespaceAware(true);
    553        
     594
    554595        try
    555596        {
     
    564605                        return new InputSource(new ByteArrayInputStream(new byte[0]));
    565606                    }
    566                 }
    567             );
     607                });
    568608            reader.setContentHandler(handler);
    569609            reader.parse(is);
    570            
    571 //            SAXParser saxParser = factory.newSAXParser();
    572 //            saxParser.parse(new InputSource(new BufferedReader(is)), handler);
     610
     611            handler.getLoadedDiagram().updateTime(curTime);
    573612            return xmlBase;
    574         }
    575         catch (SAXParseException sex)
     613        } catch (SAXParseException sex)
    576614        {
    577615            System.err.println("Error processing " + xmlBase);
    578616            System.err.println(sex.getMessage());
    579            
     617
    580618            loadedDocs.remove(xmlBase);
    581619            return null;
    582         }
    583         catch (Throwable t)
    584         {
    585             t.printStackTrace();
    586         }
    587        
     620        } catch (Throwable e)
     621        {
     622            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     623                "Could not load SVG " + xmlBase, e);
     624        }
     625
    588626        return null;
    589627    }
    590    
    591     public static void main(String argv[])
    592     {
    593         try
    594         {
    595             URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",
    596                     new URLStreamHandler()
    597             {
    598                 protected URLConnection openConnection(URL u)
    599                 {
    600                     return null;
    601                 }
    602             }
    603             );
    604 //            URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");
    605            
    606             //Investigate URI resolution
    607             URI uriA, uriB, uriC, uriD, uriE;
    608            
    609             uriA = new URI("svgSalamander", "/names/mySpecialName", null);
    610 //            uriA = new URI("http://www.kitfox.com/salamander");
    611 //            uriA = new URI("svgSalamander://mySpecialName/grape");
    612             System.err.println(uriA.toString());
    613             System.err.println(uriA.getScheme());
    614            
    615             uriB = uriA.resolve("#begin");
    616             System.err.println(uriB.toString());
    617            
    618             uriC = uriA.resolve("tree#boing");
    619             System.err.println(uriC.toString());
    620            
    621             uriC = uriA.resolve("../tree#boing");
    622             System.err.println(uriC.toString());
    623         }
    624         catch (Exception e)
    625         {
    626             e.printStackTrace();
    627         }
    628     }
    629 
     628
     629//    public static void main(String argv[])
     630//    {
     631//        try
     632//        {
     633//            URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",
     634//                    new URLStreamHandler()
     635//            {
     636//                protected URLConnection openConnection(URL u)
     637//                {
     638//                    return null;
     639//                }
     640//            }
     641//            );
     642////            URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");
     643//           
     644//            //Investigate URI resolution
     645//            URI uriA, uriB, uriC, uriD, uriE;
     646//           
     647//            uriA = new URI("svgSalamander", "/names/mySpecialName", null);
     648////            uriA = new URI("http://www.kitfox.com/salamander");
     649////            uriA = new URI("svgSalamander://mySpecialName/grape");
     650//            System.err.println(uriA.toString());
     651//            System.err.println(uriA.getScheme());
     652//           
     653//            uriB = uriA.resolve("#begin");
     654//            System.err.println(uriB.toString());
     655//           
     656//            uriC = uriA.resolve("tree#boing");
     657//            System.err.println(uriC.toString());
     658//           
     659//            uriC = uriA.resolve("../tree#boing");
     660//            System.err.println(uriC.toString());
     661//        }
     662//        catch (Exception e)
     663//        {
     664//            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     665//                "Could not parse", e);
     666//        }
     667//    }
    630668    public boolean isVerbose()
    631669    {
     
    637675        this.verbose = verbose;
    638676    }
    639    
     677
    640678    /**
    641679     * Uses serialization to duplicate this universe.
     
    650688        ByteArrayInputStream bin = new ByteArrayInputStream(bs.toByteArray());
    651689        ObjectInputStream is = new ObjectInputStream(bin);
    652         SVGUniverse universe = (SVGUniverse)is.readObject();
     690        SVGUniverse universe = (SVGUniverse) is.readObject();
    653691        is.close();
    654692
  • trunk/src/com/kitfox/svg/ShapeElement.java

    r4256 r6002  
    11/*
    2  * ShapeElement.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, 5:21 PM
     
    96105    }
    97106
     107    private Paint handleCurrentColor(StyleAttribute styleAttrib) throws SVGException
     108    {
     109        if (styleAttrib.getStringValue().equals("currentColor"))
     110        {
     111            StyleAttribute currentColorAttrib = new StyleAttribute();
     112            if (getStyle(currentColorAttrib.setName("color")))
     113            {
     114                if (!currentColorAttrib.getStringValue().equals("none"))
     115                {
     116                    return currentColorAttrib.getColorValue();
     117                }
     118            }
     119            return null;
     120        }
     121        else
     122        {
     123            return styleAttrib.getColorValue();
     124        }
     125    }
     126
    98127    protected void renderShape(Graphics2D g, Shape shape) throws SVGException
    99128    {
     
    120149            else
    121150            {
    122                 fillPaint = styleAttrib.getColorValue();
     151                fillPaint = handleCurrentColor(styleAttrib);
    123152                if (fillPaint == null)
    124153                {
     
    130159
    131160                        SVGElement ele = diagram.getUniverse().getElement(uri);
    132                         fillPaint = ((FillElement)ele).getPaint(bounds, xform);
     161                        if (ele != null)
     162                        {
     163                            fillPaint = ((FillElement)ele).getPaint(bounds, xform);
     164                        }
    133165                    }
    134166                }
     
    156188            else
    157189            {
    158                 strokePaint = styleAttrib.getColorValue();
     190                strokePaint = handleCurrentColor(styleAttrib);
    159191                if (strokePaint == null)
    160192                {
     
    166198
    167199                        SVGElement ele = diagram.getUniverse().getElement(uri);
    168                         strokePaint = ((FillElement)ele).getPaint(bounds, xform);
     200                        if (ele != null)
     201                        {
     202                            strokePaint = ((FillElement)ele).getPaint(bounds, xform);
     203                        }
    169204                    }
    170205                }
     
    303338            }
    304339
    305             Shape strokeShape = stroke.createStrokedShape(shape);
     340            Shape strokeShape;
     341            AffineTransform cacheXform = g.getTransform();
     342            if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE)
     343            {
     344                strokeShape = cacheXform.createTransformedShape(shape);
     345                strokeShape = stroke.createStrokedShape(strokeShape);
     346            }
     347            else
     348            {
     349                strokeShape = stroke.createStrokedShape(shape);
     350            }
    306351
    307352            if (strokeOpacity <= 0)
     
    309354                //Do nothing
    310355            }
    311             else if (strokeOpacity < 1f)
     356            else
    312357            {
    313358                Composite cachedComposite = g.getComposite();
    314                 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, strokeOpacity));
     359
     360                if (strokeOpacity < 1f)
     361                {
     362                    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, strokeOpacity));
     363                }
     364
     365                if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE)
     366                {
     367                    //Set to identity
     368                    g.setTransform(new AffineTransform());
     369                }
    315370
    316371                g.setPaint(strokePaint);
    317372                g.fill(strokeShape);
    318373
    319                 g.setComposite(cachedComposite);
    320             }
    321             else
    322             {
    323                 g.setPaint(strokePaint);
    324                 g.fill(strokeShape);
     374                if (vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE)
     375                {
     376                    //Set to identity
     377                    g.setTransform(cacheXform);
     378                }
     379
     380                if (strokeOpacity < 1f)
     381                {
     382                    g.setComposite(cachedComposite);
     383                }
    325384            }
    326385        }
  • trunk/src/com/kitfox/svg/Stop.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;
    31 import java.awt.*;
    32 import java.util.*;
    33 
    34 import com.kitfox.svg.xml.*;
    35 import org.xml.sax.*;
     39import java.awt.Color;
    3640
    3741/**
     
    3943 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4044 */
    41 public class Stop extends SVGElement {
     45public class Stop extends SVGElement
     46{
    4247
     48    public static final String TAG_NAME = "stop";
    4349    float offset = 0f;
    4450    float opacity = 1f;
    4551    Color color = Color.black;
    4652
    47     /** Creates a new instance of Stop */
    48     public Stop() {
     53    /**
     54     * Creates a new instance of Stop
     55     */
     56    public Stop()
     57    {
    4958    }
    50 /*
    51     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     59
     60    public String getTagName()
    5261    {
    53                 //Load style string
    54         super.loaderStartElement(helper, attrs, parent);
     62        return TAG_NAME;
     63    }
    5564
    56         String offset = attrs.getValue("offset");
    57         this.offset = (float)XMLParseUtil.parseRatio(offset);
    58 
    59         buildStop();
    60     }
    61     */
    62    
    6365    protected void build() throws SVGException
    6466    {
    6567        super.build();
    66        
     68
    6769        StyleAttribute sty = new StyleAttribute();
    68        
     70
    6971        if (getPres(sty.setName("offset")))
    7072        {
    7173            offset = sty.getFloatValue();
    7274            String units = sty.getUnits();
    73             if (units != null && units.equals("%")) offset /= 100f;
    74             if (offset > 1) offset = 1;
    75             if (offset < 0) offset = 0;
     75            if (units != null && units.equals("%"))
     76            {
     77                offset /= 100f;
     78            }
     79            if (offset > 1)
     80            {
     81                offset = 1;
     82            }
     83            if (offset < 0)
     84            {
     85                offset = 0;
     86            }
    7687        }
    77        
    78         if (getStyle(sty.setName("stop-color"))) color = sty.getColorValue();
    7988
    80         if (getStyle(sty.setName("stop-opacity"))) opacity = sty.getRatioValue();
     89        if (getStyle(sty.setName("stop-color")))
     90        {
     91            color = sty.getColorValue();
     92        }
     93
     94        if (getStyle(sty.setName("stop-opacity")))
     95        {
     96            opacity = sty.getRatioValue();
     97        }
    8198    }
    8299
    83100    /**
    84      * Updates all attributes in this diagram associated with a time event.
    85      * Ie, all attributes with track information.
     101     * Updates all attributes in this diagram associated with a time event. Ie,
     102     * all attributes with track information.
     103     *
    86104     * @return - true if this node has changed state as a result of the time
    87105     * update
     
    94112        StyleAttribute sty = new StyleAttribute();
    95113        boolean shapeChange = false;
    96        
     114
    97115        if (getPres(sty.setName("offset")))
    98116        {
     
    104122            }
    105123        }
    106        
    107         if (getPres(sty.setName("stop-color")))
     124
     125        if (getStyle(sty.setName("stop-color")))
    108126        {
    109127            Color newVal = sty.getColorValue();
     
    114132            }
    115133        }
    116        
    117         if (getPres(sty.setName("stop-opacity")))
     134
     135        if (getStyle(sty.setName("stop-opacity")))
    118136        {
    119137            float newVal = sty.getFloatValue();
     
    124142            }
    125143        }
    126        
     144
    127145        return shapeChange;
    128146    }
  • trunk/src/com/kitfox/svg/Style.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 September 19, 2004, 1:56 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
    3038import com.kitfox.svg.xml.StyleAttribute;
    31 import com.kitfox.svg.xml.*;
    32 import org.xml.sax.*;
    33 
     39import com.kitfox.svg.xml.StyleSheet;
    3440
    3541/**
     
    3945 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4046 */
    41 public class Style extends SVGElement {
     47public class Style extends SVGElement
     48{
    4249
     50    public static final String TAG_NAME = "style";
    4351    //Should be set to "text/css"
    4452    String type;
    4553    StringBuffer text = new StringBuffer();
    4654
    47     /** Creates a new instance of Stop */
    48     public Style() {
     55    StyleSheet styleSheet;
     56   
     57    /**
     58     * Creates a new instance of Stop
     59     */
     60    public Style()
     61    {
    4962    }
    50 /*
    51     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     63
     64    public String getTagName()
    5265    {
    53                 //Load style string
    54         super.loaderStartElement(helper, attrs, parent);
     66        return TAG_NAME;
     67    }
    5568
    56         this.type = attrs.getValue("type");
    57     }
    58 */
    5969    /**
    6070     * Called during load process to add text scanned within a tag
     
    6373    {
    6474        this.text.append(text);
     75       
     76        //Invalidate style sheet
     77        styleSheet = null;
    6578    }
    6679
    67    
    6880    protected void build() throws SVGException
    6981    {
    7082        super.build();
    71        
     83
    7284        StyleAttribute sty = new StyleAttribute();
    73        
    74         if (getPres(sty.setName("type"))) type = sty.getStringValue();
     85
     86        if (getPres(sty.setName("type")))
     87        {
     88            type = sty.getStringValue();
     89        }
    7590    }
    76    
     91
    7792    public boolean updateTime(double curTime) throws SVGException
    7893    {
    7994        //Style sheet doesn't change
    8095        return false;
    81     }   
    82    
     96    }
     97
     98    public StyleSheet getStyleSheet()
     99    {
     100        if (styleSheet == null && text.length() > 0)
     101        {
     102            styleSheet = StyleSheet.parseSheet(text.toString());
     103        }
     104        return styleSheet;
     105    }
    83106}
  • trunk/src/com/kitfox/svg/Symbol.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
    30 import java.awt.*;
    31 import java.awt.geom.*;
    32 
    33 import com.kitfox.svg.xml.*;
     38import com.kitfox.svg.xml.StyleAttribute;
     39import java.awt.Graphics2D;
     40import java.awt.Rectangle;
     41import java.awt.Shape;
     42import java.awt.geom.AffineTransform;
     43import java.awt.geom.Rectangle2D;
    3444
    3545/**
     
    3949public class Symbol extends Group
    4050{
     51
     52    public static final String TAG_NAME = "symbol";
    4153    AffineTransform viewXform;
    4254    Rectangle2D viewBox;
    4355
    44     /** Creates a new instance of Stop */
    45     public Symbol() {
     56    /**
     57     * Creates a new instance of Stop
     58     */
     59    public Symbol()
     60    {
    4661    }
    47 /*
    48     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     62
     63    public String getTagName()
    4964    {
    50                 //Load style string
    51         super.loaderStartElement(helper, attrs, parent);
     65        return TAG_NAME;
     66    }
    5267
    53         String viewBoxStrn = attrs.getValue("viewBox");
    54         if (viewBoxStrn != null)
    55         {
    56             float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);
    57             viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
    58         }
    59     }
    60 */
    61     /*
    62     public void loaderEndElement(SVGLoaderHelper helper)
    63     {
    64         if (viewBox == null)
    65         {
    66             viewBox = super.getBoundingBox();
    67         }
    68 
    69         //Transform pattern onto unit square
    70         viewXform = new AffineTransform();
    71         viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
    72         viewXform.translate(-viewBox.getX(), -viewBox.getY());
    73     }
    74 */
    75    
    7668    protected void build() throws SVGException
    7769    {
    7870        super.build();
    79        
     71
    8072        StyleAttribute sty = new StyleAttribute();
    81        
     73
    8274//        sty = getPres("unicode");
    8375//        if (sty != null) unicode = sty.getStringValue();
     
    8981            viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
    9082        }
    91        
     83
    9284        if (viewBox == null)
    9385        {
     
    10496    protected boolean outsideClip(Graphics2D g) throws SVGException
    10597    {
    106         g.getClipBounds(clipBounds);
     98        Shape clip = g.getClip();
     99//        g.getClipBounds(clipBounds);
    107100        Rectangle2D rect = super.getBoundingBox();
    108         if (rect.intersects(clipBounds))
     101        if (clip == null || clip.intersects(rect))
    109102        {
    110103            return false;
     
    138131
    139132    /**
    140      * Updates all attributes in this diagram associated with a time event.
    141      * Ie, all attributes with track information.
     133     * Updates all attributes in this diagram associated with a time event. Ie,
     134     * all attributes with track information.
     135     *
    142136     * @return - true if this node has changed state as a result of the time
    143137     * update
     
    147141//        if (trackManager.getNumTracks() == 0) return false;
    148142        boolean changeState = super.updateTime(curTime);
    149        
     143
    150144        //View box properties do not change
    151        
     145
    152146        return changeState;
    153147    }
    154 
    155148}
  • trunk/src/com/kitfox/svg/Text.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;
    31 import java.awt.*;
    32 import java.awt.font.*;
    33 import java.awt.geom.*;
    34 import java.util.*;
    35 import java.util.regex.*;
     39import java.awt.Graphics2D;
     40import java.awt.Shape;
     41import java.awt.font.FontRenderContext;
     42import java.awt.geom.AffineTransform;
     43import java.awt.geom.GeneralPath;
     44import java.awt.geom.Rectangle2D;
     45import java.util.Iterator;
     46import java.util.LinkedList;
     47import java.util.regex.Matcher;
     48import java.util.regex.Pattern;
    3649
    3750//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
    38 
    3951/**
    4052 * @author Mark McKay
     
    4355public class Text extends ShapeElement
    4456{
     57    public static final String TAG_NAME = "text";
    4558   
    4659    float x = 0;
    4760    float y = 0;
    4861    AffineTransform transform = null;
    49    
    5062    String fontFamily;
    5163    float fontSize;
    52    
    5364    //List of strings and tspans containing the content of this node
    5465    LinkedList content = new LinkedList();
    55    
    5666    Shape textShape;
    57    
    5867    public static final int TXAN_START = 0;
    5968    public static final int TXAN_MIDDLE = 1;
    6069    public static final int TXAN_END = 2;
    6170    int textAnchor = TXAN_START;
    62    
    6371    public static final int TXST_NORMAL = 0;
    6472    public static final int TXST_ITALIC = 1;
    6573    public static final int TXST_OBLIQUE = 2;
    6674    int fontStyle;
    67    
    6875    public static final int TXWE_NORMAL = 0;
    6976    public static final int TXWE_BOLD = 1;
     
    8087    public static final int TXWE_900 = 12;
    8188    int fontWeight;
    82    
    83     /** Creates a new instance of Stop */
     89
     90    /**
     91     * Creates a new instance of Stop
     92     */
    8493    public Text()
    8594    {
    8695    }
    87    
     96
     97    public String getTagName()
     98    {
     99        return TAG_NAME;
     100    }
     101
    88102    public void appendText(String text)
    89103    {
    90104        content.addLast(text);
    91105    }
    92    
     106
    93107    public void appendTspan(Tspan tspan) throws SVGElementException
    94108    {
    95109        super.loaderAddChild(null, tspan);
    96110        content.addLast(tspan);
    97 //        tspan.setParent(this);
    98     }
    99    
     111    }
     112
    100113    /**
    101114     * Discard cached information
     
    105118        build();
    106119    }
    107    
     120
    108121    public java.util.List getContent()
    109122    {
    110123        return content;
    111124    }
    112 /*
    113     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    114     {
    115                 //Load style string
    116         super.loaderStartElement(helper, attrs, parent);
    117  
    118         String x = attrs.getValue("x");
    119         String y = attrs.getValue("y");
    120         //String transform = attrs.getValue("transform");
    121  
    122         this.x = XMLParseUtil.parseFloat(x);
    123         this.y = XMLParseUtil.parseFloat(y);
    124     }
    125  */
     125
    126126    /**
    127127     * Called after the start element but before the end element to indicate
     
    131131    {
    132132        super.loaderAddChild(helper, child);
    133        
     133
    134134        content.addLast(child);
    135135    }
    136    
     136
    137137    /**
    138138     * Called during load process to add text scanned within a tag
     
    141141    {
    142142        Matcher matchWs = Pattern.compile("\\s*").matcher(text);
    143         if (!matchWs.matches()) content.addLast(text);
    144     }
    145    
     143        if (!matchWs.matches())
     144        {
     145            content.addLast(text);
     146        }
     147    }
     148
    146149    public void build() throws SVGException
    147150    {
    148151        super.build();
    149        
     152
    150153        StyleAttribute sty = new StyleAttribute();
    151        
    152         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    153        
    154         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    155        
    156         if (getStyle(sty.setName("font-family"))) fontFamily = sty.getStringValue();
    157         else fontFamily = "Sans Serif";
    158        
    159         if (getStyle(sty.setName("font-size"))) fontSize = sty.getFloatValueWithUnits();
    160         else fontSize = 12f;
    161        
     154
     155        if (getPres(sty.setName("x")))
     156        {
     157            x = sty.getFloatValueWithUnits();
     158        }
     159
     160        if (getPres(sty.setName("y")))
     161        {
     162            y = sty.getFloatValueWithUnits();
     163        }
     164
     165        if (getStyle(sty.setName("font-family")))
     166        {
     167            fontFamily = sty.getStringValue();
     168        } else
     169        {
     170            fontFamily = "Sans Serif";
     171        }
     172
     173        if (getStyle(sty.setName("font-size")))
     174        {
     175            fontSize = sty.getFloatValueWithUnits();
     176        } else
     177        {
     178            fontSize = 12f;
     179        }
     180
    162181        if (getStyle(sty.setName("font-style")))
    163182        {
     
    166185            {
    167186                fontStyle = TXST_NORMAL;
    168             }
    169             else if ("italic".equals(s))
     187            } else if ("italic".equals(s))
    170188            {
    171189                fontStyle = TXST_ITALIC;
    172             }
    173             else if ("oblique".equals(s))
     190            } else if ("oblique".equals(s))
    174191            {
    175192                fontStyle = TXST_OBLIQUE;
    176193            }
    177         }
    178         else fontStyle = TXST_NORMAL;
    179        
     194        } else
     195        {
     196            fontStyle = TXST_NORMAL;
     197        }
     198
    180199        if (getStyle(sty.setName("font-weight")))
    181200        {
     
    184203            {
    185204                fontWeight = TXWE_NORMAL;
    186             }
    187             else if ("bold".equals(s))
     205            } else if ("bold".equals(s))
    188206            {
    189207                fontWeight = TXWE_BOLD;
    190208            }
    191         }
    192         else fontWeight = TXWE_BOLD;
    193        
     209        } else
     210        {
     211            fontWeight = TXWE_BOLD;
     212        }
     213
    194214        if (getStyle(sty.setName("text-anchor")))
    195215        {
    196216            String s = sty.getStringValue();
    197             if (s.equals("middle")) textAnchor = TXAN_MIDDLE;
    198             else if (s.equals("end")) textAnchor = TXAN_END;
    199             else textAnchor = TXAN_START;
    200         }
    201         else textAnchor = TXAN_START;
    202        
     217            if (s.equals("middle"))
     218            {
     219                textAnchor = TXAN_MIDDLE;
     220            } else if (s.equals("end"))
     221            {
     222                textAnchor = TXAN_END;
     223            } else
     224            {
     225                textAnchor = TXAN_START;
     226            }
     227        } else
     228        {
     229            textAnchor = TXAN_START;
     230        }
     231
    203232        //text anchor
    204233        //text-decoration
    205234        //text-rendering
    206        
     235
    207236        buildFont();
    208237    }
    209    
     238
    210239    protected void buildFont() throws SVGException
    211240    {
     
    232261                break;
    233262        }
    234            
     263
    235264        //Get font
    236265        Font font = diagram.getUniverse().getFont(fontFamily);
     
    238267        {
    239268//            System.err.println("Could not load font");
    240            
    241             java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int)fontSize);
     269
     270            java.awt.Font sysFont = new java.awt.Font(fontFamily, style | weight, (int) fontSize);
    242271            buildSysFont(sysFont);
    243272            return;
    244273        }
    245        
     274
    246275//        font = new java.awt.Font(font.getFamily(), style | weight, font.getSize());
    247        
     276
    248277//        Area textArea = new Area();
    249278        GeneralPath textPath = new GeneralPath();
    250279        textShape = textPath;
    251        
     280
    252281        float cursorX = x, cursorY = y;
    253        
     282
    254283        FontFace fontFace = font.getFontFace();
    255284        //int unitsPerEm = fontFace.getUnitsPerEm();
    256285        int ascent = fontFace.getAscent();
    257         float fontScale = fontSize / (float)ascent;
    258        
     286        float fontScale = fontSize / (float) ascent;
     287
    259288//        AffineTransform oldXform = g.getTransform();
    260289        AffineTransform xform = new AffineTransform();
    261        
     290
    262291        for (Iterator it = content.iterator(); it.hasNext();)
    263292        {
    264293            Object obj = it.next();
    265            
     294
    266295            if (obj instanceof String)
    267296            {
    268                 String text = (String)obj;
    269                
     297                String text = (String) obj;
     298                if (text != null)
     299                {
     300                    text = text.trim();
     301                }
     302
    270303                strokeWidthScalar = 1f / fontScale;
    271                
     304
    272305                for (int i = 0; i < text.length(); i++)
    273306                {
     
    276309                    xform.scale(fontScale, fontScale);
    277310//                    g.transform(xform);
    278                    
     311
    279312                    String unicode = text.substring(i, i + 1);
    280313                    MissingGlyph glyph = font.getGlyph(unicode);
    281                    
     314
    282315                    Shape path = glyph.getPath();
    283316                    if (path != null)
     
    287320                    }
    288321//                    else glyph.render(g);
    289                    
     322
    290323                    cursorX += fontScale * glyph.getHorizAdvX();
    291                    
     324
    292325//                    g.setTransform(oldXform);
    293326                }
    294                
     327
    295328                strokeWidthScalar = 1f;
    296             }
    297             else if (obj instanceof Tspan)
    298             {
    299                 Tspan tspan = (Tspan)obj;
    300                
     329            } else if (obj instanceof Tspan)
     330            {
     331                Tspan tspan = (Tspan) obj;
     332
    301333                xform.setToIdentity();
    302334                xform.setToTranslation(cursorX, cursorY);
     
    304336//                tspan.setCursorX(cursorX);
    305337//                tspan.setCursorY(cursorY);
    306                
     338
    307339                Shape tspanShape = tspan.getShape();
    308340                tspanShape = xform.createTransformedShape(tspanShape);
     
    312344//                cursorY = tspan.getCursorY();
    313345            }
    314            
    315         }
    316        
     346
     347        }
     348
    317349        switch (textAnchor)
    318350        {
     
    333365        }
    334366    }
    335    
     367
    336368    private void buildSysFont(java.awt.Font font) throws SVGException
    337369    {
    338370        GeneralPath textPath = new GeneralPath();
    339371        textShape = textPath;
    340        
     372
    341373        float cursorX = x, cursorY = y;
    342        
     374
    343375//        FontMetrics fm = g.getFontMetrics(font);
    344376        FontRenderContext frc = new FontRenderContext(null, true, true);
    345        
     377
    346378//        FontFace fontFace = font.getFontFace();
    347379        //int unitsPerEm = fontFace.getUnitsPerEm();
    348380//        int ascent = fm.getAscent();
    349381//        float fontScale = fontSize / (float)ascent;
    350        
     382
    351383//        AffineTransform oldXform = g.getTransform();
    352384        AffineTransform xform = new AffineTransform();
    353        
     385
    354386        for (Iterator it = content.iterator(); it.hasNext();)
    355387        {
    356388            Object obj = it.next();
    357            
     389
    358390            if (obj instanceof String)
    359391            {
    360                 String text = (String)obj;
    361                
     392                String text = (String) obj;
     393
    362394                Shape textShape = font.createGlyphVector(frc, text).getOutline(cursorX, cursorY);
    363395                textPath.append(textShape, false);
    364396//                renderShape(g, textShape);
    365397//                g.drawString(text, cursorX, cursorY);
    366                
     398
    367399                Rectangle2D rect = font.getStringBounds(text, frc);
    368                 cursorX += (float)rect.getWidth();
    369             }
    370             else if (obj instanceof Tspan)
     400                cursorX += (float) rect.getWidth();
     401            } else if (obj instanceof Tspan)
    371402            {
    372403                /*
    373                 Tspan tspan = (Tspan)obj;
     404                 Tspan tspan = (Tspan)obj;
    374405                 
    375                 xform.setToIdentity();
    376                 xform.setToTranslation(cursorX, cursorY);
     406                 xform.setToIdentity();
     407                 xform.setToTranslation(cursorX, cursorY);
    377408                 
    378                 Shape tspanShape = tspan.getShape();
    379                 tspanShape = xform.createTransformedShape(tspanShape);
    380                 textArea.add(new Area(tspanShape));
     409                 Shape tspanShape = tspan.getShape();
     410                 tspanShape = xform.createTransformedShape(tspanShape);
     411                 textArea.add(new Area(tspanShape));
    381412                 
    382                 cursorX += tspanShape.getBounds2D().getWidth();
     413                 cursorX += tspanShape.getBounds2D().getWidth();
    383414                 */
    384                
    385                
    386                 Tspan tspan = (Tspan)obj;
     415
     416
     417                Tspan tspan = (Tspan) obj;
    387418                tspan.setCursorX(cursorX);
    388419                tspan.setCursorY(cursorY);
     
    390421                cursorX = tspan.getCursorX();
    391422                cursorY = tspan.getCursorY();
    392                
    393             }
    394         }
    395        
     423
     424            }
     425        }
     426
    396427        switch (textAnchor)
    397428        {
     
    412443        }
    413444    }
    414    
    415    
     445
    416446    public void render(Graphics2D g) throws SVGException
    417447    {
     
    420450        finishLayer(g);
    421451    }
    422    
     452
    423453    public Shape getShape()
    424454    {
    425455        return shapeToParent(textShape);
    426456    }
    427    
     457
    428458    public Rectangle2D getBoundingBox() throws SVGException
    429459    {
    430460        return boundsToParent(includeStrokeInBounds(textShape.getBounds2D()));
    431461    }
    432    
     462
    433463    /**
    434      * Updates all attributes in this diagram associated with a time event.
    435      * Ie, all attributes with track information.
     464     * Updates all attributes in this diagram associated with a time event. Ie,
     465     * all attributes with track information.
     466     *
    436467     * @return - true if this node has changed state as a result of the time
    437468     * update
     
    441472//        if (trackManager.getNumTracks() == 0) return false;
    442473        boolean changeState = super.updateTime(curTime);
    443        
     474
    444475        //Get current values for parameters
    445476        StyleAttribute sty = new StyleAttribute();
    446477        boolean shapeChange = false;
    447        
     478
    448479        if (getPres(sty.setName("x")))
    449480        {
     
    455486            }
    456487        }
    457        
     488
    458489        if (getPres(sty.setName("y")))
    459490        {
     
    465496            }
    466497        }
    467        
     498
    468499        if (getPres(sty.setName("font-family")))
    469500        {
     
    475506            }
    476507        }
    477        
     508
    478509        if (getPres(sty.setName("font-size")))
    479510        {
     
    485516            }
    486517        }
    487        
    488        
     518
     519
    489520        if (getStyle(sty.setName("font-style")))
    490521        {
     
    494525            {
    495526                newVal = TXST_NORMAL;
    496             }
    497             else if ("italic".equals(s))
     527            } else if ("italic".equals(s))
    498528            {
    499529                newVal = TXST_ITALIC;
    500             }
    501             else if ("oblique".equals(s))
     530            } else if ("oblique".equals(s))
    502531            {
    503532                newVal = TXST_OBLIQUE;
     
    509538            }
    510539        }
    511        
     540
    512541        if (getStyle(sty.setName("font-weight")))
    513542        {
     
    517546            {
    518547                newVal = TXWE_NORMAL;
    519             }
    520             else if ("bold".equals(s))
     548            } else if ("bold".equals(s))
    521549            {
    522550                newVal = TXWE_BOLD;
     
    528556            }
    529557        }
    530        
     558
    531559        if (shapeChange)
    532560        {
     
    535563//            return true;
    536564        }
    537        
     565
    538566        return changeState || shapeChange;
    539567    }
  • trunk/src/com/kitfox/svg/Title.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 September 19, 2004, 1:56 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3442 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3543 */
    36 public class Title extends SVGElement {
    37 
     44public class Title extends SVGElement
     45{
     46    public static final String TAG_NAME = "title";
     47   
    3848    StringBuffer text = new StringBuffer();
    3949
    40     /** Creates a new instance of Stop */
    41     public Title() {
     50    /**
     51     * Creates a new instance of Stop
     52     */
     53    public Title()
     54    {
     55    }
     56
     57    public String getTagName()
     58    {
     59        return TAG_NAME;
    4260    }
    4361
     
    5068    }
    5169
    52     public String getText() { return text.toString(); }
    53    
     70    public String getText()
     71    {
     72        return text.toString();
     73    }
     74
    5475    /**
    55      * Updates all attributes in this diagram associated with a time event.
    56      * Ie, all attributes with track information.
     76     * Updates all attributes in this diagram associated with a time event. Ie,
     77     * all attributes with track information.
     78     *
    5779     * @return - true if this node has changed state as a result of the time
    5880     * update
  • trunk/src/com/kitfox/svg/TransformableElement.java

    r4453 r6002  
    11/*
    2  * BoundedElement.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, 9:00 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3341import java.awt.geom.Rectangle2D;
    3442
    35 
    3643/**
    3744 * Maintains bounding box for this element
     
    4047 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4148 */
    42 public class TransformableElement extends SVGElement
     49abstract public class TransformableElement extends SVGElement
    4350{
     51    AffineTransform xform = null;
    4452
    45     AffineTransform xform = null;
    46 //    AffineTransform invXform = null;
    47 
    48     /** Creates a new instance of BoundedElement */
    49     public TransformableElement() {
     53    /**
     54     * Creates a new instance of BoundedElement
     55     */
     56    public TransformableElement()
     57    {
    5058    }
    5159
     
    5563    }
    5664
     65    /**
     66     * Fetches a copy of the cached AffineTransform. Note that this value will
     67     * only be valid after the node has been updated.
     68     *
     69     * @return
     70     */
    5771    public AffineTransform getXForm()
    5872    {
    59         return xform;
     73        return xform != null ? new AffineTransform(xform) : null;
    6074    }
    61 /*
    62     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    63     {
    64                 //Load style string
    65         super.loaderStartElement(helper, attrs, parent);
     75    /*
     76     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     77     {
     78     //Load style string
     79     super.loaderStartElement(helper, attrs, parent);
    6680
    67         String transform = attrs.getValue("transform");
    68         if (transform != null)
    69         {
    70             xform = parseTransform(transform);
    71         }
    72     }
    73 */
    74    
     81     String transform = attrs.getValue("transform");
     82     if (transform != null)
     83     {
     84     xform = parseTransform(transform);
     85     }
     86     }
     87     */
     88
    7589    protected void build() throws SVGException
    7690    {
    7791        super.build();
    78        
     92
    7993        StyleAttribute sty = new StyleAttribute();
    80        
     94
    8195        if (getPres(sty.setName("transform")))
    8296        {
     
    8498        }
    8599    }
    86    
     100
    87101    protected Shape shapeToParent(Shape shape)
    88102    {
    89         if (xform == null) return shape;
     103        if (xform == null)
     104        {
     105            return shape;
     106        }
    90107        return xform.createTransformedShape(shape);
    91108    }
     
    93110    protected Rectangle2D boundsToParent(Rectangle2D rect)
    94111    {
    95         if (xform == null) return rect;
     112        if (xform == null)
     113        {
     114            return rect;
     115        }
    96116        return xform.createTransformedShape(rect).getBounds2D();
    97117    }
    98118
    99119    /**
    100      * Updates all attributes in this diagram associated with a time event.
    101      * Ie, all attributes with track information.
     120     * Updates all attributes in this diagram associated with a time event. Ie,
     121     * all attributes with track information.
     122     *
    102123     * @return - true if this node has changed state as a result of the time
    103124     * update
     
    106127    {
    107128        StyleAttribute sty = new StyleAttribute();
    108        
     129
    109130        if (getPres(sty.setName("transform")))
    110131        {
     
    116137            }
    117138        }
    118        
     139
    119140        return false;
    120141    }
  • trunk/src/com/kitfox/svg/Tspan.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;
    31 import java.awt.*;
    32 import java.awt.font.*;
    33 import java.awt.geom.*;
    34 import java.util.*;
    35 
    36 import com.kitfox.svg.xml.*;
    37 import org.xml.sax.*;
    38 
    39 //import org.apache.batik.ext.awt.geom.ExtendedGeneralPath;
     39import java.awt.Graphics2D;
     40import java.awt.Shape;
     41import java.awt.font.FontRenderContext;
     42import java.awt.font.GlyphMetrics;
     43import java.awt.font.GlyphVector;
     44import java.awt.geom.AffineTransform;
     45import java.awt.geom.GeneralPath;
     46import java.awt.geom.Rectangle2D;
    4047
    4148/**
     
    4350 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4451 */
    45 public class Tspan extends ShapeElement {
    46 
     52public class Tspan extends ShapeElement
     53{
     54
     55    public static final String TAG_NAME = "tspan";
    4756    float[] x = null;
    4857    float[] y = null;
     
    5059    float[] dy = null;
    5160    float[] rotate = null;
    52 
    5361    private String text = "";
    54 
    5562    float cursorX;
    5663    float cursorY;
    5764
    5865//    Shape tspanShape;
    59 
    60     /** Creates a new instance of Stop */
    61     public Tspan() {
    62     }
    63 
    64     public float getCursorX() { return cursorX; }
    65     public float getCursorY() { return cursorY; }
     66    /**
     67     * Creates a new instance of Stop
     68     */
     69    public Tspan()
     70    {
     71    }
     72
     73    public String getTagName()
     74    {
     75        return TAG_NAME;
     76    }
     77
     78    public float getCursorX()
     79    {
     80        return cursorX;
     81    }
     82
     83    public float getCursorY()
     84    {
     85        return cursorY;
     86    }
    6687
    6788    public void setCursorX(float cursorX)
     
    7495        this.cursorY = cursorY;
    7596    }
    76 /*
    77     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    78     {
    79                 //Load style string
    80         super.loaderStartElement(helper, attrs, parent);
    81 
    82         String x = attrs.getValue("x");
    83         String y = attrs.getValue("y");
    84         String dx = attrs.getValue("dx");
    85         String dy = attrs.getValue("dy");
    86         String rotate = attrs.getValue("rotate");
    87 
    88         if (x != null) this.x = XMLParseUtil.parseFloatList(x);
    89         if (y != null) this.y = XMLParseUtil.parseFloatList(y);
    90         if (dx != null) this.dx = XMLParseUtil.parseFloatList(dx);
    91         if (dy != null) this.dy = XMLParseUtil.parseFloatList(dy);
    92         if (rotate != null)
    93         {
    94             this.rotate = XMLParseUtil.parseFloatList(rotate);
    95             for (int i = 0; i < this.rotate.length; i++)
    96                 this.rotate[i] = (float)Math.toRadians(this.rotate[i]);
    97         }
    98     }
    99     */
     97    /*
     98     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
     99     {
     100     //Load style string
     101     super.loaderStartElement(helper, attrs, parent);
     102
     103     String x = attrs.getValue("x");
     104     String y = attrs.getValue("y");
     105     String dx = attrs.getValue("dx");
     106     String dy = attrs.getValue("dy");
     107     String rotate = attrs.getValue("rotate");
     108
     109     if (x != null) this.x = XMLParseUtil.parseFloatList(x);
     110     if (y != null) this.y = XMLParseUtil.parseFloatList(y);
     111     if (dx != null) this.dx = XMLParseUtil.parseFloatList(dx);
     112     if (dy != null) this.dy = XMLParseUtil.parseFloatList(dy);
     113     if (rotate != null)
     114     {
     115     this.rotate = XMLParseUtil.parseFloatList(rotate);
     116     for (int i = 0; i < this.rotate.length; i++)
     117     this.rotate[i] = (float)Math.toRadians(this.rotate[i]);
     118     }
     119     }
     120     */
    100121
    101122    /**
     
    107128    }
    108129
    109    
    110130    protected void build() throws SVGException
    111131    {
    112132        super.build();
    113        
     133
    114134        StyleAttribute sty = new StyleAttribute();
    115        
    116         if (getPres(sty.setName("x"))) x = sty.getFloatList();
    117 
    118         if (getPres(sty.setName("y"))) y = sty.getFloatList();
    119 
    120         if (getPres(sty.setName("dx"))) dx = sty.getFloatList();
    121 
    122         if (getPres(sty.setName("dy"))) dy = sty.getFloatList();
     135
     136        if (getPres(sty.setName("x")))
     137        {
     138            x = sty.getFloatList();
     139        }
     140
     141        if (getPres(sty.setName("y")))
     142        {
     143            y = sty.getFloatList();
     144        }
     145
     146        if (getPres(sty.setName("dx")))
     147        {
     148            dx = sty.getFloatList();
     149        }
     150
     151        if (getPres(sty.setName("dy")))
     152        {
     153            dy = sty.getFloatList();
     154        }
    123155
    124156        if (getPres(sty.setName("rotate")))
     
    127159            for (int i = 0; i < this.rotate.length; i++)
    128160            {
    129                 rotate[i] = (float)Math.toRadians(this.rotate[i]);
    130             }
    131                
    132         }
    133     }
    134    
     161                rotate[i] = (float) Math.toRadians(this.rotate[i]);
     162            }
     163
     164        }
     165    }
     166
    135167    public void addShape(GeneralPath addShape) throws SVGException
    136168    {
     
    138170        {
    139171            cursorX = x[0];
     172        } else if (dx != null)
     173        {
     174            cursorX += dx[0];
     175        }
     176
     177        if (y != null)
     178        {
    140179            cursorY = y[0];
    141         }
    142         else if (dx != null)
    143         {
    144             cursorX += dx[0];
     180        } else if (dy != null)
     181        {
    145182            cursorY += dy[0];
    146183        }
    147184
    148185        StyleAttribute sty = new StyleAttribute();
    149        
     186
    150187        String fontFamily = null;
    151188        if (getStyle(sty.setName("font-family")))
     
    160197            fontSize = sty.getFloatValueWithUnits();
    161198        }
     199
     200        float letterSpacing = 0;
     201        if (getStyle(sty.setName("letter-spacing")))
     202        {
     203            letterSpacing = sty.getFloatValueWithUnits();
     204        }
     205
    162206
    163207        //Get font
     
    165209        if (font == null)
    166210        {
    167             addShapeSysFont(addShape, font, fontFamily, fontSize);
     211            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing);
    168212            return;
    169213        }
     
    171215        FontFace fontFace = font.getFontFace();
    172216        int ascent = fontFace.getAscent();
    173         float fontScale = fontSize / (float)ascent;
     217        float fontScale = fontSize / (float) ascent;
    174218
    175219        AffineTransform xform = new AffineTransform();
     
    184228            xform.setToTranslation(cursorX, cursorY);
    185229            xform.scale(fontScale, fontScale);
    186             if (rotate != null) xform.rotate(rotate[posPtr]);
     230            if (rotate != null)
     231            {
     232                xform.rotate(rotate[posPtr]);
     233            }
    187234
    188235            String unicode = text.substring(i, i + 1);
     
    200247                cursorX = x[posPtr];
    201248                cursorY = y[posPtr++];
    202             }
    203             else if (dx != null && posPtr < dx.length)
     249            } else if (dx != null && posPtr < dx.length)
    204250            {
    205251                cursorX += dx[posPtr];
     
    207253            }
    208254
    209             cursorX += fontScale * glyph.getHorizAdvX();
     255            cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing;
    210256        }
    211257
     
    213259    }
    214260
    215     private void addShapeSysFont(GeneralPath addShape, Font font, String fontFamily, float fontSize)
    216     {
    217         java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize);
     261    private void addShapeSysFont(GeneralPath addShape, Font font,
     262        String fontFamily, float fontSize, float letterSpacing)
     263    {
     264        java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
    218265
    219266        FontRenderContext frc = new FontRenderContext(null, true, true);
     
    226273        {
    227274            xform.setToIdentity();
    228             xform.setToTranslation(cursorX, cursorY);
    229             if (rotate != null) xform.rotate(rotate[Math.min(i, rotate.length - 1)]);
     275            xform.setToTranslation(cursorX + i * letterSpacing, cursorY);
     276            if (rotate != null)
     277            {
     278                xform.rotate(rotate[Math.min(i, rotate.length - 1)]);
     279            }
    230280
    231281            String unicode = text.substring(i, i + 1);
     
    240290                cursorX = x[posPtr];
    241291                cursorY = y[posPtr++];
    242             }
    243             else if (dx != null && posPtr < dx.length)
     292            } else if (dx != null && posPtr < dx.length)
    244293            {
    245294                cursorX += dx[posPtr];
     
    255304            cursorX = x[0];
    256305            cursorY = y[0];
    257         }
    258         else if (dx != null)
     306        } else if (dx != null)
    259307        {
    260308            cursorX += dx[0];
     
    263311
    264312        StyleAttribute sty = new StyleAttribute();
    265        
     313
    266314        String fontFamily = null;
    267315        if (getPres(sty.setName("font-family")))
     
    282330        {
    283331            System.err.println("Could not load font");
    284             java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize);
     332            java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
    285333            renderSysFont(g, sysFont);
    286334            return;
     
    290338        FontFace fontFace = font.getFontFace();
    291339        int ascent = fontFace.getAscent();
    292         float fontScale = fontSize / (float)ascent;
     340        float fontScale = fontSize / (float) ascent;
    293341
    294342        AffineTransform oldXform = g.getTransform();
     
    312360            {
    313361                renderShape(g, path);
    314             }
    315             else glyph.render(g);
     362            } else
     363            {
     364                glyph.render(g);
     365            }
    316366
    317367            if (x != null && posPtr < x.length)
     
    319369                cursorX = x[posPtr];
    320370                cursorY = y[posPtr++];
    321             }
    322             else if (dx != null && posPtr < dx.length)
     371            } else if (dx != null && posPtr < dx.length)
    323372            {
    324373                cursorX += dx[posPtr];
     
    342391        renderShape(g, textShape);
    343392        Rectangle2D rect = font.getStringBounds(text, frc);
    344         cursorX += (float)rect.getWidth();
     393        cursorX += (float) rect.getWidth();
    345394    }
    346395
     
    358407
    359408    /**
    360      * Updates all attributes in this diagram associated with a time event.
    361      * Ie, all attributes with track information.
     409     * Updates all attributes in this diagram associated with a time event. Ie,
     410     * all attributes with track information.
     411     *
    362412     * @return - true if this node has changed state as a result of the time
    363413     * update
  • trunk/src/com/kitfox/svg/Use.java

    r4256 r6002  
    11/*
    2  * LinearGradient.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:54 AM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3947 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    4048 */
    41 public class Use extends ShapeElement {
    42 
     49public class Use extends ShapeElement
     50{
     51    public static final String TAG_NAME = "use";
     52   
    4353    float x = 0f;
    4454    float y = 0f;
    4555    float width = 1f;
    4656    float height = 1f;
    47 
    48     SVGElement href = null;
    49 
     57//    SVGElement href = null;
     58    URI href = null;
    5059    AffineTransform refXform;
    5160
    52     /** Creates a new instance of LinearGradient */
    53     public Use() {
    54     }
    55 /*
    56     public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
    57     {
    58                 //Load style string
    59         super.loaderStartElement(helper, attrs, parent);
    60 
    61         String x = attrs.getValue("x");
    62         String y = attrs.getValue("y");
    63         String width = attrs.getValue("width");
    64         String height = attrs.getValue("height");
    65         String href = attrs.getValue("xlink:href");
    66 
    67         if (x != null) this.x = (float)XMLParseUtil.parseRatio(x);
    68         if (y != null) this.y = (float)XMLParseUtil.parseRatio(y);
    69         if (width != null) this.width = (float)XMLParseUtil.parseRatio(width);
    70         if (height != null) this.height = (float)XMLParseUtil.parseRatio(height);
    71 
    72 
    73         if (href != null)
    74         {
    75             try {
    76                 URI src = getXMLBase().resolve(href);
    77                 this.href = helper.universe.getElement(src);
    78             }
    79             catch (Exception e)
    80             {
    81                 e.printStackTrace();
    82             }
     61    /**
     62     * Creates a new instance of LinearGradient
     63     */
     64    public Use()
     65    {
     66    }
     67
     68    public String getTagName()
     69    {
     70        return TAG_NAME;
     71    }
     72
     73    protected void build() throws SVGException
     74    {
     75        super.build();
     76
     77        StyleAttribute sty = new StyleAttribute();
     78
     79        if (getPres(sty.setName("x")))
     80        {
     81            x = sty.getFloatValueWithUnits();
     82        }
     83
     84        if (getPres(sty.setName("y")))
     85        {
     86            y = sty.getFloatValueWithUnits();
     87        }
     88
     89        if (getPres(sty.setName("width")))
     90        {
     91            width = sty.getFloatValueWithUnits();
     92        }
     93
     94        if (getPres(sty.setName("height")))
     95        {
     96            height = sty.getFloatValueWithUnits();
     97        }
     98
     99        if (getPres(sty.setName("xlink:href")))
     100        {
     101            URI src = sty.getURIValue(getXMLBase());
     102            href = src;
     103//            href = diagram.getUniverse().getElement(src);
    83104        }
    84105
     
    86107        refXform = new AffineTransform();
    87108        refXform.translate(this.x, this.y);
    88         refXform.scale(this.width, this.height);
    89     }
    90 */
    91     protected void build() throws SVGException
    92     {
    93         super.build();
    94        
    95         StyleAttribute sty = new StyleAttribute();
    96        
    97         if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits();
    98 
    99         if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits();
    100 
    101         if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits();
    102 
    103         if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits();
    104 
    105         if (getPres(sty.setName("xlink:href")))
    106         {
    107             URI src = sty.getURIValue(getXMLBase());
    108             href = diagram.getUniverse().getElement(src);
    109         }
    110        
    111         //Determine use offset/scale
    112         refXform = new AffineTransform();
    113         refXform.translate(this.x, this.y);
    114     }
    115    
     109    }
     110
    116111    public void render(Graphics2D g) throws SVGException
    117112    {
     
    122117        g.transform(refXform);
    123118
    124         if (href == null || !(href instanceof RenderableElement)) return;
    125 
    126         RenderableElement rendEle = (RenderableElement)href;
     119        SVGElement ref = diagram.getUniverse().getElement(href);
     120
     121        if (ref == null || !(ref instanceof RenderableElement))
     122        {
     123            return;
     124        }
     125
     126        RenderableElement rendEle = (RenderableElement) ref;
    127127        rendEle.pushParentContext(this);
    128128        rendEle.render(g);
     
    136136    public Shape getShape()
    137137    {
    138         if (href instanceof ShapeElement)
    139         {
    140             Shape shape = ((ShapeElement)href).getShape();
     138        SVGElement ref = diagram.getUniverse().getElement(href);
     139        if (ref instanceof ShapeElement)
     140        {
     141            Shape shape = ((ShapeElement) ref).getShape();
    141142            shape = refXform.createTransformedShape(shape);
    142143            shape = shapeToParent(shape);
     
    149150    public Rectangle2D getBoundingBox() throws SVGException
    150151    {
    151         if (href instanceof ShapeElement)
    152         {
    153             ShapeElement shapeEle = (ShapeElement)href;
     152        SVGElement ref = diagram.getUniverse().getElement(href);
     153        if (ref instanceof ShapeElement)
     154        {
     155            ShapeElement shapeEle = (ShapeElement) ref;
    154156            shapeEle.pushParentContext(this);
    155157            Rectangle2D bounds = shapeEle.getBoundingBox();
    156158            shapeEle.popParentContext();
    157            
     159
    158160            bounds = refXform.createTransformedShape(bounds).getBounds2D();
    159161            bounds = boundsToParent(bounds);
     
    166168
    167169    /**
    168      * Updates all attributes in this diagram associated with a time event.
    169      * Ie, all attributes with track information.
     170     * Updates all attributes in this diagram associated with a time event. Ie,
     171     * all attributes with track information.
     172     *
    170173     * @return - true if this node has changed state as a result of the time
    171174     * update
     
    179182        StyleAttribute sty = new StyleAttribute();
    180183        boolean shapeChange = false;
     184
     185        if (getPres(sty.setName("x")))
     186        {
     187            float newVal = sty.getFloatValueWithUnits();
     188            if (newVal != x)
     189            {
     190                x = newVal;
     191                shapeChange = true;
     192            }
     193        }
     194
     195        if (getPres(sty.setName("y")))
     196        {
     197            float newVal = sty.getFloatValueWithUnits();
     198            if (newVal != y)
     199            {
     200                y = newVal;
     201                shapeChange = true;
     202            }
     203        }
     204
     205        if (getPres(sty.setName("width")))
     206        {
     207            float newVal = sty.getFloatValueWithUnits();
     208            if (newVal != width)
     209            {
     210                width = newVal;
     211                shapeChange = true;
     212            }
     213        }
     214
     215        if (getPres(sty.setName("height")))
     216        {
     217            float newVal = sty.getFloatValueWithUnits();
     218            if (newVal != height)
     219            {
     220                height = newVal;
     221                shapeChange = true;
     222            }
     223        }
     224
     225        if (getPres(sty.setName("xlink:href")))
     226        {
     227            URI src = sty.getURIValue(getXMLBase());
     228//            SVGElement newVal = diagram.getUniverse().getElement(src);
     229            if (!src.equals(href))
     230            {
     231                href = src;
     232                shapeChange = true;
     233            }
     234        }
     235        /*
     236         if (getPres(sty.setName("xlink:href")))
     237         {
     238         URI src = sty.getURIValue(getXMLBase());
     239         href = diagram.getUniverse().getElement(src);
     240         }
    181241       
    182         if (getPres(sty.setName("x")))
    183         {
    184             float newVal = sty.getFloatValueWithUnits();
    185             if (newVal != x)
    186             {
    187                 x = newVal;
    188                 shapeChange = true;
    189             }
    190         }
    191 
    192         if (getPres(sty.setName("y")))
    193         {
    194             float newVal = sty.getFloatValueWithUnits();
    195             if (newVal != y)
    196             {
    197                 y = newVal;
    198                 shapeChange = true;
    199             }
    200         }
    201 
    202         if (getPres(sty.setName("width")))
    203         {
    204             float newVal = sty.getFloatValueWithUnits();
    205             if (newVal != width)
    206             {
    207                 width = newVal;
    208                 shapeChange = true;
    209             }
    210         }
    211 
    212         if (getPres(sty.setName("height")))
    213         {
    214             float newVal = sty.getFloatValueWithUnits();
    215             if (newVal != height)
    216             {
    217                 height = newVal;
    218                 shapeChange = true;
    219             }
    220         }
    221        
    222         if (getPres(sty.setName("xlink:href")))
    223         {
    224             URI src = sty.getURIValue(getXMLBase());
    225             SVGElement newVal = diagram.getUniverse().getElement(src);
    226             if (newVal != href)
    227             {
    228                 href = newVal;
    229                 shapeChange = true;
    230             }
    231         }
    232 /*
    233         if (getPres(sty.setName("xlink:href")))
    234         {
    235             URI src = sty.getURIValue(getXMLBase());
    236             href = diagram.getUniverse().getElement(src);
    237         }
    238        
    239         //Determine use offset/scale
    240         refXform = new AffineTransform();
    241         refXform.translate(this.x, this.y);
    242         refXform.scale(this.width, this.height);
    243 */       
     242         //Determine use offset/scale
     243         refXform = new AffineTransform();
     244         refXform.translate(this.x, this.y);
     245         refXform.scale(this.width, this.height);
     246         */
    244247        if (shapeChange)
    245248        {
     
    250253//            return true;
    251254        }
    252        
     255
    253256        return changeState || shapeChange;
    254257    }
  • trunk/src/com/kitfox/svg/app/beans/SVGIcon.java

    r4256 r6002  
    11/*
    2  * SVGIcon.java
     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
    333 *
    434 * Created on April 21, 2005, 10:45 AM
     
    737package com.kitfox.svg.app.beans;
    838
    9 import javax.swing.*;
     39import com.kitfox.svg.*;
    1040import java.awt.*;
    1141import java.awt.geom.*;
     42import java.beans.*;
    1243import java.net.*;
    13 import java.beans.*;
    14 
    15 import com.kitfox.svg.*;
     44import javax.swing.*;
    1645
    1746/**
     
    6998       
    7099        SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
    71         if (diagram == null) return 0;
     100        if (diagram == null)
     101        {
     102            return 0;
     103        }
    72104        return (int)diagram.getHeight();
    73105    }
     
    84116       
    85117        SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
    86         if (diagram == null) return 0;
     118        if (diagram == null)
     119        {
     120            return 0;
     121        }
    87122        return (int)diagram.getWidth();
    88123    }
     
    97132    public void paintIcon(Component comp, Graphics gg, int x, int y)
    98133    {
    99         Graphics2D g = (Graphics2D)gg;
    100        
     134        //Copy graphics object so that
     135        Graphics2D g = (Graphics2D)gg.create();
     136        paintIcon(comp, g, x, y);
     137        g.dispose();
     138    }
     139   
     140    private void paintIcon(Component comp, Graphics2D g, int x, int y)
     141    {
    101142        Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    102143        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
     
    118159       
    119160        SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
    120         if (diagram == null) return;
     161        if (diagram == null)
     162        {
     163            return;
     164        }
    121165       
    122166        g.translate(x, y);
     
    189233       
    190234        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
    191         if (oldInterpolationHint != null) g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint);
     235        if (oldInterpolationHint != null)
     236        {
     237            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, oldInterpolationHint);
     238        }
    192239    }
    193240   
  • trunk/src/com/kitfox/svg/app/data/Handler.java

    r4256 r6002  
    11/*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
     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
    433 */
    534
    635package com.kitfox.svg.app.data;
    736
     37import com.kitfox.svg.SVGConst;
    838import java.io.ByteArrayInputStream;
    939import java.io.IOException;
     
    1242import java.net.URLConnection;
    1343import java.net.URLStreamHandler;
     44import java.util.logging.Level;
     45import java.util.logging.Logger;
    1446
    1547/**
     
    3668            {
    3769                content = content.substring(7);
    38                 try {
     70                try
     71                {
    3972                    buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
    40                 } catch (IOException ex) {
    41                     ex.printStackTrace();
     73                }
     74                catch (IOException e)
     75                {
     76                    Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    4277                }
    4378            }
  • trunk/src/com/kitfox/svg/batik/LinearGradientPaint.java

    r4256 r6002  
    99package com.kitfox.svg.batik;
    1010
     11import com.kitfox.svg.SVGConst;
    1112import java.awt.Color;
    1213import java.awt.PaintContext;
     
    1819import java.awt.geom.Rectangle2D;
    1920import java.awt.image.ColorModel;
     21import java.util.logging.Level;
     22import java.util.logging.Logger;
    2023
    2124/**
     
    323326                                                  colorSpace);
    324327        }
    325        
    326         catch(NoninvertibleTransformException e) {
    327             e.printStackTrace();
     328        catch(NoninvertibleTransformException e)
     329        {
     330            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    328331            throw new IllegalArgumentException("transform should be" +
    329332                                               "invertible");
  • trunk/src/com/kitfox/svg/composite/AdobeComposite.java

    r4256 r6002  
    11/*
    2  * AdobeComposite.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 April 1, 2004, 6:40 AM
     
    2837package com.kitfox.svg.composite;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import java.awt.*;
    3141import java.awt.image.*;
     42import java.util.logging.Level;
     43import java.util.logging.Logger;
    3244
    3345/**
     
    5264        if (compositeType < 0 || compositeType >= CT_LAST)
    5365        {
    54             new Exception("Invalid composite type").printStackTrace();
     66            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, "Invalid composite type");
    5567        }
    5668
    5769        if (extraAlpha < 0f || extraAlpha > 1f)
    5870        {
    59             new Exception("Invalid alpha").printStackTrace();
     71            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, "Invalid alpha");
    6072        }
    6173    }
  • trunk/src/com/kitfox/svg/composite/AdobeCompositeContext.java

    r4256 r6002  
    11/*
    2  * AdobeCompositeContext.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 April 1, 2004, 6:41 AM
  • trunk/src/com/kitfox/svg/pathcmd/Arc.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    7079    public void appendPath(GeneralPath path, BuildHistory hist)
    7180    {
    72         float offx = isRelative ? hist.history[0].x : 0f;
    73         float offy = isRelative ? hist.history[0].y : 0f;
    74 
    75         arcTo(path, rx, ry, xAxisRot, largeArc, sweep, x + offx, y + offy, hist.history[0].x, hist.history[0].y);
     81        float offx = isRelative ? hist.lastPoint.x : 0f;
     82        float offy = isRelative ? hist.lastPoint.y : 0f;
     83
     84        arcTo(path, rx, ry, xAxisRot, largeArc, sweep,
     85            x + offx, y + offy,
     86            hist.lastPoint.x, hist.lastPoint.y);
    7687//        path.lineTo(x + offx, y + offy);
    77         hist.setPoint(x + offx, y + offy);
     88//        hist.setPoint(x + offx, y + offy);
     89        hist.setLastPoint(x + offx, y + offy);
     90        hist.setLastKnot(x + offx, y + offy);
    7891    }
    7992
     
    243256        return arc;
    244257    }
     258
     259    public String toString()
     260    {
     261        return "A " + rx + " " + ry
     262             + " " + xAxisRot + " " + largeArc
     263             + " " + sweep
     264             + " " + x + " " + y;
     265    }
    245266}
  • trunk/src/com/kitfox/svg/pathcmd/BuildHistory.java

    r4256 r6002  
    11/*
    2  * BuildHistory.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, 9:18 PM
    2635 */
    27 
    2836package com.kitfox.svg.pathcmd;
    2937
     
    3240/**
    3341 * When building a path from command segments, most need to cache information
    34  * (such as the point finished at) for future commands.  This structure allows
     42 * (such as the point finished at) for future commands. This structure allows
    3543 * that
    3644 *
     
    3846 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
    3947 */
    40 public class BuildHistory {
     48public class BuildHistory
     49{
    4150
    4251//    Point2D.Float[] history = new Point2D.Float[2];
    43     Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()};
    44     Point2D.Float start = new Point2D.Float();
    45     int length = 0;
     52//    Point2D.Float[] history = {new Point2D.Float(), new Point2D.Float()};
     53//    Point2D.Float start = new Point2D.Float();
     54    Point2D.Float startPoint = new Point2D.Float();
     55    Point2D.Float lastPoint = new Point2D.Float();
     56    Point2D.Float lastKnot = new Point2D.Float();
     57    boolean init;
     58    //int length = 0;
    4659
    47     /** Creates a new instance of BuildHistory */
    48     public BuildHistory() {
     60    /**
     61     * Creates a new instance of BuildHistory
     62     */
     63    public BuildHistory()
     64    {
    4965    }
    50 
    51     public void setPoint(float x, float y)
     66   
     67    public void setStartPoint(float x, float y)
    5268    {
    53         history[0].setLocation(x, y);
    54         length = 1;
     69        startPoint.setLocation(x, y);
    5570    }
    56 
    57     public void setStart(float x, float y)
     71   
     72    public void setLastPoint(float x, float y)
    5873    {
    59         start.setLocation(x, y);
     74        lastPoint.setLocation(x, y);
    6075    }
    61 
    62     public void setPointAndKnot(float x, float y, float kx, float ky)
     76   
     77    public void setLastKnot(float x, float y)
    6378    {
    64         history[0].setLocation(x, y);
    65         history[1].setLocation(kx, ky);
    66         length = 2;
     79        lastKnot.setLocation(x, y);
    6780    }
     81//    public void setPoint(float x, float y)
     82//    {
     83//        history[0].setLocation(x, y);
     84//        length = 1;
     85//    }
     86//    public void setStart(float x, float y)
     87//    {
     88//        start.setLocation(x, y);
     89//    }
     90//    public void setPointAndKnot(float x, float y, float kx, float ky)
     91//    {
     92//        history[0].setLocation(x, y);
     93//        history[1].setLocation(kx, ky);
     94//        length = 2;
     95//    }
    6896}
  • trunk/src/com/kitfox/svg/pathcmd/Cubic.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4857    }
    4958
     59    public String toString()
     60    {
     61        return "C " + k1x + " " + k1y
     62             + " " + k2x + " " + k2y
     63             + " " + x + " " + y;
     64    }
     65
    5066    public Cubic(boolean isRelative, float k1x, float k1y, float k2x, float k2y, float x, float y) {
    5167        super(isRelative);
     
    6177    public void appendPath(GeneralPath path, BuildHistory hist)
    6278    {
    63         float offx = isRelative ? hist.history[0].x : 0f;
    64         float offy = isRelative ? hist.history[0].y : 0f;
     79        float offx = isRelative ? hist.lastPoint.x : 0f;
     80        float offy = isRelative ? hist.lastPoint.y : 0f;
    6581
    66         path.curveTo(k1x + offx, k1y + offy, k2x + offx, k2y + offy, x + offx, y + offy);
    67         hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
     82        path.curveTo(k1x + offx, k1y + offy,
     83            k2x + offx, k2y + offy,
     84            x + offx, y + offy);
     85//        hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
     86        hist.setLastPoint(x + offx, y + offy);
     87        hist.setLastKnot(k2x + offx, k2y + offy);
    6888    }
    6989
  • trunk/src/com/kitfox/svg/pathcmd/CubicSmooth.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    5766    public void appendPath(GeneralPath path, BuildHistory hist)
    5867    {
    59         float offx = isRelative ? hist.history[0].x : 0f;
    60         float offy = isRelative ? hist.history[0].y : 0f;
     68        float offx = isRelative ? hist.lastPoint.x : 0f;
     69        float offy = isRelative ? hist.lastPoint.y : 0f;
    6170
    62         float oldKx = hist.history.length >= 2 ? hist.history[1].x : hist.history[0].x;
    63         float oldKy = hist.history.length >= 2 ? hist.history[1].y : hist.history[0].y;
    64         float oldX = hist.history[0].x;
    65         float oldY = hist.history[0].y;
     71        float oldKx = hist.lastKnot.x;
     72        float oldKy = hist.lastKnot.y;
     73        float oldX = hist.lastPoint.x;
     74        float oldY = hist.lastPoint.y;
    6675        //Calc knot as reflection of old knot
    6776        float k1x = oldX * 2f - oldKx;
     
    6978
    7079        path.curveTo(k1x, k1y, k2x + offx, k2y + offy, x + offx, y + offy);
    71         hist.setPointAndKnot(x + offx, y + offy, k2x + offx, k2y + offy);
     80        hist.setLastPoint(x + offx, y + offy);
     81        hist.setLastKnot(k2x + offx, k2y + offy);
    7282    }
    7383   
     
    7686        return 6;
    7787    }
     88
     89    public String toString()
     90    {
     91        return "S " + k2x + " " + k2y
     92             + " " + x + " " + y;
     93    }
    7894}
  • trunk/src/com/kitfox/svg/pathcmd/Horizontal.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4352    }
    4453
     54    public String toString()
     55    {
     56        return "H " + x;
     57    }
     58
    4559    public Horizontal(boolean isRelative, float x) {
    4660        super(isRelative);
     
    5266    public void appendPath(GeneralPath path, BuildHistory hist)
    5367    {
    54         float offx = isRelative ? hist.history[0].x : 0f;
    55         float offy = hist.history[0].y;
     68        float offx = isRelative ? hist.lastPoint.x : 0f;
     69        float offy = hist.lastPoint.y;
    5670
    5771        path.lineTo(x + offx, offy);
    58         hist.setPoint(x + offx, offy);
     72        hist.setLastPoint(x + offx, offy);
     73        hist.setLastKnot(x + offx, offy);
    5974    }
    6075   
  • trunk/src/com/kitfox/svg/pathcmd/LineTo.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    5463    public void appendPath(GeneralPath path, BuildHistory hist)
    5564    {
    56         float offx = isRelative ? hist.history[0].x : 0f;
    57         float offy = isRelative ? hist.history[0].y : 0f;
     65        float offx = isRelative ? hist.lastPoint.x : 0f;
     66        float offy = isRelative ? hist.lastPoint.y : 0f;
    5867
    5968        path.lineTo(x + offx, y + offy);
    60         hist.setPoint(x + offx, y + offy);
     69        hist.setLastPoint(x + offx, y + offy);
     70        hist.setLastKnot(x + offx, y + offy);
    6171    }
    6272   
     
    6575        return 2;
    6676    }
     77
     78    public String toString()
     79    {
     80        return "L " + x + " " + y;
     81    }
    6782}
  • trunk/src/com/kitfox/svg/pathcmd/MoveTo.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    5362    public void appendPath(GeneralPath path, BuildHistory hist)
    5463    {
    55         float offx = isRelative ? hist.history[0].x : 0f;
    56         float offy = isRelative ? hist.history[0].y : 0f;
     64        float offx = isRelative ? hist.lastPoint.x : 0f;
     65        float offy = isRelative ? hist.lastPoint.y : 0f;
    5766
    5867        path.moveTo(x + offx, y + offy);
    59         hist.setPoint(x + offx, y + offy);
    60         hist.setStart(x + offx, y + offy);
     68        hist.setStartPoint(x + offx, y + offy);
     69        hist.setLastPoint(x + offx, y + offy);
     70        hist.setLastKnot(x + offx, y + offy);
    6171    }
    6272
     
    6575        return 2;
    6676    }
     77
     78    public String toString()
     79    {
     80        return "M " + x + " " + y;
     81    }
     82   
     83   
    6784}
  • trunk/src/com/kitfox/svg/pathcmd/PathCommand.java

    r4256 r6002  
    11/*
    2  * PathCommand.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, 8:39 PM
  • trunk/src/com/kitfox/svg/pathcmd/PathUtil.java

    r4256 r6002  
    11/*
    2  * PathUtil.java
     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
    333 *
    434 * Created on May 10, 2005, 5:56 AM
    5  *
    6  * To change this template, choose Tools | Options and locate the template under
    7  * the Source Creation and Management node. Right-click the template and choose
    8  * Open. You can then make changes to the template in the Source Editor.
    935 */
    1036
  • trunk/src/com/kitfox/svg/pathcmd/Quadratic.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4655    }
    4756
     57    public String toString()
     58    {
     59        return "Q " + kx + " " + ky
     60             + " " + x + " " + y;
     61    }
     62
    4863    public Quadratic(boolean isRelative, float kx, float ky, float x, float y) {
    4964        super(isRelative);
     
    5772    public void appendPath(GeneralPath path, BuildHistory hist)
    5873    {
    59         float offx = isRelative ? hist.history[0].x : 0f;
    60         float offy = isRelative ? hist.history[0].y : 0f;
     74        float offx = isRelative ? hist.lastPoint.x : 0f;
     75        float offy = isRelative ? hist.lastPoint.y : 0f;
    6176
    6277        path.quadTo(kx + offx, ky + offy, x + offx, y + offy);
    63         hist.setPointAndKnot(x + offx, y + offy, kx + offx, ky + offy);
     78        hist.setLastPoint(x + offx, y + offy);
     79        hist.setLastKnot(kx + offx, ky + offy);
    6480    }
    6581
  • trunk/src/com/kitfox/svg/pathcmd/QuadraticSmooth.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4453    }
    4554
     55    public String toString()
     56    {
     57        return "T " + x + " " + y;
     58    }
     59
    4660    public QuadraticSmooth(boolean isRelative, float x, float y) {
    4761        super(isRelative);
     
    5367    public void appendPath(GeneralPath path, BuildHistory hist)
    5468    {
    55         float offx = isRelative ? hist.history[0].x : 0f;
    56         float offy = isRelative ? hist.history[0].y : 0f;
     69        float offx = isRelative ? hist.lastPoint.x : 0f;
     70        float offy = isRelative ? hist.lastPoint.y : 0f;
    5771
    58         float oldKx = hist.history.length >= 2 ? hist.history[1].x : hist.history[0].x;
    59         float oldKy = hist.history.length >= 2 ? hist.history[1].y : hist.history[0].y;
    60         float oldX = hist.history[0].x;
    61         float oldY = hist.history[0].y;
     72        float oldKx = hist.lastKnot.x;
     73        float oldKy = hist.lastKnot.y;
     74        float oldX = hist.lastPoint.x;
     75        float oldY = hist.lastPoint.y;
    6276        //Calc knot as reflection of old knot
    6377        float kx = oldX * 2f - oldKx;
     
    6579
    6680        path.quadTo(kx, ky, x + offx, y + offy);
    67         hist.setPointAndKnot(x + offx, y + offy, kx, ky);
     81        hist.setLastPoint(x + offx, y + offy);
     82        hist.setLastKnot(kx, ky);
    6883    }
    6984
  • trunk/src/com/kitfox/svg/pathcmd/Terminal.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4352    }
    4453
     54    public String toString()
     55    {
     56        return "Z";
     57    }
     58
    4559
    4660//    public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
     
    4862    {
    4963        path.closePath();
    50         hist.setPoint(hist.start.x, hist.start.y);
     64        hist.setLastPoint(hist.startPoint.x, hist.startPoint.y);
     65        hist.setLastKnot(hist.startPoint.x, hist.startPoint.y);
    5166    }
    5267   
  • trunk/src/com/kitfox/svg/pathcmd/Vertical.java

    r4256 r6002  
    11/*
    2  * MoveTo.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, 8:40 PM
     
    4352    }
    4453
     54    public String toString()
     55    {
     56        return "V " + y;
     57    }
     58
    4559    public Vertical(boolean isRelative, float y) {
    4660        super(isRelative);
     
    5165    public void appendPath(GeneralPath path, BuildHistory hist)
    5266    {
    53         float offx = hist.history[0].x;
    54         float offy = isRelative ? hist.history[0].y : 0f;
     67        float offx = hist.lastPoint.x;
     68        float offy = isRelative ? hist.lastPoint.y : 0f;
    5569
    5670        path.lineTo(offx, y + offy);
    57         hist.setPoint(offx, y + offy);
     71        hist.setLastPoint(offx, y + offy);
     72        hist.setLastKnot(offx, y + offy);
    5873    }
    5974
  • trunk/src/com/kitfox/svg/pattern/PatternPaint.java

    r4256 r6002  
    11/*
    2  * PatternPaint.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 April 1, 2004, 3:37 AM
  • trunk/src/com/kitfox/svg/pattern/PatternPaintContext.java

    r4256 r6002  
    11/*
    2  * PatternPaintContext.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 April 1, 2004, 3:37 AM
     
    2837package com.kitfox.svg.pattern;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import java.awt.*;
    3141import java.awt.geom.*;
    3242import java.awt.image.*;
     43import java.util.logging.Level;
     44import java.util.logging.Logger;
    3345
    3446/**
     
    6678            xform.concatenate(userXform.createInverse());
    6779        }
    68         catch (Exception e) { e.printStackTrace(); }
     80        catch (Exception e)
     81        {
     82            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
     83        }
    6984
    7085        sourceWidth = source.getWidth();
  • trunk/src/com/kitfox/svg/xml/Base64InputStream.java

    r4256 r6002  
    11/*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
     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
    433 */
    534
  • trunk/src/com/kitfox/svg/xml/Base64OutputStream.java

    r4256 r6002  
    11/*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
     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
    433 */
    534
  • trunk/src/com/kitfox/svg/xml/Base64Util.java

    r4256 r6002  
    11/*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
     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
    433 */
    534
  • trunk/src/com/kitfox/svg/xml/ColorTable.java

    r4256 r6002  
    11/*
    2  * ColorTable.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, 4:34 AM
  • trunk/src/com/kitfox/svg/xml/NumberWithUnits.java

    r4256 r6002  
    11/*
    2  * NumberWithUnits.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 February 18, 2004, 2:43 PM
  • trunk/src/com/kitfox/svg/xml/ReadableXMLElement.java

    r4256 r6002  
    11/*
    2  * LoadableObject.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 September 1, 2003, 1:46 AM
  • trunk/src/com/kitfox/svg/xml/StyleAttribute.java

    r4256 r6002  
    11/*
    2  * StyleAttribute.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 27, 2004, 2:53 PM
     
    2837package com.kitfox.svg.xml;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import java.awt.*;
     41import java.io.*;
    3142import java.net.*;
    32 import java.io.*;
     43import java.util.logging.Level;
     44import java.util.logging.Logger;
    3345import java.util.regex.*;
    3446
     
    4153    public static final long serialVersionUID = 0;
    4254
    43     static final Matcher matchUrl = Pattern.compile("\\s*url\\((.*)\\)\\s*").matcher("");
     55    static final Pattern patternUrl = Pattern.compile("\\s*url\\((.*)\\)\\s*");
    4456    static final Matcher matchFpNumUnits = Pattern.compile("\\s*([-+]?((\\d*\\.\\d+)|(\\d+))([-+]?[eE]\\d+)?)\\s*(px|cm|mm|in|pc|pt|em|ex)\\s*").matcher("");
    4557   
     
    6880    }
    6981
    70     public String getName() { return name; }
    71     public StyleAttribute setName(String name) { this.name = name; return this; }
    72    
    73     public String getStringValue() { return stringValue; }
     82    public String getName() {
     83        return name;
     84    }
     85   
     86    public StyleAttribute setName(String name)
     87    {
     88        this.name = name;
     89        return this;
     90    }
     91   
     92    public String getStringValue()
     93    {
     94        return stringValue;
     95    }
    7496
    7597    public String[] getStringList()
     
    177199    public String parseURLFn()
    178200    {
    179         matchUrl.reset(stringValue);
    180         if (!matchUrl.matches()) return null;
     201        Matcher matchUrl = patternUrl.matcher(stringValue);
     202        if (!matchUrl.matches())
     203        {
     204            return null;
     205        }
    181206        return matchUrl.group(1);
    182207    }
     
    191216        catch (Exception e)
    192217        {
    193             e.printStackTrace();
     218            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    194219            return null;
    195220        }
     
    206231        catch (Exception e)
    207232        {
    208             e.printStackTrace();
     233            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    209234            return null;
    210235        }
     
    264289        catch (Exception e)
    265290        {
    266             e.printStackTrace();
     291            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    267292            return null;
    268293        }
     
    285310        catch (Exception e)
    286311        {
    287             e.printStackTrace();
     312            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    288313        }
    289314    }
  • trunk/src/com/kitfox/svg/xml/WritableXMLElement.java

    r4256 r6002  
    11/*
    2  * LoadableObject.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 September 1, 2003, 1:46 AM
  • trunk/src/com/kitfox/svg/xml/XMLParseUtil.java

    r4256 r6002  
    11/*
    2  * XMLParseUtil.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 February 18, 2004, 1:49 PM
     
    2837package com.kitfox.svg.xml;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import org.w3c.dom.*;
    3141import java.awt.*;
     
    3444import java.util.regex.*;
    3545import java.lang.reflect.*;
     46import java.util.logging.Level;
     47import java.util.logging.Logger;
    3648
    3749/**
     
    140152        catch (StringIndexOutOfBoundsException e)
    141153        {
    142             System.err.println("XMLParseUtil: regex parse problem: '" + val + "'");
    143             e.printStackTrace();
     154            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     155                "XMLParseUtil: regex parse problem: '" + val + "'", e);
    144156        }
    145157
     
    537549
    538550            ReadableXMLElement newObj = null;
    539             try { newObj = (ReadableXMLElement)classType.newInstance(); }
    540             catch (Exception e) { e.printStackTrace(); continue; }
     551            try
     552            {
     553                newObj = (ReadableXMLElement)classType.newInstance();
     554            }
     555            catch (Exception e)
     556            {
     557                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
     558                continue;
     559            }
    541560            newObj.read(ele, docRoot);
    542561
     
    567586        HashMap retMap = new HashMap();
    568587
    569 /*
    570         Class[] params = {Element.class, URL.class};
    571         Method loadMethod = null;
    572         try { loadMethod = classType.getMethod("load", params); }
    573         catch (Exception e) { e.printStackTrace(); return null; }
    574 
    575  */
    576588        NodeList nl = root.getChildNodes();
    577589        int size = nl.getLength();
     
    584596
    585597            ReadableXMLElement newObj = null;
    586             try { newObj = (ReadableXMLElement)classType.newInstance(); }
    587             catch (Exception e) { e.printStackTrace(); continue; }
     598            try
     599            {
     600                newObj = (ReadableXMLElement)classType.newInstance();
     601            }
     602            catch (Exception e)
     603            {
     604                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
     605                continue;
     606            }
    588607            newObj.read(ele, docRoot);
    589 /*
    590             Object[] args = {ele, source};
    591             Object obj = null;
    592             try { obj = loadMethod.invoke(null, args); }
    593             catch (Exception e) { e.printStackTrace(); }
    594 
    595  */
     608
    596609            if (newObj == null) continue;
    597610
     
    614627
    615628        HashSet retSet = new HashSet();
    616 
    617         /*
    618         Class[] params = {Element.class, URL.class};
    619         Method loadMethod = null;
    620         try { loadMethod = classType.getMethod("load", params); }
    621         catch (Exception e) { e.printStackTrace(); return null; }
    622         */
    623629
    624630        NodeList nl = root.getChildNodes();
     
    632638
    633639            ReadableXMLElement newObj = null;
    634             try { newObj = (ReadableXMLElement)classType.newInstance(); }
    635             catch (Exception e) { e.printStackTrace(); continue; }
     640            try
     641            {
     642                newObj = (ReadableXMLElement)classType.newInstance();
     643            }
     644            catch (Exception e)
     645            {
     646                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
     647                continue;
     648            }
    636649            newObj.read(ele, docRoot);
    637             /*
    638             Object[] args = {ele, source};
    639             Object obj = null;
    640             try { obj = loadMethod.invoke(null, args); }
    641             catch (Exception e) { e.printStackTrace(); }
    642              */
    643 
    644             if (newObj == null) continue;
     650
     651            if (newObj == null)
     652            {
     653                continue;
     654            }
    645655
    646656            retSet.add(newObj);
     
    672682
    673683            ReadableXMLElement newObj = null;
    674             try { newObj = (ReadableXMLElement)classType.newInstance(); }
    675             catch (Exception e) { e.printStackTrace(); continue; }
     684            try
     685            {
     686                newObj = (ReadableXMLElement)classType.newInstance();
     687            }
     688            catch (Exception e)
     689            {
     690                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
     691                continue;
     692            }
    676693            newObj.read(ele, docRoot);
    677694
     
    790807    public static HashMap parseStyle(String styleString, HashMap map) {
    791808        final Pattern patSemi = Pattern.compile(";");
    792         final Pattern patColonSpace = Pattern.compile(":");
    793 
    794         //Strips left and right whitespace
    795         final Matcher matcherContent = Pattern.compile("\\s*([^\\s](.*[^\\s])?)\\s*").matcher("");
    796809
    797810        String[] styles = patSemi.split(styleString);
     
    804817            }
    805818
    806             String[] vals = patColonSpace.split(styles[i]);
    807 
    808             matcherContent.reset(vals[0]);
    809             matcherContent.matches();
    810             vals[0] = matcherContent.group(1);
    811 
    812             matcherContent.reset(vals[1]);
    813             matcherContent.matches();
    814             vals[1] = matcherContent.group(1);
    815 
    816             map.put(vals[0], new StyleAttribute(vals[0], vals[1]));
     819            int colon = styles[i].indexOf(':');
     820            if (colon == -1)
     821            {
     822                continue;
     823            }
     824
     825            String key = styles[i].substring(0, colon).trim();
     826            String value = styles[i].substring(colon + 1).trim();
     827
     828            map.put(key, new StyleAttribute(key, value));
    817829        }
    818830
  • trunk/src/com/kitfox/svg/xml/cpx/CPXConsts.java

    r4256 r6002  
    11/*
    2  * CPXConst.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 February 12, 2004, 12:51 PM
  • trunk/src/com/kitfox/svg/xml/cpx/CPXInputStream.java

    r4256 r6002  
    11/*
    2  * CPXInputStream.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 12, 2004, 10:34 AM
     
    2837package com.kitfox.svg.xml.cpx;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import java.io.*;
    3141import java.util.*;
    3242import java.util.zip.*;
    3343import java.security.*;
     44import java.util.logging.Level;
     45import java.util.logging.Logger;
    3446import javax.crypto.*;
    3547
     
    201213            catch (Exception e)
    202214            {
    203                 e.printStackTrace();
     215                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    204216                return -1;
    205217            }
     
    207219            if (!inflater.finished())
    208220            {
    209                 new Exception("Inflation incomplete").printStackTrace();
     221                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     222                    "Inflation imncomplete");
    210223            }
    211224
     
    213226        }
    214227
    215         try {
     228        try
     229        {
    216230            return inflater.inflate(b, off, len);
    217231        }
    218232        catch (DataFormatException e)
    219233        {
    220             e.printStackTrace();
     234            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    221235            return -1;
    222236        }
  • trunk/src/com/kitfox/svg/xml/cpx/CPXOutputStream.java

    r4256 r6002  
    11/*
    2  * CPXOutputStream.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 February 12, 2004, 12:50 PM
  • trunk/src/com/kitfox/svg/xml/cpx/CPXTest.java

    r4256 r6002  
    11/*
    2  * CPXTest.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 February 12, 2004, 2:45 PM
     
    2837package com.kitfox.svg.xml.cpx;
    2938
     39import com.kitfox.svg.SVGConst;
    3040import java.io.*;
    31 import java.net.*;
     41import java.util.logging.Level;
     42import java.util.logging.Logger;
    3243
    3344/**
     
    6576        catch (Exception e)
    6677        {
    67             e.printStackTrace();
     78            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    6879        }
    6980    }
     
    8798        catch (Exception e)
    8899        {
    89             e.printStackTrace();
     100            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, null, e);
    90101        }
    91102    }
     
    94105     * @param args the command line arguments
    95106     */
    96     public static void main(String[] args) {
     107    public static void main(String[] args)
     108    {
    97109        new CPXTest();
    98110    }
Note: See TracChangeset for help on using the changeset viewer.