Krita Source Code Documentation
Loading...
Searching...
No Matches
KoCssTextUtils.cpp File Reference
#include "KoCssTextUtils.h"
#include "graphemebreak.h"
#include <QChar>
#include <kis_assert.h>

Go to the source code of this file.

Functions

static QChar findProportionalToFullWidth (const QChar &value, const QChar &defaultValue)
 
static QChar findSmallKanaToBigKana (const QChar &value, const QChar &defaultValue)
 
bool isVariationSelector (uint val)
 
QVector< QPair< int, int > > positionDifference (QStringList a, QStringList b)
 
bool regionalIndicator (uint val)
 

Variables

const QString BIDI_CONTROL_FSI = "\u2068"
 
const QString BIDI_CONTROL_LRE = "\u202a"
 
const QString BIDI_CONTROL_LRI = "\u2066"
 
const QString BIDI_CONTROL_LRO = "\u202d"
 
const QString BIDI_CONTROL_PDF = "\u202c"
 
const QString BIDI_CONTROL_PDI = "\u2069"
 
const QString BIDI_CONTROL_RLE = "\u202b"
 
const QString BIDI_CONTROL_RLI = "\u2067"
 
const QString BIDI_CONTROL_RLO = "\u202e"
 
static QVector< QChar::Script > blockScript
 
static QVector< QChar::Script > clusterScript
 
const QString UNICODE_BIDI_ISOLATE_OVERRIDE_END = "\u202c\u2069"
 
const QString UNICODE_BIDI_ISOLATE_OVERRIDE_LR_START = "\u2068\u202d"
 
const QString UNICODE_BIDI_ISOLATE_OVERRIDE_RL_START = "\u2068\u202e"
 
const QChar ZERO_WIDTH_JOINER = QChar{0x200d}
 

Function Documentation

◆ findProportionalToFullWidth()

static QChar findProportionalToFullWidth ( const QChar & value,
const QChar & defaultValue )
static

Definition at line 87 of file KoCssTextUtils.cpp.

88{
89 static QMap<QChar, QChar> map = []() {
90 QMap<QChar, QChar> map;
91 // https://stackoverflow.com/questions/8326846/
92 for (int i = 0x0021; i < 0x007F; i++) {
93 map.insert(QChar(i), QChar(i + 0xFF00 - 0x0020));
94 }
95 map.insert(QChar(0x0020), QChar(0x3000)); // Ideographic space.
96
97 return map;
98 }();
99
100 return map.value(value, defaultValue);
101}
float value(const T *src, size_t ch)

References value().

◆ findSmallKanaToBigKana()

static QChar findSmallKanaToBigKana ( const QChar & value,
const QChar & defaultValue )
static

Definition at line 118 of file KoCssTextUtils.cpp.

