Fixes for i18n.

diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c
index 7cca796..a2e4965 100644
--- a/objects/enhmetafile.c
+++ b/objects/enhmetafile.c
@@ -193,7 +193,7 @@
     )
 {
      LPENHMETAHEADER emh = EMF_GetEnhMetaHeader(hmf);
-     INT first;
+     INT first, first_A;
  
      if(!emh) return FALSE;
      if(emh->nDescription == 0 || emh->offDescription == 0) {
@@ -208,12 +208,14 @@
      first = lstrlenW( (WCHAR *) ((char *) emh + emh->offDescription));
  
      lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription), size);
-     buf += first + 1;
+     first_A = lstrlenA( buf );
+     buf += first_A + 1;
      lstrcpynWtoA(buf, (WCHAR *) ((char *) emh + emh->offDescription+2*(first+1)),
- 		 size - first - 1);
+ 		 size - first_A - 1); /* i18n ready */
+     first_A += lstrlenA(buf) + 1;
  
      EMF_ReleaseEnhMetaHeader(hmf);
-     return min(size, emh->nDescription);
+     return min(size, first_A);
 }
 
 /*****************************************************************************
diff --git a/objects/font.c b/objects/font.c
index 27df7f4..d4bbce7 100644
--- a/objects/font.c
+++ b/objects/font.c
@@ -15,6 +15,7 @@
 #include "debugtools.h"
 #include "winerror.h"
 #include "dc.h"
+#include "winnls.h"
 
 DEFAULT_DEBUG_CHANNEL(font)
 DECLARE_DEBUG_CHANNEL(gdi)
@@ -869,15 +870,19 @@
 {
     LPWSTR p;
     BOOL ret;
+    UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
+    UINT wlen;
 
   /* str may not be 0 terminated so we can't use HEAP_strdupWtoA.
    * We allocate one more than we need so that lstrcpynWtoA can write a
    * trailing 0 if it wants.
    */
 
-    p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) );
-    lstrcpynAtoW(p, str, count+1);
-    ret = GetTextExtentPoint32W( hdc, p, count, size );
+    wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
+    p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) );
+    wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
+
+    ret = GetTextExtentPoint32W( hdc, p, wlen, size );
     HeapFree( GetProcessHeap(), 0, p );
     return ret;
 }
diff --git a/objects/text.c b/objects/text.c
index 1aa4428..fed2752 100644
--- a/objects/text.c
+++ b/objects/text.c
@@ -18,6 +18,7 @@
 #include "heap.h"
 #include "debugtools.h"
 #include "cache.h"
+#include "winnls.h"
 
 DEFAULT_DEBUG_CHANNEL(text);
 
@@ -381,12 +382,16 @@
                              const RECT *lprect, LPCSTR str, UINT count,
                              const INT *lpDx )
 {
-    /* str need not be \0 terminated but lstrcpynAtoW adds \0 so we allocate one
-       more byte */
-    LPWSTR p = HeapAlloc( GetProcessHeap(), 0, (count+1) * sizeof(WCHAR) );
+    LPWSTR p;
     INT ret;
-    lstrcpynAtoW( p, str, count+1 );
-    ret = ExtTextOutW( hdc, x, y, flags, lprect, p, count, lpDx );
+    UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
+    UINT wlen;
+
+    wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
+    p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) );
+    wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
+
+    ret = ExtTextOutW( hdc, x, y, flags, lprect, p, wlen, lpDx );
     HeapFree( GetProcessHeap(), 0, p );
     return ret;
 }
@@ -679,9 +684,14 @@
                               const INT *lpTabPos, INT nTabOrg )
 {
     LONG ret;
-    LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
-    lstrcpynWtoA( p, str, count + 1 );
-    ret = TabbedTextOutA( hdc, x, y, p, count, cTabStops,
+    LPSTR p;
+    INT acount;
+    UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
+
+    acount = WideCharToMultiByte(codepage,0,str,count,NULL,0,NULL,NULL);
+    p = HEAP_xalloc( GetProcessHeap(), 0, acount ); 
+    acount = WideCharToMultiByte(codepage,0,str,count,p,acount,NULL,NULL);
+    ret = TabbedTextOutA( hdc, x, y, p, acount, cTabStops,
                             lpTabPos, nTabOrg );
     HeapFree( GetProcessHeap(), 0, p );
     return ret;
@@ -721,9 +731,14 @@
                                      INT cTabStops, const INT *lpTabPos )
 {
     LONG ret;
-    LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, count + 1 );
-    lstrcpynWtoA( p, lpstr, count + 1 );
-    ret = GetTabbedTextExtentA( hdc, p, count, cTabStops, lpTabPos );
+    LPSTR p;
+    INT acount;
+    UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
+
+    acount = WideCharToMultiByte(codepage,0,lpstr,count,NULL,0,NULL,NULL);
+    p = HEAP_xalloc( GetProcessHeap(), 0, acount );
+    acount = WideCharToMultiByte(codepage,0,lpstr,count,p,acount,NULL,NULL);
+    ret = GetTabbedTextExtentA( hdc, p, acount, cTabStops, lpTabPos );
     HeapFree( GetProcessHeap(), 0, p );
     return ret;
 }