diff options
author | Molly Lloyd <molly@mapbox.com> | 2017-03-27 17:30:58 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-28 11:06:58 -0700 |
commit | 47c1e42ac1073ef02093b59336588f389f287227 (patch) | |
tree | 9e1737ff6c56f2d07fa2eddab4055a19af5479ba | |
parent | 5f402975267e0cb0baf87a13afcd0d1366791d01 (diff) | |
download | qtlocation-mapboxgl-47c1e42ac1073ef02093b59336588f389f287227.tar.gz |
[core] implement dds for text-offset
12 files changed, 105 insertions, 24 deletions
diff --git a/include/mbgl/style/conversion/make_property_setters.hpp b/include/mbgl/style/conversion/make_property_setters.hpp index 623cc09098..2f26fe75c4 100644 --- a/include/mbgl/style/conversion/make_property_setters.hpp +++ b/include/mbgl/style/conversion/make_property_setters.hpp @@ -60,7 +60,7 @@ auto makeLayoutPropertySetters() { result["text-padding"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<float>, &SymbolLayer::setTextPadding>; result["text-keep-upright"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setTextKeepUpright>; result["text-transform"] = &setLayoutProperty<V, SymbolLayer, DataDrivenPropertyValue<TextTransformType>, &SymbolLayer::setTextTransform>; - result["text-offset"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<std::array<float, 2>>, &SymbolLayer::setTextOffset>; + result["text-offset"] = &setLayoutProperty<V, SymbolLayer, DataDrivenPropertyValue<std::array<float, 2>>, &SymbolLayer::setTextOffset>; result["text-allow-overlap"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setTextAllowOverlap>; result["text-ignore-placement"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setTextIgnorePlacement>; result["text-optional"] = &setLayoutProperty<V, SymbolLayer, PropertyValue<bool>, &SymbolLayer::setTextOptional>; diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index d24f808bac..b507c992f5 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -151,9 +151,9 @@ public: DataDrivenPropertyValue<TextTransformType> getTextTransform() const; void setTextTransform(DataDrivenPropertyValue<TextTransformType>); - static PropertyValue<std::array<float, 2>> getDefaultTextOffset(); - PropertyValue<std::array<float, 2>> getTextOffset() const; - void setTextOffset(PropertyValue<std::array<float, 2>>); + static DataDrivenPropertyValue<std::array<float, 2>> getDefaultTextOffset(); + DataDrivenPropertyValue<std::array<float, 2>> getTextOffset() const; + void setTextOffset(DataDrivenPropertyValue<std::array<float, 2>>); static PropertyValue<bool> getDefaultTextAllowOverlap(); PropertyValue<bool> getTextAllowOverlap() const; diff --git a/mapbox-gl-js b/mapbox-gl-js -Subproject c24867267058f1e5f07ad50a003b2d32c3c532d +Subproject c34b6e9bc4a2672c1046267408f1055271484b2 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index bfbbf1e77b..ef0bd38b56 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -2055,11 +2055,11 @@ public class PropertyFactory { /** * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. * - * @param <Z> the zoom parameter type - * @param function a wrapper {@link CameraFunction} for Float[] + * @param <T> the function input type + * @param function a wrapper function for Float[] * @return property wrapper around a Float[] function */ - public static <Z extends Number> PropertyValue<CameraFunction<Z, Float[]>> textOffset(CameraFunction<Z, Float[]> function) { + public static <T> PropertyValue<Function<T, Float[]>> textOffset(Function<T, Float[]> function) { return new LayoutPropertyValue<>("text-offset", function); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java index c90af339b1..cac950dfc4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java @@ -1455,6 +1455,51 @@ public class SymbolLayerTest extends BaseStyleTest { } @Test + public void testTextOffsetAsIdentitySourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOffset(property("FeaturePropertyA", Stops.<Float[]>identity())) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); + assertEquals(IdentityStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + } + + @Test + public void testTextOffsetAsIntervalSourceFunction() { + checkViewIsDisplayed(R.id.mapView); + Timber.i("text-offset"); + assertNotNull(layer); + + // Set + layer.setProperties( + textOffset( + property( + "FeaturePropertyA", + interval( + stop(1, textOffset(new Float[]{0f,0f})) + ) + ) + ) + ); + + // Verify + assertNotNull(layer.getTextOffset()); + assertNotNull(layer.getTextOffset().getFunction()); + assertEquals(SourceFunction.class, layer.getTextOffset().getFunction().getClass()); + assertEquals("FeaturePropertyA", ((SourceFunction) layer.getTextOffset().getFunction()).getProperty()); + assertEquals(IntervalStops.class, layer.getTextOffset().getFunction().getStops().getClass()); + } + + @Test public void testTextAllowOverlapAsConstant() { checkViewIsDisplayed(R.id.mapView); Timber.i("text-allow-overlap"); diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index c76efe2de7..11dc67b458 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -1026,6 +1026,15 @@ MGL_EXPORT * `MGLCameraStyleFunction` with an interpolation mode of: * `MGLInterpolationModeExponential` * `MGLInterpolationModeInterval` + * `MGLSourceStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` + * `MGLInterpolationModeIdentity` + * `MGLCompositeStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` */ @property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textOffset; #else @@ -1047,6 +1056,15 @@ MGL_EXPORT * `MGLCameraStyleFunction` with an interpolation mode of: * `MGLInterpolationModeExponential` * `MGLInterpolationModeInterval` + * `MGLSourceStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` + * `MGLInterpolationModeIdentity` + * `MGLCompositeStyleFunction` with an interpolation mode of: + * `MGLInterpolationModeExponential` + * `MGLInterpolationModeInterval` + * `MGLInterpolationModeCategorical` */ @property (nonatomic, null_resettable) MGLStyleValue<NSValue *> *textOffset; #endif diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 8441931685..6e35bf5dd2 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -763,7 +763,7 @@ namespace mbgl { - (void)setTextOffset:(MGLStyleValue<NSValue *> *)textOffset { MGLAssertStyleLayerIsValid(); - auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toInterpolatablePropertyValue(textOffset); + auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenPropertyValue(textOffset); self.rawLayer->setTextOffset(mbglValue); } @@ -772,9 +772,9 @@ namespace mbgl { auto propertyValue = self.rawLayer->getTextOffset(); if (propertyValue.isUndefined()) { - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(self.rawLayer->getDefaultTextOffset()); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(self.rawLayer->getDefaultTextOffset()); } - return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); + return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toDataDrivenStyleValue(propertyValue); } - (void)setTextOptional:(MGLStyleValue<NSNumber *> *)textOptional { diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index e3e473ef78..18dfa1366f 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -1158,7 +1158,7 @@ #endif ]; layer.textOffset = constantStyleValue; - mbgl::style::PropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; + mbgl::style::DataDrivenPropertyValue<std::array<float, 2>> propertyValue = { { 1, 1 } }; XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, @"Setting textOffset to a constant value should update text-offset."); XCTAssertEqualObjects(layer.textOffset, constantStyleValue, @@ -1175,6 +1175,29 @@ XCTAssertEqualObjects(layer.textOffset, functionStyleValue, @"textOffset should round-trip camera functions."); + functionStyleValue = [MGLStyleValue<NSValue *> valueWithInterpolationMode:MGLInterpolationModeExponential sourceStops:@{@18: constantStyleValue} attributeName:@"keyName" options:nil]; + layer.textOffset = functionStyleValue; + + mbgl::style::ExponentialStops<std::array<float, 2>> exponentialStops = { {{18, { 1, 1 }}}, 1.0 }; + propertyValue = mbgl::style::SourceFunction<std::array<float, 2>> { "keyName", exponentialStops }; + + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a source function should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, functionStyleValue, + @"textOffset should round-trip source functions."); + + functionStyleValue = [MGLStyleValue<NSValue *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; + layer.textOffset = functionStyleValue; + + std::map<float, std::array<float, 2>> innerStops { {18, { 1, 1 }} }; + mbgl::style::CompositeExponentialStops<std::array<float, 2>> compositeStops { { {10.0, innerStops} }, 1.0 }; + + propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>> { "keyName", compositeStops }; + + XCTAssertEqual(rawLayer->getTextOffset(), propertyValue, + @"Setting textOffset to a composite function should update text-offset."); + XCTAssertEqualObjects(layer.textOffset, functionStyleValue, + @"textOffset should round-trip composite functions."); layer.textOffset = nil; @@ -1182,11 +1205,6 @@ @"Unsetting textOffset should return text-offset to the default value."); XCTAssertEqualObjects(layer.textOffset, defaultStyleValue, @"textOffset should return the default value after being unset."); - - functionStyleValue = [MGLStyleValue<NSValue *> valueWithInterpolationMode:MGLInterpolationModeIdentity sourceStops:nil attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textOffset = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); - functionStyleValue = [MGLStyleValue<NSValue *> valueWithInterpolationMode:MGLInterpolationModeInterval compositeStops:@{@18: constantStyleValue} attributeName:@"" options:nil]; - XCTAssertThrowsSpecificNamed(layer.textOffset = functionStyleValue, NSException, NSInvalidArgumentException, @"MGLStyleValue should raise an exception if it is applied to a property that cannot support it"); } // text-optional diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 3a2c082ad8..8e36bb84ea 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -250,7 +250,7 @@ void SymbolLayout::prepare(uintptr_t tileUID, /* verticalAlign */ verticalAlign, /* justify */ justify, /* spacing: ems */ layout.get<TextLetterSpacing>() * oneEm, - /* translate */ Point<float>(layout.get<TextOffset>()[0], layout.get<TextOffset>()[1]), + /* translate */ Point<float>(layout.evaluate<TextOffset>(zoom, feature)[0] * oneEm, layout.evaluate<TextOffset>(zoom, feature)[1] * oneEm), /* verticalHeight */ oneEm, /* writingMode */ writingMode, /* bidirectional algorithm object */ bidi); diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 42bcf0e6b0..02e1e364f1 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -483,15 +483,15 @@ void SymbolLayer::setTextTransform(DataDrivenPropertyValue<TextTransformType> va impl->layout.unevaluated.get<TextTransform>() = value; impl->observer->onLayerLayoutPropertyChanged(*this, "text-transform"); } -PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextOffset() { +DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextOffset() { return TextOffset::defaultValue(); } -PropertyValue<std::array<float, 2>> SymbolLayer::getTextOffset() const { +DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getTextOffset() const { return impl->layout.unevaluated.get<TextOffset>(); } -void SymbolLayer::setTextOffset(PropertyValue<std::array<float, 2>> value) { +void SymbolLayer::setTextOffset(DataDrivenPropertyValue<std::array<float, 2>> value) { if (value == getTextOffset()) return; impl->layout.unevaluated.get<TextOffset>() = value; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index f2b7bfa00f..e7cfb8d455 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -160,7 +160,7 @@ struct TextTransform : DataDrivenLayoutProperty<TextTransformType> { static TextTransformType defaultValue() { return TextTransformType::None; } }; -struct TextOffset : LayoutProperty<std::array<float, 2>> { +struct TextOffset : DataDrivenLayoutProperty<std::array<float, 2>> { static constexpr const char * key = "text-offset"; static std::array<float, 2> defaultValue() { return {{ 0, 0 }}; } }; diff --git a/src/mbgl/text/glyph_set.cpp b/src/mbgl/text/glyph_set.cpp index 19a6e2cddd..ea0dd123db 100644 --- a/src/mbgl/text/glyph_set.cpp +++ b/src/mbgl/text/glyph_set.cpp @@ -45,7 +45,7 @@ const Shaping GlyphSet::getShaping(const std::u16string& logicalInput, const float verticalHeight, const WritingModeType writingMode, BiDi& bidi) const { - Shaping shaping(translate.x * 24, translate.y * 24, writingMode); + Shaping shaping(translate.x, translate.y, writingMode); std::vector<std::u16string> reorderedLines = bidi.processText(logicalInput, @@ -66,9 +66,9 @@ void align(Shaping& shaping, const std::size_t lineCount, const Point<float>& translate) { const float shiftX = - (justify - horizontalAlign) * maxLineLength + ::round(translate.x * 24 /* one em */); + (justify - horizontalAlign) * maxLineLength + ::round(translate.x); const float shiftY = - (-verticalAlign * lineCount + 0.5) * lineHeight + ::round(translate.y * 24 /* one em */); + (-verticalAlign * lineCount + 0.5) * lineHeight + ::round(translate.y); for (auto& glyph : shaping.positionedGlyphs) { glyph.x += shiftX; |