summaryrefslogtreecommitdiffstats
path: root/modules/text_server_adv
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2023-08-14 18:12:05 -0500
committerDavid Snopek <dsnopek@gmail.com>2023-08-14 18:12:05 -0500
commitd585ca546bf8920ead41bf3d371bfc85fcfba8a1 (patch)
tree59b8941f16d1e51511818a923647bd4441e4dc5a /modules/text_server_adv
parentc495eb5102278a110c14bbffbf833ed436d1594d (diff)
downloadredot-engine-d585ca546bf8920ead41bf3d371bfc85fcfba8a1.tar.gz
Use `String::resize()` and `CharString` in text_server_adv again
Diffstat (limited to 'modules/text_server_adv')
-rw-r--r--modules/text_server_adv/text_server_adv.cpp8
-rw-r--r--modules/text_server_adv/thorvg_svg_in_ot.cpp15
-rw-r--r--modules/text_server_adv/thorvg_svg_in_ot.h14
3 files changed, 3 insertions, 34 deletions
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 043a33ab35..2a502d081e 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -2113,12 +2113,10 @@ Dictionary TextServerAdvanced::_font_get_ot_name_strings(const RID &p_font_rid)
name = vformat("unknown_%d", names[i].name_id);
} break;
}
+ String text;
unsigned int text_size = hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, nullptr, nullptr) + 1;
- // @todo After godot-cpp#1141 is fixed, use text.resize() and write directly to text.wptr() instead of using a temporary buffer.
- char32_t *buffer = memnew_arr(char32_t, text_size);
- hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, &text_size, (uint32_t *)buffer);
- String text(buffer);
- memdelete_arr(buffer);
+ text.resize(text_size);
+ hb_ot_name_get_utf32(hb_face, names[i].name_id, names[i].language, &text_size, (uint32_t *)text.ptrw());
if (!text.is_empty()) {
Dictionary &id_string = names_for_lang[String(hb_language_to_string(names[i].language))];
id_string[name] = text;
diff --git a/modules/text_server_adv/thorvg_svg_in_ot.cpp b/modules/text_server_adv/thorvg_svg_in_ot.cpp
index 2f48f1564c..951ca15503 100644
--- a/modules/text_server_adv/thorvg_svg_in_ot.cpp
+++ b/modules/text_server_adv/thorvg_svg_in_ot.cpp
@@ -155,21 +155,10 @@ FT_Error tvg_svg_in_ot_preset_slot(FT_GlyphSlot p_slot, FT_Bool p_cache, FT_Poin
}
String xml_code_str = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"" + rtos(min_x) + " " + rtos(min_y) + " " + rtos(new_w) + " " + rtos(new_h) + "\">" + xml_body;
-#ifndef GDEXTENSION
gl_state.xml_code = xml_code_str.utf8();
-#else
- CharString xml_code = xml_code_str.utf8();
- gl_state.xml_code_length = xml_code.length();
- gl_state.xml_code = memnew_arr(char, gl_state.xml_code_length);
- memcpy(gl_state.xml_code, xml_code.get_data(), gl_state.xml_code_length);
-#endif
picture = tvg::Picture::gen();
-#ifndef GDEXTENSION
result = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false);
-#else
- result = picture->load(gl_state.xml_code, gl_state.xml_code_length, "svg+xml", false);
-#endif
if (result != tvg::Result::Success) {
ERR_FAIL_V_MSG(FT_Err_Invalid_SVG_Document, "Failed to load SVG document (glyph metrics).");
}
@@ -257,11 +246,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<tvg::Picture> picture = tvg::Picture::gen();
-#ifndef GDEXTENSION
tvg::Result res = picture->load(gl_state.xml_code.get_data(), gl_state.xml_code.length(), "svg+xml", false);
-#else
- tvg::Result res = picture->load(gl_state.xml_code, gl_state.xml_code_length, "svg+xml", false);
-#endif
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 5e79c8e444..034fffb5e6 100644
--- a/modules/text_server_adv/thorvg_svg_in_ot.h
+++ b/modules/text_server_adv/thorvg_svg_in_ot.h
@@ -66,22 +66,8 @@ struct GL_State {
float y = 0;
float w = 0;
float h = 0;
-#ifndef GDEXTENSION
CharString xml_code;
-#else
- // @todo After godot-cpp#1142 is fixed, use CharString just like when compiled as a Godot module.
- char *xml_code = nullptr;
- int xml_code_length = 0;
-#endif
tvg::Matrix m;
-
-#ifdef GDEXTENSION
- ~GL_State() {
- if (xml_code) {
- memdelete_arr(xml_code);
- }
- }
-#endif
};
struct TVG_State {