From 6776ed9f1a81e517139d85eb6d2e28911fd0fc35 Mon Sep 17 00:00:00 2001 From: kitfox Date: Tue, 19 Mar 2013 05:20:37 +0000 Subject: Adding support for style sheets. git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@153 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b --- src/main/java/com/kitfox/svg/MissingGlyph.java | 151 ++++++++++++------------- 1 file changed, 70 insertions(+), 81 deletions(-) (limited to 'src/main/java/com/kitfox/svg/MissingGlyph.java') diff --git a/src/main/java/com/kitfox/svg/MissingGlyph.java b/src/main/java/com/kitfox/svg/MissingGlyph.java index e11fd0a..cf041b5 100644 --- a/src/main/java/com/kitfox/svg/MissingGlyph.java +++ b/src/main/java/com/kitfox/svg/MissingGlyph.java @@ -33,17 +33,17 @@ * * Created on February 20, 2004, 10:00 PM */ - package com.kitfox.svg; -import com.kitfox.svg.xml.*; - -import java.awt.*; -import java.awt.geom.*; -import java.util.*; - -import com.kitfox.svg.pathcmd.*; -//import org.apache.batik.ext.awt.geom.ExtendedGeneralPath; +import com.kitfox.svg.pathcmd.BuildHistory; +import com.kitfox.svg.pathcmd.PathCommand; +import com.kitfox.svg.xml.StyleAttribute; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.GeneralPath; +import java.awt.geom.Rectangle2D; +import java.util.Iterator; /** * Implements an embedded font. @@ -55,69 +55,28 @@ import com.kitfox.svg.pathcmd.*; */ public class MissingGlyph extends ShapeElement { + public static final String TAG_NAME = "missingglyph"; + //We may define a path -// ExtendedGeneralPath path = null; Shape path = null; - //Alternately, we may have child graphical elements - int horizAdvX = -1; //Inherits font's value if not set int vertOriginX = -1; //Inherits font's value if not set int vertOriginY = -1; //Inherits font's value if not set int vertAdvY = -1; //Inherits font's value if not set - /** Creates a new instance of Font */ + /** + * Creates a new instance of Font + */ public MissingGlyph() { } -/* - public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) - { - //Load style string - super.loaderStartElement(helper, attrs, parent); - - //If glyph path was specified, calculate it - String commandList = attrs.getValue("d"); - if (commandList != null) - { - StyleAttribute atyleAttrib = getStyle("fill-rule"); - String fillRule = (atyleAttrib == null) ? "nonzero" : atyleAttrib.getStringValue(); - - PathCommand[] commands = parsePathList(commandList); - -// ExtendedGeneralPath buildPath = new ExtendedGeneralPath( - GeneralPath buildPath = new GeneralPath( - fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, - commands.length); - - BuildHistory hist = new BuildHistory(); - - for (int i = 0; i < commands.length; i++) - { - PathCommand cmd = commands[i]; - cmd.appendPath(buildPath, hist); - } - - //Reflect glyph path to put it in user coordinate system - AffineTransform at = new AffineTransform(); - at.scale(1, -1); - path = at.createTransformedShape(buildPath); - } - - - //Read glyph spacing info - String horizAdvX = attrs.getValue("horiz-adv-x"); - String vertOriginX = attrs.getValue("vert-origin-x"); - String vertOriginY = attrs.getValue("vert-origin-y"); - String vertAdvY = attrs.getValue("vert-adv-y"); - - if (horizAdvX != null) this.horizAdvX = XMLParseUtil.parseInt(horizAdvX); - if (vertOriginX != null) this.vertOriginX = XMLParseUtil.parseInt(vertOriginX); - if (vertOriginY != null) this.vertOriginY = XMLParseUtil.parseInt(vertOriginY); - if (vertAdvY != null) this.vertAdvY = XMLParseUtil.parseInt(vertAdvY); + public String getTagName() + { + return TAG_NAME; } -*/ + /** * Called after the start element but before the end element to indicate * each child tag that has been processed @@ -127,26 +86,26 @@ public class MissingGlyph extends ShapeElement super.loaderAddChild(helper, child); } - protected void build() throws SVGException { super.build(); - + StyleAttribute sty = new StyleAttribute(); - + String commandList = ""; - if (getPres(sty.setName("d"))) commandList = sty.getStringValue(); + if (getPres(sty.setName("d"))) + { + commandList = sty.getStringValue(); + } + - //If glyph path was specified, calculate it if (commandList != null) { -// StyleAttribute atyleAttrib = getStyle("fill-rule"); String fillRule = getStyle(sty.setName("fill-rule")) ? sty.getStringValue() : "nonzero"; PathCommand[] commands = parsePathList(commandList); -// ExtendedGeneralPath buildPath = new ExtendedGeneralPath( GeneralPath buildPath = new GeneralPath( fillRule.equals("evenodd") ? GeneralPath.WIND_EVEN_ODD : GeneralPath.WIND_NON_ZERO, commands.length); @@ -167,13 +126,25 @@ public class MissingGlyph extends ShapeElement //Read glyph spacing info - if (getPres(sty.setName("horiz-adv-x"))) horizAdvX = sty.getIntValue(); + if (getPres(sty.setName("horiz-adv-x"))) + { + horizAdvX = sty.getIntValue(); + } - if (getPres(sty.setName("vert-origin-x"))) vertOriginX = sty.getIntValue(); + if (getPres(sty.setName("vert-origin-x"))) + { + vertOriginX = sty.getIntValue(); + } - if (getPres(sty.setName("vert-origin-y"))) vertOriginY = sty.getIntValue(); + if (getPres(sty.setName("vert-origin-y"))) + { + vertOriginY = sty.getIntValue(); + } - if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); + if (getPres(sty.setName("vert-adv-y"))) + { + vertAdvY = sty.getIntValue(); + } } public Shape getPath() @@ -185,15 +156,18 @@ public class MissingGlyph extends ShapeElement { //Do not push or pop stack - if (path != null) renderShape(g, path); - + if (path != null) + { + renderShape(g, path); + } + Iterator it = children.iterator(); while (it.hasNext()) { - SVGElement ele = (SVGElement)it.next(); + SVGElement ele = (SVGElement) it.next(); if (ele instanceof RenderableElement) { - ((RenderableElement)ele).render(g); + ((RenderableElement) ele).render(g); } } @@ -203,47 +177,62 @@ public class MissingGlyph extends ShapeElement public int getHorizAdvX() { if (horizAdvX == -1) - horizAdvX = ((Font)parent).getHorizAdvX(); + { + horizAdvX = ((Font) parent).getHorizAdvX(); + } return horizAdvX; } public int getVertOriginX() { if (vertOriginX == -1) + { vertOriginX = getHorizAdvX() / 2; + } return vertOriginX; } public int getVertOriginY() { if (vertOriginY == -1) - vertOriginY = ((Font)parent).getFontFace().getAscent(); + { + vertOriginY = ((Font) parent).getFontFace().getAscent(); + } return vertOriginY; } public int getVertAdvY() { if (vertAdvY == -1) - vertAdvY = ((Font)parent).getFontFace().getUnitsPerEm(); + { + vertAdvY = ((Font) parent).getFontFace().getUnitsPerEm(); + } return vertAdvY; } public Shape getShape() { - if (path != null) return shapeToParent(path); + if (path != null) + { + return shapeToParent(path); + } return null; } public Rectangle2D getBoundingBox() throws SVGException { - if (path != null) return boundsToParent(includeStrokeInBounds(path.getBounds2D())); + if (path != null) + { + return boundsToParent(includeStrokeInBounds(path.getBounds2D())); + } return null; } /** - * Updates all attributes in this diagram associated with a time event. - * Ie, all attributes with track information. + * Updates all attributes in this diagram associated with a time event. Ie, + * all attributes with track information. + * * @return - true if this node has changed state as a result of the time * update */ -- cgit v1.2.3-55-g7522