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

Public Member Functions

 ~SkUnicode_icu () 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 type) override
 
std::unique_ptr< SkBreakIteratormakeBreakIterator (BreakType type) override
 
SkString toUpper (const SkString &str) override
 
SkString toUpper (const SkString &str, const char *locale) override
 
bool getBidiRegions (const char utf8[], int utf8Units, TextDirection dir, std::vector< BidiRegion > *results) override
 
bool getWords (const char utf8[], int utf8Units, const char *locale, std::vector< Position > *results) override
 
bool getUtf8Words (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 computeCodeUnitFlags (char utf8[], int utf8Units, bool replaceTabs, TArray< SkUnicode::CodeUnitFlags, true > *results) override
 
bool computeCodeUnitFlags (char16_t utf16[], int utf16Units, bool replaceTabs, TArray< SkUnicode::CodeUnitFlags, true > *results) 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
 

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 336 of file SkUnicode_icu.cpp.

Constructor & Destructor Documentation

◆ ~SkUnicode_icu()

SkUnicode_icu::~SkUnicode_icu ( )
inlineoverride

Definition at line 473 of file SkUnicode_icu.cpp.

473{ }

Member Function Documentation

◆ computeCodeUnitFlags() [1/2]

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

Implements SkUnicode.

Definition at line 571 of file SkUnicode_icu.cpp.

572 {
573 results->clear();
574 results->push_back_n(utf8Units + 1, CodeUnitFlags::kNoCodeUnitFlag);
575
576 SkUnicode_icu::extractPositions(utf8, utf8Units, BreakType::kLines, nullptr, // TODO: locale
577 [&](int pos, int status) {
578 (*results)[pos] |= status == UBRK_LINE_HARD
579 ? CodeUnitFlags::kHardLineBreakBefore
580 : CodeUnitFlags::kSoftLineBreakBefore;
581 });
582
583 SkUnicode_icu::extractPositions(utf8, utf8Units, BreakType::kGraphemes, nullptr, //TODO
584 [&](int pos, int status) {
585 (*results)[pos] |= CodeUnitFlags::kGraphemeStart;
586 });
587
588 const char* current = utf8;
589 const char* end = utf8 + utf8Units;
590 while (current < end) {
591 auto before = current - utf8;
592 SkUnichar unichar = SkUTF::NextUTF8(&current, end);
593 if (unichar < 0) unichar = 0xFFFD;
594 auto after = current - utf8;
595 if (replaceTabs && this->isTabulation(unichar)) {
596 results->at(before) |= SkUnicode::kTabulation;
597 if (replaceTabs) {
598 unichar = ' ';
599 utf8[before] = ' ';
600 }
601 }
602 for (auto i = before; i < after; ++i) {
603 if (this->isSpace(unichar)) {
605 }
606 if (this->isWhitespace(unichar)) {
608 }
609 if (this->isControl(unichar)) {
610 results->at(i) |= SkUnicode::kControl;
611 }
612 if (this->isIdeographic(unichar)) {
613 results->at(i) |= SkUnicode::kIdeographic;
614 }
615 }
616 }
617
618 return true;
619 }
SkPoint pos
int32_t SkUnichar
Definition: SkTypes.h:175
@ kPartOfWhiteSpaceBreak
Definition: SkUnicode.h:81
@ kTabulation
Definition: SkUnicode.h:87
@ kControl
Definition: SkUnicode.h:86
@ kIdeographic
Definition: SkUnicode.h:89
@ kPartOfIntraWordBreak
Definition: SkUnicode.h:85
T * push_back_n(int n)
Definition: SkTArray.h:267
glong glong end
SK_SPI SkUnichar NextUTF8(const char **ptr, const char *end)
Definition: SkUTF.cpp:118

◆ computeCodeUnitFlags() [2/2]

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

Implements SkUnicode.

Definition at line 621 of file SkUnicode_icu.cpp.

622 {
623 results->clear();
624 results->push_back_n(utf16Units + 1, CodeUnitFlags::kNoCodeUnitFlag);
625
626 // Get white spaces
627 this->forEachCodepoint((char16_t*)&utf16[0], utf16Units,
628 [this, results, replaceTabs, &utf16](SkUnichar unichar, int32_t start, int32_t end) {
629 for (auto i = start; i < end; ++i) {
630 if (replaceTabs && this->isTabulation(unichar)) {
631 results->at(i) |= SkUnicode::kTabulation;
632 if (replaceTabs) {
633 unichar = ' ';
634 utf16[start] = ' ';
635 }
636 }
637 if (this->isSpace(unichar)) {
639 }
640 if (this->isWhitespace(unichar)) {
642 }
643 if (this->isControl(unichar)) {
644 results->at(i) |= SkUnicode::kControl;
645 }
646 }
647 });
648 // Get graphemes
649 this->forEachBreak((char16_t*)&utf16[0],
650 utf16Units,
653 (*results)[pos] |= CodeUnitFlags::kGraphemeStart;
654 });
655 // Get line breaks
656 this->forEachBreak(
657 (char16_t*)&utf16[0],
658 utf16Units,
661 if (status ==
663 // Hard line breaks clears off all the other flags
664 // TODO: Treat \n as a formatting mark and do not pass it to SkShaper
665 (*results)[pos-1] = CodeUnitFlags::kHardLineBreakBefore;
666 } else {
667 (*results)[pos] |= CodeUnitFlags::kSoftLineBreakBefore;
668 }
669 });
670
671 return true;
672 }
int32_t Position
Definition: SkUnicode.h:65
int32_t Status
Definition: SkUnicode.h:66
void forEachCodepoint(const char *utf8, int32_t utf8Units, Callback &&callback)
Definition: SkUnicode.h:239
void forEachBreak(const char16_t utf16[], int utf16Units, SkUnicode::BreakType type, Callback &&callback)
Definition: SkUnicode.h:290

