summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-06-24 20:09:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-06-24 20:09:50 +0300
commit6432012822e9c153fb288fe10c17a16d0b14a347 (patch)
treea3e14e93859f5ef5ed911df418202374a35ef95a
parent663a045a164f8973d4f66e2d8e45b495eb0519e6 (diff)
fix for rare crash
-rw-r--r--libs/mTextControl/src/FormattedTextDraw.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp
index 58023f93fb..de93cef046 100644
--- a/libs/mTextControl/src/FormattedTextDraw.cpp
+++ b/libs/mTextControl/src/FormattedTextDraw.cpp
@@ -196,6 +196,13 @@ HRESULT CFormattedTextDraw::Create()
HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *Height)
{
+ if (hdcDraw == 0)
+ return S_FALSE;
+
+ int iCaps = GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
+ if (iCaps == 0)
+ return S_FALSE;
+
LOGFONT lf;
GetObject(GetCurrentObject((HDC)hdcDraw, OBJ_FONT), sizeof(lf), &lf);
@@ -210,7 +217,7 @@ HRESULT CFormattedTextDraw::get_NaturalSize(void *hdcDraw, long *Width, long *He
cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE;
cf.crTextColor = GetTextColor((HDC)hdcDraw);
cf.bCharSet = lf.lfCharSet;
- cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps((HDC)hdcDraw, LOGPIXELSY);
+ cf.yHeight = 1440 * abs(lf.lfHeight) / iCaps;
wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE);
if (!m_spTextServices)