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
|
#pragma once
#include <mbgl/text/glyph_range.hpp>
#include <mbgl/util/rect.hpp>
#include <cstdint>
#include <vector>
#include <string>
#include <map>
namespace mbgl {
// Note: this only works for the BMP
GlyphRange getGlyphRange(char16_t 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) {
return lhs.width == rhs.width &&
lhs.height == rhs.height &&
lhs.left == rhs.left &&
lhs.top == rhs.top &&
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_)) {}
explicit operator bool() const {
return metrics || rect.hasArea();
}
const Rect<uint16_t> rect;
const GlyphMetrics metrics;
};
typedef std::map<uint32_t, Glyph> GlyphPositions;
class PositionedGlyph {
public:
explicit PositionedGlyph(uint32_t glyph_, float x_, float y_)
: glyph(glyph_), x(x_), y(y_) {}
uint32_t glyph = 0;
float x = 0;
float y = 0;
};
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) {}
std::vector<PositionedGlyph> positionedGlyphs;
std::u16string text;
int32_t top;
int32_t bottom;
int32_t left;
int32_t right;
explicit operator bool() const { return !positionedGlyphs.empty(); }
};
class SDFGlyph {
public:
uint32_t id = 0;
// A signed distance field of the glyph with a border of 3 pixels.
std::string bitmap;
// Glyph metrics
GlyphMetrics metrics;
};
} // end namespace mbgl
|