1 /*
2 * Copyright 2023 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
8 #include "include/private/base/SkDebug.h"
9 #include "modules/skunicode/src/SkUnicode_hardcoded.h"
10 #include <algorithm>
11 #include <array>
12 #include <utility>
13
isControl(SkUnichar utf8)14 bool SkUnicodeHardCodedCharProperties::isControl(SkUnichar utf8) {
15 return (utf8 < ' ') || (utf8 >= 0x7f && utf8 <= 0x9f) ||
16 (utf8 >= 0x200D && utf8 <= 0x200F) ||
17 (utf8 >= 0x202A && utf8 <= 0x202E);
18 }
19
isWhitespace(SkUnichar unichar)20 bool SkUnicodeHardCodedCharProperties::isWhitespace(SkUnichar unichar) {
21 static constexpr std::array<SkUnichar, 21> whitespaces {
22 0x0009, // character tabulation
23 0x000A, // line feed
24 0x000B, // line tabulation
25 0x000C, // form feed
26 0x000D, // carriage return
27 0x0020, // space
28 //0x0085, // next line
29 //0x00A0, // no-break space
30 0x1680, // ogham space mark
31 0x2000, // en quad
32 0x2001, // em quad
33 0x2002, // en space
34 0x2003, // em space
35 0x2004, // three-per-em space
36 0x2005, // four-per-em space
37 0x2006, // six-per-em space
38 //0x2007, // figure space
39 0x2008, // punctuation space
40 0x2009, // thin space
41 0x200A, // hair space
42 0x2028, // line separator
43 0x2029, // paragraph separator
44 //0x202F, // narrow no-break space
45 0x205F, // medium mathematical space
46 0x3000};// ideographic space
47 return std::find(whitespaces.begin(), whitespaces.end(), unichar) != whitespaces.end();
48 }
49
isSpace(SkUnichar unichar)50 bool SkUnicodeHardCodedCharProperties::isSpace(SkUnichar unichar) {
51 static constexpr std::array<SkUnichar, 25> spaces {
52 0x0009, // character tabulation
53 0x000A, // line feed
54 0x000B, // line tabulation
55 0x000C, // form feed
56 0x000D, // carriage return
57 0x0020, // space
58 0x0085, // next line
59 0x00A0, // no-break space
60 0x1680, // ogham space mark
61 0x2000, // en quad
62 0x2001, // em quad
63 0x2002, // en space
64 0x2003, // em space
65 0x2004, // three-per-em space
66 0x2005, // four-per-em space
67 0x2006, // six-per-em space
68 0x2007, // figure space
69 0x2008, // punctuation space
70 0x2009, // thin space
71 0x200A, // hair space
72 0x2028, // line separator
73 0x2029, // paragraph separator
74 0x202F, // narrow no-break space
75 0x205F, // medium mathematical space
76 0x3000}; // ideographic space
77 return std::find(spaces.begin(), spaces.end(), unichar) != spaces.end();
78 }
79
isTabulation(SkUnichar utf8)80 bool SkUnicodeHardCodedCharProperties::isTabulation(SkUnichar utf8) {
81 return utf8 == '\t';
82 }
83
isHardBreak(SkUnichar utf8)84 bool SkUnicodeHardCodedCharProperties::isHardBreak(SkUnichar utf8) {
85 return utf8 == '\n' || utf8 == u'\u2028';
86 }
87
isEmoji(SkUnichar unichar)88 bool SkUnicodeHardCodedCharProperties::isEmoji(SkUnichar unichar) {
89 SkDEBUGFAIL("isEmoji Not implemented");
90 return false;
91 }
92
isEmojiComponent(SkUnichar utf8)93 bool SkUnicodeHardCodedCharProperties::isEmojiComponent(SkUnichar utf8) {
94 SkDEBUGFAIL("isEmojiComponent Not implemented");
95 return false;
96 }
97
isEmojiModifier(SkUnichar utf8)98 bool SkUnicodeHardCodedCharProperties::isEmojiModifier(SkUnichar utf8) {
99 SkDEBUGFAIL("isEmojiModifier Not implemented");
100 return false;
101 }
102
isEmojiModifierBase(SkUnichar utf8)103 bool SkUnicodeHardCodedCharProperties::isEmojiModifierBase(SkUnichar utf8) {
104 SkDEBUGFAIL("isEmojiModifierBase Not implemented");
105 return false;
106 }
107
isRegionalIndicator(SkUnichar unichar)108 bool SkUnicodeHardCodedCharProperties::isRegionalIndicator(SkUnichar unichar) {
109 SkDEBUGFAIL("isRegionalIndicator Not implemented");
110 return false;
111 }
112
isIdeographic(SkUnichar unichar)113 bool SkUnicodeHardCodedCharProperties::isIdeographic(SkUnichar unichar) {
114 static constexpr std::array<std::pair<SkUnichar, SkUnichar>, 8> ranges {{
115 {4352, 4607}, // Hangul Jamo
116 {11904, 42191}, // CJK_Radicals
117 {43072, 43135}, // Phags_Pa
118 {44032, 55215}, // Hangul_Syllables
119 {63744, 64255}, // CJK_Compatibility_Ideographs
120 {65072, 65103}, // CJK_Compatibility_Forms
121 {65381, 65500}, // Katakana_Hangul_Halfwidth
122 {131072, 196607}// Supplementary_Ideographic_Plane
123 }};
124 for (auto range : ranges) {
125 if (range.first <= unichar && range.second > unichar) {
126 return true;
127 }
128 }
129 return false;
130 }
131