📄 font.c
字号:
{ "MS Sans Serif", FW_NORMAL, 20, 16, 4, 4, 0, 8, 16 },
{ "MS Sans Serif", FW_NORMAL, 24, 19, 5, 6, 0, 9, 20 },
{ "MS Sans Serif", FW_NORMAL, 29, 23, 6, 5, 0, 12, 25 },
{ "MS Sans Serif", FW_NORMAL, 37, 29, 8, 5, 0, 16, 32 },
{ "MS Serif", FW_NORMAL, 10, 8, 2, 2, 0, 5, 8 },
{ "MS Serif", FW_NORMAL, 11, 9, 2, 2, 0, 5, 9 },
{ "MS Serif", FW_NORMAL, 13, 11, 2, 2, 0, 5, 12 },
{ "MS Serif", FW_NORMAL, 16, 13, 3, 3, 0, 6, 16 },
{ "MS Serif", FW_NORMAL, 19, 15, 4, 3, 0, 8, 19 },
{ "MS Serif", FW_NORMAL, 21, 16, 5, 3, 0, 9, 23 },
{ "MS Serif", FW_NORMAL, 27, 21, 6, 3, 0, 12, 27 },
{ "MS Serif", FW_NORMAL, 35, 27, 8, 3, 0, 16, 34 },
{ "Courier", FW_NORMAL, 13, 11, 2, 0, 0, 8, 8 },
{ "Courier", FW_NORMAL, 16, 13, 3, 0, 0, 9, 9 },
{ "Courier", FW_NORMAL, 20, 16, 4, 0, 0, 12, 12 },
{ "System", FW_BOLD, 16, 13, 3, 3, 0, 7, 15 },
{ "Small Fonts", FW_NORMAL, 3, 2, 1, 0, 0, 1, 2 },
{ "Small Fonts", FW_NORMAL, 5, 4, 1, 1, 0, 3, 4 },
{ "Small Fonts", FW_NORMAL, 6, 5, 1, 1, 0, 3, 13 },
{ "Small Fonts", FW_NORMAL, 8, 7, 1, 1, 0, 4, 7 },
{ "Small Fonts", FW_NORMAL, 10, 8, 2, 2, 0, 4, 8 },
{ "Small Fonts", FW_NORMAL, 11, 9, 2, 2, 0, 5, 9 }
/* FIXME: add "Fixedsys", "Terminal" */
};
HDC hdc;
LOGFONT lf;
HFONT hfont, old_hfont;
TEXTMETRIC tm;
INT ret, i;
hdc = CreateCompatibleDC(0);
assert(hdc);
for (i = 0; i < sizeof(fd)/sizeof(fd[0]); i++)
{
memset(&lf, 0, sizeof(lf));
lf.lfHeight = fd[i].height;
strcpy(lf.lfFaceName, fd[i].face_name);
ret = EnumFontFamilies(hdc, fd[i].face_name, find_font_proc, (LPARAM)&lf);
if (ret)
{
trace("font %s height %d not found\n", fd[i].face_name, fd[i].height);
continue;
}
trace("found font %s, height %ld\n", lf.lfFaceName, lf.lfHeight);
hfont = create_font(lf.lfFaceName, &lf);
old_hfont = SelectObject(hdc, hfont);
ok(GetTextMetrics(hdc, &tm), "GetTextMetrics error %ld\n", GetLastError());
ok(tm.tmWeight == fd[i].weight, "%s(%d): tm.tmWeight %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmWeight, fd[i].weight);
ok(tm.tmHeight == fd[i].height, "%s(%d): tm.tmHeight %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmHeight, fd[i].height);
ok(tm.tmAscent == fd[i].ascent, "%s(%d): tm.tmAscent %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmAscent, fd[i].ascent);
ok(tm.tmDescent == fd[i].descent, "%s(%d): tm.tmDescent %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmDescent, fd[i].descent);
ok(tm.tmInternalLeading == fd[i].int_leading, "%s(%d): tm.tmInternalLeading %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmInternalLeading, fd[i].int_leading);
ok(tm.tmExternalLeading == fd[i].ext_leading, "%s(%d): tm.tmExternalLeading %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmExternalLeading, fd[i].ext_leading);
ok(tm.tmAveCharWidth == fd[i].ave_char_width, "%s(%d): tm.tmAveCharWidth %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmAveCharWidth, fd[i].ave_char_width);
ok(tm.tmMaxCharWidth == fd[i].max_char_width, "%s(%d): tm.tmMaxCharWidth %ld != %d\n", fd[i].face_name, fd[i].height, tm.tmMaxCharWidth, fd[i].max_char_width);
SelectObject(hdc, old_hfont);
DeleteObject(hfont);
}
DeleteDC(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);
}
static void test_GetCharABCWidthsW(void)
{
BOOL ret;
ABC abc[1];
typedef BOOL (WINAPI *fnGetCharABCWidthsW)(HDC hdc, UINT first, UINT last, LPABC abc);
fnGetCharABCWidthsW GetCharABCWidthsW = (fnGetCharABCWidthsW)GetProcAddress(LoadLibrary("gdi32"), "GetCharABCWidthsW");
if (!GetCharABCWidthsW) return;
ret = GetCharABCWidthsW(NULL, 'a', 'a', abc);
ok(!ret, "GetCharABCWidthsW should have returned FALSE\n");
}
static void test_text_extents(void)
{
static const WCHAR wt[] = {'O','n','e','\n','t','w','o',' ','3',0};
LPINT extents;
INT i, len, fit1, fit2;
LOGFONTA lf;
TEXTMETRICA tm;
HDC hdc;
HFONT hfont;
SIZE sz;
SIZE sz1, sz2;
memset(&lf, 0, sizeof(lf));
strcpy(lf.lfFaceName, "Arial");
lf.lfHeight = 20;
hfont = CreateFontIndirectA(&lf);
hdc = GetDC(0);
hfont = SelectObject(hdc, hfont);
GetTextMetricsA(hdc, &tm);
GetTextExtentPointA(hdc, "o", 1, &sz);
ok(sz.cy == tm.tmHeight, "cy %ld tmHeight %ld\n", sz.cy, tm.tmHeight);
len = lstrlenW(wt);
extents = HeapAlloc(GetProcessHeap(), 0, len * sizeof extents[0]);
memset(extents, 0, len * sizeof extents[0]);
extents[0] = 1; /* So that the increasing sequence test will fail
if the extents array is untouched. */
GetTextExtentExPointW(hdc, wt, len, 32767, &fit1, extents, &sz1);
GetTextExtentPointW(hdc, wt, len, &sz2);
ok(sz1.cx == sz2.cx && sz1.cy == sz2.cy,
"results from GetTextExtentExPointW and GetTextExtentPointW differ\n");
for (i = 1; i < len; ++i)
ok(extents[i-1] <= extents[i],
"GetTextExtentExPointW generated a non-increasing sequence of partial extents (at position %d)\n",
i);
ok(extents[len-1] == sz1.cx, "GetTextExtentExPointW extents and size don't match\n");
ok(0 <= fit1 && fit1 <= len, "GetTextExtentExPointW generated illegal value %d for fit\n", fit1);
ok(0 < fit1, "GetTextExtentExPointW says we can't even fit one letter in 32767 logical units\n");
GetTextExtentExPointW(hdc, wt, len, extents[2], &fit2, NULL, &sz2);
ok(sz1.cx == sz2.cx && sz1.cy == sz2.cy, "GetTextExtentExPointW returned different sizes for the same string\n");
ok(fit2 == 3, "GetTextExtentExPointW extents isn't consistent with fit\n");
GetTextExtentExPointW(hdc, wt, len, extents[2]-1, &fit2, NULL, &sz2);
ok(fit2 == 2, "GetTextExtentExPointW extents isn't consistent with fit\n");
GetTextExtentExPointW(hdc, wt, 2, 0, NULL, extents + 2, &sz2);
ok(extents[0] == extents[2] && extents[1] == extents[3],
"GetTextExtentExPointW with lpnFit == NULL returns incorrect results\n");
GetTextExtentExPointW(hdc, wt, 2, 0, NULL, NULL, &sz1);
ok(sz1.cx == sz2.cx && sz1.cy == sz2.cy,
"GetTextExtentExPointW with lpnFit and alpDx both NULL returns incorrect results\n");
HeapFree(GetProcessHeap(), 0, extents);
SelectObject(hdc, hfont);
DeleteObject(hfont);
ReleaseDC(NULL, hdc);
}
static void test_GetGlyphIndices()
{
HDC hdc;
HFONT hfont;
DWORD charcount;
LOGFONTA lf;
DWORD flags = 0;
WCHAR testtext[] = {'T','e','s','t',0xffff,0};
WORD glyphs[(sizeof(testtext)/2)-1];
TEXTMETRIC textm;
typedef BOOL (WINAPI *fnGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags);
fnGetGlyphIndicesW GetGlyphIndicesW = (fnGetGlyphIndicesW)GetProcAddress(LoadLibrary("gdi32"),
"GetGlyphIndicesW");
if (!GetGlyphIndicesW) {
trace("GetGlyphIndices not available on platform\n");
return;
}
memset(&lf, 0, sizeof(lf));
strcpy(lf.lfFaceName, "Symbol");
lf.lfHeight = 20;
hfont = CreateFontIndirectA(&lf);
hdc = GetDC(0);
ok(GetTextMetrics(hdc, &textm), "GetTextMetric failed\n");
flags |= GGI_MARK_NONEXISTING_GLYPHS;
charcount = GetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags);
ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %ld\n", charcount);
ok(glyphs[4] == 0x001f, "GetGlyphIndices should have returned a nonexistent char not %04x\n", glyphs[4]);
flags = 0;
charcount = GetGlyphIndicesW(hdc, testtext, (sizeof(testtext)/2)-1, glyphs, flags);
ok(charcount == 5, "GetGlyphIndices count of glyphs should = 5 not %ld\n", charcount);
ok(glyphs[4] == textm.tmDefaultChar, "GetGlyphIndices should have returned a %04x not %04x\n",
textm.tmDefaultChar, glyphs[4]);
}
START_TEST(font)
{
test_logfont();
test_bitmap_font();
test_bitmap_font_metrics();
test_GdiGetCharDimensions();
test_GetCharABCWidthsW();
test_text_extents();
test_GetGlyphIndices();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -