summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-04-22 10:38:42 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-04-22 15:53:18 -0700
commit5939dd5b412fcc1ef857711a137589aa865bd442 (patch)
tree4bd4e021ea564ee262cff56ab7b6f76e98b29471
parentd77e35b6866e461c3cb05de2112d548be4ef7780 (diff)
downloadqtlocation-mapboxgl-5939dd5b412fcc1ef857711a137589aa865bd442.tar.gz
[core] Use the proper type for font stacks
-rw-r--r--include/mbgl/storage/resource.hpp3
-rw-r--r--include/mbgl/style/types.hpp11
-rw-r--r--src/mbgl/geometry/glyph_atlas.cpp8
-rw-r--r--src/mbgl/geometry/glyph_atlas.hpp8
-rw-r--r--src/mbgl/layer/symbol_layer.hpp2
-rw-r--r--src/mbgl/storage/resource.cpp4
-rw-r--r--src/mbgl/style/function.cpp4
-rw-r--r--src/mbgl/style/property_parsing.cpp49
-rw-r--r--src/mbgl/style/style.cpp6
-rw-r--r--src/mbgl/style/style.hpp4
-rw-r--r--src/mbgl/style/style_parser.cpp8
-rw-r--r--src/mbgl/style/style_parser.hpp3
-rw-r--r--src/mbgl/style/types.cpp16
-rw-r--r--src/mbgl/text/glyph_pbf.cpp2
-rw-r--r--src/mbgl/text/glyph_pbf.hpp6
-rw-r--r--src/mbgl/text/glyph_store.cpp14
-rw-r--r--src/mbgl/text/glyph_store.hpp16
-rw-r--r--src/mbgl/util/interpolate.hpp1
-rw-r--r--test/map/map.cpp2
-rw-r--r--test/src/mbgl/test/stub_style_observer.hpp8
-rw-r--r--test/storage/resource.cpp2
-rw-r--r--test/style/glyph_store.cpp36
-rw-r--r--test/style/style_parser.cpp6
23 files changed, 128 insertions, 91 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index edd9f58c72..296dff7f3d 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -3,6 +3,7 @@
#include <mbgl/storage/response.hpp>
#include <mbgl/util/optional.hpp>
+#include <mbgl/style/types.hpp>
#include <string>
@@ -42,7 +43,7 @@ public:
int32_t y,
int8_t z);
static Resource glyphs(const std::string& urlTemplate,
- const std::string& fontStack,
+ const FontStack& fontStack,
const std::pair<uint16_t, uint16_t>& glyphRange);
static Resource spriteImage(const std::string& base, float pixelRatio);
static Resource spriteJSON(const std::string& base, float pixelRatio);
diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp
index 999b8d8b79..ca56d39991 100644
--- a/include/mbgl/style/types.hpp
+++ b/include/mbgl/style/types.hpp
@@ -5,12 +5,21 @@
#include <string>
#include <array>
+#include <vector>
namespace mbgl {
// Stores a premultiplied color, with all four channels ranging from 0..1
-typedef std::array<float, 4> Color;
+using Color = std::array<float, 4>;
+// An array of font names
+using FontStack = std::vector<std::string>;
+
+std::string fontStackToString(const FontStack&);
+
+struct FontStackHash {
+ std::size_t operator()(const FontStack&) const;
+};
template <typename T>
struct Faded {
diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp
index 92fc7903b2..fd43fb8c18 100644
--- a/src/mbgl/geometry/glyph_atlas.cpp
+++ b/src/mbgl/geometry/glyph_atlas.cpp
@@ -24,7 +24,7 @@ GlyphAtlas::~GlyphAtlas() {
void GlyphAtlas::addGlyphs(uintptr_t tileUID,
const std::u32string& text,
- const std::string& stackName,
+ const FontStack& fontStack,
const GlyphSet& glyphSet,
GlyphPositions& face)
{
@@ -40,19 +40,19 @@ void GlyphAtlas::addGlyphs(uintptr_t tileUID,
}
const SDFGlyph& sdf = sdf_it->second;
- Rect<uint16_t> rect = addGlyph(tileUID, stackName, sdf);
+ Rect<uint16_t> rect = addGlyph(tileUID, fontStack, sdf);
face.emplace(chr, Glyph{rect, sdf.metrics});
}
}
Rect<uint16_t> GlyphAtlas::addGlyph(uintptr_t tileUID,
- const std::string& stackName,
+ const FontStack& fontStack,
const SDFGlyph& glyph)
{
// Use constant value for now.
const uint8_t buffer = 3;
- std::map<uint32_t, GlyphValue>& face = index[stackName];
+ std::map<uint32_t, GlyphValue>& face = index[fontStack];
std::map<uint32_t, GlyphValue>::iterator it = face.find(glyph.id);
// The glyph is already in this texture.
diff --git a/src/mbgl/geometry/glyph_atlas.hpp b/src/mbgl/geometry/glyph_atlas.hpp
index 9b8af9f75d..df1446cd47 100644
--- a/src/mbgl/geometry/glyph_atlas.hpp
+++ b/src/mbgl/geometry/glyph_atlas.hpp
@@ -9,7 +9,7 @@
#include <string>
#include <set>
-#include <map>
+#include <unordered_map>
#include <mutex>
#include <atomic>
@@ -22,7 +22,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);
@@ -46,12 +46,12 @@ private:
};
Rect<uint16_t> addGlyph(uintptr_t tileID,
- const std::string& stackName,
+ const FontStack&,
const SDFGlyph&);
std::mutex mtx;
BinPack<uint16_t> bin;
- std::map<std::string, std::map<uint32_t, GlyphValue>> index;
+ std::unordered_map<FontStack, std::map<uint32_t, GlyphValue>, FontStackHash> index;
const std::unique_ptr<uint8_t[]> data;
std::atomic<bool> dirty;
gl::TextureHolder texture;
diff --git a/src/mbgl/layer/symbol_layer.hpp b/src/mbgl/layer/symbol_layer.hpp
index 440631bcb4..f8e42ab821 100644
--- a/src/mbgl/layer/symbol_layer.hpp
+++ b/src/mbgl/layer/symbol_layer.hpp
@@ -28,7 +28,7 @@ public:
LayoutProperty<RotationAlignmentType> textRotationAlignment { RotationAlignmentType::Viewport };
LayoutProperty<std::string> textField { "" };
- LayoutProperty<std::string> textFont { "Open Sans Regular, Arial Unicode MS Regular" };
+ LayoutProperty<std::vector<std::string>> textFont { { "Open Sans Regular", "Arial Unicode MS Regular" } };
LayoutProperty<float> textSize { 16.0f };
LayoutProperty<float> textMaxWidth { 10.0f /* em */ };
LayoutProperty<float> textLineHeight { 1.2f /* em */ };
diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp
index d5b88d9292..d633ae195e 100644
--- a/src/mbgl/storage/resource.cpp
+++ b/src/mbgl/storage/resource.cpp
@@ -33,12 +33,12 @@ Resource Resource::spriteJSON(const std::string& base, float pixelRatio) {
};
}
-Resource Resource::glyphs(const std::string& urlTemplate, const std::string& fontStack, const std::pair<uint16_t, uint16_t>& glyphRange) {
+Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair<uint16_t, uint16_t>& glyphRange) {
return Resource {
Resource::Kind::Glyphs,
util::replaceTokens(urlTemplate, [&](const std::string& token) {
if (token == "fontstack") {
- return util::percentEncode(fontStack);
+ return util::percentEncode(fontStackToString(fontStack));
} else if (token == "range") {
return util::toString(glyphRange.first) + "-" + util::toString(glyphRange.second);
} else {
diff --git a/src/mbgl/style/function.cpp b/src/mbgl/style/function.cpp
index 55643ed43f..bc3e6074fb 100644
--- a/src/mbgl/style/function.cpp
+++ b/src/mbgl/style/function.cpp
@@ -14,9 +14,10 @@ template <> inline bool defaultStopsValue() { return true; }
template <> inline float defaultStopsValue() { return 1.0f; }
template <> inline Color defaultStopsValue() { return {{ 0, 0, 0, 1 }}; }
template <> inline std::vector<float> defaultStopsValue() { return {{ 1, 0 }}; }
+template <> inline std::vector<std::string> defaultStopsValue() { return {{}}; }
template <> inline std::array<float, 2> defaultStopsValue() { return {{ 0, 0 }}; }
-template <> inline std:: string defaultStopsValue() { return {}; }
+template <> inline std::string defaultStopsValue() { return {}; }
template <> inline TranslateAnchorType defaultStopsValue() { return {}; };
template <> inline RotateAnchorType defaultStopsValue() { return {}; };
template <> inline LineCapType defaultStopsValue() { return {}; };
@@ -79,6 +80,7 @@ template class Function<bool>;
template class Function<float>;
template class Function<Color>;
template class Function<std::vector<float>>;
+template class Function<std::vector<std::string>>;
template class Function<std::array<float, 2>>;
template class Function<std::string>;
diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp
index 879f61411a..6f052222e4 100644
--- a/src/mbgl/style/property_parsing.cpp
+++ b/src/mbgl/style/property_parsing.cpp
@@ -32,28 +32,6 @@ optional<float> parseProperty(const char* name, const JSValue& value) {
template <>
optional<std::string> parseProperty(const char* name, const JSValue& value) {
- if (std::string { "text-font" } == name) {
- if (!value.IsArray()) {
- Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name);
- return {};
- }
-
- std::string result = "";
- for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
- const JSValue& stop = value[i];
- if (stop.IsString()) {
- result += stop.GetString();
- if (i < value.Size()-1) {
- result += ",";
- }
- } else {
- Log::Warning(Event::ParseStyle, "text-font members must be strings");
- return {};
- }
- }
- return result;
- }
-
if (!value.IsString()) {
Log::Warning(Event::ParseStyle, "value of '%s' must be a string", name);
return {};
@@ -209,6 +187,29 @@ optional<std::vector<float>> parseProperty(const char* name, const JSValue& valu
}
template <>
+optional<std::vector<std::string>> parseProperty(const char* name, const JSValue& value) {
+ if (!value.IsArray()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name);
+ return {};
+ }
+
+ std::vector<std::string> result;
+
+ for (rapidjson::SizeType i = 0; i < value.Size(); ++i) {
+ const JSValue& part = value[i];
+
+ if (!part.IsString()) {
+ Log::Warning(Event::ParseStyle, "value of '%s' must be an array of strings", name);
+ return {};
+ }
+
+ result.push_back({ part.GetString(), part.GetStringLength() });
+ }
+
+ return result;
+}
+
+template <>
optional<PropertyTransition> parseProperty(const char *, const JSValue& value) {
PropertyTransition transition;
if (value.IsObject()) {
@@ -362,6 +363,10 @@ template<> optional<Function<Color>> parseProperty(const char* name, const JSVal
return parseFunction<Color>(name, value);
}
+template<> optional<Function<std::vector<std::string>>> parseProperty(const char* name, const JSValue& value) {
+ return parseFunction<std::vector<std::string>>(name, value);
+}
+
template <typename T>
optional<Function<Faded<T>>> parseFadedFunction(const JSValue& value) {
if (!value.HasMember("stops")) {
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index a480ef8d97..338f6113b0 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -330,16 +330,16 @@ void Style::setObserver(Observer* observer_) {
observer = observer_;
}
-void Style::onGlyphsLoaded(const std::string& fontStack, const GlyphRange& glyphRange) {
+void Style::onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) {
shouldReparsePartialTiles = true;
observer->onGlyphsLoaded(fontStack, glyphRange);
observer->onResourceLoaded();
}
-void Style::onGlyphsError(const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
+void Style::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load glyph range %d-%d for font stack %s: %s",
- glyphRange.first, glyphRange.second, fontStack.c_str(), util::toString(error).c_str());
+ glyphRange.first, glyphRange.second, fontStackToString(fontStack).c_str(), util::toString(error).c_str());
observer->onGlyphsError(fontStack, glyphRange, error);
observer->onResourceError(error);
}
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index b3c06d8214..790518d08e 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -128,8 +128,8 @@ private:
std::vector<std::unique_ptr<StyleLayer>>::const_iterator findLayer(const std::string& layerID) const;
// GlyphStore::Observer implementation.
- void onGlyphsLoaded(const std::string& fontStack, const GlyphRange&) override;
- void onGlyphsError(const std::string& fontStack, const GlyphRange&, std::exception_ptr) override;
+ void onGlyphsLoaded(const FontStack&, const GlyphRange&) override;
+ void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override;
// SpriteStore::Observer implementation.
void onSpriteLoaded() override;
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index e312dee3b3..ff0a3b13af 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -492,12 +492,12 @@ void StyleParser::parseVisibility(StyleLayer& layer, const JSValue& value) {
layer.visibility = VisibilityTypeClass({ value["visibility"].GetString(), value["visibility"].GetStringLength() });
}
-std::vector<std::string> StyleParser::fontStacks() const {
- std::set<std::string> result;
+std::vector<FontStack> StyleParser::fontStacks() const {
+ std::set<FontStack> result;
for (const auto& layer : layers) {
if (layer->is<SymbolLayer>()) {
- LayoutProperty<std::string> property = layer->as<SymbolLayer>()->layout.textFont;
+ LayoutProperty<FontStack> property = layer->as<SymbolLayer>()->layout.textFont;
if (property.parsedValue) {
for (const auto& stop : property.parsedValue->getStops()) {
result.insert(stop.second);
@@ -508,7 +508,7 @@ std::vector<std::string> StyleParser::fontStacks() const {
}
}
- return std::vector<std::string>(result.begin(), result.end());
+ return std::vector<FontStack>(result.begin(), result.end());
}
} // namespace mbgl
diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp
index 280cda530b..4cc4e2f2cb 100644
--- a/src/mbgl/style/style_parser.hpp
+++ b/src/mbgl/style/style_parser.hpp
@@ -1,6 +1,7 @@
#ifndef MBGL_STYLE_STYLE_PARSER
#define MBGL_STYLE_STYLE_PARSER
+#include <mbgl/style/types.hpp>
#include <mbgl/style/style_layer.hpp>
#include <mbgl/source/source.hpp>
#include <mbgl/util/rapidjson.hpp>
@@ -29,7 +30,7 @@ public:
std::vector<std::unique_ptr<StyleLayer>> layers;
// Statically evaluate layer properties to determine what font stacks are used.
- std::vector<std::string> fontStacks() const;
+ std::vector<FontStack> fontStacks() const;
static std::unique_ptr<SourceInfo> parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize);
static std::unique_ptr<SourceInfo> parseTileJSON(const JSValue&);
diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp
new file mode 100644
index 0000000000..27574afa93
--- /dev/null
+++ b/src/mbgl/style/types.cpp
@@ -0,0 +1,16 @@
+#include <mbgl/style/types.hpp>
+
+#include <boost/functional/hash.hpp>
+#include <boost/algorithm/string/join.hpp>
+
+namespace mbgl {
+
+std::string fontStackToString(const FontStack& fontStack) {
+ return boost::algorithm::join(fontStack, ",");
+}
+
+std::size_t FontStackHash::operator()(const FontStack& fontStack) const {
+ return boost::hash_range(fontStack.begin(), fontStack.end());
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp
index 105ea45190..2588afaefa 100644
--- a/src/mbgl/text/glyph_pbf.cpp
+++ b/src/mbgl/text/glyph_pbf.cpp
@@ -61,7 +61,7 @@ void parseGlyphPBF(mbgl::GlyphSet& glyphSet, const std::string& data) {
namespace mbgl {
GlyphPBF::GlyphPBF(GlyphStore* store,
- const std::string& fontStack,
+ const FontStack& fontStack,
const GlyphRange& glyphRange,
GlyphStore::Observer* observer_,
FileSource& fileSource)
diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp
index 5b47563f7d..d281d2a04f 100644
--- a/src/mbgl/text/glyph_pbf.hpp
+++ b/src/mbgl/text/glyph_pbf.hpp
@@ -3,6 +3,7 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/glyph_store.hpp>
+#include <mbgl/style/types.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <atomic>
@@ -12,14 +13,13 @@
namespace mbgl {
-class GlyphSet;
class AsyncRequest;
class FileSource;
class GlyphPBF : private util::noncopyable {
public:
- GlyphPBF(GlyphStore* store,
- const std::string& fontStack,
+ GlyphPBF(GlyphStore*,
+ const FontStack&,
const GlyphRange&,
GlyphStore::Observer*,
FileSource&);
diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp
index 9f6a6b7b72..540908ed63 100644
--- a/src/mbgl/text/glyph_store.cpp
+++ b/src/mbgl/text/glyph_store.cpp
@@ -11,9 +11,9 @@ GlyphStore::GlyphStore(FileSource& fileSource_)
GlyphStore::~GlyphStore() = default;
-void GlyphStore::requestGlyphRange(const std::string& fontStackName, const GlyphRange& range) {
+void GlyphStore::requestGlyphRange(const FontStack& fontStack, const GlyphRange& range) {
std::lock_guard<std::mutex> lock(rangesMutex);
- auto& rangeSets = ranges[fontStackName];
+ auto& rangeSets = ranges[fontStack];
const auto& rangeSetsIt = rangeSets.find(range);
if (rangeSetsIt != rangeSets.end()) {
@@ -21,17 +21,17 @@ void GlyphStore::requestGlyphRange(const std::string& fontStackName, const Glyph
}
rangeSets.emplace(range,
- std::make_unique<GlyphPBF>(this, fontStackName, range, observer, fileSource));
+ std::make_unique<GlyphPBF>(this, fontStack, range, observer, fileSource));
}
-bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set<GlyphRange>& glyphRanges) {
+bool GlyphStore::hasGlyphRanges(const FontStack& fontStack, const std::set<GlyphRange>& glyphRanges) {
if (glyphRanges.empty()) {
return true;
}
std::lock_guard<std::mutex> lock(rangesMutex);
- const auto& rangeSets = ranges[fontStackName];
+ const auto& rangeSets = ranges[fontStack];
bool hasRanges = true;
for (const auto& range : glyphRanges) {
@@ -39,7 +39,7 @@ bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set
if (rangeSetsIt == rangeSets.end()) {
// Push the request to the MapThread, so we can easly cancel
// if it is still pending when we destroy this object.
- workQueue.push(std::bind(&GlyphStore::requestGlyphRange, this, fontStackName, range));
+ workQueue.push(std::bind(&GlyphStore::requestGlyphRange, this, fontStack, range));
hasRanges = false;
continue;
@@ -53,7 +53,7 @@ bool GlyphStore::hasGlyphRanges(const std::string& fontStackName, const std::set
return hasRanges;
}
-util::exclusive<GlyphSet> GlyphStore::getGlyphSet(const std::string& fontStack) {
+util::exclusive<GlyphSet> GlyphStore::getGlyphSet(const FontStack& fontStack) {
auto lock = std::make_unique<std::lock_guard<std::mutex>>(glyphSetsMutex);
auto it = glyphSets.find(fontStack);
diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp
index 5b80589f4b..f89ff80864 100644
--- a/src/mbgl/text/glyph_store.hpp
+++ b/src/mbgl/text/glyph_store.hpp
@@ -3,11 +3,13 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/glyph_set.hpp>
+#include <mbgl/style/types.hpp>
#include <mbgl/util/exclusive.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/work_queue.hpp>
#include <exception>
+#include <vector>
#include <set>
#include <string>
#include <unordered_map>
@@ -26,21 +28,21 @@ public:
public:
virtual ~Observer() = default;
- virtual void onGlyphsLoaded(const std::string& /* fontStack */, const GlyphRange&) {};
- virtual void onGlyphsError(const std::string& /* fontStack */, const GlyphRange&, std::exception_ptr) {};
+ virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {};
+ virtual void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) {};
};
GlyphStore(FileSource&);
~GlyphStore();
- util::exclusive<GlyphSet> getGlyphSet(const std::string& fontStack);
+ util::exclusive<GlyphSet> getGlyphSet(const 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
// 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);
+ bool hasGlyphRanges(const FontStack&, const std::set<GlyphRange>&);
void setURL(const std::string &url) {
glyphURL = url;
@@ -53,15 +55,15 @@ public:
void setObserver(Observer* observer);
private:
- void requestGlyphRange(const std::string& fontStackName, const GlyphRange& range);
+ void requestGlyphRange(const FontStack&, const GlyphRange&);
FileSource& fileSource;
std::string glyphURL;
- std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
+ std::unordered_map<FontStack, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>, FontStackHash> ranges;
std::mutex rangesMutex;
- std::unordered_map<std::string, std::unique_ptr<GlyphSet>> glyphSets;
+ std::unordered_map<FontStack, std::unique_ptr<GlyphSet>, FontStackHash> glyphSets;
std::mutex glyphSetsMutex;
util::WorkQueue workQueue;
diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp
index 7d1a857e8e..f456a0ecb1 100644
--- a/src/mbgl/util/interpolate.hpp
+++ b/src/mbgl/util/interpolate.hpp
@@ -35,6 +35,7 @@ inline std::array<T, 2> interpolate(const std::array<T, 2>& a, const std::array<
// fake interpolations that just return the first value
template<> inline bool interpolate(const bool a, const bool, const double) { return a; }
template<> inline std::vector<float> interpolate(const std::vector<float> a, const std::vector<float>, const double) { return a; }
+template<> inline std::vector<std::string> interpolate(const std::vector<std::string> a, const std::vector<std::string>, const double) { return a; }
template<> inline std::string interpolate(const std::string a, const std::string, const double) { return a; }
template<> inline TranslateAnchorType interpolate(const TranslateAnchorType a, const TranslateAnchorType, const double) { return a; }
template<> inline RotateAnchorType interpolate(const RotateAnchorType a, const RotateAnchorType, const double) { return a; }
diff --git a/test/map/map.cpp b/test/map/map.cpp
index 2fdf63a79a..1e8c1b2a4e 100644
--- a/test/map/map.cpp
+++ b/test/map/map.cpp
@@ -32,7 +32,7 @@ TEST(Map, Offline) {
fileSource.put(Resource::spriteJSON(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.json"));
fileSource.put(Resource::spriteImage(prefix + "/offline/sprite", 1.0), expiredItem("offline/sprite.png"));
fileSource.put(Resource::tile(prefix + "/offline/{z}-{x}-{y}.vector.pbf", 1.0, 0, 0, 0), expiredItem("offline/0-0-0.vector.pbf"));
- fileSource.put(Resource::glyphs(prefix + "/offline/{fontstack}/{range}.pbf", "Helvetica", {0, 255}), expiredItem("offline/glyph.pbf"));
+ fileSource.put(Resource::glyphs(prefix + "/offline/{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("offline/glyph.pbf"));
NetworkStatus::Set(NetworkStatus::Status::Offline);
Map map(view, fileSource, MapMode::Still);
diff --git a/test/src/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp
index 7236ca74f5..f428b4fda7 100644
--- a/test/src/mbgl/test/stub_style_observer.hpp
+++ b/test/src/mbgl/test/stub_style_observer.hpp
@@ -10,11 +10,11 @@ namespace mbgl {
*/
class StubStyleObserver : public Style::Observer {
public:
- void onGlyphsLoaded(const std::string& fontStack, const GlyphRange& glyphRange) override {
+ void onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) override {
if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange);
}
- void onGlyphsError(const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) override {
+ void onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) override {
if (glyphsError) glyphsError(fontStack, glyphRange, error);
}
@@ -50,8 +50,8 @@ public:
if (resourceError) resourceError(error);
};
- std::function<void (const std::string& fontStack, const GlyphRange&)> glyphsLoaded;
- std::function<void (const std::string& fontStack, const GlyphRange&, std::exception_ptr)> glyphsError;
+ std::function<void (const FontStack&, const GlyphRange&)> glyphsLoaded;
+ std::function<void (const FontStack&, const GlyphRange&, std::exception_ptr)> glyphsError;
std::function<void ()> spriteLoaded;
std::function<void (std::exception_ptr)> spriteError;
std::function<void (Source&)> sourceLoaded;
diff --git a/test/storage/resource.cpp b/test/storage/resource.cpp
index 0b04c1b3e4..5d6c3bcbf2 100644
--- a/test/storage/resource.cpp
+++ b/test/storage/resource.cpp
@@ -40,7 +40,7 @@ TEST(Resource, Tile) {
TEST(Resource, Glyphs) {
using namespace mbgl;
- Resource resource = Resource::glyphs("http://example.com/{fontstack}/{range}", "stack", {0, 255});
+ Resource resource = Resource::glyphs("http://example.com/{fontstack}/{range}", {{"stack"}}, {0, 255});
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
EXPECT_EQ("http://example.com/stack/0-255", resource.url);
}
diff --git a/test/style/glyph_store.cpp b/test/style/glyph_store.cpp
index 96d112183a..2a874a05a7 100644
--- a/test/style/glyph_store.cpp
+++ b/test/style/glyph_store.cpp
@@ -18,7 +18,7 @@ public:
StubStyleObserver observer;
GlyphStore glyphStore { fileSource };
- void run(const std::string& url, const std::string& fontStack, const std::set<GlyphRange>& glyphRanges) {
+ void run(const std::string& url, const FontStack& fontStack, const std::set<GlyphRange>& glyphRanges) {
// Squelch logging.
Log::setObserver(std::make_unique<Log::NullObserver>());
@@ -44,16 +44,16 @@ TEST(GlyphStore, LoadingSuccess) {
return response;
};
- test.observer.glyphsError = [&] (const std::string&, const GlyphRange&, std::exception_ptr) {
+ test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) {
FAIL();
test.end();
};
- test.observer.glyphsLoaded = [&] (const std::string&, const GlyphRange&) {
- if (!test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}, {256, 511}}))
+ test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) {
+ if (!test.glyphStore.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}}))
return;
- auto glyphSet = test.glyphStore.getGlyphSet("Test Stack");
+ auto glyphSet = test.glyphStore.getGlyphSet({{"Test Stack"}});
ASSERT_FALSE(glyphSet->getSDFs().empty());
test.end();
@@ -61,7 +61,7 @@ TEST(GlyphStore, LoadingSuccess) {
test.run(
"test/fixtures/resources/glyphs.pbf",
- "Test Stack",
+ {{"Test Stack"}},
{{0, 255}, {256, 511}});
}
@@ -76,23 +76,23 @@ TEST(GlyphStore, LoadingFail) {
return response;
};
- test.observer.glyphsError = [&] (const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
- EXPECT_EQ(fontStack, "Test Stack");
+ test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
+ EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "Failed by the test case");
- auto glyphSet = test.glyphStore.getGlyphSet("Test Stack");
+ auto glyphSet = test.glyphStore.getGlyphSet({{"Test Stack"}});
ASSERT_TRUE(glyphSet->getSDFs().empty());
- ASSERT_FALSE(test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}}));
+ ASSERT_FALSE(test.glyphStore.hasGlyphRanges({{"Test Stack"}}, {{0, 255}}));
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
- "Test Stack",
+ {{"Test Stack"}},
{{0, 255}});
}
@@ -105,23 +105,23 @@ TEST(GlyphStore, LoadingCorrupted) {
return response;
};
- test.observer.glyphsError = [&] (const std::string& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
- EXPECT_EQ(fontStack, "Test Stack");
+ test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
+ EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
EXPECT_TRUE(error != nullptr);
EXPECT_EQ(util::toString(error), "pbf unknown field type exception");
- auto glyphSet = test.glyphStore.getGlyphSet("Test Stack");
+ auto glyphSet = test.glyphStore.getGlyphSet({{"Test Stack"}});
ASSERT_TRUE(glyphSet->getSDFs().empty());
- ASSERT_FALSE(test.glyphStore.hasGlyphRanges("Test Stack", {{0, 255}}));
+ ASSERT_FALSE(test.glyphStore.hasGlyphRanges({{"Test Stack"}}, {{0, 255}}));
test.end();
};
test.run(
"test/fixtures/resources/glyphs.pbf",
- "Test Stack",
+ {{"Test Stack"}},
{{0, 255}});
}
@@ -133,12 +133,12 @@ TEST(GlyphStore, LoadingCancel) {
return optional<Response>();
};
- test.observer.glyphsLoaded = [&] (const std::string&, const GlyphRange&) {
+ test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) {
FAIL() << "Should never be called";
};
test.run(
"test/fixtures/resources/glyphs.pbf",
- "Test Stack",
+ {{"Test Stack"}},
{{0, 255}});
}
diff --git a/test/style/style_parser.cpp b/test/style/style_parser.cpp
index f549d638a4..6245c326a5 100644
--- a/test/style/style_parser.cpp
+++ b/test/style/style_parser.cpp
@@ -120,7 +120,7 @@ TEST(StyleParser, FontStacks) {
parser.parse(util::read_file("test/fixtures/style_parser/font_stacks.json"));
auto result = parser.fontStacks();
ASSERT_EQ(3, result.size());
- ASSERT_EQ("a", result[0]);
- ASSERT_EQ("a,b", result[1]);
- ASSERT_EQ("a,b,c", result[2]);
+ ASSERT_EQ(FontStack({"a"}), result[0]);
+ ASSERT_EQ(FontStack({"a", "b"}), result[1]);
+ ASSERT_EQ(FontStack({"a", "b", "c"}), result[2]);
}