summaryrefslogtreecommitdiff
path: root/src/mbgl/layout/symbol_instance.hpp
blob: 7d002d22859b6d2312e91e003f5faf68d0f41b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#pragma once

#include <mbgl/text/quads.hpp>
#include <mbgl/text/glyph_atlas.hpp>
#include <mbgl/text/collision_feature.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/util/traits.hpp>
#include <mbgl/util/util.hpp>

namespace mbgl {

class Anchor;
class IndexedSubfeature;

struct ShapedTextOrientations {
    Shaping horizontal;
    Shaping vertical;
    // The following are used with variable text placement on.
    Shaping& right = horizontal; 
    Shaping center;
    Shaping left;
    bool singleLine = false;
};

struct SymbolInstanceSharedData {
    SymbolInstanceSharedData(GeometryCoordinates line,
                            const ShapedTextOrientations& shapedTextOrientations,
                            const optional<PositionedIcon>& shapedIcon,
                            const optional<PositionedIcon>& verticallyShapedIcon,
                            const style::SymbolLayoutProperties::Evaluated& layout,
                            const style::SymbolPlacementType textPlacement,
                            const std::array<float, 2>& textOffset,
                            const GlyphPositions& positions,
                            bool allowVerticalPlacement);
    bool empty() const;
    GeometryCoordinates line;
    // Note: When singleLine == true, only `rightJustifiedGlyphQuads` is populated.
    SymbolQuads rightJustifiedGlyphQuads;
    SymbolQuads centerJustifiedGlyphQuads;
    SymbolQuads leftJustifiedGlyphQuads;
    SymbolQuads verticalGlyphQuads;
    optional<SymbolQuad> iconQuad;
    optional<SymbolQuad> verticalIconQuad;
};

enum class SymbolContent : uint8_t {
    None = 0,
    Text = 1 << 0,
    IconRGBA = 1 << 1,
    IconSDF = 1 << 2
};

MBGL_CONSTEXPR SymbolContent operator|(SymbolContent a, SymbolContent b) {
    return SymbolContent(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}

MBGL_CONSTEXPR SymbolContent& operator|=(SymbolContent& a, SymbolContent b) {
    return (a = a | b);
}

MBGL_CONSTEXPR SymbolContent operator&(SymbolContent a, SymbolContent b) {
    return SymbolContent(mbgl::underlying_type(a) & mbgl::underlying_type(b));
}

class SymbolInstance {
public:
    SymbolInstance(Anchor& anchor_,
                   std::shared_ptr<SymbolInstanceSharedData> sharedData,
                   const ShapedTextOrientations& shapedTextOrientations,
                   const optional<PositionedIcon>& shapedIcon,
                   const optional<PositionedIcon>& verticallyShapedIcon,
                   const float textBoxScale,
                   const float textPadding,
                   const style::SymbolPlacementType textPlacement,
                   const std::array<float, 2>& textOffset,
                   const float iconBoxScale,
                   const float iconPadding,
                   const std::array<float, 2>& iconOffset,
                   const IndexedSubfeature& indexedFeature,
                   const std::size_t layoutFeatureIndex,
                   const std::size_t dataFeatureIndex,
                   std::u16string key,
                   const float overscaling,
                   const float iconRotation,
                   const float textRotation,
                   float radialTextOffset,
                   bool allowVerticalPlacement,
                   const SymbolContent iconType = SymbolContent::None);

    optional<size_t> getDefaultHorizontalPlacedTextIndex() const;
    const GeometryCoordinates& line() const;
    const SymbolQuads& rightJustifiedGlyphQuads() const;
    const SymbolQuads& leftJustifiedGlyphQuads() const;
    const SymbolQuads& centerJustifiedGlyphQuads() const;
    const SymbolQuads& verticalGlyphQuads() const;
    bool hasText() const;
    bool hasIcon() const;
    bool hasSdfIcon() const;
    const optional<SymbolQuad>& iconQuad() const;
    const optional<SymbolQuad>& verticalIconQuad() const;
    void releaseSharedData();

private:
    std::shared_ptr<SymbolInstanceSharedData> sharedData;

public:
    Anchor anchor;
    SymbolContent symbolContent;

    std::size_t rightJustifiedGlyphQuadsSize;
    std::size_t centerJustifiedGlyphQuadsSize;
    std::size_t leftJustifiedGlyphQuadsSize;
    std::size_t verticalGlyphQuadsSize;

    CollisionFeature textCollisionFeature;
    CollisionFeature iconCollisionFeature;
    optional<CollisionFeature> verticalTextCollisionFeature = nullopt;
    optional<CollisionFeature> verticalIconCollisionFeature = nullopt;
    WritingModeType writingModes;
    std::size_t layoutFeatureIndex; // Index into the set of features included at layout time
    std::size_t dataFeatureIndex;   // Index into the underlying tile data feature set
    std::array<float, 2> textOffset;
    std::array<float, 2> iconOffset;
    std::u16string key;
    bool isDuplicate;
    optional<size_t> placedRightTextIndex;
    optional<size_t> placedCenterTextIndex;
    optional<size_t> placedLeftTextIndex;
    optional<size_t> placedVerticalTextIndex;
    optional<size_t> placedIconIndex;
    optional<size_t> placedVerticalIconIndex;
    float textBoxScale;
    float radialTextOffset;
    bool singleLine;
    uint32_t crossTileID = 0;
};

} // namespace mbgl