summaryrefslogtreecommitdiff
path: root/include/mbgl/text/glyph.hpp
blob: 899c8fffee8e0cbc3c9095f2e88a9736b456d59e (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
#ifndef MBGL_TEXT_GLYPH
#define MBGL_TEXT_GLYPH

#include <mbgl/util/rect.hpp>

#include <cstdint>
#include <vector>
#include <map>

namespace mbgl {

typedef std::pair<uint16_t, uint16_t> GlyphRange;

// Note: this only works for the BMP
GlyphRange getGlyphRange(char32_t glyph);

struct GlyphMetrics {
    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;

};

struct Glyph {
    inline explicit Glyph() : rect(0, 0, 0, 0), metrics() {}
    inline explicit Glyph(const Rect<uint16_t> &rect,
                          const GlyphMetrics &metrics)
        : rect(rect), metrics(metrics) {}

    operator bool() const {
        return !metrics && !rect;
    }

    const Rect<uint16_t> rect;
    const GlyphMetrics metrics;
};

typedef std::map<uint32_t, Glyph> GlyphPositions;

class GlyphPlacement {
public:
    inline explicit GlyphPlacement(uint32_t face, uint32_t glyph, uint32_t x, uint32_t y)
        : face(face), glyph(glyph), x(x), y(y) {}

    uint32_t face = 0;
    uint32_t glyph = 0;
    int32_t x = 0;
    int32_t y = 0;
};

typedef std::vector<GlyphPlacement> Shaping;
}

#endif