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 19namespace minikin { 20 21bool isNewEmoji(uint32_t c) { 22 // Emoji characters new in Unicode emoji 11 23 // From https://www.unicode.org/Public/emoji/11.0/emoji-data.txt 24 // TODO: Remove once emoji-data.text 11 is in ICU or update to 11. 25 if (c < 0x1F6F9 || c > 0x1F9FF) { 26 // Optimization for characters outside the new emoji range. 27 return false; 28 } 29 return c == 0x265F || c == 0x267E || c == 0x1F6F9 || (0x1F94D <= c && c <= 0x1F94F) || 30 (0x1F96C <= c && c <= 0x1F970) || (0x1F973 <= c && c <= 0x1F976) || c == 0x1F97A || 31 (0x1F97C <= c && c <= 0x1F97F) || (0x1F998 <= c && c <= 0x1F9A2) || 32 (0x1F9B0 <= c && c <= 0x1F9B9) || (0x1F9C1 <= c && c <= 0x1F9C2) || 33 (0x1F9E7 <= c && c <= 0x1F9FF); 34} 35 36bool isEmoji(uint32_t c) { 37 return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI); 38} 39 40bool isEmojiModifier(uint32_t c) { 41 // Emoji modifier are not expected to change, so there's a small change we need to customize 42 // this. 43 return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER); 44} 45 46bool isEmojiBase(uint32_t c) { 47 // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep 48 // them as emoji modifier bases since there are fonts and user-generated text out there that 49 // treats these as potential emoji bases. 50 if (c == 0x1F91D || c == 0x1F93C) { 51 return true; 52 } 53 // Emoji Modifier Base characters new in Unicode emoji 11 54 // From https://www.unicode.org/Public/emoji/11.0/emoji-data.txt 55 // TODO: Remove once emoji-data.text 11 is in ICU or update to 11. 56 if ((0x1F9B5 <= c && c <= 0x1F9B6) || (0x1F9B8 <= c && c <= 0x1F9B9)) { 57 return true; 58 } 59 return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE); 60} 61 62UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) { 63 if (isNewEmoji(c)) { 64 // All new emoji characters in Unicode 10.0 are of the bidi class ON. 65 return U_OTHER_NEUTRAL; 66 } else { 67 return u_charDirection(c); 68 } 69} 70 71} // namespace minikin 72