fix(renderer): Drop strings with invalid UTF8

This commit is contained in:
patrick96 2023-05-10 15:15:09 +02:00 committed by Patrick Ziegler
parent 63443f82d5
commit 3a27e891d2
4 changed files with 10 additions and 9 deletions

View File

@ -163,9 +163,14 @@ namespace cairo {
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::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()) {
auto remaining = chars.size();

View File

@ -220,10 +220,6 @@ class font_fc : public font {
m_scaled, x, y, utf8.c_str(), utf8.size(), &glyphs, &nglyphs, &clusters, &nclusters, &cf);
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));
}

View File

@ -24,7 +24,7 @@ class sstream {
return m_stream.str();
}
string to_string() const {
string to_string() const {
return m_stream.str();
}
@ -88,7 +88,7 @@ string utf8_truncate(string&& value, size_t len);
/**
* @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

View File

@ -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) {
if (!src) {