summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-21 18:53:27 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-21 18:53:27 +0300
commitc1e25c5724629f1315a1043d99272ee8dddfc049 (patch)
tree965d0a423c8b1ab041dc923f438422661017c717 /plugins
parent2ad54d3a441e42f187213f1bdec14d61272a3b27 (diff)
NewStory: fix for drawing emoji
Diffstat (limited to 'plugins')
-rw-r--r--plugins/NewStory/src/history_array.cpp2
-rw-r--r--plugins/NewStory/src/history_array.h2
-rw-r--r--plugins/NewStory/src/templates.cpp66
-rw-r--r--plugins/NewStory/src/utils.cpp30
-rw-r--r--plugins/NewStory/src/utils.h4
5 files changed, 51 insertions, 53 deletions
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("&nbsp;");
+ buf.Append(L"&nbsp;");
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("<br>");
+ buf.Append(L"<br>");
p++;
}
- else if (*p == '\n') buf.Append("<br>");
- else if (*p == '&') buf.Append("&amp;");
- else if (*p == '>') buf.Append("&gt;");
- else if (*p == '<') buf.Append("&lt;");
- else if (*p == '&') buf.Append("&quot;");
+ else if (*p == '\n') buf.Append(L"<br>");
+ else if (*p == '&') buf.Append(L"&amp;");
+ else if (*p == '>') buf.Append(L"&gt;");
+ else if (*p == '<') buf.Append(L"&lt;");
+ else if (*p == '&') buf.Append(L"&quot;");
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("</font>"); continue;
- case 1: buf.Append("<font class=\"nick\">"); continue;
+ case 0: buf.Append(L"</font>"); continue;
+ case 1: buf.Append(L"<font class=\"nick\">"); continue;
case 2: case 3: case 4: case 5: case 6:
- buf.AppendFormat("<font color=%06X>", color2html(g_plugin.clCustom[colorId-2]));
+ buf.AppendFormat(L"<font color=%06X>", 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("<html><head>");
- str.Append("<style type=\"text/css\">\n");
+ CMStringW str;
+ str.Append(L"<html><head>");
+ str.Append(L"<style type=\"text/css\">\n");
int fontID, colorID;
getFontColor(fontID, colorID);
auto &F = g_fontTable[fontID];
- char szFont[100];
- str.AppendFormat("body {margin: 0px; text-align: left; %s; color: NSText; overflow: auto;}\n", font2html(F.lf, szFont));
- str.AppendFormat(".nick {color: #%06X }\n", color2html(g_colorTable[(dbe.flags & DBEF_SENT) ? COLOR_OUTNICK : COLOR_INNICK].cl));
+ wchar_t szFont[100];
+ str.AppendFormat(L"body {margin: 0px; text-align: left; %s; color: NSText; overflow: auto;}\n", font2html(F.lf, szFont));
+ str.AppendFormat(L".nick {color: #%06X }\n", color2html(g_colorTable[(dbe.flags & DBEF_SENT) ? COLOR_OUTNICK : COLOR_INNICK].cl));
- str.Append("</style></head><body class=\"body\">\n");
+ str.Append(L"</style></head><body class=\"body\">\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("</body></html>");
+ str.Append(L"</body></html>");
// 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, "<a href =\"%s\">%s</a>", url.c_str(), url.c_str());
+ CMStringW newText(FORMAT, L"<a href =\"%s\">%s</a>", 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("<img class=\"img\" src=\"file://%s\" title=\"%s\" alt=\"%s\" />", T2Utf(smiley.filepath).get(), szText.c_str(), szText.c_str());
- else
- szNew.Format("<img class=\"img\" src=\"file://%s\" title=\"%s\" alt=\"%s\" />", (char *)smiley.filepath, szText.c_str(), szText.c_str());
+ CMStringW szNew;
+ szNew.Format(L"<img class=\"img\" src=\"file://%s\" title=\"%s\" alt=\"%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);