summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph.hpp
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-08-07 19:19:32 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-08-09 18:02:46 +0300
commitc53896caefc96a8c18ab746026330ddc4fc0338e (patch)
tree8f562b0c416d6c99f7b565e58b758701f6081677 /src/mbgl/text/glyph.hpp
parent9ecbe3642fb4a53b558598239b59bf1d0224c25b (diff)
downloadqtlocation-mapboxgl-c53896caefc96a8c18ab746026330ddc4fc0338e.tar.gz
Bump Mapbox GL Nativeqt-v1.1.0
mapbox-gl-native @ edd7948893fcd40a24d96b790e21d3dd028cecbe
Diffstat (limited to 'src/mbgl/text/glyph.hpp')
-rw-r--r--src/mbgl/text/glyph.hpp101
1 files changed, 62 insertions, 39 deletions
diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp
index 2bf1448492..19ecdfd17c 100644
--- a/src/mbgl/text/glyph.hpp
+++ b/src/mbgl/text/glyph.hpp
@@ -1,7 +1,13 @@
#pragma once
#include <mbgl/text/glyph_range.hpp>
+#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/rect.hpp>
+#include <mbgl/util/traits.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/immutable.hpp>
+#include <mbgl/util/image.hpp>
+#include <mbgl/util/util.hpp>
#include <cstdint>
#include <vector>
@@ -10,21 +16,18 @@
namespace mbgl {
+using GlyphID = char16_t;
+using GlyphIDs = std::set<GlyphID>;
+
// Note: this only works for the BMP
-GlyphRange getGlyphRange(char16_t glyph);
+GlyphRange getGlyphRange(GlyphID glyph);
struct GlyphMetrics {
- explicit operator bool() const {
- return !(width == 0 && height == 0 && advance == 0);
- }
-
- // Glyph metrics.
uint32_t width = 0;
uint32_t height = 0;
int32_t left = 0;
int32_t top = 0;
uint32_t advance = 0;
-
};
inline bool operator==(const GlyphMetrics& lhs, const GlyphMetrics& rhs) {
@@ -35,59 +38,79 @@ inline bool operator==(const GlyphMetrics& lhs, const GlyphMetrics& rhs) {
lhs.advance == rhs.advance;
}
-struct Glyph {
- explicit Glyph() : rect(0, 0, 0, 0), metrics() {}
- explicit Glyph(Rect<uint16_t> rect_, GlyphMetrics metrics_)
- : rect(std::move(rect_)), metrics(std::move(metrics_)) {}
+class Glyph {
+public:
+ // We're using this value throughout the Mapbox GL ecosystem. If this is different, the glyphs
+ // also need to be reencoded.
+ static constexpr const uint8_t borderSize = 3;
+
+ GlyphID id = 0;
- explicit operator bool() const {
- return metrics || rect.hasArea();
- }
+ // A signed distance field of the glyph with a border (see above).
+ AlphaImage bitmap;
- const Rect<uint16_t> rect;
- const GlyphMetrics metrics;
+ // Glyph metrics
+ GlyphMetrics metrics;
};
-typedef std::map<uint32_t, Glyph> GlyphPositions;
+using Glyphs = std::map<GlyphID, optional<Immutable<Glyph>>>;
+using GlyphMap = std::map<FontStack, Glyphs>;
class PositionedGlyph {
public:
- explicit PositionedGlyph(uint32_t glyph_, float x_, float y_)
- : glyph(glyph_), x(x_), y(y_) {}
+ explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, float angle_)
+ : glyph(glyph_), x(x_), y(y_), angle(angle_) {}
- uint32_t glyph = 0;
+ GlyphID glyph = 0;
float x = 0;
float y = 0;
+ float angle = 0;
};
+enum class WritingModeType : uint8_t;
+
class Shaping {
public:
- explicit Shaping() : top(0), bottom(0), left(0), right(0) {}
- explicit Shaping(float x, float y, std::u16string text_)
- : text(std::move(text_)), top(y), bottom(y), left(x), right(x) {}
+ explicit Shaping() = default;
+ explicit Shaping(float x, float y, WritingModeType writingMode_)
+ : top(y), bottom(y), left(x), right(x), writingMode(writingMode_) {}
std::vector<PositionedGlyph> positionedGlyphs;
- std::u16string text;
- int32_t top;
- int32_t bottom;
- int32_t left;
- int32_t right;
+ int32_t top = 0;
+ int32_t bottom = 0;
+ int32_t left = 0;
+ int32_t right = 0;
+ WritingModeType writingMode;
explicit operator bool() const { return !positionedGlyphs.empty(); }
};
-class SDFGlyph {
-public:
- // We're using this value throughout the Mapbox GL ecosystem. If this is different, the glyphs
- // also need to be reencoded.
- static constexpr const uint8_t borderSize = 3;
+enum class WritingModeType : uint8_t {
+ None = 0,
+ Horizontal = 1 << 0,
+ Vertical = 1 << 1,
+};
- uint32_t id = 0;
+MBGL_CONSTEXPR WritingModeType operator|(WritingModeType a, WritingModeType b) {
+ return WritingModeType(mbgl::underlying_type(a) | mbgl::underlying_type(b));
+}
- // A signed distance field of the glyph with a border (see above).
- std::string bitmap;
+MBGL_CONSTEXPR WritingModeType& operator|=(WritingModeType& a, WritingModeType b) {
+ return (a = a | b);
+}
- // Glyph metrics
- GlyphMetrics metrics;
-};
+MBGL_CONSTEXPR bool operator&(WritingModeType lhs, WritingModeType rhs) {
+ return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
+}
+
+MBGL_CONSTEXPR WritingModeType& operator&=(WritingModeType& lhs, WritingModeType rhs) {
+ return (lhs = WritingModeType(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs)));
+}
+
+MBGL_CONSTEXPR WritingModeType operator~(WritingModeType value) {
+ return WritingModeType(~mbgl::underlying_type(value));
+}
+
+using GlyphDependencies = std::map<FontStack,GlyphIDs>;
+using GlyphRangeDependencies = std::map<FontStack,GlyphRangeSet>;
} // end namespace mbgl