summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-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)