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 #include "ohos_drawing_text_adapter_impl.h"
17
18 #include "drawing_text_font_descriptor.h"
19 #include "drawing_text_typography.h"
20 #include "nweb_log.h"
21
22 namespace OHOS::NWeb {
23
GetInstance()24 OhosDrawingTextFontAdapter& OhosDrawingTextFontAdapterImpl::GetInstance()
25 {
26 WVLOG_D("drawing text font adapter impl get instance.");
27 static OhosDrawingTextFontAdapterImpl instance;
28 return instance;
29 }
30
~OhosDrawingTextFontAdapterImpl()31 OhosDrawingTextFontAdapterImpl::~OhosDrawingTextFontAdapterImpl()
32 {
33 WVLOG_D("Drawing text font adapter impl destructor.");
34 }
35
GetSystemFontFullNamesByType(int32_t systemFontType,void ** drawingArray)36 int OhosDrawingTextFontAdapterImpl::GetSystemFontFullNamesByType(int32_t systemFontType, void** drawingArray)
37 {
38 if (drawingArray == nullptr) {
39 WVLOG_E("drawingArray GetSystemFontFullNamesByType, drawingArray_ptr is null.");
40 return -1;
41 }
42 *drawingArray = OH_Drawing_GetSystemFontFullNamesByType(static_cast<OH_Drawing_SystemFontType>(systemFontType));
43 if (*drawingArray == nullptr) {
44 WVLOG_E("drawingArray GetSystemFontFullNamesByType, drawingArray is null.");
45 return -1;
46 }
47 WVLOG_D("drawingArray GetSystemFontFullNamesByType %{public}d", systemFontType);
48 return 0;
49 }
50
GetFontDescriptorByFullName(void * drawingString,int32_t systemFontType,void ** drawingFontDescriptor)51 int OhosDrawingTextFontAdapterImpl::GetFontDescriptorByFullName(void* drawingString,
52 int32_t systemFontType, void** drawingFontDescriptor)
53 {
54 if (drawingFontDescriptor == nullptr) {
55 WVLOG_E("drawingArray GetFontDescriptorByFullName, drawingFontDescriptor is null.");
56 return -1;
57 }
58 *drawingFontDescriptor = OH_Drawing_GetFontDescriptorByFullName(
59 static_cast<OH_Drawing_String*>(drawingString),
60 static_cast<OH_Drawing_SystemFontType>(systemFontType));
61 if (*drawingFontDescriptor == nullptr) {
62 WVLOG_E("drawingArray GetFontDescriptorByFullName, drawingArray is null.");
63 return -1;
64 }
65 WVLOG_D("drawingArray GetFontDescriptorByFullName success!!!");
66 return 0;
67 }
68
GetSystemFontFullNameByIndex(void * drawingArray,int32_t indexOfFullName,const void ** drawingString)69 int OhosDrawingTextFontAdapterImpl::GetSystemFontFullNameByIndex(void* drawingArray,
70 int32_t indexOfFullName, const void** drawingString)
71 {
72 if (drawingString == nullptr) {
73 WVLOG_E("drawingArray GetSystemFontFullNameByIndex, drawingString is null.");
74 return -1;
75 }
76 *drawingString = OH_Drawing_GetSystemFontFullNameByIndex(
77 static_cast<OH_Drawing_Array*>(drawingArray),
78 static_cast<size_t>(indexOfFullName));
79 if (*drawingString == nullptr) {
80 WVLOG_E("drawingArray GetSystemFontFullNameByIndex, drawingArray is null.");
81 return -1;
82 }
83 WVLOG_D("drawingArray GetSystemFontFullNameByIndex success!!!");
84 return 0;
85 }
86
DestroySystemFontFullNames(void * drawingArray)87 void OhosDrawingTextFontAdapterImpl::DestroySystemFontFullNames(void* drawingArray)
88 {
89 OH_Drawing_DestroySystemFontFullNames(static_cast<OH_Drawing_Array*>(drawingArray));
90 WVLOG_D("DestroySystemFontFullNames");
91 }
92
DestroyFontDescriptor(void * descriptor)93 void OhosDrawingTextFontAdapterImpl::DestroyFontDescriptor(void* descriptor)
94 {
95 OH_Drawing_DestroyFontDescriptor(static_cast<OH_Drawing_FontDescriptor*>(descriptor));
96 WVLOG_D("DestroySystemFontDescriptor");
97 }
98
GetInstance()99 OhosDrawingTextTypographyAdapter& OhosDrawingTextTypographyAdapterImpl::GetInstance()
100 {
101 WVLOG_D("drawing text typography adapter impl get instance.");
102 static OhosDrawingTextTypographyAdapterImpl instance;
103 return instance;
104 }
105
~OhosDrawingTextTypographyAdapterImpl()106 OhosDrawingTextTypographyAdapterImpl::~OhosDrawingTextTypographyAdapterImpl()
107 {
108 WVLOG_D("Drawing text typography adapter impl destructor.");
109 }
110
GetSystemFontConfigInfo(void * fontConfigInfoErrorCode,void ** fontConfigInfo)111 int OhosDrawingTextTypographyAdapterImpl::GetSystemFontConfigInfo(void* fontConfigInfoErrorCode, void** fontConfigInfo)
112 {
113 if (fontConfigInfo == nullptr) {
114 WVLOG_E("drawingArray GetSystemFontConfigInfo, fontConfigInfo is null.");
115 return -1;
116 }
117 *fontConfigInfo =
118 OH_Drawing_GetSystemFontConfigInfo(static_cast<OH_Drawing_FontConfigInfoErrorCode*>(fontConfigInfoErrorCode));
119 if (*fontConfigInfo == nullptr) {
120 WVLOG_E("drawingArray GetSystemFontConfigInfo, drawingArray is null.");
121 return -1;
122 }
123 WVLOG_D("drawingArray GetSystemFontConfigInfo success!!!");
124 return 0;
125 }
126
GetDrawingArraySize(void * drawingArray,int32_t & sizeOfArray)127 int OhosDrawingTextTypographyAdapterImpl::GetDrawingArraySize(void* drawingArray, int32_t& sizeOfArray)
128 {
129 sizeOfArray = static_cast<int32_t>(OH_Drawing_GetDrawingArraySize(static_cast<OH_Drawing_Array*>(drawingArray)));
130 if (sizeOfArray < 0) {
131 WVLOG_E("drawingArray GetDrawingArraySize, drawingArray is null.");
132 return -1;
133 }
134 WVLOG_D("drawingArray GetDrawingArraySize success!!!");
135 return 0;
136 }
137
DestroySystemFontConfigInfo(void * fontConfigInfo)138 void OhosDrawingTextTypographyAdapterImpl::DestroySystemFontConfigInfo(void* fontConfigInfo)
139 {
140 OH_Drawing_DestroySystemFontConfigInfo(static_cast<OH_Drawing_FontConfigInfo*>(fontConfigInfo));
141 WVLOG_D("DestroySystemFontConfigInfo");
142 }
143 } // namespace OHOS::NWeb
144