Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/CharacterEmoji.cpp

Issue 1856353002: Use ICU's emoji character properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uchar.h: include explicitly Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/fonts/Character.h" 5 #include "platform/fonts/Character.h"
6 6
7 #include <unicode/uchar.h>
8 #include <unicode/uvernum.h>
9
10 #if defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56)
drott 2016/04/05 19:40:40 Can we avoid #ifdef and only keep the ICU property
7 #include <unicode/uniset.h> 11 #include <unicode/uniset.h>
12 #endif
8 13
9 using namespace WTF; 14 using namespace WTF;
10 using namespace Unicode; 15 using namespace Unicode;
11 16
12 namespace blink { 17 namespace blink {
13 18
19 // ICU 56 or earlier does not have API for Emoji properties,
20 // but Chrome's copy of ICU 56 does.
21 #if defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56)
14 // The following UnicodeSet patterns were compiled from 22 // The following UnicodeSet patterns were compiled from
15 // http://www.unicode.org/Public/emoji/2.0//emoji-data.txt 23 // http://www.unicode.org/Public/emoji/2.0//emoji-data.txt
16 24
17 // FIXME crbug.com/579552:
18 // These patterns should move to property group definitions in ICU.
19
20 static const char kEmojiTextPattern[] = 25 static const char kEmojiTextPattern[] =
21 R"([[#][*][0-9][\u00A9][\u00AE][\u203C][\u2049][\u2122][\u2139])" 26 R"([[#][*][0-9][\u00A9][\u00AE][\u203C][\u2049][\u2122][\u2139])"
22 R"([\u2194-\u2199][\u21A9-\u21AA][\u231A-\u231B][\u2328][\u23CF])" 27 R"([\u2194-\u2199][\u21A9-\u21AA][\u231A-\u231B][\u2328][\u23CF])"
23 R"([\u23E9-\u23F3][\u23F8-\u23FA][\u24C2][\u25AA-\u25AB][\u25B6][\u25C0])" 28 R"([\u23E9-\u23F3][\u23F8-\u23FA][\u24C2][\u25AA-\u25AB][\u25B6][\u25C0])"
24 R"([\u25FB-\u25FE][\u2600-\u2604][\u260E][\u2611][\u2614-\u2615][\u2618])" 29 R"([\u25FB-\u25FE][\u2600-\u2604][\u260E][\u2611][\u2614-\u2615][\u2618])"
25 R"([\u261D][\u2620][\u2622-\u2623][\u2626][\u262A][\u262E-\u262F])" 30 R"([\u261D][\u2620][\u2622-\u2623][\u2626][\u262A][\u262E-\u262F])"
26 R"([\u2638-\u263A][\u2648-\u2653][\u2660][\u2663][\u2665-\u2666][\u2668])" 31 R"([\u2638-\u263A][\u2648-\u2653][\u2660][\u2663][\u2665-\u2666][\u2668])"
27 R"([\u267B][\u267F][\u2692-\u2694][\u2696-\u2697][\u2699][\u269B-\u269C])" 32 R"([\u267B][\u267F][\u2692-\u2694][\u2696-\u2697][\u2699][\u269B-\u269C])"
28 R"([\u26A0-\u26A1][\u26AA-\u26AB][\u26B0-\u26B1][\u26BD-\u26BE])" 33 R"([\u26A0-\u26A1][\u26AA-\u26AB][\u26B0-\u26B1][\u26BD-\u26BE])"
29 R"([\u26C4-\u26C5][\u26C8][\u26CE-\u26CF][\u26D1][\u26D3-\u26D4])" 34 R"([\u26C4-\u26C5][\u26C8][\u26CE-\u26CF][\u26D1][\u26D3-\u26D4])"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 98 }
94 99
95 bool Character::isEmojiEmojiPresentation(UChar32 ch) 100 bool Character::isEmojiEmojiPresentation(UChar32 ch)
96 { 101 {
97 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojiEmojiSet, ()); 102 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojiEmojiSet, ());
98 if (emojiEmojiSet.isEmpty()) 103 if (emojiEmojiSet.isEmpty())
99 applyPatternAndFreeze(&emojiEmojiSet, kEmojiEmojiPattern); 104 applyPatternAndFreeze(&emojiEmojiSet, kEmojiEmojiPattern);
100 return emojiEmojiSet.contains(ch); 105 return emojiEmojiSet.contains(ch);
101 } 106 }
102 107
103
104 bool Character::isEmojiModifierBase(UChar32 ch) 108 bool Character::isEmojiModifierBase(UChar32 ch)
105 { 109 {
106 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojieModifierBaseSet, ()); 110 DEFINE_STATIC_LOCAL(icu::UnicodeSet, emojieModifierBaseSet, ());
107 if (emojieModifierBaseSet.isEmpty()) 111 if (emojieModifierBaseSet.isEmpty())
108 applyPatternAndFreeze(&emojieModifierBaseSet, kEmojiModifierBasePattern) ; 112 applyPatternAndFreeze(&emojieModifierBaseSet, kEmojiModifierBasePattern) ;
109 return emojieModifierBaseSet.contains(ch); 113 return emojieModifierBaseSet.contains(ch);
110 } 114 }
115 #else
116 bool Character::isEmojiTextPresentation(UChar32 ch)
117 {
118 return u_hasBinaryProperty(ch, UCHAR_EMOJI)
119 && !u_hasBinaryProperty(ch, UCHAR_EMOJI_PRESENTATION);
120 }
121
122 bool Character::isEmojiEmojiPresentation(UChar32 ch)
123 {
124 return u_hasBinaryProperty(ch, UCHAR_EMOJI_PRESENTATION);
125 }
126
127 bool Character::isEmojiModifierBase(UChar32 ch)
128 {
129 return u_hasBinaryProperty(ch, UCHAR_EMOJI_MODIFIER_BASE);
130 }
131 #endif // defined(USING_SYSTEM_ICU) && (U_ICU_VERSION_MAJOR_NUM <= 56)
111 132
112 bool Character::isEmojiKeycapBase(UChar32 ch) 133 bool Character::isEmojiKeycapBase(UChar32 ch)
113 { 134 {
114 return (ch >= '0' && ch <= '9') || ch == '#'; 135 return (ch >= '0' && ch <= '9') || ch == '#';
115 } 136 }
116 137
117 bool Character::isRegionalIndicator(UChar32 ch) 138 bool Character::isRegionalIndicator(UChar32 ch)
118 { 139 {
119 return (ch >= 0x1F1E6 && ch <= 0x1F1FF); 140 return (ch >= 0x1F1E6 && ch <= 0x1F1FF);
120 } 141 }
121 142
122 143
123 }; // namespace blink 144 }; // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698