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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/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        }
Note: See TracChangeset for help on using the changeset viewer.