Flutter Engine
The Flutter Engine
Functions
SkShapers::unicode Namespace Reference

Functions

SKSHAPER_API std::unique_ptr< SkShaper::BiDiRunIteratorBidiRunIterator (sk_sp< SkUnicode > unicode, const char *utf8, size_t utf8Bytes, uint8_t bidiLevel)
 

Function Documentation

◆ BidiRunIterator()

std::unique_ptr< SkShaper::BiDiRunIterator > SkShapers::unicode::BidiRunIterator ( sk_sp< SkUnicode unicode,
const char *  utf8,
size_t  utf8Bytes,
uint8_t  bidiLevel 
)

Definition at line 120 of file SkShaper_skunicode.cpp.

123 {
124 if (!unicode) {
125 return nullptr;
126 }
127 // ubidi only accepts utf16 (though internally it basically works on utf32 chars).
128 // We want an ubidi_setPara(UBiDi*, UText*, UBiDiLevel, UBiDiLevel*, UErrorCode*);
129 if (!SkTFitsIn<int32_t>(utf8Bytes)) {
130 SkDEBUGF("Bidi error: text too long");
131 return nullptr;
132 }
133
134 int32_t utf16Units = SkUTF::UTF8ToUTF16(nullptr, 0, utf8, utf8Bytes);
135 if (utf16Units < 0) {
136 SkDEBUGF("Invalid utf8 input\n");
137 return nullptr;
138 }
139
140 std::unique_ptr<uint16_t[]> utf16(new uint16_t[utf16Units]);
141 (void)SkUTF::UTF8ToUTF16(utf16.get(), utf16Units, utf8, utf8Bytes);
142
143 auto bidiDir = (bidiLevel % 2 == 0) ? SkBidiIterator::kLTR : SkBidiIterator::kRTL;
144 SkUnicodeBidi bidi = unicode->makeBidiIterator(utf16.get(), utf16Units, bidiDir);
145 if (!bidi) {
146 SkDEBUGF("Bidi error\n");
147 return nullptr;
148 }
149
150 return std::make_unique<SkUnicodeBidiRunIterator>(utf8, utf8 + utf8Bytes, std::move(bidi));
151}
#define SkDEBUGF(...)
Definition: SkDebug.h:24
std::unique_ptr< SkBidiIterator > SkUnicodeBidi
SK_SPI int UTF8ToUTF16(uint16_t dst[], int dstCapacity, const char src[], size_t srcByteLength)
Definition: SkUTF.cpp:259