26#include <unordered_map>
48 std::vector<BidiRegion>* results)
override {
49 return fBidiFact->
ExtractBidi(utf8, utf8Units, dir, results);
55 std::vector<SkUnicode::Position>* results)
override {
56 SkDEBUGF(
"Method 'getSentences' is not implemented\n");
69 while (lineBreak < utf8Units) {
70 lineBreak += grapheme_next_line_break_utf8(utf8 + lineBreak, utf8Units - lineBreak);
72 auto codePoint = utf8[lineBreak - 1];
73 (*results)[lineBreak] |= this->
isHardBreak(codePoint)
79 size_t graphemeBreak = 0;
81 while (graphemeBreak < utf8Units) {
82 graphemeBreak += grapheme_next_character_break_utf8(utf8 + graphemeBreak, utf8Units - graphemeBreak);
86 const char* current = utf8;
87 const char*
end = utf8 + utf8Units;
88 while (current <
end) {
89 auto before = current - utf8;
91 if (unichar < 0) unichar = 0xFFFD;
92 auto after = current - utf8;
100 for (
auto i = before; i < after; ++i) {
121 bool getUtf8To16Mapping(
const char utf8[],
int utf8Units, std::unordered_map<Position, Position>* results) {
123 const char* ptr8 = utf8;
124 const char* end8 = utf8 + utf8Units;
125 while (ptr8 < end8) {
126 results->emplace(ptr8 - utf8, utf16Units);
139 results->emplace(utf8Units, utf16Units);
143 bool getWords(
const char utf8[],
int utf8Units,
const char* locale, std::vector<Position>* results)
override {
144 std::unordered_map<Position, Position> mapping;
148 size_t wordBreak = 0;
149 while (wordBreak < utf8Units) {
150 wordBreak += grapheme_next_word_break_utf8(utf8 + wordBreak, utf8Units - wordBreak);
151 if (mapping.find(wordBreak) == mapping.end()) {
154 results->emplace_back(mapping[wordBreak]);
162 std::vector<Position>* results)
override {
166 size_t lineBreak = 0;
168 while (lineBreak < utf8Units) {
169 lineBreak += grapheme_next_line_break_utf8(utf8 + lineBreak, utf8Units - lineBreak);
174 const char* current = utf8;
175 const char*
end = utf8 + utf8Units;
176 while (current <
end) {
177 auto index = current - utf8;
186 bool whitespaces =
false;
187 for (
size_t i = 0; i < breaks.size(); ++i) {
190 results->emplace_back(i);
193 results->emplace_back(i);
197 results->emplace_back(i);
218 return this->
toUpper(str,
nullptr);
229 int32_t logicalFromVisual[])
override {
240 std::vector<SkUnicode::LineBreakBefore> fLineBreaks;
242 static constexpr const int kDone = -1;
246 {
return fLineBreaks[(fLineBreakIndex = 0)].
pos; }
248 {
return fLineBreaks[fLineBreakIndex].pos; }
250 {
return fLineBreaks[++fLineBreakIndex].pos; }
252 return fLineBreaks[fLineBreakIndex].breakType ==
257 bool isDone()
override {
return fLineBreaks[fLineBreakIndex].pos == kDone; }
258 bool setText(
const char utftext8[],
int utf8Units)
override {
260 size_t lineBreak = 0;
263 for (
size_t pos = 0;
pos < utf8Units;) {
264 pos += grapheme_next_line_break_utf8(utftext8 +
pos, utf8Units -
pos);
265 auto codePoint = utftext8[
pos];
266 fLineBreaks.emplace_back(
pos,
276 bool setText(
const char16_t utftext16[],
int utf16Units)
override {
293 return std::make_unique<SkBreakIterator_libgrapheme>(
this);
296 return std::make_unique<SkBreakIterator_libgrapheme>(
this);
301 return sk_make_sp<SkUnicode_libgrapheme>();
bool ExtractBidi(const char utf8[], int utf8Units, SkUnicode::TextDirection dir, std::vector< SkUnicode::BidiRegion > *bidiRegions) const
virtual void bidi_reorderVisual(const SkUnicode::BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) const =0
std::unique_ptr< SkBidiIterator > MakeIterator(const uint16_t utf16[], int utf16Units, SkBidiIterator::Direction dir) const
Position current() override
Position first() override
bool setText(const char16_t utftext16[], int utf16Units) override
SkBreakIterator_libgrapheme(SkUnicode_libgrapheme *unicode)
bool setText(const char utftext8[], int utf8Units) override
const char * data() const
bool isTabulation(SkUnichar utf8) override
bool isIdeographic(SkUnichar utf8) override
bool isSpace(SkUnichar utf8) override
bool isHardBreak(SkUnichar utf8) override
bool isControl(SkUnichar utf8) override
bool isWhitespace(SkUnichar utf8) override
bool getUtf8Words(const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results) override
bool computeCodeUnitFlags(char utf8[], int utf8Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results) override
bool getUtf8To16Mapping(const char utf8[], int utf8Units, std::unordered_map< Position, Position > *results)
SkString toUpper(const SkString &str) override
SkString toUpper(const SkString &str, const char *locale) override
void reorderVisual(const BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) override
bool computeCodeUnitFlags(char16_t utf16[], int utf16Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results) override
~SkUnicode_libgrapheme() override=default
std::unique_ptr< SkBidiIterator > makeBidiIterator(const uint16_t text[], int count, SkBidiIterator::Direction dir) override
bool getWords(const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results) override
bool getSentences(const char utf8[], int utf8Units, const char *locale, std::vector< SkUnicode::Position > *results) override
bool getBidiRegions(const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *results) override
std::unique_ptr< SkBreakIterator > makeBreakIterator(const char locale[], BreakType breakType) override
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
SK_SPI size_t ToUTF16(SkUnichar uni, uint16_t utf16[2]=nullptr)
SKUNICODE_API sk_sp< SkUnicode > Make()