1) Fixed WMF Text issues.  Many thanks Herve Girod!
2) Updated test-references.
Bug #40368, #40403


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/branches/svg11@441788 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sources/org/apache/batik/svggen/SVGGraphics2D.java b/sources/org/apache/batik/svggen/SVGGraphics2D.java
index 023e580..01597b9 100644
--- a/sources/org/apache/batik/svggen/SVGGraphics2D.java
+++ b/sources/org/apache/batik/svggen/SVGGraphics2D.java
@@ -1206,14 +1206,15 @@
         AffineTransform savTxf = getTransform();
         AffineTransform txtTxf = transformText(x, y);            
 
-        Element text =
-            getDOMFactory().createElementNS(SVG_NAMESPACE_URI, SVG_TEXT_TAG);
-        text.setAttributeNS(null, SVG_X_ATTRIBUTE, generatorCtx.doubleString(x));
-        text.setAttributeNS(null, SVG_Y_ATTRIBUTE, generatorCtx.doubleString(y));
-            
-        text.setAttributeNS(XML_NAMESPACE_URI,
-                            XML_SPACE_ATTRIBUTE,
+        Element text = getDOMFactory().createElementNS(SVG_NAMESPACE_URI, 
+                                                       SVG_TEXT_TAG);
+        text.setAttributeNS(null, SVG_X_ATTRIBUTE, 
+                            generatorCtx.doubleString(x));
+        text.setAttributeNS(null, SVG_Y_ATTRIBUTE, 
+                            generatorCtx.doubleString(y));
+        text.setAttributeNS(XML_NAMESPACE_URI, XML_SPACE_ATTRIBUTE,
                             XML_PRESERVE_VALUE);
+            
         text.appendChild(getDOMFactory().createTextNode(s));
         domGroupManager.addElement(text, DOMGroupManager.FILL);
             
@@ -1288,6 +1289,8 @@
                             generatorCtx.doubleString(x));
         text.setAttributeNS(null, SVG_Y_ATTRIBUTE, 
                             generatorCtx.doubleString(y));
+        text.setAttributeNS(XML_NAMESPACE_URI, XML_SPACE_ATTRIBUTE,
+                            XML_PRESERVE_VALUE);
         
         Font  baseFont  = getFont();
         Paint basePaint = getPaint();
diff --git a/sources/org/apache/batik/transcoder/wmf/WMFConstants.java b/sources/org/apache/batik/transcoder/wmf/WMFConstants.java
index 5c219a7..6a7b8c0 100644
--- a/sources/org/apache/batik/transcoder/wmf/WMFConstants.java
+++ b/sources/org/apache/batik/transcoder/wmf/WMFConstants.java
@@ -100,29 +100,29 @@
     public static final int META_CREATEBRUSHINDIRECT    = 0x02FC;
     public static final int META_CREATEREGION           = 0x06FF;
     public static final int META_POLYBEZIER16           = 0x1000;
-    public static final int META_CREATEBRUSH		  = 0x00F8;
-    public static final int META_CREATEBITMAPINDIRECT	  = 0x02FD;
-    public static final int META_CREATEBITMAP		  = 0x06FE;
+    public static final int META_CREATEBRUSH            = 0x00F8;
+    public static final int META_CREATEBITMAPINDIRECT   = 0x02FD;
+    public static final int META_CREATEBITMAP           = 0x06FE;
     
-    public static final int META_OBJ_WHITE_BRUSH        = 0;
-    public static final int META_OBJ_LTGRAY_BRUSH       = 1;
-    public static final int META_OBJ_GRAY_BRUSH         = 2;
-    public static final int META_OBJ_DKGRAY_BRUSH       = 3;
-    public static final int META_OBJ_BLACK_BRUSH        = 4;
-    public static final int META_OBJ_NULL_BRUSH         = 5;
-    public static final int META_OBJ_HOLLOW_BRUSH       = 5;
-    public static final int META_OBJ_WHITE_PEN          = 6;
-    public static final int META_OBJ_BLACK_PEN          = 7;
-    public static final int META_OBJ_NULL_PEN           = 8;
-    public static final int META_OBJ_OEM_FIXED_FONT     = 10;
-    public static final int META_OBJ_ANSI_FIXED_FONT    = 11;
-    public static final int META_OBJ_ANSI_VAR_FONT      = 12;
-    public static final int META_OBJ_SYSTEM_FONT        = 13;
+    public static final int META_OBJ_WHITE_BRUSH         = 0;
+    public static final int META_OBJ_LTGRAY_BRUSH        = 1;
+    public static final int META_OBJ_GRAY_BRUSH          = 2;
+    public static final int META_OBJ_DKGRAY_BRUSH        = 3;
+    public static final int META_OBJ_BLACK_BRUSH         = 4;
+    public static final int META_OBJ_NULL_BRUSH          = 5;
+    public static final int META_OBJ_HOLLOW_BRUSH        = 5;
+    public static final int META_OBJ_WHITE_PEN           = 6;
+    public static final int META_OBJ_BLACK_PEN           = 7;
+    public static final int META_OBJ_NULL_PEN            = 8;
+    public static final int META_OBJ_OEM_FIXED_FONT      = 10;
+    public static final int META_OBJ_ANSI_FIXED_FONT     = 11;
+    public static final int META_OBJ_ANSI_VAR_FONT       = 12;
+    public static final int META_OBJ_SYSTEM_FONT         = 13;
     public static final int META_OBJ_DEVICE_DEFAULT_FONT = 14;
-    public static final int META_OBJ_DEFAULT_PALETTE    = 15;
-    public static final int META_OBJ_SYSTEM_FIXED_FONT  = 16;
+    public static final int META_OBJ_DEFAULT_PALETTE     = 15;
+    public static final int META_OBJ_SYSTEM_FIXED_FONT   = 16;
     
-/* New StretchBlt() Modes */    
+    /* New StretchBlt() Modes */    
     public static final int STRETCH_BLACKONWHITE = 1;
     public static final int STRETCH_WHITEONBLACK = 2;
     public static final int STRETCH_COLORONCOLOR = 3;
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java b/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java
index 574ed3c..60e6263 100644
--- a/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFPainter.java
@@ -37,7 +37,8 @@
     
     public static final String WMF_FILE_EXTENSION = ".wmf";
     protected WMFFont wmfFont = null;
