[4/4] gdi32: Move common code into helper function.

Kusanagi Kouichi slash at ac.auone-net.jp
Wed Jan 26 10:09:12 CST 2011


Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
---
 dlls/gdi32/font.c |   38 +++++++++++---------------------------
 1 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index d8cade7..bba5e6d 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -1553,11 +1553,12 @@ UINT WINAPI GetOutlineTextMetricsW(
     return ret;
 }
 
-static LPSTR FONT_GetCharsByRangeA(HDC hdc, UINT firstChar, UINT lastChar, PINT pByteLen)
+static LPWSTR FONT_GetCharsByRangeA(HDC hdc, UINT firstChar, UINT lastChar, PINT pLen)
 {
     INT i, count = lastChar - firstChar + 1;
     UINT c;
     LPSTR str;
+    LPWSTR wstr;
 
     if (count <= 0)
         return NULL;
@@ -1578,7 +1579,7 @@ static LPSTR FONT_GetCharsByRangeA(HDC hdc, UINT firstChar, UINT lastChar, PINT
         break;
     }
 
-    str = HeapAlloc(GetProcessHeap(), 0, count * 2 + 1);
+    str = HeapAlloc(GetProcessHeap(), 0, count * 2);
     if (str == NULL)
         return NULL;
 
@@ -1588,11 +1589,11 @@ static LPSTR FONT_GetCharsByRangeA(HDC hdc, UINT firstChar, UINT lastChar, PINT
             str[i++] = (BYTE)(c >> 8);
         str[i] = (BYTE)c;
     }
-    str[i] = '\0';
 
-    *pByteLen = i;
+    wstr = FONT_mbtowc(hdc, str, i, pLen, NULL);
+    HeapFree(GetProcessHeap(), 0, str);
 
-    return str;
+    return wstr;
 }
 
 /***********************************************************************
@@ -1632,16 +1633,13 @@ BOOL WINAPI GetCharWidth32A( HDC hdc, UINT firstChar, UINT lastChar,
                                LPINT buffer )
 {
     INT i, wlen;
-    LPSTR str;
     LPWSTR wstr;
     BOOL ret = TRUE;
 
-    str = FONT_GetCharsByRangeA(hdc, firstChar, lastChar, &i);
-    if(str == NULL)
+    wstr = FONT_GetCharsByRangeA(hdc, firstChar, lastChar, &wlen);
+    if (wstr == NULL)
         return FALSE;
 
-    wstr = FONT_mbtowc(hdc, str, i, &wlen, NULL);
-
     for(i = 0; i < wlen; i++)
     {
 	if(!GetCharWidth32W(hdc, wstr[i], wstr[i], buffer))
@@ -1652,7 +1650,6 @@ BOOL WINAPI GetCharWidth32A( HDC hdc, UINT firstChar, UINT lastChar,
 	buffer++;
     }
 
-    HeapFree(GetProcessHeap(), 0, str);
     HeapFree(GetProcessHeap(), 0, wstr);
 
     return ret;
@@ -2336,20 +2333,12 @@ BOOL WINAPI GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar,
                                   LPABC abc )
 {
     INT i, wlen;
-    LPSTR str;
     LPWSTR wstr;
     BOOL ret = TRUE;
 
-    str = FONT_GetCharsByRangeA(hdc, firstChar, lastChar, &i);
-    if (str == NULL)
-        return FALSE;
-
-    wstr = FONT_mbtowc(hdc, str, i, &wlen, NULL);
+    wstr = FONT_GetCharsByRangeA(hdc, firstChar, lastChar, &wlen);
     if (wstr == NULL)
-    {
-        HeapFree(GetProcessHeap(), 0, str);
         return FALSE;
-    }
 
     for(i = 0; i < wlen; i++)
     {
@@ -2361,7 +2350,6 @@ BOOL WINAPI GetCharABCWidthsA(HDC hdc, UINT firstChar, UINT lastChar,
 	abc++;
     }
 
-    HeapFree(GetProcessHeap(), 0, str);
     HeapFree(GetProcessHeap(), 0, wstr);
 
     return ret;
@@ -3022,16 +3010,13 @@ GetCharacterPlacementW(
 BOOL WINAPI GetCharABCWidthsFloatA( HDC hdc, UINT first, UINT last, LPABCFLOAT abcf )
 {
     INT i, wlen;
-    LPSTR str;
     LPWSTR wstr;
     BOOL ret = TRUE;
 
-    str = FONT_GetCharsByRangeA(hdc, first, last, &i);
-    if (str == NULL)
+    wstr = FONT_GetCharsByRangeA(hdc, first, last, &wlen);
+    if (wstr == NULL)
         return FALSE;
 
-    wstr = FONT_mbtowc( hdc, str, i, &wlen, NULL );
-
     for (i = 0; i < wlen; i++)
     {
         if (!GetCharABCWidthsFloatW( hdc, wstr[i], wstr[i], abcf ))
@@ -3042,7 +3027,6 @@ BOOL WINAPI GetCharABCWidthsFloatA( HDC hdc, UINT first, UINT last, LPABCFLOAT a
         abcf++;
     }
 
-    HeapFree( GetProcessHeap(), 0, str );
     HeapFree( GetProcessHeap(), 0, wstr );
 
     return ret;
-- 
1.7.2.3




More information about the wine-patches mailing list