diff --git a/src/renderer/win32/BUILD.bazel b/src/renderer/win32/BUILD.bazel index 4224a28ac..f664131c4 100644 --- a/src/renderer/win32/BUILD.bazel +++ b/src/renderer/win32/BUILD.bazel @@ -261,14 +261,15 @@ mozc_cc_library( name = "win32_image_util", srcs = ["win32_image_util.cc"], hdrs = ["win32_image_util.h"], - copts = copts_wtl(), tags = MOZC_TAGS.WIN_ONLY, target_compatible_with = ["@platforms//os:windows"], deps = [ "//base:coordinates", "//base:logging", "//base:util", - "//third_party/wtl", + "//bazel/win32:gdi32", + "//bazel/win32:user32", + "@com_microsoft_wil//:wil", ], ) diff --git a/src/renderer/win32/win32_image_util.cc b/src/renderer/win32/win32_image_util.cc index 6a09a0031..fc2d3bce9 100644 --- a/src/renderer/win32/win32_image_util.cc +++ b/src/renderer/win32/win32_image_util.cc @@ -29,13 +29,8 @@ #include "renderer/win32/win32_image_util.h" -// clang-format off -#include -#include -#include -#include -#include -// clang-format on +#include +#include #include #include @@ -44,6 +39,7 @@ #include #include +#include "base/coordinates.h" #include "base/logging.h" #include "base/util.h" @@ -57,12 +53,6 @@ using ::mozc::renderer::win32::internal::SafeFrameBuffer; using ::mozc::renderer::win32::internal::SubdivisionalPixel; using ::mozc::renderer::win32::internal::TextLabel; -using ::WTL::CBitmap; -using ::WTL::CBitmapHandle; -using ::WTL::CDC; -using ::WTL::CFont; -using ::WTL::CFontHandle; - Rect GetBalloonBoundingRect( double left, double top, double width, double height, double balloon_tail_height, double balloon_tail_width, @@ -418,21 +408,20 @@ std::vector> Get1bitGlyph( bitmap_info.color_palette[1] = kForegroundColor; // white uint8_t *buffer = nullptr; - CBitmap dib; - dib.CreateDIBSection( + wil::unique_hbitmap dib(::CreateDIBSection( nullptr, reinterpret_cast(&bitmap_info), - DIB_RGB_COLORS, reinterpret_cast(&buffer), nullptr, 0); + DIB_RGB_COLORS, reinterpret_cast(&buffer), nullptr, 0)); - CDC dc; - dc.CreateCompatibleDC(nullptr); - CBitmapHandle old_bitmap = dc.SelectBitmap(dib); + wil::unique_hdc dc(::CreateCompatibleDC(nullptr)); + wil::unique_select_object old_bitmap(wil::SelectObject(dc.get(), dib.get())); std::wstring wide_fontname; Util::Utf8ToWide(fontname, &wide_fontname); LOGFONT logfont = {}; logfont.lfWeight = FW_NORMAL; logfont.lfCharSet = DEFAULT_CHARSET; - logfont.lfHeight = GetHeightFromDeciPoint(font_point * 10 * kDivision, dc); + logfont.lfHeight = GetHeightFromDeciPoint(font_point * 10 * kDivision, + dc.get()); logfont.lfQuality = NONANTIALIASED_QUALITY; const errno_t error = wcscpy_s(logfont.lfFaceName, wide_fontname.c_str()); if (error != 0) { @@ -440,24 +429,22 @@ std::vector> Get1bitGlyph( return pixels; } - CFont font_handle; - font_handle.CreateFontIndirectW(&logfont); - const CFontHandle old_font = dc.SelectFont(font_handle); - const CPoint lefttop( - static_cast(floor((left - bounding_rect.Left()) * kDivision)), - static_cast(floor((top - bounding_rect.Top()) * kDivision))); - const CSize size(static_cast(ceil(width * kDivision)), - static_cast(ceil(height * kDivision))); - - CRect rect(lefttop, size); - dc.SetBkMode(TRANSPARENT); - dc.SetTextColor(RGB(255, 255, 255)); + wil::unique_hfont font_handle(::CreateFontIndirectW(&logfont)); + wil::unique_select_object old_font( + wil::SelectObject(dc.get(), font_handle.get())); + const int rect_left = + static_cast(floor((left - bounding_rect.Left()) * kDivision)); + const int rect_top = + static_cast(floor((top - bounding_rect.Top()) * kDivision)); + RECT rect = {rect_left, rect_top, + rect_left + static_cast(ceil(width * kDivision)), + rect_top + static_cast(ceil(height * kDivision))}; + ::SetBkMode(dc.get(), TRANSPARENT); + ::SetTextColor(dc.get(), RGB(255, 255, 255)); std::wstring wide_text; Util::Utf8ToWide(text, &wide_text); - dc.DrawTextW(wide_text.c_str(), wide_text.size(), &rect, - DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CENTER); - dc.SelectFont(old_font); - dc.SelectBitmap(old_bitmap); + ::DrawTextW(dc.get(), wide_text.c_str(), wide_text.size(), &rect, + DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CENTER); ::GdiFlush(); // DIB section requires 32-bit alignment for each line. @@ -643,9 +630,9 @@ HBITMAP BalloonImage::CreateInternal(const BalloonImageInfo &info, bitmap_info.bmiHeader.biCompression = BI_RGB; bitmap_info.bmiHeader.biSizeImage = 0; PBGRA *buffer = nullptr; - CBitmap dib; - dib.CreateDIBSection(nullptr, &bitmap_info, DIB_RGB_COLORS, - reinterpret_cast(&buffer), nullptr, 0); + wil::unique_hbitmap dib( + ::CreateDIBSection(nullptr, &bitmap_info, DIB_RGB_COLORS, + reinterpret_cast(&buffer), nullptr, 0)); struct Accessor { public: @@ -735,7 +722,7 @@ HBITMAP BalloonImage::CreateInternal(const BalloonImageInfo &info, } } - return dib.Detach(); + return dib.release(); } namespace internal {