-    protected int currentAlign = 0;
+    protected int currentHorizAlign = 0;
+    protected int currentVertAlign = 0;    
     
     public static final int PEN = 1;
     public static final int BRUSH = 2;
@@ -60,9 +61,7 @@
      *  @return the Image associated with the bitmap (null if the dimensions detected in the
      *     header are not consistent with the assumed dimensions)
      */ 
-    protected BufferedImage getImage(byte[] bit, int width, int height) {       
-        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
-        WritableRaster raster = img.getRaster();                  
+    protected BufferedImage getImage(byte[] bit, int width, int height) {
         // get the header of the bitmap, first the width and height
         int _width = (((int)bit[7] & 0x00ff) << 24) | (((int)bit[6] & 0x00ff) << 16)
                     | (((int)bit[5] & 0x00ff) << 8) | (int)bit[4] & 0x00ff;
@@ -233,32 +232,6 @@
         return ats;
     }    
     
-    /** Decode a byte array in a String, considering the last selected charset.
-     */
-    protected String decodeString(byte[] bstr) {
-        // manage the charset encoding
-        String str;
-        try {
-            if (wmfFont.charset == WMFConstants.META_CHARSET_ANSI) {
-                str = new String(bstr);
-            } else if (wmfFont.charset == WMFConstants.META_CHARSET_DEFAULT) {
-                str = new String(bstr, WMFConstants.CHARSET_DEFAULT);
-            } else if (wmfFont.charset == WMFConstants.META_CHARSET_GREEK) {
-                str = new String(bstr, WMFConstants.CHARSET_GREEK);
-            } else if (wmfFont.charset == WMFConstants.META_CHARSET_RUSSIAN) {
-                str = new String(bstr, WMFConstants.CHARSET_CYRILLIC);
-            } else if (wmfFont.charset == WMFConstants.META_CHARSET_HEBREW) {
-                str = new String(bstr, WMFConstants.CHARSET_HEBREW);
-            } else if (wmfFont.charset == WMFConstants.META_CHARSET_ARABIC) {
-                str = new String(bstr, WMFConstants.CHARSET_ARABIC);
-            } else str = new String(bstr);
-        } catch (UnsupportedEncodingException e) {
-            str = new String(bstr);
-        }
-        
-        return str;
-    }
-    
     /**
      * Sets the WMFRecordStore this WMFPainter should use to render
      */
@@ -284,4 +257,4 @@
     protected int addObjectAt( WMFRecordStore store, int type, Object obj, int idx ) {
         return currentStore.addObjectAt( type, obj, idx );
     }
-}
\ No newline at end of file
+}
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java b/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java
index a719f19..7e2d74a 100644
--- a/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/AbstractWMFReader.java
@@ -18,15 +18,12 @@
 
 package org.apache.batik.transcoder.wmf.tosvg;
 
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.geom.Rectangle2D;
 import java.io.DataInputStream;
 import java.io.IOException;
-import java.net.URL;
 import java.util.Vector;
-import java.awt.Font;
-import java.awt.Toolkit;
-import java.awt.Rectangle;
-import java.awt.geom.Dimension2D;
-import java.awt.geom.Rectangle2D;
 
 import org.apache.batik.transcoder.wmf.WMFConstants;
 
@@ -299,7 +296,7 @@
      *               readShort(is);
      *          break;
      * </pre>
-     * @see svglab.encoding.wmf.WMFConstants
+     * @see WMFConstants
      */
     protected abstract boolean readRecords(DataInputStream is) throws IOException;
     
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java
index 3708c5e..4e00d08 100755
--- a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFHeaderProperties.java
@@ -1,6 +1,6 @@
 /*
 
-   Copyright 2005  The Apache Software Foundation 
+   Copyright 2005-2006  The Apache Software Foundation 
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -18,31 +18,40 @@
 
 package org.apache.batik.transcoder.wmf.tosvg;
 
-import java.awt.Rectangle;
 import java.awt.Color;
-import java.awt.geom.Rectangle2D;
-import java.awt.geom.Point2D;
-import java.awt.geom.Dimension2D;
+import java.awt.Font;
+import java.awt.Rectangle;
 import java.awt.Shape;
-import java.io.File;
-import java.io.IOException;
-import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
 import java.io.BufferedInputStream;
-import java.util.ArrayList;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 
-import org.apache.batik.transcoder.wmf.WMFConstants;
 import org.apache.batik.ext.awt.geom.Polygon2D;
 import org.apache.batik.ext.awt.geom.Polyline2D;
+import org.apache.batik.transcoder.wmf.WMFConstants;
 
-/** This class holds simple properties about a WMF Metafile. It can be used whenever general 
- * informations must be retrieved about this file.
+/** 
+ * This class holds simple properties about a WMF Metafile. It can be used
+ * whenever general information must be retrieved about this file.
  */
 public class WMFHeaderProperties extends AbstractWMFReader {
     protected DataInputStream stream;
     private int _bleft, _bright, _btop, _bbottom, _bwidth, _bheight;
     private int _ileft, _iright, _itop, _ibottom;    
     private float scale = 1f;
+    private int startX = 0;
+    private int startY = 0;    
+    private int currentHorizAlign = 0;
+    private int currentVertAlign = 0;  
+    private WMFFont wf = null;
+    private static final FontRenderContext fontCtx = 
+            new FontRenderContext(new AffineTransform(), false, true);    
     private transient boolean firstEffectivePaint = true; 
     public static final int PEN = 1;
     public static final int BRUSH = 2;
@@ -108,6 +117,8 @@
         vpH = -1;
         vpX = 0;
         vpY = 0;
+        startX = 0;
+        startY = 0;        
         firstEffectivePaint = true;
     }    
     
@@ -126,11 +137,6 @@
         int penObject = -1; // the last pen
         int fontObject = -1; // the last font 
         GdiObject gdiObj;
