Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
SkUnicode_icu4x Class Reference
Inheritance diagram for SkUnicode_icu4x:
SkUnicode SkRefCnt SkRefCntBase

Public Member Functions

 SkUnicode_icu4x ()
 
 ~SkUnicode_icu4x () override=default
 
void reset ()
 
bool isControl (SkUnichar utf8) override
 
bool isWhitespace (SkUnichar utf8) override
 
bool isSpace (SkUnichar utf8) override
 
bool isHardBreak (SkUnichar utf8) override
 
bool isEmoji (SkUnichar utf8) override
 
bool isEmojiComponent (SkUnichar utf8) override
 
bool isEmojiModifierBase (SkUnichar utf8) override
 
bool isEmojiModifier (SkUnichar utf8) override
 
bool isRegionalIndicator (SkUnichar utf8) override
 
bool isIdeographic (SkUnichar utf8) override
 
bool isTabulation (SkUnichar utf8) override
 
std::unique_ptr< SkBidiIteratormakeBidiIterator (const uint16_t text[], int count, SkBidiIterator::Direction dir) override
 
std::unique_ptr< SkBidiIteratormakeBidiIterator (const char text[], int count, SkBidiIterator::Direction dir) override
 
std::unique_ptr< SkBreakIteratormakeBreakIterator (const char locale[], BreakType breakType) override
 
std::unique_ptr< SkBreakIteratormakeBreakIterator (BreakType breakType) override
 
bool getBidiRegions (const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *results) override
 
bool getBidiRegions (const uint16_t utf16[], int utf16Units, TextDirection dir, std::vector< BidiRegion > *results)
 
bool computeCodeUnitFlags (char utf8[], int utf8Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results) override
 
bool computeCodeUnitFlags (char16_t utf16[], int utf16Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results) override
 
bool getWords (const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results) override
 
SkString toUpper (const SkString &str) override
 
SkString toUpper (const SkString &str, const char *localeStr) override
 
void reorderVisual (const BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) override
 
- Public Member Functions inherited from SkUnicode
 ~SkUnicode () override=default
 
virtual SkString toUpper (const SkString &)=0
 
virtual SkString toUpper (const SkString &, const char *locale)=0
 
virtual bool isControl (SkUnichar utf8)=0
 
virtual bool isWhitespace (SkUnichar utf8)=0
 
virtual bool isSpace (SkUnichar utf8)=0
 
virtual bool isTabulation (SkUnichar utf8)=0
 
virtual bool isHardBreak (SkUnichar utf8)=0
 
virtual bool isEmoji (SkUnichar utf8)=0
 
virtual bool isEmojiComponent (SkUnichar utf8)=0
 
virtual bool isEmojiModifierBase (SkUnichar utf8)=0
 
virtual bool isEmojiModifier (SkUnichar utf8)=0
 
virtual bool isRegionalIndicator (SkUnichar utf8)=0
 
virtual bool isIdeographic (SkUnichar utf8)=0
 
virtual std::unique_ptr< SkBidiIteratormakeBidiIterator (const uint16_t text[], int count, SkBidiIterator::Direction)=0
 
virtual std::unique_ptr< SkBidiIteratormakeBidiIterator (const char text[], int count, SkBidiIterator::Direction)=0
 
virtual std::unique_ptr< SkBreakIteratormakeBreakIterator (const char locale[], BreakType breakType)=0
 
virtual std::unique_ptr< SkBreakIteratormakeBreakIterator (BreakType type)=0
 
virtual bool getBidiRegions (const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *results)=0
 
virtual bool getWords (const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results)=0
 
virtual bool getUtf8Words (const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results)=0
 
virtual bool getSentences (const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results)=0
 
virtual bool computeCodeUnitFlags (char utf8[], int utf8Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results)=0
 
virtual bool computeCodeUnitFlags (char16_t utf16[], int utf16Units, bool replaceTabs, skia_private::TArray< SkUnicode::CodeUnitFlags, true > *results)=0
 
