From 33a4369a71e999ab149e744fd15bde1f7979d24e Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 3 Sep 2021 13:09:42 +0800 Subject: [PATCH] Store shared original string to glyph layouts directly --- lib/irrlicht/include/GlyphLayout.h | 9 +++++++++ lib/irrlicht/include/IGUIFont.h | 6 ++---- lib/irrlicht/source/Irrlicht/CGUIFont.h | 2 +- src/font/font_manager.cpp | 19 +++++++++---------- src/font/font_manager.hpp | 5 ++--- src/guiengine/scalable_font.cpp | 10 ++++------ src/guiengine/scalable_font.hpp | 2 +- .../online/networking_lobby.cpp | 4 +--- 8 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/irrlicht/include/GlyphLayout.h b/lib/irrlicht/include/GlyphLayout.h index 1016e53bd..d7d37028e 100644 --- a/lib/irrlicht/include/GlyphLayout.h +++ b/lib/irrlicht/include/GlyphLayout.h @@ -9,7 +9,9 @@ #include "dimension2d.h" #include +#include #include +#include #include namespace irr @@ -17,6 +19,11 @@ namespace irr namespace gui { +enum ShapeFlag +{ +SF_DISABLE_CACHE = 1, /* Disable caching glyph layouts. */ +}; + enum GlyphLayoutFlag { GLF_RTL_LINE = 1, /* This line from this glyph is RTL. */ @@ -51,6 +58,8 @@ u32 original_index; u16 flags; //! this is the face_idx used in stk face ttf u16 face_idx; +//! original string, which is used to map with cluster above +std::shared_ptr orig_string; }; namespace Private diff --git a/lib/irrlicht/include/IGUIFont.h b/lib/irrlicht/include/IGUIFont.h index dd371693a..21b152a36 100644 --- a/lib/irrlicht/include/IGUIFont.h +++ b/lib/irrlicht/include/IGUIFont.h @@ -120,11 +120,9 @@ public: */ virtual void setInvisibleCharacters( const wchar_t *s ) = 0; - //! Convert text to glyph layouts for fast rendering with caching enabled - /* If line_data is not null, each broken line u32string will be saved and - can be used for advanced glyph and text mapping, and cache will be disabled. */ + //! Convert text to glyph layouts for fast rendering with optional caching enabled. */ virtual void initGlyphLayouts(const core::stringw& text, - std::vector& gls, std::vector* line_data = NULL) = 0; + std::vector& gls, u32 shape_flag = 0) = 0; virtual f32 getInverseShaping() const = 0; virtual f32 getScale() const = 0; diff --git a/lib/irrlicht/source/Irrlicht/CGUIFont.h b/lib/irrlicht/source/Irrlicht/CGUIFont.h index 713e4f053..fb60fd774 100644 --- a/lib/irrlicht/source/Irrlicht/CGUIFont.h +++ b/lib/irrlicht/source/Irrlicht/CGUIFont.h @@ -65,7 +65,7 @@ public: bool vcenter=false, const core::rect* clip=0) {} virtual void initGlyphLayouts(const core::stringw& text, - std::vector& gls, std::vector* line_data = NULL) {} + std::vector& gls, u32 shape_flag = 0) {} //! returns the dimension of a text virtual core::dimension2d getDimension(const wchar_t* text) const; diff --git a/src/font/font_manager.cpp b/src/font/font_manager.cpp index eb642a898..519b57c40 100644 --- a/src/font/font_manager.cpp +++ b/src/font/font_manager.cpp @@ -263,8 +263,7 @@ namespace LineBreakingRules // ---------------------------------------------------------------------------- /* Turn text into glyph layout for rendering by libraqm. */ void FontManager::shape(const std::u32string& text, - std::vector& gls, - std::vector* line_data) + std::vector& gls) { // Helper struct struct ShapeGlyph @@ -302,6 +301,8 @@ void FontManager::shape(const std::u32string& text, lines.push_back(U""); int start = 0; + std::shared_ptr orig_string = + std::make_shared(text); for (unsigned l = 0; l < lines.size(); l++) { std::vector glyphs; @@ -516,6 +517,7 @@ void FontManager::shape(const std::u32string& text, gl.flags |= gui::GLF_RTL_CHAR; if (FT_HAS_COLOR(glyphs[idx].ftface)) gl.flags |= gui::GLF_COLORED; + gl.orig_string = orig_string; cur_line.push_back(gl); } // Sort glyphs in logical order @@ -590,22 +592,19 @@ std::vector& } // getCachedLayouts // ---------------------------------------------------------------------------- -/** Convert text to glyph layouts for fast rendering with caching enabled - * If line_data is not null, each broken line u32string will be saved and - * can be used for advanced glyph and text mapping, and cache will be - * disabled, no newline characters are allowed in text if line_data is not - * NULL. +/** Convert text to glyph layouts for fast rendering with (optional) caching + * enabled. */ void FontManager::initGlyphLayouts(const core::stringw& text, std::vector& gls, - std::vector* line_data) + u32 shape_flag) { if (GUIEngine::isNoGraphics() || text.empty()) return; - if (line_data != NULL) + if ((shape_flag & gui::SF_DISABLE_CACHE) != 0) { - shape(StringUtils::wideToUtf32(text), gls, line_data); + shape(StringUtils::wideToUtf32(text), gls); return; } diff --git a/src/font/font_manager.hpp b/src/font/font_manager.hpp index 9091768cd..b02f1f858 100644 --- a/src/font/font_manager.hpp +++ b/src/font/font_manager.hpp @@ -132,8 +132,7 @@ public: unsigned getShapingDPI() const { return m_shaping_dpi; } // ------------------------------------------------------------------------ void shape(const std::u32string& text, - std::vector& gls, - std::vector* line_data = NULL); + std::vector& gls); // ------------------------------------------------------------------------ std::vector& getCachedLayouts (const irr::core::stringw& str); @@ -142,7 +141,7 @@ public: // ------------------------------------------------------------------------ void initGlyphLayouts(const irr::core::stringw& text, std::vector& gls, - std::vector* line_data = NULL); + irr::u32 shape_flag = 0); #endif // ------------------------------------------------------------------------ void loadFonts(); diff --git a/src/guiengine/scalable_font.cpp b/src/guiengine/scalable_font.cpp index 37530cbb0..202268cdc 100644 --- a/src/guiengine/scalable_font.cpp +++ b/src/guiengine/scalable_font.cpp @@ -154,17 +154,15 @@ s32 ScalableFont::getHeightPerLine() const } // getHeightPerLine // ---------------------------------------------------------------------------- -/** Convert text to glyph layouts for fast rendering with caching enabled - * If line_data is not null, each broken line u32string will be saved and - * can be used for advanced glyph and text mapping, and cache will be - * disabled. +/** Convert text to glyph layouts for fast rendering with optional caching + * enabled. */ void ScalableFont::initGlyphLayouts(const core::stringw& text, std::vector& gls, - std::vector* line_data) + u32 shape_flag) { #ifndef SERVER_ONLY - font_manager->initGlyphLayouts(text, gls, line_data); + font_manager->initGlyphLayouts(text, gls, shape_flag); #endif } // initGlyphLayouts diff --git a/src/guiengine/scalable_font.hpp b/src/guiengine/scalable_font.hpp index db1d9c5c1..498f5fd89 100644 --- a/src/guiengine/scalable_font.hpp +++ b/src/guiengine/scalable_font.hpp @@ -89,7 +89,7 @@ public: // ------------------------------------------------------------------------ virtual void initGlyphLayouts(const core::stringw& text, std::vector& gls, - std::vector* line_data = NULL); + u32 shape_flag = 0); // ------------------------------------------------------------------------ /** returns the dimension of a text */ virtual core::dimension2d getDimension(const wchar_t* text) const; diff --git a/src/states_screens/online/networking_lobby.cpp b/src/states_screens/online/networking_lobby.cpp index 9d6d3ba94..0d37ebe0e 100644 --- a/src/states_screens/online/networking_lobby.cpp +++ b/src/states_screens/online/networking_lobby.cpp @@ -265,10 +265,8 @@ void NetworkingLobby::addMoreServerInfo(core::stringw info) #ifndef SERVER_ONLY const unsigned box_width = m_text_bubble->getDimension().Width; const float box_height = m_text_bubble->getDimension().Height; - // For future copy text from lobby chat - std::vector text_line; std::vector cur_info; - font_manager->initGlyphLayouts(info, cur_info, &text_line); + font_manager->initGlyphLayouts(info, cur_info, gui::SF_DISABLE_CACHE); gui::IGUIFont* font = GUIEngine::getFont(); gui::breakGlyphLayouts(cur_info, box_width, font->getInverseShaping(), font->getScale());