diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-05-28 22:12:31 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-05-28 22:12:31 +0200 |
commit | 6f68cd3676fd61e74e4d10675d960a1b9fed58d6 (patch) | |
tree | 220642be68edda399ef3de839ee82732bd1d71a5 | |
parent | 193b2aacb78872084564e0f3398fb9cb0ed7983b (diff) | |
download | qtlocation-mapboxgl-6f68cd3676fd61e74e4d10675d960a1b9fed58d6.tar.gz |
return font stack
-rw-r--r-- | include/llmr/text/glyph_store.hpp | 13 | ||||
-rw-r--r-- | src/map/tile_parser.cpp | 2 | ||||
-rw-r--r-- | src/text/glyph_store.cpp | 28 |
3 files changed, 33 insertions, 10 deletions
diff --git a/include/llmr/text/glyph_store.hpp b/include/llmr/text/glyph_store.hpp index c2d467e780..90fa6d908e 100644 --- a/include/llmr/text/glyph_store.hpp +++ b/include/llmr/text/glyph_store.hpp @@ -26,11 +26,14 @@ public: class FontStack { public: - void insert(uint32_t id, const SDFGlyph &glyph); + void insert(uint32_t id, const GlyphMetrics &glyphMetrics, const std::string &bitmap); + + const std::map<uint32_t, GlyphMetrics> &getMetrics() const; private: - std::map<uint32_t, SDFGlyph> glyphs; - std::mutex mtx; + std::map<uint32_t, std::string> bitmaps; + std::map<uint32_t, GlyphMetrics> metrics; + mutable std::mutex mtx; }; class GlyphPBF { @@ -54,10 +57,14 @@ public: // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges); + FontStack &getFontStack(const std::string &fontStack); + private: // Loads an individual glyph range from the font stack and adds it to rangeSets std::shared_future<GlyphPBF &> loadGlyphRange(const std::string &fontStack, std::map<GlyphRange, std::unique_ptr<GlyphPBF>> &rangeSets, GlyphRange range); + FontStack &createFontStack(const std::string &fontStack); + private: std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges; std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks; diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index f44d464f11..744f6fe212 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -205,6 +205,8 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye glyphStore.waitForGlyphRanges(bucket_desc.geometry.font, ranges); } + const FontStack &fontStack = glyphStore.getFontStack(bucket_desc.geometry.font); + // Shape and place all labels. { FilteredVectorTileLayer filtered_layer(layer, bucket_desc); diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 65fe38bc4b..a355b28f24 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -9,11 +9,16 @@ namespace llmr { -void FontStack::insert(uint32_t id, const SDFGlyph &glyph) { +void FontStack::insert(uint32_t id, const GlyphMetrics &glyphMetrics, const std::string &bitmap) { std::lock_guard<std::mutex> lock(mtx); - glyphs.emplace(id, glyph); + metrics.emplace(id, glyphMetrics); + bitmaps.emplace(id, bitmap); } +const std::map<uint32_t, GlyphMetrics> &FontStack::getMetrics() const { + std::lock_guard<std::mutex> lock(mtx); + return metrics; +} GlyphPBF::GlyphPBF(const std::string &fontStack, GlyphRange glyphRange) : future(promise.get_future().share()) @@ -112,11 +117,7 @@ void GlyphStore::waitForGlyphRanges(const std::string &fontStack, const std::set std::lock_guard<std::mutex> lock(mtx); auto &rangeSets = ranges[fontStack]; - auto stack_it = stacks.find(fontStack); - if (stack_it == stacks.end()) { - stack_it = stacks.emplace(fontStack, std::make_unique<FontStack>()).first; - } - stack = stack_it->second.get(); + stack = &createFontStack(fontStack); // Attempt to load the glyph range. If the GlyphSet already exists, we are getting back // the same shared_future. @@ -143,5 +144,18 @@ std::shared_future<GlyphPBF &> GlyphStore::loadGlyphRange(const std::string &nam return range_it->second->getFuture(); } +FontStack &GlyphStore::createFontStack(const std::string &fontStack) { + auto stack_it = stacks.find(fontStack); + if (stack_it == stacks.end()) { + stack_it = stacks.emplace(fontStack, std::make_unique<FontStack>()).first; + } + return *stack_it->second.get(); +} + +FontStack &GlyphStore::getFontStack(const std::string &fontStack) { + std::lock_guard<std::mutex> lock(mtx); + return createFontStack(fontStack); +} + } |