• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.. All rights reserved.
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 "hm_symbol_txt.h"
17 #include "modules/skparagraph/include/Paragraph.h"
18 #include "paragraph_impl.h"
19 
20 #include <algorithm>
21 #include <bitset>
22 #include <memory>
23 #include <string>
24 #include <tuple>
25 
26 #ifdef USE_M133_SKIA
27 #include "include/private/base/SkTArray.h"
28 #else
29 #include "include/private/SkTArray.h"
30 #endif // USE_M133_SKIA
31 
32 #include "paragraph_style.h"
33 #include "SkScalar.h"
34 #include "symbol_engine/hm_symbol_run.h"
35 #include "symbol_engine/hm_symbol_txt.h"
36 #include "text_font_utils.h"
37 #include "text_style.h"
38 
39 namespace OHOS {
40 namespace Rosen {
41 namespace SPText {
42 using PaintID = skt::ParagraphPainter::PaintID;
43 using ParagraphStyleFuncVector = std::vector<std::function<void(skt::Paragraph&, const ParagraphStyle&,
44     skt::InternalState&)>>;
45 using TextStyleFuncVector = std::vector<std::function<void(ParagraphImpl&, skt::Block&, const TextStyle&,
46     skt::InternalState&)>>;
47 using SymbolFuncVecotr = std::vector<std::function<void(const HMSymbolTxt&, std::shared_ptr<HMSymbolRun>&,
48     skt::InternalState&)>>;
49 
50 namespace {
51     ParagraphStyleFuncVector g_paragraphStyleHandlers = {
__anon1f1602b80202() 52         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
53             paragraph.getParagraphStyle().exportTextStyle().setFontSize(style.fontSize);
54 #ifdef USE_M133_SKIA
55             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
56 #else
57             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
58 #endif // USE_M133_SKIA
59             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
60                 textStyles.front().fStyle.setFontSize(style.fontSize);
61                 state = std::min(skt::InternalState::kIndexed, state);
62             }
63         },
64 
__anon1f1602b80302() 65         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
66             paragraph.getParagraphStyle().setTextDirection(static_cast<skt::TextDirection>(style.textDirection));
67             state = std::min(skt::InternalState::kIndexed, state);
68         },
69 
__anon1f1602b80402() 70         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
71             paragraph.getParagraphStyle().setMaxLines(style.maxLines);
72             state = std::min(skt::InternalState::kShaped, state);
73         },
74 
__anon1f1602b80502() 75         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
76             RSFontStyle skiaFontStyle = paragraph.getParagraphStyle().getTextStyle().getFontStyle();
77             RSFontStyle fontStyle{TextFontUtils::GetSkiaFontWeight(style.fontWeight),
78                 skiaFontStyle.GetWidth(), skiaFontStyle.GetSlant()};
79             paragraph.getParagraphStyle().exportTextStyle().setFontStyle(fontStyle);
80 #ifdef USE_M133_SKIA
81             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
82 #else
83             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
84 #endif // USE_M133_SKIA
85             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
86                 textStyles.front().fStyle.setFontStyle(fontStyle);
87                 state = std::min(skt::InternalState::kIndexed, state);
88             }
89         },
90 
__anon1f1602b80602() 91         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
92             RSFontStyle skiaFontStyle = paragraph.getParagraphStyle().getTextStyle().getFontStyle();
93             RSFontStyle fontStyle{skiaFontStyle.GetWeight(), skiaFontStyle.GetWidth(),
94                 TextFontUtils::GetSkiaFontSlant(style.fontStyle)};
95             paragraph.getParagraphStyle().exportTextStyle().setFontStyle(fontStyle);
96 #ifdef USE_M133_SKIA
97             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
98 #else
99             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
100 #endif // USE_M133_SKIA
101             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
102                 textStyles.front().fStyle.setFontStyle(fontStyle);
103                 state = std::min(skt::InternalState::kIndexed, state);
104             }
105         },
106 
__anon1f1602b80702() 107         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
108             std::vector<std::string> spFontFamiles {style.fontFamily};
109             std::vector<SkString> skiaFontFamiles = TextFontUtils::GetSkiaFontfamilies(spFontFamiles);
110             paragraph.getParagraphStyle().exportTextStyle().setFontFamilies(skiaFontFamiles);
111 #ifdef USE_M133_SKIA
112             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
113 #else
114             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
115 #endif // USE_M133_SKIA
116             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
117                 textStyles.front().fStyle.setFontFamilies(skiaFontFamiles);
118                 state = std::min(skt::InternalState::kIndexed, state);
119             }
120         },
121 
__anon1f1602b80802() 122         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
123             paragraph.getParagraphStyle().exportTextStyle().setHeight(style.height);
124 
125 #ifdef USE_M133_SKIA
126             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
127 #else
128             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
129 #endif // USE_M133_SKIA
130             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
131                 textStyles.front().fStyle.setHeight(style.height);
132             }
133 
134             if (!textStyles.front().fStyle.getHeightOverride()) {
135                 return;
136             }
137             state = std::min(skt::InternalState::kIndexed, state);
138         },
139 
__anon1f1602b80902() 140         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
141             paragraph.getParagraphStyle().exportTextStyle().setHeightOverride(style.heightOverride);
142 #ifdef USE_M133_SKIA
143             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
144 #else
145             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
146 #endif // USE_M133_SKIA
147             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
148                 textStyles.front().fStyle.setHeightOverride(style.heightOverride);
149                 state = std::min(skt::InternalState::kIndexed, state);
150             }
151         },
152 
__anon1f1602b80a02() 153         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
154             skt::TextStyle& skiaTextStyle =  paragraph.getParagraphStyle().exportTextStyle();
155             skiaTextStyle.setHalfLeading(style.halfLeading);
156 
157 #ifdef USE_M133_SKIA
158             skia_private::TArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
159 #else
160             SkTArray<skt::Block, true>& textStyles = paragraph.exportTextStyles();
161 #endif // USE_M133_SKIA
162             if (!textStyles.empty() && (textStyles.front().fStyle.getTextStyleUid() == style.defaultTextStyleUid)) {
163                 textStyles.front().fStyle.setHalfLeading(style.halfLeading);
164                 state = std::min(skt::InternalState::kIndexed, state);
165             }
166         },
167 
__anon1f1602b80b02() 168         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
169             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
170 
171             if (strutStyle.getStrutEnabled() == style.strutEnabled) {
172                 return;
173             }
174             strutStyle.setStrutEnabled(style.strutEnabled);
175             state = std::min(skt::InternalState::kIndexed, state);
176         },
177 
__anon1f1602b80c02() 178         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
179             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
180             RSFontStyle fontStyle = strutStyle.getFontStyle();
181             strutStyle.setFontStyle(RSFontStyle(TextFontUtils::GetSkiaFontWeight(style.strutFontWeight),
182                 fontStyle.GetWidth(), fontStyle.GetSlant()));
183 
184             if (!strutStyle.getStrutEnabled()) {
185                 return;
186             }
187             state = std::min(skt::InternalState::kIndexed, state);
188         },
189 
__anon1f1602b80d02() 190         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
191             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
192             RSFontStyle fontStyle = strutStyle.getFontStyle();
193             strutStyle.setFontStyle(RSFontStyle(fontStyle.GetWeight(),
194                 TextFontUtils::GetSkiaFontWidth(style.strutFontWidth), fontStyle.GetSlant()));
195 
196             if (!strutStyle.getStrutEnabled()) {
197                 return;
198             }
199             state = std::min(skt::InternalState::kIndexed, state);
200         },
201 
__anon1f1602b80e02() 202         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
203             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
204             RSFontStyle fontStyle = strutStyle.getFontStyle();
205             strutStyle.setFontStyle(RSFontStyle(fontStyle.GetWeight(),
206                 fontStyle.GetWidth(), TextFontUtils::GetSkiaFontSlant(style.strutFontStyle)));
207 
208             if (!strutStyle.getStrutEnabled()) {
209                 return;
210             }
211             state = std::min(skt::InternalState::kIndexed, state);
212         },
213 
__anon1f1602b80f02() 214         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
215             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
216             std::vector<SkString> skiaFontFamiles = TextFontUtils::GetSkiaFontfamilies(style.strutFontFamilies);
217             strutStyle.setFontFamilies(skiaFontFamiles);
218 
219             if (!strutStyle.getStrutEnabled()) {
220                 return;
221             }
222             state = std::min(skt::InternalState::kIndexed, state);
223         },
224 
__anon1f1602b81002() 225         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
226             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
227             strutStyle.setFontSize(style.strutFontSize);
228 
229             if (!strutStyle.getStrutEnabled()) {
230                 return;
231             }
232             state = std::min(skt::InternalState::kIndexed, state);
233         },
234 
__anon1f1602b81102() 235         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
236             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
237             strutStyle.setHeight(style.strutHeight);
238 
239             if (!strutStyle.getStrutEnabled()) {
240                 return;
241             }
242             state = std::min(skt::InternalState::kIndexed, state);
243         },
244 
__anon1f1602b81202() 245         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
246             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
247             strutStyle.setHeightOverride(style.strutHeightOverride);
248 
249             if (!strutStyle.getStrutEnabled()) {
250                 return;
251             }
252             state = std::min(skt::InternalState::kIndexed, state);
253         },
254 
__anon1f1602b81302() 255         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
256             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
257             strutStyle.setHalfLeading(style.strutHalfLeading);
258 
259             if (!strutStyle.getStrutEnabled()) {
260                 return;
261             }
262             state = std::min(skt::InternalState::kIndexed, state);
263         },
264 
__anon1f1602b81402() 265         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
266             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
267             strutStyle.setForceStrutHeight(style.strutHeight);
268 
269             if (!strutStyle.getStrutEnabled()) {
270                 return;
271             }
272             state = std::min(skt::InternalState::kIndexed, state);
273         },
274 
__anon1f1602b81502() 275         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
276             skt::StrutStyle& strutStyle =  paragraph.getParagraphStyle().exportStrutStyle();
277             strutStyle.setLineBreakStrategy(static_cast<skt::LineBreakStrategy>(style.breakStrategy));
278             state = std::min(skt::InternalState::kShaped, state);
279         },
280 
__anon1f1602b81602() 281         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
282             paragraph.getParagraphStyle().exportStrutStyle()
283                 .setWordBreakType(static_cast<skt::WordBreakType>(style.wordBreakType));
284             state = std::min(skt::InternalState::kShaped, state);
285         },
286 
__anon1f1602b81702() 287         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
288             paragraph.getParagraphStyle().setEllipsis(style.ellipsis.c_str());
289             state = std::min(skt::InternalState::kShaped, state);
290         },
291 
__anon1f1602b81802() 292         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
293             paragraph.getParagraphStyle().setEllipsisMod(static_cast<skt::EllipsisModal>(style.ellipsisModal));
294             state = std::min(skt::InternalState::kShaped, state);
295         },
296 
__anon1f1602b81902() 297         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
298             paragraph.updateTextAlign(static_cast<skt::TextAlign>(style.textAlign));
299             state = std::min(skt::InternalState::kShaped, state);
300         },
301 
__anon1f1602b81a02() 302         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
303             paragraph.getParagraphStyle().setParagraphSpacing(style.paragraphSpacing);
304             state = std::min(skt::InternalState::kShaped, state);
305         },
306 
__anon1f1602b81b02() 307         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
308             paragraph.getParagraphStyle().setIsEndAddParagraphSpacing(style.isEndAddParagraphSpacing);
309             state = std::min(skt::InternalState::kShaped, state);
310         },
311 
__anon1f1602b81c02() 312         [](skt::Paragraph& paragraph, const ParagraphStyle& style, skt::InternalState& state) {
313             paragraph.getParagraphStyle().setTextHeightBehavior(
314                 static_cast<skt::TextHeightBehavior>(style.textHeightBehavior));
315             state = std::min(skt::InternalState::kIndexed, state);
316         }
317     };
318 
319     TextStyleFuncVector g_textStyleHandlers = {
__anon1f1602b81d02() 320         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
321             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
322             skiaTextStyle.setFontSize(spTextStyle.fontSize);
323             state = std::min(skt::InternalState::kIndexed, state);
324         },
325 
__anon1f1602b81e02() 326         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
327             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
328             RSFontStyle skiaFontStyle = skiaTextStyle.getFontStyle();
329             skiaTextStyle.setFontStyle(RSFontStyle(TextFontUtils::GetSkiaFontWeight(spTextStyle.fontWeight),
330                 skiaFontStyle.GetWidth(), skiaFontStyle.GetSlant()));
331             FontVariations updateFontVariations;
332             updateFontVariations.SetAxisValue("wght", TextFontUtils::GetSkiaFontWeight(spTextStyle.fontWeight));
333             if (!updateFontVariations.GetAxisValues().empty()) {
334                 TextFontUtils::MakeFontArguments(skiaTextStyle, updateFontVariations);
335             }
336             state = std::min(skt::InternalState::kIndexed, state);
337         },
338 
__anon1f1602b81f02() 339         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
340             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
341             RSFontStyle skiaFontStyle = skiaTextStyle.getFontStyle();
342             skiaTextStyle.setFontStyle(RSFontStyle(skiaFontStyle.GetWeight(),
343                 TextFontUtils::GetSkiaFontWidth(spTextStyle.fontWidth), skiaFontStyle.GetSlant()));
344             state = std::min(skt::InternalState::kIndexed, state);
345         },
346 
__anon1f1602b82002() 347         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
348             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
349             RSFontStyle skiaFontStyle = skiaTextStyle.getFontStyle();
350             skiaTextStyle.setFontStyle(RSFontStyle(skiaFontStyle.GetWeight(), skiaFontStyle.GetWidth(),
351                 TextFontUtils::GetSkiaFontSlant(spTextStyle.fontStyle)));
352             state = std::min(skt::InternalState::kIndexed, state);
353         },
354 
__anon1f1602b82102() 355         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
356             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
357             std::vector<SkString> skiaFontFamiles = TextFontUtils::GetSkiaFontfamilies(spTextStyle.fontFamilies);
358             skiaTextStyle.setFontFamilies(skiaFontFamiles);
359             state = std::min(skt::InternalState::kIndexed, state);
360         },
361 
__anon1f1602b82202() 362         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
363             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
364             skiaTextStyle.setLetterSpacing(spTextStyle.letterSpacing);
365             state = std::min(skt::InternalState::kIndexed, state);
366         },
367 
__anon1f1602b82302() 368         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
369             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
370             skiaTextStyle.setWordSpacing(spTextStyle.wordSpacing);
371             state = std::min(skt::InternalState::kIndexed, state);
372         },
373 
__anon1f1602b82402() 374         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
375             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
376             skiaTextStyle.setHeightOverride(spTextStyle.heightOverride);
377             state = std::min(skt::InternalState::kIndexed, state);
378         },
379 
__anon1f1602b82502() 380         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
381             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
382             skiaTextStyle.setHeight(spTextStyle.height);
383             if (skiaTextStyle.getHeightOverride()) {
384                 state = std::min(skt::InternalState::kIndexed, state);
385             }
386         },
387 
__anon1f1602b82602() 388         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
389             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
390             skiaTextStyle.resetFontFeatures();
391             for (std::pair<std::string, int> spFontFeature: spTextStyle.fontFeatures.GetFontFeatures()) {
392                 skiaTextStyle.addFontFeature(static_cast<SkString>(spFontFeature.first.c_str()), spFontFeature.second);
393             }
394             state = std::min(skt::InternalState::kIndexed, state);
395         },
396 
__anon1f1602b82702() 397         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
398             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
399             if (!spTextStyle.fontVariations.GetAxisValues().empty()) {
400                 TextFontUtils::MakeFontArguments(skiaTextStyle, spTextStyle.fontVariations);
401                 state = std::min(skt::InternalState::kIndexed, state);
402             }
403         },
404 
__anon1f1602b82802() 405         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
406             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
407             skiaTextStyle.setBaselineShift(spTextStyle.baseLineShift);
408             state = std::min(skt::InternalState::kIndexed, state);
409         },
410 
__anon1f1602b82902() 411         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
412             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
413             skiaTextStyle.setDecoration(static_cast<skt::TextDecoration>(spTextStyle.decoration));
414             state = std::min(skt::InternalState::kFormatted, state);
415         },
416 
__anon1f1602b82a02() 417         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
418             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
419             skiaTextStyle.setDecorationColor(spTextStyle.decorationColor);
420             state = std::min(skt::InternalState::kFormatted, state);
421         },
422 
__anon1f1602b82b02() 423         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
424             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
425             skiaTextStyle.setDecorationStyle(static_cast<skt::TextDecorationStyle>(spTextStyle.decorationStyle));
426             state = std::min(skt::InternalState::kFormatted, state);
427         },
428 
__anon1f1602b82c02() 429         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
430             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
431             skiaTextStyle.setDecorationThicknessMultiplier(SkDoubleToScalar(spTextStyle.decorationThicknessMultiplier));
432             state = std::min(skt::InternalState::kFormatted, state);
433         },
434 
__anon1f1602b82d02() 435         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
436             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
437             skiaTextStyle.setBackgroundRect({spTextStyle.backgroundRect.color, spTextStyle.backgroundRect.leftTopRadius,
438                 spTextStyle.backgroundRect.rightTopRadius, spTextStyle.backgroundRect.rightBottomRadius,
439                 spTextStyle.backgroundRect.leftBottomRadius});
440             if (paragraph.isRunCombinated()) {
441                 state = std::min(skt::InternalState::kIndexed, state);
442                 return;
443             }
444             state = std::min(skt::InternalState::kFormatted, state);
445         },
446 
__anon1f1602b82e02() 447         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
448             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
449             skiaTextStyle.setStyleId(spTextStyle.styleId);
450             state = std::min(skt::InternalState::kFormatted, state);
451         },
452 
__anon1f1602b82f02() 453         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
454             skt::TextRange textRange = skiaBlock.fRange;
455             paragraph.UpdateColor(textRange.start, textRange.end, spTextStyle.color, skt::UtfEncodeType::kUtf16);
456             state = std::min(skt::InternalState::kFormatted, state);
457         },
458 
__anon1f1602b83002() 459         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
460             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
461             bool hasShadow = skiaTextStyle.getShadowNumber() > 0;
462             skiaTextStyle.resetShadows();
463             for (const TextShadow& txtShadow : spTextStyle.textShadows) {
464                 skiaTextStyle.addShadow(TextFontUtils::MakeTextShadow(txtShadow));
465             }
466             if (hasShadow && spTextStyle.textShadows.size() > 0) {
467                 state = std::min(skt::InternalState::kFormatted, state);
468                 return;
469             }
470             state = std::min(skt::InternalState::kShaped, state);
471         },
472 
__anon1f1602b83102() 473         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
474             skt::TextStyle& skiaTextStyle = skiaBlock.fStyle;
475             skiaTextStyle.setHalfLeading(spTextStyle.halfLeading);
476             state = std::min(skt::InternalState::kIndexed, state);
477         },
478 
__anon1f1602b83202() 479         [](ParagraphImpl& paragraph, skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state) {
480             std::ignore = skiaBlock;
481             std::ignore = state;
482             paragraph.UpdateForegroundBrush(spTextStyle);
483         },
484     };
485 
486     SymbolFuncVecotr g_symbolStyleHandlers = {
__anon1f1602b83302() 487         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
488             symbolRun->SetSymbolEffect(symbolStyle.GetEffectStrategy());
489         },
__anon1f1602b83402() 490         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
491             symbolRun->SetAnimationMode(symbolStyle.GetAnimationMode());
492         },
__anon1f1602b83502() 493         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
494             symbolRun->SetAnimationStart(symbolStyle.GetAnimationStart());
495         },
__anon1f1602b83602() 496         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
497             symbolRun->SetCommonSubType(symbolStyle.GetCommonSubType());
498         },
__anon1f1602b83702() 499         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
500             symbolRun->SetSymbolColor(symbolStyle.GetSymbolColor());
501         },
__anon1f1602b83802() 502         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
503             symbolRun->SetRenderMode(symbolStyle.GetRenderMode());
504         },
__anon1f1602b83902() 505         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
506             symbolRun->SetSymbolColor(symbolStyle.GetSymbolColor());
507         },
__anon1f1602b83a02() 508         [](const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& symbolRun, skt::InternalState& state) {
509             symbolRun->SetSymbolShadow(symbolStyle.GetSymbolShadow());
510         },
511     };
512 }
513 
ParagraphStyleUpdater(skt::Paragraph & skiaParagraph,const ParagraphStyle & spParagraphStyle,skt::InternalState & state)514 void ParagraphImpl::ParagraphStyleUpdater(skt::Paragraph& skiaParagraph, const ParagraphStyle& spParagraphStyle,
515     skt::InternalState& state)
516 {
517     const std::bitset<static_cast<size_t>(RelayoutParagraphStyleAttribute::PARAGRAPH_STYLE_ATTRIBUTE_BUTT)>&
518         paragraphStyleChangeBitmap = spParagraphStyle.relayoutChangeBitmap;
519     if (!paragraphStyleChangeBitmap.any()) {
520         return;
521     }
522 
523     for (size_t i = 0; i < paragraphStyleChangeBitmap.size(); ++i) {
524         if (!paragraphStyleChangeBitmap.test(i)) {
525             continue;
526         }
527         g_paragraphStyleHandlers[i](skiaParagraph, spParagraphStyle, state);
528     }
529 }
530 
TextStyleUpdater(skt::Block & skiaBlock,const TextStyle & spTextStyle,skt::InternalState & state)531 void ParagraphImpl::TextStyleUpdater(skt::Block& skiaBlock, const TextStyle& spTextStyle, skt::InternalState& state)
532 {
533     const std::bitset<static_cast<size_t>(RelayoutTextStyleAttribute::TEXT_STYLE_ATTRIBUTE_BUTT)>&
534         relayoutChangeBitmap = spTextStyle.relayoutChangeBitmap;
535 
536     for (size_t i = 0; i < relayoutChangeBitmap.size(); ++i) {
537         if (!relayoutChangeBitmap.test(i)) {
538             continue;
539         }
540 
541         g_textStyleHandlers[i](*this, skiaBlock, spTextStyle, state);
542     }
543 }
544 
UpdateSymbolRun(const HMSymbolTxt & symbolStyle,std::shared_ptr<HMSymbolRun> & hmSymbolRun,skt::InternalState & state,size_t index)545 void ParagraphImpl::UpdateSymbolRun(const HMSymbolTxt& symbolStyle, std::shared_ptr<HMSymbolRun>& hmSymbolRun,
546     skt::InternalState& state, size_t index)
547 {
548     if (hmSymbolRun->GetSymbolUid() != symbolStyle.GetSymbolUid()) {
549         return;
550     }
551 
552     g_symbolStyleHandlers[index](symbolStyle, hmSymbolRun, state);
553     for (PaintRecord& p : paints_) {
554         if (p.symbol.GetSymbolUid() != hmSymbolRun->GetSymbolUid()) {
555             continue;
556         }
557         p.symbol = hmSymbolRun->GetSymbolTxt();
558     }
559 }
560 
SymbolStyleUpdater(const HMSymbolTxt & symbolStyle,std::vector<std::shared_ptr<HMSymbolRun>> & hmSymbolRuns,skt::InternalState & state)561 void ParagraphImpl::SymbolStyleUpdater(const HMSymbolTxt& symbolStyle, std::vector<std::shared_ptr<HMSymbolRun>>&
562     hmSymbolRuns, skt::InternalState& state)
563 {
564     const SymbolBitmapType& symbolStyleBitmap = symbolStyle.GetSymbolBitmap();
565 
566     for (size_t i = 0; i < symbolStyleBitmap.size(); ++i) {
567         if (!symbolStyleBitmap.test(i)) {
568             continue;
569         }
570 
571         for (size_t j = 0; j < hmSymbolRuns.size(); ++j) {
572             UpdateSymbolRun(symbolStyle, hmSymbolRuns[j], state, i);
573         }
574     }
575 }
576 
ApplyParagraphStyleChanges(const ParagraphStyle & style)577 void ParagraphImpl::ApplyParagraphStyleChanges(const ParagraphStyle& style)
578 {
579     if (paragraph_ == nullptr) {
580         return;
581     }
582 
583     skt::InternalState state = paragraph_->getState();
584     ParagraphStyleUpdater(*paragraph_, style, state);
585     paragraph_->setState(state);
586 }
587 
ApplyTextStyleChanges(const std::vector<TextStyle> & textStyles)588 void ParagraphImpl::ApplyTextStyleChanges(const std::vector<TextStyle>& textStyles)
589 {
590     if (paragraph_ == nullptr) {
591         return;
592     }
593 #ifdef USE_M133_SKIA
594     skia_private::TArray<skt::Block, true>& skiaTextStyles = paragraph_->exportTextStyles();
595 #else
596     SkTArray<skt::Block, true>& skiaTextStyles = paragraph_->exportTextStyles();
597 #endif // USE_M133_SKIA
598 
599     skt::InternalState state = paragraph_->getState();
600 
601     for (size_t i = 0; i < textStyles.size(); ++i) {
602         const TextStyle& spTextStyle = textStyles[i];
603         size_t spTextStyleUid = spTextStyle.textStyleUid;
604 
605         for (size_t j = 0; j < skiaTextStyles.size(); ++j) {
606             skt::Block& skiaBlock = skiaTextStyles[j];
607             size_t skiaTextStyleUid = skiaBlock.fStyle.getTextStyleUid();
608             if (skiaTextStyleUid != spTextStyleUid) {
609                 continue;
610             }
611 
612             if (spTextStyle.isSymbolGlyph && spTextStyle.symbol.GetSymbolBitmap().any()) {
613                 SymbolStyleUpdater(spTextStyle.symbol, hmSymbols_, state);
614             }
615 
616             if (spTextStyle.relayoutChangeBitmap.any()) {
617                 TextStyleUpdater(skiaBlock, spTextStyle, state);
618             }
619         }
620     }
621     paragraph_->setState(state);
622 }
623 
Relayout(double width,const ParagraphStyle & paragrahStyle,const std::vector<TextStyle> & textStyles)624 void ParagraphImpl::Relayout(double width, const ParagraphStyle& paragrahStyle,
625     const std::vector<TextStyle>& textStyles)
626 {
627     lineMetrics_.reset();
628     lineMetricsStyles_.clear();
629     ApplyParagraphStyleChanges(paragrahStyle);
630     ApplyTextStyleChanges(textStyles);
631     paragraph_->layout(width);
632 }
633 } // namespace SPText
634 } // namespace Rosen
635 } // namespace OHOS