• 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 #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     *drawingArray = OH_Drawing_GetSystemFontFullNamesByType(static_cast<OH_Drawing_SystemFontType>(systemFontType));
39     if (*drawingArray == nullptr) {
40         WVLOG_E("drawingArray GetSystemFontFullNamesByType, drawingArray is null.");
41         return -1;
42     }
43     WVLOG_D("drawingArray GetSystemFontFullNamesByType %{public}d", systemFontType);
44     return 0;
45 }
46 
GetFontDescriptorByFullName(void * drawingString,int32_t systemFontType,void ** drawingFontDescriptor)47 int OhosDrawingTextFontAdapterImpl::GetFontDescriptorByFullName(void* drawingString,
48     int32_t systemFontType, void** drawingFontDescriptor)
49 {
50     *drawingFontDescriptor = OH_Drawing_GetFontDescriptorByFullName(
51         static_cast<OH_Drawing_String*>(drawingString),
52         static_cast<OH_Drawing_SystemFontType>(systemFontType));
53     if (*drawingFontDescriptor == nullptr) {
54       WVLOG_E("drawingArray GetFontDescriptorByFullName, drawingArray is null.");
55       return -1;
56     }
57     WVLOG_D("drawingArray GetFontDescriptorByFullName success!!!");
58     return 0;
59 }
60 
GetSystemFontFullNameByIndex(void * drawingArray,int32_t indexOfFullName,const void ** drawingString)61 int OhosDrawingTextFontAdapterImpl::GetSystemFontFullNameByIndex(void* drawingArray,
62     int32_t indexOfFullName, const void** drawingString)
63 {
64     *drawingString = OH_Drawing_GetSystemFontFullNameByIndex(
65         static_cast<OH_Drawing_Array*>(drawingArray),
66         static_cast<size_t>(indexOfFullName));
67     if (*drawingString == nullptr) {
68         WVLOG_E("drawingArray GetSystemFontFullNameByIndex, drawingArray is null.");
69         return -1;
70     }
71     WVLOG_D("drawingArray GetSystemFontFullNameByIndex sucess!!!");
72     return 0;
73 }
74 
DestroySystemFontFullNames(void * drawingArray)75 void OhosDrawingTextFontAdapterImpl::DestroySystemFontFullNames(void* drawingArray)
76 {
77     OH_Drawing_DestroySystemFontFullNames(static_cast<OH_Drawing_Array*>(drawingArray));
78     WVLOG_D("DestroySystemFontFullNames");
79 }
80 
DestroyFontDescriptor(void * descriptor)81 void OhosDrawingTextFontAdapterImpl::DestroyFontDescriptor(void* descriptor)
82 {
83     OH_Drawing_DestroyFontDescriptor(static_cast<OH_Drawing_FontDescriptor*>(descriptor));
84     WVLOG_D("DestroySystemFontDescriptor");
85 }
86 
GetInstance()87 OhosDrawingTextTypographyAdapter& OhosDrawingTextTypographyAdapterImpl::GetInstance()
88 {
89     WVLOG_D("drawing text typography adapter impl get instance.");
90     static OhosDrawingTextTypographyAdapterImpl instance;
91     return instance;
92 }
93 
~OhosDrawingTextTypographyAdapterImpl()94 OhosDrawingTextTypographyAdapterImpl::~OhosDrawingTextTypographyAdapterImpl()
95 {
96     WVLOG_D("Drawing text typography adapter impl desctrutor");
97 }
98 
GetSystemFontConfigInfo(void * fontConfigInfoErrorCode,void ** fontConfigInfo)99 int OhosDrawingTextTypographyAdapterImpl::GetSystemFontConfigInfo(void* fontConfigInfoErrorCode, void** fontConfigInfo)
100 {
101     *fontConfigInfo =
102       OH_Drawing_GetSystemFontConfigInfo(static_cast<OH_Drawing_FontConfigInfoErrorCode*>(fontConfigInfoErrorCode));
103     if (*fontConfigInfo == nullptr) {
104         WVLOG_E("drawingArray GetSystemFontConfigInfo, drawingArray is null.");
105         return -1;
106     }
107     WVLOG_D("drawingArray GetSystemFontConfigInfo success!!!");
108     return 0;
109 }
110 
GetDrawingArraySize(void * drawingArray,int32_t & sizeOfArray)111 int OhosDrawingTextTypographyAdapterImpl::GetDrawingArraySize(void* drawingArray, int32_t& sizeOfArray)
112 {
113     sizeOfArray = static_cast<int32_t>(OH_Drawing_GetDrawingArraySize(static_cast<OH_Drawing_Array*>(drawingArray)));
114     if (sizeOfArray < 0) {
115         WVLOG_E("drawingArray GetDrawingArraySize, drawingArray is null.");
116         return -1;
117     }
118     WVLOG_D("drawingArray GetDrawingArraySize success!!!");
119     return 0;
120 }
121 
DestroySystemFontConfigInfo(void * fontConfigInfo)122 void OhosDrawingTextTypographyAdapterImpl::DestroySystemFontConfigInfo(void* fontConfigInfo)
123 {
124     OH_Drawing_DestroySystemFontConfigInfo(static_cast<OH_Drawing_FontConfigInfo*>(fontConfigInfo));
125     WVLOG_D("DestroySystemFontConfigInfo");
126 }
127 } //namespace OHOS::NWeb
128