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 #define LOG_TAG "Minikin"
     19 
     20 #include "MinikinInternal.h"
     21 #include "HbFontCache.h"
     22 
     23 #include <log/log.h>
     24 
     25 namespace minikin {
     26 
     27 android::Mutex gMinikinLock;
     28 
     29 void assertMinikinLocked() {
     30 #ifdef ENABLE_RACE_DETECTION
     31     LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0);
     32 #endif
     33 }
     34 
     35 hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) {
     36     assertMinikinLocked();
     37     hb_font_t* font = getHbFontLocked(minikinFont);
     38     hb_face_t* face = hb_font_get_face(font);
     39     hb_blob_t* blob = hb_face_reference_table(face, tag);
     40     hb_font_destroy(font);
     41     return blob;
     42 }
     43 
     44 inline static bool isBMPVariationSelector(uint32_t codePoint) {
     45     return VS1 <= codePoint && codePoint <= VS16;
     46 }
     47 
     48 inline static bool isVariationSelectorSupplement(uint32_t codePoint) {
     49     return VS17 <= codePoint && codePoint <= VS256;
     50 }
     51 
     52 uint16_t getVsIndex(uint32_t codePoint) {
     53     if (isBMPVariationSelector(codePoint)) {
     54         return codePoint - VS1;
     55     } else if (isVariationSelectorSupplement(codePoint)) {
     56         return codePoint - VS17 + 16;
     57     } else {
     58         return INVALID_VS_INDEX;
     59     }
     60 }
     61 
     62 bool isVariationSelector(uint32_t codePoint) {
     63     return isBMPVariationSelector(codePoint) || isVariationSelectorSupplement(codePoint);
     64 }
     65 
     66 }  // namespace minikin
     67