-        /* TODO : it is assumed that the previous Font creation before a textout
-         * corresponds to the next, which can be false
-         */
-        int lfWidth = 0; // for Font width        
-        int lfHeight = 0; // for Font height
         
         while (functionId > 0) {            
             recSize = readInt( is );
@@ -192,55 +198,138 @@
                     } else
                         objIndex = addObjectAt(BRUSH, color, objIndex );
                 }
-                break;            
+                break; 
+                
+            case WMFConstants.META_SETTEXTALIGN:
+                    int align = readShort( is );
+                    // need to do this, because sometimes there is more than one short
+                    if (recSize > 1) for (int i = 1; i < recSize; i++) readShort( is );
+                    currentHorizAlign = WMFUtilities.getHorizontalAlignment(align);
+                    currentVertAlign = WMFUtilities.getVerticalAlignment(align);                        
+                    break;                                
 
             case WMFConstants.META_EXTTEXTOUT: {
                     int y = readShort( is );
                     int x = readShort( is );
-                    int lenText = readInt( is );
-                    int len = 2*(recSize-4);
-                    for (int i = 0 ; i < len; i++ ) is.readByte();
+                    int lenText = readShort( is );
+                    int flag = readShort( is );
+                    int read = 4; // used to track the actual size really read                   
+                    boolean clipped = false;
+                    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
+                    int len;
+                    // determination of clipping property
+                    if ((flag & WMFConstants.ETO_CLIPPED) != 0) {
+                        x1 =  readShort( is );
+                        y1 =  readShort( is );
+                        x2 =  readShort( is );
+                        y2 =  readShort( is );
+                        read += 4;
+                        clipped = true;
+                    }
+                    byte bstr[] = new byte[ lenText ];
+                    int i = 0;
+                    for ( ; i < lenText; i++ ) {
+                        bstr[ i ] = is.readByte();
+                    }
+                    String sr = WMFUtilities.decodeString(wf, bstr);                    
+                    
+                    read += (lenText + 1)/2;                    
+                    /* must do this because WMF strings always have an even number of bytes, even
+                     * if there is an odd number of characters
+                     */
+                    if (lenText % 2 != 0) is.readByte();
+                    // if the record was not completely read, finish reading
+                    if (read < recSize) for (int j = read; j < recSize; j++) readShort( is );
+                    TextLayout layout = new TextLayout( sr, wf.font, fontCtx );
+                    
+                    int lfWidth = (int)layout.getBounds().getWidth();
+                    x = (int)layout.getBounds().getX();   
+                    int lfHeight = 
+                        (int)getVerticalAlignmentValue(layout, currentVertAlign);
+                                    
                     resizeBounds(x, y);
-                    resizeBounds(x+lfWidth*lenText, y+lfHeight);
+                    resizeBounds(x+lfWidth, y+lfHeight);
                     firstEffectivePaint = false;
                 }
                 break;
-
+                
+            case WMFConstants.META_DRAWTEXT:
             case WMFConstants.META_TEXTOUT: {
                     int len = readShort( is );
-                    for ( int i = 0; i < len; i++ ) is.readByte();
-                    if (len % 2 != 0) is.readByte();                     
+                    int read = 1; // used to track the actual size really read
+                    byte bstr[] = new byte[ len ];
+                    for ( int i = 0; i < len; i++ ) {
+                        bstr[ i ] = is.readByte();
+                    }
+                    String sr = WMFUtilities.decodeString(wf, bstr);
+                    
+                    /* must do this because WMF strings always have an even number of bytes, even
+                     * if there is an odd number of characters
+                     */
+                    if (len % 2 != 0) is.readByte(); 
+                    read += (len + 1) / 2;
+                    
                     int y = readShort( is );
                     int x = readShort( is );
+                    read += 2;
+                    // if the record was not completely read, finish reading                    
+                    if (read < recSize) for (int j = read; j < recSize; j++) readShort( is );
+                    TextLayout layout = new TextLayout( sr, wf.font, fontCtx );
+                    int lfWidth = (int)layout.getBounds().getWidth();
+                    x = (int)layout.getBounds().getX();                                      
+                    int lfHeight = 
+                        (int)getVerticalAlignmentValue(layout, currentVertAlign);                    
+                    
                     resizeBounds(x, y);
-                    resizeBounds(x+lfWidth*len, y+lfHeight);
+                    resizeBounds(x+lfWidth, y+lfHeight);
                 }
                 break;
 
-
             case WMFConstants.META_CREATEFONTINDIRECT: {
-                // TODO : handle object creation for fonts, because font use can
-                // be done in a different order than font creation
-                    int objIndex = 0;
-                    lfHeight = readShort( is );
-                    lfWidth = readShort( is );
-                    readShort( is );
-                    readShort( is );
-                    readShort( is );
+                    int lfHeight = readShort( is );
+                    float size = (int)(scaleY * lfHeight);
+                    int lfWidth = readShort( is );
+                    int escape = (int)readShort( is );
+                    int orient = (int)readShort( is );
+                    int weight = (int)readShort( is );
 
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-                    is.readByte();
-
-                    int len = (2*(recSize-9));
-                    for ( int i = 0; i < len; i++ ) is.readByte();
+                    int italic = (int)is.readByte();
+                    int underline = (int)is.readByte();
+                    int strikeOut = (int)is.readByte();
+                    int charset = (int)(is.readByte() & 0x00ff);
+                    int lfOutPrecision = is.readByte();
+                    int lfClipPrecision = is.readByte();
+                    int lfQuality = is.readByte();
+                    int lfPitchAndFamily = is.readByte();
                     
-                    objIndex = addObjectAt( FONT, new Boolean(true) , objIndex );                    
+                    int style = italic > 0 ? Font.ITALIC : Font.PLAIN;
+                    style |= (weight > 400) ? Font.BOLD : Font.PLAIN;                    
+
+                    // don't need to read the end of the record, 
+                    // because it will always be completely used
+                    int len = (2*(recSize-9));
+                    byte lfFaceName[] = new byte[ len ];
+                    byte ch;
+                    for ( int i = 0; i < len; i++ ) lfFaceName[ i ] = is.readByte();
+                    String face = new String( lfFaceName );
+
+                    // FIXED : management of font names
+                    int d = 0;
+                    while   ((d < face.length()) &&
+                    ((Character.isLetterOrDigit(face.charAt(d))) ||
+                    (Character.isWhitespace(face.charAt(d))))) d++;
+                    if (d > 0) face = face.substring(0,d);
+                    else face = "System";
+
+                    if ( size < 0 ) size = -size /* * -1.3 */;
+                    int objIndex = 0;
+
+                    Font f = new Font(face, style, (int)size);
+                    f = f.deriveFont(size);
+                    WMFFont wf = new WMFFont(f, charset, underline,
+                        strikeOut, italic, weight, orient, escape);
+                        
+                    objIndex = addObjectAt( FONT, wf , objIndex );                                                            
                 }
                 break;
                 
