Full Unicode patch with RTL Support & BiDi logic.
This commit is well documented, so no need to tell you my life story. Full Unicode patch with RTL Support & BiDi logic. Removed the legacy codePage, normalised to UTF8 (65001). It also comes with: CTRL + A : select text (highlighted) CTRL + C : copy CTRL + V : paste CTRL + X : cut CTRL + Y : redo CTRL + Z : undo
This commit is contained in:
@@ -2,38 +2,30 @@
|
||||
#include "TextBar.h"
|
||||
#include "EterLib/Util.h"
|
||||
|
||||
#include <utf8.h>
|
||||
|
||||
void CTextBar::__SetFont(int fontSize, bool isBold)
|
||||
{
|
||||
int iCodePage = GetDefaultCodePage();
|
||||
LOGFONTW logFont{};
|
||||
|
||||
LOGFONT logFont;
|
||||
logFont.lfHeight = fontSize;
|
||||
logFont.lfEscapement = 0;
|
||||
logFont.lfOrientation = 0;
|
||||
logFont.lfWeight = isBold ? FW_BOLD : FW_NORMAL;
|
||||
logFont.lfItalic = FALSE;
|
||||
logFont.lfUnderline = FALSE;
|
||||
logFont.lfStrikeOut = FALSE;
|
||||
logFont.lfCharSet = DEFAULT_CHARSET;
|
||||
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
||||
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
logFont.lfQuality = ANTIALIASED_QUALITY;
|
||||
logFont.lfPitchAndFamily = DEFAULT_PITCH;
|
||||
wcscpy_s(logFont.lfFaceName, LF_FACESIZE, L"Tahoma");
|
||||
|
||||
memset(&logFont, 0, sizeof(LOGFONT));
|
||||
|
||||
logFont.lfHeight = fontSize;
|
||||
logFont.lfEscapement = 0;
|
||||
logFont.lfOrientation = 0;
|
||||
|
||||
if (isBold)
|
||||
logFont.lfWeight = FW_BOLD;
|
||||
else
|
||||
logFont.lfWeight = FW_NORMAL;
|
||||
|
||||
logFont.lfItalic = FALSE;
|
||||
logFont.lfUnderline = FALSE;
|
||||
logFont.lfStrikeOut = FALSE;
|
||||
logFont.lfCharSet = GetCharsetFromCodePage(iCodePage);
|
||||
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
||||
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
logFont.lfQuality = ANTIALIASED_QUALITY;
|
||||
logFont.lfPitchAndFamily = DEFAULT_PITCH;
|
||||
strcpy(logFont.lfFaceName, GetFontFaceFromCodePage(iCodePage));
|
||||
m_hFont = CreateFontIndirect(&logFont);
|
||||
|
||||
|
||||
HDC hdc = m_dib.GetDCHandle();
|
||||
m_hOldFont = (HFONT)SelectObject(hdc, m_hFont);
|
||||
|
||||
}
|
||||
|
||||
void CTextBar::SetTextColor(int r, int g, int b)
|
||||
@@ -41,11 +33,24 @@ void CTextBar::SetTextColor(int r, int g, int b)
|
||||
HDC hDC = m_dib.GetDCHandle();
|
||||
::SetTextColor(hDC, RGB(r, g, b));
|
||||
}
|
||||
|
||||
void CTextBar::GetTextExtent(const char * c_szText, SIZE* p_size)
|
||||
|
||||
void CTextBar::GetTextExtent(const char* c_szText, SIZE* p_size)
|
||||
{
|
||||
if (!c_szText || !p_size)
|
||||
{
|
||||
if (p_size)
|
||||
{
|
||||
p_size->cx = 0;
|
||||
p_size->cy = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
HDC hDC = m_dib.GetDCHandle();
|
||||
GetTextExtentPoint32(hDC, c_szText, strlen(c_szText), p_size);
|
||||
|
||||
// UTF-8 → UTF-16
|
||||
std::wstring wText = Utf8ToWide(c_szText);
|
||||
GetTextExtentPoint32W(hDC, wText.c_str(), static_cast<int>(wText.length()), p_size);
|
||||
}
|
||||
|
||||
void CTextBar::TextOut(int ix, int iy, const char * c_szText)
|
||||
@@ -63,10 +68,9 @@ void CTextBar::OnCreate()
|
||||
|
||||
CTextBar::CTextBar(int fontSize, bool isBold)
|
||||
{
|
||||
m_hOldFont = NULL;
|
||||
m_hOldFont = NULL;
|
||||
m_fontSize = fontSize;
|
||||
m_isBold = isBold;
|
||||
|
||||
}
|
||||
|
||||
CTextBar::~CTextBar()
|
||||
|
||||
Reference in New Issue
Block a user