From 321623f2c7824f8a41beab0b78e6ecc5b53de141 Mon Sep 17 00:00:00 2001 From: berryzplus Date: Sat, 3 Jun 2023 02:17:42 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unittests/test-charcode.cpp | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unittests/test-charcode.cpp b/tests/unittests/test-charcode.cpp index 47f4512a7a..9249bcadf1 100644 --- a/tests/unittests/test-charcode.cpp +++ b/tests/unittests/test-charcode.cpp @@ -39,6 +39,12 @@ class CharWidthCache : public testing::Test { lf2 = LOGFONT(); lf2.lfCharSet = DEFAULT_CHARSET; std::wcscpy(lf2.lfFaceName, L"Meiryo"); + lf3 = LOGFONT(); + lf3.lfCharSet = DEFAULT_CHARSET; + std::wcscpy(lf3.lfFaceName, L"MS Gothic"); // UD デジタル 教科書体 N-B + lf3.lfPitchAndFamily = FIXED_PITCH; + lf3.lfHeight = 10; + lf3.lfWeight = FW_BOLD; dc = GetDC(nullptr); font = CreateFontIndirect(&lf1); @@ -53,6 +59,7 @@ class CharWidthCache : public testing::Test { LOGFONT lf1; LOGFONT lf2; + LOGFONT lf3; HDC dc; HFONT font; HFONT oldFont; @@ -158,6 +165,35 @@ TEST_F(CharWidthCache, CalcPxWidthByFont2) EXPECT_EQ(cache.CalcPxWidthByFont2(L"\xd83c\xdf38"), size.cx); } +TEST_F(CharWidthCache, CalcPxWidthByFont3) +{ + // フォントを作り直して設定する + SelectObject(dc, oldFont); + font = CreateFontIndirect(&lf3); + oldFont = static_cast(SelectObject(dc, font)); + + // 半角×2≠全角となることを確認する + SIZE size = {}; + GetTextExtentPoint32(dc, L"a", 1, &size); + EXPECT_EQ(6, size.cx); + GetTextExtentPoint32(dc, L"あ", 1, &size); + EXPECT_EQ(11, size.cx); + + // フォントを元に戻しておく + font = static_cast(SelectObject(dc, oldFont)); + DeleteObject(font); + + SelectCharWidthCache(CWM_FONT_EDIT, CWM_CACHE_LOCAL); + InitCharWidthCache(lf3); + CCharWidthCache& cache = GetCharWidthCache(); + + // 半角×2=全角となることを確認する + constexpr auto halfWidth = 6; + constexpr auto fullWidth = halfWidth * 2; + EXPECT_EQ(cache.CalcPxWidthByFont(L'a'), halfWidth); + EXPECT_EQ(cache.CalcPxWidthByFont(L'あ'), fullWidth); +} + TEST_F(CharWidthCache, FontNo) { // 文字幅キャッシュには半角と全角とで異なるフォントを指定することができる。