summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-03-31 11:48:15 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-03-31 11:48:19 +0300
commitc96a3b3959b6e618311e5c5157d9af0bf3439dd2 (patch)
tree3cd08d4621c373cfe6d02183db4656113929b96b /libs
parentb4129cd056469e8f915522b9ce7eab2a39e3fa3b (diff)
fixes #4319 (NewStory: пропала поддержка смайликов средствами шрифта)
Diffstat (limited to 'libs')
-rw-r--r--libs/litehtml/containers/windows/win32/win32_container.cpp19
-rw-r--r--libs/litehtml/include/litehtml/utf8_strings.h24
-rw-r--r--libs/litehtml/src/background.cpp12
-rw-r--r--libs/litehtml/src/document_container.cpp24
-rw-r--r--libs/litehtml/src/el_before_after.cpp6
-rw-r--r--libs/litehtml/src/num_cvt.cpp6
-rw-r--r--libs/litehtml/src/utf8_strings.cpp24
7 files changed, 57 insertions, 58 deletions
diff --git a/libs/litehtml/containers/windows/win32/win32_container.cpp b/libs/litehtml/containers/windows/win32/win32_container.cpp
index bbcbfe53dc..e028c986fb 100644
--- a/libs/litehtml/containers/windows/win32/win32_container.cpp
+++ b/libs/litehtml/containers/windows/win32/win32_container.cpp
@@ -1,4 +1,5 @@
#include "win32_container.h"
+#include <newpluginapi.h>
win32_container::win32_container()
{
@@ -60,15 +61,15 @@ litehtml::uint_ptr win32_container::create_font( const char* font_list, int size
{
litehtml::trim(name);
trim_quotes(name);
- std::wstring wname = (const wchar_t*)litehtml_to_wchar(name.c_str());
- if (m_installed_fonts.count(wname))
+ Utf2T wname(name.c_str());
+ if (m_installed_fonts.count(wname.get()))
{
font_name = wname;
found = true;
break;
}
}
- if (!found) font_name = litehtml_to_wchar(get_default_font_name());
+ if (!found) font_name = Utf2T(get_default_font_name());
font_name = get_exact_font_name(font_name.c_str());
LOGFONT lf = {};
@@ -119,8 +120,8 @@ int win32_container::text_width( const char* text, uint_ptr hFont )
{
SIZE size = {};
SelectObject(m_tmp_hdc, (HFONT)hFont);
- std::wstring wtext = (const wchar_t*)litehtml_to_wchar(text);
- GetTextExtentPoint32(m_tmp_hdc, wtext.c_str(), (int)wtext.size(), &size);
+ Utf2T wtext(text);
+ GetTextExtentPoint32(m_tmp_hdc, wtext, (int)mir_wstrlen(wtext), &size);
return size.cx;
}
@@ -135,7 +136,7 @@ void win32_container::draw_text( uint_ptr hdc, const char* text, uint_ptr hFont,
SetTextColor((HDC) hdc, RGB(color.red, color.green, color.blue));
RECT rcText = { pos.left(), pos.top(), pos.right(), pos.bottom() };
- DrawText((HDC) hdc, litehtml_to_wchar(text), -1, &rcText, DT_SINGLELINE | DT_NOPREFIX | DT_BOTTOM | DT_NOCLIP);
+ DrawText((HDC) hdc, Utf2T(text), -1, &rcText, DT_SINGLELINE | DT_NOPREFIX | DT_BOTTOM | DT_NOCLIP);
SelectObject((HDC) hdc, oldFont);
@@ -209,7 +210,7 @@ void win32_container::draw_list_marker(uint_ptr hdc, const litehtml::list_marker
void win32_container::make_url_utf8(const char* url, const char* basepath, std::wstring& out)
{
- make_url(litehtml::utf8_to_wchar(url), litehtml::utf8_to_wchar(basepath), out);
+ make_url(Utf2T(url), Utf2T(basepath), out);
}
void win32_container::load_image( const char* src, const char* baseurl, bool redraw_on_ready )
@@ -352,7 +353,7 @@ void win32_container::transform_text(litehtml::string& text, litehtml::text_tran
{
if (text.empty()) return;
- LPWSTR txt = _wcsdup(litehtml_to_wchar(text.c_str()));
+ LPWSTR txt = _wcsdup(Utf2T(text.c_str()));
switch (tt)
{
case litehtml::text_transform_capitalize:
@@ -365,7 +366,7 @@ void win32_container::transform_text(litehtml::string& text, litehtml::text_tran
CharLowerBuff(txt, lstrlen(txt));
break;
}
- text = litehtml_from_wchar(txt);
+ text = T2Utf(txt);
free(txt);
}
diff --git a/libs/litehtml/include/litehtml/utf8_strings.h b/libs/litehtml/include/litehtml/utf8_strings.h
index f438ad2b30..a4f1a78fa8 100644
--- a/libs/litehtml/include/litehtml/utf8_strings.h
+++ b/libs/litehtml/include/litehtml/utf8_strings.h
@@ -7,36 +7,36 @@
namespace litehtml
{
// converts UTF-32 ch to UTF-8 and appends it to str
- void append_char(string& str, int ch);
+ void append_char(string& str, char32_t ch);
- class utf8_to_wchar
+ class utf8_to_utf32
{
const byte* m_utf8;
- std::wstring m_str;
+ std::u32string m_str;
public:
- utf8_to_wchar(const char* val);
- operator const wchar_t*() const
+ utf8_to_utf32(const char* val);
+ operator const char32_t*() const
{
return m_str.c_str();
}
private:
- ucode_t getb()
+ char32_t getb()
{
if (!(*m_utf8)) return 0;
return *m_utf8++;
}
- ucode_t get_next_utf8(ucode_t val)
+ char32_t get_next_utf8(char32_t val)
{
return (val & 0x3f);
}
- ucode_t get_char();
+ char32_t get_char();
};
- class wchar_to_utf8
+ class utf32_to_utf8
{
std::string m_str;
public:
- wchar_to_utf8(const std::wstring& val);
+ utf32_to_utf8(const std::u32string& val);
operator const char*() const
{
return m_str.c_str();
@@ -48,8 +48,8 @@ namespace litehtml
}
};
-#define litehtml_from_wchar(str) litehtml::wchar_to_utf8(str)
-#define litehtml_to_wchar(str) litehtml::utf8_to_wchar(str)
+#define litehtml_from_utf32(str) litehtml::utf32_to_utf8(str)
+#define litehtml_to_utf32(str) litehtml::utf8_to_utf32(str)
}
#endif // LH_UTF8_STRINGS_H
diff --git a/libs/litehtml/src/background.cpp b/libs/litehtml/src/background.cpp
index 2a3ac7b88b..b7ae75c6b6 100644
--- a/libs/litehtml/src/background.cpp
+++ b/libs/litehtml/src/background.cpp
@@ -786,7 +786,7 @@ bool litehtml::background_layer::gradient_base::prepare_color_points(float line_
}
if(item.length.units() == css_units_percentage)
{
- color_points.emplace_back(item.length.val() / 100.0, item.color);
+ color_points.emplace_back(item.length.val() / 100.0f, item.color);
} else if(item.length.units() != css_units_none)
{
if(line_len != 0)
@@ -799,7 +799,7 @@ bool litehtml::background_layer::gradient_base::prepare_color_points(float line_
{
none_units++;
}
- color_points.emplace_back(0, item.color);
+ color_points.emplace_back(0.0f, item.color);
}
}
if(color_points.empty())
@@ -812,7 +812,7 @@ bool litehtml::background_layer::gradient_base::prepare_color_points(float line_
// Add color point with offset 0 if not exists
if(color_points[0].offset != 0)
{
- color_points.emplace(color_points.begin(), 0, color_points[0].color);
+ color_points.emplace(color_points.begin(), 0.0f, color_points[0].color);
}
// Add color point with offset 1.0 if not exists
if (color_points.back().offset < 1)
@@ -823,7 +823,7 @@ bool litehtml::background_layer::gradient_base::prepare_color_points(float line_
none_units--;
} else
{
- color_points.emplace_back(1.0, color_points.back().color);
+ color_points.emplace_back(1.0f, color_points.back().color);
}
}
} else
@@ -901,7 +901,7 @@ bool litehtml::background_layer::gradient_base::prepare_angle_color_points(backg
{
none_units++;
}
- color_points.emplace_back(0, item.color);
+ color_points.emplace_back(0.0f, item.color);
} else
{
color_points.emplace_back(item.angle, item.color);
@@ -917,7 +917,7 @@ bool litehtml::background_layer::gradient_base::prepare_angle_color_points(backg
// Add color point with offset 0 if not exists
if (color_points[0].offset != 0)
{
- color_points.emplace(color_points.begin(), 0, color_points[0].color);
+ color_points.emplace(color_points.begin(), 0.0f, color_points[0].color);
}
// Add color point with offset 1.0 if not exists
if (color_points.back().offset < 360.0f)
diff --git a/libs/litehtml/src/document_container.cpp b/libs/litehtml/src/document_container.cpp
index 2fb601efe4..8c3aea61bd 100644
--- a/libs/litehtml/src/document_container.cpp
+++ b/libs/litehtml/src/document_container.cpp
@@ -3,21 +3,19 @@
void litehtml::document_container::split_text(const char* text, const std::function<void(const char*)>& on_word, const std::function<void(const char*)>& on_space)
{
- std::wstring str;
- std::wstring str_in = (const wchar_t*)utf8_to_wchar(text);
- ucode_t c;
- for (size_t i = 0; i < str_in.length(); i++)
+ std::u32string str;
+ std::u32string str_in = (const char32_t*)utf8_to_utf32(text);
+ for (auto c : str_in)
{
- c = (ucode_t)str_in[i];
if (c <= ' ' && (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f'))
{
if (!str.empty())
{
- on_word(wchar_to_utf8(str.c_str()));
+ on_word(utf32_to_utf8(str));
str.clear();
}
- str += (wchar_t)c;
- on_space(wchar_to_utf8(str.c_str()));
+ str += c;
+ on_space(utf32_to_utf8(str));
str.clear();
}
// CJK character range
@@ -25,20 +23,20 @@ void litehtml::document_container::split_text(const char* text, const std::funct
{
if (!str.empty())
{
- on_word(wchar_to_utf8(str.c_str()));
+ on_word(utf32_to_utf8(str));
str.clear();
}
- str += (wchar_t)c;
- on_word(wchar_to_utf8(str.c_str()));
+ str += c;
+ on_word(utf32_to_utf8(str));
str.clear();
}
else
{
- str += (wchar_t)c;
+ str += c;
}
}
if (!str.empty())
{
- on_word(wchar_to_utf8(str.c_str()));
+ on_word(utf32_to_utf8(str));
}
}
diff --git a/libs/litehtml/src/el_before_after.cpp b/libs/litehtml/src/el_before_after.cpp
index 39fa646cea..5bf5aae81c 100644
--- a/libs/litehtml/src/el_before_after.cpp
+++ b/libs/litehtml/src/el_before_after.cpp
@@ -208,8 +208,8 @@ void litehtml::el_before_after_base::add_function( const string& fnc, const stri
litehtml::string litehtml::el_before_after_base::convert_escape( const char* txt )
{
char* str_end;
- wchar_t u_str[2];
- u_str[0] = (wchar_t) strtol(txt, &str_end, 16);
+ char32_t u_str[2];
+ u_str[0] = (char32_t) strtol(txt, &str_end, 16);
u_str[1] = 0;
- return litehtml::string(litehtml_from_wchar(u_str));
+ return litehtml::string(litehtml_from_utf32(u_str));
}
diff --git a/libs/litehtml/src/num_cvt.cpp b/libs/litehtml/src/num_cvt.cpp
index 23d594b5c9..b1d0f3b75e 100644
--- a/libs/litehtml/src/num_cvt.cpp
+++ b/libs/litehtml/src/num_cvt.cpp
@@ -4,7 +4,7 @@
static std::vector<char> latin_lower = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
static std::vector<char> latin_upper = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
-static std::vector<std::wstring> greek_lower = { L"α", L"β", L"γ", L"δ", L"ε", L"ζ", L"η", L"θ", L"ι", L"κ", L"λ", L"μ", L"ν", L"ξ", L"ο", L"π", L"ρ", L"σ", L"τ", L"υ", L"φ", L"χ", L"ψ", L"ω" };
+static std::vector<std::u32string> greek_lower = { U"α", U"β", U"γ", U"δ", U"ε", U"ζ", U"η", U"θ", U"ι", U"κ", U"λ", U"μ", U"ν", U"ξ", U"ο", U"π", U"ρ", U"σ", U"τ", U"υ", U"φ", U"χ", U"ψ", U"ω" };
static litehtml::string to_mapped_alpha(int num, const std::vector<char>& map)
{
@@ -22,7 +22,7 @@ static litehtml::string to_mapped_alpha(int num, const std::vector<char>& map)
return out;
}
-static litehtml::string to_mapped_alpha(int num, const std::vector<std::wstring>& map)
+static litehtml::string to_mapped_alpha(int num, const std::vector<std::u32string>& map)
{
int dividend = num;
litehtml::string out;
@@ -31,7 +31,7 @@ static litehtml::string to_mapped_alpha(int num, const std::vector<std::wstring>
while (dividend > 0)
{
modulo = (dividend - 1) % map.size();
- out = litehtml_from_wchar(map[modulo]).c_str() + out;
+ out = litehtml_from_utf32(map[modulo]).c_str() + out;
dividend = (int)((dividend - modulo) / map.size());
}
diff --git a/libs/litehtml/src/utf8_strings.cpp b/libs/litehtml/src/utf8_strings.cpp
index ae74d10f1d..864a4d0147 100644
--- a/libs/litehtml/src/utf8_strings.cpp
+++ b/libs/litehtml/src/utf8_strings.cpp
@@ -4,22 +4,22 @@
namespace litehtml
{
-utf8_to_wchar::utf8_to_wchar(const char* val)
+utf8_to_utf32::utf8_to_utf32(const char* val)
{
m_utf8 = (const byte*) val;
if (!m_utf8) return;
while (true)
{
- ucode_t wch = get_char();
+ char32_t wch = get_char();
if (!wch) break;
- m_str += (wchar_t)wch;
+ m_str += wch;
}
}
-ucode_t utf8_to_wchar::get_char()
+char32_t utf8_to_utf32::get_char()
{
- ucode_t b1 = getb();
+ char32_t b1 = getb();
if (!b1)
{
@@ -37,14 +37,14 @@ ucode_t utf8_to_wchar::get_char()
else if ((b1 & 0xe0) == 0xc0)
{
// 2-byte sequence: 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
- ucode_t r = (b1 & 0x1f) << 6;
+ char32_t r = (b1 & 0x1f) << 6;
r |= get_next_utf8(getb());
return r;
}
else if ((b1 & 0xf0) == 0xe0)
{
// 3-byte sequence: zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
- ucode_t r = (b1 & 0x0f) << 12;
+ char32_t r = (b1 & 0x0f) << 12;
r |= get_next_utf8(getb()) << 6;
r |= get_next_utf8(getb());
return r;
@@ -54,9 +54,9 @@ ucode_t utf8_to_wchar::get_char()
// 4-byte sequence: 11101110wwwwzzzzyy + 110111yyyyxxxxxx
// = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
// (uuuuu = wwww + 1)
- int b2 = get_next_utf8(getb());
- int b3 = get_next_utf8(getb());
- int b4 = get_next_utf8(getb());
+ char32_t b2 = get_next_utf8(getb());
+ char32_t b3 = get_next_utf8(getb());
+ char32_t b4 = get_next_utf8(getb());
return ((b1 & 7) << 18) | ((b2 & 0x3f) << 12) |
((b3 & 0x3f) << 6) | (b4 & 0x3f);
}
@@ -65,7 +65,7 @@ ucode_t utf8_to_wchar::get_char()
return '?';
}
-void append_char(string& str, int code)
+void append_char(string& str, char32_t code)
{
if (code <= 0x7F)
{
@@ -95,7 +95,7 @@ void append_char(string& str, int code)
}
}
-wchar_to_utf8::wchar_to_utf8(const std::wstring& wstr)
+utf32_to_utf8::utf32_to_utf8(const std::u32string& wstr)
{
for (auto ch: wstr)
append_char(m_str, ch);