diff --git a/drape/glyph_manager.cpp b/drape/glyph_manager.cpp index 432b929fe8..19f0f4b79a 100644 --- a/drape/glyph_manager.cpp +++ b/drape/glyph_manager.cpp @@ -10,7 +10,6 @@ #include "base/math.hpp" #include "base/timer.hpp" -#include "std/mutex.hpp" #include "std/unique_ptr.hpp" #include "std/unordered_set.hpp" @@ -311,14 +310,14 @@ struct UnicodeBlock int GetFontOffset(int idx) const { if (m_fontsWeight.empty()) - return -1; + return kInvalidFont; int maxWight = 0; int upperBoundWeight = numeric_limits::max(); - if (idx != -1) + if (idx != kInvalidFont) upperBoundWeight = m_fontsWeight[idx]; - int index = -1; + int index = kInvalidFont; for (size_t i = 0; i < m_fontsWeight.size(); ++i) { int w = m_fontsWeight[i]; @@ -475,7 +474,7 @@ GlyphManager::GlyphManager(GlyphManager::Params const & params) GlyphManager::~GlyphManager() { - for (unique_ptr const & f : m_impl->m_fonts) + for (auto const & f : m_impl->m_fonts) f->DestroyFont(); FREETYPE_CHECK(FT_Done_FreeType(m_impl->m_library)); @@ -525,20 +524,14 @@ int GlyphManager::GetFontIndexImmutable(strings::UniChar unicodePoint) const int GlyphManager::FindFontIndexInBlock(UnicodeBlock const & block, strings::UniChar unicodePoint) const { - int fontIndex = kInvalidFont; ASSERT(block.HasSymbol(unicodePoint), ()); - do + for (int fontIndex = block.GetFontOffset(kInvalidFont); fontIndex != kInvalidFont; fontIndex = block.GetFontOffset(fontIndex)) { - if (fontIndex != kInvalidFont) - { - ASSERT_LESS(fontIndex, m_impl->m_fonts.size(), ()); - unique_ptr const & f = m_impl->m_fonts[fontIndex]; - if (f->HasGlyph(unicodePoint)) - return fontIndex; - } - fontIndex = block.GetFontOffset(fontIndex); + ASSERT_LESS(fontIndex, m_impl->m_fonts.size(), ()); + auto const & f = m_impl->m_fonts[fontIndex]; + if (f->HasGlyph(unicodePoint)) + return fontIndex; } - while(fontIndex != kInvalidFont); return kInvalidFont; } @@ -549,7 +542,7 @@ GlyphManager::Glyph GlyphManager::GetGlyph(strings::UniChar unicodePoint) if (fontIndex == kInvalidFont) return GetInvalidGlyph(); - unique_ptr const & f = m_impl->m_fonts[fontIndex]; + auto const & f = m_impl->m_fonts[fontIndex]; Glyph glyph = f->GetGlyph(unicodePoint, m_impl->m_baseGlyphHeight); glyph.m_fontIndex = fontIndex; return glyph; @@ -559,7 +552,7 @@ GlyphManager::Glyph GlyphManager::GenerateGlyph(Glyph const & glyph) const { ASSERT_NOT_EQUAL(glyph.m_fontIndex, -1, ()); ASSERT_LESS(glyph.m_fontIndex, m_impl->m_fonts.size(), ()); - unique_ptr const & f = m_impl->m_fonts[glyph.m_fontIndex]; + auto const & f = m_impl->m_fonts[glyph.m_fontIndex]; return f->GenerateGlyph(glyph); } @@ -578,7 +571,7 @@ void GlyphManager::MarkGlyphReady(Glyph const & glyph) bool GlyphManager::AreGlyphsReady(strings::UniString const & str) const { - for (strings::UniChar const & code : str) + for (auto const & code : str) { int const fontIndex = GetFontIndexImmutable(code); if (fontIndex == kInvalidFont) diff --git a/drape/glyph_manager.hpp b/drape/glyph_manager.hpp index 52d6fe90e5..0e2b8c2cf6 100644 --- a/drape/glyph_manager.hpp +++ b/drape/glyph_manager.hpp @@ -87,6 +87,7 @@ public: private: int GetFontIndex(strings::UniChar unicodePoint); + // Immutable version can be called from any thread and doesn't require internal synchronization. int GetFontIndexImmutable(strings::UniChar unicodePoint) const; int FindFontIndexInBlock(UnicodeBlock const & block, strings::UniChar unicodePoint) const; diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 32a6e53de5..1db94de932 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -33,8 +33,8 @@ size_t const kDuplicatedGlyphsCount = 128; size_t const kReservedPatterns = 10; size_t const kReservedColors = 20; -float const kGlyphAreaMultiplier = 1.2; -float const kGlyphAreaCoverage = 0.9; +float const kGlyphAreaMultiplier = 1.2f; +float const kGlyphAreaCoverage = 0.9f; namespace { @@ -266,7 +266,7 @@ size_t TextureManager::FindGlyphsGroup(strings::UniChar const & c) const size_t TextureManager::FindGlyphsGroup(strings::UniString const & text) const { size_t groupIndex = kInvalidGlyphGroup; - for (strings::UniChar const & c : text) + for (auto const & c : text) { // skip glyphs which can be duplicated if (c < kDuplicatedGlyphsCount) @@ -313,7 +313,7 @@ size_t TextureManager::FindGlyphsGroup(TMultilineText const & text) const size_t TextureManager::GetNumberOfUnfoundCharacters(strings::UniString const & text, HybridGlyphGroup const & group) const { size_t cnt = 0; - for (strings::UniChar const & c : text) + for (auto const & c : text) if (group.m_glyphs.find(c) == group.m_glyphs.end()) cnt++; @@ -322,7 +322,7 @@ size_t TextureManager::GetNumberOfUnfoundCharacters(strings::UniString const & t void TextureManager::MarkCharactersUsage(strings::UniString const & text, HybridGlyphGroup & group) { - for (strings::UniChar const & c : text) + for (auto const & c : text) group.m_glyphs.emplace(c); } diff --git a/drape_frontend/gui/gui_text.cpp b/drape_frontend/gui/gui_text.cpp index cff0f5b8bc..8b80113ddb 100644 --- a/drape_frontend/gui/gui_text.cpp +++ b/drape_frontend/gui/gui_text.cpp @@ -125,9 +125,8 @@ void StaticLabel::CacheStaticText(string const & text, char const * delim, ASSERT(!textParts.empty(), ()); - for (strings::UniString const & str : textParts) - for (strings::UniChar const & c : str) - result.m_alphabet.insert(c); + for (auto const & str : textParts) + result.m_alphabet.insert(str.begin(), str.end()); dp::TextureManager::TMultilineGlyphsBuffer buffers; mng->GetGlyphRegions(textParts, buffers); @@ -576,12 +575,10 @@ StaticLabelHandle::StaticLabelHandle(ref_ptr textureManager, m2::PointF const & size, TAlphabet const & alphabet) : TBase(anchor, pivot, size) + , m_alphabet(alphabet.begin(), alphabet.end()) , m_textureManager(textureManager) , m_glyphsReady(false) -{ - for (strings::UniChar const & c : alphabet) - m_alphabet.push_back(c); -} +{} bool StaticLabelHandle::Update(ScreenBase const & screen) { diff --git a/drape_frontend/text_handle.cpp b/drape_frontend/text_handle.cpp index 95dcdecb65..301ffaf616 100644 --- a/drape_frontend/text_handle.cpp +++ b/drape_frontend/text_handle.cpp @@ -59,10 +59,9 @@ void TextHandle::GetAttributeMutation(ref_ptr mutato bool TextHandle::Update(ScreenBase const & screen) { - if (m_glyphsReady) - return true; + if (!m_glyphsReady) + m_glyphsReady = m_textureManager->AreGlyphsReady(m_text); - m_glyphsReady = m_textureManager->AreGlyphsReady(m_text); return m_glyphsReady; } diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp index cad0358e4d..0d399d7ecc 100644 --- a/drape_frontend/text_layout.cpp +++ b/drape_frontend/text_layout.cpp @@ -98,7 +98,7 @@ public: private: glsl::vec2 m_penPosition; gpu::TTextDynamicVertexBuffer & m_buffer; - float m_textRatio = 0.0; + float m_textRatio = 0.0f; bool m_isFirstGlyph = true; }; diff --git a/drape_frontend/text_layout.hpp b/drape_frontend/text_layout.hpp index fe3133bc6a..2d596695e7 100644 --- a/drape_frontend/text_layout.hpp +++ b/drape_frontend/text_layout.hpp @@ -50,7 +50,7 @@ protected: dp::TextureManager::TGlyphsBuffer m_metrics; strings::UniString m_text; - float m_textSizeRatio = 0.0; + float m_textSizeRatio = 0.0f; }; class StraightTextLayout : public TextLayout