◆ getBidiRegions()

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

Implements SkUnicode.

Definition at line 521 of file SkUnicode_icu.cpp.

524 {
525 return fBidiFact->ExtractBidi(utf8, utf8Units, dir, results);
526 }
bool ExtractBidi(const char utf8[], int utf8Units, SkUnicode::TextDirection dir, std::vector< SkUnicode::BidiRegion > *bidiRegions) const
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

◆ getSentences()

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

Implements SkUnicode.

Definition at line 559 of file SkUnicode_icu.cpp.

562 {
563 SkUnicode_icu::extractPositions(
564 utf8, utf8Units, BreakType::kSentences, nullptr,
565 [&](int pos, int status) {
566 results->emplace_back(pos);
567 });
568 return true;
569 }

◆ getUtf8Words()

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

Implements SkUnicode.

Definition at line 536 of file SkUnicode_icu.cpp.

539 {
540 // Convert to UTF16 since we want the results in utf16
541 auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
542 std::vector<Position> utf16Results;
543 if (!SkUnicode_icu::extractWords(
544 (uint16_t*)utf16.c_str(), utf16.size(), locale, &utf16Results)) {
545 return false;
546 }
547
548 std::vector<Position> mapping;
549 SkSpan<const char> text(utf8, utf8Units);
551 text, [&](size_t index) { mapping.emplace_back(index); }, [&](size_t index) {});
552
553 for (auto i16 : utf16Results) {
554 results->emplace_back(mapping[i16]);
555 }
556 return true;
557 }
static std::u16string convertUtf8ToUtf16(const char *utf8, int utf8Units)
Definition: SkUnicode.cpp:32
static bool extractUtfConversionMapping(SkSpan< const char > utf8, Appender8 &&appender8, Appender16 &&appender16)
Definition: SkUnicode.h:193
std::u16string text

◆ getWords()

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

Implements SkUnicode.

Definition at line 528 of file SkUnicode_icu.cpp.

