fix(renderer): Drop strings with invalid UTF8
This commit is contained in:
parent
63443f82d5
commit
3a27e891d2
@ -163,9 +163,14 @@ namespace cairo {
|
|||||||
std::iter_swap(fns.begin(), fns.begin() + t.font - 1);
|
std::iter_swap(fns.begin(), fns.begin() + t.font - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
string utf8 = string(t.contents);
|
string utf8 = t.contents;
|
||||||
string_util::unicode_charlist chars;
|
string_util::unicode_charlist chars;
|
||||||
string_util::utf8_to_ucs4(utf8.c_str(), chars);
|
bool success = string_util::utf8_to_ucs4(utf8.c_str(), chars);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
m_log.warn("Dropping invalid UTF8 text '%s'", utf8);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
while (!chars.empty()) {
|
while (!chars.empty()) {
|
||||||
auto remaining = chars.size();
|
auto remaining = chars.size();
|
||||||
|
@ -220,10 +220,6 @@ class font_fc : public font {
|
|||||||
m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
|
m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
|
||||||
|
|
||||||
if (status != CAIRO_STATUS_SUCCESS) {
|
if (status != CAIRO_STATUS_SUCCESS) {
|
||||||
logger::make().notice("ERROR %d", status);
|
|
||||||
for (char& c : utf8) {
|
|
||||||
logger::make().notice("0x%02x", c);
|
|
||||||
}
|
|
||||||
throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs() " << cairo_status_to_string(status));
|
throw application_error(sstream() << "cairo_scaled_font_text_to_glyphs() " << cairo_status_to_string(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ string utf8_truncate(string&& value, size_t len);
|
|||||||
/**
|
/**
|
||||||
* @brief Create a UCS-4 codepoint from a utf-8 encoded string
|
* @brief Create a UCS-4 codepoint from a utf-8 encoded string
|
||||||
*/
|
*/
|
||||||
bool utf8_to_ucs4(const char* src, unicode_charlist& result_list);
|
[[nodiscard]] bool utf8_to_ucs4(const char* src, unicode_charlist& result_list);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Convert a UCS-4 codepoint to a utf-8 encoded string
|
* @brief Convert a UCS-4 codepoint to a utf-8 encoded string
|
||||||
|
@ -270,7 +270,7 @@ static pair<int, uint32_t> utf8_get_len(uint8_t leading) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a UCS-4 codepoint from a utf-8 encoded string
|
* @brief Create a list of UCS-4 codepoint from a utf-8 encoded string
|
||||||
*/
|
*/
|
||||||
bool utf8_to_ucs4(const char* src, unicode_charlist& result_list) {
|
bool utf8_to_ucs4(const char* src, unicode_charlist& result_list) {
|
||||||
if (!src) {
|
if (!src) {
|
||||||
|
Loading…
Reference in New Issue
Block a user