From 6f68cd3676fd61e74e4d10675d960a1b9fed58d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 28 May 2014 22:12:31 +0200 Subject: return font stack --- include/llmr/text/glyph_store.hpp | 13 ++++++++++--- src/map/tile_parser.cpp | 2 ++ 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 &getMetrics() const; private: - std::map glyphs; - std::mutex mtx; + std::map bitmaps; + std::map 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 &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 loadGlyphRange(const std::string &fontStack, std::map> &rangeSets, GlyphRange range); + FontStack &createFontStack(const std::string &fontStack); + private: std::unordered_map>> ranges; std::unordered_map> 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 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 lock(mtx); - glyphs.emplace(id, glyph); + metrics.emplace(id, glyphMetrics); + bitmaps.emplace(id, bitmap); } +const std::map &FontStack::getMetrics() const { + std::lock_guard 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 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()).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 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()).first; + } + return *stack_it->second.get(); +} + +FontStack &GlyphStore::getFontStack(const std::string &fontStack) { + std::lock_guard lock(mtx); + return createFontStack(fontStack); +} + } -- cgit v1.2.1