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