• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_DRAWING_TEXT_ADAPTER_H
17 #define OHOS_DRAWING_TEXT_ADAPTER_H
18 
19 #include <string>
20 
21 namespace OHOS::NWeb {
22 
23 typedef struct OH_Drawing_FontFallbackInfo {
24     /** The type of language supported by the font set. The language format is bcp47 */
25     char* language;
26     /** Font family name */
27     char* familyName;
28 } ArkWeb_Drawing_FontFallbackInfo;
29 
30 typedef struct OH_Drawing_FontAliasInfo {
31     /** Font family name */
32     char* familyName;
33     /**
34      * Font weight value. When the weight value is greater than 0,
35      * the font set contains only fonts with the specified weight.
36      * When the weight value is equal to 0, the font set contains all fonts.
37      */
38     int weight;
39 } ArkWeb_Drawing_FontAliasInfo;
40 
41 typedef struct OH_Drawing_FontAdjustInfo {
42     /** The font's original weight value */
43     int weight;
44     /** The font weight displayed in the application */
45     int to;
46 } ArkWeb_Drawing_FontAdjustInfo;
47 
48 typedef struct OH_Drawing_FontGenericInfo {
49     /** Font family name */
50     char* familyName;
51     /** The size of alias font lists */
52     size_t aliasInfoSize;
53     /** The size of font weight mapping information lists */
54     size_t adjustInfoSize;
55     /** List of alias fonts */
56     ArkWeb_Drawing_FontAliasInfo* aliasInfoSet;
57     /** Font weight mapping information lists */
58     ArkWeb_Drawing_FontAdjustInfo* adjustInfoSet;
59 } ArkWeb_Drawing_FontGenericInfo;
60 
61 typedef struct OH_Drawing_FontFallbackGroup {
62     /**
63      * The name of the font set corresponding to the fallback font set. If the value is null,
64      * all fonts can be set using the fallback font set list.
65      */
66     char* groupName;
67     /** Fallback font Info Size */
68     size_t fallbackInfoSize;
69     /** A list of font sets for fallback fonts */
70     ArkWeb_Drawing_FontFallbackInfo* fallbackInfoSet;
71 } ArkWeb_Drawing_FontFallbackGroup;
72 
73 typedef struct ArkWeb_Drawing_FontConfigInfo {
74     /** Count of system font file paths */
75     size_t fontDirSize;
76     /** List size of generic font sets */
77     size_t fontGenericInfoSize;
78     /** Count of fallback font set lists */
79     size_t fallbackGroupSize;
80     /** List of system font file paths */
81     char** fontDirSet;
82     /** List of generic font sets */
83     ArkWeb_Drawing_FontGenericInfo* fontGenericInfoSet;
84     /** List of fallback font sets */
85     ArkWeb_Drawing_FontFallbackGroup* fallbackGroupSet;
86 } ArkWeb_Drawing_FontConfigInfo;
87 
88 typedef enum {
89     /** All font types */
90     ALL = 1 << 0,
91     /** System generic font type */
92     GENERIC = 1 << 1,
93     /** Stylish font type */
94     STYLISH = 1 << 2,
95     /** Installed font types */
96     INSTALLED = 1 << 3,
97 } ArkWeb_Drawing_SystemFontType;
98 
99 typedef struct {
100     /** A pointer to a byte string containing UTF-16 encoded entities */
101     uint8_t* strData;
102     /** The length of `strData` in bytes */
103     uint32_t strLen;
104 } ArkWeb_Drawing_String;
105 
106 typedef struct ArkWeb_Drawing_FontDescriptor {
107     /** The file path of System font */
108     char* path;
109     /** A name that uniquely identifies the font */
110     char* postScriptName;
111     /** The name of System font */
112     char* fullName;
113     /** The family of System font */
114     char* fontFamily;
115     /** The subfont family of the system font */
116     char* fontSubfamily;
117     /** The weight of System font */
118     int weight;
119     /** The width of System font */
120     int width;
121     /** Whether the system font is tilted */
122     int italic;
123     /** Whether the system font is compact */
124     bool monoSpace;
125     /** whether symbolic fonts are supported */
126     bool symbolic;
127 } ArkWeb_Drawing_FontDescriptor;
128 
129 class OhosDrawingTextFontAdapter {
130 public:
131     OhosDrawingTextFontAdapter() = default;
132 
133     virtual ~OhosDrawingTextFontAdapter() = default;
134 
135     virtual int GetSystemFontFullNamesByType(int32_t systemFontType, void** drawingArray) = 0;
136 
137     virtual int GetFontDescriptorByFullName(void* drawingString,
138                                             int32_t systemFontType, void** drawingFontDescriptor) = 0;
139 
140     virtual int GetSystemFontFullNameByIndex(void* drawingArray,
141                                             int32_t indexOfFullName, const void** drawingString) = 0;
142 
143     virtual void DestroySystemFontFullNames(void* drawingArray) = 0;
144 
145     virtual void DestroyFontDescriptor(void* descriptor) = 0;
146 };
147 
148 class OhosDrawingTextTypographyAdapter {
149 public:
150     OhosDrawingTextTypographyAdapter() = default;
151 
152     virtual ~OhosDrawingTextTypographyAdapter() = default;
153 
154     virtual int GetSystemFontConfigInfo(void* fontConfigInfoErrorCode, void** fontConfigInfo) = 0;
155 
156     virtual int GetDrawingArraySize(void* drawingArray, int32_t& sizeOfArray) = 0;
157 
158     virtual void DestroySystemFontConfigInfo(void* fontConfigInfo) = 0;
159 };
160 } // namespace OHOS::NWeb
161 
162 #endif // OHOS_DRAWING_TEXT_ADAPTER_H