diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-01-05 12:40:54 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-01-10 15:31:12 -0800 |
commit | 76ed5079a547e9f98616a9401c8814d224cec9d8 (patch) | |
tree | 4bad1bcefd0744a0262d6973b825a977fa2cfe45 /src | |
parent | 158bd5e08cae5974a9c587677d7d8e63a36a5ff0 (diff) | |
download | qtlocation-mapboxgl-76ed5079a547e9f98616a9401c8814d224cec9d8.tar.gz |
[core, ios, macos, android] Add data-driven-styling support for `text-font`
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 29 | ||||
-rw-r--r-- | src/mbgl/style/conversion/make_property_setters.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/expression/assertion.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/expression/boolean_operator.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/style/expression/case.cpp | 13 | ||||
-rw-r--r-- | src/mbgl/style/expression/coalesce.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/expression/coercion.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/expression/equals.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/expression/interpolate.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/expression/let.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/style/expression/match.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/style/expression/step.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_properties.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/parser.cpp | 29 |
15 files changed, 134 insertions, 31 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index fc1ede56ff..a41a98fcaf 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -32,7 +32,7 @@ using namespace style; template <class Property> static bool has(const style::SymbolLayoutProperties::PossiblyEvaluated& layout) { return layout.get<Property>().match( - [&] (const std::string& s) { return !s.empty(); }, + [&] (const typename Property::Type& t) { return !t.empty(); }, [&] (const auto&) { return true; } ); } @@ -82,7 +82,7 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, layout.get<IconPitchAlignment>() = layout.get<IconRotationAlignment>(); } - const bool hasText = has<TextField>(layout) && !layout.get<TextFont>().empty(); + const bool hasText = has<TextField>(layout) && has<TextFont>(layout); const bool hasIcon = has<IconImage>(layout); if (!hasText && !hasIcon) { @@ -143,12 +143,15 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, && layout.get<SymbolPlacement>() == SymbolPlacementType::Line && util::i18n::allowsVerticalWritingMode(*ft.text); + FontStack fontStack = layout.evaluate<TextFont>(zoom, ft); + GlyphIDs& dependencies = glyphDependencies[fontStack]; + // Loop through all characters of this text and collect unique codepoints. for (char16_t chr : *ft.text) { - glyphDependencies[layout.get<TextFont>()].insert(chr); + dependencies.insert(chr); if (canVerticalizeText) { if (char16_t verticalChr = util::i18n::verticalizePunctuation(chr)) { - glyphDependencies[layout.get<TextFont>()].insert(verticalChr); + dependencies.insert(verticalChr); } } } @@ -183,18 +186,20 @@ void SymbolLayout::prepare(const GlyphMap& glyphMap, const GlyphPositions& glyph const bool textAlongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map && layout.get<SymbolPlacement>() == SymbolPlacementType::Line; - auto glyphMapIt = glyphMap.find(layout.get<TextFont>()); - const Glyphs& glyphs = glyphMapIt != glyphMap.end() - ? glyphMapIt->second : Glyphs(); - - auto glyphPositionsIt = glyphPositions.find(layout.get<TextFont>()); - const GlyphPositionMap& glyphPositionMap = glyphPositionsIt != glyphPositions.end() - ? glyphPositionsIt->second : GlyphPositionMap(); - for (auto it = features.begin(); it != features.end(); ++it) { auto& feature = *it; if (feature.geometry.empty()) continue; + FontStack fontStack = layout.evaluate<TextFont>(zoom, feature); + + auto glyphMapIt = glyphMap.find(fontStack); + const Glyphs& glyphs = glyphMapIt != glyphMap.end() + ? glyphMapIt->second : Glyphs(); + + auto glyphPositionsIt = glyphPositions.find(fontStack); + const GlyphPositionMap& glyphPositionMap = glyphPositionsIt != glyphPositions.end() + ? glyphPositionsIt->second : GlyphPositionMap(); + std::pair<Shaping, Shaping> shapedTextOrientations; optional<PositionedIcon> shapedIcon; diff --git a/src/mbgl/style/conversion/make_property_setters.hpp b/src/mbgl/style/conversion/make_property_setters.hpp index 074d7eb730..18370df636 100644 --- a/src/mbgl/style/conversion/make_property_setters.hpp +++ b/src/mbgl/style/conversion/make_property_setters.hpp @@ -49,7 +49,7 @@ inline auto makeLayoutPropertySetters() { result["text-pitch-alignment"] = &setProperty<SymbolLayer, PropertyValue<AlignmentType>, &SymbolLayer::setTextPitchAlignment>; result["text-rotation-alignment"] = &setProperty<SymbolLayer, PropertyValue<AlignmentType>, &SymbolLayer::setTextRotationAlignment>; result["text-field"] = &setProperty<SymbolLayer, DataDrivenPropertyValue<std::string>, &SymbolLayer::setTextField>; - result["text-font"] = &setProperty<SymbolLayer, PropertyValue<std::vector<std::string>>, &SymbolLayer::setTextFont>; + result["text-font"] = &setProperty<SymbolLayer, DataDrivenPropertyValue<std::vector<std::string>>, &SymbolLayer::setTextFont>; result["text-size"] = &setProperty<SymbolLayer, DataDrivenPropertyValue<float>, &SymbolLayer::setTextSize>; result["text-max-width"] = &setProperty<SymbolLayer, DataDrivenPropertyValue<float>, &SymbolLayer::setTextMaxWidth>; result["text-line-height"] = &setProperty<SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextLineHeight>; diff --git a/src/mbgl/style/expression/assertion.cpp b/src/mbgl/style/expression/assertion.cpp index a17c53cf54..0187921af9 100644 --- a/src/mbgl/style/expression/assertion.cpp +++ b/src/mbgl/style/expression/assertion.cpp @@ -66,6 +66,16 @@ bool Assertion::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Assertion::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& input : inputs) { + for (auto& output : input->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + return result; +} + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/expression/boolean_operator.cpp b/src/mbgl/style/expression/boolean_operator.cpp index 88797f965a..8d277450ba 100644 --- a/src/mbgl/style/expression/boolean_operator.cpp +++ b/src/mbgl/style/expression/boolean_operator.cpp @@ -26,6 +26,10 @@ bool Any::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Any::possibleOutputs() const { + return {{ true }, { false }}; +} + EvaluationResult All::evaluate(const EvaluationContext& params) const { for (auto it = inputs.begin(); it != inputs.end(); it++) { @@ -49,6 +53,10 @@ bool All::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> All::possibleOutputs() const { + return {{ true }, { false }}; +} + using namespace mbgl::style::conversion; template <class T> diff --git a/src/mbgl/style/expression/case.cpp b/src/mbgl/style/expression/case.cpp index 049f258606..295e694189 100644 --- a/src/mbgl/style/expression/case.cpp +++ b/src/mbgl/style/expression/case.cpp @@ -34,6 +34,19 @@ bool Case::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Case::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& branch : branches) { + for (auto& output : branch.second->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + for (auto& output : otherwise->possibleOutputs()) { + result.push_back(std::move(output)); + } + return result; +} + using namespace mbgl::style::conversion; ParseResult Case::parse(const Convertible& value, ParsingContext& ctx) { assert(isArray(value)); diff --git a/src/mbgl/style/expression/coalesce.cpp b/src/mbgl/style/expression/coalesce.cpp index 0373c9626c..872a9abbef 100644 --- a/src/mbgl/style/expression/coalesce.cpp +++ b/src/mbgl/style/expression/coalesce.cpp @@ -27,6 +27,16 @@ bool Coalesce::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Coalesce::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& arg : args) { + for (auto& output : arg->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + return result; +} + using namespace mbgl::style::conversion; ParseResult Coalesce::parse(const Convertible& value, ParsingContext& ctx) { assert(isArray(value)); diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp index 8ed8e160dd..56ab33fcfd 100644 --- a/src/mbgl/style/expression/coercion.cpp +++ b/src/mbgl/style/expression/coercion.cpp @@ -136,6 +136,16 @@ bool Coercion::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Coercion::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& input : inputs) { + for (auto& output : input->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + return result; +} + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/expression/equals.cpp b/src/mbgl/style/expression/equals.cpp index 08ef85e92b..6d963cc1d8 100644 --- a/src/mbgl/style/expression/equals.cpp +++ b/src/mbgl/style/expression/equals.cpp @@ -37,6 +37,10 @@ bool Equals::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Equals::possibleOutputs() const { + return {{ true }, { false }}; +} + static bool isComparableType(const type::Type& type) { return type == type::String || type == type::Number || diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp index 5ddfca8e9f..4cb22a3e4f 100644 --- a/src/mbgl/style/expression/interpolate.cpp +++ b/src/mbgl/style/expression/interpolate.cpp @@ -206,6 +206,16 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { ); } +std::vector<optional<Value>> InterpolateBase::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& stop : stops) { + for (auto& output : stop.second->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + return result; +} + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/expression/let.cpp b/src/mbgl/style/expression/let.cpp index 5c08248eef..fe48138ac3 100644 --- a/src/mbgl/style/expression/let.cpp +++ b/src/mbgl/style/expression/let.cpp @@ -17,6 +17,10 @@ void Let::eachChild(const std::function<void(const Expression&)>& visit) const { visit(*result); } +std::vector<optional<Value>> Let::possibleOutputs() const { + return result->possibleOutputs(); +} + using namespace mbgl::style::conversion; ParseResult Let::parse(const Convertible& value, ParsingContext& ctx) { @@ -67,6 +71,10 @@ EvaluationResult Var::evaluate(const EvaluationContext& params) const { void Var::eachChild(const std::function<void(const Expression&)>&) const {} +std::vector<optional<Value>> Var::possibleOutputs() const { + return { nullopt }; +} + ParseResult Var::parse(const Convertible& value_, ParsingContext& ctx) { assert(isArray(value_)); diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp index 35356747c9..0b2790b688 100644 --- a/src/mbgl/style/expression/match.cpp +++ b/src/mbgl/style/expression/match.cpp @@ -26,6 +26,20 @@ bool Match<T>::operator==(const Expression& e) const { return false; } +template <typename T> +std::vector<optional<Value>> Match<T>::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& branch : branches) { + for (auto& output : branch.second->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + for (auto& output : otherwise->possibleOutputs()) { + result.push_back(std::move(output)); + } + return result; +} + template<> EvaluationResult Match<std::string>::evaluate(const EvaluationContext& params) const { const EvaluationResult inputValue = input->evaluate(params); diff --git a/src/mbgl/style/expression/step.cpp b/src/mbgl/style/expression/step.cpp index 11bf543b76..614a2addad 100644 --- a/src/mbgl/style/expression/step.cpp +++ b/src/mbgl/style/expression/step.cpp @@ -47,6 +47,16 @@ bool Step::operator==(const Expression& e) const { return false; } +std::vector<optional<Value>> Step::possibleOutputs() const { + std::vector<optional<Value>> result; + for (const auto& stop : stops) { + for (auto& output : stop.second->possibleOutputs()) { + result.push_back(std::move(output)); + } + } + return result; +} + Range<float> Step::getCoveringStops(const double lower, const double upper) const { return ::mbgl::style::expression::getCoveringStops(stops, lower, upper); } diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 9a944657ca..d1a1ba246e 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -412,15 +412,15 @@ void SymbolLayer::setTextField(DataDrivenPropertyValue<std::string> value) { baseImpl = std::move(impl_); observer->onLayerChanged(*this); } -PropertyValue<std::vector<std::string>> SymbolLayer::getDefaultTextFont() { +DataDrivenPropertyValue<std::vector<std::string>> SymbolLayer::getDefaultTextFont() { return TextFont::defaultValue(); } -PropertyValue<std::vector<std::string>> SymbolLayer::getTextFont() const { +DataDrivenPropertyValue<std::vector<std::string>> SymbolLayer::getTextFont() const { return impl().layout.get<TextFont>(); } -void SymbolLayer::setTextFont(PropertyValue<std::vector<std::string>> value) { +void SymbolLayer::setTextFont(DataDrivenPropertyValue<std::vector<std::string>> value) { if (value == getTextFont()) return; auto impl_ = mutableImpl(); diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 436b5cbd4f..e70ac28d59 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -112,7 +112,7 @@ struct TextField : DataDrivenLayoutProperty<std::string> { static std::string defaultValue() { return ""; } }; -struct TextFont : LayoutProperty<std::vector<std::string>> { +struct TextFont : DataDrivenLayoutProperty<std::vector<std::string>> { static constexpr const char * key = "text-font"; static std::vector<std::string> defaultValue() { return { "Open Sans Regular", "Arial Unicode MS Regular" }; } }; diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 10fce33986..52d788b3a1 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -271,28 +271,29 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique } std::vector<FontStack> Parser::fontStacks() const { - std::set<FontStack> optional; + std::set<FontStack> result; for (const auto& layer : layers) { if (layer->is<SymbolLayer>()) { - PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont(); - if (textFont.isUndefined()) { - optional.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); - } else if (textFont.isConstant()) { - optional.insert(textFont.asConstant()); - } else if (textFont.isCameraFunction()) { - textFont.asCameraFunction().stops.match( - [&] (const auto& stops) { - for (const auto& stop : stops.stops) { - optional.insert(stop.second); + layer->as<SymbolLayer>()->getTextFont().match( + [&] (Undefined) { + result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); + }, + [&] (const FontStack& constant) { + result.insert(constant); + }, + [&] (const auto& function) { + for (const auto& value : function.possibleOutputs()) { + if (value) { + result.insert(*value); } } - ); - } + } + ); } } - return std::vector<FontStack>(optional.begin(), optional.end()); + return std::vector<FontStack>(result.begin(), result.end()); } } // namespace style |