Convert GetCharWidth to unicode

Dmitry Timoshkov dmitry at baikal.ru
Mon Oct 29 05:51:31 CST 2001


Hello.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Convert GetCharWidth to unicode.

diff -u cvs/wine/graphics/x11drv/xfont.c wine/graphics/x11drv/xfont.c
--- cvs/wine/graphics/x11drv/xfont.c	Wed Oct 24 15:27:33 2001
+++ wine/graphics/x11drv/xfont.c	Mon Oct 29 16:59:50 2001
@@ -3334,10 +3334,15 @@
 
 	    for (i = firstChar; i <= lastChar; i++)
 	    {
-		if (i >= pfo->fs->min_char_or_byte2 && 
-		    i <= pfo->fs->max_char_or_byte2)
+		WCHAR wch = i;
+		BYTE ch;
+		UINT ch_f; /* character code in the font encoding */
+		WideCharToMultiByte( pfo->fi->codepage, 0, &wch, 1, &ch, 1, NULL, NULL );
+		ch_f = ch;
+		if (ch_f >= pfo->fs->min_char_or_byte2 && 
+		    ch_f <= pfo->fs->max_char_or_byte2)
 		{
-		    cs = &pfo->fs->per_char[(i - pfo->fs->min_char_or_byte2)]; 
+		    cs = &pfo->fs->per_char[(ch_f - pfo->fs->min_char_or_byte2)]; 
 		    if (CI_NONEXISTCHAR(cs)) cs = def; 
   		} else cs = def;
 		if(pfo->lpX11Trans)
diff -u cvs/wine/objects/font.c wine/objects/font.c
--- cvs/wine/objects/font.c	Mon Oct 29 16:01:45 2001
+++ wine/objects/font.c	Mon Oct 29 16:59:50 2001
@@ -1507,10 +1507,10 @@
 
 
 /***********************************************************************
- *           GetCharWidthA      (GDI32.@)
- *           GetCharWidth32A    (GDI32.@)
+ *           GetCharWidthW      (GDI32.@)
+ *           GetCharWidth32W    (GDI32.@)
  */
-BOOL WINAPI GetCharWidth32A( HDC hdc, UINT firstChar, UINT lastChar,
+BOOL WINAPI GetCharWidth32W( HDC hdc, UINT firstChar, UINT lastChar,
                                LPINT buffer )
 {
     UINT i, extra;
@@ -1538,13 +1538,39 @@
 
 
 /***********************************************************************
- *           GetCharWidthW      (GDI32.@)
- *           GetCharWidth32W    (GDI32.@)
+ *           GetCharWidthA      (GDI32.@)
+ *           GetCharWidth32A    (GDI32.@)
  */
-BOOL WINAPI GetCharWidth32W( HDC hdc, UINT firstChar, UINT lastChar,
+BOOL WINAPI GetCharWidth32A( HDC hdc, UINT firstChar, UINT lastChar,
                                LPINT buffer )
 {
-    return GetCharWidth32A( hdc, firstChar, lastChar, buffer );
+    INT i, wlen, count = (INT)(lastChar - firstChar + 1);
+    LPSTR str;
+    LPWSTR wstr;
+    BOOL ret = TRUE;
+
+    if(count <= 0) return FALSE;
+    
+    str = HeapAlloc(GetProcessHeap(), 0, count);
+    for(i = 0; i < count; i++)
+	str[i] = (BYTE)(firstChar + i);
+
+    wstr = FONT_mbtowc(hdc, str, count, &wlen, NULL);
+
+    for(i = 0; i < wlen; i++)
+    {
+	if(!GetCharWidth32W(hdc, wstr[i], wstr[i], buffer))
+	{
+	    ret = FALSE;
+	    break;
+	}
+	buffer++;
+    }
+
+    HeapFree(GetProcessHeap(), 0, str);
+    HeapFree(GetProcessHeap(), 0, wstr);
+
+    return ret;
 }
 
 






More information about the wine-patches mailing list