119{
120 static QMap<QChar, QChar> map = {
121 // NOTE: these are not fully sequential!
122 // clang-format off
123 {QChar{0x3041}, QChar{0x3042}},
124 {QChar{0x3043}, QChar{0x3044}},
125 {QChar{0x3045}, QChar{0x3046}},
126 {QChar{0x3047}, QChar{0x3048}},
127 {QChar{0x3049}, QChar{0x304A}},
128 {QChar{0x3095}, QChar{0x304B}},
129 {QChar{0x3096}, QChar{0x3051}},
130 {QChar{0x1B132}, QChar{0x3053}},
131 {QChar{0x3063}, QChar{0x3064}},
132 {QChar{0x3083}, QChar{0x3084}},
133 {QChar{0x3085}, QChar{0x3086}},
134 {QChar{0x3087}, QChar{0x3088}},
135 {QChar{0x308E}, QChar{0x308F}},
136 {QChar{0x1B150}, QChar{0x3090}},
137 {QChar{0x1B151}, QChar{0x3091}},
138 {QChar{0x1B152}, QChar{0x3092}},
139
140 {QChar{0x30A1}, QChar{0x30A2}},
141 {QChar{0x30A3}, QChar{0x30A4}},
142 {QChar{0x30A5}, QChar{0x30A6}},
143 {QChar{0x30A7}, QChar{0x30A8}},
144 {QChar{0x30A9}, QChar{0x30AA}},
145 {QChar{0x30F5}, QChar{0x30AB}},
146 {QChar{0x31F0}, QChar{0x30AF}},
147 {QChar{0x30F6}, QChar{0x30B1}},
148 {QChar{0x1B155}, QChar{0x30B3}},
149 {QChar{0x31F1}, QChar{0x30B7}},
150 {QChar{0x31F2}, QChar{0x30B9}},
151 {QChar{0x30C3}, QChar{0x30C4}},
152 {QChar{0x31F3}, QChar{0x30C8}},
153 {QChar{0x31F4}, QChar{0x30CC}},
154 {QChar{0x31F5}, QChar{0x30CF}},
155 {QChar{0x31F6}, QChar{0x30D2}},
156 {QChar{0x31F7}, QChar{0x30D5}},
157 {QChar{0x31F8}, QChar{0x30D8}},
158 {QChar{0x31F9}, QChar{0x30DB}},
159 {QChar{0x31FA}, QChar{0x30E0}},
160 {QChar{0x30E3}, QChar{0x30E4}},
161 {QChar{0x30E5}, QChar{0x30E6}},
162 {QChar{0x30E7}, QChar{0x30E8}},
163 {QChar{0x31FB}, QChar{0x30E9}},
164 {QChar{0x31FC}, QChar{0x30EA}},
165 {QChar{0x31FD}, QChar{0x30EB}},
166 {QChar{0x31FE}, QChar{0x30EC}},
167 {QChar{0x31FF}, QChar{0x30ED}},
168 {QChar{0x30EE}, QChar{0x30EF}},
169 {QChar{0x1B164}, QChar{0x30F0}},
170 {QChar{0x1B165}, QChar{0x30F1}},
171 {QChar{0x1B166}, QChar{0x30F2}},
172 {QChar{0x1B167}, QChar{0x30F3}},
173
174 {QChar{0xFF67}, QChar{0xFF71}},
175 {QChar{0xFF68}, QChar{0xFF72}},
176 {QChar{0xFF69}, QChar{0xFF73}},
177 {QChar{0xFF6A}, QChar{0xFF74}},
178 {QChar{0xFF6B}, QChar{0xFF75}},
179 {QChar{0xFF6F}, QChar{0xFF82}},
180 {QChar{0xFF6C}, QChar{0xFF94}},
181 {QChar{0xFF6D}, QChar{0xFF95}},
182 {QChar{0xFF6E}, QChar{0xFF96}},
183 // clang-format on
184 };
185
186 return map.value(value, defaultValue);
187}

References value().

◆ isVariationSelector()

bool isVariationSelector ( uint val)

Definition at line 505 of file KoCssTextUtils.cpp.

505 {
506 // Original set of VS
507 if (val == 0xfe00 || (val > 0xfe00 && val <= 0xfe0f)) {
508 return true;
509 }
510 // Extended set VS
511 if (val == 0xe0100 || (val > 0xe0100 && val <= 0xe01ef)) {
512 return true;
513 }
514 // Mongolian VS
515 if (val == 0x180b || (val > 0x180b && val <= 0x180f)) {
516 return true;
517 }
518 // Emoji skin tones
519 if (val == 0x1f3fb || (val > 0x1f3fb && val <= 0x1f3ff)) {
520 return true;
521 }
522 return false;
523}

◆ positionDifference()

QVector< QPair< int, int > > positionDifference ( QStringList a,
QStringList b )

Definition at line 11 of file KoCssTextUtils.cpp.

11 {
12 QVector<QPair<int, int>> positions;
13 if (a.isEmpty() && b.isEmpty()) return positions;
14
15 int countA = 0;
16 int countB = 0;
17 for (int i=0; i< a.size(); i++) {
18 QString textA = a.at(i);
19 QString textB = b.at(i);
20 if (textA.size() > textB.size()) {
21 for (int j=0; j < textA.size(); j++) {
22 int k = j < textB.size()? countB+j: -1;
23 positions.append(qMakePair(countA+j, k));
24 }
25 } else {
26 for (int j=0; j < textB.size(); j++) {
27 int k = j < textA.size()? countA+j: -1;
28 positions.append(qMakePair(k, countB+j));
29 }
30 }
31 countA += textA.size();
32 countB += textB.size();
33 }
34
35 return positions;
36}

