Home | History | Annotate | Download | only in minikin
      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 
     29 void assertMinikinLocked() {
     30 #ifdef ENABLE_RACE_DETECTION
     31     LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0);
     32 #endif
     33 }
     34 
     35 bool isEmoji(uint32_t c) {
     36     const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]);
     37     return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c);
     38 }
     39 
     40 // Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt
     41 bool isEmojiModifier(uint32_t c) {
     42     return (0x1F3FB <= c && c <= 0x1F3FF);
     43 }
     44 
     45 // Based on Emoji_Modifier_Base from
     46 // http://www.unicode.org/Public/emoji/3.0/emoji-data.txt
     47 bool isEmojiBase(uint32_t c) {
     48     if (0x261D <= c && c <= 0x270D) {
     49         return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D));
     50     } else if (0x1F385 <= c && c <= 0x1F93E) {
     51         return (c == 0x1F385
     52                 || (0x1F3C3 <= c && c <= 0x1F3C4)
     53                 || (0x1F3CA <= c && c <= 0x1F3CB)
     54                 || (0x1F442 <= c && c <= 0x1F443)
     55                 || (0x1F446 <= c && c <= 0x1F450)
     56                 || (0x1F466 <= c && c <= 0x1F469)
     57                 || c == 0x1F46E
     58                 || (0x1F470 <= c && c <= 0x1F478)
     59                 || c == 0x1F47C
     60                 || (0x1F481 <= c && c <= 0x1F483)
     61                 || (0x1F485 <= c && c <= 0x1F487)
     62                 || c == 0x1F4AA
     63                 || c == 0x1F575
     64                 || c == 0x1F57A
     65                 || c == 0x1F590
     66                 || (0x1F595 <= c && c <= 0x1F596)
     67                 || (0x1F645 <= c && c <= 0x1F647)
     68                 || (0x1F64B <= c && c <= 0x1F64F)
     69                 || c == 0x1F6A3
     70                 || (0x1F6B4 <= c && c <= 0x1F6B6)
     71                 || c == 0x1F6C0
     72                 || (0x1F918 <= c && c <= 0x1F91E)
     73                 || c == 0x1F926
     74                 || c == 0x1F930
     75                 || (0x1F933 <= c && c <= 0x1F939)
     76                 || (0x1F93B <= c && c <= 0x1F93E));
     77     } else {
     78         return false;
     79     }
     80 }
     81 
     82 hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) {
     83     assertMinikinLocked();
     84     hb_font_t* font = getHbFontLocked(minikinFont);
     85     hb_face_t* face = hb_font_get_face(font);
     86     hb_blob_t* blob = hb_face_reference_table(face, tag);
     87     hb_font_destroy(font);
     88     return blob;
     89 }
     90 
     91 }
     92