diff options
-rw-r--r-- | src/mbgl/layout/merge_lines.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_feature.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 21 | ||||
-rw-r--r-- | test/util/merge_lines.cpp | 49 |
4 files changed, 41 insertions, 42 deletions
diff --git a/src/mbgl/layout/merge_lines.cpp b/src/mbgl/layout/merge_lines.cpp index ddae9c2c8d..ce6b5f30d0 100644 --- a/src/mbgl/layout/merge_lines.cpp +++ b/src/mbgl/layout/merge_lines.cpp @@ -65,12 +65,12 @@ void mergeLines(std::vector<SymbolFeature> &features) { SymbolFeature &feature = features[k]; GeometryCollection &geometry = feature.geometry; - if (!feature.label.length()) { + if (!feature.label) { continue; } - const auto leftKey = getKey(feature.label, geometry, Side::Left); - const auto rightKey = getKey(feature.label, geometry, Side::Right); + const auto leftKey = getKey(*feature.label, geometry, Side::Left); + const auto rightKey = getKey(*feature.label, geometry, Side::Right); const auto left = rightIndex.find(leftKey); const auto right = leftIndex.find(rightKey); @@ -85,7 +85,7 @@ void mergeLines(std::vector<SymbolFeature> &features) { leftIndex.erase(leftKey); rightIndex.erase(rightKey); - rightIndex[getKey(feature.label, features[i].geometry, Side::Right)] = i; + rightIndex[getKey(*feature.label, features[i].geometry, Side::Right)] = i; } else if (left != rightIndex.end()) { // found mergeable line adjacent to the start of the current line, merge diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp index 3b4eb78d86..fa5af97861 100644 --- a/src/mbgl/layout/symbol_feature.hpp +++ b/src/mbgl/layout/symbol_feature.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/tile/geometry_tile_data.hpp> +#include <mbgl/util/optional.hpp> #include <string> @@ -9,8 +10,8 @@ namespace mbgl { class SymbolFeature { public: GeometryCollection geometry; - std::u32string label; - std::string sprite; + optional<std::u32string> label; + optional<std::string> sprite; std::size_t index; }; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 5161d3c34b..84fd9393a2 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -91,11 +91,9 @@ SymbolLayout::SymbolLayout(std::string bucketName_, ft.label = util::utf8_to_utf32::convert(u8string); - if (!ft.label.empty()) { - // Loop through all characters of this text and collect unique codepoints. - for (char32_t chr : ft.label) { - ranges.insert(getGlyphRange(chr)); - } + // Loop through all characters of this text and collect unique codepoints. + for (char32_t chr : *ft.label) { + ranges.insert(getGlyphRange(chr)); } } @@ -103,8 +101,7 @@ SymbolLayout::SymbolLayout(std::string bucketName_, ft.sprite = util::replaceTokens(layout.iconImage, getValue); } - if (ft.label.length() || ft.sprite.length()) { - + if (ft.label || ft.sprite) { auto &multiline = ft.geometry; GeometryCollection geometryCollection = feature->getGeometries(); @@ -194,9 +191,9 @@ void SymbolLayout::prepare(uintptr_t tileUID, GlyphPositions face; // if feature has text, shape the text - if (feature.label.length()) { + if (feature.label) { shapedText = glyphSet->getShaping( - /* string */ feature.label, + /* string */ *feature.label, /* maxWidth: ems */ layout.symbolPlacement != SymbolPlacementType::Line ? layout.textMaxWidth * 24 : 0, /* lineHeight: ems */ layout.textLineHeight * 24, @@ -208,13 +205,13 @@ void SymbolLayout::prepare(uintptr_t tileUID, // Add the glyphs we need for this label to the glyph atlas. if (shapedText) { - glyphAtlas.addGlyphs(tileUID, feature.label, layout.textFont, **glyphSet, face); + glyphAtlas.addGlyphs(tileUID, *feature.label, layout.textFont, **glyphSet, face); } } // if feature has icon, get sprite atlas position - if (feature.sprite.length()) { - auto image = spriteAtlas.getImage(feature.sprite, SpritePatternMode::Single); + if (feature.sprite) { + auto image = spriteAtlas.getImage(*feature.sprite, SpritePatternMode::Single); if (image) { shapedIcon = shapeIcon(*image, layout); assert((*image).spriteImage); diff --git a/test/util/merge_lines.cpp b/test/util/merge_lines.cpp index 4b8b0c4e79..db81d8b209 100644 --- a/test/util/merge_lines.cpp +++ b/test/util/merge_lines.cpp @@ -1,6 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/layout/merge_lines.hpp> +#include <mbgl/layout/symbol_feature.hpp> const std::u32string aaa = U"a"; const std::u32string bbb = U"b"; @@ -8,21 +9,21 @@ const std::u32string bbb = U"b"; TEST(MergeLines, SameText) { // merges lines with the same text std::vector<mbgl::SymbolFeature> input1 = { - { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, "", 0 }, - { {{{4, 0}, {5, 0}, {6, 0}}}, bbb, "", 0 }, - { {{{8, 0}, {9, 0}}}, aaa, "", 0 }, - { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, "", 0 }, - { {{{6, 0}, {7, 0}, {8, 0}}}, aaa, "", 0 }, - { {{{5, 0}, {6, 0}}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, 0 }, + { {{{4, 0}, {5, 0}, {6, 0}}}, bbb, {}, 0 }, + { {{{8, 0}, {9, 0}}}, aaa, {}, 0 }, + { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, 0 }, + { {{{6, 0}, {7, 0}, {8, 0}}}, aaa, {}, 0 }, + { {{{5, 0}, {6, 0}}}, aaa, {}, 0 } }; const std::vector<mbgl::SymbolFeature> expected1 = { - { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, aaa, "", 0 }, - { {{{4, 0}, {5, 0}, {6, 0}}}, bbb, "", 0 }, - { {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}}, aaa, {}, 0 }, + { {{{4, 0}, {5, 0}, {6, 0}}}, bbb, {}, 0 }, + { {{{5, 0}, {6, 0}, {7, 0}, {8, 0}, {9, 0}}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 } }; mbgl::util::mergeLines(input1); @@ -35,15 +36,15 @@ TEST(MergeLines, SameText) { TEST(MergeLines, BothEnds) { // mergeLines handles merge from both ends std::vector<mbgl::SymbolFeature> input2 = { - { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, "", 0 }, - { {{{4, 0}, {5, 0}, {6, 0}}}, aaa, "", 0 }, - { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, 0 }, + { {{{4, 0}, {5, 0}, {6, 0}}}, aaa, {}, 0 }, + { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, 0 } }; const std::vector<mbgl::SymbolFeature> expected2 = { - { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 } }; mbgl::util::mergeLines(input2); @@ -56,15 +57,15 @@ TEST(MergeLines, BothEnds) { TEST(MergeLines, CircularLines) { // mergeLines handles circular lines std::vector<mbgl::SymbolFeature> input3 = { - { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, "", 0 }, - { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, "", 0 }, - { {{{4, 0}, {0, 0}}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}}}, aaa, {}, 0 }, + { {{{2, 0}, {3, 0}, {4, 0}}}, aaa, {}, 0 }, + { {{{4, 0}, {0, 0}}}, aaa, {}, 0 } }; const std::vector<mbgl::SymbolFeature> expected3 = { - { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 }, - { {{}}, aaa, "", 0 } + { {{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {0, 0}}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 }, + { {{}}, aaa, {}, 0 } }; mbgl::util::mergeLines(input3); |