diff --git a/WeaselUI/WeaselPanel.cpp b/WeaselUI/WeaselPanel.cpp index 20a979c4e..08181f969 100644 --- a/WeaselUI/WeaselPanel.cpp +++ b/WeaselUI/WeaselPanel.cpp @@ -147,7 +147,7 @@ void WeaselPanel::Refresh() } } -void WeaselPanel::_InitFontRes(void) +void WeaselPanel::_InitFontRes(bool forced) { HMONITOR hMonitor = MonitorFromRect(m_inputPos, MONITOR_DEFAULTTONEAREST); UINT dpiX = 96, dpiY = 96; @@ -155,7 +155,7 @@ void WeaselPanel::_InitFontRes(void) GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY); // prepare d2d1 resources // if style changed, or dpi changed, or pDWR NULL, re-initialize directwrite resources - if ((pDWR == NULL) || (m_ostyle != m_style) || (dpiX != dpi)) + if (forced || (pDWR == NULL) || (m_ostyle != m_style) || (dpiX != dpi)) { pDWR.reset(); pDWR = std::make_shared< DirectWriteResources>(m_style, dpiX); @@ -581,7 +581,12 @@ bool WeaselPanel::_DrawCandidates(CDCHandle &dc, bool back) const std::vector &candidates(m_ctx.cinfo.candies); const std::vector &comments(m_ctx.cinfo.comments); const std::vector &labels(m_ctx.cinfo.labels); - + // prevent all text format nullptr + if(pDWR->pTextFormat.Get() == nullptr + && pDWR->pLabelTextFormat.Get() == nullptr + && pDWR->pCommentTextFormat.Get() == nullptr) { + _InitFontRes(true); + } ComPtr txtFormat = pDWR->pTextFormat; ComPtr labeltxtFormat = pDWR->pLabelTextFormat; ComPtr commenttxtFormat = pDWR->pCommentTextFormat; diff --git a/WeaselUI/WeaselPanel.h b/WeaselUI/WeaselPanel.h index 9ccf6c671..21a885626 100644 --- a/WeaselUI/WeaselPanel.h +++ b/WeaselUI/WeaselPanel.h @@ -56,7 +56,7 @@ class WeaselPanel : bool GetIsReposition(){ return m_istorepos; } private: - void _InitFontRes(void); + void _InitFontRes(bool forced = false); void _CaptureRect(CRect& rect); bool m_mouse_entry = false; void _CreateLayout();