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 // Definitions internal to Minikin 18 19 #include "MinikinInternal.h" 20 #include "HbFontCache.h" 21 #include "generated/UnicodeData.h" 22 23 #include <cutils/log.h> 24 25 namespace android { 26 27 Mutex gMinikinLock; 28 assertMinikinLocked()29void assertMinikinLocked() { 30 #ifdef ENABLE_RACE_DETECTION 31 LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0); 32 #endif 33 } 34 isEmoji(uint32_t c)35bool isEmoji(uint32_t c) { 36 // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. 37 // TODO: remove once emoji database is updated. 38 if (c == 0x2695 || c == 0x2640 || c == 0x2642) { 39 return true; 40 } 41 const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); 42 return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); 43 } 44 45 // Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt isEmojiModifier(uint32_t c)46bool isEmojiModifier(uint32_t c) { 47 return (0x1F3FB <= c && c <= 0x1F3FF); 48 } 49 50 // Based on Emoji_Modifier_Base from 51 // http://www.unicode.org/Public/emoji/3.0/emoji-data.txt isEmojiBase(uint32_t c)52bool isEmojiBase(uint32_t c) { 53 if (0x261D <= c && c <= 0x270D) { 54 return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); 55 } else if (0x1F385 <= c && c <= 0x1F93E) { 56 return (c == 0x1F385 57 || (0x1F3C3 <= c && c <= 0x1F3C4) 58 || (0x1F3CA <= c && c <= 0x1F3CB) 59 || (0x1F442 <= c && c <= 0x1F443) 60 || (0x1F446 <= c && c <= 0x1F450) 61 || (0x1F466 <= c && c <= 0x1F469) 62 || c == 0x1F46E 63 || (0x1F470 <= c && c <= 0x1F478) 64 || c == 0x1F47C 65 || (0x1F481 <= c && c <= 0x1F483) 66 || (0x1F485 <= c && c <= 0x1F487) 67 || c == 0x1F4AA 68 || c == 0x1F575 69 || c == 0x1F57A 70 || c == 0x1F590 71 || (0x1F595 <= c && c <= 0x1F596) 72 || (0x1F645 <= c && c <= 0x1F647) 73 || (0x1F64B <= c && c <= 0x1F64F) 74 || c == 0x1F6A3 75 || (0x1F6B4 <= c && c <= 0x1F6B6) 76 || c == 0x1F6C0 77 || (0x1F918 <= c && c <= 0x1F91E) 78 || c == 0x1F926 79 || c == 0x1F930 80 || (0x1F933 <= c && c <= 0x1F939) 81 || (0x1F93B <= c && c <= 0x1F93E)); 82 } else { 83 return false; 84 } 85 } 86 getFontTable(MinikinFont * minikinFont,uint32_t tag)87hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) { 88 assertMinikinLocked(); 89 hb_font_t* font = getHbFontLocked(minikinFont); 90 hb_face_t* face = hb_font_get_face(font); 91 hb_blob_t* blob = hb_face_reference_table(face, tag); 92 hb_font_destroy(font); 93 return blob; 94 } 95 96 } 97