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 "drawing.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(void *context); 34 std::shared_ptr<RSTypeface> GetTypeface() const; 35 explicit TexgineTypeface(std::shared_ptr<RSTypeface> typeface); 36 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 size_t FontStyleDetection(); 69 /* 70 * @brief Create a typeface accroding to the stream 71 */ 72 static std::shared_ptr<TexgineTypeface> MakeFromStream(std::unique_ptr<TexgineMemoryStream> stream, int index = 0); 73 74 /* 75 * @brief Create a typeface with the file 76 * @path The typeface file path 77 * @index The ttc index, default is 0 78 */ 79 static std::shared_ptr<TexgineTypeface> MakeFromFile(const std::string &path, int index = 0); 80 81 bool DetectRawInformation() const; 82 83 void InputOriginalStyle(bool primitivism); 84 85 private: 86 bool rawInformation_ = false; 87 std::shared_ptr<RSTypeface> typeface_ = nullptr; 88 }; 89 } // namespace TextEngine 90 } // namespace Rosen 91 } // namespace OHOS 92 93 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_DRAWING_TEXGINE_TYPEFACE_H 94