@@ -274,6 +363,7 @@
                         brushObject = gdiIndex;
                         break;
                     case FONT: {
+                        this.wf =  ((WMFFont)gdiObj.obj);
                         fontObject = gdiIndex;
                         }
                         break;
@@ -295,12 +385,21 @@
                     gdiObj.clear();
                     break;                
                 
-            case WMFConstants.META_LINETO:
-            case WMFConstants.META_MOVETO: {
+            case WMFConstants.META_LINETO: {
                     int y = readShort( is );
                     int x = readShort( is );
-                    if (penObject >= 0) resizeBounds(x, y);
-                    firstEffectivePaint = false;
+                    if (penObject >= 0) {
+                        resizeBounds(startX, startY);
+                        resizeBounds(x, y);                        
+                        firstEffectivePaint = false;                        
+                    }                    
+                    startX = x;
+                    startY = y;
+                }
+                break;                
+            case WMFConstants.META_MOVETO: {
+                    startY = readShort( is );
+                    startX = readShort( is );
                 }
                 break;
                 
@@ -362,7 +461,7 @@
                     int right = readShort( is );
                     int top = readShort( is );
                     int left = readShort( is );
-                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bottom-top);
+                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bot-top);
                     paint(brushObject, penObject, rec);
                 }
                 break;
@@ -374,7 +473,7 @@
                     int right = readShort( is );
                     int top = readShort( is );
                     int left = readShort( is ); 
-                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bottom-top);
+                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bot-top);
                     paint(brushObject, penObject, rec);
                 }
                 break;
@@ -390,7 +489,7 @@
                     int right = readShort( is );
                     int top = readShort( is );
                     int left = readShort( is );
-                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bottom-top);
+                    Rectangle2D.Float rec = new Rectangle2D.Float(left, top, right-left, bot-top);
                     paint(brushObject, penObject, rec);
                 }
                 break;
@@ -511,38 +610,30 @@
      * width and height of the Metafile are kept.
      */
     private void resizeBounds(int x, int y) {
-        if ((x < right) && (x > left)) {
-            if (_bleft == -1) _bleft = x;
-            else if (x < _bleft) _bleft = x;
-            if (_bright == -1) _bright = x;
-            else if (x > _bright) _bright = x; 
-        }
-        
-        if ((y < bottom) && (y > top)) {
-            if (_btop == -1) _btop = y;
-            else if (y < _btop) _btop = y;
-            if (_bbottom == -1) _bbottom = y;
-            else if (y > _bbottom) _bbottom = y;      
-        }
+        if (_bleft == -1) _bleft = x;
+        else if (x < _bleft) _bleft = x;
+        if (_bright == -1) _bright = x;
+        else if (x > _bright) _bright = x;        
+
+        if (_btop == -1) _btop = y;
+        else if (y < _btop) _btop = y;
+        if (_bbottom == -1) _bbottom = y;
+        else if (y > _bbottom) _bbottom = y;                  
     }
     
     /** resize Bounds for each image primitive encountered. Only elements that are in the overall
      * width and height of the Metafile are kept.
      */
     private void resizeImageBounds(int x, int y) {
-        if ((x < right) && (x > left)) {
-            if (_ileft == -1) _ileft = x;
-            else if (x < _ileft) _ileft = x;
-            if (_iright == -1) _iright = x;
-            else if (x > _iright) _iright = x; 
-        }
-        
-        if ((y < bottom) && (y > top)) {
-            if (_itop == -1) _itop = y;
-            else if (y < _itop) _itop = y;
-            if (_ibottom == -1) _ibottom = y;
-            else if (y > _ibottom) _ibottom = y;      
-        }
+        if (_ileft == -1) _ileft = x;
+        else if (x < _ileft) _ileft = x;
+        if (_iright == -1) _iright = x;
+        else if (x > _iright) _iright = x;        
+
+        if (_itop == -1) _itop = y;
+        else if (y < _itop) _itop = y;
+        if (_ibottom == -1) _ibottom = y;
+        else if (y > _ibottom) _ibottom = y;                  
     }
         
     /** get the Color corresponding with the Object (pen or brush object).
@@ -597,5 +688,13 @@
                 firstEffectivePaint = false; 
             }
         }
+    }  
+    
+    /** get the vertical Alignment value for the text.
+     */
+    private float getVerticalAlignmentValue(TextLayout layout, int vertAlign) { 
+        if (vertAlign == WMFConstants.TA_BASELINE) return -layout.getAscent();       
+        else if (vertAlign == WMFConstants.TA_TOP) return (layout.getAscent() + layout.getDescent()); 
+        else return 0;                                
     }        
 }
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java
index dfac090..c8a0af8 100644
--- a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFPainter.java
@@ -19,41 +19,39 @@
 package org.apache.batik.transcoder.wmf.tosvg;
 
 import java.awt.BasicStroke;
-import java.awt.Stroke;
 import java.awt.Color;
-import java.awt.Font;
-import java.awt.Paint;
-import java.awt.Image;
 import java.awt.Dimension;
-import java.awt.TexturePaint;
+import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
-import java.awt.Polygon;
+import java.awt.Image;
+import java.awt.Paint;
 import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.TexturePaint;
 import java.awt.Toolkit;
