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 #include <utils/Log.h> 24 #include <utils/Mutex.h> 25 26 #include "minikin/HbUtils.h" 27 #include "minikin/MinikinFont.h" 28 29 namespace minikin { 30 31 #ifdef ENABLE_ASSERTION 32 #define MINIKIN_ASSERT(cond, ...) LOG_ALWAYS_FATAL_IF(!(cond), __VA_ARGS__) 33 #else 34 #define MINIKIN_ASSERT(cond, ...) ((void)0) 35 #endif 36 37 #define MINIKIN_NOT_REACHED(...) MINIKIN_ASSERT(false, __VA_ARGS__); 38 39 constexpr uint32_t MAX_UNICODE_CODE_POINT = 0x10FFFF; 40 41 constexpr uint32_t VS1 = 0xFE00; 42 constexpr uint32_t VS16 = 0xFE0F; 43 constexpr uint32_t VS17 = 0xE0100; 44 constexpr uint32_t VS256 = 0xE01EF; 45 46 // Returns variation selector index. This is one unit less than the variation selector number. For 47 // example, VARIATION SELECTOR-25 maps to 24. 48 // [0x00-0x0F] for U+FE00..U+FE0F 49 // [0x10-0xFF] for U+E0100..U+E01EF 50 // INVALID_VS_INDEX for other input. 51 constexpr uint16_t INVALID_VS_INDEX = 0xFFFF; 52 uint16_t getVsIndex(uint32_t codePoint); 53 54 // Returns true if the code point is a variation selector. 55 // Note that this function returns false for Mongolian free variation selectors. 56 bool isVariationSelector(uint32_t codePoint); 57 58 // An RAII accessor for hb_blob_t 59 class HbBlob { 60 public: 61 HbBlob(const HbFaceUniquePtr& face, uint32_t tag) 62 : mBlob(hb_face_reference_table(face.get(), tag)) {} 63 HbBlob(const HbFontUniquePtr& font, uint32_t tag) 64 : mBlob(hb_face_reference_table(hb_font_get_face(font.get()), tag)) {} 65 66 inline const uint8_t* get() const { 67 return reinterpret_cast<const uint8_t*>(hb_blob_get_data(mBlob.get(), nullptr)); 68 } 69 70 inline size_t size() const { return (size_t)hb_blob_get_length(mBlob.get()); } 71 72 inline operator bool() const { return size() > 0; } 73 74 private: 75 HbBlobUniquePtr mBlob; 76 }; 77 78 } // namespace minikin 79 80 #endif // MINIKIN_INTERNAL_H 81