[core] FontStack ⇢ GlyphSet (#4803)
A font stack is an array of font names. This is not that.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include <mbgl/geometry/glyph_atlas.hpp>
|
||||
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
|
||||
#include <mbgl/gl/gl.hpp>
|
||||
#include <mbgl/gl/gl_object_store.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
@@ -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<std::mutex> lock(mtx);
|
||||
|
||||
const std::map<uint32_t, SDFGlyph>& sdfs = fontStack.getSDFs();
|
||||
const std::map<uint32_t, SDFGlyph>& sdfs = glyphSet.getSDFs();
|
||||
|
||||
for (uint32_t chr : text)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <mbgl/text/get_anchors.hpp>
|
||||
#include <mbgl/renderer/painter.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/text/collision_tile.hpp>
|
||||
#include <mbgl/shader/sdf_shader.hpp>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/pbf.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -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<const uint8_t *>(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;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FontStack;
|
||||
class GlyphSet;
|
||||
class AsyncRequest;
|
||||
class FileSource;
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
#include <cassert>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/platform/log.hpp>
|
||||
#include <mbgl/util/math.hpp>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
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<uint32_t, SDFGlyph> &FontStack::getSDFs() const {
|
||||
const std::map<uint32_t, SDFGlyph> &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<float> &translate) const {
|
||||
@@ -84,7 +85,7 @@ void justifyLine(std::vector<PositionedGlyph> &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<float> &translate) const {
|
||||
uint32_t lastSafeBreak = 0;
|
||||
@@ -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 <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/util/vec.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FontStack {
|
||||
class GlyphSet {
|
||||
public:
|
||||
void insert(uint32_t id, const SDFGlyph &glyph);
|
||||
const std::map<uint32_t, SDFGlyph> &getSDFs() const;
|
||||
@@ -53,15 +53,15 @@ bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set
|
||||
return hasRanges;
|
||||
}
|
||||
|
||||
util::exclusive<FontStack> GlyphStore::getFontStack(const std::string& fontStack) {
|
||||
auto lock = std::make_unique<std::lock_guard<std::mutex>>(stacksMutex);
|
||||
util::exclusive<GlyphSet> GlyphStore::getGlyphSet(const std::string& fontStack) {
|
||||
auto lock = std::make_unique<std::lock_guard<std::mutex>>(glyphSetsMutex);
|
||||
|
||||
auto it = stacks.find(fontStack);
|
||||
if (it == stacks.end()) {
|
||||
it = stacks.emplace(fontStack, std::make_unique<FontStack>()).first;
|
||||
auto it = glyphSets.find(fontStack);
|
||||
if (it == glyphSets.end()) {
|
||||
it = glyphSets.emplace(fontStack, std::make_unique<GlyphSet>()).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) };
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef MBGL_TEXT_GLYPH_STORE
|
||||
#define MBGL_TEXT_GLYPH_STORE
|
||||
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/util/exclusive.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/work_queue.hpp>
|
||||
@@ -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<FontStack> getFontStack(const std::string& fontStack);
|
||||
util::exclusive<GlyphSet> 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<GlyphRange>& glyphRanges);
|
||||
|
||||
@@ -61,8 +61,8 @@ private:
|
||||
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
|
||||
std::mutex rangesMutex;
|
||||
|
||||
std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks;
|
||||
std::mutex stacksMutex;
|
||||
std::unordered_map<std::string, std::unique_ptr<GlyphSet>> glyphSets;
|
||||
std::mutex glyphSetsMutex;
|
||||
|
||||
util::WorkQueue workQueue;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/test/stub_style_observer.hpp>
|
||||
|
||||
#include <mbgl/text/font_stack.hpp>
|
||||
#include <mbgl/text/glyph_set.hpp>
|
||||
#include <mbgl/text/glyph_store.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user