◆ regionalIndicator()

bool regionalIndicator ( uint val)

Definition at line 525 of file KoCssTextUtils.cpp.

525 {
526 if (val == 0x1f1e6 || (val > 0x1f1e6 && val <= 0x1f1ff)) {
527 return true;
528 }
529 return false;
530}

Variable Documentation

◆ BIDI_CONTROL_FSI

const QString BIDI_CONTROL_FSI = "\u2068"

Definition at line 446 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_LRE

const QString BIDI_CONTROL_LRE = "\u202a"

Definition at line 439 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_LRI

const QString BIDI_CONTROL_LRI = "\u2066"

Definition at line 444 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_LRO

const QString BIDI_CONTROL_LRO = "\u202d"

Definition at line 442 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_PDF

const QString BIDI_CONTROL_PDF = "\u202c"

Definition at line 441 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_PDI

const QString BIDI_CONTROL_PDI = "\u2069"

Definition at line 447 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_RLE

const QString BIDI_CONTROL_RLE = "\u202b"

Definition at line 440 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_RLI

const QString BIDI_CONTROL_RLI = "\u2067"

Definition at line 445 of file KoCssTextUtils.cpp.

◆ BIDI_CONTROL_RLO

const QString BIDI_CONTROL_RLO = "\u202e"

Definition at line 443 of file KoCssTextUtils.cpp.

◆ blockScript

QVector<QChar::Script> blockScript
static
Initial value:
{
QChar::Script_Bopomofo,
QChar::Script_Han,
QChar::Script_Hangul,
QChar::Script_Hiragana,
QChar::Script_Katakana,
QChar::Script_Yi
}

Definition at line 404 of file KoCssTextUtils.cpp.

404 {
405 QChar::Script_Bopomofo,
406 QChar::Script_Han,
407 QChar::Script_Hangul,
408 QChar::Script_Hiragana,
409 QChar::Script_Katakana,
410 QChar::Script_Yi
411};

◆ clusterScript

QVector<QChar::Script> clusterScript
static
Initial value:
{
QChar::Script_Khmer,
QChar::Script_Lao,
QChar::Script_Myanmar,
QChar::Script_NewTaiLue,
QChar::Script_TaiLe,
QChar::Script_TaiTham,
QChar::Script_TaiViet,
QChar::Script_Thai
}

Definition at line 413 of file KoCssTextUtils.cpp.

413 {
414 QChar::Script_Khmer,
415 QChar::Script_Lao,
416 QChar::Script_Myanmar,
417 QChar::Script_NewTaiLue,
418 QChar::Script_TaiLe,
419 QChar::Script_TaiTham,
420 QChar::Script_TaiViet,
421 QChar::Script_Thai
422};

◆ UNICODE_BIDI_ISOLATE_OVERRIDE_END

const QString UNICODE_BIDI_ISOLATE_OVERRIDE_END = "\u202c\u2069"

Definition at line 450 of file KoCssTextUtils.cpp.

◆ UNICODE_BIDI_ISOLATE_OVERRIDE_LR_START

const QString UNICODE_BIDI_ISOLATE_OVERRIDE_LR_START = "\u2068\u202d"

Definition at line 448 of file KoCssTextUtils.cpp.

◆ UNICODE_BIDI_ISOLATE_OVERRIDE_RL_START

const QString UNICODE_BIDI_ISOLATE_OVERRIDE_RL_START = "\u2068\u202e"

Definition at line 449 of file KoCssTextUtils.cpp.

◆ ZERO_WIDTH_JOINER

const QChar ZERO_WIDTH_JOINER = QChar{0x200d}

Definition at line 451 of file KoCssTextUtils.cpp.

451{0x200d};