summaryrefslogtreecommitdiff
path: root/include/llmr/style/types.hpp
blob: 82632849aca363f48e39ba06561114a8c0da5810 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef LLMR_STYLE_TYPES
#define LLMR_STYLE_TYPES

#include <llmr/util/enum.hpp>

#include <string>
#include <array>

namespace llmr {

// Stores a premultiplied color, with all four channels ranging from 0..1
typedef std::array<float, 4> Color;

enum class StyleLayerType : uint8_t {
    Unknown,
    Fill,
    Line,
    Icon,
    Text,
    Raster,
    Composite,
    Background
};

LLMR_DEFINE_ENUM_CLASS(StyleLayerTypeClass, StyleLayerType, {
    { StyleLayerType::Unknown, "unknown" },
    { StyleLayerType::Fill, "fill" },
    { StyleLayerType::Line, "line" },
    { StyleLayerType::Icon, "icon" },
    { StyleLayerType::Text, "text" },
    { StyleLayerType::Raster, "raster" },
    { StyleLayerType::Composite, "composite" },
    { StyleLayerType::Background, "background" },
    { StyleLayerType(-1), "unknown" },
});


enum class WindingType : uint8_t {
    EvenOdd,
    NonZero,
    Default = NonZero
};

enum class CapType : uint8_t {
    None,
    Round,
    Butt,
    Square,
    Default = None
};

enum class JoinType : uint8_t {
    None,
    Miter,
    Bevel,
    Round,
    Default = None
};

enum class TextPathType : uint8_t {
    Horizontal,
    Curve,
    Default = Horizontal
};

enum class TextTransformType : uint8_t {
    None,
    Uppercase,
    Lowercase,
    Default = None
};

enum class TranslateAnchorType : uint8_t {
    Map,
    Viewport,
    Default = Map
};

enum class RotateAnchorType : uint8_t {
    Map,
    Viewport,
    Default = Viewport
};

enum class SourceType : uint8_t {
    Vector,
    Raster,
    GeoJSON,
    Video,
    Default = Vector
};

inline WindingType parseWindingType(const std::string &type) {
    if (type == "even-odd") return WindingType::EvenOdd;
    if (type == "non-zero") return WindingType::NonZero;
    return WindingType::Default;
}

inline CapType parseCapType(const std::string &cap) {
    if (cap == "round") return CapType::Round;
    if (cap == "butt") return CapType::Butt;
    if (cap == "square") return CapType::Square;
    return CapType::None;
}

inline JoinType parseJoinType(const std::string &join) {
    if (join == "miter") return JoinType::Miter;
    if (join == "bevel") return JoinType::Bevel;
    if (join == "round") return JoinType::Round;
    return JoinType::None;
}

inline TextPathType parseTextPathType(const std::string &path) {
    if (path == "horizontal") return TextPathType::Horizontal;
    if (path == "curve") return TextPathType::Curve;
    return TextPathType::Default;
}

inline TextTransformType parseTextTransformType(const std::string& transform) {
    if (transform == "uppercase") return TextTransformType::Uppercase;
    if (transform == "lowercase") return TextTransformType::Lowercase;
    return TextTransformType::Default;
};

inline TranslateAnchorType parseTranslateAnchorType(const std::string &anchor) {
    if (anchor == "map") return TranslateAnchorType::Map;
    if (anchor == "viewport") return TranslateAnchorType::Viewport;
    return TranslateAnchorType::Default;
}

inline RotateAnchorType parseRotateAnchorType(const std::string &anchor) {
    if (anchor == "map") return RotateAnchorType::Map;
    if (anchor == "viewport") return RotateAnchorType::Viewport;
    return RotateAnchorType::Default;
}

inline float parseAlignmentType(const std::string &alignment) {
    if (alignment == "right") return 1.0f;
    if (alignment == "left") return 0.0f;
    return 0.5f;
}

inline float parseVerticalAlignmentType(const std::string &alignment) {
    if (alignment == "bottom") return 1.0f;
    if (alignment == "top") return 0.0f;
    return 0.5f;
}

inline SourceType parseSourceType(const std::string &source) {
    if (source == "vector") return SourceType::Vector;
    if (source == "raster") return SourceType::Raster;
    if (source == "geojson") return SourceType::GeoJSON;
    if (source == "video") return SourceType::Video;
    return SourceType::Default;
}

}

#endif