diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-12-27 02:07:08 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2017-01-09 14:11:29 +0300 |
commit | ef4348e4bad8127ff79998835ef292da59237e8f (patch) | |
tree | 64959129e6f5214345853022334d3e40ead9307f /drape | |
parent | 96b5b1f78456750554e8ac1a003672d192f38ebd (diff) |
Glyph borders added.
Diffstat (limited to 'drape')
-rw-r--r-- | drape/font_texture.cpp | 4 | ||||
-rw-r--r-- | drape/glyph_manager.cpp | 36 | ||||
-rw-r--r-- | drape/texture_manager.hpp | 2 |
3 files changed, 31 insertions, 11 deletions
diff --git a/drape/font_texture.cpp b/drape/font_texture.cpp index a036bf16a5..5e4b59ade8 100644 --- a/drape/font_texture.cpp +++ b/drape/font_texture.cpp @@ -78,8 +78,8 @@ m2::RectF GlyphPacker::MapTextureCoords(const m2::RectU & pixelRect) const // Half-pixel offset to eliminate arfefacts on fetching from texture. float offset = 0.0f; - //if (pixelRect.SizeX() != 0 && pixelRect.SizeY() != 0) - // offset = 0.5f; + if (pixelRect.SizeX() != 0 && pixelRect.SizeY() != 0) + offset = 0.5f; return m2::RectF((pixelRect.minX() + offset) / fWidth, (pixelRect.minY() + offset) / fHeight, diff --git a/drape/glyph_manager.cpp b/drape/glyph_manager.cpp index 4ec0b1a968..cf5330c1d9 100644 --- a/drape/glyph_manager.cpp +++ b/drape/glyph_manager.cpp @@ -66,6 +66,7 @@ namespace { uint32_t const kSdfBorder = 4; +double const kNonSdfBorder = 0.2; int const kInvalidFont = -1; template <typename ToDo> @@ -199,10 +200,10 @@ public: float const scale = isSdf ? 1.0f / m_sdfScale : 1.0; - SharedBufferManager::shared_buffer_ptr_t data; int imageWidth = bitmap.width; int imageHeight = bitmap.rows; + int border = 0; if (bitmap.buffer != nullptr) { if (isSdf) @@ -210,10 +211,29 @@ public: sdf_image::SdfImage img(bitmap.rows, bitmap.pitch, bitmap.buffer, m_sdfScale * kSdfBorder); imageWidth = img.GetWidth() * scale; imageHeight = img.GetHeight() * scale; + + size_t const bufferSize = bitmap.rows * bitmap.pitch; + data = SharedBufferManager::instance().reserveSharedBuffer(bufferSize); + memcpy(&(*data)[0], bitmap.buffer, bufferSize); + } + else + { + border = glyphHeight * kNonSdfBorder; + imageHeight += 2 * border; + imageWidth += 2 * border; + + size_t const bufferSize = imageWidth * imageHeight; + data = SharedBufferManager::instance().reserveSharedBuffer(bufferSize); + memset(data->data(), 0, data->size()); + + for (size_t row = border; row < bitmap.rows + border; ++row) + { + size_t const dstBaseIndex = row * imageWidth + border; + size_t const srcBaseIndex = (row - border) * bitmap.pitch; + for (size_t column = 0; column < bitmap.pitch; ++column) + data->data()[dstBaseIndex + column] = bitmap.buffer[srcBaseIndex + column]; + } } - size_t bufferSize = bitmap.rows * bitmap.pitch; - data = SharedBufferManager::instance().reserveSharedBuffer(bufferSize); - memcpy(&(*data)[0], bitmap.buffer, bufferSize); } GlyphManager::Glyph result; @@ -227,9 +247,9 @@ public: result.m_metrics = GlyphManager::GlyphMetrics { static_cast<float>(glyph->advance.x >> 16) * scale, - static_cast<float>(glyph->advance.y >> 16) * scale, - static_cast<float>(bbox.xMin) * scale, - static_cast<float>(bbox.yMin) * scale, + static_cast<float>(glyph->advance.y >> 16) * scale, + static_cast<float>(bbox.xMin) * scale + border, + static_cast<float>(bbox.yMin) * scale + border, true }; @@ -323,7 +343,7 @@ private: FT_Face m_fontFace; uint32_t m_sdfScale; - set<pair<strings::UniChar, int>> m_readyGlyphs; + std::set<pair<strings::UniChar, int>> m_readyGlyphs; }; } diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index c02de9e9b4..e7308a8aa7 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -126,7 +126,7 @@ private: : m_texture(nullptr) {} - set<pair<strings::UniChar, int> > m_glyphs; + std::set<pair<strings::UniChar, int> > m_glyphs; ref_ptr<Texture> m_texture; }; |