• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <minikin/Emoji.h>
18 
19 namespace minikin {
20 
isNewEmoji(uint32_t c)21 bool isNewEmoji(uint32_t c) {
22     // Emoji characters new in Unicode emoji 5.0.
23     // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt
24     // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0.
25     if (c < 0x1F6F7 || c > 0x1F9E6) {
26         // Optimization for characters outside the new emoji range.
27         return false;
28     }
29     return (0x1F6F7 <= c && c <= 0x1F6F8)
30             || c == 0x1F91F
31             || (0x1F928 <= c && c <= 0x1F92F)
32             || (0x1F931 <= c && c <= 0x1F932)
33             || c == 0x1F94C
34             || (0x1F95F <= c && c <= 0x1F96B)
35             || (0x1F992 <= c && c <= 0x1F997)
36             || (0x1F9D0 <= c && c <= 0x1F9E6);
37 }
38 
isEmoji(uint32_t c)39 bool isEmoji(uint32_t c) {
40     return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI);
41 }
42 
isEmojiModifier(uint32_t c)43 bool isEmojiModifier(uint32_t c) {
44     // Emoji modifier are not expected to change, so there's a small change we need to customize
45     // this.
46     return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER);
47 }
48 
isEmojiBase(uint32_t c)49 bool isEmojiBase(uint32_t c) {
50     // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep
51     // them as emoji modifier bases since there are fonts and user-generated text out there that
52     // treats these as potential emoji bases.
53     if (c == 0x1F91D || c == 0x1F93C) {
54         return true;
55     }
56     // Emoji Modifier Base characters new in Unicode emoji 5.0.
57     // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt
58     // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0.
59     if (c == 0x1F91F
60             || (0x1F931 <= c && c <= 0x1F932)
61             || (0x1F9D1 <= c && c <= 0x1F9DD)) {
62         return true;
63     }
64     return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE);
65 }
66 
emojiBidiOverride(const void *,UChar32 c)67 UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) {
68     if (isNewEmoji(c)) {
69         // All new emoji characters in Unicode 10.0 are of the bidi class ON.
70         return U_OTHER_NEUTRAL;
71     } else {
72         return u_charDirection(c);
73     }
74 }
75 
76 }  // namespace minikin
77 
78