-import java.awt.image.BufferedImage;
-import java.awt.image.ImageObserver;
 import java.awt.font.FontRenderContext;
 import java.awt.font.TextLayout;
-import java.awt.font.TextAttribute;
 import java.awt.geom.AffineTransform;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Point2D;
 import java.awt.geom.Arc2D;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.GeneralPath;
 import java.awt.geom.Line2D;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.awt.geom.RoundRectangle2D;
-import java.awt.geom.Ellipse2D;
-import java.text.AttributedString;
-import java.text.AttributedCharacterIterator;
+import java.awt.image.BufferedImage;
+import java.awt.image.ImageObserver;
 import java.io.BufferedInputStream;
+import java.text.AttributedCharacterIterator;
+import java.util.Iterator;
 import java.util.Stack;
 import java.util.Vector;
-import java.util.Iterator;
 
-import org.apache.batik.transcoder.wmf.WMFConstants;
 import org.apache.batik.ext.awt.geom.Polygon2D;
 import org.apache.batik.ext.awt.geom.Polyline2D;
+import org.apache.batik.transcoder.wmf.WMFConstants;
+
 /**
   * Core class for rendering the WMF image. It is able to render a
   * WMF file in a <tt>Graphics</tt> object.
@@ -524,9 +522,11 @@
                     break;
                     
                 case WMFConstants.META_SETTEXTALIGN:
-                    currentAlign = 
-                        getHorizontalAlignement((int)mr.ElementAt( 0 ).intValue());
-                    break;                
+                    currentHorizAlign = 
+                            WMFUtilities.getHorizontalAlignment((int)mr.ElementAt( 0 ).intValue());
+                    currentVertAlign = 
+                            WMFUtilities.getVerticalAlignment((int)mr.ElementAt( 0 ).intValue());                        
+                    break;
                     
                 case WMFConstants.META_SETTEXTCOLOR:
                     frgdColor = new Color( (int)mr.ElementAt( 0 ).intValue(),
@@ -546,7 +546,7 @@
                     try {
                         float x, y;
                         byte[] bstr = ((MetaRecord.ByteRecord)mr).bstr;
-                        String sr = decodeString(bstr);
+                        String sr = WMFUtilities.decodeString(wmfFont, bstr);
 
                         x = scaleX * ( vpX + (float)(xOffset + mr.ElementAt( 0 ).intValue()));
                         y = scaleY * ( vpY + (float)(yOffset + mr.ElementAt( 1 ).intValue()));
@@ -558,7 +558,6 @@
                         Point2D.Double pen = new Point2D.Double( 0, 0 );
                         GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO );
                         TextLayout layout = new TextLayout( sr, g2d.getFont(), frc );
-                        pen.y += layout.getAscent();
                         
                         int flag = mr.ElementAt( 2 ).intValue();
                         int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
@@ -576,9 +575,11 @@
                         }
                         
                         firstEffectivePaint = false; 
+                        y += getVerticalAlignmentValue(layout, currentVertAlign);                        
+                        
                         drawString(flag, g2d, 
-                            getCharacterIterator(g2d, sr, wmfFont, currentAlign), x, y, layout, 
-                            wmfFont, currentAlign);
+                            getCharacterIterator(g2d, sr, wmfFont, currentHorizAlign), 
+                            x, y, layout, wmfFont, currentHorizAlign);
                         if (clipped) g2d.setClip(clip);
                     } catch ( Exception e ) {
                     }          
@@ -589,7 +590,7 @@
                     try {
                         float x, y;
                         byte[] bstr = ((MetaRecord.ByteRecord)mr).bstr;
-                        String sr = decodeString(bstr);
+                        String sr = WMFUtilities.decodeString(wmfFont, bstr);
 
                         x = scaleX * ( vpX + (float)(xOffset + mr.ElementAt( 0 ).intValue()));
                         y = scaleY * ( vpY + (float)(yOffset + mr.ElementAt( 1 ).intValue()));
@@ -602,12 +603,12 @@
                         GeneralPath gp = new GeneralPath( GeneralPath.WIND_NON_ZERO );
                         TextLayout layout = new TextLayout( sr, g2d.getFont(), frc );
                         
-                        pen.y += layout.getAscent();
-                        firstEffectivePaint = false;                         
+                        firstEffectivePaint = false; 
+                        y += getVerticalAlignmentValue(layout, currentVertAlign);
                         
                         drawString(-1, g2d, 
                             getCharacterIterator(g2d, sr, wmfFont), 
-                            x, y, layout, wmfFont, currentAlign);
+                            x, y, layout, wmfFont, currentHorizAlign);
                     } catch ( Exception e ) {
                     }
                     break;
@@ -1093,6 +1094,12 @@
                 firstEffectivePaint = false;
             }
         } 
+    }  
+    
+    private float getVerticalAlignmentValue(TextLayout layout, int vertAlign) {
+        if (vertAlign == WMFConstants.TA_BOTTOM) return -layout.getDescent();       
+        else if (vertAlign == WMFConstants.TA_TOP) return layout.getAscent(); 
+        else return 0;                        
     }    
 
     /**
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java
index 11f264d..27c833d 100644
--- a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFTranscoder.java
@@ -19,40 +19,23 @@
 package org.apache.batik.transcoder.wmf.tosvg;
 
 import java.awt.Dimension;
-import java.awt.BasicStroke;
-import java.awt.geom.Rectangle2D;
 import java.io.BufferedInputStream;
 import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLConnection;
 
-import org.w3c.dom.svg.SVGDocument;
-import org.apache.batik.transcoder.TranscodingHints;
-import org.apache.batik.transcoder.keys.*;
-import org.apache.batik.dom.svg.SVGDOMImplementation;
-import org.apache.batik.transcoder.AbstractTranscoder;
+import org.apache.batik.svggen.SVGGraphics2D;
+import org.apache.batik.transcoder.ToSVGAbstractTranscoder;
 import org.apache.batik.transcoder.TranscoderException;
 import org.apache.batik.transcoder.TranscoderInput;
 import org.apache.batik.transcoder.TranscoderOutput;
-import org.apache.batik.util.SVGConstants;
-import org.w3c.dom.DOMImplementation;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.xml.sax.XMLFilter;
-import org.apache.batik.svggen.SVGGraphics2D;
-import org.apache.batik.util.SVGConstants;
-import org.apache.batik.transcoder.ToSVGAbstractTranscoder;
-
-import org.w3c.dom.Node;
-import org.w3c.dom.DocumentFragment;
 
 /** This class implements the <tt>Transcoder</tt> interface and
  *  can convert a WMF input document into an SVG document.
diff --git a/sources/org/apache/batik/transcoder/wmf/tosvg/WMFUtilities.java b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFUtilities.java
new file mode 100644
index 0000000..8511ef8
--- /dev/null
+++ b/sources/org/apache/batik/transcoder/wmf/tosvg/WMFUtilities.java
@@ -0,0 +1,77 @@
+/*
+
+   Copyright 2006 The Apache Software Foundation 
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+  
+ */
+
+package org.apache.batik.transcoder.wmf.tosvg;
+
+import java.awt.font.TextLayout;
+import java.io.UnsupportedEncodingException;
+import org.apache.batik.transcoder.wmf.WMFConstants;
+
+/** This class holds various utilies for importing WMF files that can be used either for
+ *  {@link org.apache.batik.transcoder.wmf.tosvg.AbstractWMFReader}s and 
+ *  {@link org.apache.batik.transcoder.wmf.tosvg.AbstractWMFPainter}s
+ */
+public class WMFUtilities {
+    /** Decode a byte array in a String, considering the last selected charset.
+     */
+    public static String decodeString(WMFFont wmfFont, byte[] bstr) {
+        // manage the charset encoding
+        String str;
+        try {
+            if (wmfFont.charset == WMFConstants.META_CHARSET_ANSI) {
+                str = new String(bstr);
+            } else if (wmfFont.charset == WMFConstants.META_CHARSET_DEFAULT) {
+                str = new String(bstr, WMFConstants.CHARSET_DEFAULT);
+            } else if (wmfFont.charset == WMFConstants.META_CHARSET_GREEK) {
+                str = new String(bstr, WMFConstants.CHARSET_GREEK);
+            } else if (wmfFont.charset == WMFConstants.META_CHARSET_RUSSIAN) {
+                str = new String(bstr, WMFConstants.CHARSET_CYRILLIC);
+            } else if (wmfFont.charset == WMFConstants.META_CHARSET_HEBREW) {
+                str = new String(bstr, WMFConstants.CHARSET_HEBREW);
+            } else if (wmfFont.charset == WMFConstants.META_CHARSET_ARABIC) {
+                str = new String(bstr, WMFConstants.CHARSET_ARABIC);
+            } else str = new String(bstr);
+        } catch (UnsupportedEncodingException e) {
+            str = new String(bstr);
+        }
+        
+        return str;
+    }          
+    
+    /** Get the Horizontal Alignement for the Alignment property.
+     */
+    public static int getHorizontalAlignment(int align) {
+        int v = align;
+        v = v % WMFConstants.TA_BASELINE; // skip baseline alignment (24)
+        v = v % WMFConstants.TA_BOTTOM;  // skip bottom aligment (8)
+        if (v >= 6) return WMFConstants.TA_CENTER;
+        else if (v >= 2) return WMFConstants.TA_RIGHT;
+        else return WMFConstants.TA_LEFT;
+    }
+    
+    /** Get the Vertical Alignement for the Alignment property.
+     */    
+    public static int getVerticalAlignment(int align) {
+        int v = align;
+        if ((v/WMFConstants.TA_BASELINE) != 0) return WMFConstants.TA_BASELINE;
+        v = v % WMFConstants.TA_BASELINE; // skip baseline alignment (24)
+        if ((v/WMFConstants.TA_BOTTOM) != 0) return WMFConstants.TA_BOTTOM;
+        else return WMFConstants.TA_TOP;
+    }     
+}
+
diff --git a/test-references/org/apache/batik/svggen/AttributedCharacterIterator.svg b/test-references/org/apache/batik/svggen/AttributedCharacterIterator.svg
index fc044cd..2c10b68 100644
--- a/test-references/org/apache/batik/svggen/AttributedCharacterIterator.svg
+++ b/test-references/org/apache/batik/svggen/AttributedCharacterIterator.svg
@@ -5,7 +5,7 @@
 ><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
   /><g
   ><g fill="maroon" font-size="15" font-weight="bold" stroke="maroon"
