diff options
Diffstat (limited to 'src/mbgl/text')
-rw-r--r-- | src/mbgl/text/quads.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/text/shaping.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/text/shaping.hpp | 14 |
3 files changed, 20 insertions, 12 deletions
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 20427924a4..92866566d8 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -13,11 +13,13 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, const std::vector<Coordinate>& line, const SymbolLayoutProperties& layout, const bool alongLine) { + auto image = *(shapedIcon.image); + const float border = 1.0; auto left = shapedIcon.left - border; - auto right = left + shapedIcon.image.w; + auto right = left + image.pos.w / image.relativePixelRatio; auto top = shapedIcon.top - border; - auto bottom = top + shapedIcon.image.h; + auto bottom = top + image.pos.h / image.relativePixelRatio; vec2<float> tl{left, top}; vec2<float> tr{right, top}; vec2<float> br{right, bottom}; @@ -51,7 +53,7 @@ SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, } SymbolQuads quads; - quads.emplace_back(tl, tr, bl, br, shapedIcon.image, 0, anchor, globalMinScale, std::numeric_limits<float>::infinity()); + quads.emplace_back(tl, tr, bl, br, image.pos, 0, anchor, globalMinScale, std::numeric_limits<float>::infinity()); return quads; } diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 735841e8ca..f12658c669 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -3,13 +3,13 @@ namespace mbgl { -PositionedIcon shapeIcon(const Rect<uint16_t>& image, const SymbolLayoutProperties& layout) { +PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties& layout) { float dx = layout.icon.offset.value[0]; float dy = layout.icon.offset.value[1]; - float x1 = dx - image.originalW / 2.0f; - float x2 = x1 + image.originalW; - float y1 = dy - image.originalH / 2.0f; - float y2 = y1 + image.originalH; + float x1 = dx - image.texture->width / 2.0f; + float x2 = x1 + image.texture->width; + float y1 = dy - image.texture->height / 2.0f; + float y2 = y1 + image.texture->height; return PositionedIcon(image, y1, y2, x1, x2); } diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index acf8c470bf..decf7b946e 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -2,29 +2,35 @@ #define MBGL_TEXT_SHAPING #include <mbgl/text/glyph.hpp> +#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/sprite/sprite_image.hpp> +#include <mapbox/optional.hpp> #include <mbgl/util/vec.hpp> namespace mbgl { + struct SpriteAtlasElement; + class PositionedIcon { public: inline explicit PositionedIcon() {} - inline explicit PositionedIcon(Rect<uint16_t> _image, + inline explicit PositionedIcon(const SpriteAtlasElement& _image, float _top, float _bottom, float _left, float _right) : image(_image), top(_top), bottom(_bottom), left(_left), right(_right) {} - Rect<uint16_t> image; + + mapbox::util::optional<SpriteAtlasElement> image; float top = 0; float bottom = 0; float left = 0; float right = 0; - operator bool() const { return image.hasArea(); } + operator bool() const { return image && (*image).pos.hasArea(); } }; class SymbolLayoutProperties; - PositionedIcon shapeIcon(const Rect<uint16_t>& image, const SymbolLayoutProperties&); + PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties&); } // namespace mbgl |