Store shared original string to glyph layouts directly
This commit is contained in:
parent
474e2e025a
commit
33a4369a71
@ -9,7 +9,9 @@
|
||||
#include "dimension2d.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<std::u32string> orig_string;
|
||||
};
|
||||
|
||||
namespace Private
|
||||
|
@ -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<GlyphLayout>& gls, std::vector<std::u32string>* line_data = NULL) = 0;
|
||||
std::vector<GlyphLayout>& gls, u32 shape_flag = 0) = 0;
|
||||
|
||||
virtual f32 getInverseShaping() const = 0;
|
||||
virtual f32 getScale() const = 0;
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
bool vcenter=false, const core::rect<s32>* clip=0) {}
|
||||
|
||||
virtual void initGlyphLayouts(const core::stringw& text,
|
||||
std::vector<GlyphLayout>& gls, std::vector<std::u32string>* line_data = NULL) {}
|
||||
std::vector<GlyphLayout>& gls, u32 shape_flag = 0) {}
|
||||
|
||||
//! returns the dimension of a text
|
||||
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
|
||||
|
@ -263,8 +263,7 @@ namespace LineBreakingRules
|
||||
// ----------------------------------------------------------------------------
|
||||
/* Turn text into glyph layout for rendering by libraqm. */
|
||||
void FontManager::shape(const std::u32string& text,
|
||||
std::vector<irr::gui::GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* line_data)
|
||||
std::vector<irr::gui::GlyphLayout>& 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<std::u32string> orig_string =
|
||||
std::make_shared<std::u32string>(text);
|
||||
for (unsigned l = 0; l < lines.size(); l++)
|
||||
{
|
||||
std::vector<ShapeGlyph> 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<irr::gui::GlyphLayout>&
|
||||
} // 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<irr::gui::GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* 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;
|
||||
}
|
||||
|
||||
|
@ -132,8 +132,7 @@ public:
|
||||
unsigned getShapingDPI() const { return m_shaping_dpi; }
|
||||
// ------------------------------------------------------------------------
|
||||
void shape(const std::u32string& text,
|
||||
std::vector<irr::gui::GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* line_data = NULL);
|
||||
std::vector<irr::gui::GlyphLayout>& gls);
|
||||
// ------------------------------------------------------------------------
|
||||
std::vector<irr::gui::GlyphLayout>& getCachedLayouts
|
||||
(const irr::core::stringw& str);
|
||||
@ -142,7 +141,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
void initGlyphLayouts(const irr::core::stringw& text,
|
||||
std::vector<irr::gui::GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* line_data = NULL);
|
||||
irr::u32 shape_flag = 0);
|
||||
#endif
|
||||
// ------------------------------------------------------------------------
|
||||
void loadFonts();
|
||||
|
@ -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<GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* line_data)
|
||||
u32 shape_flag)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
font_manager->initGlyphLayouts(text, gls, line_data);
|
||||
font_manager->initGlyphLayouts(text, gls, shape_flag);
|
||||
#endif
|
||||
} // initGlyphLayouts
|
||||
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void initGlyphLayouts(const core::stringw& text,
|
||||
std::vector<GlyphLayout>& gls,
|
||||
std::vector<std::u32string>* line_data = NULL);
|
||||
u32 shape_flag = 0);
|
||||
// ------------------------------------------------------------------------
|
||||
/** returns the dimension of a text */
|
||||
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
|
||||
|
@ -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<std::u32string> text_line;
|
||||
std::vector<GlyphLayout> 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());
|
||||
|
Loading…
Reference in New Issue
Block a user