1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2022 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_FONT_HEADER_H 17a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_FONT_HEADER_H 18a3e0fd82Sopenharmony_ci 19a3e0fd82Sopenharmony_ci#include <string> 20a3e0fd82Sopenharmony_ci#include "graphic_config.h" 21a3e0fd82Sopenharmony_ci#include "gfx_utils/common_macros.h" 22a3e0fd82Sopenharmony_cinamespace OHOS { 23a3e0fd82Sopenharmony_ci#pragma pack(1) 24a3e0fd82Sopenharmony_ci#define BIT_TO_BYTE(x) (((x) + 0x7) >> 3) 25a3e0fd82Sopenharmony_ci 26a3e0fd82Sopenharmony_cienum UITextWildcardStaticType : uint8_t { TEXT_STATIC_STR1 = 0, TEXT_STATIC_STR2, TEXT_STATIC_STR3 }; 27a3e0fd82Sopenharmony_ci 28a3e0fd82Sopenharmony_cistruct UITextLanguageTextParam { 29a3e0fd82Sopenharmony_ci uint16_t textId; 30a3e0fd82Sopenharmony_ci uint16_t fontId; 31a3e0fd82Sopenharmony_ci uint8_t align : 2; // UITextLanguageAlignment 32a3e0fd82Sopenharmony_ci uint8_t direct : 1; // UITextLanguageDirect 33a3e0fd82Sopenharmony_ci uint8_t shaping : 1; 34a3e0fd82Sopenharmony_ci uint8_t wildCard1 : 1; 35a3e0fd82Sopenharmony_ci uint8_t wildCard2 : 1; 36a3e0fd82Sopenharmony_ci uint8_t reserve : 2; 37a3e0fd82Sopenharmony_ci uint32_t strOff1; 38a3e0fd82Sopenharmony_ci uint16_t strLen1; 39a3e0fd82Sopenharmony_ci uint16_t strLen2; 40a3e0fd82Sopenharmony_ci uint16_t strLen3; 41a3e0fd82Sopenharmony_ci uint32_t codePointsOff; 42a3e0fd82Sopenharmony_ci uint16_t codePointsLen; 43a3e0fd82Sopenharmony_ci}; // UITextLanguageTextParam 44a3e0fd82Sopenharmony_ci 45a3e0fd82Sopenharmony_ci// bin header 46a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_VERSION_OFFSET = 0; 47a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_VERSION_LEN = 10; 48a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_MAGIC_NUM_OFFSET = FONT_VERSION_OFFSET + FONT_VERSION_LEN; 49a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_MAGIC_NUM_LEN = 6; 50a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_NUMBER_OFFSET = FONT_MAGIC_NUM_OFFSET + FONT_MAGIC_NUM_LEN; 51a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_NUMBER_LEN = 2; 52a3e0fd82Sopenharmony_ciconstexpr uint8_t BIN_HEAD_RES_OFFSET = FONT_NUMBER_OFFSET + FONT_NUMBER_LEN; 53a3e0fd82Sopenharmony_ciconstexpr uint8_t BIN_HEAD_RES_LEN = 2; 54a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_DATA_OFFSET = BIN_HEAD_RES_OFFSET + BIN_HEAD_RES_LEN; 55a3e0fd82Sopenharmony_ciconstexpr uint8_t BIN_HEAD_TOTAL_LEN = FONT_VERSION_LEN + FONT_MAGIC_NUM_LEN + FONT_NUMBER_LEN + BIN_HEAD_RES_LEN; 56a3e0fd82Sopenharmony_ci 57a3e0fd82Sopenharmony_ci// font header 58a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_ID_OFFSET = 0; 59a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_ID_LEN = 1; 60a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_NUM_OFFSET = FONT_ID_OFFSET + FONT_ID_LEN; 61a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_NUM_LEN = 2; 62a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_HEIGHT_OFFSET = GLYPH_NUM_OFFSET + GLYPH_NUM_LEN; 63a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_HEIGHT_LEN = 2; 64a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_ASCEND_OFFSET = FONT_HEIGHT_OFFSET + FONT_HEIGHT_LEN; 65a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_ASCEND_LEN = 2; 66a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_DESCEND_OFFSET = FONT_ASCEND_OFFSET + FONT_ASCEND_LEN; 67a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_DESCEND_LEN = 2; 68a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_INDEX_OFF_OFFSET = FONT_DESCEND_OFFSET + FONT_DESCEND_LEN; 69a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_INDEX_OFF_LEN = 4; 70a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_INDEX_LEN_OFFSET = FONT_INDEX_OFF_OFFSET + FONT_INDEX_OFF_LEN; 71a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_INDEX_LEN_LEN = 4; 72a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_OFF_OFFSET = FONT_INDEX_LEN_OFFSET + FONT_INDEX_LEN_LEN; 73a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_OFF_LEN = 4; 74a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_LEN_OFFSET = GLYPH_OFF_OFFSET + GLYPH_OFF_LEN; 75a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_LEN_LEN = 4; 76a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_HEAD_RES_OFFSET = GLYPH_LEN_OFFSET + GLYPH_LEN_LEN; 77a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_HEAD_RES_LEN = 2; 78a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_HEAD_TOTAL_LEN = FONT_ID_LEN + GLYPH_NUM_LEN + FONT_HEIGHT_LEN + FONT_ASCEND_LEN + 79a3e0fd82Sopenharmony_ci FONT_DESCEND_LEN + GLYPH_OFF_LEN + GLYPH_LEN_LEN + FONT_HEAD_RES_LEN; 80a3e0fd82Sopenharmony_ci 81a3e0fd82Sopenharmony_ci// glyph header, internal using, not write to bin file 82a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_G_HEIGHT_OFFSET = 0; 83a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_G_HEIGHT_LEN = 2; 84a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_NUM_OFFSET = FONT_G_HEIGHT_OFFSET + FONT_G_HEIGHT_LEN; 85a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_NUM_LEN = 2; 86a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_ASCEND_OFFSET = GLYPH_G_NUM_OFFSET + GLYPH_G_NUM_LEN; 87a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_ASCEND_LEN = 2; 88a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_DESCEND_OFFSET = GLYPH_G_ASCEND_OFFSET + GLYPH_G_ASCEND_LEN; 89a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_DESCEND_LEN = 2; 90a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_INDEX_OFF_OFFSET = GLYPH_G_DESCEND_OFFSET + GLYPH_G_DESCEND_LEN; 91a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_INDEX_OFF_LEN = 4; 92a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_INDEX_LEN_OFFSET = GLYPH_G_INDEX_OFF_OFFSET + GLYPH_G_INDEX_OFF_LEN; 93a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_INDEX_LEN_LEN = 4; 94a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_OFF_OFFSET = GLYPH_G_INDEX_LEN_OFFSET + GLYPH_G_INDEX_LEN_LEN; 95a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_OFF_LEN = 4; 96a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_LEN_OFFSET = GLYPH_G_OFF_OFFSET + GLYPH_G_OFF_LEN; 97a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_G_LEN_LEN = 4; 98a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_G_HEAD_TOTAL_LEN = 99a3e0fd82Sopenharmony_ci FONT_G_HEIGHT_LEN + GLYPH_G_NUM_LEN + GLYPH_G_ASCEND_LEN + GLYPH_G_DESCEND_LEN + GLYPH_G_OFF_LEN + GLYPH_G_LEN_LEN; 100a3e0fd82Sopenharmony_ci 101a3e0fd82Sopenharmony_ci// glyph node 102a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_UNICODE_OFFSET = GLYPH_G_NUM_OFFSET + GLYPH_G_NUM_LEN; 103a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_UNICODE_LEN = 4; 104a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_LEFT_OFFSET = GLYPH_UNICODE_OFFSET + GLYPH_UNICODE_LEN; 105a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_LEFT_LEN = 2; 106a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_TOP_OFFSET = GLYPH_LEFT_OFFSET + GLYPH_LEFT_LEN; 107a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_TOP_LEN = 2; 108a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_ADVANCE_OFFSET = GLYPH_TOP_OFFSET + GLYPH_TOP_LEN; 109a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_ADVANCE_LEN = 2; 110a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_COLS_OFFSET = GLYPH_ADVANCE_OFFSET + GLYPH_ADVANCE_LEN; 111a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_COLS_LEN = 2; 112a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_ROWS_OFFSET = GLYPH_COLS_OFFSET + GLYPH_COLS_LEN; 113a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_ROWS_LEN = 2; 114a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_DATA_OFF_OFFSET = GLYPH_ROWS_OFFSET + GLYPH_ROWS_LEN; 115a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_DATA_OFF_LEN = 4; 116a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_KERN_OFF_OFFSET = GLYPH_DATA_OFF_OFFSET + GLYPH_DATA_OFF_LEN; 117a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_KERN_OFF_LEN = 4; 118a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_KERN_SIZE_OFFSET = GLYPH_KERN_OFF_OFFSET + GLYPH_KERN_OFF_LEN; 119a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_KERN_SIZE_LEN = 2; 120a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_HEAD_RES_OFFSET = GLYPH_KERN_SIZE_OFFSET + GLYPH_KERN_SIZE_LEN; 121a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_HEAD_RES_LEN = 2; 122a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_HEAD_TOTAL_LEN = GLYPH_UNICODE_LEN + GLYPH_LEFT_LEN + GLYPH_TOP_LEN + GLYPH_ADVANCE_LEN + 123a3e0fd82Sopenharmony_ci GLYPH_COLS_LEN + GLYPH_ROWS_LEN + GLYPH_DATA_OFF_LEN + GLYPH_KERN_OFF_LEN + 124a3e0fd82Sopenharmony_ci GLYPH_KERN_SIZE_LEN + GLYPH_HEAD_RES_LEN; 125a3e0fd82Sopenharmony_ci 126a3e0fd82Sopenharmony_ci// language texts table header 127a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_PARAM_OFF = 0; 128a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_PARAM_LEN = 4; 129a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_UTF8P_OFF = LANG_TEXTS_PARAM_OFF + LANG_TEXTS_PARAM_LEN; 130a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_UTF8P_LEN = 4; 131a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_UTF8_OFF = LANG_TEXTS_UTF8P_OFF + LANG_TEXTS_UTF8P_LEN; 132a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_UTF8_LEN = 4; 133a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_TEXTS_TOTAL_LEN = LANG_TEXTS_PARAM_LEN + LANG_TEXTS_UTF8P_LEN + LANG_TEXTS_UTF8_LEN; 134a3e0fd82Sopenharmony_ci 135a3e0fd82Sopenharmony_ci// language texts utf-8 param header 136a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_UTF8_PARAM_TOTAL_LEN = 8; // 4B offset + 4B len 137a3e0fd82Sopenharmony_ci 138a3e0fd82Sopenharmony_ci// language bin header 139a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_OFFSET_OFF = 0; 140a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_OFFSET_LEN = 4; 141a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_SIZE_OFF = LANG_OFFSET_OFF + LANG_OFFSET_LEN; 142a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_SIZE_LEN = 4; 143a3e0fd82Sopenharmony_ciconstexpr uint8_t LANG_HEAD_TOTAL_LEN = LANG_OFFSET_LEN + LANG_SIZE_LEN; 144a3e0fd82Sopenharmony_ci 145a3e0fd82Sopenharmony_ci// dynamic font 146a3e0fd82Sopenharmony_ciconstexpr uint32_t GLYPH_HEADER_LENGTH = 0xD7C00; // 860 K, almost 33870 glyph header 147a3e0fd82Sopenharmony_ciconstexpr uint32_t FONT_HEADER_LENGTH = FONT_HEAD_TOTAL_LEN * 150; // 150 font, almost 3K 148a3e0fd82Sopenharmony_ciconstexpr uint32_t DYNAMIC_FONT_HEADER_TOTAL_LENGTH = GLYPH_HEADER_LENGTH + FONT_HEADER_LENGTH; 149a3e0fd82Sopenharmony_ci 150a3e0fd82Sopenharmony_ci// static font psram 151a3e0fd82Sopenharmony_ciconstexpr uint32_t UTF8_PARAM_LENGTH = LANG_UTF8_PARAM_TOTAL_LEN * 100; // 100 lang, almost 1K 152a3e0fd82Sopenharmony_ciconstexpr uint32_t STATIC_PARAM_LENGTH = sizeof(UITextLanguageTextParam) * 3218; // 3218 texts, 44K 153a3e0fd82Sopenharmony_ciconstexpr uint32_t STATIC_UTF8_LENGTH = 0xC800; // 50 * 1024 = 50K 154a3e0fd82Sopenharmony_ciconstexpr uint32_t STATIC_FONT_HEADER_LENGTH = FONT_HEAD_TOTAL_LEN * 150; // 150 font, almost 3K 155a3e0fd82Sopenharmony_ciconstexpr uint32_t STATIC_GLYPH_HEADER_LENGTH = 0x15C00; // 87K, almost 26 * 3426 glyph header 156a3e0fd82Sopenharmony_ciconstexpr uint32_t STATIC_FONT_HEADER_TOTAL_LENGTH = UTF8_PARAM_LENGTH + STATIC_PARAM_LENGTH + STATIC_UTF8_LENGTH + 157a3e0fd82Sopenharmony_ci STATIC_FONT_HEADER_LENGTH + STATIC_GLYPH_HEADER_LENGTH; 158a3e0fd82Sopenharmony_ci 159a3e0fd82Sopenharmony_ciconstexpr uint8_t MAX_CACHE_CHAR_NUMBER = 50; // cache 50 letters 160a3e0fd82Sopenharmony_ciconstexpr uint32_t DYNAMIC_ONE_CHAR_LENGTH = 0x5000; // 20 K means w200:h200:bpp4, 200 x 200 / 2 161a3e0fd82Sopenharmony_ci 162a3e0fd82Sopenharmony_ci// 50 * 20K = 1000K 163a3e0fd82Sopenharmony_ciconstexpr uint32_t DYNAMIC_TEXT_CACHE_LENGTH = MAX_CACHE_CHAR_NUMBER * DYNAMIC_ONE_CHAR_LENGTH; 164a3e0fd82Sopenharmony_ciconstexpr uint32_t MIN_FONT_PSRAM_LENGTH = 0x380000; 165a3e0fd82Sopenharmony_ci 166a3e0fd82Sopenharmony_ci// text shaping psram 167a3e0fd82Sopenharmony_ciconstexpr uint32_t SHAPING_TTF_TABLE_LENGTH = 0x4B000; // 307K 168a3e0fd82Sopenharmony_ciconstexpr uint32_t SHAPING_WORD_DICT_LENGTH = 0xD000; // 53K 169a3e0fd82Sopenharmony_ciconstexpr uint32_t SHAPING_CACHE_LENGTH = 0x50000; // 328K 170a3e0fd82Sopenharmony_ciconstexpr uint32_t MIN_SHAPING_PSRAM_LENGTH = 171a3e0fd82Sopenharmony_ci SHAPING_TTF_TABLE_LENGTH + SHAPING_WORD_DICT_LENGTH + SHAPING_CACHE_LENGTH + HARFBUZ_CACHE_LENGTH; 172a3e0fd82Sopenharmony_ci 173a3e0fd82Sopenharmony_ci// other definition 174a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_DPI = 100; 175a3e0fd82Sopenharmony_ciconstexpr uint8_t FONT_PIXEL_IN_POINT = 64; 176a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_1 = 1; 177a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_1 = 7; 178a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_SHIFT_1 = 3; 179a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_NUM_1 = 0x80; 180a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_2 = 2; 181a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_2 = 3; 182a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_SHIFT_2 = 2; 183a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_NUM_2 = 0xC0; 184a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_4 = 4; 185a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_4 = 1; 186a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_SHIFT_4 = 1; 187a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_MASK_NUM_4 = 0xF0; 188a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_8 = 8; 189a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_16 = 16; 190a3e0fd82Sopenharmony_ciconstexpr uint8_t BPP_BIT_32 = 32; 191a3e0fd82Sopenharmony_ciconstexpr uint32_t DEFAULT_FONT_SIZE = 10; 192a3e0fd82Sopenharmony_ciconstexpr uint32_t MAX_CHAR_MB_LEN = 16; 193a3e0fd82Sopenharmony_ciconstexpr uint32_t MAX_CHAR_NUM = 512; 194a3e0fd82Sopenharmony_ciconstexpr uint8_t BITS_PER_BYTE = 8; 195a3e0fd82Sopenharmony_ciconstexpr uint8_t BITS_MASK_IN_BYTE = 7; 196a3e0fd82Sopenharmony_ciconstexpr uint32_t MAX_MONO_ADVANCE = 128; 197a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT0 = 0; 198a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT1 = 1; 199a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT2 = 2; 200a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT3 = 3; 201a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT4 = 4; 202a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT5 = 5; 203a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT6 = 6; 204a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT7 = 7; 205a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT8 = 8; 206a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT12 = 12; 207a3e0fd82Sopenharmony_ciconstexpr uint8_t BIT18 = 18; 208a3e0fd82Sopenharmony_ciconstexpr uint8_t GLYPH_KERN_ITEM_LEN = 2; 209a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK1 = 0x80; 210a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK2 = 0xC0; 211a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK3 = 0xE0; 212a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK4 = 0xF0; 213a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK5 = 0xF8; 214a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK6 = 0x3F; 215a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK7 = 0x1F; 216a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK8 = 0x07; 217a3e0fd82Sopenharmony_ciconstexpr uint8_t UTF_TO_UNICODE_MASK9 = 0x0F; 218a3e0fd82Sopenharmony_ciconstexpr uint8_t MAX_FILE_NAME_LEN = 255; 219a3e0fd82Sopenharmony_ciconstexpr uint8_t GPU_FONT_ALIGN_BIT = 16; 220a3e0fd82Sopenharmony_ciconstexpr uint8_t INVALID_UCHAR_ID = 0xFF; 221a3e0fd82Sopenharmony_ciconstexpr uint16_t INVALID_USHORT_ID = 0xFFFF; 222a3e0fd82Sopenharmony_ciconstexpr uint32_t INVALID_UINT_ID = 0xFFFFFFFF; 223a3e0fd82Sopenharmony_ciconstexpr int8_t INVALID_RET_VALUE = -1; 224a3e0fd82Sopenharmony_ciconstexpr int8_t RET_VALUE_OK = 0; 225a3e0fd82Sopenharmony_ciconstexpr const char* FONT_MAGIC_NUMBER = const_cast<char *>("OHOS."); 226a3e0fd82Sopenharmony_ci 227a3e0fd82Sopenharmony_ci/** 228a3e0fd82Sopenharmony_ci * @brief struct BinHeader for font 229a3e0fd82Sopenharmony_ci * refer to ui_font.h 230a3e0fd82Sopenharmony_ci */ 231a3e0fd82Sopenharmony_cistruct BinHeader { 232a3e0fd82Sopenharmony_ci char fontVersion[FONT_VERSION_LEN]; // FONT_VERSION_OFFSET 233a3e0fd82Sopenharmony_ci char fontMagic[FONT_MAGIC_NUM_LEN]; // FONT_MAGIC_NUM_OFFSET 234a3e0fd82Sopenharmony_ci uint16_t fontNum; // FONT_NUMBER_OFFSET 235a3e0fd82Sopenharmony_ci uint16_t reserve; // BIN_HEAD_RES_OFFSET 236a3e0fd82Sopenharmony_ci}; 237a3e0fd82Sopenharmony_ci 238a3e0fd82Sopenharmony_ci/** 239a3e0fd82Sopenharmony_ci * @brief struct FontHeader 240a3e0fd82Sopenharmony_ci * refer to ui_font.h 241a3e0fd82Sopenharmony_ci */ 242a3e0fd82Sopenharmony_cistruct FontHeader { 243a3e0fd82Sopenharmony_ci uint16_t fontId; // FONT_ID_OFFSET 244a3e0fd82Sopenharmony_ci uint16_t glyphNum; // GLYPH_NUM_OFFSET 245a3e0fd82Sopenharmony_ci uint16_t fontHeight; // FONT_HEIGHT_OFFSET 246a3e0fd82Sopenharmony_ci int16_t ascender; // FONT_ASCEND_LEN 247a3e0fd82Sopenharmony_ci int16_t descender; // FONT_DESCEND_LEN 248a3e0fd82Sopenharmony_ci uint32_t indexOffset; 249a3e0fd82Sopenharmony_ci uint32_t indexLen; 250a3e0fd82Sopenharmony_ci uint32_t glyphOffset; // GLYPH_G_OFF_OFFSET 251a3e0fd82Sopenharmony_ci uint32_t glyphLen; // GLYPH_OFF_OFFSET 252a3e0fd82Sopenharmony_ci uint16_t reserve; // GLYPH_LEN_OFFSET 253a3e0fd82Sopenharmony_ci}; 254a3e0fd82Sopenharmony_ci 255a3e0fd82Sopenharmony_ci/** 256a3e0fd82Sopenharmony_ci * @brief struct GlyphHeader for font, font tool using, not for bin file 257a3e0fd82Sopenharmony_ci * refer to ui_font.h 258a3e0fd82Sopenharmony_ci */ 259a3e0fd82Sopenharmony_cistruct GlyphHeader { 260a3e0fd82Sopenharmony_ci uint16_t fontHeight; // FONT_G_HEIGHT_OFFSET 261a3e0fd82Sopenharmony_ci uint16_t glyphNum; // GLYPH_G_NUM_OFFSET 262a3e0fd82Sopenharmony_ci int16_t ascender; // GLYPH_G_ASCEND_LEN 263a3e0fd82Sopenharmony_ci int16_t descender; // GLYPH_G_DESCEND_LEN 264a3e0fd82Sopenharmony_ci uint32_t indexOffset; 265a3e0fd82Sopenharmony_ci uint32_t indexLen; 266a3e0fd82Sopenharmony_ci uint32_t glyphOffset; // GLYPH_G_OFF_OFFSET 267a3e0fd82Sopenharmony_ci uint32_t glyphLen; // GLYPH_G_LEN_OFFSET 268a3e0fd82Sopenharmony_ci}; 269a3e0fd82Sopenharmony_ci 270a3e0fd82Sopenharmony_cienum TextStyle : uint8_t { 271a3e0fd82Sopenharmony_ci TEXT_STYLE_NORMAL = 0, // default value 272a3e0fd82Sopenharmony_ci TEXT_STYLE_ITALIC, // text style italic 273a3e0fd82Sopenharmony_ci TEXT_STYLE_BOLD, // text style bold 274a3e0fd82Sopenharmony_ci TEXT_STYLE_BOLD_ITALIC // text style bold and italic 275a3e0fd82Sopenharmony_ci}; 276a3e0fd82Sopenharmony_ci 277a3e0fd82Sopenharmony_ci/** 278a3e0fd82Sopenharmony_ci * @brief struct GlyphNode for font 279a3e0fd82Sopenharmony_ci * refer to ui_font.h 280a3e0fd82Sopenharmony_ci * be careful about glyphNode struct's size, if ENABLE_TEXT_STYLE changes, glyphs.bin shall be reconstruct. 281a3e0fd82Sopenharmony_ci */ 282a3e0fd82Sopenharmony_cistruct GlyphNode { 283a3e0fd82Sopenharmony_ci uint32_t unicode; // GLYPH_UNICODE_OFFSET 284a3e0fd82Sopenharmony_ci int16_t left; // GLYPH_LEFT_OFFSET 285a3e0fd82Sopenharmony_ci int16_t top; // GLYPH_TOP_OFFSET 286a3e0fd82Sopenharmony_ci uint16_t advance; // GLYPH_ADVANCE_OFFSET 287a3e0fd82Sopenharmony_ci uint16_t cols; // GLYPH_COLS_OFFSET 288a3e0fd82Sopenharmony_ci uint16_t rows; // GLYPH_ROWS_OFFSET 289a3e0fd82Sopenharmony_ci uint32_t dataOff; // GLYPH_DATA_OFF_OFFSET 290a3e0fd82Sopenharmony_ci uint32_t kernOff; // GLYPH_KERN_OFF_OFFSET 291a3e0fd82Sopenharmony_ci uint16_t kernSize; // GLYPH_KERN_SIZE_OFFSET 292a3e0fd82Sopenharmony_ci uint16_t fontId; // GLYPH_FONT_ID 293a3e0fd82Sopenharmony_ci uint16_t dataFlag; // GLYPH_DATA_HEAD_FLAG 294a3e0fd82Sopenharmony_ci#if defined(ENABLE_TEXT_STYLE) && ENABLE_TEXT_STYLE 295a3e0fd82Sopenharmony_ci TextStyle textStyle; // GLYPH_TEXT_STYLE 296a3e0fd82Sopenharmony_ci#endif 297a3e0fd82Sopenharmony_ci}; 298a3e0fd82Sopenharmony_ci 299a3e0fd82Sopenharmony_ci/** 300a3e0fd82Sopenharmony_ci * @brief struct GlyphCacheNode for font 301a3e0fd82Sopenharmony_ci * refer to ui_font.h 302a3e0fd82Sopenharmony_ci */ 303a3e0fd82Sopenharmony_cistruct GlyphCacheNode { 304a3e0fd82Sopenharmony_ci GlyphNode node; 305a3e0fd82Sopenharmony_ci uint16_t cacheType; 306a3e0fd82Sopenharmony_ci}; 307a3e0fd82Sopenharmony_ci 308a3e0fd82Sopenharmony_cienum GlyphCacheType : uint16_t { 309a3e0fd82Sopenharmony_ci CACHE_TYPE_NONE = 0, // default value 310a3e0fd82Sopenharmony_ci CACHE_TYPE_STATIC, // static font 311a3e0fd82Sopenharmony_ci CACHE_TYPE_DYNAMIC, // dynamic font 312a3e0fd82Sopenharmony_ci}; 313a3e0fd82Sopenharmony_ci 314a3e0fd82Sopenharmony_ci/** 315a3e0fd82Sopenharmony_ci * @brief struct LangBinHeader for font 316a3e0fd82Sopenharmony_ci * refer to ui_font.h 317a3e0fd82Sopenharmony_ci */ 318a3e0fd82Sopenharmony_cistruct LangBinHeader { 319a3e0fd82Sopenharmony_ci char fontVersion[FONT_VERSION_LEN]; // FONT_VERSION_OFFSET 320a3e0fd82Sopenharmony_ci char fontMagic[FONT_MAGIC_NUM_LEN]; // FONT_MAGIC_NUM_OFFSET 321a3e0fd82Sopenharmony_ci}; 322a3e0fd82Sopenharmony_ci 323a3e0fd82Sopenharmony_ci/** 324a3e0fd82Sopenharmony_ci * @brief struct LangFontBinHeader for font 325a3e0fd82Sopenharmony_ci * refer to ui_font.h 326a3e0fd82Sopenharmony_ci */ 327a3e0fd82Sopenharmony_cistruct LangFontBinHeader { 328a3e0fd82Sopenharmony_ci uint32_t offset; // LANG_OFFSET_LEN 329a3e0fd82Sopenharmony_ci uint32_t size; // LANG_SIZE_LEN 330a3e0fd82Sopenharmony_ci}; 331a3e0fd82Sopenharmony_ci 332a3e0fd82Sopenharmony_ci/** 333a3e0fd82Sopenharmony_ci * @brief struct LangTexsTableHeader for font 334a3e0fd82Sopenharmony_ci * refer to ui_font.h 335a3e0fd82Sopenharmony_ci */ 336a3e0fd82Sopenharmony_cistruct LangTexsTableHeader { 337a3e0fd82Sopenharmony_ci uint32_t textParamStart; 338a3e0fd82Sopenharmony_ci uint32_t textParamLen; // LANG_TEXTS_PARAM_LEN 339a3e0fd82Sopenharmony_ci uint32_t textUtf8ParamStart; 340a3e0fd82Sopenharmony_ci uint32_t textUtf8ParamLen; // LANG_TEXTS_UTF8P_LEN 341a3e0fd82Sopenharmony_ci uint32_t textUtf8Start; 342a3e0fd82Sopenharmony_ci uint32_t textUtf8Len; // LANG_TEXTS_UTF8_LEN 343a3e0fd82Sopenharmony_ci uint32_t textUtf8MaxItemLen; 344a3e0fd82Sopenharmony_ci uint32_t textCodepointsStart; 345a3e0fd82Sopenharmony_ci uint32_t textCodepointsMaxItemLen; 346a3e0fd82Sopenharmony_ci uint32_t textCodepointsTotalLen; 347a3e0fd82Sopenharmony_ci}; 348a3e0fd82Sopenharmony_ci 349a3e0fd82Sopenharmony_ci/** 350a3e0fd82Sopenharmony_ci * @brief struct LangTexsUtf8Param for font 351a3e0fd82Sopenharmony_ci * refer to ui_font.h 352a3e0fd82Sopenharmony_ci */ 353a3e0fd82Sopenharmony_cistruct LangTexsUtf8Param { 354a3e0fd82Sopenharmony_ci uint32_t offset; 355a3e0fd82Sopenharmony_ci uint32_t len; 356a3e0fd82Sopenharmony_ci uint32_t codePointOffset; 357a3e0fd82Sopenharmony_ci uint32_t codePointLen; 358a3e0fd82Sopenharmony_ci}; 359a3e0fd82Sopenharmony_ci 360a3e0fd82Sopenharmony_ci/** 361a3e0fd82Sopenharmony_ci * @brief struct KernNode for kerning of font 362a3e0fd82Sopenharmony_ci * refer to ui_font.h 363a3e0fd82Sopenharmony_ci */ 364a3e0fd82Sopenharmony_cistruct KernNode { 365a3e0fd82Sopenharmony_ci uint32_t unicode; // GLYPH_UNICODE_LEN 366a3e0fd82Sopenharmony_ci int16_t kernValue; // GLYPH_KERN_SIZE_LEN 367a3e0fd82Sopenharmony_ci uint8_t found; // found the kerning or not 368a3e0fd82Sopenharmony_ci}; 369a3e0fd82Sopenharmony_ci 370a3e0fd82Sopenharmony_ci/** 371a3e0fd82Sopenharmony_ci * @brief struct TtfHeader for header of ttftab.bin 372a3e0fd82Sopenharmony_ci * refer to ui_font.h 373a3e0fd82Sopenharmony_ci */ 374a3e0fd82Sopenharmony_cistruct TtfHeader { 375a3e0fd82Sopenharmony_ci uint8_t ttfId; 376a3e0fd82Sopenharmony_ci uint32_t offset; 377a3e0fd82Sopenharmony_ci uint32_t len; 378a3e0fd82Sopenharmony_ci}; 379a3e0fd82Sopenharmony_ci 380a3e0fd82Sopenharmony_cistruct UITextLanguageFontParam { 381a3e0fd82Sopenharmony_ci uint8_t size; // Invalid value for vector font 382a3e0fd82Sopenharmony_ci uint8_t fontWeight; 383a3e0fd82Sopenharmony_ci uint8_t shaping; 384a3e0fd82Sopenharmony_ci uint8_t ttfId; // auto create during registration for vector font 385a3e0fd82Sopenharmony_ci const char* ttfName; 386a3e0fd82Sopenharmony_ci uint8_t ttfIndex; 387a3e0fd82Sopenharmony_ci uint8_t ttcIndex; 388a3e0fd82Sopenharmony_ci}; // UITextLanguageFontParam 389a3e0fd82Sopenharmony_ci 390a3e0fd82Sopenharmony_cistruct TextIsoHeader { 391a3e0fd82Sopenharmony_ci uint16_t paramLen; 392a3e0fd82Sopenharmony_ci uint16_t strLen; 393a3e0fd82Sopenharmony_ci}; 394a3e0fd82Sopenharmony_ci 395a3e0fd82Sopenharmony_cistruct TextIsoParam { 396a3e0fd82Sopenharmony_ci uint16_t offset; 397a3e0fd82Sopenharmony_ci uint16_t len; 398a3e0fd82Sopenharmony_ci}; 399a3e0fd82Sopenharmony_ci 400a3e0fd82Sopenharmony_cistruct LangTextParam { 401a3e0fd82Sopenharmony_ci uint8_t fontDirect; // refer to UITextLanguageDirect 402a3e0fd82Sopenharmony_ci uint8_t fontSize; 403a3e0fd82Sopenharmony_ci const char* familyName; // such as "Roboto-Medium" 404a3e0fd82Sopenharmony_ci const char* langName; // such as "ar", "zh" 405a3e0fd82Sopenharmony_ci}; 406a3e0fd82Sopenharmony_ci 407a3e0fd82Sopenharmony_cistruct FileCommonHeader { 408a3e0fd82Sopenharmony_ci const char magicWord[5]; // 5:file identifier's length is 5 409a3e0fd82Sopenharmony_ci uint32_t fileLength; 410a3e0fd82Sopenharmony_ci}; 411a3e0fd82Sopenharmony_ci 412a3e0fd82Sopenharmony_cistruct TtfInfo { 413a3e0fd82Sopenharmony_ci const char* ttfName; 414a3e0fd82Sopenharmony_ci uint8_t shaping; 415a3e0fd82Sopenharmony_ci}; 416a3e0fd82Sopenharmony_ci 417a3e0fd82Sopenharmony_cistruct UI_STRUCT_ALIGN Metric { 418a3e0fd82Sopenharmony_ci int left; 419a3e0fd82Sopenharmony_ci int top; 420a3e0fd82Sopenharmony_ci int cols; 421a3e0fd82Sopenharmony_ci int rows; 422a3e0fd82Sopenharmony_ci int advance; 423a3e0fd82Sopenharmony_ci uint8_t buf[0]; 424a3e0fd82Sopenharmony_ci}; 425a3e0fd82Sopenharmony_ci 426a3e0fd82Sopenharmony_ci#pragma pack() 427a3e0fd82Sopenharmony_ci} // namespace OHOS 428a3e0fd82Sopenharmony_ci#endif /* UI_FONT_HEADER_H */ 429