diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-12-18 17:26:31 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@gmail.com> | 2018-12-21 10:31:40 -0800 |
commit | 2171ded437f5dff42f17b5e7eb38a01f6c44d2c0 (patch) | |
tree | cc64020e48a9ad9942227f43df38ca3fdb14bcee /platform/default/src/mbgl/storage | |
parent | a408b2f5d5708e4b9fb7a870b4b58cd96eee9609 (diff) | |
download | qtlocation-mapboxgl-2171ded437f5dff42f17b5e7eb38a01f6c44d2c0.tar.gz |
[core] Support for excluding ideographic glyphs from offline downloads.
Diffstat (limited to 'platform/default/src/mbgl/storage')
-rw-r--r-- | platform/default/src/mbgl/storage/offline.cpp | 19 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/offline_download.cpp | 13 |
2 files changed, 23 insertions, 9 deletions
diff --git a/platform/default/src/mbgl/storage/offline.cpp b/platform/default/src/mbgl/storage/offline.cpp index e1ec0acb31..fd945c724f 100644 --- a/platform/default/src/mbgl/storage/offline.cpp +++ b/platform/default/src/mbgl/storage/offline.cpp @@ -16,12 +16,13 @@ namespace mbgl { // OfflineTilePyramidRegionDefinition OfflineTilePyramidRegionDefinition::OfflineTilePyramidRegionDefinition( - std::string styleURL_, LatLngBounds bounds_, double minZoom_, double maxZoom_, float pixelRatio_) + std::string styleURL_, LatLngBounds bounds_, double minZoom_, double maxZoom_, float pixelRatio_, bool includeIdeographs_) : styleURL(std::move(styleURL_)), bounds(std::move(bounds_)), minZoom(minZoom_), maxZoom(maxZoom_), - pixelRatio(pixelRatio_) { + pixelRatio(pixelRatio_), + includeIdeographs(includeIdeographs_) { if (minZoom < 0 || maxZoom < 0 || maxZoom < minZoom || pixelRatio < 0 || !std::isfinite(minZoom) || std::isnan(maxZoom) || !std::isfinite(pixelRatio)) { throw std::invalid_argument("Invalid offline region definition"); @@ -31,12 +32,13 @@ OfflineTilePyramidRegionDefinition::OfflineTilePyramidRegionDefinition( // OfflineGeometryRegionDefinition -OfflineGeometryRegionDefinition::OfflineGeometryRegionDefinition(std::string styleURL_, Geometry<double> geometry_, double minZoom_, double maxZoom_, float pixelRatio_) +OfflineGeometryRegionDefinition::OfflineGeometryRegionDefinition(std::string styleURL_, Geometry<double> geometry_, double minZoom_, double maxZoom_, float pixelRatio_, bool includeIdeographs_) : styleURL(styleURL_) , geometry(std::move(geometry_)) , minZoom(minZoom_) , maxZoom(maxZoom_) - , pixelRatio(pixelRatio_) { + , pixelRatio(pixelRatio_) + , includeIdeographs(includeIdeographs_){ if (minZoom < 0 || maxZoom < 0 || maxZoom < minZoom || pixelRatio < 0 || !std::isfinite(minZoom) || std::isnan(maxZoom) || !std::isfinite(pixelRatio)) { throw std::invalid_argument("Invalid offline region definition"); @@ -64,7 +66,8 @@ OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string& region) || !(hasValidBounds() || hasValidGeometry()) || !doc.HasMember("min_zoom") || !doc["min_zoom"].IsDouble() || (doc.HasMember("max_zoom") && !doc["max_zoom"].IsDouble()) - || !doc.HasMember("pixel_ratio") || !doc["pixel_ratio"].IsDouble()) { + || !doc.HasMember("pixel_ratio") || !doc["pixel_ratio"].IsDouble() + || (doc.HasMember("include_ideographs") && !doc["include_ideographs"].IsBool())) { throw std::runtime_error("Malformed offline region definition"); } @@ -74,6 +77,7 @@ OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string& region) double minZoom = doc["min_zoom"].GetDouble(); double maxZoom = doc.HasMember("max_zoom") ? doc["max_zoom"].GetDouble() : INFINITY; float pixelRatio = doc["pixel_ratio"].GetDouble(); + bool includeIdeographs = doc.HasMember("include_ideographs") ? doc["include_ideographs"].GetBool() : true; if (doc.HasMember("bounds")) { return OfflineTilePyramidRegionDefinition{ @@ -81,12 +85,12 @@ OfflineRegionDefinition decodeOfflineRegionDefinition(const std::string& region) LatLngBounds::hull( LatLng(doc["bounds"][0].GetDouble(), doc["bounds"][1].GetDouble()), LatLng(doc["bounds"][2].GetDouble(), doc["bounds"][3].GetDouble())), - minZoom, maxZoom, pixelRatio }; + minZoom, maxZoom, pixelRatio, includeIdeographs }; } else { return OfflineGeometryRegionDefinition{ styleURL, mapbox::geojson::convert<Geometry<double>>(doc["geometry"].GetObject()), - minZoom, maxZoom, pixelRatio }; + minZoom, maxZoom, pixelRatio, includeIdeographs }; }; } @@ -104,6 +108,7 @@ std::string encodeOfflineRegionDefinition(const OfflineRegionDefinition& region) } doc.AddMember("pixel_ratio", _region.pixelRatio, doc.GetAllocator()); + doc.AddMember("include_ideographs", _region.includeIdeographs, doc.GetAllocator()); }); // Encode specific properties diff --git a/platform/default/src/mbgl/storage/offline_download.cpp b/platform/default/src/mbgl/storage/offline_download.cpp index c97797a5a2..d60ae786dd 100644 --- a/platform/default/src/mbgl/storage/offline_download.cpp +++ b/platform/default/src/mbgl/storage/offline_download.cpp @@ -13,6 +13,7 @@ #include <mbgl/style/conversion/json.hpp> #include <mbgl/style/conversion/tileset.hpp> #include <mbgl/text/glyph.hpp> +#include <mbgl/util/i18n.hpp> #include <mbgl/util/mapbox.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/tile_cover.hpp> @@ -205,7 +206,10 @@ OfflineRegionStatus OfflineDownload::getStatus() const { } if (!parser.glyphURL.empty()) { - result->requiredResourceCount += parser.fontStacks().size() * GLYPH_RANGES_PER_FONT_STACK; + result->requiredResourceCount += parser.fontStacks().size() * + (definition.match([](auto& reg){ return reg.includeIdeographs; }) ? + GLYPH_RANGES_PER_FONT_STACK : + NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK); } if (!parser.spriteURL.empty()) { @@ -298,9 +302,14 @@ void OfflineDownload::activateDownload() { } if (!parser.glyphURL.empty()) { + const bool includeIdeographs = definition.match([](auto& reg){ return reg.includeIdeographs; }); for (const auto& fontStack : parser.fontStacks()) { for (char16_t i = 0; i < GLYPH_RANGES_PER_FONT_STACK; i++) { - queueResource(Resource::glyphs(parser.glyphURL, fontStack, getGlyphRange(i * GLYPHS_PER_GLYPH_RANGE))); + // Assumes that if a glyph range starts with fixed width/ideographic characters, the entire + // range will be fixed width. + if (includeIdeographs || !util::i18n::allowsFixedWidthGlyphGeneration(i * GLYPHS_PER_GLYPH_RANGE)) { + queueResource(Resource::glyphs(parser.glyphURL, fontStack, getGlyphRange(i * GLYPHS_PER_GLYPH_RANGE))); + } } } } |