• 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 12
23     // From https://www.unicode.org/Public/emoji/12.0/emoji-data.txt
24     // TODO: Remove once emoji-data.text 12 is in ICU or update to 12.
25     if (c < 0x1F6D5 || c > 0x1FA95) {
26         // Optimization for characters outside the new emoji range.
27         return false;
28     }
29     return c == 0x1F6D5 || c == 0x1F6FA || c == 0x1F93F || c == 0x1F971 || c == 0x1F97B ||
30            (0x1F7E0 <= c && c <= 0x1F7EB) || (0x1F90D <= c && c <= 0x1F90F) ||
31            (0x1F9A5 <= c && c <= 0x1F9AA) || (0x1F9AE <= c && c <= 0x1F9AF) ||
32            (0x1F9BA <= c && c <= 0x1F9BF) || (0x1F9C3 <= c && c <= 0x1F9CA) ||
33            (0x1F9CD <= c && c <= 0x1F9CF) || (0x1FA70 <= c && c <= 0x1FA73) ||
34            (0x1FA78 <= c && c <= 0x1FA7A) || (0x1FA80 <= c && c <= 0x1FA82) ||
35            (0x1FA90 <= c && c <= 0x1FA95);
36 }
37 
isEmoji(uint32_t c)38 bool isEmoji(uint32_t c) {
39     return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI);
40 }
41 
isEmojiModifier(uint32_t c)42 bool isEmojiModifier(uint32_t c) {
43     // Emoji modifier are not expected to change, so there's a small change we need to customize
44     // this.
45     return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER);
46 }
47 
isEmojiBase(uint32_t c)48 bool isEmojiBase(uint32_t c) {
49     // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep
50     // them as emoji modifier bases since there are fonts and user-generated text out there that
51     // treats these as potential emoji bases.
52     if (c == 0x1F91D || c == 0x1F93C) {
53         return true;
54     }
55     // Emoji Modifier Base characters new in Unicode emoji 11
56     // From https://www.unicode.org/Public/emoji/11.0/emoji-data.txt
57     // TODO: Remove once emoji-data.text 11 is in ICU or update to 11.
58     if ((0x1F9B5 <= c && c <= 0x1F9B6) || (0x1F9B8 <= c && c <= 0x1F9B9)) {
59         return true;
60     }
61     return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE);
62 }
63 
emojiBidiOverride(const void *,UChar32 c)64 UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) {
65     if (isNewEmoji(c)) {
66         // All new emoji characters in Unicode 10.0 are of the bidi class ON.
67         return U_OTHER_NEUTRAL;
68     } else {
69         return u_charDirection(c);
70     }
71 }
72 
73 }  // namespace minikin
74