From c1e25c5724629f1315a1043d99272ee8dddfc049 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 21 Mar 2024 18:53:27 +0300 Subject: NewStory: fix for drawing emoji --- plugins/NewStory/src/history_array.cpp | 2 +- plugins/NewStory/src/history_array.h | 2 +- plugins/NewStory/src/templates.cpp | 66 +++++++++++++++++----------------- plugins/NewStory/src/utils.cpp | 30 ++++++++-------- plugins/NewStory/src/utils.h | 4 +-- 5 files changed, 51 insertions(+), 53 deletions(-) (limited to 'plugins/NewStory/src') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index e9cc5989fa..37bfc35ccf 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -458,7 +458,7 @@ void ItemData::load(bool bLoadAlways) void ItemData::setText() { - m_doc = litehtml::document::createFromString(formatHtml(), &pOwner->webPage); + m_doc = litehtml::document::createFromString(T2Utf(formatHtml()), &pOwner->webPage); } // Array diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index e805d8f45d..ae32334d84 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -47,7 +47,7 @@ struct ItemData int getCopyTemplate() const; void getFontColor(int &fontId, int &colorId) const; - CMStringA formatHtml(const wchar_t *pwszStr = 0); + CMStringW formatHtml(const wchar_t *pwszStr = 0); CMStringW formatString() { return TplFormatString(getTemplate(), hContact, this); } CMStringW formatStringEx(wchar_t *sztpl); diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index adf7870a50..8ad26c7c88 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -36,23 +36,23 @@ static uint32_t color2html(COLORREF clr) return (((clr & 0xFF) << 16) | (clr & 0xFF00) | ((clr & 0xFF0000) >> 16)); } -static char* font2html(LOGFONTA &lf, char *dest) +static wchar_t* font2html(LOGFONTA &lf, wchar_t *dest) { - mir_snprintf(dest, 100, "font-family: %s; font-size: %dpt; font-weight: %s; %s", + mir_snwprintf(dest, 100, L"font-family: %s; font-size: %dpt; font-weight: %s %s", lf.lfFaceName, abs((signed char)lf.lfHeight) * 74 / g_iPixelY, lf.lfWeight >= FW_BOLD ? "bold" : "normal", - lf.lfItalic ? "font-style: italic;" : ""); + lf.lfItalic ? "; font-style: italic;" : ""); return dest; } -static void AppendString(CMStringA &buf, const char *p) +static void AppendString(CMStringW &buf, const wchar_t *p) { bool wasSpace = false; for (; *p; p++) { if (*p == ' ') { if (wasSpace) - buf.Append(" "); + buf.Append(L" "); else { buf.AppendChar(' '); wasSpace = true; @@ -62,55 +62,55 @@ static void AppendString(CMStringA &buf, const char *p) wasSpace = false; if (*p == '\r' && p[1] == '\n') { - buf.Append("
"); + buf.Append(L"
"); p++; } - else if (*p == '\n') buf.Append("
"); - else if (*p == '&') buf.Append("&"); - else if (*p == '>') buf.Append(">"); - else if (*p == '<') buf.Append("<"); - else if (*p == '&') buf.Append("""); + else if (*p == '\n') buf.Append(L"
"); + else if (*p == '&') buf.Append(L"&"); + else if (*p == '>') buf.Append(L">"); + else if (*p == '<') buf.Append(L"<"); + else if (*p == '&') buf.Append(L"""); else if (*p == '[') { p++; if (*p == 'c') { int colorId = -1; if (p[2] == ']') { - colorId = atoi(p + 1); + colorId = _wtoi(p + 1); p += 2; } else if (p[3] == ']') { - colorId = atoi(p + 1); + colorId = _wtoi(p + 1); p += 3; } switch (colorId) { - case 0: buf.Append(""); continue; - case 1: buf.Append(""); continue; + case 0: buf.Append(L""); continue; + case 1: buf.Append(L""); continue; case 2: case 3: case 4: case 5: case 6: - buf.AppendFormat("", color2html(g_plugin.clCustom[colorId-2])); + buf.AppendFormat(L"", color2html(g_plugin.clCustom[colorId-2])); continue; } } - char *pEnd = ""; + wchar_t *pEnd = L""; if (*p == '/') { - pEnd = "/"; + pEnd = L"/"; p++; } if (*p == 'b' && p[1] == ']') { - buf.AppendFormat("<%sb>", pEnd); + buf.AppendFormat(L"<%sb>", pEnd); p++; } else if (*p == 'i' && p[1] == ']') { - buf.AppendFormat("<%si>", pEnd); + buf.AppendFormat(L"<%si>", pEnd); p++; } else if (*p == 'u' && p[1] == ']') { - buf.AppendFormat("<%su>", pEnd); + buf.AppendFormat(L"<%su>", pEnd); p++; } else if (*p == 's' && p[1] == ']') { - buf.AppendFormat("<%ss>", pEnd); + buf.AppendFormat(L"<%ss>", pEnd); p++; } else { @@ -124,30 +124,30 @@ static void AppendString(CMStringA &buf, const char *p) } } -CMStringA ItemData::formatHtml(const wchar_t *pwszStr) +CMStringW ItemData::formatHtml(const wchar_t *pwszStr) { - CMStringA str; - str.Append(""); - str.Append("\n"); + str.Append(L"\n"); - CMStringA szBody; - AppendString(szBody, T2Utf((pwszStr) ? pwszStr : formatString()).get()); + CMStringW szBody; + AppendString(szBody, (pwszStr) ? pwszStr : formatString()); UrlAutodetect(szBody); if (g_plugin.bHasSmileys) ReplaceSmileys(hContact, szBody); str += szBody; - str.Append(""); + str.Append(L""); // Netlib_Logf(0, str); return str; diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index 66ad836a9a..a752b3688f 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -118,18 +118,18 @@ void RemoveBbcodes(CMStringW &wszText) ///////////////////////////////////////////////////////////////////////////////////////// -static int countNoWhitespace(const char *str) +static int countNoWhitespace(const wchar_t *str) { int c; for (c = 0; *str != '\n' && *str != '\r' && *str != '\t' && *str != ' ' && *str != '\0'; str++, c++); return c; } -static int DetectUrl(const char *text) +static int DetectUrl(const wchar_t *text) { int i; for (i = 0; text[i] != '\0'; i++) - if (!((text[i] >= '0' && text[i] <= '9') || isalpha(text[i]))) + if (!((text[i] >= '0' && text[i] <= '9') || iswalpha(text[i]))) break; if (i <= 0 || memcmp(text + i, "://", 3)) @@ -137,21 +137,21 @@ static int DetectUrl(const char *text) i += countNoWhitespace(text + i); for (; i > 0; i--) - if ((text[i - 1] >= '0' && text[i - 1] <= '9') || isalpha(text[i - 1]) || text[i - 1] == '/') + if ((text[i - 1] >= '0' && text[i - 1] <= '9') || iswalpha(text[i - 1]) || text[i - 1] == '/') break; return i; } -void UrlAutodetect(CMStringA &str) +void UrlAutodetect(CMStringW &str) { for (auto *p = str.c_str(); *p; p++) if (int len = DetectUrl(p)) { int pos = p - str.c_str(); - CMStringA url = str.Mid(pos, len); + CMStringW url = str.Mid(pos, len); str.Delete(pos, len); - CMStringA newText(FORMAT, "%s", url.c_str(), url.c_str()); + CMStringW newText(FORMAT, L"%s", url.c_str(), url.c_str()); str.Insert(pos, newText); p = str.c_str() + pos + newText.GetLength(); } @@ -159,29 +159,27 @@ void UrlAutodetect(CMStringA &str) ///////////////////////////////////////////////////////////////////////////////////////// -void ReplaceSmileys(MCONTACT hContact, CMStringA &str) +void ReplaceSmileys(MCONTACT hContact, CMStringW &str) { SMADD_BATCHPARSE sp; sp.Protocolname = Proto_GetBaseAccountName(hContact); - sp.flag = SAFL_PATH; - sp.str.a = str.c_str(); + sp.flag = SAFL_PATH | SAFL_UNICODE; + sp.str.w = str.c_str(); sp.hContact = hContact; if (auto *spRes = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp)) { for (int i = (int)sp.numSmileys-1; i >= 0; i--) { auto &smiley = spRes[i]; if (mir_wstrlen(smiley.filepath) > 0) { - CMStringA szText(str.Mid(smiley.startChar, smiley.size)); + CMStringW szText(str.Mid(smiley.startChar, smiley.size)); str.Delete(smiley.startChar, smiley.size); - CMStringA szNew; - if (sp.oflag & SAFL_UNICODE) - szNew.Format("\"%s\"", T2Utf(smiley.filepath).get(), szText.c_str(), szText.c_str()); - else - szNew.Format("\"%s\"", (char *)smiley.filepath, szText.c_str(), szText.c_str()); + CMStringW szNew; + szNew.Format(L"\"%s\"", smiley.filepath, szText.c_str(), szText.c_str()); str.Insert(smiley.startChar, szNew); } } + CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes); } } diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h index 24b65beec1..1af7323338 100644 --- a/plugins/NewStory/src/utils.h +++ b/plugins/NewStory/src/utils.h @@ -9,6 +9,6 @@ bool NSMenu_Process(int iCommand, NewstoryListData *data); int GetFontHeight(const LOGFONTA &lf); -void ReplaceSmileys(MCONTACT hContact, CMStringA &str); -void UrlAutodetect(CMStringA &str); +void ReplaceSmileys(MCONTACT hContact, CMStringW &str); +void UrlAutodetect(CMStringW &str); void RemoveBbcodes(CMStringW &pwszText); -- cgit v1.2.3