-    ><text x="10" y="100" stroke="none"
+    ><text xml:space="preserve" x="10" y="100" stroke="none"
       ><tspan
         >Attributed</tspan
         ><tspan fill="black" font-weight="normal"
diff --git a/test-references/org/apache/batik/svggen/ContextAttributedCharacterIterator.svg b/test-references/org/apache/batik/svggen/ContextAttributedCharacterIterator.svg
index 2b1e474..6aba825 100644
--- a/test-references/org/apache/batik/svggen/ContextAttributedCharacterIterator.svg
+++ b/test-references/org/apache/batik/svggen/ContextAttributedCharacterIterator.svg
@@ -61,7 +61,7 @@
           /></font
         ></defs
         ><g class="testC1"
-        ><text x="10" y="100" class="testC2"
+        ><text xml:space="preserve" x="10" y="100" class="testC2"
           ><tspan class="testC3"
             >Attributed</tspan
             ><tspan class="testC4"
diff --git a/test-references/org/apache/batik/transcoder/wmf/black_shapes.svg b/test-references/org/apache/batik/transcoder/wmf/black_shapes.svg
index 5eb48d6..b5a4817 100755
--- a/test-references/org/apache/batik/transcoder/wmf/black_shapes.svg
+++ b/test-references/org/apache/batik/transcoder/wmf/black_shapes.svg
@@ -13,13 +13,13 @@
       /><rect x="240" y="432" fill="black" width="483.8333" height="173.5" stroke="none"

     /></g

     ><g stroke-linecap="butt" fill="aqua" font-family="&apos;monospaced&apos;" stroke-linejoin="round" stroke="aqua" stroke-width="0.6667"

