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.h"
17#include "node_extened.h"
18#include "styled_string.h"
19
20#include "base/utils/utils.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26constexpr int NUM_0 = 0;
27constexpr int NUM_1 = 1;
28constexpr int NUM_2 = 2;
29constexpr int NUM_3 = 3;
30constexpr int NUM_4 = 4;
31constexpr int NUM_5 = 5;
32constexpr int32_t MAX_DISPLAY_COUNT_MIN = 6;
33constexpr int32_t MAX_DISPLAY_COUNT_MAX = 9;
34
35ArkUI_LayoutConstraint* OH_ArkUI_LayoutConstraint_Create()
36{
37    ArkUI_LayoutConstraint* layoutConstraint = new ArkUI_LayoutConstraint { 0, 0, 0, 0, 0, 0 };
38    return layoutConstraint;
39}
40
41ArkUI_LayoutConstraint* OH_ArkUI_LayoutConstraint_Copy(const ArkUI_LayoutConstraint* constraint)
42{
43    CHECK_NULL_RETURN(constraint, nullptr);
44    ArkUI_LayoutConstraint* layoutConstraint = new ArkUI_LayoutConstraint { 0, 0, 0, 0, 0, 0 };
45    layoutConstraint->minWidth = constraint->minWidth;
46    layoutConstraint->maxWidth = constraint->maxWidth;
47    layoutConstraint->minHeight = constraint->minHeight;
48    layoutConstraint->maxHeight = constraint->maxHeight;
49    layoutConstraint->percentReferWidth = constraint->percentReferWidth;
50    layoutConstraint->percentReferHeight = constraint->percentReferHeight;
51    return layoutConstraint;
52}
53
54void* OH_ArkUI_LayoutConstraint_Dispose(ArkUI_LayoutConstraint* constraint)
55{
56    delete constraint;
57    return nullptr;
58}
59
60ArkUI_LayoutConstraint* OH_ArkUI_NodeCustomEvent_GetLayoutConstraintInMeasure(ArkUI_NodeCustomEvent* event)
61{
62    CHECK_NULL_RETURN(event, nullptr);
63    ArkUI_LayoutConstraint* layoutConstraint = new ArkUI_LayoutConstraint;
64    layoutConstraint->minWidth = event->event->data[NUM_0];
65    layoutConstraint->minHeight = event->event->data[NUM_1];
66    layoutConstraint->maxWidth = event->event->data[NUM_2];
67    layoutConstraint->maxHeight = event->event->data[NUM_3];
68    layoutConstraint->percentReferWidth = event->event->data[NUM_4];
69    layoutConstraint->percentReferHeight = event->event->data[NUM_5];
70    return layoutConstraint;
71}
72
73ArkUI_IntOffset OH_ArkUI_NodeCustomEvent_GetPositionInLayout(ArkUI_NodeCustomEvent* event)
74{
75    ArkUI_IntOffset intOffset;
76    CHECK_NULL_RETURN(event, intOffset);
77    intOffset.x = event->event->data[NUM_0];
78    intOffset.y = event->event->data[NUM_1];
79    return intOffset;
80}
81
82ArkUI_DrawContext* OH_ArkUI_NodeCustomEvent_GetDrawContextInDraw(ArkUI_NodeCustomEvent* event)
83{
84    CHECK_NULL_RETURN(event, nullptr);
85    ArkUI_DrawContext* drawContext = new ArkUI_DrawContext();
86    drawContext->width = event->event->data[NUM_2];
87    drawContext->height = event->event->data[NUM_3];
88    drawContext->canvas = reinterpret_cast<void*>(event->event->canvas);
89    return drawContext;
90}
91
92int32_t OH_ArkUI_NodeCustomEvent_GetEventTargetId(ArkUI_NodeCustomEvent* event)
93{
94    CHECK_NULL_RETURN(event, -1);
95    return event->targetId;
96}
97
98void* OH_ArkUI_NodeCustomEvent_GetUserData(ArkUI_NodeCustomEvent* event)
99{
100    CHECK_NULL_RETURN(event, nullptr);
101    return event->userData;
102}
103
104ArkUI_NodeHandle OH_ArkUI_NodeCustomEvent_GetNodeHandle(ArkUI_NodeCustomEvent* event)
105{
106    CHECK_NULL_RETURN(event, nullptr);
107    return event->node;
108}
109
110ArkUI_NodeCustomEventType OH_ArkUI_NodeCustomEvent_GetEventType(ArkUI_NodeCustomEvent* event)
111{
112    CHECK_NULL_RETURN(event, static_cast<ArkUI_NodeCustomEventType>(-1));
113    return static_cast<ArkUI_NodeCustomEventType>(event->event->kind);
114}
115
116int32_t OH_ArkUI_NodeCustomEvent_GetCustomSpanMeasureInfo(
117    ArkUI_NodeCustomEvent* event, ArkUI_CustomSpanMeasureInfo* info)
118{
119    if (!event || !info || !event->event) {
120        return ARKUI_ERROR_CODE_PARAM_INVALID;
121    }
122    info->fontSize = event->event->numberData[0].f32;
123    return ARKUI_ERROR_CODE_NO_ERROR;
124}
125
126int32_t OH_ArkUI_NodeCustomEvent_SetCustomSpanMetrics(
127    ArkUI_NodeCustomEvent* event, ArkUI_CustomSpanMetrics* metrics)
128{
129    if (!event || !metrics || !event->event) {
130        return ARKUI_ERROR_CODE_PARAM_INVALID;
131    }
132    event->event->numberReturnData[0].f32 = metrics->width;
133    event->event->numberReturnData[1].f32 = metrics->height;
134    return ARKUI_ERROR_CODE_NO_ERROR;
135}
136
137int32_t OH_ArkUI_NodeCustomEvent_GetCustomSpanDrawInfo(
138    ArkUI_NodeCustomEvent* event, ArkUI_CustomSpanDrawInfo* info)
139{
140    if (!event || !info || !event->event) {
141        return ARKUI_ERROR_CODE_PARAM_INVALID;
142    }
143    info->optionsX = event->event->numberData[0].f32;
144    info->optionsLineTop = event->event->numberData[1].f32;
145    info->optionsLineBottom = event->event->numberData[2].f32;
146    info->optionsBaseLine = event->event->numberData[3].f32;
147    return ARKUI_ERROR_CODE_NO_ERROR;
148}
149
150ArkUI_CustomSpanMeasureInfo* OH_ArkUI_CustomSpanMeasureInfo_Create(void)
151{
152    ArkUI_CustomSpanMeasureInfo* info = new ArkUI_CustomSpanMeasureInfo { 0 };
153    return info;
154}
155
156void OH_ArkUI_CustomSpanMeasureInfo_Dispose(ArkUI_CustomSpanMeasureInfo* info)
157{
158    if (!info) {
159        return;
160    }
161    delete info;
162    info = nullptr;
163}
164
165float OH_ArkUI_CustomSpanMeasureInfo_GetFontSize(ArkUI_CustomSpanMeasureInfo* info)
166{
167    if (!info) {
168        return 0.0f;
169    }
170    return info->fontSize;
171}
172
173ArkUI_CustomSpanMetrics* OH_ArkUI_CustomSpanMetrics_Create(void)
174{
175    ArkUI_CustomSpanMetrics* metrics = new ArkUI_CustomSpanMetrics { 0, 0 };
176    return metrics;
177}
178
179void OH_ArkUI_CustomSpanMetrics_Dispose(ArkUI_CustomSpanMetrics* metrics)
180{
181    if (!metrics) {
182        return;
183    }
184    delete metrics;
185    metrics = nullptr;
186}
187
188int32_t OH_ArkUI_CustomSpanMetrics_SetWidth(ArkUI_CustomSpanMetrics* metrics, float width)
189{
190    if (!metrics) {
191        return ARKUI_ERROR_CODE_PARAM_INVALID;
192    }
193    metrics->width = width;
194    return ARKUI_ERROR_CODE_NO_ERROR;
195}
196
197int32_t OH_ArkUI_CustomSpanMetrics_SetHeight(ArkUI_CustomSpanMetrics* metrics, float height)
198{
199    if (!metrics) {
200        return ARKUI_ERROR_CODE_PARAM_INVALID;
201    }
202    metrics->height = height;
203    return ARKUI_ERROR_CODE_NO_ERROR;
204}
205
206ArkUI_CustomSpanDrawInfo* OH_ArkUI_CustomSpanDrawInfo_Create(void)
207{
208    ArkUI_CustomSpanDrawInfo* info = new ArkUI_CustomSpanDrawInfo { 0, 0, 0, 0 };
209    return info;
210}
211
212void OH_ArkUI_CustomSpanDrawInfo_Dispose(ArkUI_CustomSpanDrawInfo* info)
213{
214    if (!info) {
215        return;
216    }
217    delete info;
218    info = nullptr;
219}
220
221float OH_ArkUI_CustomSpanDrawInfo_GetXOffset(ArkUI_CustomSpanDrawInfo* info)
222{
223    if (!info) {
224        return 0.0f;
225    }
226    return info->optionsX;
227}
228
229float OH_ArkUI_CustomSpanDrawInfo_GetLineTop(ArkUI_CustomSpanDrawInfo* info)
230{
231    if (!info) {
232        return 0.0f;
233    }
234    return info->optionsLineTop;
235}
236
237float OH_ArkUI_CustomSpanDrawInfo_GetLineBottom(ArkUI_CustomSpanDrawInfo* info)
238{
239    if (!info) {
240        return 0.0f;
241    }
242    return info->optionsLineBottom;
243}
244
245float OH_ArkUI_CustomSpanDrawInfo_GetBaseline(ArkUI_CustomSpanDrawInfo* info)
246{
247    if (!info) {
248        return 0.0f;
249    }
250    return info->optionsBaseLine;
251}
252
253int32_t OH_ArkUI_LayoutConstraint_GetMaxWidth(const ArkUI_LayoutConstraint* constraint)
254{
255    CHECK_NULL_RETURN(constraint, -1);
256    return constraint->maxWidth;
257}
258int32_t OH_ArkUI_LayoutConstraint_GetMinWidth(const ArkUI_LayoutConstraint* constraint)
259{
260    CHECK_NULL_RETURN(constraint, -1);
261    return constraint->minWidth;
262}
263int32_t OH_ArkUI_LayoutConstraint_GetMaxHeight(const ArkUI_LayoutConstraint* constraint)
264{
265    CHECK_NULL_RETURN(constraint, -1);
266    return constraint->maxHeight;
267}
268int32_t OH_ArkUI_LayoutConstraint_GetMinHeight(const ArkUI_LayoutConstraint* constraint)
269{
270    CHECK_NULL_RETURN(constraint, -1);
271    return constraint->minHeight;
272}
273int32_t OH_ArkUI_LayoutConstraint_GetPercentReferenceWidth(const ArkUI_LayoutConstraint* constraint)
274{
275    CHECK_NULL_RETURN(constraint, -1);
276    return constraint->percentReferWidth;
277}
278int32_t OH_ArkUI_LayoutConstraint_GetPercentReferenceHeight(const ArkUI_LayoutConstraint* constraint)
279{
280    CHECK_NULL_RETURN(constraint, -1);
281    return constraint->percentReferHeight;
282}
283
284void OH_ArkUI_LayoutConstraint_SetMinWidth(ArkUI_LayoutConstraint* constraint, int32_t value)
285{
286    CHECK_NULL_VOID(constraint);
287    constraint->minWidth = value;
288}
289void OH_ArkUI_LayoutConstraint_SetMaxWidth(ArkUI_LayoutConstraint* constraint, int32_t value)
290{
291    CHECK_NULL_VOID(constraint);
292    constraint->maxWidth = value;
293}
294
295void OH_ArkUI_LayoutConstraint_SetMaxHeight(ArkUI_LayoutConstraint* constraint, int32_t value)
296{
297    CHECK_NULL_VOID(constraint);
298    constraint->maxHeight = value;
299}
300void OH_ArkUI_LayoutConstraint_SetMinHeight(ArkUI_LayoutConstraint* constraint, int32_t value)
301{
302    CHECK_NULL_VOID(constraint);
303    constraint->minHeight = value;
304}
305void OH_ArkUI_LayoutConstraint_SetPercentReferenceWidth(ArkUI_LayoutConstraint* constraint, int32_t value)
306{
307    CHECK_NULL_VOID(constraint);
308    constraint->percentReferWidth = value;
309}
310void OH_ArkUI_LayoutConstraint_SetPercentReferenceHeight(ArkUI_LayoutConstraint* constraint, int32_t value)
311{
312    CHECK_NULL_VOID(constraint);
313    constraint->percentReferHeight = value;
314}
315
316void* OH_ArkUI_DrawContext_GetCanvas(ArkUI_DrawContext* context)
317{
318    return context ? context->canvas : nullptr;
319}
320ArkUI_IntSize OH_ArkUI_DrawContext_GetSize(ArkUI_DrawContext* context)
321{
322    ArkUI_IntSize intSize;
323    if (context == nullptr) {
324        return intSize;
325    }
326    intSize.width = context->width;
327    intSize.height = context->height;
328    return intSize;
329}
330
331ArkUI_SwiperIndicator* OH_ArkUI_SwiperIndicator_Create(ArkUI_SwiperIndicatorType indicatorType)
332{
333    if (indicatorType != ARKUI_SWIPER_INDICATOR_TYPE_DOT) {
334        return nullptr;
335    }
336    ArkUI_SwiperIndicator* indicator = new ArkUI_SwiperIndicator;
337    indicator->type = indicatorType;
338    indicator->dimLeft = ArkUI_OptionalFloat { 0, 0.0f };
339    indicator->dimRight = ArkUI_OptionalFloat { 0, 0.0f };
340    indicator->dimTop = ArkUI_OptionalFloat { 0, 0.0f };
341    indicator->dimBottom = ArkUI_OptionalFloat { 0, 0.0f };
342    if (indicatorType == ARKUI_SWIPER_INDICATOR_TYPE_DOT) {
343        indicator->itemWidth = ArkUI_OptionalFloat { 0, 0.0f };
344        indicator->itemHeight = ArkUI_OptionalFloat { 0, 0.0f };
345        indicator->selectedItemWidth = ArkUI_OptionalFloat { 0, 0.0f };
346        indicator->selectedItemHeight = ArkUI_OptionalFloat { 0, 0.0f };
347        indicator->maskValue = ArkUI_OptionalInt { 0, 0 };
348        indicator->colorValue = ArkUI_OptionalUint { 0, 0xFF000000 };
349        indicator->selectedColorValue = ArkUI_OptionalUint { 0, 0xFF000000 };
350        indicator->maxDisplayCount = ArkUI_OptionalInt { 0, 0 };
351    } else {
352        return nullptr;
353    }
354    return indicator;
355}
356
357void OH_ArkUI_SwiperIndicator_Dispose(ArkUI_SwiperIndicator* indicator)
358{
359    delete indicator;
360}
361
362void OH_ArkUI_SwiperIndicator_SetStartPosition(ArkUI_SwiperIndicator* indicator, float value)
363{
364    CHECK_NULL_VOID(indicator);
365    indicator->dimLeft.isSet = 1;
366    indicator->dimLeft.value = value;
367}
368
369float OH_ArkUI_SwiperIndicator_GetStartPosition(ArkUI_SwiperIndicator* indicator)
370{
371    CHECK_NULL_RETURN(indicator, 0.0f);
372    return indicator->dimLeft.value;
373}
374
375void OH_ArkUI_SwiperIndicator_SetTopPosition(ArkUI_SwiperIndicator* indicator, float value)
376{
377    CHECK_NULL_VOID(indicator);
378    indicator->dimTop.isSet = 1;
379    indicator->dimTop.value = value;
380}
381
382float OH_ArkUI_SwiperIndicator_GetTopPosition(ArkUI_SwiperIndicator* indicator)
383{
384    CHECK_NULL_RETURN(indicator, 0.0f);
385    return indicator->dimTop.value;
386}
387
388void OH_ArkUI_SwiperIndicator_SetEndPosition(ArkUI_SwiperIndicator* indicator, float value)
389{
390    CHECK_NULL_VOID(indicator);
391    indicator->dimRight.isSet = 1;
392    indicator->dimRight.value = value;
393}
394
395float OH_ArkUI_SwiperIndicator_GetEndPosition(ArkUI_SwiperIndicator* indicator)
396{
397    CHECK_NULL_RETURN(indicator, 0.0f);
398    return indicator->dimRight.value;
399}
400
401void OH_ArkUI_SwiperIndicator_SetBottomPosition(ArkUI_SwiperIndicator* indicator, float value)
402{
403    CHECK_NULL_VOID(indicator);
404    indicator->dimBottom.isSet = 1;
405    indicator->dimBottom.value = value;
406}
407
408float OH_ArkUI_SwiperIndicator_GetBottomPosition(ArkUI_SwiperIndicator* indicator)
409{
410    CHECK_NULL_RETURN(indicator, 0.0f);
411    return indicator->dimBottom.value;
412}
413
414void OH_ArkUI_SwiperIndicator_SetItemWidth(ArkUI_SwiperIndicator* indicator, float value)
415{
416    CHECK_NULL_VOID(indicator);
417    indicator->itemWidth.isSet = 1;
418    indicator->itemWidth.value = value;
419}
420
421float OH_ArkUI_SwiperIndicator_GetItemWidth(ArkUI_SwiperIndicator* indicator)
422{
423    CHECK_NULL_RETURN(indicator, 0.0f);
424    return indicator->itemWidth.value;
425}
426
427void OH_ArkUI_SwiperIndicator_SetItemHeight(ArkUI_SwiperIndicator* indicator, float value)
428{
429    CHECK_NULL_VOID(indicator);
430    indicator->itemHeight.isSet = 1;
431    indicator->itemHeight.value = value;
432}
433
434float OH_ArkUI_SwiperIndicator_GetItemHeight(ArkUI_SwiperIndicator* indicator)
435{
436    CHECK_NULL_RETURN(indicator, 0.0f);
437    return indicator->itemHeight.value;
438}
439
440void OH_ArkUI_SwiperIndicator_SetSelectedItemWidth(ArkUI_SwiperIndicator* indicator, float value)
441{
442    CHECK_NULL_VOID(indicator);
443    indicator->selectedItemWidth.isSet = 1;
444    indicator->selectedItemWidth.value = value;
445}
446
447float OH_ArkUI_SwiperIndicator_GetSelectedItemWidth(ArkUI_SwiperIndicator* indicator)
448{
449    CHECK_NULL_RETURN(indicator, 0.0f);
450    return indicator->selectedItemWidth.value;
451}
452
453void OH_ArkUI_SwiperIndicator_SetSelectedItemHeight(ArkUI_SwiperIndicator* indicator, float value)
454{
455    CHECK_NULL_VOID(indicator);
456    indicator->selectedItemHeight.isSet = 1;
457    indicator->selectedItemHeight.value = value;
458}
459
460float OH_ArkUI_SwiperIndicator_GetSelectedItemHeight(ArkUI_SwiperIndicator* indicator)
461{
462    CHECK_NULL_RETURN(indicator, 0.0f);
463    return indicator->selectedItemHeight.value;
464}
465
466void OH_ArkUI_SwiperIndicator_SetMask(ArkUI_SwiperIndicator* indicator, int32_t mask)
467{
468    CHECK_NULL_VOID(indicator);
469    indicator->maskValue.isSet = 1;
470    indicator->maskValue.value = mask;
471}
472
473int32_t OH_ArkUI_SwiperIndicator_GetMask(ArkUI_SwiperIndicator* indicator)
474{
475    CHECK_NULL_RETURN(indicator, 0);
476    return indicator->maskValue.value;
477}
478
479void OH_ArkUI_SwiperIndicator_SetColor(ArkUI_SwiperIndicator* indicator, uint32_t color)
480{
481    CHECK_NULL_VOID(indicator);
482    indicator->colorValue.isSet = 1;
483    indicator->colorValue.value = color;
484}
485
486uint32_t OH_ArkUI_SwiperIndicator_GetColor(ArkUI_SwiperIndicator* indicator)
487{
488    CHECK_NULL_RETURN(indicator, 0);
489    return indicator->colorValue.value;
490}
491
492void OH_ArkUI_SwiperIndicator_SetSelectedColor(ArkUI_SwiperIndicator* indicator, uint32_t selectedColor)
493{
494    CHECK_NULL_VOID(indicator);
495    indicator->selectedColorValue.isSet = 1;
496    indicator->selectedColorValue.value = selectedColor;
497}
498
499uint32_t OH_ArkUI_SwiperIndicator_GetSelectedColor(ArkUI_SwiperIndicator* indicator)
500{
501    CHECK_NULL_RETURN(indicator, 0);
502    return indicator->selectedColorValue.value;
503}
504
505
506int32_t OH_ArkUI_SwiperIndicator_SetMaxDisplayCount(ArkUI_SwiperIndicator* indicator, int32_t maxDisplayCount)
507{
508    CHECK_NULL_RETURN(indicator, ARKUI_ERROR_CODE_PARAM_INVALID);
509    if (maxDisplayCount < MAX_DISPLAY_COUNT_MIN || maxDisplayCount > MAX_DISPLAY_COUNT_MAX) {
510        return ARKUI_ERROR_CODE_PARAM_INVALID;
511    }
512    indicator->maxDisplayCount.isSet = 1;
513    indicator->maxDisplayCount.value = maxDisplayCount;
514    return ARKUI_ERROR_CODE_NO_ERROR;
515}
516
517int32_t OH_ArkUI_SwiperIndicator_GetMaxDisplayCount(ArkUI_SwiperIndicator* indicator)
518{
519    CHECK_NULL_RETURN(indicator, 0);
520    return indicator->maxDisplayCount.value;
521}
522
523ArkUI_StyledString* OH_ArkUI_StyledString_Create(
524    OH_Drawing_TypographyStyle* typoStyle, OH_Drawing_FontCollection* collection)
525{
526    ArkUI_StyledString* storage = new ArkUI_StyledString;
527    storage->builder = OH_Drawing_CreateTypographyHandler(typoStyle, collection);
528    OH_Drawing_TypographyStyle* typographyStyle = OH_Drawing_CreateTypographyStyle();
529    storage->paragraphStyle = typographyStyle;
530    return storage;
531}
532
533void OH_ArkUI_StyledString_Destroy(ArkUI_StyledString* storage)
534{
535    OH_Drawing_DestroyTypographyHandler(reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder));
536    for (auto item : storage->items) {
537        if (item->placeholder) {
538            delete reinterpret_cast<OH_Drawing_PlaceholderSpan*>(item->placeholder);
539            item->placeholder = nullptr;
540        }
541        delete item;
542    }
543    while (!storage->styles.empty()) {
544        auto style = reinterpret_cast<OH_Drawing_TextStyle*>(storage->styles.top());
545        OH_Drawing_DestroyTextStyle(style);
546        storage->styles.pop();
547    }
548    storage->styles = std::stack<void*>();
549    storage->items.clear();
550    OH_Drawing_TypographyStyle* paragraphStyle =
551        reinterpret_cast<OH_Drawing_TypographyStyle*>(storage->paragraphStyle);
552    OH_Drawing_DestroyTypographyStyle(paragraphStyle);
553    delete storage;
554}
555
556void OH_ArkUI_StyledString_PushTextStyle(ArkUI_StyledString* storage, OH_Drawing_TextStyle* style)
557{
558    OH_Drawing_TypographyHandlerPushTextStyle(reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder), style);
559    OH_Drawing_TextStyle* textStyle = OH_Drawing_CreateTextStyle();
560    // copy text style
561    if (style) {
562        OH_Drawing_SetTextStyleColor(textStyle, OH_Drawing_TextStyleGetColor(style));
563        OH_Drawing_SetTextStyleFontSize(textStyle, OH_Drawing_TextStyleGetFontSize(style));
564        OH_Drawing_SetTextStyleFontWeight(textStyle, OH_Drawing_TextStyleGetFontWeight(style));
565        OH_Drawing_SetTextStyleBaseLine(textStyle, OH_Drawing_TextStyleGetBaseline(style));
566        OH_Drawing_SetTextStyleFontHeight(textStyle, OH_Drawing_TextStyleGetFontHeight(style));
567        OH_Drawing_SetTextStyleFontStyle(textStyle, OH_Drawing_TextStyleGetFontStyle(style));
568    }
569    storage->styles.push(textStyle);
570}
571
572void OH_ArkUI_StyledString_AddText(ArkUI_StyledString* storage, const char* content)
573{
574    OH_Drawing_TypographyHandlerAddText(reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder), content);
575
576    ArkUI_SpanItem* spanItem = new ArkUI_SpanItem;
577    spanItem->content = content;
578    if (storage->styles.empty()) {
579        spanItem->textStyle = nullptr;
580    } else {
581        spanItem->textStyle = storage->styles.top();
582    }
583    storage->items.emplace_back(spanItem);
584}
585
586void OH_ArkUI_StyledString_PopTextStyle(ArkUI_StyledString* storage)
587{
588    OH_Drawing_TypographyHandlerPopTextStyle(reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder));
589    if (storage->styles.empty()) {
590        return;
591    }
592    storage->styles.pop();
593}
594
595OH_Drawing_Typography* OH_ArkUI_StyledString_CreateTypography(ArkUI_StyledString* storage)
596{
597    OH_Drawing_Typography* paragraph =
598        OH_Drawing_CreateTypography(reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder));
599    storage->paragraph = paragraph;
600    return reinterpret_cast<OH_Drawing_Typography*>(paragraph);
601}
602
603void OH_ArkUI_StyledString_AddPlaceholder(ArkUI_StyledString* storage, OH_Drawing_PlaceholderSpan* placeholder)
604{
605    OH_Drawing_TypographyHandlerAddPlaceholder(
606        reinterpret_cast<OH_Drawing_TypographyCreate*>(storage->builder), placeholder);
607    ArkUI_SpanItem* spanItem = new ArkUI_SpanItem;
608    if (placeholder) {
609        spanItem->placeholder = new OH_Drawing_PlaceholderSpan {
610            placeholder->width, placeholder->height,
611            placeholder->alignment, placeholder->baseline,
612            placeholder->baselineOffset };
613    } else {
614        spanItem->placeholder = new OH_Drawing_PlaceholderSpan();
615    }
616    storage->items.emplace_back(spanItem);
617}
618
619ArkUI_AccessibilityState* OH_ArkUI_AccessibilityState_Create()
620{
621    ArkUI_AccessibilityState* state = new ArkUI_AccessibilityState;
622    state->isDisabled = ArkUI_OptionalInt { 0, 0 };
623    state->isSelected = ArkUI_OptionalInt { 0, 0 };
624    state->checkedType = ArkUI_OptionalInt { 0, 0 };
625    return state;
626}
627
628void OH_ArkUI_AccessibilityState_Dispose(ArkUI_AccessibilityState* state)
629{
630    delete state;
631}
632
633void OH_ArkUI_AccessibilityState_SetDisabled(ArkUI_AccessibilityState* state, int32_t isDisabled)
634{
635    CHECK_NULL_VOID(state);
636    state->isDisabled.isSet = 1;
637    state->isDisabled.value = isDisabled;
638}
639
640int32_t OH_ArkUI_AccessibilityState_IsDisabled(ArkUI_AccessibilityState* state)
641{
642    CHECK_NULL_RETURN(state, 0);
643    return state->isDisabled.value;
644}
645
646void OH_ArkUI_AccessibilityState_SetSelected(ArkUI_AccessibilityState* state, int32_t isSelected)
647{
648    CHECK_NULL_VOID(state);
649    state->isSelected.isSet = 1;
650    state->isSelected.value = isSelected;
651}
652
653int32_t OH_ArkUI_AccessibilityState_IsSelected(ArkUI_AccessibilityState* state)
654{
655    CHECK_NULL_RETURN(state, 0);
656    return state->isSelected.value;
657}
658
659void OH_ArkUI_AccessibilityState_SetCheckedState(ArkUI_AccessibilityState* state, int32_t checkedState)
660{
661    CHECK_NULL_VOID(state);
662    state->checkedType.isSet = 1;
663    state->checkedType.value = checkedState;
664}
665
666int32_t OH_ArkUI_AccessibilityState_GetCheckedState(ArkUI_AccessibilityState* state)
667{
668    CHECK_NULL_RETURN(state, 0);
669    return state->checkedType.value;
670}
671
672ArkUI_AccessibilityValue* OH_ArkUI_AccessibilityValue_Create()
673{
674    ArkUI_AccessibilityValue* value = new ArkUI_AccessibilityValue;
675    value->min = ArkUI_OptionalInt { 0, -1 };
676    value->max = ArkUI_OptionalInt { 0, -1 };
677    value->current = ArkUI_OptionalInt { 0, -1 };
678    value->text = ArkUI_OptionalCharPtr { 0, "" };
679    return value;
680}
681
682void OH_ArkUI_AccessibilityValue_Dispose(ArkUI_AccessibilityValue* value)
683{
684    delete value;
685}
686
687void OH_ArkUI_AccessibilityValue_SetMin(ArkUI_AccessibilityValue* value, int32_t min)
688{
689    CHECK_NULL_VOID(value);
690    value->min.isSet = 1;
691    value->min.value = min;
692}
693
694int32_t OH_ArkUI_AccessibilityValue_GetMin(ArkUI_AccessibilityValue* value)
695{
696    CHECK_NULL_RETURN(value, -1);
697    return value->min.value;
698}
699
700void OH_ArkUI_AccessibilityValue_SetMax(ArkUI_AccessibilityValue* value, int32_t max)
701{
702    CHECK_NULL_VOID(value);
703    value->max.isSet = 1;
704    value->max.value = max;
705}
706
707int32_t OH_ArkUI_AccessibilityValue_GetMax(ArkUI_AccessibilityValue* value)
708{
709    CHECK_NULL_RETURN(value, -1);
710    return value->max.value;
711}
712
713void OH_ArkUI_AccessibilityValue_SetCurrent(ArkUI_AccessibilityValue* value, int32_t current)
714{
715    CHECK_NULL_VOID(value);
716    value->current.isSet = 1;
717    value->current.value = current;
718}
719
720int32_t OH_ArkUI_AccessibilityValue_GetCurrent(ArkUI_AccessibilityValue* value)
721{
722    CHECK_NULL_RETURN(value, -1);
723    return value->current.value;
724}
725
726void OH_ArkUI_AccessibilityValue_SetText(ArkUI_AccessibilityValue* value, const char* text)
727{
728    CHECK_NULL_VOID(value);
729    value->text.isSet = 1;
730    value->text.value = text;
731}
732
733const char* OH_ArkUI_AccessibilityValue_GetText(ArkUI_AccessibilityValue* value)
734{
735    CHECK_NULL_RETURN(value, "");
736    return value->text.value;
737}
738#ifdef __cplusplus
739};
740#endif
741