-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayout.h
62 lines (46 loc) · 1009 Bytes
/
Layout.h
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
#pragma once
#include <cstdint>
#include <vector>
#include <SheenBidi.h>
#include <harfbuzz/hb.h>
// NOTE: Works only for one line
struct TextLayout {
struct Glyph {
uint32_t codepoint;
uint32_t cluster;
float x_offset;
float y_offset;
float x_advance;
float y_advance;
};
struct Run {
hb_buffer_t* buffer;
hb_script_t script;
hb_direction_t direction;
uint32_t offset;
uint32_t length;
};
public:
TextLayout(hb_font_t* font, SBStringEncoding encoding, void* string, size_t length);
~TextLayout();
void layout();
float get_caret_pos_from_index(uint32_t index);
uint32_t get_caret_index_from_pos(float pos);
const std::vector<Glyph>& get_glyphs() const {
return glyphs;
}
const std::vector<Run>& get_runs() const {
return runs;
}
private:
void split_into_runs(
const SBRun* sb_runs,
SBUInteger run_count
);
void shape();
private:
SBCodepointSequence text = {};
hb_font_t* hb_font = nullptr;
std::vector<Run> runs;
std::vector<Glyph> glyphs;
};