-    ><text x="678.3334" y="491.5" stroke="none"

+    ><text xml:space="preserve" x="678.3334" y="491.5" stroke="none"

       >20</text

-      ><text fill="rgb(255,102,255)" x="624" font-size="10" y="522.5" stroke="none"

+      ><text x="624" font-size="10" y="522.5" fill="rgb(255,102,255)" stroke="none" xml:space="preserve"

       >SHTZ</text

-      ><text fill="rgb(255,102,255)" x="655.6667" font-size="10" y="522.5" stroke="none"

+      ><text x="655.6667" font-size="10" y="522.5" fill="rgb(255,102,255)" stroke="none" xml:space="preserve"

       >1500 </text

-      ><text fill="rgb(255,102,255)" x="687.3334" font-size="10" y="522.5" stroke="none"

+      ><text x="687.3334" font-size="10" y="522.5" fill="rgb(255,102,255)" stroke="none" xml:space="preserve"

       >FT</text

       ><path fill="lime" d="M520 473.5 L524.8334 473.8333 L527.1667 474 L527.6667 471.1667 L524.8334 470.8333 L520 470.5 L515.1667 470.8333 L510.3333 471.5 L509.8333 471.5 L507.8333 472.1667 L508.5 475 L511 474.3333 L510.3333 473 L510.3333 474.5 L515.1667 473.8333 Z" stroke="none"

       /><path fill="lime" d="M500.3333 477.8333 L499 475.1667 L496.5 476.3333 L492.6667 478.8333 L492.1667 479.1667 L488.6667 481.8333 L490.5 484.1667 L494.3333 481.3333 L493.1667 480.1667 L493.8333 481.6667 L497.6667 479.1667 Z" stroke="none"

diff --git a/test-references/org/apache/batik/transcoder/wmf/testChart.svg b/test-references/org/apache/batik/transcoder/wmf/testChart.svg
index 6a27fea..6cbc8e2 100755
--- a/test-references/org/apache/batik/transcoder/wmf/testChart.svg
+++ b/test-references/org/apache/batik/transcoder/wmf/testChart.svg
@@ -66,29 +66,29 @@
       /><rect fill="none" width="451.9937" x="549.2787" height="156.6992" y="580.989"

       /><rect fill="none" width="454.3748" x="549.2787" height="154.3181" y="174.7654"

       /><rect fill="none" width="454.3748" x="47.2441" height="153.1086" y="178.3181"

-      /><text x="33.0315" font-size="63" y="84.1701" text-decoration="underline" stroke="none" font-weight="bold"

+      /><text font-size="63" x="33.0315" y="84.1701" text-decoration="underline" stroke="none" font-weight="bold" xml:space="preserve"

       >Metafile Companion Test Chart</text

     ></g

     ><g font-size="26" stroke-linecap="butt" transform="translate(70.1858,185.4992)" fill="white" stroke-linejoin="round" stroke="white" font-weight="bold" stroke-width="1.5118"

     ><rect width="100" x="0" height="25" y="-19" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="70.1858" y="185.4992" stroke="none"

+    ><text xml:space="preserve" x="70.1858" y="185.4992" stroke="none"

       >Objects</text

       ><rect x="0" y="-19" transform="translate(573.4677,185.4992)" fill="white" width="86" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="573.4677" y="185.4992" stroke="none"

+    ><text xml:space="preserve" x="573.4677" y="185.4992" stroke="none"

       >Colors</text

       ><rect x="-1" y="-19" transform="translate(573.4677,591.7606)" fill="white" width="130" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="573.4677" y="591.7606" stroke="none"

+    ><text xml:space="preserve" x="573.4677" y="591.7606" stroke="none"

       >Advanced</text

       ><rect x="1" y="-19" transform="translate(72.7559,591.6094)" fill="white" width="54" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="72.7559" y="591.6094" stroke="none"

+    ><text xml:space="preserve" x="72.7559" y="591.6094" stroke="none"

       >Fills</text

       ><line fill="none" x1="70.1102" x2="112.8945" y1="278.9291" y2="230.8535" stroke-width="0.7559"

       /><rect x="200.8063" y="235.011" fill="none" width="42.1417" height="39.7607" stroke-width="0.7559"

@@ -98,14 +98,14 @@
     ><rect width="88" x="2" height="20" y="-19" stroke="none"

     /></g

     ><g font-size="26" transform="matrix(0.9397,-0.342,0.342,0.9397,-216.0685,358.3464)" stroke-linejoin="round" stroke-linecap="butt"

-    ><text x="945.7512" y="662.0977" stroke="none"

+    ><text xml:space="preserve" x="945.7512" y="662.0977" stroke="none"

       >Rotated</text

     ></g

     ><g font-size="26" stroke-linecap="butt" transform="translate(433.1717,263.3575)" fill="white" stroke-linejoin="round" stroke="white" stroke-width="0.7559"

     ><rect width="51" x="0" height="20" y="-19" stroke="none"

     /></g

     ><g font-size="26" stroke-width="0.7559" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="433.1717" y="263.3575" stroke="none"

+    ><text xml:space="preserve" x="433.1717" y="263.3575" stroke="none"

       >Text</text

       ><path fill="silver" stroke-width="0.0378" d="M792.6047 679.7858 L830.4 625.3607 L866.6835 679.7858 ZM806.3622 673.5874 L829.6441 638.9669 L852.6236 673.5874 ZM818.3055 665.5748 L828.8882 649.852 L839.3197 665.5748 Z" fill-rule="evenodd" stroke="none"

       /><path fill="none" d="M792.6047 679.7858 L830.4 625.3607 L866.6835 679.7858 Z" stroke-width="0.0378"

@@ -163,49 +163,49 @@
     ><rect width="70" x="1" height="20" y="-19" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="74.1165" y="386.5701" stroke="none"

+    ><text xml:space="preserve" x="74.1165" y="386.5701" stroke="none"

       >Lines</text

       ><rect fill="none" width="451.9937" x="549.2787" height="156.6614" y="376.7055"

       /><rect x="1" y="-19" transform="translate(574.8284,387.9307)" fill="white" width="73" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="574.8284" y="387.9307" stroke="none"

