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_TEXGINE_DRAWING_TEXGINE_TYPEFACE_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TYPEFACE_H 18 19 #include <memory> 20 21 #include <include/core/SkTypeface.h> 22 23 #include "texgine_font_style.h" 24 #include "texgine_stream.h" 25 #include "texgine_string.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 namespace TextEngine { 30 class TexgineTypeface { 31 public: 32 TexgineTypeface(); 33 explicit TexgineTypeface(SkTypeface *tf); 34 explicit TexgineTypeface(sk_sp<SkTypeface> typeface); 35 explicit TexgineTypeface(void *context); 36 sk_sp<SkTypeface> GetTypeface() const; 37 /* 38 * @brief Return the table contents that accroding table tag 39 * @param tag The table tag 40 */ 41 size_t GetTableSize(uint32_t tag) const; 42 43 /* 44 * @brief Copy the contents of a table into data 45 * @param tag The table tag whose contents are to be copied 46 * @param offset The offset (in bytes) of the table content, from which the copy should start 47 * @param length The number of bytes of table data to be copied, starting from offset 48 * @param data The table data copied to this address 49 * @return the number of bytes actually copied into data 50 */ 51 size_t GetTableData(uint32_t tag, size_t offset, size_t length, void *data) const; 52 53 /* 54 * @brief Returns the unit/em value of this font, and returns zero if there are errors 55 */ 56 int GetUnitsPerEm() const; 57 58 /* 59 * @brief Return the family name of this typeface 60 */ 61 void GetFamilyName(TexgineString *name) const; 62 63 /* 64 * @brief Return the typeface`s font style 65 */ 66 std::shared_ptr<TexgineFontStyle> GetFontStyle() const; 67 68 /* 69 * @brief Create a typeface accroding to the stream 70 */ 71 static std::shared_ptr<TexgineTypeface> MakeFromStream(std::unique_ptr<TexgineMemoryStream> stream, int index = 0); 72 73 /* 74 * @brief Create a typeface with the file 75 * @path The typeface file path 76 * @index The ttc index, default is 0 77 */ 78 static std::shared_ptr<TexgineTypeface> MakeFromFile(const std::string &path, int index = 0); 79 80 private: 81 sk_sp<SkTypeface> typeface_ = nullptr; 82 }; 83 } // namespace TextEngine 84 } // namespace Rosen 85 } // namespace OHOS 86 87 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TYPEFACE_H 88