From 05fa6e314adf0b5e088dd85e2fe0b8ebce421eac Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 7 Apr 2023 17:44:39 +0200 Subject: [SVG Font] Keep a copy of UTF-8 XML source string during the whole SVG processing. (cherry picked from commit 19179238fa18a0f5c8ba612e93cc699e4e750a3c) --- modules/text_server_adv/thorvg_svg_in_ot.cpp | 12 +++++++----- modules/text_server_adv/thorvg_svg_in_ot.h | 2 +- modules/text_server_fb/thorvg_svg_in_ot.cpp | 12 +++++++----- modules/text_server_fb/thorvg_svg_in_ot.h | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/text_server_adv/thorvg_svg_in_ot.cpp b/modules/text_server_adv/thorvg_svg_in_ot.cpp index 1406e3aaa0..4fd4c7c1f6 100644 --- a/modules/text_server_adv/thorvg_svg_in_ot.cpp +++ b/modules/text_server_adv/thorvg_svg_in_ot.cpp @@ -126,10 +126,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin xml_body += vformat("", parser->get_node_name()); } } - String temp_xml = "" + xml_body; + String temp_xml_str = "" + xml_body; + CharString temp_xml = temp_xml_str.utf8(); std::unique_ptr picture = tvg::Picture::gen(); - tvg::Result result = picture->load(temp_xml.utf8().get_data(), temp_xml.utf8().length(), "svg+xml", false); + tvg::Result result = picture->load(temp_xml.get_data(), temp_xml.length(), "svg+xml", false); if (result != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (bounds detection)."); } @@ -146,10 +147,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin new_h = (new_w / aspect); } - gl_state.xml_code = "" + xml_body; + String xml_code_str = "" + xml_body; + gl_state.xml_code = xml_code_str.utf8(); picture = tvg::Picture::gen(); - result = picture->load(gl_state.xml_code.utf8().get_data(), gl_state.xml_code.utf8().length(), "svg+xml", false); + result = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false); if (result != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph metrics)."); } @@ -237,7 +239,7 @@ FT_Error tvg_svg_in_ot_render(FT_GlyphSlot p_slot, FT_Pointer *p_state) { ERR_FAIL_COND_V_MSG(!gl_state.ready, FT_Err_Invalid_SVG_Document, "SVG glyph not ready."); std::unique_ptr picture = tvg::Picture::gen(); - tvg::Result res = picture->load(gl_state.xml_code.utf8().get_data(), gl_state.xml_code.utf8().length(), "svg+xml", false); + tvg::Result res = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false); if (res != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph rendering)."); } diff --git a/modules/text_server_adv/thorvg_svg_in_ot.h b/modules/text_server_adv/thorvg_svg_in_ot.h index 4035a984b6..e9bf05c2c3 100644 --- a/modules/text_server_adv/thorvg_svg_in_ot.h +++ b/modules/text_server_adv/thorvg_svg_in_ot.h @@ -65,7 +65,7 @@ struct GL_State { float y = 0; float w = 0; float h = 0; - String xml_code; + CharString xml_code; tvg::Matrix m; }; diff --git a/modules/text_server_fb/thorvg_svg_in_ot.cpp b/modules/text_server_fb/thorvg_svg_in_ot.cpp index 1406e3aaa0..4fd4c7c1f6 100644 --- a/modules/text_server_fb/thorvg_svg_in_ot.cpp +++ b/modules/text_server_fb/thorvg_svg_in_ot.cpp @@ -126,10 +126,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin xml_body += vformat("", parser->get_node_name()); } } - String temp_xml = "" + xml_body; + String temp_xml_str = "" + xml_body; + CharString temp_xml = temp_xml_str.utf8(); std::unique_ptr picture = tvg::Picture::gen(); - tvg::Result result = picture->load(temp_xml.utf8().get_data(), temp_xml.utf8().length(), "svg+xml", false); + tvg::Result result = picture->load(temp_xml.get_data(), temp_xml.length(), "svg+xml", false); if (result != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (bounds detection)."); } @@ -146,10 +147,11 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin new_h = (new_w / aspect); } - gl_state.xml_code = "" + xml_body; + String xml_code_str = "" + xml_body; + gl_state.xml_code = xml_code_str.utf8(); picture = tvg::Picture::gen(); - result = picture->load(gl_state.xml_code.utf8().get_data(), gl_state.xml_code.utf8().length(), "svg+xml", false); + result = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false); if (result != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph metrics)."); } @@ -237,7 +239,7 @@ FT_Error tvg_svg_in_ot_render(FT_GlyphSlot p_slot, FT_Pointer *p_state) { ERR_FAIL_COND_V_MSG(!gl_state.ready, FT_Err_Invalid_SVG_Document, "SVG glyph not ready."); std::unique_ptr picture = tvg::Picture::gen(); - tvg::Result res = picture->load(gl_state.xml_code.utf8().get_data(), gl_state.xml_code.utf8().length(), "svg+xml", false); + tvg::Result res = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false); if (res != tvg::Result::Success) { ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph rendering)."); } diff --git a/modules/text_server_fb/thorvg_svg_in_ot.h b/modules/text_server_fb/thorvg_svg_in_ot.h index 4035a984b6..e9bf05c2c3 100644 --- a/modules/text_server_fb/thorvg_svg_in_ot.h +++ b/modules/text_server_fb/thorvg_svg_in_ot.h @@ -65,7 +65,7 @@ struct GL_State { float y = 0; float w = 0; float h = 0; - String xml_code; + CharString xml_code; tvg::Matrix m; }; -- cgit v1.2.3