529 {
530
531 // Convert to UTF16 since we want the results in utf16
532 auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
533 return SkUnicode_icu::extractWords((uint16_t*)utf16.c_str(), utf16.size(), locale, results);
534 }

◆ makeBidiIterator() [1/2]

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

Implements SkUnicode.

Definition at line 478 of file SkUnicode_icu.cpp.

480 {
481 return fBidiFact->MakeIterator(text, count, dir);
482 }
int count
Definition: FontMgrTest.cpp:50
std::unique_ptr< SkBidiIterator > MakeIterator(const uint16_t utf16[], int utf16Units, SkBidiIterator::Direction dir) const

◆ makeBidiIterator() [2/2]

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

Implements SkUnicode.

Definition at line 474 of file SkUnicode_icu.cpp.

475 {
476 return fBidiFact->MakeIterator(text, count, dir);
477 }

◆ makeBreakIterator() [1/2]

std::unique_ptr< SkBreakIterator > SkUnicode_icu::makeBreakIterator ( BreakType  type)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 491 of file SkUnicode_icu.cpp.

491 {
492 return makeBreakIterator(sk_uloc_getDefault(), type);
493 }
GLenum type
std::unique_ptr< SkBreakIterator > makeBreakIterator(const char locale[], BreakType type) override

◆ makeBreakIterator() [2/2]

std::unique_ptr< SkBreakIterator > SkUnicode_icu::makeBreakIterator ( const char  locale[],
BreakType  type 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 483 of file SkUnicode_icu.cpp.

484 {
486 if (!iterator) {
487 return nullptr;
488 }
489 return std::unique_ptr<SkBreakIterator>(new SkBreakIterator_icu(std::move(iterator)));
490 }
std::unique_ptr< UBreakIterator, SkFunctionObject< ubrk_close_wrapper > > ICUBreakIterator
static SkIcuBreakIteratorCache & get()
ICUBreakIterator makeBreakIterator(SkUnicode::BreakType type, const char *bcp47)

◆ reorderVisual()

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

Implements SkUnicode.

Definition at line 674 of file SkUnicode_icu.cpp.

676 {
677 fBidiFact->bidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
678 }
virtual void bidi_reorderVisual(const SkUnicode::BidiLevel runLevels[], int levelsCount, int32_t logicalFromVisual[]) const =0

◆ toUpper() [1/2]

SkString SkUnicode_icu::toUpper ( const SkString str)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 495 of file SkUnicode_icu.cpp.

495 {
496 return this->toUpper(str, nullptr);
497 }
SkString toUpper(const SkString &str) override

◆ toUpper() [2/2]

SkString SkUnicode_icu::toUpper ( const SkString str,
const char *  locale 
)
inlineoverridevirtual

Implements SkUnicode.

Definition at line 499 of file SkUnicode_icu.cpp.

499 {
500 // Convert to UTF16 since that's what ICU wants.
501 auto str16 = SkUnicode::convertUtf8ToUtf16(str.c_str(), str.size());
502
503 UErrorCode icu_err = U_ZERO_ERROR;
504 const auto upper16len = sk_u_strToUpper(nullptr, 0, (UChar*)(str16.c_str()), str16.size(),
505 locale, &icu_err);
506 if (icu_err != U_BUFFER_OVERFLOW_ERROR || upper16len <= 0) {
507 return SkString();
508 }
509
510 AutoSTArray<128, uint16_t> upper16(upper16len);
511 icu_err = U_ZERO_ERROR;
512 sk_u_strToUpper((UChar*)(upper16.get()), SkToS32(upper16.size()),
513 (UChar*)(str16.c_str()), str16.size(),
514 locale, &icu_err);
515 SkASSERT(!U_FAILURE(icu_err));
516
517 // ... and back to utf8 'cause that's what we want.
518 return convertUtf16ToUtf8((char16_t*)upper16.get(), upper16.size());
519 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133
static SkString convertUtf16ToUtf8(const char16_t *utf16, int utf16Units)
Definition: SkUnicode.cpp:14

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