| 108 | } |
| 109 | |
| 110 | ref_ptr<Texture::ResourceInfo> GlyphIndex::MapResource(GlyphFontAndId const & key, bool & newResource) |
| 111 | { |
| 112 | newResource = false; |
| 113 | if (auto const found = m_index.find(key); found != m_index.end()) |
| 114 | return make_ref(&found->second); |
| 115 | |
| 116 | newResource = true; |
| 117 | |
| 118 | constexpr bool kUseSdf = true; |
| 119 | GlyphImage glyphImage = m_mng->GetGlyphImage(key, dp::kBaseFontSizePixels, kUseSdf); |
| 120 | m2::RectU r; |
| 121 | if (!m_packer.PackGlyph(glyphImage.m_width, glyphImage.m_height, r)) |
| 122 | { |
| 123 | glyphImage.Destroy(); |
| 124 | |
| 125 | LOG(LWARNING, ("Glyphs packer could not pack a glyph with fontIndex =", key.m_fontIndex, "glyphId =", key.m_glyphId, |
| 126 | "w =", glyphImage.m_width, "h =", glyphImage.m_height, "packerSize =", m_packer.GetSize())); |
| 127 | |
| 128 | // TODO(AB): Is it a valid invalid glyph? |
| 129 | GlyphFontAndId constexpr kInvalidGlyphKey{0, 0}; |
| 130 | if (auto const found = m_index.find(kInvalidGlyphKey); found != m_index.end()) |
| 131 | { |
| 132 | newResource = false; |
| 133 | return make_ref(&found->second); |
| 134 | } |
| 135 | |
| 136 | LOG(LERROR, ("Invalid glyph was not found in the index")); |
| 137 | |
| 138 | return nullptr; |
| 139 | } |
| 140 | |
| 141 | auto res = m_index.emplace(key, GlyphInfo{m_packer.MapTextureCoords(r)}); |
| 142 | ASSERT(res.second, ()); |
| 143 | |
| 144 | { |
| 145 | std::lock_guard lock(m_mutex); |
| 146 | m_pendingNodes.emplace_back(r, Glyph{std::move(glyphImage), key}); |
| 147 | } |
| 148 | |
| 149 | return make_ref(&res.first->second); |
| 150 | } |
| 151 | |
| 152 | bool GlyphIndex::CanBeGlyphPacked(uint32_t glyphsCount) const |
| 153 | { |
no test coverage detected