From ee2337c6bc391d0ab1d58123899920c6df0d2ef0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 30 Oct 2023 15:22:28 +0300 Subject: =?UTF-8?q?fixes=20#3616=20(NewStory:=20=D0=BD=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E=D1=82=20=D0=BD=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8=20=D1=86=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B2=D0=BE=D0=B5=D0=B3=D0=BE=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=20=D0=B8=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D0=B5=D1=81=D0=B5=D0=B4=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/mTextControl/src/FormattedTextDraw.cpp | 76 ++++++++++++++++------------- libs/mTextControl/src/FormattedTextDraw.h | 14 +++--- libs/mTextControl/src/services.cpp | 26 ++++------ 3 files changed, 58 insertions(+), 58 deletions(-) (limited to 'libs/mTextControl/src') diff --git a/libs/mTextControl/src/FormattedTextDraw.cpp b/libs/mTextControl/src/FormattedTextDraw.cpp index e89ab6ad1d..e093048160 100644 --- a/libs/mTextControl/src/FormattedTextDraw.cpp +++ b/libs/mTextControl/src/FormattedTextDraw.cpp @@ -156,6 +156,8 @@ HRESULT CFormattedTextDraw::putRTFText(char *newVal) if (!m_spTextServices) return S_FALSE; + m_bNative = true; + STREAMDATATEXT streamData = {}; streamData.isUnicode = false; streamData.ansi = newVal; @@ -176,23 +178,25 @@ HRESULT CFormattedTextDraw::putRTFText(char *newVal) HRESULT CFormattedTextDraw::Draw(HDC hdcDraw, RECT *prc) { - LOGFONT lf; - GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); - - LRESULT lResult; - CHARFORMAT cf; - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE | - (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) | - (lf.lfItalic ? CFM_ITALIC : 0) | - (lf.lfUnderline ? CFM_UNDERLINE : 0) | - (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); - cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; - cf.crTextColor = GetTextColor(hdcDraw); - cf.bCharSet = lf.lfCharSet; - cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps(hdcDraw, LOGPIXELSY); - wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); - m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + if (!m_bNative) { + LOGFONT lf; + GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); + + LRESULT lResult; + CHARFORMAT cf; + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE | + (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) | + (lf.lfItalic ? CFM_ITALIC : 0) | + (lf.lfUnderline ? CFM_UNDERLINE : 0) | + (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); + cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; + cf.crTextColor = GetTextColor(hdcDraw); + cf.bCharSet = lf.lfCharSet; + cf.yHeight = 1440 * abs(lf.lfHeight) / GetDeviceCaps(hdcDraw, LOGPIXELSY); + wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); + m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + } m_spTextServices->TxDraw( DVASPECT_CONTENT, // Draw Aspect @@ -220,27 +224,29 @@ HRESULT CFormattedTextDraw::get_NaturalSize(HDC hdcDraw, long *Width, long *Heig if (iCaps == 0) return S_FALSE; - LOGFONT lf; - GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); - - LRESULT lResult; - CHARFORMAT cf; - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE | - (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) | - (lf.lfItalic ? CFM_ITALIC : 0) | - (lf.lfUnderline ? CFM_UNDERLINE : 0) | - (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); - cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; - cf.crTextColor = GetTextColor(hdcDraw); - cf.bCharSet = lf.lfCharSet; - cf.yHeight = 1440 * abs(lf.lfHeight) / iCaps; - wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); - if (!m_spTextServices) return S_FALSE; - m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + if (!m_bNative) { + LOGFONT lf; + GetObject(GetCurrentObject(hdcDraw, OBJ_FONT), sizeof(lf), &lf); + + LRESULT lResult; + CHARFORMAT cf; + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_FACE/*|CFM_COLOR*/ | CFM_CHARSET | CFM_SIZE | + (lf.lfWeight >= FW_BOLD ? CFM_BOLD : 0) | + (lf.lfItalic ? CFM_ITALIC : 0) | + (lf.lfUnderline ? CFM_UNDERLINE : 0) | + (lf.lfStrikeOut ? CFM_STRIKEOUT : 0); + cf.dwEffects = CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE; + cf.crTextColor = GetTextColor(hdcDraw); + cf.bCharSet = lf.lfCharSet; + cf.yHeight = 1440 * abs(lf.lfHeight) / iCaps; + wcsncpy_s(cf.szFaceName, lf.lfFaceName, _TRUNCATE); + + m_spTextServices->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + } *Height = 1; diff --git a/libs/mTextControl/src/FormattedTextDraw.h b/libs/mTextControl/src/FormattedTextDraw.h index f9ff25f2b6..edfcac0d2f 100644 --- a/libs/mTextControl/src/FormattedTextDraw.h +++ b/libs/mTextControl/src/FormattedTextDraw.h @@ -17,17 +17,18 @@ class CFormattedTextDraw : public ITextHost, public MZeroedObject { HWND m_hwndParent; - RECT m_rcClient; // Client Rect - RECT m_rcViewInset; // view rect inset - SIZEL m_sizelExtent; // Extent array + RECT m_rcClient; // Client Rect + RECT m_rcViewInset; // view rect inset + SIZEL m_sizelExtent; // Extent array - int nPixelsPerInchX; // Pixels per logical inch along width - int nPixelsPerInchY; // Pixels per logical inch along height + int nPixelsPerInchX; // Pixels per logical inch along width + int nPixelsPerInchY; // Pixels per logical inch along height CHARFORMAT2W m_CF; PARAFORMAT2 m_PF; - uint32_t m_dwPropertyBits; // Property bits + uint32_t m_dwPropertyBits; // Property bits + bool m_bNative = false; // Doesn't generate RTF itself, uses external plain RTF ITextServices *m_spTextServices; ITextDocument *m_spTextDocument; @@ -45,6 +46,7 @@ public: __forceinline ITextServices *getTextService() { return m_spTextServices; }; __forceinline ITextDocument *getTextDocument() { return m_spTextDocument; }; + __forceinline bool isNative() const { return m_bNative; } __forceinline void setParentWnd(HWND hwnd, RECT rect) { m_hwndParent = hwnd; m_rcClient = rect; } // IUnknown diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp index 1575b716dd..8c6e06d165 100644 --- a/libs/mTextControl/src/services.cpp +++ b/libs/mTextControl/src/services.cpp @@ -85,16 +85,6 @@ MTEXTCONTROL_DLL(TextObject *) MTextCreateW(HANDLE userHandle, const char *szPro MText_InitFormatting0(result->ftd, result->options); result->ftd->putTextW((wchar_t *)text); MText_InitFormatting1(result); - - /* - LRESULT res; - CMStringA buf; - EDITSTREAM es = { 0 }; - es.dwCookie = (DWORD_PTR)&buf; - es.pfnCallback = &EditStreamOutCallback; - result->ftd->getTextService()->TxSendMessage(EM_STREAMOUT, SF_RTF, (LPARAM)&es, &res); - - Netlib_Logf(0, "Rtf created: %s", buf.c_str());*/ return result; } @@ -145,14 +135,16 @@ MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, TextObject *text) if (!text || !dc) return 0; - COLORREF cl = GetTextColor(dc); + if (!text->ftd->isNative()) { + COLORREF cl = GetTextColor(dc); - LRESULT lResult; - CHARFORMAT cf = { 0 }; - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_COLOR; - cf.crTextColor = cl; - text->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + LRESULT lResult; + CHARFORMAT cf = { 0 }; + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_COLOR; + cf.crTextColor = cl; + text->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); + } SetBkMode(dc, TRANSPARENT); -- cgit v1.2.3