summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/text/glyph_pbf.cpp21
-rw-r--r--src/mbgl/text/glyph_pbf.hpp2
-rw-r--r--src/mbgl/text/glyph_set.cpp6
-rw-r--r--src/mbgl/text/glyph_set.hpp2
4 files changed, 20 insertions, 11 deletions
diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp
index 26eff812b7..c49f19c73a 100644
--- a/src/mbgl/text/glyph_pbf.cpp
+++ b/src/mbgl/text/glyph_pbf.cpp
@@ -14,10 +14,10 @@
namespace mbgl {
-namespace {
+std::vector<SDFGlyph> parseGlyphPBF(const GlyphRange& glyphRange, const std::string& data) {
+ std::vector<SDFGlyph> result;
+ result.reserve(256);
-// Parses a Glyph Protobuf and inserts it into the GlyphAtlas. Must be called from main thread.
-void parseGlyphPBF(GlyphSet& glyphSet, const GlyphRange& glyphRange, const std::string& data) {
protozero::pbf_reader glyphs_pbf(data);
while (glyphs_pbf.next(1)) {
@@ -94,12 +94,12 @@ void parseGlyphPBF(GlyphSet& glyphSet, const GlyphRange& glyphRange, const std::
glyph.bitmap = AlphaImage(size, reinterpret_cast<const uint8_t*>(glyphData.data()), glyphData.size());
}
- glyphSet.insert(glyph.id, std::move(glyph));
+ result.push_back(std::move(glyph));
}
}
-}
-} // namespace
+ return result;
+}
GlyphPBF::GlyphPBF(GlyphAtlas* atlas,
const FontStack& fontStack,
@@ -117,13 +117,20 @@ GlyphPBF::GlyphPBF(GlyphAtlas* atlas,
parsed = true;
observer->onGlyphsLoaded(fontStack, glyphRange);
} else {
+ std::vector<SDFGlyph> glyphs;
+
try {
- parseGlyphPBF(atlas->getGlyphSet(fontStack), glyphRange, *res.data);
+ glyphs = parseGlyphPBF(glyphRange, *res.data);
} catch (...) {
observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
return;
}
+ GlyphSet& glyphSet = atlas->getGlyphSet(fontStack);
+ for (auto& glyph : glyphs) {
+ glyphSet.insert(std::move(glyph));
+ }
+
parsed = true;
observer->onGlyphsLoaded(fontStack, glyphRange);
}
diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp
index d5b89cd107..914338f1ec 100644
--- a/src/mbgl/text/glyph_pbf.hpp
+++ b/src/mbgl/text/glyph_pbf.hpp
@@ -18,6 +18,8 @@ class GlyphAtlasObserver;
class AsyncRequest;
class FileSource;
+std::vector<SDFGlyph> parseGlyphPBF(const GlyphRange&, const std::string& data);
+
class GlyphPBF : private util::noncopyable {
public:
GlyphPBF(GlyphAtlas*,
diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp
index b8e155502e..3305d4136e 100644
--- a/src/mbgl/text/glyph_set.cpp
+++ b/src/mbgl/text/glyph_set.cpp
@@ -3,11 +3,11 @@
namespace mbgl {
-void GlyphSet::insert(uint32_t id, SDFGlyph&& glyph) {
- auto it = sdfs.find(id);
+void GlyphSet::insert(SDFGlyph&& glyph) {
+ auto it = sdfs.find(glyph.id);
if (it == sdfs.end()) {
// Glyph doesn't exist yet.
- sdfs.emplace(id, std::move(glyph));
+ sdfs.emplace(glyph.id, std::move(glyph));
} else if (it->second.metrics == glyph.metrics) {
if (it->second.bitmap != glyph.bitmap) {
// The actual bitmap was updated; this is unsupported.
diff --git a/src/mbgl/text/glyph_set.hpp b/src/mbgl/text/glyph_set.hpp
index 9f4bef94d2..01d89c7f79 100644
--- a/src/mbgl/text/glyph_set.hpp
+++ b/src/mbgl/text/glyph_set.hpp
@@ -7,7 +7,7 @@ namespace mbgl {
class GlyphSet {
public:
- void insert(uint32_t id, SDFGlyph&&);
+ void insert(SDFGlyph&&);
const std::map<uint32_t, SDFGlyph>& getSDFs() const;
private: