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 28 namespace minikin { 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 34 extern android::Mutex gMinikinLock; 35 36 // Aborts if gMinikinLock is not acquired. Do nothing on the release build. 37 void assertMinikinLocked(); 38 39 hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag); 40 41 constexpr uint32_t MAX_UNICODE_CODE_POINT = 0x10FFFF; 42 43 constexpr uint32_t VS1 = 0xFE00; 44 constexpr uint32_t VS16 = 0xFE0F; 45 constexpr uint32_t VS17 = 0xE0100; 46 constexpr uint32_t VS256 = 0xE01EF; 47 48 // Returns variation selector index. This is one unit less than the variation selector number. For 49 // example, VARIATION SELECTOR-25 maps to 24. 50 // [0x00-0x0F] for U+FE00..U+FE0F 51 // [0x10-0xFF] for U+E0100..U+E01EF 52 // INVALID_VS_INDEX for other input. 53 constexpr uint16_t INVALID_VS_INDEX = 0xFFFF; 54 uint16_t getVsIndex(uint32_t codePoint); 55 56 // Returns true if the code point is a variation selector. 57 // Note that this function returns false for Mongolian free variation selectors. 58 bool isVariationSelector(uint32_t codePoint); 59 60 // An RAII wrapper for hb_blob_t 61 class HbBlob { 62 public: 63 // Takes ownership of hb_blob_t object, caller is no longer 64 // responsible for calling hb_blob_destroy(). HbBlob(hb_blob_t * blob)65 explicit HbBlob(hb_blob_t* blob) : mBlob(blob) { 66 } 67 ~HbBlob()68 ~HbBlob() { 69 hb_blob_destroy(mBlob); 70 } 71 get()72 const uint8_t* get() const { 73 const char* data = hb_blob_get_data(mBlob, nullptr); 74 return reinterpret_cast<const uint8_t*>(data); 75 } 76 size()77 size_t size() const { 78 return (size_t)hb_blob_get_length(mBlob); 79 } 80 81 private: 82 hb_blob_t* mBlob; 83 }; 84 85 } // namespace minikin 86 87 #endif // MINIKIN_INTERNAL_H 88