Skip to content

Commit

Permalink
attempt to fix empty text issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxliang committed Sep 6, 2023
1 parent 9c9189c commit 26fb7e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ void WeaselPanel::Refresh()
}
}

void WeaselPanel::_InitFontRes(void)
void WeaselPanel::_InitFontRes(bool forced)
{
HMONITOR hMonitor = MonitorFromRect(m_inputPos, MONITOR_DEFAULTTONEAREST);
UINT dpiX = 96, dpiY = 96;
if (hMonitor)
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);
Expand Down Expand Up @@ -581,7 +581,12 @@ bool WeaselPanel::_DrawCandidates(CDCHandle &dc, bool back)
const std::vector<Text> &candidates(m_ctx.cinfo.candies);
const std::vector<Text> &comments(m_ctx.cinfo.comments);
const std::vector<Text> &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<IDWriteTextFormat1> txtFormat = pDWR->pTextFormat;
ComPtr<IDWriteTextFormat1> labeltxtFormat = pDWR->pLabelTextFormat;
ComPtr<IDWriteTextFormat1> commenttxtFormat = pDWR->pCommentTextFormat;
Expand Down
2 changes: 1 addition & 1 deletion WeaselUI/WeaselPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 26fb7e7

Please sign in to comment.