summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph_pbf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text/glyph_pbf.cpp')
-rw-r--r--src/mbgl/text/glyph_pbf.cpp46
1 files changed, 11 insertions, 35 deletions
diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp
index c14f52de7a..0c0626c0de 100644
--- a/src/mbgl/text/glyph_pbf.cpp
+++ b/src/mbgl/text/glyph_pbf.cpp
@@ -12,8 +12,6 @@
#include <mbgl/util/token.hpp>
#include <mbgl/util/url.hpp>
-#include <sstream>
-
namespace {
void parseGlyphPBF(mbgl::FontStack& stack, const std::string& data) {
@@ -65,8 +63,10 @@ namespace mbgl {
GlyphPBF::GlyphPBF(GlyphStore* store,
const std::string& fontStack,
- const GlyphRange& glyphRange)
- : parsed(false) {
+ const GlyphRange& glyphRange,
+ GlyphStore::Observer* observer_)
+ : parsed(false),
+ observer(observer_) {
// Load the glyph set URL
std::string url = util::replaceTokens(store->getURL(), [&](const std::string &name) -> std::string {
if (name == "fontstack") return util::percentEncode(fontStack);
@@ -74,7 +74,7 @@ GlyphPBF::GlyphPBF(GlyphStore* store,
return "";
});
- auto requestCallback = [this, store, fontStack, url](Response res) {
+ auto requestCallback = [this, store, fontStack, glyphRange](Response res) {
if (res.stale) {
// Only handle fresh responses.
return;
@@ -82,12 +82,10 @@ GlyphPBF::GlyphPBF(GlyphStore* store,
req = nullptr;
if (res.error) {
- std::stringstream message;
- message << "Failed to load [" << url << "]: " << res.error->message;
- emitGlyphPBFLoadingFailed(message.str());
+ observer->onGlyphsError(fontStack, glyphRange, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else {
data = res.data;
- parse(store, fontStack, url);
+ parse(store, fontStack, glyphRange);
}
};
@@ -97,7 +95,7 @@ GlyphPBF::GlyphPBF(GlyphStore* store,
GlyphPBF::~GlyphPBF() = default;
-void GlyphPBF::parse(GlyphStore* store, const std::string& fontStack, const std::string& url) {
+void GlyphPBF::parse(GlyphStore* store, const std::string& fontStack, const GlyphRange& glyphRange) {
assert(data);
if (data->empty()) {
// If there is no data, this means we either haven't
@@ -107,35 +105,13 @@ void GlyphPBF::parse(GlyphStore* store, const std::string& fontStack, const std:
try {
parseGlyphPBF(**store->getFontStack(fontStack), *data);
- } catch (const std::exception& ex) {
- std::stringstream message;
- message << "Failed to parse [" << url << "]: " << ex.what();
- emitGlyphPBFLoadingFailed(message.str());
+ } catch (...) {
+ observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
return;
}
parsed = true;
-
- emitGlyphPBFLoaded();
-}
-
-void GlyphPBF::setObserver(Observer* observer_) {
- observer = observer_;
-}
-
-void GlyphPBF::emitGlyphPBFLoaded() {
- if (observer) {
- observer->onGlyphPBFLoaded();
- }
-}
-
-void GlyphPBF::emitGlyphPBFLoadingFailed(const std::string& message) {
- if (!observer) {
- return;
- }
-
- auto error = std::make_exception_ptr(util::GlyphRangeLoadingException(message));
- observer->onGlyphPBFLoadingFailed(error);
+ observer->onGlyphsLoaded(fontStack, glyphRange);
}
} // namespace mbgl