summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorYoung Hahn <young@mapbox.com>2016-06-15 17:13:31 -0400
committerGitHub <noreply@github.com>2016-06-15 17:13:31 -0400
commit199ea2a82a74cf2f7b63078e2dd4b8274c061851 (patch)
tree5d56478a020a911745d793b8ac5d7f236730c621 /test
parenta020e535cac36d69a8939fb7956260d2217c65b4 (diff)
downloadqtlocation-mapboxgl-199ea2a82a74cf2f7b63078e2dd4b8274c061851.tar.gz
Support for icon-text-fit, icon-text-fit-padding (#5334)
* Add support for icon-text-fit * Port unit tests for getIconQuads() from js => cpp * Add support for padding in all 4 directions. * Update all hashes post-merge
Diffstat (limited to 'test')
-rw-r--r--test/test.gypi2
-rw-r--r--test/text/quads.cpp266
2 files changed, 268 insertions, 0 deletions
diff --git a/test/test.gypi b/test/test.gypi
index da605b6fd8..e72718d865 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -56,6 +56,8 @@
'math/minmax.cpp',
'math/clamp.cpp',
+ 'text/quads.cpp',
+
'tile/geometry_tile_data.cpp',
'tile/tile_id.cpp',
diff --git a/test/text/quads.cpp b/test/text/quads.cpp
new file mode 100644
index 0000000000..6fdd769fc3
--- /dev/null
+++ b/test/text/quads.cpp
@@ -0,0 +1,266 @@
+#include <mbgl/geometry/anchor.hpp>
+#include <mbgl/sprite/sprite_atlas.hpp>
+#include <mbgl/test/util.hpp>
+#include <mbgl/text/quads.hpp>
+#include <mbgl/text/shaping.hpp>
+#include <mbgl/text/glyph.hpp>
+#include <mbgl/style/layers/symbol_layer.hpp>
+#include <mbgl/style/layers/symbol_layer_impl.hpp>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+TEST(getIconQuads, normal) {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0);
+ SpriteAtlasElement image = {
+ Rect<uint16_t>( 0, 0, 15, 11 ),
+ std::shared_ptr<const SpriteImage>(),
+ 1.0f
+ };
+ PositionedIcon shapedIcon(image, -5.0, 6.0, -7.0, 8.0);
+ GeometryCoordinates line;
+ Shaping shapedText;
+
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads.size(), 1u);
+ ASSERT_EQ(quads[0].anchorPoint.x, 2);
+ ASSERT_EQ(quads[0].anchorPoint.y, 3);
+ ASSERT_EQ(quads[0].tl.x, -8);
+ ASSERT_EQ(quads[0].tl.y, -6);
+ ASSERT_EQ(quads[0].tr.x, 7);
+ ASSERT_EQ(quads[0].tr.y, -6);
+ ASSERT_EQ(quads[0].bl.x, -8);
+ ASSERT_EQ(quads[0].bl.y, 5);
+ ASSERT_EQ(quads[0].br.x, 7);
+ ASSERT_EQ(quads[0].br.y, 5);
+ ASSERT_EQ(quads[0].anchorAngle, 0.0f);
+ ASSERT_EQ(quads[0].glyphAngle, 0.0f);
+ ASSERT_EQ(quads[0].minScale, 0.5f);
+}
+
+TEST(getIconQuads, style) {
+ Anchor anchor(0.0, 0.0, 0.0, 0.5f, 0);
+ SpriteAtlasElement image = {
+ Rect<uint16_t>( 0, 0, 20, 20 ),
+ std::shared_ptr<const SpriteImage>(),
+ 1.0f
+ };
+ PositionedIcon shapedIcon(image, -10.0, 10.0, -10.0, 10.0);
+ GeometryCoordinates line;
+ Shaping shapedText;
+ shapedText.top = -10.0f;
+ shapedText.bottom = 30.0f;
+ shapedText.left = -60.0f;
+ shapedText.right = 20.0f;
+ shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f));
+
+ // none
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads.size(), 1u);
+ ASSERT_EQ(quads[0].anchorPoint.x, 0);
+ ASSERT_EQ(quads[0].anchorPoint.y, 0);
+ ASSERT_EQ(quads[0].tl.x, -11);
+ ASSERT_EQ(quads[0].tl.y, -11);
+ ASSERT_EQ(quads[0].tr.x, 9);
+ ASSERT_EQ(quads[0].tr.y, -11);
+ ASSERT_EQ(quads[0].bl.x, -11);
+ ASSERT_EQ(quads[0].bl.y, 9);
+ ASSERT_EQ(quads[0].br.x, 9);
+ ASSERT_EQ(quads[0].br.y, 9);
+ ASSERT_EQ(quads[0].anchorAngle, 0.0f);
+ ASSERT_EQ(quads[0].glyphAngle, 0.0f);
+ ASSERT_EQ(quads[0].minScale, 0.5f);
+ }
+
+ // width
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -60);
+ ASSERT_EQ(quads[0].tl.y, 0);
+ ASSERT_EQ(quads[0].tr.x, 20);
+ ASSERT_EQ(quads[0].tr.y, 0);
+ ASSERT_EQ(quads[0].bl.x, -60);
+ ASSERT_EQ(quads[0].bl.y, 20);
+ ASSERT_EQ(quads[0].br.x, 20);
+ ASSERT_EQ(quads[0].br.y, 20);
+ }
+
+ // width x textSize
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -30);
+ ASSERT_EQ(quads[0].tl.y, -5);
+ ASSERT_EQ(quads[0].tr.x, 10);
+ ASSERT_EQ(quads[0].tr.y, -5);
+ ASSERT_EQ(quads[0].bl.x, -30);
+ ASSERT_EQ(quads[0].bl.y, 15);
+ ASSERT_EQ(quads[0].br.x, 10);
+ ASSERT_EQ(quads[0].br.y, 15);
+ }
+
+ // width x textSize + padding
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
+ layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -40);
+ ASSERT_EQ(quads[0].tl.y, -10);
+ ASSERT_EQ(quads[0].tr.x, 20);
+ ASSERT_EQ(quads[0].tr.y, -10);
+ ASSERT_EQ(quads[0].bl.x, -40);
+ ASSERT_EQ(quads[0].bl.y, 20);
+ ASSERT_EQ(quads[0].br.x, 20);
+ ASSERT_EQ(quads[0].br.y, 20);
+ }
+
+ // height
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -30);
+ ASSERT_EQ(quads[0].tl.y, -10);
+ ASSERT_EQ(quads[0].tr.x, -10);
+ ASSERT_EQ(quads[0].tr.y, -10);
+ ASSERT_EQ(quads[0].bl.x, -30);
+ ASSERT_EQ(quads[0].bl.y, 30);
+ ASSERT_EQ(quads[0].br.x, -10);
+ ASSERT_EQ(quads[0].br.y, 30);
+ }
+
+ // height x textSize
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -20);
+ ASSERT_EQ(quads[0].tl.y, -5);
+ ASSERT_EQ(quads[0].tr.x, 0);
+ ASSERT_EQ(quads[0].tr.y, -5);
+ ASSERT_EQ(quads[0].bl.x, -20);
+ ASSERT_EQ(quads[0].bl.y, 15);
+ ASSERT_EQ(quads[0].br.x, 0);
+ ASSERT_EQ(quads[0].br.y, 15);
+ }
+
+ // height x textSize + padding
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
+ layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -30);
+ ASSERT_EQ(quads[0].tl.y, -10);
+ ASSERT_EQ(quads[0].tr.x, 10);
+ ASSERT_EQ(quads[0].tr.y, -10);
+ ASSERT_EQ(quads[0].bl.x, -30);
+ ASSERT_EQ(quads[0].bl.y, 20);
+ ASSERT_EQ(quads[0].br.x, 10);
+ ASSERT_EQ(quads[0].br.y, 20);
+ }
+
+ // both
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(24.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -60);
+ ASSERT_EQ(quads[0].tl.y, -10);
+ ASSERT_EQ(quads[0].tr.x, 20);
+ ASSERT_EQ(quads[0].tr.y, -10);
+ ASSERT_EQ(quads[0].bl.x, -60);
+ ASSERT_EQ(quads[0].bl.y, 30);
+ ASSERT_EQ(quads[0].br.x, 20);
+ ASSERT_EQ(quads[0].br.y, 30);
+ }
+
+ // both x textSize
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -30);
+ ASSERT_EQ(quads[0].tl.y, -5);
+ ASSERT_EQ(quads[0].tr.x, 10);
+ ASSERT_EQ(quads[0].tr.y, -5);
+ ASSERT_EQ(quads[0].bl.x, -30);
+ ASSERT_EQ(quads[0].bl.y, 15);
+ ASSERT_EQ(quads[0].br.x, 10);
+ ASSERT_EQ(quads[0].br.y, 15);
+ }
+
+ // both x textSize + padding
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ layer->impl->layout.iconTextFitPadding.value[0] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[1] = 10.0f;
+ layer->impl->layout.iconTextFitPadding.value[2] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -40);
+ ASSERT_EQ(quads[0].tl.y, -10);
+ ASSERT_EQ(quads[0].tr.x, 20);
+ ASSERT_EQ(quads[0].tr.y, -10);
+ ASSERT_EQ(quads[0].bl.x, -40);
+ ASSERT_EQ(quads[0].bl.y, 20);
+ ASSERT_EQ(quads[0].br.x, 20);
+ ASSERT_EQ(quads[0].br.y, 20);
+ }
+
+ // both x textSize + padding t/r/b/l
+ {
+ auto layer = std::make_unique<SymbolLayer>("symbol");
+ layer->impl->layout.textSize = LayoutProperty<float>(12.0f);
+ layer->impl->layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ layer->impl->layout.iconTextFitPadding.value[0] = 0.0f;
+ layer->impl->layout.iconTextFitPadding.value[1] = 5.0f;
+ layer->impl->layout.iconTextFitPadding.value[2] = 10.0f;
+ layer->impl->layout.iconTextFitPadding.value[3] = 15.0f;
+ SymbolQuads quads = getIconQuads(anchor, shapedIcon, line, layer->impl->layout, false, shapedText);
+
+ ASSERT_EQ(quads[0].tl.x, -45);
+ ASSERT_EQ(quads[0].tl.y, -5);
+ ASSERT_EQ(quads[0].tr.x, 15);
+ ASSERT_EQ(quads[0].tr.y, -5);
+ ASSERT_EQ(quads[0].bl.x, -45);
+ ASSERT_EQ(quads[0].bl.y, 25);
+ ASSERT_EQ(quads[0].br.x, 15);
+ ASSERT_EQ(quads[0].br.y, 25);
+ }
+}
+