[core] move icon rotation from shaping to quad generation to mirror JS
This commit is contained in:
committed by
Alexander Shalamov
parent
1342cb44b3
commit
027e803b72
@@ -26,14 +26,15 @@ SymbolInstanceSharedData::SymbolInstanceSharedData(GeometryCoordinates line_,
|
||||
const style::SymbolPlacementType textPlacement,
|
||||
const std::array<float, 2>& textOffset,
|
||||
const ImageMap& imageMap,
|
||||
float iconRotation,
|
||||
SymbolContent iconType,
|
||||
bool allowVerticalPlacement)
|
||||
: line(std::move(line_)) {
|
||||
// Create the quads used for rendering the icon and glyphs.
|
||||
if (shapedIcon) {
|
||||
iconQuads = getIconQuads(*shapedIcon, iconType);
|
||||
iconQuads = getIconQuads(*shapedIcon, iconRotation, iconType);
|
||||
if (verticallyShapedIcon) {
|
||||
verticalIconQuads = getIconQuads(*verticallyShapedIcon, iconType);
|
||||
verticalIconQuads = getIconQuads(*verticallyShapedIcon, iconRotation, iconType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ struct SymbolInstanceSharedData {
|
||||
const style::SymbolPlacementType textPlacement,
|
||||
const std::array<float, 2>& textOffset,
|
||||
const ImageMap& imageMap,
|
||||
float iconRotation,
|
||||
SymbolContent iconType,
|
||||
bool allowVerticalPlacement);
|
||||
bool empty() const;
|
||||
|
||||
@@ -474,8 +474,7 @@ void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap,
|
||||
iconType = SymbolContent::IconRGBA;
|
||||
shapedIcon = PositionedIcon::shapeIcon(imagePositions.at(feature.icon->id()),
|
||||
layout->evaluate<IconOffset>(zoom, feature),
|
||||
layout->evaluate<IconAnchor>(zoom, feature),
|
||||
layout->evaluate<IconRotate>(zoom, feature) * util::DEG2RAD);
|
||||
layout->evaluate<IconAnchor>(zoom, feature));
|
||||
if (image->second->sdf) {
|
||||
iconType = SymbolContent::IconSDF;
|
||||
}
|
||||
@@ -601,6 +600,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex,
|
||||
textPlacement,
|
||||
textOffset,
|
||||
imageMap,
|
||||
iconRotation,
|
||||
iconType,
|
||||
allowVerticalPlacement);
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace mbgl {
|
||||
|
||||
using namespace style;
|
||||
|
||||
SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, SymbolContent iconType) {
|
||||
SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, const float iconRotate, const SymbolContent iconType) {
|
||||
const ImagePosition& image = shapedIcon.image();
|
||||
|
||||
// If you have a 10px icon that isn't perfectly aligned to the pixel grid it will cover 11 actual
|
||||
@@ -42,7 +42,7 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, SymbolContent iconTyp
|
||||
Point<float> br{right, bottom};
|
||||
Point<float> bl{left, bottom};
|
||||
|
||||
const float angle = shapedIcon.angle();
|
||||
const float angle = iconRotate * util::DEG2RAD;
|
||||
|
||||
if (angle) {
|
||||
// Compute the transformation matrix.
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
using SymbolQuads = std::vector<SymbolQuad>;
|
||||
|
||||
SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, SymbolContent iconType);
|
||||
SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, float iconRotate, SymbolContent iconType);
|
||||
|
||||
SymbolQuads getGlyphQuads(const Shaping& shapedText,
|
||||
const std::array<float, 2> textOffset,
|
||||
|
||||
@@ -70,8 +70,7 @@ style::TextJustifyType getAnchorJustification(style::SymbolAnchorType anchor) {
|
||||
|
||||
PositionedIcon PositionedIcon::shapeIcon(const ImagePosition& image,
|
||||
const std::array<float, 2>& iconOffset,
|
||||
style::SymbolAnchorType iconAnchor,
|
||||
const float iconRotation) {
|
||||
style::SymbolAnchorType iconAnchor) {
|
||||
AnchorAlignment anchorAlign = AnchorAlignment::getAnchorAlignment(iconAnchor);
|
||||
float dx = iconOffset[0];
|
||||
float dy = iconOffset[1];
|
||||
@@ -80,7 +79,7 @@ PositionedIcon PositionedIcon::shapeIcon(const ImagePosition& image,
|
||||
float top = dy - image.displaySize()[1] * anchorAlign.verticalAlign;
|
||||
float bottom = top + image.displaySize()[1];
|
||||
|
||||
return PositionedIcon { image, top, bottom, left, right, iconRotation };
|
||||
return PositionedIcon{image, top, bottom, left, right};
|
||||
}
|
||||
|
||||
void PositionedIcon::fitIconToText(const Shaping& shapedText,
|
||||
|
||||
@@ -28,21 +28,19 @@ class BiDi;
|
||||
|
||||
class PositionedIcon {
|
||||
private:
|
||||
PositionedIcon(ImagePosition image_, float top_, float bottom_, float left_, float right_, float angle_)
|
||||
: _image(image_), _top(top_), _bottom(bottom_), _left(left_), _right(right_), _angle(angle_) {}
|
||||
PositionedIcon(ImagePosition image_, float top_, float bottom_, float left_, float right_)
|
||||
: _image(image_), _top(top_), _bottom(bottom_), _left(left_), _right(right_) {}
|
||||
|
||||
ImagePosition _image;
|
||||
float _top;
|
||||
float _bottom;
|
||||
float _left;
|
||||
float _right;
|
||||
float _angle;
|
||||
|
||||
public:
|
||||
static PositionedIcon shapeIcon(const ImagePosition&,
|
||||
const std::array<float, 2>& iconOffset,
|
||||
style::SymbolAnchorType iconAnchor,
|
||||
const float iconRotation);
|
||||
style::SymbolAnchorType iconAnchor);
|
||||
|
||||
// Updates shaped icon's bounds based on shaped text's bounds and provided
|
||||
// layout properties.
|
||||
@@ -57,7 +55,6 @@ public:
|
||||
float bottom() const { return _bottom; }
|
||||
float left() const { return _left; }
|
||||
float right() const { return _right; }
|
||||
float angle() const { return _angle; }
|
||||
};
|
||||
|
||||
const Shaping getShaping(const TaggedString& string,
|
||||
|
||||
@@ -24,6 +24,7 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) {
|
||||
placementType,
|
||||
textOffset,
|
||||
imageMap,
|
||||
0,
|
||||
SymbolContent::IconSDF,
|
||||
false);
|
||||
return SymbolInstance(anchor, std::move(sharedData), shaping, nullopt, nullopt, 0, 0, placementType, textOffset, 0, 0, iconOffset, subfeature, 0, 0, key, 0.0f, 0.0f, 0.0f, variableTextOffset, false);
|
||||
|
||||
@@ -18,11 +18,11 @@ TEST(getIconQuads, normal) {
|
||||
style::Image::Impl("test", PremultipliedImage({1,1}), 1.0)
|
||||
};
|
||||
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -6.5f, -4.5f }}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-6.5f, -4.5f}}, SymbolAnchorType::Center);
|
||||
|
||||
GeometryCoordinates line;
|
||||
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -54,7 +54,7 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// none
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
|
||||
EXPECT_FLOAT_EQ(-18.5f, shapedIcon.top());
|
||||
EXPECT_FLOAT_EQ(-0.5f, shapedIcon.right());
|
||||
@@ -62,7 +62,7 @@ TEST(getIconQuads, style) {
|
||||
EXPECT_FLOAT_EQ(-18.5f, shapedIcon.left());
|
||||
|
||||
SymbolLayoutProperties::Evaluated layout;
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -79,9 +79,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// width
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Width, {{0, 0, 0, 0}}, {{0, 0}}, 24.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -98,9 +98,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// width x textSize
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Width, {{0, 0, 0, 0}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -117,9 +117,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// width x textSize + padding
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Width, {{5, 10, 5, 10}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -136,9 +136,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// height
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Height, {{0, 0, 0, 0}}, {{0, 0}}, 24.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -156,9 +156,9 @@ TEST(getIconQuads, style) {
|
||||
// height x textSize
|
||||
{
|
||||
SymbolLayoutProperties::Evaluated layout;
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Height, {{0, 0, 0, 0}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -175,9 +175,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// height x textSize + padding
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Height, {{5, 10, 5, 20}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -194,9 +194,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// both
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Both, {{0, 0, 0, 0}}, {{0, 0}}, 24.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -213,9 +213,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// both x textSize
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Both, {{0, 0, 0, 0}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -232,9 +232,9 @@ TEST(getIconQuads, style) {
|
||||
|
||||
// both x textSize + padding
|
||||
{
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Both, {{5, 10, 5, 10}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
@@ -253,9 +253,9 @@ TEST(getIconQuads, style) {
|
||||
{
|
||||
SymbolLayoutProperties::Evaluated layout;
|
||||
layout.get<TextSize>() = 12.0f;
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center, 0);
|
||||
auto shapedIcon = PositionedIcon::shapeIcon(image, {{-9.5f, -9.5f}}, SymbolAnchorType::Center);
|
||||
shapedIcon.fitIconToText(shapedText, IconTextFitType::Both, {{0, 5, 10, 15}}, {{0, 0}}, 12.0f / 24.0f);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, SymbolContent::IconRGBA);
|
||||
SymbolQuads quads = getIconQuads(shapedIcon, 0, SymbolContent::IconRGBA);
|
||||
|
||||
ASSERT_EQ(quads.size(), 1);
|
||||
const auto& quad = quads[0];
|
||||
|
||||
Reference in New Issue
Block a user