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/Font.java | 272 ++++++++++++++++++--------------- 1 file changed, 149 insertions(+), 123 deletions(-) (limited to 'src/main/java/com/kitfox/svg/Font.java') diff --git a/src/main/java/com/kitfox/svg/Font.java b/src/main/java/com/kitfox/svg/Font.java index f6e96a0..8d782de 100644 --- a/src/main/java/com/kitfox/svg/Font.java +++ b/src/main/java/com/kitfox/svg/Font.java @@ -33,14 +33,10 @@ * * Created on February 20, 2004, 10:00 PM */ - package com.kitfox.svg; import com.kitfox.svg.xml.StyleAttribute; -import com.kitfox.svg.xml.*; -import org.xml.sax.*; - -import java.util.*; +import java.util.HashMap; /** * Implements an embedded font. @@ -52,62 +48,47 @@ import java.util.*; */ public class Font extends SVGElement { + + public static final String TAG_NAME = "font"; int horizOriginX = 0; int horizOriginY = 0; int horizAdvX = -1; //Must be specified int vertOriginX = -1; //Defaults to horizAdvX / 2 int vertOriginY = -1; //Defaults to font's ascent int vertAdvY = -1; //Defaults to one 'em'. See font-face - FontFace fontFace = null; MissingGlyph missingGlyph = null; final HashMap glyphs = new HashMap(); - /** Creates a new instance of Font */ + /** + * Creates a new instance of Font + */ public Font() { } -/* - public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) - { - //Load style string - super.loaderStartElement(helper, attrs, parent); - - String horizOriginX = attrs.getValue("horiz-origin-x"); - String horizOriginY = attrs.getValue("horiz-origin-y"); - 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 (horizOriginX != null) this.horizOriginX = XMLParseUtil.parseInt(horizOriginX); - if (horizOriginY != null) this.horizOriginY = XMLParseUtil.parseInt(horizOriginY); - 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 */ public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException { - super.loaderAddChild(helper, child); + super.loaderAddChild(helper, child); if (child instanceof Glyph) { - glyphs.put(((Glyph)child).getUnicode(), child); - } - else if (child instanceof MissingGlyph) + glyphs.put(((Glyph) child).getUnicode(), child); + } else if (child instanceof MissingGlyph) { - missingGlyph = (MissingGlyph)child; - } - else if (child instanceof FontFace) + missingGlyph = (MissingGlyph) child; + } else if (child instanceof FontFace) { - fontFace = (FontFace)child; + fontFace = (FontFace) child; } } @@ -116,66 +97,111 @@ public class Font extends SVGElement super.loaderEndElement(helper); //build(); - + helper.universe.registerFont(this); } - + protected void build() throws SVGException { super.build(); - + StyleAttribute sty = new StyleAttribute(); - - if (getPres(sty.setName("horiz-origin-x"))) horizOriginX = sty.getIntValue(); - - if (getPres(sty.setName("horiz-origin-y"))) horizOriginY = 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-y"))) vertOriginY = sty.getIntValue(); - - if (getPres(sty.setName("vert-adv-y"))) vertAdvY = sty.getIntValue(); + + if (getPres(sty.setName("horiz-origin-x"))) + { + horizOriginX = sty.getIntValue(); + } + + if (getPres(sty.setName("horiz-origin-y"))) + { + horizOriginY = 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-y"))) + { + vertOriginY = sty.getIntValue(); + } + + if (getPres(sty.setName("vert-adv-y"))) + { + vertAdvY = sty.getIntValue(); + } + } + + public FontFace getFontFace() + { + return fontFace; } - - public FontFace getFontFace() { return fontFace; } public MissingGlyph getGlyph(String unicode) { - Glyph retVal = (Glyph)glyphs.get(unicode); - if (retVal == null) return missingGlyph; + Glyph retVal = (Glyph) glyphs.get(unicode); + if (retVal == null) + { + return missingGlyph; + } return retVal; } - public int getHorizOriginX() { return horizOriginX; } - public int getHorizOriginY() { return horizOriginY; } - public int getHorizAdvX() { return horizAdvX; } + public int getHorizOriginX() + { + return horizOriginX; + } + + public int getHorizOriginY() + { + return horizOriginY; + } + + public int getHorizAdvX() + { + return horizAdvX; + } public int getVertOriginX() { - if (vertOriginX != -1) return vertOriginX; + if (vertOriginX != -1) + { + return vertOriginX; + } vertOriginX = getHorizAdvX() / 2; return vertOriginX; } public int getVertOriginY() { - if (vertOriginY != -1) return vertOriginY; + if (vertOriginY != -1) + { + return vertOriginY; + } vertOriginY = fontFace.getAscent(); return vertOriginY; } public int getVertAdvY() { - if (vertAdvY != -1) return vertAdvY; + if (vertAdvY != -1) + { + return vertAdvY; + } vertAdvY = fontFace.getUnitsPerEm(); return vertAdvY; } - + /** - * 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 */ @@ -184,73 +210,73 @@ public class Font extends SVGElement //Fonts can't change return false; /* - if (trackManager.getNumTracks() == 0) return false; + if (trackManager.getNumTracks() == 0) return false; - //Get current values for parameters - StyleAttribute sty = new StyleAttribute(); - boolean stateChange = false; + //Get current values for parameters + StyleAttribute sty = new StyleAttribute(); + boolean stateChange = false; - if (getPres(sty.setName("horiz-origin-x"))) - { - int newVal = sty.getIntValue(); - if (newVal != horizOriginX) - { - horizOriginX = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("horiz-origin-x"))) + { + int newVal = sty.getIntValue(); + if (newVal != horizOriginX) + { + horizOriginX = newVal; + stateChange = true; + } + } - if (getPres(sty.setName("horiz-origin-y"))) - { - int newVal = sty.getIntValue(); - if (newVal != horizOriginY) - { - horizOriginY = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("horiz-origin-y"))) + { + int newVal = sty.getIntValue(); + if (newVal != horizOriginY) + { + horizOriginY = newVal; + stateChange = true; + } + } - if (getPres(sty.setName("horiz-adv-x"))) - { - int newVal = sty.getIntValue(); - if (newVal != horizAdvX) - { - horizAdvX = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("horiz-adv-x"))) + { + int newVal = sty.getIntValue(); + if (newVal != horizAdvX) + { + horizAdvX = newVal; + stateChange = true; + } + } - if (getPres(sty.setName("vert-origin-x"))) - { - int newVal = sty.getIntValue(); - if (newVal != vertOriginX) - { - vertOriginX = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("vert-origin-x"))) + { + int newVal = sty.getIntValue(); + if (newVal != vertOriginX) + { + vertOriginX = newVal; + stateChange = true; + } + } - if (getPres(sty.setName("vert-origin-y"))) - { - int newVal = sty.getIntValue(); - if (newVal != vertOriginY) - { - vertOriginY = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("vert-origin-y"))) + { + int newVal = sty.getIntValue(); + if (newVal != vertOriginY) + { + vertOriginY = newVal; + stateChange = true; + } + } - if (getPres(sty.setName("vert-adv-y"))) - { - int newVal = sty.getIntValue(); - if (newVal != vertAdvY) - { - vertAdvY = newVal; - stateChange = true; - } - } + if (getPres(sty.setName("vert-adv-y"))) + { + int newVal = sty.getIntValue(); + if (newVal != vertAdvY) + { + vertAdvY = newVal; + stateChange = true; + } + } - return shapeChange; - */ + return shapeChange; + */ } } -- cgit v1.2.3-55-g7522