Implement and test GdiGetCharDimensions.
This commit is contained in:
parent
cd4e1e512f
commit
0ceb6b6f6b
|
@ -2517,3 +2517,43 @@ done:
|
|||
memset(fs, 0, sizeof(FONTSIGNATURE));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* GdiGetCharDimensions (GDI32.@)
|
||||
*
|
||||
* Gets the average width of the characters in the English alphabet.
|
||||
*
|
||||
* PARAMS
|
||||
* hdc [I] Handle to the device context to measure on.
|
||||
* lptm [O] Pointer to memory to store the text metrics into.
|
||||
* height [O] On exit, the maximum height of characters in the English alphabet.
|
||||
*
|
||||
* RETURNS
|
||||
* The average width of characters in the English alphabet.
|
||||
*
|
||||
* NOTES
|
||||
* This function is used by the dialog manager to get the size of a dialog
|
||||
* unit. It should also be used by other pieces of code that need to know
|
||||
* the size of a dialog unit in logical units without having access to the
|
||||
* window handle of the dialog.
|
||||
* Windows caches the font metrics from this function, but we don't and
|
||||
* there doesn't appear to be an immediate advantage to do so.
|
||||
*
|
||||
* SEE ALSO
|
||||
* GetTextExtentPointW, GetTextMetricsW, MapDialogRect.
|
||||
*/
|
||||
LONG WINAPI GdiGetCharDimensions(HDC hdc, LPTEXTMETRICW lptm, LONG *height)
|
||||
{
|
||||
SIZE sz;
|
||||
static const WCHAR alphabet[] = {
|
||||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
|
||||
'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H',
|
||||
'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0};
|
||||
|
||||
if(lptm && !GetTextMetricsW(hdc, lptm)) return 0;
|
||||
|
||||
if(!GetTextExtentPointW(hdc, alphabet, 52, &sz)) return 0;
|
||||
|
||||
if (height) *height = sz.cy;
|
||||
return (sz.cx / 26 + 1) / 2;
|
||||
}
|
||||
|
|
|
@ -155,6 +155,7 @@
|
|||
@ stub GdiDllInitialize
|
||||
@ stdcall GdiFlush()
|
||||
@ stdcall GdiGetBatchLimit()
|
||||
@ stdcall GdiGetCharDimensions(ptr ptr ptr)
|
||||
@ stub GdiGetLocalBitmap
|
||||
@ stub GdiGetLocalBrush
|
||||
@ stub GdiGetLocalDC
|
||||
|
|
|
@ -266,9 +266,45 @@ static void test_gdi_objects(void)
|
|||
ReleaseDC(NULL, hdc);
|
||||
}
|
||||
|
||||
static void test_GdiGetCharDimensions(void)
|
||||
{
|
||||
HDC hdc;
|
||||
TEXTMETRICW tm;
|
||||
LONG ret;
|
||||
SIZE size;
|
||||
LONG avgwidth, height;
|
||||
static const char szAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
typedef LONG (WINAPI *fnGdiGetCharDimensions)(HDC hdc, LPTEXTMETRICW lptm, LONG *height);
|
||||
fnGdiGetCharDimensions GdiGetCharDimensions = (fnGdiGetCharDimensions)GetProcAddress(LoadLibrary("gdi32"), "GdiGetCharDimensions");
|
||||
if (!GdiGetCharDimensions) return;
|
||||
|
||||
hdc = CreateCompatibleDC(NULL);
|
||||
|
||||
GetTextExtentPoint(hdc, szAlphabet, strlen(szAlphabet), &size);
|
||||
avgwidth = ((size.cx / 26) + 1) / 2;
|
||||
|
||||
ret = GdiGetCharDimensions(hdc, &tm, &height);
|
||||
ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
|
||||
ok(height == tm.tmHeight, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", tm.tmHeight, height);
|
||||
|
||||
ret = GdiGetCharDimensions(hdc, &tm, NULL);
|
||||
ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
|
||||
|
||||
ret = GdiGetCharDimensions(hdc, NULL, NULL);
|
||||
ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
|
||||
|
||||
height = 0;
|
||||
ret = GdiGetCharDimensions(hdc, NULL, &height);
|
||||
ok(ret == avgwidth, "GdiGetCharDimensions should have returned width of %ld instead of %ld\n", avgwidth, ret);
|
||||
ok(height == size.cy, "GdiGetCharDimensions should have set height to %ld instead of %ld\n", size.cy, height);
|
||||
|
||||
DeleteDC(hdc);
|
||||
}
|
||||
|
||||
START_TEST(gdiobj)
|
||||
{
|
||||
test_logfont();
|
||||
test_bitmap_font();
|
||||
test_gdi_objects();
|
||||
test_GdiGetCharDimensions();
|
||||
}
|
||||
|
|
|
@ -3335,6 +3335,7 @@ BOOL WINAPI GdiAlphaBlend(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNC
|
|||
BOOL WINAPI GdiComment(HDC,UINT,const BYTE *);
|
||||
DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *);
|
||||
BOOL WINAPI GdiFlush(void);
|
||||
LONG WINAPI GdiGetCharDimensions(HDC, LPTEXTMETRICW, LONG *);
|
||||
BOOL WINAPI GdiGradientFill(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG);
|
||||
BOOL WINAPI GdiIsMetaFileDC(HDC);
|
||||
BOOL WINAPI GdiIsMetaPrintDC(HDC);
|
||||
|
|
Loading…
Reference in New Issue