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
|
/*
* Copyright © 2018–2019 Egmont Koblinger
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib.h>
#include "ring.hh"
#include "ringview.hh"
#include "vterowdata.hh"
#include "vtetypes.hh"
#include "vteunistr.h"
namespace vte {
namespace base {
class RingView;
/* BidiRow contains the BiDi transformation of a single row. */
class BidiRow {
friend class BidiRunner;
public:
BidiRow() { }
~BidiRow();
// prevent accidents
BidiRow(BidiRow& o) = delete;
BidiRow(BidiRow const& o) = delete;
BidiRow(BidiRow&& o) = delete;
BidiRow& operator= (BidiRow& o) = delete;
BidiRow& operator= (BidiRow const& o) = delete;
BidiRow& operator= (BidiRow&& o) = delete;
vte::grid::column_t log2vis(vte::grid::column_t col) const;
vte::grid::column_t vis2log(vte::grid::column_t col) const;
bool log_is_rtl(vte::grid::column_t col) const;
bool vis_is_rtl(vte::grid::column_t col) const;
vteunistr vis_get_shaped_char(vte::grid::column_t col, vteunistr s) const;
/* Whether the line's base direction is RTL. */
inline constexpr bool base_is_rtl() const noexcept { return m_base_rtl; }
/* Whether the implicit paragraph contains a foreign directionality character.
* This is used in the cursor, showing the character's directionality. */
inline constexpr bool has_foreign() const noexcept { return m_has_foreign; }
private:
void set_width(vte::grid::column_t width);
/* The value of m_width == 0 is a valid representation of the trivial LTR mapping. */
uint16_t m_width{0};
uint16_t m_width_alloc{0};
/* These will be initialized / allocated on demand, when some shuffling or shaping is needed. */
uint16_t *m_log2vis{nullptr};
uint16_t *m_vis2log{nullptr};
uint8_t *m_vis_rtl{nullptr}; /* FIXME use a bitset */
gunichar *m_vis_shaped_base_char{nullptr}; /* without combining accents */
bool m_base_rtl{false};
bool m_has_foreign{false};
};
/* BidiRunner is not a "real" class, rather the collection of methods that run the BiDi algorithm. */
class BidiRunner {
public:
constexpr BidiRunner(RingView *ringview) : m_ringview{ringview} { }
~BidiRunner() { }
// prevent accidents
BidiRunner(BidiRunner& o) = delete;
BidiRunner(BidiRunner const& o) = delete;
BidiRunner(BidiRunner&& o) = delete;
BidiRunner& operator= (BidiRunner& o) = delete;
BidiRunner& operator= (BidiRunner const& o) = delete;
BidiRunner& operator= (BidiRunner&& o) = delete;
void paragraph(vte::grid::row_t start, vte::grid::row_t end,
bool do_bidi, bool do_shaping);
private:
RingView *m_ringview;
#ifdef WITH_FRIBIDI
void explicit_line_shape(vte::grid::row_t row);
#endif
void explicit_line(vte::grid::row_t row, bool rtl, bool do_shaping);
void explicit_paragraph(vte::grid::row_t start, vte::grid::row_t end, bool rtl, bool do_shaping);
#ifdef WITH_FRIBIDI
bool implicit_paragraph(vte::grid::row_t start, vte::grid::row_t end, bool do_shaping);
#endif
};
}; /* namespace base */
}; /* namespace vte */
gboolean vte_bidi_get_mirror_char (vteunistr unistr, gboolean mirror_box_drawing, vteunistr *unistr_mirrored);
|