return font stack

This commit is contained in:
Konstantin Käfer
2014-05-28 22:12:31 +02:00
parent 193b2aacb7
commit 6f68cd3676
3 changed files with 33 additions and 10 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}
}