template<typename Callback >
void forEachCodepoint (const char *utf8, int32_t utf8Units, Callback &&callback)
 
template<typename Callback >
void forEachCodepoint (const char16_t *utf16, int32_t utf16Units, Callback &&callback)
 
template<typename Callback >
void forEachBidiRegion (const uint16_t utf16[], int utf16Units, SkBidiIterator::Direction dir, Callback &&callback)
 
template<typename Callback >
void forEachBreak (const char16_t utf16[], int utf16Units, SkUnicode::BreakType type, Callback &&callback)
 
virtual void reorderVisual (const BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[])=0
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Friends

class SkBreakIterator_icu4x
 
class SkBidiIterator_icu4x
 

Additional Inherited Members

- Public Types inherited from SkUnicode
enum  CodeUnitFlags {
  kNoCodeUnitFlag = 0x00 , kPartOfWhiteSpaceBreak = 0x01 , kGraphemeStart = 0x02 , kSoftLineBreakBefore = 0x04 ,
  kHardLineBreakBefore = 0x08 , kPartOfIntraWordBreak = 0x10 , kControl = 0x20 , kTabulation = 0x40 ,
  kGlyphClusterStart = 0x80 , kIdeographic = 0x100 , kEmoji = 0x200 , kWordBreak = 0x400 ,
  kSentenceBreak = 0x800
}
 
enum class  TextDirection { kLTR , kRTL }
 
enum class  LineBreakType { kSoftLineBreak = 0 , kHardLineBreak = 100 }
 
enum class  BreakType { kWords , kGraphemes , kLines , kSentences }
 
typedef size_t Position
 
typedef uint8_t BidiLevel
 
- Static Public Member Functions inherited from SkUnicode
static bool hasTabulationFlag (SkUnicode::CodeUnitFlags flags)
 
static bool hasHardLineBreakFlag (SkUnicode::CodeUnitFlags flags)
 
static bool hasSoftLineBreakFlag (SkUnicode::CodeUnitFlags flags)
 
static bool hasGraphemeStartFlag (SkUnicode::CodeUnitFlags flags)
 
static bool hasControlFlag (SkUnicode::CodeUnitFlags flags)
 
static bool hasPartOfWhiteSpaceBreakFlag (SkUnicode::CodeUnitFlags flags)
 
static bool extractBidi (const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *bidiRegions)
 
static SkString convertUtf16ToUtf8 (const char16_t *utf16, int utf16Units)
 
static SkString convertUtf16ToUtf8 (const std::u16string &utf16)
 
static std::u16string convertUtf8ToUtf16 (const char *utf8, int utf8Units)
 
static std::u16string convertUtf8ToUtf16 (const SkString &utf8)
 
template<typename Appender8 , typename Appender16 >
static bool extractUtfConversionMapping (SkSpan< const char > utf8, Appender8 &&appender8, Appender16 &&appender16)
 

Detailed Description

Definition at line 35 of file SkUnicode_icu4x.cpp.

Constructor & Destructor Documentation

◆ SkUnicode_icu4x()

SkUnicode_icu4x::SkUnicode_icu4x ( )
inline

Definition at line 37 of file SkUnicode_icu4x.cpp.

37 {
38 fLocale = ICU4XLocale::create_from_string("tr").ok().value();
39 fDataProvider = ICU4XDataProvider::create_compiled();
40 fCaseMapper = ICU4XCaseMapper::create(fDataProvider).ok().value();
41 const auto general = ICU4XCodePointMapData8::load_general_category(fDataProvider).ok().value();
42 fControls = general.get_set_for_value(/*Control*/15);
43 fWhitespaces = general.get_set_for_value(/*SpaceSeparator*/12);
44 fSpaces = general.get_set_for_value(/*SpaceSeparator*/12);
45 // TODO: u_isSpace
46 fBlanks = ICU4XCodePointSetData::load_blank(fDataProvider).ok().value();
47 fEmoji = ICU4XCodePointSetData::load_emoji(fDataProvider).ok().value();
48 fEmojiComponent = ICU4XCodePointSetData::load_emoji_component(fDataProvider).ok().value();
49 fEmojiModifier = ICU4XCodePointSetData::load_emoji_modifier(fDataProvider).ok().value();
50 fEmojiModifierBase = ICU4XCodePointSetData::load_emoji_modifier_base(fDataProvider).ok().value();
51 fEmoji = ICU4XCodePointSetData::load_emoji(fDataProvider).ok().value();
52 fRegionalIndicator = ICU4XCodePointSetData::load_regional_indicator(fDataProvider).ok().value();
53 fIdeographic = ICU4XCodePointSetData::load_ideographic(fDataProvider).ok().value();
54 fLineBreaks = ICU4XCodePointMapData8::load_line_break(fDataProvider).ok().value();
55 }
int_closure create

