From e65142190544de5b7dcb54f8ed18e6bc216fab79 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Sun, 2 Jun 2024 21:21:18 +0300 Subject: [TextServer, GDExtension] Fix building text servers as GDExtension, expose new/changed low-level methods to GDExtension API. --- modules/text_server_adv/gdextension_build/SConstruct | 4 +++- modules/text_server_adv/text_server_adv.cpp | 16 +++++++--------- modules/text_server_adv/text_server_adv.h | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) (limited to 'modules/text_server_adv') diff --git a/modules/text_server_adv/gdextension_build/SConstruct b/modules/text_server_adv/gdextension_build/SConstruct index 2f7a175d91..d0d13fec3f 100644 --- a/modules/text_server_adv/gdextension_build/SConstruct +++ b/modules/text_server_adv/gdextension_build/SConstruct @@ -61,8 +61,8 @@ if env["thorvg_enabled"] and env["freetype_enabled"]: thirdparty_tvg_dir = "../../../thirdparty/thorvg/" thirdparty_tvg_sources = [ # common - "src/common/tvgBezier.cpp", "src/common/tvgCompressor.cpp", + "src/common/tvgLines.cpp", "src/common/tvgMath.cpp", "src/common/tvgStr.cpp", # SVG parser @@ -73,6 +73,7 @@ if env["thorvg_enabled"] and env["freetype_enabled"]: "src/loaders/svg/tvgSvgUtil.cpp", "src/loaders/svg/tvgXmlParser.cpp", "src/loaders/raw/tvgRawLoader.cpp", + # image loaders "src/loaders/external_png/tvgPngLoader.cpp", "src/loaders/jpg/tvgJpgd.cpp", "src/loaders/jpg/tvgJpgLoader.cpp", @@ -117,6 +118,7 @@ if env["thorvg_enabled"] and env["freetype_enabled"]: "../../../thirdparty/thorvg/src/loaders/raw", "../../../thirdparty/thorvg/src/loaders/external_png", "../../../thirdparty/thorvg/src/loaders/jpg", + "../../../thirdparty/libpng", ] ) diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 09a037fd28..361d88af90 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -851,7 +851,7 @@ _FORCE_INLINE_ TextServerAdvanced::FontTexturePosition TextServerAdvanced::find_ { // Zero texture. uint8_t *w = tex.image->ptrw(); - ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.image->data_size(), ret); + ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.image->get_data_size(), ret); // Initialize the texture to all-white pixels to prevent artifacts when the // font is displayed at a non-default scale with filtering enabled. if (p_color_size == 2) { @@ -1040,7 +1040,7 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_msdf( for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * 4; - ERR_FAIL_COND_V(ofs >= tex.image->data_size(), FontGlyph()); + ERR_FAIL_COND_V(ofs >= tex.image->get_data_size(), FontGlyph()); wr[ofs + 0] = (uint8_t)(CLAMP(image(j, i)[0] * 256.f, 0.f, 255.f)); wr[ofs + 1] = (uint8_t)(CLAMP(image(j, i)[1] * 256.f, 0.f, 255.f)); wr[ofs + 2] = (uint8_t)(CLAMP(image(j, i)[2] * 256.f, 0.f, 255.f)); @@ -1118,7 +1118,7 @@ _FORCE_INLINE_ TextServerAdvanced::FontGlyph TextServerAdvanced::rasterize_bitma for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int ofs = ((i + tex_pos.y + p_rect_margin * 2) * tex.texture_w + j + tex_pos.x + p_rect_margin * 2) * color_size; - ERR_FAIL_COND_V(ofs >= tex.image->data_size(), FontGlyph()); + ERR_FAIL_COND_V(ofs >= tex.image->get_data_size(), FontGlyph()); switch (p_bitmap.pixel_mode) { case FT_PIXEL_MODE_MONO: { int byte = i * p_bitmap.pitch + (j >> 3); @@ -2468,7 +2468,7 @@ int64_t TextServerAdvanced::_font_get_spacing(const RID &p_font_rid, SpacingType } } -void TextServerAdvanced::_font_set_baseline_offset(const RID &p_font_rid, float p_baseline_offset) { +void TextServerAdvanced::_font_set_baseline_offset(const RID &p_font_rid, double p_baseline_offset) { FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid); if (fdv) { if (fdv->baseline_offset != p_baseline_offset) { @@ -2486,7 +2486,7 @@ void TextServerAdvanced::_font_set_baseline_offset(const RID &p_font_rid, float } } -float TextServerAdvanced::_font_get_baseline_offset(const RID &p_font_rid) const { +double TextServerAdvanced::_font_get_baseline_offset(const RID &p_font_rid) const { FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid); if (fdv) { return fdv->baseline_offset; @@ -7142,9 +7142,7 @@ PackedInt32Array TextServerAdvanced::_string_get_character_breaks(const String & } ubrk_close(bi); } else { - for (int i = 0; i <= p_string.size(); i++) { - ret.push_back(i); - } + return TextServer::string_get_character_breaks(p_string, p_language); } return ret; @@ -7342,7 +7340,7 @@ bool TextServerAdvanced::_is_valid_identifier(const String &p_string) const { return true; } -bool TextServerAdvanced::_is_valid_letter(char32_t p_unicode) const { +bool TextServerAdvanced::_is_valid_letter(uint64_t p_unicode) const { #ifndef ICU_STATIC_DATA if (!icu_data_loaded) { return TextServer::is_valid_letter(p_unicode); diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 8895a83089..92bdb93bcf 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -296,7 +296,7 @@ class TextServerAdvanced : public TextServerExtension { struct FontAdvancedLinkedVariation { RID base_font; int extra_spacing[4] = { 0, 0, 0, 0 }; - float baseline_offset = 0.0; + double baseline_offset = 0.0; }; struct FontAdvanced { @@ -325,7 +325,7 @@ class TextServerAdvanced : public TextServerExtension { int weight = 400; int stretch = 100; int extra_spacing[4] = { 0, 0, 0, 0 }; - float baseline_offset = 0.0; + double baseline_offset = 0.0; HashMap cache; @@ -578,7 +578,7 @@ class TextServerAdvanced : public TextServerExtension { double embolden = 0.0; Transform2D transform; int extra_spacing[4] = { 0, 0, 0, 0 }; - float baseline_offset = 0.0; + double baseline_offset = 0.0; bool operator==(const SystemFontKey &p_b) const { return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (disable_embedded_bitmaps == p_b.disable_embedded_bitmaps) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset); @@ -791,8 +791,8 @@ public: MODBIND3(font_set_spacing, const RID &, SpacingType, int64_t); MODBIND2RC(int64_t, font_get_spacing, const RID &, SpacingType); - MODBIND2(font_set_baseline_offset, const RID &, float); - MODBIND1RC(float, font_get_baseline_offset, const RID &); + MODBIND2(font_set_baseline_offset, const RID &, double); + MODBIND1RC(double, font_get_baseline_offset, const RID &); MODBIND2(font_set_transform, const RID &, const Transform2D &); MODBIND1RC(Transform2D, font_get_transform, const RID &); @@ -988,7 +988,7 @@ public: MODBIND1RC(String, strip_diacritics, const String &); MODBIND1RC(bool, is_valid_identifier, const String &); - MODBIND1RC(bool, is_valid_letter, char32_t); + MODBIND1RC(bool, is_valid_letter, uint64_t); MODBIND2RC(String, string_to_upper, const String &, const String &); MODBIND2RC(String, string_to_lower, const String &, const String &); -- cgit v1.2.3