1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ROSEN_MODULES_TEXGINE_SRC_FONT_PARSER_H 17 #define ROSEN_MODULES_TEXGINE_SRC_FONT_PARSER_H 18 19 #include <hb.h> 20 #include <string> 21 #include <vector> 22 #include <include/core/SkFontMgr.h> 23 #include <include/core/SkString.h> 24 25 #include "include/core/SkTypeface.h" 26 #include "opentype_parser/cmap_table_parser.h" 27 #include "opentype_parser/name_table_parser.h" 28 #include "opentype_parser/post_table_parser.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 namespace TextEngine { 33 class FontParser { 34 public: 35 enum class PlatformId { 36 UNITE_CODE = 0, 37 MACINTOSH = 1, 38 ISO = 2, 39 WINDOWS = 3, 40 CUSTOM = 4, 41 }; 42 43 enum class EncodingIdWin { 44 SYMBOL = 0, 45 UNICODE_BMP = 1, 46 }; 47 48 enum class Version { 49 SYMBOL = 0, 50 UNICODE_BMP = 1, 51 }; 52 53 enum class NameId { 54 COPYRIGHT = 0, 55 FONT_FAMILY = 1, 56 FONT_SUBFAMILY = 2, 57 UNIQUE_FONT_ID = 3, 58 FULL_NAME = 4, 59 VERSION_STRING = 5, 60 POSTSCRIPT_NAME = 6, 61 TRADEMARK = 7, 62 }; 63 64 struct FontDescriptor { 65 FontDescriptor(); 66 std::string path; 67 std::string postScriptName; 68 std::string fullName; 69 std::string fontFamily; 70 std::string fontSubfamily; 71 int weight; 72 int width; 73 int italic; 74 bool monoSpace; 75 bool symbolic; 76 }; 77 78 FontParser(); 79 std::vector<FontDescriptor> GetVisibilityFonts(); 80 81 private: 82 static void GetStringFromNameId(NameId nameId, const std::string& nameString, FontDescriptor& fontDescriptor); 83 static void ProcessCmapTable(const struct CmapTables* cmapTable, FontDescriptor& fontDescriptor); 84 int ProcessNameTable(const struct NameTable* nameTable, FontDescriptor& fontDescriptor) const; 85 static void ProcessPostTable(const struct PostTable* postTable, FontDescriptor& fontDescriptor); 86 int ParseCmapTable(sk_sp<SkTypeface> typeface, FontDescriptor& fontDescriptor); 87 int ParseNameTable(sk_sp<SkTypeface> typeface, FontDescriptor& fontDescriptor); 88 int ParsePostTable(sk_sp<SkTypeface> typeface, FontDescriptor& fontDescriptor); 89 int ParseTable(sk_sp<SkTypeface> typeface, FontDescriptor& fontDescriptor); 90 int SetFontDescriptor(); 91 92 const char* data_; 93 unsigned int length_; 94 std::vector<std::string> fontSet_; 95 std::vector<FontDescriptor> visibilityFonts_; 96 }; 97 } // namespace TextEngine 98 } // namespace Rosen 99 } // namespace OHOS 100 101 #endif // ROSEN_MODULES_TEXGINE_SRC_FONT_PARSER_H 102