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#ifndef MINIKIN_INTERNAL_H 20#define MINIKIN_INTERNAL_H 21 22#include <hb.h> 23 24#include <utils/Mutex.h> 25 26#include <minikin/MinikinFont.h> 27 28namespace android { 29 30// All external Minikin interfaces are designed to be thread-safe. 31// Presently, that's implemented by through a global lock, and having 32// all external interfaces take that lock. 33 34extern Mutex gMinikinLock; 35 36// Aborts if gMinikinLock is not acquired. Do nothing on the release build. 37void assertMinikinLocked(); 38 39// Returns true if c is emoji. 40bool isEmoji(uint32_t c); 41 42// Returns true if c is emoji modifier base. 43bool isEmojiBase(uint32_t c); 44 45// Returns true if c is emoji modifier. 46bool isEmojiModifier(uint32_t c); 47 48hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag); 49 50// An RAII wrapper for hb_blob_t 51class HbBlob { 52public: 53 // Takes ownership of hb_blob_t object, caller is no longer 54 // responsible for calling hb_blob_destroy(). 55 HbBlob(hb_blob_t* blob) : mBlob(blob) { 56 } 57 58 ~HbBlob() { 59 hb_blob_destroy(mBlob); 60 } 61 62 const uint8_t* get() const { 63 const char* data = hb_blob_get_data(mBlob, nullptr); 64 return reinterpret_cast<const uint8_t*>(data); 65 } 66 67 size_t size() const { 68 unsigned int length = 0; 69 hb_blob_get_data(mBlob, &length); 70 return (size_t)length; 71 } 72 73private: 74 hb_blob_t* mBlob; 75}; 76 77} 78 79#endif // MINIKIN_INTERNAL_H 80