Index: trunk/src/com/kitfox/svg/Tspan.java
===================================================================
--- trunk/src/com/kitfox/svg/Tspan.java	(revision 6002)
+++ trunk/src/com/kitfox/svg/Tspan.java	(revision 7676)
@@ -44,4 +44,5 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 
@@ -60,6 +61,6 @@
     float[] rotate = null;
     private String text = "";
-    float cursorX;
-    float cursorY;
+//    float cursorX;
+//    float cursorY;
 
 //    Shape tspanShape;
@@ -76,23 +77,23 @@
     }
 
-    public float getCursorX()
-    {
-        return cursorX;
-    }
-
-    public float getCursorY()
-    {
-        return cursorY;
-    }
-
-    public void setCursorX(float cursorX)
-    {
-        this.cursorX = cursorX;
-    }
-
-    public void setCursorY(float cursorY)
-    {
-        this.cursorY = cursorY;
-    }
+//    public float getCursorX()
+//    {
+//        return cursorX;
+//    }
+//
+//    public float getCursorY()
+//    {
+//        return cursorY;
+//    }
+//
+//    public void setCursorX(float cursorX)
+//    {
+//        this.cursorX = cursorX;
+//    }
+//
+//    public void setCursorY(float cursorY)
+//    {
+//        this.cursorY = cursorY;
+//    }
     /*
      public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
@@ -165,21 +166,21 @@
     }
 
-    public void addShape(GeneralPath addShape) throws SVGException
-    {
-        if (x != null)
-        {
-            cursorX = x[0];
-        } else if (dx != null)
-        {
-            cursorX += dx[0];
-        }
-
-        if (y != null)
-        {
-            cursorY = y[0];
-        } else if (dy != null)
-        {
-            cursorY += dy[0];
-        }
+    public void appendToShape(GeneralPath addShape, Point2D cursor) throws SVGException
+    {
+//        if (x != null)
+//        {
+//            cursorX = x[0];
+//        } else if (dx != null)
+//        {
+//            cursorX += dx[0];
+//        }
+//
+//        if (y != null)
+//        {
+//            cursorY = y[0];
+//        } else if (dy != null)
+//        {
+//            cursorY += dy[0];
+//        }
 
         StyleAttribute sty = new StyleAttribute();
@@ -209,5 +210,5 @@
         if (font == null)
         {
-            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing);
+            addShapeSysFont(addShape, font, fontFamily, fontSize, letterSpacing, cursor);
             return;
         }
@@ -221,8 +222,30 @@
         strokeWidthScalar = 1f / fontScale;
 
-        int posPtr = 1;
-
-        for (int i = 0; i < text.length(); i++)
-        {
+        float cursorX = (float)cursor.getX();
+        float cursorY = (float)cursor.getY();
+    
+//        int i = 0;
+
+        String drawText = this.text;
+        drawText = drawText.trim();
+        for (int i = 0; i < drawText.length(); i++)
+        {
+            if (x != null && i < x.length)
+            {
+                cursorX = x[i];
+            } else if (dx != null && i < dx.length)
+            {
+                cursorX += dx[i];
+            }
+            
+            if (y != null && i < y.length)
+            {
+                cursorY = y[i];
+            } else if (dy != null && i < dy.length)
+            {
+                cursorY += dy[i];
+            }
+  //          i++;
+            
             xform.setToIdentity();
             xform.setToTranslation(cursorX, cursorY);
@@ -230,8 +253,8 @@
             if (rotate != null)
             {
-                xform.rotate(rotate[posPtr]);
-            }
-
-            String unicode = text.substring(i, i + 1);
+                xform.rotate(rotate[i]);
+            }
+
+            String unicode = drawText.substring(i, i + 1);
             MissingGlyph glyph = font.getGlyph(unicode);
 
@@ -243,35 +266,48 @@
             }
 
-            if (x != null && posPtr < x.length)
-            {
-                cursorX = x[posPtr];
-                cursorY = y[posPtr++];
-            } else if (dx != null && posPtr < dx.length)
-            {
-                cursorX += dx[posPtr];
-                cursorY += dy[posPtr++];
-            }
-
             cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing;
         }
 
+        //Save final draw point so calling method knows where to begin next
+        // text draw
+        cursor.setLocation(cursorX, cursorY);
         strokeWidthScalar = 1f;
     }
 
     private void addShapeSysFont(GeneralPath addShape, Font font,
-        String fontFamily, float fontSize, float letterSpacing)
-    {
+        String fontFamily, float fontSize, float letterSpacing, Point2D cursor)
+    {
+
         java.awt.Font sysFont = new java.awt.Font(fontFamily, java.awt.Font.PLAIN, (int) fontSize);
 
         FontRenderContext frc = new FontRenderContext(null, true, true);
-        GlyphVector textVector = sysFont.createGlyphVector(frc, text);
+        String renderText = this.text.trim();
 
         AffineTransform xform = new AffineTransform();
 
-        int posPtr = 1;
-        for (int i = 0; i < text.length(); i++)
-        {
+        float cursorX = (float)cursor.getX();
+        float cursorY = (float)cursor.getY();
+//        int i = 0;
+        for (int i = 0; i < renderText.length(); i++)
+        {
+            if (x != null && i < x.length)
+            {
+                cursorX = x[i];
+            } else if (dx != null && i < dx.length)
+            {
+                cursorX += dx[i];
+            }
+
+            if (y != null && i < y.length)
+            {
+                cursorY = y[i];
+            } else if (dy != null && i < dy.length)
+            {
+                cursorY += dy[i];
+            }
+//            i++;
+            
             xform.setToIdentity();
-            xform.setToTranslation(cursorX + i * letterSpacing, cursorY);
+            xform.setToTranslation(cursorX, cursorY);
             if (rotate != null)
             {
@@ -279,25 +315,25 @@
             }
 
-            String unicode = text.substring(i, i + 1);
-            Shape glyphOutline = textVector.getGlyphOutline(i);
-            GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(i);
+//            String unicode = renderText.substring(i, i + 1);
+            GlyphVector textVector = sysFont.createGlyphVector(frc, renderText.substring(i, i + 1));
+            Shape glyphOutline = textVector.getGlyphOutline(0);
+            GlyphMetrics glyphMetrics = textVector.getGlyphMetrics(0);
 
             glyphOutline = xform.createTransformedShape(glyphOutline);
             addShape.append(glyphOutline, false);
 
-            if (x != null && posPtr < x.length)
-            {
-                cursorX = x[posPtr];
-                cursorY = y[posPtr++];
-            } else if (dx != null && posPtr < dx.length)
-            {
-                cursorX += dx[posPtr];
-                cursorY += dy[posPtr++];
-            }
-        }
+
+//            cursorX += fontScale * glyph.getHorizAdvX() + letterSpacing;
+            cursorX += glyphMetrics.getAdvance() + letterSpacing;
+        }
+        
+        cursor.setLocation(cursorX, cursorY);
     }
 
     public void render(Graphics2D g) throws SVGException
     {
+        float cursorX = 0;
+        float cursorY = 0;
+    
         if (x != null)
         {
@@ -385,4 +421,7 @@
     protected void renderSysFont(Graphics2D g, java.awt.Font font) throws SVGException
     {
+        float cursorX = 0;
+        float cursorY = 0;
+    
         int posPtr = 1;
         FontRenderContext frc = g.getFontRenderContext();
