From 0c5d805bf9ac14eeaaaef8c08281a3e6f33ddb0b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 22 Apr 2016 13:28:03 -0700 Subject: [PATCH] =?UTF-8?q?[core]=20FontStack=20=E2=87=A2=20GlyphSet=20(#4?= =?UTF-8?q?803)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A font stack is an array of font names. This is not that. --- src/mbgl/geometry/glyph_atlas.cpp | 6 ++---- src/mbgl/geometry/glyph_atlas.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 8 ++++---- src/mbgl/text/glyph_pbf.cpp | 8 ++++---- src/mbgl/text/glyph_pbf.hpp | 2 +- src/mbgl/text/{font_stack.cpp => glyph_set.cpp} | 13 +++++++------ src/mbgl/text/{font_stack.hpp => glyph_set.hpp} | 6 +++--- src/mbgl/text/glyph_store.cpp | 12 ++++++------ src/mbgl/text/glyph_store.hpp | 12 ++++++------ test/style/glyph_store.cpp | 14 +++++++------- 10 files changed, 41 insertions(+), 42 deletions(-) rename src/mbgl/text/{font_stack.cpp => glyph_set.cpp} (95%) rename src/mbgl/text/{font_stack.hpp => glyph_set.hpp} (90%) diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp index 046ba4652..92fc7903b 100644 --- a/src/mbgl/geometry/glyph_atlas.cpp +++ b/src/mbgl/geometry/glyph_atlas.cpp @@ -1,7 +1,5 @@ #include -#include - #include #include #include @@ -27,12 +25,12 @@ GlyphAtlas::~GlyphAtlas() { void GlyphAtlas::addGlyphs(uintptr_t tileUID, const std::u32string& text, const std::string& stackName, - const FontStack& fontStack, + const GlyphSet& glyphSet, GlyphPositions& face) { std::lock_guard lock(mtx); - const std::map& sdfs = fontStack.getSDFs(); + const std::map& sdfs = glyphSet.getSDFs(); for (uint32_t chr : text) { diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp index 2758ac7ce..9b8af9f75 100644 --- a/src/mbgl/geometry/glyph_atlas.hpp +++ b/src/mbgl/geometry/glyph_atlas.hpp @@ -23,7 +23,7 @@ public: void addGlyphs(uintptr_t tileUID, const std::u32string& text, const std::string& stackName, - const FontStack&, + const GlyphSet&, GlyphPositions&); void removeGlyphs(uintptr_t tileUID); diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 146fd8590..cdb30bf22 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -225,7 +225,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID, layout.textJustify == TextJustifyType::Left ? 0 : 0.5; - auto fontStack = glyphStore.getFontStack(layout.textFont); + auto glyphSet = glyphStore.getGlyphSet(layout.textFont); for (const auto& feature : features) { if (feature.geometry.empty()) continue; @@ -236,7 +236,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID, // if feature has text, shape the text if (feature.label.length()) { - shapedText = fontStack->getShaping( + shapedText = glyphSet->getShaping( /* string */ feature.label, /* maxWidth: ems */ layout.symbolPlacement != SymbolPlacementType::Line ? layout.textMaxWidth * 24 : 0, @@ -249,7 +249,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID, // Add the glyphs we need for this label to the glyph atlas. if (shapedText) { - glyphAtlas.addGlyphs(tileUID, feature.label, layout.textFont, **fontStack, face); + glyphAtlas.addGlyphs(tileUID, feature.label, layout.textFont, **glyphSet, face); } } diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp index c9466e865..105ea4519 100644 --- a/src/mbgl/text/glyph_pbf.cpp +++ b/src/mbgl/text/glyph_pbf.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -13,7 +13,7 @@ namespace { -void parseGlyphPBF(mbgl::FontStack& stack, const std::string& data) { +void parseGlyphPBF(mbgl::GlyphSet& glyphSet, const std::string& data) { mbgl::pbf glyphs_pbf(reinterpret_cast(data.data()), data.size()); while (glyphs_pbf.next()) { @@ -45,7 +45,7 @@ void parseGlyphPBF(mbgl::FontStack& stack, const std::string& data) { } } - stack.insert(glyph.id, glyph); + glyphSet.insert(glyph.id, glyph); } else { fontstack_pbf.skip(); } @@ -77,7 +77,7 @@ GlyphPBF::GlyphPBF(GlyphStore* store, observer->onGlyphsLoaded(fontStack, glyphRange); } else { try { - parseGlyphPBF(**store->getFontStack(fontStack), *res.data); + parseGlyphPBF(**store->getGlyphSet(fontStack), *res.data); } catch (...) { observer->onGlyphsError(fontStack, glyphRange, std::current_exception()); return; diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp index 93b7c9db7..5b47563f7 100644 --- a/src/mbgl/text/glyph_pbf.hpp +++ b/src/mbgl/text/glyph_pbf.hpp @@ -12,7 +12,7 @@ namespace mbgl { -class FontStack; +class GlyphSet; class AsyncRequest; class FileSource; diff --git a/src/mbgl/text/font_stack.cpp b/src/mbgl/text/glyph_set.cpp similarity index 95% rename from src/mbgl/text/font_stack.cpp rename to src/mbgl/text/glyph_set.cpp index 60e90a77e..40041dff9 100644 --- a/src/mbgl/text/font_stack.cpp +++ b/src/mbgl/text/glyph_set.cpp @@ -1,11 +1,12 @@ -#include -#include +#include #include #include +#include + namespace mbgl { -void FontStack::insert(uint32_t id, const SDFGlyph &glyph) { +void GlyphSet::insert(uint32_t id, const SDFGlyph &glyph) { auto it = sdfs.find(id); if (it == sdfs.end()) { // Glyph doesn't exist yet. @@ -25,11 +26,11 @@ void FontStack::insert(uint32_t id, const SDFGlyph &glyph) { } } -const std::map &FontStack::getSDFs() const { +const std::map &GlyphSet::getSDFs() const { return sdfs; } -const Shaping FontStack::getShaping(const std::u32string &string, const float maxWidth, +const Shaping GlyphSet::getShaping(const std::u32string &string, const float maxWidth, const float lineHeight, const float horizontalAlign, const float verticalAlign, const float justify, const float spacing, const vec2 &translate) const { @@ -84,7 +85,7 @@ void justifyLine(std::vector &positionedGlyphs, const std::map< } } -void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float maxWidth, +void GlyphSet::lineWrap(Shaping &shaping, const float lineHeight, const float maxWidth, const float horizontalAlign, const float verticalAlign, const float justify, const vec2 &translate) const { uint32_t lastSafeBreak = 0; diff --git a/src/mbgl/text/font_stack.hpp b/src/mbgl/text/glyph_set.hpp similarity index 90% rename from src/mbgl/text/font_stack.hpp rename to src/mbgl/text/glyph_set.hpp index d81460a53..571407165 100644 --- a/src/mbgl/text/font_stack.hpp +++ b/src/mbgl/text/glyph_set.hpp @@ -1,12 +1,12 @@ -#ifndef MBGL_TEXT_FONT_STACK -#define MBGL_TEXT_FONT_STACK +#ifndef MBGL_TEXT_GLYPH_SET +#define MBGL_TEXT_GLYPH_SET #include #include namespace mbgl { -class FontStack { +class GlyphSet { public: void insert(uint32_t id, const SDFGlyph &glyph); const std::map &getSDFs() const; diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index cd960dd8e..9f6a6b7b7 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -53,15 +53,15 @@ bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set return hasRanges; } -util::exclusive GlyphStore::getFontStack(const std::string& fontStack) { - auto lock = std::make_unique>(stacksMutex); +util::exclusive GlyphStore::getGlyphSet(const std::string& fontStack) { + auto lock = std::make_unique>(glyphSetsMutex); - auto it = stacks.find(fontStack); - if (it == stacks.end()) { - it = stacks.emplace(fontStack, std::make_unique()).first; + auto it = glyphSets.find(fontStack); + if (it == glyphSets.end()) { + it = glyphSets.emplace(fontStack, std::make_unique()).first; } - // FIXME: We lock all FontStacks, but what we should + // FIXME: We lock all GlyphSets, but what we should // really do is lock only the one we are returning. return { it->second.get(), std::move(lock) }; } diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index 682939785..5b80589f4 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -1,8 +1,8 @@ #ifndef MBGL_TEXT_GLYPH_STORE #define MBGL_TEXT_GLYPH_STORE -#include #include +#include #include #include #include @@ -18,7 +18,7 @@ class FileSource; class GlyphPBF; // The GlyphStore manages the loading and storage of Glyphs -// and creation of FontStack objects. The GlyphStore lives +// and creation of GlyphSet objects. The GlyphStore lives // on the MapThread but can be queried from any thread. class GlyphStore : private util::noncopyable { public: @@ -33,12 +33,12 @@ public: GlyphStore(FileSource&); ~GlyphStore(); - util::exclusive getFontStack(const std::string& fontStack); + util::exclusive getGlyphSet(const std::string& fontStack); // Returns true if the set of GlyphRanges are available and parsed or false // if they are not. For the missing ranges, a request on the FileSource is // made and when the glyph if finally parsed, it gets added to the respective - // FontStack and a signal is emitted to notify the observers. This method + // GlyphSet and a signal is emitted to notify the observers. This method // can be called from any thread. bool hasGlyphRanges(const std::string& fontStack, const std::set& glyphRanges); @@ -61,8 +61,8 @@ private: std::unordered_map>> ranges; std::mutex rangesMutex; - std::unordered_map> stacks; - std::mutex stacksMutex; + std::unordered_map> glyphSets; + std::mutex glyphSetsMutex; util::WorkQueue workQueue; diff --git a/test/style/glyph_store.cpp b/test/style/glyph_store.cpp index c101d45bd..96d112183 100644 --- a/test/style/glyph_store.cpp +++ b/test/style/glyph_store.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -53,8 +53,8 @@ TEST(GlyphStore, LoadingSuccess) { if (!test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}, {256, 511}})) return; - auto fontStack = test.glyphStore.getFontStack("Test Stack"); - ASSERT_FALSE(fontStack->getSDFs().empty()); + auto glyphSet = test.glyphStore.getGlyphSet("Test Stack"); + ASSERT_FALSE(glyphSet->getSDFs().empty()); test.end(); }; @@ -83,8 +83,8 @@ TEST(GlyphStore, LoadingFail) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "Failed by the test case"); - auto stack = test.glyphStore.getFontStack("Test Stack"); - ASSERT_TRUE(stack->getSDFs().empty()); + auto glyphSet = test.glyphStore.getGlyphSet("Test Stack"); + ASSERT_TRUE(glyphSet->getSDFs().empty()); ASSERT_FALSE(test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}})); test.end(); @@ -112,8 +112,8 @@ TEST(GlyphStore, LoadingCorrupted) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "pbf unknown field type exception"); - auto stack = test.glyphStore.getFontStack("Test Stack"); - ASSERT_TRUE(stack->getSDFs().empty()); + auto glyphSet = test.glyphStore.getGlyphSet("Test Stack"); + ASSERT_TRUE(glyphSet->getSDFs().empty()); ASSERT_FALSE(test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}})); test.end();