Author: khornicek
Date: Wed Oct 12 23:07:22 2011
New Revision: 54103
URL:
http://svn.reactos.org/svn/reactos?rev=54103&view=rev
Log:
[GDI32]
Partial winesync to reduce code duplication and fix a crash in gdi32 font winetest.
Modified:
trunk/reactos/dll/win32/gdi32/objects/font.c
Modified: trunk/reactos/dll/win32/gdi32/objects/font.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/gdi32/objects/fo…
==============================================================================
--- trunk/reactos/dll/win32/gdi32/objects/font.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/gdi32/objects/font.c [iso-8859-1] Wed Oct 12 23:07:22 2011
@@ -127,6 +127,50 @@
return strW;
}
+static LPSTR FONT_GetCharsByRangeA(HDC hdc, UINT firstChar, UINT lastChar, PINT
pByteLen)
+{
+ INT i, count = lastChar - firstChar + 1;
+ UINT c;
+ LPSTR str;
+
+ if (count <= 0)
+ return NULL;
+
+ switch (GdiGetCodePage(hdc))
+ {
+ case 932:
+ case 936:
+ case 949:
+ case 950:
+ case 1361:
+ if (lastChar > 0xffff)
+ return NULL;
+ if ((firstChar ^ lastChar) > 0xff)
+ return NULL;
+ break;
+ default:
+ if (lastChar > 0xff)
+ return NULL;
+ break;
+ }
+
+ str = HeapAlloc(GetProcessHeap(), 0, count * 2 + 1);
+ if (str == NULL)
+ return NULL;
+
+ for(i = 0, c = firstChar; c <= lastChar; i++, c++)
+ {
+ if (c > 0xff)
+ str[i++] = (BYTE)(c >> 8);
+ str[i] = (BYTE)c;
+ }
+ str[i] = '\0';
+
+ *pByteLen = i;
+
+ return str;
+}
+
VOID FASTCALL
NewTextMetricW2A(NEWTEXTMETRICA *tma, NEWTEXTMETRICW *tmw)
{
@@ -627,21 +671,16 @@
LPINT lpBuffer
)
{
- INT i, wlen, count = (INT)(iLastChar - iFirstChar + 1);
+ INT wlen, count = 0;
LPSTR str;
LPWSTR wstr;
BOOL ret = TRUE;
DPRINT("GetCharWidthsA\n");
- if(count <= 0) return FALSE;
-
- str = HeapAlloc(GetProcessHeap(), 0, count+1);
+
+ str = FONT_GetCharsByRangeA(hdc, iFirstChar, iLastChar, &count);
if (!str)
return FALSE;
-
- for(i = 0; i < count; i++)
- str[i] = (BYTE)(iFirstChar + i);
- str[i] = '\0';
wstr = FONT_mbtowc(hdc, str, count+1, &wlen, NULL);
if (!wstr)
@@ -675,20 +714,16 @@
LPINT lpBuffer
)
{
- INT i, wlen, count = (INT)(iLastChar - iFirstChar + 1);
+ INT wlen, count = 0;
LPSTR str;
LPWSTR wstr;
BOOL ret = TRUE;
DPRINT("GetCharWidths32A\n");
- if(count <= 0) return FALSE;
-
- str = HeapAlloc(GetProcessHeap(), 0, count+1);
+
+ str = FONT_GetCharsByRangeA(hdc, iFirstChar, iLastChar, &count);
if (!str)
return FALSE;
- for(i = 0; i < count; i++)
- str[i] = (BYTE)(iFirstChar + i);
- str[i] = '\0';
wstr = FONT_mbtowc(hdc, str, count+1, &wlen, NULL);
if (!wstr)
@@ -722,20 +757,16 @@
PFLOAT pxBuffer
)
{
- INT i, wlen, count = (INT)(iLastChar - iFirstChar + 1);
+ INT wlen, count = 0;
LPSTR str;
LPWSTR wstr;
BOOL ret = TRUE;
DPRINT("GetCharWidthsFloatA\n");
- if(count <= 0) return FALSE;
-
- str = HeapAlloc(GetProcessHeap(), 0, count+1);
+
+ str = FONT_GetCharsByRangeA(hdc, iFirstChar, iLastChar, &count);
if (!str)
return FALSE;
- for(i = 0; i < count; i++)
- str[i] = (BYTE)(iFirstChar + i);
- str[i] = '\0';
wstr = FONT_mbtowc(hdc, str, count+1, &wlen, NULL);
if (!wstr)
@@ -758,25 +789,21 @@
APIENTRY
GetCharABCWidthsA(
HDC hdc,
- UINT uFirstChar,
- UINT uLastChar,
+ UINT iFirstChar,
+ UINT iLastChar,
LPABC lpabc
)
{
- INT i, wlen, count = (INT)(uLastChar - uFirstChar + 1);
+ INT wlen, count = 0;
LPSTR str;
LPWSTR wstr;
BOOL ret = TRUE;
DPRINT("GetCharABCWidthsA\n");
- if(count <= 0) return FALSE;
-
- str = HeapAlloc(GetProcessHeap(), 0, count+1);
+
+ str = FONT_GetCharsByRangeA(hdc, iFirstChar, iLastChar, &count);
if (!str)
return FALSE;
- for(i = 0; i < count; i++)
- str[i] = (BYTE)(uFirstChar + i);
- str[i] = '\0';
wstr = FONT_mbtowc(hdc, str, count+1, &wlen, NULL);
if (!wstr)
@@ -810,21 +837,16 @@
LPABCFLOAT lpABCF
)
{
- INT i, wlen, count = (INT)(iLastChar - iFirstChar + 1);
+ INT wlen, count = 0;
LPSTR str;
LPWSTR wstr;
BOOL ret = TRUE;
DPRINT("GetCharABCWidthsFloatA\n");
- if (count <= 0) return FALSE;
-
- str = HeapAlloc(GetProcessHeap(), 0, count+1);
+
+ str = FONT_GetCharsByRangeA(hdc, iFirstChar, iLastChar, &count);
if (!str)
return FALSE;
-
- for(i = 0; i < count; i++)
- str[i] = (BYTE)(iFirstChar + i);
- str[i] = '\0';
wstr = FONT_mbtowc( hdc, str, count+1, &wlen, NULL );
if (!wstr)