From b4e88ac42c444e4ed98b3f6d69187f78eed397b5 Mon Sep 17 00:00:00 2001 From: kitfox Date: Wed, 11 Jul 2012 05:17:46 +0000 Subject: Adding support for 'letter-spacing' attr in Tspan element. git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@117 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b --- src/main/java/com/kitfox/svg/Tspan.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main/java/com/kitfox/svg/Tspan.java b/src/main/java/com/kitfox/svg/Tspan.java index bffa6b8..ceaa394 100644 --- a/src/main/java/com/kitfox/svg/Tspan.java +++ b/src/main/java/com/kitfox/svg/Tspan.java @@ -159,12 +159,19 @@ public class Tspan extends ShapeElement { { fontSize = sty.getFloatValueWithUnits(); } + + float letterSpacing = 0; + if (getStyle(sty.setName("letter-spacing"))) + { + letterSpacing = sty.getFloatValueWithUnits(); + } + //Get font Font font = diagram.getUniverse().getFont(fontFamily); if (font == null) { - addShapeSysFont(addShape, font, fontFamily, fontSize); + addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing); return; } @@ -206,13 +213,14 @@ public class Tspan extends ShapeElement { cursorY += dy[posPtr++]; } - cursorX += fontScale * glyph.getHorizAdvX(); + cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing; } strokeWidthScalar = 1f; } - private void addShapeSysFont(GeneralPath addShape, Font font, String fontFamily, float fontSize) + private void addShapeSysFont(GeneralPath addShape, Font font, + String fontFamily, float fontSize, float letterSpacing) { java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int)fontSize); @@ -225,7 +233,7 @@ public class Tspan extends ShapeElement { for (int i = 0; i < text.length(); i++) { xform.setToIdentity(); - xform.setToTranslation(cursorX, cursorY); + xform.setToTranslation(cursorX + i * letterSpacing, cursorY); if (rotate != null) xform.rotate(rotate[Math.min(i, rotate.length - 1)]); String unicode = text.substring(i, i + 1); -- cgit v1.2.3-55-g7522