• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "core/interfaces/native/node/node_span_modifier.h"
16 
17 #include "base/utils/utf_helper.h"
18 #include "bridge/common/utils/utils.h"
19 #include "core/components_ng/pattern/text/span_model_ng.h"
20 #include "core/pipeline/base/element_register.h"
21 #include "draw/canvas.h"
22 #include "frameworks/core/components/common/properties/text_style.h"
23 
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr TextCase DEFAULT_TEXT_CASE = TextCase::NORMAL;
27 constexpr FontWeight DEFAULT_FONT_WEIGHT = FontWeight::NORMAL;
28 constexpr Ace::FontStyle DEFAULT_FONT_STYLE_VALUE = Ace::FontStyle::NORMAL;
29 constexpr Dimension DEFAULT_FONT_SIZE = Dimension(16.0, DimensionUnit::FP);
30 constexpr Dimension DEFAULT_BASELINE_OFFSET { 0.0, DimensionUnit::FP };
31 std::string g_strValue;
32 constexpr int NUM_0 = 0;
33 constexpr int NUM_1 = 1;
34 constexpr int NUM_2 = 2;
35 constexpr int NUM_3 = 3;
36 constexpr int NUM_32 = 32;
37 constexpr int DEFAULT_LENGTH = 4;
SetSpanContent(ArkUINodeHandle node,const char * value)38 void SetSpanContent(ArkUINodeHandle node, const char* value)
39 {
40     CHECK_NULL_VOID(value);
41     auto* uiNode = reinterpret_cast<UINode*>(node);
42     CHECK_NULL_VOID(uiNode);
43     std::string content(value);
44     SpanModelNG::InitSpan(uiNode, UtfUtils::Str8DebugToStr16(content));
45 }
46 
GetSpanContent(ArkUINodeHandle node)47 const char* GetSpanContent(ArkUINodeHandle node)
48 {
49     auto* uiNode = reinterpret_cast<UINode*>(node);
50     CHECK_NULL_RETURN(uiNode, nullptr);
51     g_strValue = UtfUtils::Str16DebugToStr8(SpanModelNG::GetContent(uiNode));
52     return g_strValue.c_str();
53 }
54 
SetSpanSrc(ArkUINodeHandle node,ArkUI_CharPtr src)55 void SetSpanSrc(ArkUINodeHandle node, ArkUI_CharPtr src)
56 {
57     auto* uiNode = reinterpret_cast<UINode*>(node);
58     CHECK_NULL_VOID(uiNode);
59     std::string content(src);
60     SpanModelNG::InitSpan(uiNode, UtfUtils::Str8DebugToStr16(content));
61 }
62 
SetSpanTextCase(ArkUINodeHandle node,int32_t value)63 void SetSpanTextCase(ArkUINodeHandle node, int32_t value)
64 {
65     auto* uiNode = reinterpret_cast<UINode*>(node);
66     CHECK_NULL_VOID(uiNode);
67     SpanModelNG::SetTextCase(uiNode, static_cast<TextCase>(value));
68 }
69 
GetSpanTextCase(ArkUINodeHandle node)70 int32_t GetSpanTextCase(ArkUINodeHandle node)
71 {
72     auto defaultTextCase = static_cast<int32_t>(DEFAULT_TEXT_CASE);
73     auto* uiNode = reinterpret_cast<UINode*>(node);
74     CHECK_NULL_RETURN(uiNode, defaultTextCase);
75     return static_cast<int32_t>(SpanModelNG::GetTextCase(uiNode));
76 }
77 
ResetSpanTextCase(ArkUINodeHandle node)78 void ResetSpanTextCase(ArkUINodeHandle node)
79 {
80     auto* uiNode = reinterpret_cast<UINode*>(node);
81     CHECK_NULL_VOID(uiNode);
82     SpanModelNG::ResetTextCase(uiNode);
83 }
84 
SetSpanFontWeightStr(ArkUINodeHandle node,const char * value)85 void SetSpanFontWeightStr(ArkUINodeHandle node, const char* value)
86 {
87     auto* uiNode = reinterpret_cast<UINode*>(node);
88     CHECK_NULL_VOID(uiNode);
89     SpanModelNG::SetFontWeight(uiNode, Framework::ConvertStrToFontWeight(value));
90 }
91 
SetSpanFontWeight(ArkUINodeHandle node,ArkUI_Int32 fontWeight)92 void SetSpanFontWeight(ArkUINodeHandle node, ArkUI_Int32 fontWeight)
93 {
94     auto* uiNode = reinterpret_cast<UINode*>(node);
95     CHECK_NULL_VOID(uiNode);
96     SpanModelNG::SetFontWeight(uiNode, static_cast<FontWeight>(fontWeight));
97 }
98 
GetSpanFontWeight(ArkUINodeHandle node)99 int32_t GetSpanFontWeight(ArkUINodeHandle node)
100 {
101     int32_t defaultFontWeight = static_cast<int32_t>(DEFAULT_FONT_WEIGHT);
102     auto* uiNode = reinterpret_cast<UINode*>(node);
103     CHECK_NULL_RETURN(uiNode, defaultFontWeight);
104     return static_cast<int32_t>(SpanModelNG::GetFontWeight(uiNode));
105 }
106 
ResetSpanFontWeight(ArkUINodeHandle node)107 void ResetSpanFontWeight(ArkUINodeHandle node)
108 {
109     auto* uiNode = reinterpret_cast<UINode*>(node);
110     CHECK_NULL_VOID(uiNode);
111     SpanModelNG::ResetFontWeight(uiNode);
112 }
113 
SetSpanLineHeight(ArkUINodeHandle node,ArkUI_Float32 number,ArkUI_Int32 unit)114 void SetSpanLineHeight(ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit)
115 {
116     auto* uiNode = reinterpret_cast<UINode*>(node);
117     CHECK_NULL_VOID(uiNode);
118     SpanModelNG::SetLineHeight(uiNode, Dimension(number, static_cast<DimensionUnit>(unit)));
119 }
120 
GetSpanLineHeight(ArkUINodeHandle node)121 float GetSpanLineHeight(ArkUINodeHandle node)
122 {
123     auto* uiNode = reinterpret_cast<UINode*>(node);
124     CHECK_NULL_RETURN(uiNode, 0.0f);
125     return SpanModelNG::GetTextLineHeight(uiNode).ConvertToVp();
126 }
127 
ResetSpanLineHeight(ArkUINodeHandle node)128 void ResetSpanLineHeight(ArkUINodeHandle node)
129 {
130     auto* uiNode = reinterpret_cast<UINode*>(node);
131     CHECK_NULL_VOID(uiNode);
132     SpanModelNG::ResetLineHeight(uiNode);
133 }
134 
SetSpanFontStyle(ArkUINodeHandle node,int32_t value)135 void SetSpanFontStyle(ArkUINodeHandle node, int32_t value)
136 {
137     auto* uiNode = reinterpret_cast<UINode*>(node);
138     CHECK_NULL_VOID(uiNode);
139     SpanModelNG::SetItalicFontStyle(uiNode, static_cast<Ace::FontStyle>(value));
140 }
141 
GetSpanFontStyle(ArkUINodeHandle node)142 int32_t GetSpanFontStyle(ArkUINodeHandle node)
143 {
144     int32_t defaultFontStyle = static_cast<int32_t>(DEFAULT_FONT_STYLE_VALUE);
145     auto* uiNode = reinterpret_cast<UINode*>(node);
146     CHECK_NULL_RETURN(uiNode, defaultFontStyle);
147     return static_cast<int32_t>(SpanModelNG::GetFontStyle(uiNode));
148 }
149 
ResetSpanFontStyle(ArkUINodeHandle node)150 void ResetSpanFontStyle(ArkUINodeHandle node)
151 {
152     auto* uiNode = reinterpret_cast<UINode*>(node);
153     CHECK_NULL_VOID(uiNode);
154     SpanModelNG::ResetItalicFontStyle(uiNode);
155 }
156 
SetSpanFontSize(ArkUINodeHandle node,ArkUI_Float32 number,ArkUI_Int32 unit)157 void SetSpanFontSize(ArkUINodeHandle node, ArkUI_Float32 number, ArkUI_Int32 unit)
158 {
159     auto* uiNode = reinterpret_cast<UINode*>(node);
160     CHECK_NULL_VOID(uiNode);
161     SpanModelNG::SetFontSize(uiNode, Dimension(number, static_cast<DimensionUnit>(unit)));
162 }
163 
GetSpanFontSize(ArkUINodeHandle node,ArkUI_Int32 unit)164 float GetSpanFontSize(ArkUINodeHandle node, ArkUI_Int32 unit)
165 {
166     auto* uiNode = reinterpret_cast<UINode*>(node);
167     CHECK_NULL_RETURN(uiNode, DEFAULT_FONT_SIZE.Value());
168     return SpanModelNG::GetFontSize(uiNode).GetNativeValue(static_cast<DimensionUnit>(unit));
169 }
170 
ResetSpanFontSize(ArkUINodeHandle node)171 void ResetSpanFontSize(ArkUINodeHandle node)
172 {
173     auto* uiNode = reinterpret_cast<UINode*>(node);
174     CHECK_NULL_VOID(uiNode);
175     SpanModelNG::ResetFontSize(uiNode);
176 }
177 
SetSpanFontFamily(ArkUINodeHandle node,const char ** fontFamilies,uint32_t length)178 void SetSpanFontFamily(ArkUINodeHandle node, const char** fontFamilies, uint32_t length)
179 {
180     CHECK_NULL_VOID(fontFamilies);
181     if (length <= 0) {
182         return;
183     }
184     auto* uiNode = reinterpret_cast<UINode*>(node);
185     CHECK_NULL_VOID(uiNode);
186     std::vector<std::string> families;
187     for (uint32_t i = 0; i < length; i++) {
188         const char* family = *(fontFamilies + i);
189         if (family != nullptr) {
190             families.emplace_back(std::string(family));
191         }
192     }
193     SpanModelNG::SetFontFamily(uiNode, families);
194 }
195 
ResetSpanFontFamily(ArkUINodeHandle node)196 void ResetSpanFontFamily(ArkUINodeHandle node)
197 {
198     auto* uiNode = reinterpret_cast<UINode*>(node);
199     CHECK_NULL_VOID(uiNode);
200     SpanModelNG::ResetFontFamily(uiNode);
201 }
202 
SetSpanDecoration(ArkUINodeHandle node,ArkUI_Int32 decoration,ArkUI_Uint32 color,ArkUI_Int32 style)203 void SetSpanDecoration(ArkUINodeHandle node, ArkUI_Int32 decoration, ArkUI_Uint32 color, ArkUI_Int32 style)
204 {
205     auto* uiNode = reinterpret_cast<UINode*>(node);
206     CHECK_NULL_VOID(uiNode);
207     SpanModelNG::SetTextDecoration(uiNode, static_cast<TextDecoration>(decoration));
208     SpanModelNG::SetTextDecorationStyle(uiNode, static_cast<TextDecorationStyle>(style));
209     SpanModelNG::SetTextDecorationColor(uiNode, Color(color));
210 }
211 
GetSpanDecoration(ArkUINodeHandle node,ArkUITextDecorationType * decoration)212 void GetSpanDecoration(ArkUINodeHandle node, ArkUITextDecorationType* decoration)
213 {
214     CHECK_NULL_VOID(decoration);
215     auto* uiNode = reinterpret_cast<UINode*>(node);
216     CHECK_NULL_VOID(uiNode);
217     decoration->decorationType = static_cast<int32_t>(SpanModelNG::GetTextDecoration(uiNode));
218     decoration->color = SpanModelNG::GetTextDecorationColor(uiNode).GetValue();
219     decoration->style = static_cast<int32_t>(SpanModelNG::GetTextDecorationStyle(uiNode));
220 }
221 
ResetSpanDecoration(ArkUINodeHandle node)222 void ResetSpanDecoration(ArkUINodeHandle node)
223 {
224     auto* uiNode = reinterpret_cast<UINode*>(node);
225     CHECK_NULL_VOID(uiNode);
226     SpanModelNG::ResetTextDecoration(uiNode);
227     SpanModelNG::ResetTextDecorationStyle(uiNode);
228     SpanModelNG::ResetTextDecorationColor(uiNode);
229 }
230 
SetSpanFontColor(ArkUINodeHandle node,uint32_t textColor)231 void SetSpanFontColor(ArkUINodeHandle node, uint32_t textColor)
232 {
233     auto* uiNode = reinterpret_cast<UINode*>(node);
234     CHECK_NULL_VOID(uiNode);
235     SpanModelNG::SetTextColor(uiNode, Color(textColor));
236 }
237 
GetSpanFontColor(ArkUINodeHandle node)238 uint32_t GetSpanFontColor(ArkUINodeHandle node)
239 {
240     auto* uiNode = reinterpret_cast<UINode*>(node);
241     CHECK_NULL_RETURN(uiNode, Color::BLACK.GetValue());
242     return SpanModelNG::GetFontColor(uiNode).GetValue();
243 }
244 
ResetSpanFontColor(ArkUINodeHandle node)245 void ResetSpanFontColor(ArkUINodeHandle node)
246 {
247     auto* uiNode = reinterpret_cast<UINode*>(node);
248     CHECK_NULL_VOID(uiNode);
249     SpanModelNG::ResetTextColor(uiNode);
250 }
251 
SetSpanLetterSpacing(ArkUINodeHandle node,const struct ArkUIStringAndFloat * letterSpacingValue)252 void SetSpanLetterSpacing(ArkUINodeHandle node, const struct ArkUIStringAndFloat* letterSpacingValue)
253 {
254     auto* uiNode = reinterpret_cast<UINode*>(node);
255     CHECK_NULL_VOID(uiNode);
256     Dimension result;
257     if (letterSpacingValue->valueStr != nullptr) {
258         result = StringUtils::StringToDimensionWithUnit(std::string(letterSpacingValue->valueStr), DimensionUnit::FP);
259     } else {
260         result = Dimension(letterSpacingValue->value, DimensionUnit::FP);
261     }
262     SpanModelNG::SetLetterSpacing(uiNode, result);
263 }
264 
GetSpanLetterSpacing(ArkUINodeHandle node)265 float GetSpanLetterSpacing(ArkUINodeHandle node)
266 {
267     auto* uiNode = reinterpret_cast<UINode*>(node);
268     CHECK_NULL_RETURN(uiNode, 0.0f);
269     return SpanModelNG::GetLetterSpacing(uiNode).ConvertToVp();
270 }
271 
ResetSpanLetterSpacing(ArkUINodeHandle node)272 void ResetSpanLetterSpacing(ArkUINodeHandle node)
273 {
274     auto* uiNode = reinterpret_cast<UINode*>(node);
275     CHECK_NULL_VOID(uiNode);
276     SpanModelNG::ResetLetterSpacing(uiNode);
277 }
278 
SetSpanBaselineOffset(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit)279 void SetSpanBaselineOffset(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit)
280 {
281     auto* uiNode = reinterpret_cast<UINode*>(node);
282     CHECK_NULL_VOID(uiNode);
283     SpanModelNG::SetBaselineOffset(uiNode, CalcDimension(value, (DimensionUnit)unit));
284 }
285 
GetSpanBaselineOffset(ArkUINodeHandle node)286 float GetSpanBaselineOffset(ArkUINodeHandle node)
287 {
288     auto* uiNode = reinterpret_cast<UINode*>(node);
289     CHECK_NULL_RETURN(uiNode, 0.0f);
290     return SpanModelNG::GetBaselineOffset(uiNode).ConvertToVp();
291 }
292 
ResetSpanBaselineOffset(ArkUINodeHandle node)293 void ResetSpanBaselineOffset(ArkUINodeHandle node)
294 {
295     auto* uiNode = reinterpret_cast<UINode*>(node);
296     CHECK_NULL_VOID(uiNode);
297     SpanModelNG::SetBaselineOffset(uiNode, DEFAULT_BASELINE_OFFSET);
298 }
299 
SetSpanFont(ArkUINodeHandle node,const struct ArkUIFontStruct * fontInfo)300 void SetSpanFont(ArkUINodeHandle node, const struct ArkUIFontStruct* fontInfo)
301 {
302     CHECK_NULL_VOID(fontInfo);
303     auto* uiNode = reinterpret_cast<UINode*>(node);
304     CHECK_NULL_VOID(uiNode);
305     Font font;
306     font.fontSize = Dimension(fontInfo->fontSizeNumber, static_cast<DimensionUnit>(fontInfo->fontSizeUnit));
307     font.fontStyle = static_cast<Ace::FontStyle>(fontInfo->fontStyle);
308     font.fontWeight = static_cast<FontWeight>(fontInfo->fontWeight);
309     std::vector<std::string> families;
310     if (fontInfo->fontFamilies && fontInfo->familyLength > 0) {
311         if (fontInfo->familyLength > DEFAULT_MAX_FONT_FAMILY_LENGTH) {
312             return;
313         }
314         families.resize(fontInfo->familyLength);
315         for (uint32_t i = 0; i < fontInfo->familyLength; i++) {
316             families.at(i) = std::string(*(fontInfo->fontFamilies + i));
317         }
318     }
319     font.fontFamilies = families;
320     SpanModelNG::SetFont(uiNode, font);
321 }
322 
ResetSpanFont(ArkUINodeHandle node)323 void ResetSpanFont(ArkUINodeHandle node)
324 {
325     auto* uiNode = reinterpret_cast<UINode*>(node);
326     CHECK_NULL_VOID(uiNode);
327     SpanModelNG::ResetFont(uiNode);
328 }
329 
SetSpanTextBackgroundStyle(ArkUINodeHandle node,ArkUI_Uint32 color,const ArkUI_Float32 * values,const ArkUI_Int32 * units,ArkUI_Int32 length)330 void SetSpanTextBackgroundStyle(
331     ArkUINodeHandle node, ArkUI_Uint32 color, const ArkUI_Float32* values, const ArkUI_Int32* units, ArkUI_Int32 length)
332 {
333     auto* uiNode = reinterpret_cast<UINode*>(node);
334     CHECK_NULL_VOID(uiNode);
335     if (length != DEFAULT_LENGTH) {
336         return;
337     }
338     TextBackgroundStyle font;
339     NG::BorderRadiusProperty borderRadius;
340     borderRadius.radiusTopLeft = Dimension(values[NUM_0], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_0]));
341     borderRadius.radiusTopRight = Dimension(values[NUM_1], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_1]));
342     borderRadius.radiusBottomLeft = Dimension(values[NUM_2], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_2]));
343     borderRadius.radiusBottomRight = Dimension(values[NUM_3], static_cast<OHOS::Ace::DimensionUnit>(units[NUM_3]));
344     font.backgroundColor = Color(color);
345     font.backgroundRadius = borderRadius;
346     font.backgroundRadius->multiValued = true;
347     SpanModelNG::SetTextBackgroundStyle(uiNode, font);
348 }
349 
ResetSpanTextBackgroundStyle(ArkUINodeHandle node)350 void ResetSpanTextBackgroundStyle(ArkUINodeHandle node)
351 {
352     auto* uiNode = reinterpret_cast<UINode*>(node);
353     CHECK_NULL_VOID(uiNode);
354     TextBackgroundStyle font;
355     NG::BorderRadiusProperty borderRadius;
356     borderRadius.radiusTopLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
357     borderRadius.radiusTopRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
358     borderRadius.radiusBottomLeft = Dimension(0, OHOS::Ace::DimensionUnit::VP);
359     borderRadius.radiusBottomRight = Dimension(0, OHOS::Ace::DimensionUnit::VP);
360     font.backgroundColor = Color(0x00000000);
361     font.backgroundRadius = borderRadius;
362     font.backgroundRadius->multiValued = true;
363     SpanModelNG::SetTextBackgroundStyle(uiNode, font);
364 }
365 
GetSpanTextBackgroundStyle(ArkUINodeHandle node,ArkUITextBackgroundStyleOptions * options)366 void GetSpanTextBackgroundStyle(ArkUINodeHandle node, ArkUITextBackgroundStyleOptions* options)
367 {
368     auto* uiNode = reinterpret_cast<UINode*>(node);
369     CHECK_NULL_VOID(uiNode);
370     auto styleOptions = SpanModelNG::GetSpanTextBackgroundStyle(uiNode);
371     options->color = styleOptions.backgroundColor->GetValue();
372     options->topLeft = styleOptions.backgroundRadius->radiusTopLeft->Value();
373     options->topRight = styleOptions.backgroundRadius->radiusTopRight->Value();
374     options->bottomLeft = styleOptions.backgroundRadius->radiusBottomLeft->Value();
375     options->bottomRight= styleOptions.backgroundRadius->radiusBottomRight->Value();
376 }
377 
SetTextTextShadow(ArkUINodeHandle node,struct ArkUITextShadowStruct * shadows,ArkUI_Uint32 length)378 void SetTextTextShadow(ArkUINodeHandle node, struct ArkUITextShadowStruct* shadows, ArkUI_Uint32 length)
379 {
380     CHECK_NULL_VOID(shadows);
381     auto* frameNode = reinterpret_cast<FrameNode*>(node);
382     CHECK_NULL_VOID(frameNode);
383     std::vector<Shadow> shadowList(length);
384     for (uint32_t i = 0; i < length; i++) {
385         Shadow shadow;
386         ArkUITextShadowStruct* shadowStruct = shadows + i;
387         shadow.SetBlurRadius(shadowStruct->radius);
388         shadow.SetShadowType(static_cast<ShadowType>(shadowStruct->type));
389         shadow.SetColor(Color(shadowStruct->color));
390         shadow.SetOffsetX(shadowStruct->offsetX);
391         shadow.SetOffsetY(shadowStruct->offsetY);
392         shadow.SetIsFilled(static_cast<bool>(shadowStruct->fill));
393         shadowList.at(i) = shadow;
394     }
395     SpanModelNG::SetTextShadow(frameNode, shadowList);
396 }
397 
GetTextShadow(ArkUINodeHandle node,ArkUITextShadowStruct * shadow,uint32_t size)398 void GetTextShadow(ArkUINodeHandle node, ArkUITextShadowStruct* shadow, uint32_t size)
399 {
400     auto* frameNode = reinterpret_cast<FrameNode*>(node);
401     CHECK_NULL_VOID(frameNode);
402     std::vector<ArkUITextShadowStruct> shadowArray;
403     auto textShadowVector = SpanModelNG::GetTextShadow(frameNode);
404     for (uint32_t i = 0; i < size; i++) {
405         if (i < textShadowVector.size()) {
406             *(shadow + i) = { static_cast<float>(textShadowVector[i].GetBlurRadius()),
407                 static_cast<int32_t>(textShadowVector[i].GetShadowType()), textShadowVector[i].GetColor().GetValue(),
408                 textShadowVector[i].GetOffset().GetX(), textShadowVector[i].GetOffset().GetY(),
409                 textShadowVector[i].GetIsFilled() };
410         } else {
411             *(shadow + i) = { 0.0f, static_cast<int32_t>(ShadowType::COLOR), Color::TRANSPARENT.GetValue(), 0.0f, 0.0f,
412                 0 };
413         }
414     }
415 }
416 
ResetTextTextShadow(ArkUINodeHandle node)417 void ResetTextTextShadow(ArkUINodeHandle node)
418 {
419     auto* frameNode = reinterpret_cast<FrameNode*>(node);
420     CHECK_NULL_VOID(frameNode);
421     SpanModelNG::ResetTextShadow(frameNode);
422 }
423 
SetAccessibilityText(ArkUINodeHandle node,ArkUI_CharPtr value)424 void SetAccessibilityText(ArkUINodeHandle node, ArkUI_CharPtr value)
425 {
426     auto* frameNode = reinterpret_cast<FrameNode*>(node);
427     CHECK_NULL_VOID(frameNode);
428     std::string valueStr = value;
429     SpanModelNG::SetAccessibilityText(frameNode, valueStr);
430 }
431 
ResetAccessibilityText(ArkUINodeHandle node)432 void ResetAccessibilityText(ArkUINodeHandle node)
433 {
434     auto* frameNode = reinterpret_cast<FrameNode*>(node);
435     CHECK_NULL_VOID(frameNode);
436     SpanModelNG::SetAccessibilityText(frameNode, "");
437 }
438 
SetAccessibilityDescription(ArkUINodeHandle node,ArkUI_CharPtr value)439 void SetAccessibilityDescription(ArkUINodeHandle node, ArkUI_CharPtr value)
440 {
441     auto* frameNode = reinterpret_cast<FrameNode*>(node);
442     CHECK_NULL_VOID(frameNode);
443     CHECK_NULL_VOID(value);
444     std::string valueStr = value;
445     SpanModelNG::SetAccessibilityDescription(frameNode, valueStr);
446 }
447 
ResetAccessibilityDescription(ArkUINodeHandle node)448 void ResetAccessibilityDescription(ArkUINodeHandle node)
449 {
450     auto* frameNode = reinterpret_cast<FrameNode*>(node);
451     CHECK_NULL_VOID(frameNode);
452     SpanModelNG::SetAccessibilityDescription(frameNode, "");
453 }
454 
SetAccessibilityLevel(ArkUINodeHandle node,ArkUI_CharPtr value)455 void SetAccessibilityLevel(ArkUINodeHandle node, ArkUI_CharPtr value)
456 {
457     auto* frameNode = reinterpret_cast<FrameNode*>(node);
458     CHECK_NULL_VOID(frameNode);
459     CHECK_NULL_VOID(value);
460     std::string valueStr = value;
461     SpanModelNG::SetAccessibilityImportance(frameNode, valueStr);
462 }
463 
ResetAccessibilityLevel(ArkUINodeHandle node)464 void ResetAccessibilityLevel(ArkUINodeHandle node)
465 {
466     auto* frameNode = reinterpret_cast<FrameNode*>(node);
467     CHECK_NULL_VOID(frameNode);
468     SpanModelNG::SetAccessibilityImportance(frameNode, "");
469 }
470 
GetSpanFontFamily(ArkUINodeHandle node)471 ArkUI_CharPtr GetSpanFontFamily(ArkUINodeHandle node)
472 {
473     auto* frameNode = reinterpret_cast<UINode*>(node);
474     CHECK_NULL_RETURN(frameNode, nullptr);
475     std::vector<std::string> fontFamilies = SpanModelNG::GetSpanFontFamily(frameNode);
476     std::string families;
477     //set index start
478     uint32_t index = 0;
479     for (auto& family : fontFamilies) {
480         families += family;
481         if (index != fontFamilies.size() - 1) {
482             families += ",";
483         }
484         index++;
485     }
486     g_strValue = families;
487     return g_strValue.c_str();
488 }
489 } // namespace
490 namespace NodeModifier {
GetSpanModifier()491 const ArkUISpanModifier* GetSpanModifier()
492 {
493     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
494     static const ArkUISpanModifier modifier = {
495         .setSpanSrc = SetSpanSrc,
496         .setContent = SetSpanContent,
497         .setSpanTextCase = SetSpanTextCase,
498         .resetSpanTextCase = ResetSpanTextCase,
499         .setSpanFontWeight = SetSpanFontWeight,
500         .resetSpanFontWeight = ResetSpanFontWeight,
501         .setSpanLineHeight = SetSpanLineHeight,
502         .resetSpanLineHeight = ResetSpanLineHeight,
503         .setSpanFontStyle = SetSpanFontStyle,
504         .resetSpanFontStyle = ResetSpanFontStyle,
505         .setSpanFontSize = SetSpanFontSize,
506         .resetSpanFontSize = ResetSpanFontSize,
507         .setSpanFontFamily = SetSpanFontFamily,
508         .resetSpanFontFamily = ResetSpanFontFamily,
509         .setSpanDecoration = SetSpanDecoration,
510         .resetSpanDecoration = ResetSpanDecoration,
511         .setSpanFontColor = SetSpanFontColor,
512         .resetSpanFontColor = ResetSpanFontColor,
513         .setSpanLetterSpacing = SetSpanLetterSpacing,
514         .resetSpanLetterSpacing = ResetSpanLetterSpacing,
515         .setSpanBaselineOffset = SetSpanBaselineOffset,
516         .resetSpanBaselineOffset = ResetSpanBaselineOffset,
517         .setSpanFont = SetSpanFont,
518         .resetSpanFont = ResetSpanFont,
519         .setSpanFontWeightStr = SetSpanFontWeightStr,
520         .getSpanContent = GetSpanContent,
521         .getSpanDecoration = GetSpanDecoration,
522         .getSpanFontColor = GetSpanFontColor,
523         .getSpanFontSize = GetSpanFontSize,
524         .getSpanFontStyle = GetSpanFontStyle,
525         .getSpanFontWeight = GetSpanFontWeight,
526         .getSpanLineHeight = GetSpanLineHeight,
527         .getSpanTextCase = GetSpanTextCase,
528         .getSpanLetterSpacing = GetSpanLetterSpacing,
529         .getSpanBaselineOffset = GetSpanBaselineOffset,
530         .setSpanTextBackgroundStyle = SetSpanTextBackgroundStyle,
531         .resetSpanTextBackgroundStyle = ResetSpanTextBackgroundStyle,
532         .getSpanTextBackgroundStyle = GetSpanTextBackgroundStyle,
533         .setTextShadow = SetTextTextShadow,
534         .resetTextShadow = ResetTextTextShadow,
535         .getTextShadows = GetTextShadow,
536         .getSpanFontFamily = GetSpanFontFamily,
537         .setAccessibilityText = SetAccessibilityText,
538         .resetAccessibilityText = ResetAccessibilityText,
539         .setAccessibilityDescription = SetAccessibilityDescription,
540         .resetAccessibilityDescription = ResetAccessibilityDescription,
541         .setAccessibilityLevel = SetAccessibilityLevel,
542         .resetAccessibilityLevel = ResetAccessibilityLevel,
543     };
544     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
545     return &modifier;
546 }
547 
GetCJUISpanModifier()548 const CJUISpanModifier* GetCJUISpanModifier()
549 {
550     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
551     static const CJUISpanModifier modifier = {
552         .setSpanSrc = SetSpanSrc,
553         .setContent = SetSpanContent,
554         .setSpanTextCase = SetSpanTextCase,
555         .resetSpanTextCase = ResetSpanTextCase,
556         .setSpanFontWeight = SetSpanFontWeight,
557         .resetSpanFontWeight = ResetSpanFontWeight,
558         .setSpanLineHeight = SetSpanLineHeight,
559         .resetSpanLineHeight = ResetSpanLineHeight,
560         .setSpanFontStyle = SetSpanFontStyle,
561         .resetSpanFontStyle = ResetSpanFontStyle,
562         .setSpanFontSize = SetSpanFontSize,
563         .resetSpanFontSize = ResetSpanFontSize,
564         .setSpanFontFamily = SetSpanFontFamily,
565         .resetSpanFontFamily = ResetSpanFontFamily,
566         .setSpanDecoration = SetSpanDecoration,
567         .resetSpanDecoration = ResetSpanDecoration,
568         .setSpanFontColor = SetSpanFontColor,
569         .resetSpanFontColor = ResetSpanFontColor,
570         .setSpanLetterSpacing = SetSpanLetterSpacing,
571         .resetSpanLetterSpacing = ResetSpanLetterSpacing,
572         .setSpanBaselineOffset = SetSpanBaselineOffset,
573         .resetSpanBaselineOffset = ResetSpanBaselineOffset,
574         .setSpanFont = SetSpanFont,
575         .resetSpanFont = ResetSpanFont,
576         .setSpanFontWeightStr = SetSpanFontWeightStr,
577         .getSpanContent = GetSpanContent,
578         .getSpanDecoration = GetSpanDecoration,
579         .getSpanFontColor = GetSpanFontColor,
580         .getSpanFontSize = GetSpanFontSize,
581         .getSpanFontStyle = GetSpanFontStyle,
582         .getSpanFontWeight = GetSpanFontWeight,
583         .getSpanLineHeight = GetSpanLineHeight,
584         .getSpanTextCase = GetSpanTextCase,
585         .getSpanLetterSpacing = GetSpanLetterSpacing,
586         .getSpanBaselineOffset = GetSpanBaselineOffset,
587         .setSpanTextBackgroundStyle = SetSpanTextBackgroundStyle,
588         .resetSpanTextBackgroundStyle = ResetSpanTextBackgroundStyle,
589         .getSpanTextBackgroundStyle = GetSpanTextBackgroundStyle,
590         .setTextShadow = SetTextTextShadow,
591         .resetTextShadow = ResetTextTextShadow,
592         .getTextShadows = GetTextShadow,
593     };
594     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
595     return &modifier;
596 }
597 
SetCustomSpanOnMeasure(ArkUINodeHandle node,void * extraParam)598 void SetCustomSpanOnMeasure(ArkUINodeHandle node, void* extraParam)
599 {
600     auto* frameNode = reinterpret_cast<CustomSpanNode*>(node);
601     CHECK_NULL_VOID(frameNode);
602     std::function<CustomSpanMetrics(CustomSpanMeasureInfo)> onMeasureFunc =
603         [node, extraParam](CustomSpanMeasureInfo customSpanMeasureInfo) -> CustomSpanMetrics {
604         ArkUICustomNodeEvent event;
605         event.kind = ArkUIAPINodeFlags::CUSTOM_MEASURE;
606         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
607         event.numberData[0].f32 = customSpanMeasureInfo.fontSize;
608         event.numberReturnData[0].f32 = 0.0f;
609         event.numberReturnData[1].f32 = 0.0f;
610         SendArkUIAsyncCustomEvent(&event);
611         float width = std::max(event.numberReturnData[0].f32, 0.0f);
612         float height = std::max(event.numberReturnData[1].f32, 0.0f);
613         return { width, height };
614     };
615     frameNode->GetSpanItem()->onMeasure = onMeasureFunc;
616 }
617 
SetCustomSpanOnDraw(ArkUINodeHandle node,void * extraParam)618 void SetCustomSpanOnDraw(ArkUINodeHandle node, void* extraParam)
619 {
620     auto* frameNode = reinterpret_cast<CustomSpanNode*>(node);
621     CHECK_NULL_VOID(frameNode);
622     std::function<void(NG::DrawingContext&, CustomSpanOptions)> onDrawFunc =
623         [node, extraParam](NG::DrawingContext& context, CustomSpanOptions customSpanOptions) {
624         auto canvas = reinterpret_cast<uintptr_t>(&context.canvas);
625         ArkUICustomNodeEvent event;
626         event.kind = ArkUIAPINodeFlags::CUSTOM_DRAW;
627         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
628         event.data[NUM_0] = (ArkUI_Int32)(canvas & 0xffffffff);
629         event.data[NUM_1] =
630             (ArkUI_Int32)((static_cast<uint64_t>(canvas) >> NUM_32) & 0xffffffff);
631         event.data[NUM_2] = context.width;
632         event.data[NUM_3] = context.height;
633         event.canvas = reinterpret_cast<intptr_t>(&context.canvas);
634         event.numberData[0].f32 = customSpanOptions.x;
635         event.numberData[1].f32 = customSpanOptions.lineTop;
636         event.numberData[2].f32 = customSpanOptions.lineBottom;
637         event.numberData[3].f32 = customSpanOptions.baseline;
638         // clip
639         context.canvas.Save();
640         auto clipInnerRect = RSRect(0, 0, context.width, context.height);
641         context.canvas.ClipRect(clipInnerRect, RSClipOp::INTERSECT);
642         SendArkUIAsyncCustomEvent(&event);
643         context.canvas.Restore();
644     };
645     frameNode->GetSpanItem()->onDraw = onDrawFunc;
646 }
647 } // namespace NodeModifier
648 
649 } // namespace OHOS::Ace::NG
650