diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-10-02 17:03:50 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-15 13:15:46 -0700 |
commit | ce76bde13d0f4381ee861f81daf636defaff0bc5 (patch) | |
tree | e37d93d14fc64620069bac5488bae871af2fa431 /platform | |
parent | bc718257748f1ad87658e85f8c31b574afca57a9 (diff) | |
download | qtlocation-mapboxgl-ce76bde13d0f4381ee861f81daf636defaff0bc5.tar.gz |
[core] Initial implementation of 'format' expression
Diffstat (limited to 'platform')
-rw-r--r-- | platform/node/src/node_expression.cpp | 32 | ||||
-rw-r--r-- | platform/node/test/ignores.json | 17 |
2 files changed, 32 insertions, 17 deletions
diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index c0b512a899..4f1e392505 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -37,10 +37,11 @@ type::Type parseType(v8::Local<v8::Object> type) { static std::unordered_map<std::string, type::Type> types = { {"string", type::String}, {"number", type::Number}, - {"noolean", type::Boolean}, + {"boolean", type::Boolean}, {"object", type::Object}, {"color", type::Color}, - {"value", type::Value} + {"value", type::Value}, + {"formatted", type::Formatted} }; v8::Local<v8::Value> v8kind = Nan::Get(type, Nan::New("kind").ToLocalChecked()).ToLocalChecked(); @@ -151,6 +152,33 @@ struct ToValue { Nan::EscapableHandleScope scope; return scope.Escape(Nan::Null()); } + + v8::Local<v8::Value> operator()(const Formatted& formatted) { + // This mimics the internal structure of the Formatted class in formatted.js + // A better approach might be to use the explicit serialized form + // both here and on the JS side? e.g. toJS(fromExpressionValue<mbgl::Value>(formatted)) + std::unordered_map<std::string, mbgl::Value> serialized; + std::vector<mbgl::Value> sections; + for (const auto& section : formatted.sections) { + std::unordered_map<std::string, mbgl::Value> serializedSection; + serializedSection.emplace("text", section.text); + if (section.fontScale) { + serializedSection.emplace("scale", *section.fontScale); + } else { + serializedSection.emplace("scale", mbgl::NullValue()); + } + if (section.fontStack) { + std::string fontStackString; + serializedSection.emplace("fontStack", mbgl::fontStackToString(*section.fontStack)); + } else { + serializedSection.emplace("fontStack", mbgl::NullValue()); + } + sections.push_back(serializedSection); + } + serialized.emplace("sections", sections); + + return toJS(serialized); + } v8::Local<v8::Value> operator()(const mbgl::Color& color) { return operator()(std::vector<Value> { diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json index e6ef57bd1e..9632677d46 100644 --- a/platform/node/test/ignores.json +++ b/platform/node/test/ignores.json @@ -1,17 +1,5 @@ { "expression-tests/collator/accent-equals-de": "Locale-specific behavior changes based on platform.", - "expression-tests/format/basic": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/coercion": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/implicit": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/implicit-assert": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/implicit-coerce": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/implicit-omit": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/to-string": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/to-string": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/to-string": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/to-string": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/basic": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "expression-tests/format/to-string": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", "expression-tests/interpolate-hcl/linear": "https://github.com/mapbox/mapbox-gl-native/issues/8720", "expression-tests/interpolate-lab/linear": "https://github.com/mapbox/mapbox-gl-native/issues/8720", "expression-tests/is-supported-script/default": "This tests RTL text plugin behavior specific to GL JS", @@ -82,6 +70,7 @@ "query-tests/feature-state/default": "skip - port https://github.com/mapbox/mapbox-gl-js/pull/6263 - needs issue", "query-tests/regressions/mapbox-gl-js#6555": "skip - no querySourceFeatures in mbgl-node; needs issue", "render-tests/background-color/transition": "https://github.com/mapbox/mapbox-gl-native/issues/10619", + "render-tests/canvas/default": "skip - js specific", "render-tests/collator/resolved-locale": "Some test platforms don't resolve 'en' locale", "render-tests/collator/default": "Some test platforms don't resolve 'en' locale", "render-tests/custom-layer-js/null-island": "skip - js specific", @@ -121,6 +110,7 @@ "render-tests/regressions/mapbox-gl-js#6706": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/regressions/mapbox-gl-js#6806": "pending https://github.com/mapbox/mapbox-gl-js/pull/6812", "render-tests/regressions/mapbox-gl-js#7271": "https://github.com/mapbox/mapbox-gl-native/issues/12888", + "render-tests/regressions/mapbox-gl-js#7302": "skip - js specific", "render-tests/regressions/mapbox-gl-native#7357": "https://github.com/mapbox/mapbox-gl-native/issues/7357", "render-tests/runtime-styling/image-add-sdf": "https://github.com/mapbox/mapbox-gl-native/issues/9847", "render-tests/runtime-styling/paint-property-fill-flat-to-extrude": "https://github.com/mapbox/mapbox-gl-native/issues/6745", @@ -128,9 +118,6 @@ "render-tests/symbol-cross-fade/chinese": "https://github.com/mapbox/mapbox-gl-native/issues/10619", "render-tests/symbol-placement/line-overscaled": "https://github.com/mapbox/mapbox-gl-js/issues/5654", "render-tests/symbol-visibility/visible": "https://github.com/mapbox/mapbox-gl-native/issues/10409", - "render-tests/text-field/formatted-arabic": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "render-tests/text-field/formatted-line": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", - "render-tests/text-field/formatted": "skip - https://github.com/mapbox/mapbox-gl-native/pull/12624", "render-tests/text-pitch-alignment/auto-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-alignment/map-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", "render-tests/text-pitch-alignment/viewport-text-rotation-alignment-map": "https://github.com/mapbox/mapbox-gl-native/issues/9732", |