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/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
Note: See TracChangeset for help on using the changeset viewer.