◆ ~SkUnicode_icu4x()

SkUnicode_icu4x::~SkUnicode_icu4x ( )
overridedefault

Member Function Documentation

◆ computeCodeUnitFlags() [1/2]

bool SkUnicode_icu4x::computeCodeUnitFlags ( char  utf8[],
int  utf8Units,
bool  replaceTabs,
skia_private::TArray< SkUnicode::CodeUnitFlags, true > *  results 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 125 of file SkUnicode_icu4x.cpp.

128 {
129 results->clear();
130 results->push_back_n(utf8Units + 1, CodeUnitFlags::kNoCodeUnitFlag);
131 this->markLineBreaks(utf8, utf8Units, /*hardLineBreaks=*/false, results);
132 this->markHardLineBreaksHack(utf8, utf8Units, results);
133 this->markGraphemes(utf8, utf8Units, results);
134 this->markCharacters(utf8, utf8Units, replaceTabs, results);
135 return true;
136 }
T * push_back_n(int n)
Definition: SkTArray.h:267

◆ computeCodeUnitFlags() [2/2]

bool SkUnicode_icu4x::computeCodeUnitFlags ( char16_t  utf16[],
int  utf16Units,
bool  replaceTabs,
skia_private::TArray< SkUnicode::CodeUnitFlags, true > *  results 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 138 of file SkUnicode_icu4x.cpp.

139 {
140 SkASSERT(false);
141 return true;
142 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ getBidiRegions() [1/2]

bool SkUnicode_icu4x::getBidiRegions ( const char  utf8[],
int  utf8Units,
TextDirection  dir,
std::vector< BidiRegion > *  results 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 94 of file SkUnicode_icu4x.cpp.

97 {
98
99 const auto bidi = ICU4XBidi::create(fDataProvider).ok().value();
100 std::string_view string_view(utf8, utf8Units);
101 auto info = bidi.for_text(string_view, dir == TextDirection::kLTR ? 0 : 1);
102 auto currentLevel = info.level_at(0);
103 size_t start = 0;
104
105 for (size_t i = 1; i < info.size(); i++) {
106 const auto level = info.level_at(i);
107 if (level != currentLevel) {
108 (*results).emplace_back(start, i, currentLevel);
109 currentLevel = level;
110 start = i;
111 }
112 }
113 (*results).emplace_back(start, info.size(), currentLevel);
114 return true;
115 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145

◆ getBidiRegions() [2/2]

bool SkUnicode_icu4x::getBidiRegions ( const uint16_t  utf16[],
int  utf16Units,
TextDirection  dir,
std::vector< BidiRegion > *  results 
)
inline

Definition at line 117 of file SkUnicode_icu4x.cpp.

120 {
121 auto utf8 = SkUnicode::convertUtf16ToUtf8((char16_t*)utf16, utf16Units);
122 return this->getBidiRegions(utf8.data(), utf8.size(), dir, results);
123 }
bool getBidiRegions(const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *results) override
static SkString convertUtf16ToUtf8(const char16_t *utf16, int utf16Units)
Definition: SkUnicode.cpp:14

◆ getWords()

bool SkUnicode_icu4x::getWords ( const char  utf8[],
int  utf8Units,
const char *  locale,
std::vector< Position > *  results 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 144 of file SkUnicode_icu4x.cpp.

147 {
148 auto utf16 = SkUnicode::convertUtf8ToUtf16(utf8, utf8Units);
149 const diplomat::span<const uint16_t> span((uint16_t*)utf16.data(), utf16.size());
150 const auto segmenter = ICU4XWordSegmenter::create_dictionary(fDataProvider).ok().value();
151 auto iterator = segmenter.segment_utf16(span);
152 while (true) {
153 int32_t breakpoint = iterator.next();
154 if (breakpoint == -1) {
155 break;
156 }
157 results->emplace_back(breakpoint);
158 }
159 return true;
160 }
static std::u16string convertUtf8ToUtf16(const char *utf8, int utf8Units)
Definition: SkUnicode.cpp:32

◆ isControl()

bool SkUnicode_icu4x::isControl ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 62 of file SkUnicode_icu4x.cpp.

62{ return fControls.contains(utf8); }

◆ isEmoji()

bool SkUnicode_icu4x::isEmoji ( SkUnichar  utf8)
inlineoverridevirtual

Returns if a code point may start an emoji sequence. Returns true for '#', '*', and '0'-'9' since they may start an emoji sequence. To determine if a list of code points begins with an emoji sequence, use getEmojiSequence.

Implements SkUnicode.

Definition at line 72 of file SkUnicode_icu4x.cpp.

72{ return fEmoji.contains(utf8); }

◆ isEmojiComponent()

bool SkUnicode_icu4x::isEmojiComponent ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 73 of file SkUnicode_icu4x.cpp.

73{ return fEmojiComponent.contains(utf8); }

◆ isEmojiModifier()

bool SkUnicode_icu4x::isEmojiModifier ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 75 of file SkUnicode_icu4x.cpp.

75{ return fEmojiModifier.contains(utf8); }

◆ isEmojiModifierBase()

bool SkUnicode_icu4x::isEmojiModifierBase ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 74 of file SkUnicode_icu4x.cpp.

74{ return fEmojiModifierBase.contains(utf8); }

◆ isHardBreak()

bool SkUnicode_icu4x::isHardBreak ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 65 of file SkUnicode_icu4x.cpp.

65 {
66 auto value = fLineBreaks.get(utf8);
67 return (value == /*MandatoryBreak*/6) ||
68 (value == /*CarriageReturn*/10) ||
69 (value == /*LineFeed*/17) ||
70 (value == /*NextLine*/29);
71 }
uint8_t value

◆ isIdeographic()

bool SkUnicode_icu4x::isIdeographic ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 77 of file SkUnicode_icu4x.cpp.

77{ return fIdeographic.contains(utf8); }

◆ isRegionalIndicator()

bool SkUnicode_icu4x::isRegionalIndicator ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 76 of file SkUnicode_icu4x.cpp.

76{ return fRegionalIndicator.contains(utf8); }

◆ isSpace()

bool SkUnicode_icu4x::isSpace ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 64 of file SkUnicode_icu4x.cpp.

64{ return fBlanks.contains(utf8); }

◆ isTabulation()

bool SkUnicode_icu4x::isTabulation ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 80 of file SkUnicode_icu4x.cpp.

80 {
81 return utf8 == '\t';
82 }

◆ isWhitespace()

bool SkUnicode_icu4x::isWhitespace ( SkUnichar  utf8)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 63 of file SkUnicode_icu4x.cpp.

63{ return fWhitespaces.contains(utf8); }

◆ makeBidiIterator() [1/2]

std::unique_ptr< SkBidiIterator > SkUnicode_icu4x::makeBidiIterator ( const char  text[],
int  count,
SkBidiIterator::Direction  dir 
)
overridevirtual

Implements SkUnicode.

Definition at line 381 of file SkUnicode_icu4x.cpp.

383 {
384 if (fRegions) {
385 fRegions->clear();
386 } else {
387 fRegions = std::make_shared<std::vector<SkUnicode::BidiRegion>>();
388 }
389 if (this->getBidiRegions(text, count, dir == SkBidiIterator::Direction::kLTR ? TextDirection::kLTR : TextDirection::kRTL, fRegions.get())) {
390 return std::make_unique<SkBidiIterator_icu4x>(fRegions);
391 } else {
392 return nullptr;
393 }
394}
int count
Definition: FontMgrTest.cpp:50
std::u16string text

◆ makeBidiIterator() [2/2]

std::unique_ptr< SkBidiIterator > SkUnicode_icu4x::makeBidiIterator ( const uint16_t  text[],
int  count,
SkBidiIterator::Direction  dir 
)
overridevirtual

Implements SkUnicode.

Definition at line 366 of file SkUnicode_icu4x.cpp.

367 {
368 if (fRegions) {
369 fRegions->clear();
370 } else {
371 fRegions = std::make_shared<std::vector<SkUnicode::BidiRegion>>();
372 }
373
374 if (this->getBidiRegions(text, count, dir == SkBidiIterator::Direction::kLTR ? TextDirection::kLTR : TextDirection::kRTL, fRegions.get())) {
375 return std::make_unique<SkBidiIterator_icu4x>(fRegions);
376 } else {
377 return nullptr;
378 }
379}

◆ makeBreakIterator() [1/2]

std::unique_ptr< SkBreakIterator > SkUnicode_icu4x::makeBreakIterator ( BreakType  breakType)
overridevirtual

Implements SkUnicode.

Definition at line 401 of file SkUnicode_icu4x.cpp.

401 {
402 SkASSERT(false); return nullptr;
403}

◆ makeBreakIterator() [2/2]

std::unique_ptr< SkBreakIterator > SkUnicode_icu4x::makeBreakIterator ( const char  locale[],
BreakType  breakType 
)
overridevirtual

Implements SkUnicode.

Definition at line 396 of file SkUnicode_icu4x.cpp.

397 {
398 SkASSERT(false); return nullptr;
399}

◆ reorderVisual()

void SkUnicode_icu4x::reorderVisual ( const BidiLevel  runLevels[],
int  levelsCount,
int32_t  logicalFromVisual[] 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 174 of file SkUnicode_icu4x.cpp.

176 {
177
178 const auto bidi = ICU4XBidi::create(fDataProvider).ok().value();
179 const diplomat::span<const uint8_t> levels(&runLevels[0], levelsCount);
180 auto map = bidi.reorder_visual(levels);
181 SkASSERT(levelsCount == map.len());
182 std::vector<int32_t> results;
183 for (size_t i = 0; i < map.len(); i++) {
184 auto level = map.get(i);
185 logicalFromVisual[i] = SkToS32(level);
186 }
187 }
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680

◆ reset()

void SkUnicode_icu4x::reset ( )

◆ toUpper() [1/2]

SkString SkUnicode_icu4x::toUpper ( const SkString str)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 162 of file SkUnicode_icu4x.cpp.

162 {
163 return toUpper(str, "und");
164 }
SkString toUpper(const SkString &str) override

◆ toUpper() [2/2]

SkString SkUnicode_icu4x::toUpper ( const SkString str,
const char *  localeStr 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 166 of file SkUnicode_icu4x.cpp.

166 {
167 auto locale = ICU4XLocale::create_from_string(localeStr).ok().value();
168 std::string std_string(str.data(), str.size());
169 // TODO: upper case
170 auto result = fCaseMapper.uppercase(std_string, locale).ok().value();
171 return SkString(result.data(), result.size());
172 }
size_t size() const
Definition: SkString.h:131
const char * data() const
Definition: SkString.h:132
GAsyncResult * result

Friends And Related Function Documentation

◆ SkBidiIterator_icu4x

friend class SkBidiIterator_icu4x
friend

Definition at line 191 of file SkUnicode_icu4x.cpp.

◆ SkBreakIterator_icu4x

friend class SkBreakIterator_icu4x
friend

Definition at line 190 of file SkUnicode_icu4x.cpp.


The documentation for this class was generated from the following file: