1 /*
2  * Copyright (c) 2024 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 "native_styled_string_descriptor.h"
17 #include "interfaces/native/node/node_model.h"
18 #include "base/utils/utils.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
OH_ArkUI_StyledString_Descriptor_Create()24 ArkUI_StyledString_Descriptor* OH_ArkUI_StyledString_Descriptor_Create()
25 {
26     CHECK_NULL_RETURN(OHOS::Ace::NodeModel::GetFullImpl() || OHOS::Ace::NodeModel::InitialFullImpl(), nullptr);
27     return OHOS::Ace::NodeModel::GetFullImpl()->getStyledStringAPI()->createArkUIStyledStringDescriptor();
28 }
29 
OH_ArkUI_StyledString_Descriptor_Destroy(ArkUI_StyledString_Descriptor * descriptor)30 void OH_ArkUI_StyledString_Descriptor_Destroy(ArkUI_StyledString_Descriptor* descriptor)
31 {
32     CHECK_NULL_VOID(OHOS::Ace::NodeModel::GetFullImpl() || OHOS::Ace::NodeModel::InitialFullImpl());
33     OHOS::Ace::NodeModel::GetFullImpl()->getStyledStringAPI()->destroyArkUIStyledStringDescriptor(descriptor);
34 }
35 
OH_ArkUI_UnmarshallStyledStringDescriptor(uint8_t * buffer,size_t bufferSize,ArkUI_StyledString_Descriptor * descriptor)36 int32_t OH_ArkUI_UnmarshallStyledStringDescriptor(
37     uint8_t* buffer, size_t bufferSize, ArkUI_StyledString_Descriptor* descriptor)
38 {
39     CHECK_NULL_RETURN(
40         OHOS::Ace::NodeModel::GetFullImpl() || OHOS::Ace::NodeModel::InitialFullImpl(), ARKUI_ERROR_CODE_PARAM_INVALID);
41     return OHOS::Ace::NodeModel::GetFullImpl()->getStyledStringAPI()->unmarshallStyledStringDescriptor(
42         buffer, bufferSize, descriptor);
43 }
44 
OH_ArkUI_MarshallStyledStringDescriptor(uint8_t * buffer,size_t bufferSize,ArkUI_StyledString_Descriptor * descriptor,size_t * resultSize)45 int32_t OH_ArkUI_MarshallStyledStringDescriptor(
46     uint8_t* buffer, size_t bufferSize, ArkUI_StyledString_Descriptor* descriptor, size_t* resultSize)
47 {
48     CHECK_NULL_RETURN(
49         OHOS::Ace::NodeModel::GetFullImpl() || OHOS::Ace::NodeModel::InitialFullImpl(), ARKUI_ERROR_CODE_PARAM_INVALID);
50     return OHOS::Ace::NodeModel::GetFullImpl()->getStyledStringAPI()->marshallStyledStringDescriptor(
51         buffer, bufferSize, descriptor, resultSize);
52 }
53 
OH_ArkUI_ConvertToHtml(ArkUI_StyledString_Descriptor * descriptor)54 const char* OH_ArkUI_ConvertToHtml(ArkUI_StyledString_Descriptor* descriptor)
55 {
56     CHECK_NULL_RETURN(
57         OHOS::Ace::NodeModel::GetFullImpl() ||  OHOS::Ace::NodeModel::InitialFullImpl(), "");
58     return OHOS::Ace::NodeModel::GetFullImpl()->getStyledStringAPI()->convertToHtml(descriptor);
59 }
60 
61 #ifdef __cplusplus
62 };
63 #endif
64