+    ><text xml:space="preserve" x="574.8284" y="387.9307" stroke="none"

       >Fonts</text

       ><rect x="1" y="-19" transform="translate(820.0441,434.3433)" fill="white" width="59" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-weight="bold" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="820.0441" y="434.3433" stroke="none"

+    ><text xml:space="preserve" x="820.0441" y="434.3433" stroke="none"

       >Bold</text

     ></g

     ><g font-size="26" stroke-linecap="butt" transform="translate(822.6142,499.3512)" fill="white" font-family="&apos;Courier New&apos;" stroke-linejoin="round" stroke="white" stroke-width="1.5118"

     ><rect width="138" x="1" height="18" y="-17" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-family="&apos;Courier New&apos;" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="822.6142" y="499.3512" text-decoration="underline" stroke="none"

+    ><text xml:space="preserve" x="822.6142" y="499.3512" text-decoration="underline" stroke="none"

       >Underline</text

     ></g

     ><g font-size="26" stroke-linecap="butt" transform="translate(821.2535,465.4866)" fill="white" font-family="&apos;Times New Roman&apos;" stroke-linejoin="round" font-style="italic" stroke="white" stroke-width="1.5118"

     ><rect width="58" x="-1" height="20" y="-19" stroke="none"

     /></g

     ><g font-size="26" stroke-linecap="butt" font-family="&apos;Times New Roman&apos;" stroke-linejoin="round" font-style="italic" stroke-width="1.5118"

-    ><text x="821.2535" y="465.4866" stroke="none"

+    ><text xml:space="preserve" x="821.2535" y="465.4866" stroke="none"

       >Italic</text

     ></g

     ><g font-size="26" stroke-linecap="butt" transform="translate(574.6772,433.1339)" fill="white" stroke-linejoin="round" stroke="white" stroke-width="1.5118"

     ><rect width="52" x="-1" height="20" y="-19" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="574.6772" y="433.1339" stroke="none"

+    ><text xml:space="preserve" x="574.6772" y="433.1339" stroke="none"

       >Arial</text

       ><rect x="0" y="-19" transform="translate(573.3165,465.4866)" fill="white" width="203" height="20" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-family="&apos;Times New Roman&apos;" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="573.3165" y="465.4866" stroke="none"

+    ><text xml:space="preserve" x="573.3165" y="465.4866" stroke="none"

       >Times New Roman</text

       ><rect x="1" y="-17" transform="translate(574.6772,499.3512)" fill="white" width="170" height="18" stroke="none"

     /></g

     ><g font-size="26" stroke-width="1.5118" font-family="&apos;Courier New&apos;" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="574.6772" y="499.3512" stroke="none"

+    ><text xml:space="preserve" x="574.6772" y="499.3512" stroke="none"

       >Courier New</text

       ><rect x="579.9685" y="628.2331" fill="url(#pattern9)" width="45.6945" height="45.6567" stroke="none" stroke-width="0.0378"

       /><rect x="579.9685" y="628.2331" fill="none" width="45.6945" height="45.6567" stroke-width="0.0378"

@@ -215,27 +215,27 @@
       /><rect x="656.7685" y="634.1292" fill="none" width="48.0378" height="45.6945" stroke-width="0.0378"

       /><rect x="714.6331" y="634.1292" fill="url(#pattern10)" width="44.485" height="45.6945" stroke="none" stroke-width="0.0378"

       /><rect x="714.6331" y="634.1292" fill="none" width="44.485" height="45.6945" stroke-width="0.0378"

-      /><text font-size="15" x="933.7166" y="721.9653" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      /><text font-size="15" x="933.7166" y="721.9653" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Text</text

-      ><text font-size="15" x="921.7976" y="705.1843" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="921.7976" y="705.1843" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Rotated</text

-      ><text font-size="15" x="565.9843" y="705.9401" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="565.9843" y="705.9401" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Background</text

-      ><text font-size="15" x="585.1843" y="722.7213" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="585.1843" y="722.7213" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Color</text

-      ><text font-size="15" x="801.6756" y="706.3937" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="801.6756" y="706.3937" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Complex</text

-      ><text font-size="15" x="807.1181" y="723.1748" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="807.1181" y="723.1748" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Polygon</text

-      ><text font-size="15" x="664.8567" y="705.9401" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="664.8567" y="705.9401" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Transparency</text

-      ><text font-size="15" x="98.4945" y="502.2236" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="98.4945" y="502.2236" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Patterns</text

-      ><text font-size="15" x="248.2772" y="503.4331" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="248.2772" y="503.4331" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Thickness</text

-      ><text font-size="15" x="345.9126" y="725.7071" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="345.9126" y="725.7071" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Bitmap Fill Patterns</text

-      ><text font-size="15" x="130.6882" y="725.4047" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378"

+      ><text font-size="15" x="130.6882" y="725.4047" font-family="&apos;Times New Roman&apos;" stroke="none" stroke-width="0.0378" xml:space="preserve"

       >Basic Fill Patterns</text

     ></g

     ><g font-size="15" stroke-linecap="butt" fill="url(#pattern11)" font-family="&apos;Times New Roman&apos;" stroke-linejoin="round" stroke="url(#pattern11)" stroke-width="0.0378"

diff --git a/test-references/org/apache/batik/transcoder/wmf/textGreek.svg b/test-references/org/apache/batik/transcoder/wmf/textGreek.svg
index cdad35b..1a45463 100755
--- a/test-references/org/apache/batik/transcoder/wmf/textGreek.svg
+++ b/test-references/org/apache/batik/transcoder/wmf/textGreek.svg
@@ -8,7 +8,7 @@
     ><rect width="960" x="0" height="720" y="0" stroke="none"

     /></g

     ><g font-size="32" stroke-width="0.1667" font-family="&apos;Courier New&apos;" stroke-linecap="butt" stroke-linejoin="round"

-    ><text x="224" y="248" stroke="none"

+    ><text xml:space="preserve" x="224" y="248" stroke="none"

       >α</text

     ></g

   ></g