• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "include/core/SkString.h"
8 #include "include/private/SkMutex.h"
9 #include "include/private/SkOnce.h"
10 #include "include/private/SkTFitsIn.h"
11 #include "include/private/SkTHash.h"
12 #include "include/private/SkTemplates.h"
13 #include "modules/skunicode/include/SkUnicode.h"
14 #include "modules/skunicode/src/SkUnicode_icu.h"
15 #include "src/utils/SkUTF.h"
16 #include <vector>
17 #include <functional>
18 
19 #if defined(SK_USING_THIRD_PARTY_ICU)
20 #include "SkLoadICU.h"
21 #endif
22 
ICULib()23 static const SkICULib* ICULib() {
24     static const auto gICU = SkLoadICULib();
25 
26     return gICU.get();
27 }
28 
29 // sk_* wrappers for ICU funcs
30 #define SKICU_FUNC(funcname)                                                                \
31     template <typename... Args>                                                             \
32     auto sk_##funcname(Args&&... args) -> decltype(funcname(std::forward<Args>(args)...)) { \
33         return ICULib()->f_##funcname(std::forward<Args>(args)...);                         \
34     }                                                                                       \
35 
36 SKICU_EMIT_FUNCS
37 #undef SKICU_FUNC
38 
sk_ubrk_clone(const UBreakIterator * bi,UErrorCode * status)39 static inline UBreakIterator* sk_ubrk_clone(const UBreakIterator* bi, UErrorCode* status) {
40     const auto* icu = ICULib();
41     SkASSERT(icu->f_ubrk_clone_ || icu->f_ubrk_safeClone_);
42     return icu->f_ubrk_clone_
43         ? icu->f_ubrk_clone_(bi, status)
44         : icu->f_ubrk_safeClone_(bi, nullptr, nullptr, status);
45 }
46 
ubidi_close_wrapper(UBiDi * bidi)47 static void ubidi_close_wrapper(UBiDi* bidi) {
48     sk_ubidi_close(bidi);
49 }
utext_close_wrapper(UText * ut)50 static UText* utext_close_wrapper(UText* ut) {
51     return sk_utext_close(ut);
52 }
ubrk_close_wrapper(UBreakIterator * bi)53 static void ubrk_close_wrapper(UBreakIterator* bi) {
54     sk_ubrk_close(bi);
55 }
56 
57 using SkUnicodeBidi = std::unique_ptr<UBiDi, SkFunctionWrapper<decltype(ubidi_close),
58                                                                ubidi_close_wrapper>>;
59 using ICUUText = std::unique_ptr<UText, SkFunctionWrapper<decltype(utext_close),
60                                                          utext_close_wrapper>>;
61 using ICUBreakIterator = std::unique_ptr<UBreakIterator, SkFunctionWrapper<decltype(ubrk_close),
62                                                                            ubrk_close_wrapper>>;
63 /** Replaces invalid utf-8 sequences with REPLACEMENT CHARACTER U+FFFD. */
utf8_next(const char ** ptr,const char * end)64 static inline SkUnichar utf8_next(const char** ptr, const char* end) {
65     SkUnichar val = SkUTF::NextUTF8(ptr, end);
66     return val < 0 ? 0xFFFD : val;
67 }
68 
convertType(SkUnicode::BreakType type)69 static UBreakIteratorType convertType(SkUnicode::BreakType type) {
70     switch (type) {
71         case SkUnicode::BreakType::kLines: return UBRK_LINE;
72         case SkUnicode::BreakType::kGraphemes: return UBRK_CHARACTER;
73         case SkUnicode::BreakType::kWords: return UBRK_WORD;
74         default:
75             return UBRK_CHARACTER;
76     }
77 }
78 
79 class SkBidiIterator_icu : public SkBidiIterator {
80     SkUnicodeBidi fBidi;
81 public:
SkBidiIterator_icu(SkUnicodeBidi bidi)82     explicit SkBidiIterator_icu(SkUnicodeBidi bidi) : fBidi(std::move(bidi)) {}
getLength()83     Position getLength() override { return sk_ubidi_getLength(fBidi.get()); }
getLevelAt(Position pos)84     Level getLevelAt(Position pos) override { return sk_ubidi_getLevelAt(fBidi.get(), pos); }
85 
makeBidiIterator(const uint16_t utf16[],int utf16Units,Direction dir)86     static std::unique_ptr<SkBidiIterator> makeBidiIterator(const uint16_t utf16[], int utf16Units, Direction dir) {
87         UErrorCode status = U_ZERO_ERROR;
88         SkUnicodeBidi bidi(sk_ubidi_openSized(utf16Units, 0, &status));
89         if (U_FAILURE(status)) {
90             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
91             return nullptr;
92         }
93         SkASSERT(bidi);
94         uint8_t bidiLevel = (dir == SkBidiIterator::kLTR) ? UBIDI_LTR : UBIDI_RTL;
95         // The required lifetime of utf16 isn't well documented.
96         // It appears it isn't used after ubidi_setPara except through ubidi_getText.
97         sk_ubidi_setPara(bidi.get(), (const UChar*)utf16, utf16Units, bidiLevel, nullptr, &status);
98         if (U_FAILURE(status)) {
99             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
100             return nullptr;
101         }
102         return std::unique_ptr<SkBidiIterator>(new SkBidiIterator_icu(std::move(bidi)));
103     }
104 
105     // ICU bidi iterator works with utf16 but clients (Flutter for instance) may work with utf8
106     // This method allows the clients not to think about all these details
makeBidiIterator(const char utf8[],int utf8Units,Direction dir)107     static std::unique_ptr<SkBidiIterator> makeBidiIterator(const char utf8[], int utf8Units, Direction dir) {
108         // Convert utf8 into utf16 since ubidi only accepts utf16
109         if (!SkTFitsIn<int32_t>(utf8Units)) {
110             SkDEBUGF("Bidi error: text too long");
111             return nullptr;
112         }
113 
114         // Getting the length like this seems to always set U_BUFFER_OVERFLOW_ERROR
115         int utf16Units = SkUTF::UTF8ToUTF16(nullptr, 0, utf8, utf8Units);
116         if (utf16Units < 0) {
117             SkDEBUGF("Bidi error: Invalid utf8 input");
118             return nullptr;
119         }
120         std::unique_ptr<uint16_t[]> utf16(new uint16_t[utf16Units]);
121         SkDEBUGCODE(int dstLen =) SkUTF::UTF8ToUTF16(utf16.get(), utf16Units, utf8, utf8Units);
122         SkASSERT(dstLen == utf16Units);
123 
124         return makeBidiIterator(utf16.get(), utf16Units, dir);
125     }
126 
127     // This method returns the final results only: a list of bidi regions
128     // (this is all SkParagraph really needs; SkShaper however uses the iterator itself)
getBidiRegions(const char utf8[],int utf8Units,Direction dir)129     static std::vector<Region> getBidiRegions(const char utf8[], int utf8Units, Direction dir) {
130 
131         auto bidiIterator = makeBidiIterator(utf8, utf8Units, dir);
132         std::vector<Region> bidiRegions;
133         const char* start8 = utf8;
134         const char* end8 = utf8 + utf8Units;
135         SkBidiIterator::Level currentLevel = 0;
136 
137         Position pos8 = 0;
138         Position pos16 = 0;
139         Position end16 = bidiIterator->getLength();
140         while (pos16 < end16) {
141             auto level = bidiIterator->getLevelAt(pos16);
142             if (pos16 == 0) {
143                 currentLevel = level;
144             } else if (level != currentLevel) {
145                 auto end = SkTo<Position>(start8 - utf8);
146                 bidiRegions.emplace_back(pos8, end, currentLevel);
147                 currentLevel = level;
148                 pos8 = end;
149             }
150             SkUnichar u = utf8_next(&start8, end8);
151             pos16 += SkUTF::ToUTF16(u);
152         }
153         auto end = start8 - utf8;
154         if (end != pos8) {
155             bidiRegions.emplace_back(pos8, end, currentLevel);
156         }
157         return bidiRegions;
158     }
159 };
160 
ReorderVisual(const Level runLevels[],int levelsCount,int32_t logicalFromVisual[])161 void SkBidiIterator::ReorderVisual(const Level runLevels[], int levelsCount,
162                                    int32_t logicalFromVisual[]) {
163     sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
164 }
165 
166 class SkBreakIterator_icu : public SkBreakIterator {
167     ICUBreakIterator fBreakIterator;
168     Position fLastResult;
169  public:
SkBreakIterator_icu(ICUBreakIterator iter)170     explicit SkBreakIterator_icu(ICUBreakIterator iter)
171         : fBreakIterator(std::move(iter)), fLastResult(0) {}
first()172     Position first() override
173       { return fLastResult = sk_ubrk_first(fBreakIterator.get()); }
current()174     Position current() override
175       { return fLastResult = sk_ubrk_current(fBreakIterator.get()); }
next()176     Position next() override
177       { return fLastResult = sk_ubrk_next(fBreakIterator.get()); }
preceding(Position offset)178     Position preceding(Position offset) override
179         { return fLastResult = sk_ubrk_preceding(fBreakIterator.get(), offset); }
following(Position offset)180     Position following(Position offset) override
181         { return fLastResult = sk_ubrk_following(fBreakIterator.get(), offset);}
status()182     Status status() override { return sk_ubrk_getRuleStatus(fBreakIterator.get()); }
isDone()183     bool isDone() override { return fLastResult == UBRK_DONE; }
184 
setText(const char utftext8[],int utf8Units)185     bool setText(const char utftext8[], int utf8Units) override {
186         UErrorCode status = U_ZERO_ERROR;
187         ICUUText text(sk_utext_openUTF8(nullptr, &utftext8[0], utf8Units, &status));
188 
189         if (U_FAILURE(status)) {
190             SkDEBUGF("Break error: %s", sk_u_errorName(status));
191             return false;
192         }
193         SkASSERT(text);
194         sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
195         if (U_FAILURE(status)) {
196             SkDEBUGF("Break error: %s", sk_u_errorName(status));
197             return false;
198         }
199         fLastResult = 0;
200         return true;
201     }
setText(const char16_t utftext16[],int utf16Units)202     bool setText(const char16_t utftext16[], int utf16Units) override {
203         UErrorCode status = U_ZERO_ERROR;
204         ICUUText text(sk_utext_openUChars(nullptr, reinterpret_cast<const UChar*>(&utftext16[0]),
205                                           utf16Units, &status));
206 
207         if (U_FAILURE(status)) {
208             SkDEBUGF("Break error: %s", sk_u_errorName(status));
209             return false;
210         }
211         SkASSERT(text);
212         sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
213         if (U_FAILURE(status)) {
214             SkDEBUGF("Break error: %s", sk_u_errorName(status));
215             return false;
216         }
217         fLastResult = 0;
218         return true;
219     }
220 };
221 
222 class SkIcuBreakIteratorCache {
223     SkTHashMap<SkUnicode::BreakType, ICUBreakIterator> fBreakCache;
224     SkMutex fBreakCacheMutex;
225 
226  public:
get()227     static SkIcuBreakIteratorCache& get() {
228         static SkIcuBreakIteratorCache instance;
229         return instance;
230     }
231 
makeBreakIterator(SkUnicode::BreakType type)232     ICUBreakIterator makeBreakIterator(SkUnicode::BreakType type) {
233         UErrorCode status = U_ZERO_ERROR;
234         ICUBreakIterator* cachedIterator;
235         {
236             SkAutoMutexExclusive lock(fBreakCacheMutex);
237             cachedIterator = fBreakCache.find(type);
238             if (!cachedIterator) {
239                 ICUBreakIterator newIterator(sk_ubrk_open(convertType(type), sk_uloc_getDefault(),
240                                                           nullptr, 0, &status));
241                 if (U_FAILURE(status)) {
242                     SkDEBUGF("Break error: %s", sk_u_errorName(status));
243                 } else {
244                     cachedIterator = fBreakCache.set(type, std::move(newIterator));
245                 }
246             }
247         }
248         ICUBreakIterator iterator;
249         if (cachedIterator) {
250             iterator.reset(sk_ubrk_clone(cachedIterator->get(), &status));
251             if (U_FAILURE(status)) {
252                 SkDEBUGF("Break error: %s", sk_u_errorName(status));
253             }
254         }
255         return iterator;
256     }
257 };
258 
259 class SkScriptIterator_icu : public SkScriptIterator {
260  public:
getScript(SkUnichar u,ScriptID * script)261    bool getScript(SkUnichar u, ScriptID* script) override {
262         UErrorCode status = U_ZERO_ERROR;
263         UScriptCode scriptCode = sk_uscript_getScript(u, &status);
264         if (U_FAILURE (status)) {
265             return false;
266         }
267         if (script) {
268             *script = (ScriptID)scriptCode;
269         }
270         return true;
271    }
272 
makeScriptIterator()273    static std::unique_ptr<SkScriptIterator> makeScriptIterator() {
274         return std::unique_ptr<SkScriptIterator>(new SkScriptIterator_icu());
275    }
276 };
277 
278 class SkUnicode_icu : public SkUnicode {
extractBidi(const char utf8[],int utf8Units,TextDirection dir,std::vector<BidiRegion> * bidiRegions)279     static bool extractBidi(const char utf8[],
280                             int utf8Units,
281                             TextDirection dir,
282                             std::vector<BidiRegion>* bidiRegions) {
283 
284         // Convert to UTF16 since for now bidi iterator only operates on utf16
285         auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
286 
287         // Create bidi iterator
288         UErrorCode status = U_ZERO_ERROR;
289         SkUnicodeBidi bidi(sk_ubidi_openSized(utf16.size(), 0, &status));
290         if (U_FAILURE(status)) {
291             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
292             return false;
293         }
294         SkASSERT(bidi);
295         uint8_t bidiLevel = (dir == TextDirection::kLTR) ? UBIDI_LTR : UBIDI_RTL;
296         // The required lifetime of utf16 isn't well documented.
297         // It appears it isn't used after ubidi_setPara except through ubidi_getText.
298         sk_ubidi_setPara(bidi.get(), (const UChar*)utf16.c_str(), utf16.size(), bidiLevel, nullptr,
299                          &status);
300         if (U_FAILURE(status)) {
301             SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
302             return false;
303         }
304 
305         // Iterate through bidi regions and the result positions into utf8
306         const char* start8 = utf8;
307         const char* end8 = utf8 + utf8Units;
308         BidiLevel currentLevel = 0;
309 
310         Position pos8 = 0;
311         Position pos16 = 0;
312         Position end16 = sk_ubidi_getLength(bidi.get());
313         while (pos16 < end16) {
314             auto level = sk_ubidi_getLevelAt(bidi.get(), pos16);
315             if (pos16 == 0) {
316                 currentLevel = level;
317             } else if (level != currentLevel) {
318                 Position end = start8 - utf8;
319                 bidiRegions->emplace_back(pos8, end, currentLevel);
320                 currentLevel = level;
321                 pos8 = end;
322             }
323             SkUnichar u = utf8_next(&start8, end8);
324             pos16 += SkUTF::ToUTF16(u);
325         }
326         Position end = start8 - utf8;
327         if (end != pos8) {
328             bidiRegions->emplace_back(pos8, end, currentLevel);
329         }
330         return true;
331     }
332 
extractWords(uint16_t utf16[],int utf16Units,std::vector<Position> * words)333     static bool extractWords(uint16_t utf16[], int utf16Units, std::vector<Position>* words) {
334 
335         UErrorCode status = U_ZERO_ERROR;
336 
337         ICUBreakIterator iterator = SkIcuBreakIteratorCache::get().makeBreakIterator(BreakType::kWords);
338         if (!iterator) {
339             SkDEBUGF("Break error: %s", sk_u_errorName(status));
340             return false;
341         }
342         SkASSERT(iterator);
343 
344         ICUUText utf16UText(sk_utext_openUChars(nullptr, (UChar*)utf16, utf16Units, &status));
345         if (U_FAILURE(status)) {
346             SkDEBUGF("Break error: %s", sk_u_errorName(status));
347             return false;
348         }
349 
350         sk_ubrk_setUText(iterator.get(), utf16UText.get(), &status);
351         if (U_FAILURE(status)) {
352             SkDEBUGF("Break error: %s", sk_u_errorName(status));
353             return false;
354         }
355 
356         // Get the words
357         int32_t pos = sk_ubrk_first(iterator.get());
358         while (pos != UBRK_DONE) {
359             words->emplace_back(pos);
360             pos = sk_ubrk_next(iterator.get());
361         }
362 
363         return true;
364     }
365 
extractPositions(const char utf8[],int utf8Units,BreakType type,std::function<void (int,int)> setBreak)366     static bool extractPositions
367         (const char utf8[], int utf8Units, BreakType type, std::function<void(int, int)> setBreak) {
368 
369         UErrorCode status = U_ZERO_ERROR;
370         ICUUText text(sk_utext_openUTF8(nullptr, &utf8[0], utf8Units, &status));
371 
372         if (U_FAILURE(status)) {
373             SkDEBUGF("Break error: %s", sk_u_errorName(status));
374             return false;
375         }
376         SkASSERT(text);
377 
378         ICUBreakIterator iterator = SkIcuBreakIteratorCache::get().makeBreakIterator(type);
379         if (!iterator) {
380             return false;
381         }
382 
383         sk_ubrk_setUText(iterator.get(), text.get(), &status);
384         if (U_FAILURE(status)) {
385             SkDEBUGF("Break error: %s", sk_u_errorName(status));
386             return false;
387         }
388 
389         auto iter = iterator.get();
390         int32_t pos = sk_ubrk_first(iter);
391         while (pos != UBRK_DONE) {
392             auto status = type == SkUnicode::BreakType::kLines
393                               ? UBRK_LINE_SOFT
394                               : sk_ubrk_getRuleStatus(iter);
395             setBreak(pos, status);
396             pos = sk_ubrk_next(iter);
397         }
398 
399         if (type == SkUnicode::BreakType::kLines) {
400             // This is a workaround for https://bugs.chromium.org/p/skia/issues/detail?id=10715
401             // (ICU line break iterator does not work correctly on Thai text with new lines)
402             // So, we only use the iterator to collect soft line breaks and
403             // scan the text for all hard line breaks ourselves
404             const char* end = utf8 + utf8Units;
405             const char* ch = utf8;
406             while (ch < end) {
407                 auto unichar = utf8_next(&ch, end);
408                 if (isHardLineBreak(unichar)) {
409                     setBreak(ch - utf8, UBRK_LINE_HARD);
410                 }
411             }
412         }
413         return true;
414     }
415 
416 public:
~SkUnicode_icu()417     ~SkUnicode_icu() override { }
makeBidiIterator(const uint16_t text[],int count,SkBidiIterator::Direction dir)418     std::unique_ptr<SkBidiIterator> makeBidiIterator(const uint16_t text[], int count,
419                                                      SkBidiIterator::Direction dir) override {
420         return SkBidiIterator_icu::makeBidiIterator(text, count, dir);
421     }
makeBidiIterator(const char text[],int count,SkBidiIterator::Direction dir)422     std::unique_ptr<SkBidiIterator> makeBidiIterator(const char text[],
423                                                      int count,
424                                                      SkBidiIterator::Direction dir) override {
425         return SkBidiIterator_icu::makeBidiIterator(text, count, dir);
426     }
makeBreakIterator(const char locale[],BreakType breakType)427     std::unique_ptr<SkBreakIterator> makeBreakIterator(const char locale[],
428                                                        BreakType breakType) override {
429         UErrorCode status = U_ZERO_ERROR;
430         ICUBreakIterator iterator(sk_ubrk_open(convertType(breakType), locale, nullptr, 0,
431                                                &status));
432         if (U_FAILURE(status)) {
433             SkDEBUGF("Break error: %s", sk_u_errorName(status));
434             return nullptr;
435         }
436         return std::unique_ptr<SkBreakIterator>(new SkBreakIterator_icu(std::move(iterator)));
437     }
makeBreakIterator(BreakType breakType)438     std::unique_ptr<SkBreakIterator> makeBreakIterator(BreakType breakType) override {
439         return makeBreakIterator(sk_uloc_getDefault(), breakType);
440     }
makeScriptIterator()441     std::unique_ptr<SkScriptIterator> makeScriptIterator() override {
442         return SkScriptIterator_icu::makeScriptIterator();
443     }
444 
445     // TODO: Use ICU data file to detect controls and whitespaces
isControl(SkUnichar utf8)446     bool isControl(SkUnichar utf8) override {
447         return sk_u_iscntrl(utf8);
448     }
449 
isWhitespace(SkUnichar utf8)450     bool isWhitespace(SkUnichar utf8) override {
451         return sk_u_isWhitespace(utf8);
452     }
453 
isSpace(SkUnichar utf8)454     bool isSpace(SkUnichar utf8) override {
455         return sk_u_isspace(utf8);
456     }
457 
isHardLineBreak(SkUnichar utf8)458     static bool isHardLineBreak(SkUnichar utf8) {
459         auto property = sk_u_getIntPropertyValue(utf8, UCHAR_LINE_BREAK);
460         return property == U_LB_LINE_FEED || property == U_LB_MANDATORY_BREAK;
461     }
462 
toUpper(const SkString & str)463     SkString toUpper(const SkString& str) override {
464         // Convert to UTF16 since that's what ICU wants.
465         auto str16 = convertUtf8ToUtf16(str.c_str(), str.size());
466 
467         UErrorCode icu_err = U_ZERO_ERROR;
468         const auto upper16len = sk_u_strToUpper(nullptr, 0, (UChar*)(str16.c_str()), str16.size(),
469                                                 nullptr, &icu_err);
470         if (icu_err != U_BUFFER_OVERFLOW_ERROR || upper16len <= 0) {
471             return SkString();
472         }
473 
474         SkAutoSTArray<128, uint16_t> upper16(upper16len);
475         icu_err = U_ZERO_ERROR;
476         sk_u_strToUpper((UChar*)(upper16.get()), SkToS32(upper16.size()),
477                         (UChar*)(str16.c_str()), str16.size(),
478                         nullptr, &icu_err);
479         SkASSERT(!U_FAILURE(icu_err));
480 
481         // ... and back to utf8 'cause that's what we want.
482         return convertUtf16ToUtf8((char16_t*)upper16.get(), upper16.size());
483     }
484 
getBidiRegions(const char utf8[],int utf8Units,TextDirection dir,std::vector<BidiRegion> * results)485     bool getBidiRegions(const char utf8[],
486                         int utf8Units,
487                         TextDirection dir,
488                         std::vector<BidiRegion>* results) override {
489         return extractBidi(utf8, utf8Units, dir, results);
490     }
491 
getLineBreaks(const char utf8[],int utf8Units,std::vector<LineBreakBefore> * results)492     bool getLineBreaks(const char utf8[],
493                        int utf8Units,
494                        std::vector<LineBreakBefore>* results) override {
495 
496         return extractPositions(utf8, utf8Units, BreakType::kLines,
497             [results](int pos, int status) {
498                     results->emplace_back(pos, status == UBRK_LINE_HARD
499                                                         ? LineBreakType::kHardLineBreak
500                                                         : LineBreakType::kSoftLineBreak);
501         });
502     }
503 
getWords(const char utf8[],int utf8Units,std::vector<Position> * results)504     bool getWords(const char utf8[], int utf8Units, std::vector<Position>* results) override {
505 
506         // Convert to UTF16 since we want the results in utf16
507         auto utf16 = convertUtf8ToUtf16(utf8, utf8Units);
508         return extractWords((uint16_t*)utf16.c_str(), utf16.size(), results);
509     }
510 
getGraphemes(const char utf8[],int utf8Units,std::vector<Position> * results)511     bool getGraphemes(const char utf8[], int utf8Units, std::vector<Position>* results) override {
512 
513         return extractPositions(utf8, utf8Units, BreakType::kGraphemes,
514             [results](int pos, int status) { results->emplace_back(pos);
515         });
516     }
517 
reorderVisual(const BidiLevel runLevels[],int levelsCount,int32_t logicalFromVisual[])518     void reorderVisual(const BidiLevel runLevels[],
519                        int levelsCount,
520                        int32_t logicalFromVisual[]) override {
521         sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
522     }
523 };
524 
Make()525 std::unique_ptr<SkUnicode> SkUnicode::Make() {
526     #if defined(SK_USING_THIRD_PARTY_ICU)
527     if (!SkLoadICU()) {
528         static SkOnce once;
529         once([] { SkDEBUGF("SkLoadICU() failed!\n"); });
530         return nullptr;
531     }
532     #endif
533 
534     return ICULib()
535         ? std::make_unique<SkUnicode_icu>()
536         : nullptr;
537 }
538