• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_UTILS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_UTILS_H
18 
19 namespace OHOS::Ace::NG {
20 
ToBriefString(const TextStyle & style,const ImageSpanAttribute & imageStyle,struct UpdateSpanStyle opt)21 static std::string ToBriefString(const TextStyle& style, const ImageSpanAttribute& imageStyle,
22     struct UpdateSpanStyle opt)
23 {
24     std::stringstream ss;
25     /* text style */
26     ss << "te={";
27     IF_TRUE(opt.updateTextColor, ss << style.GetTextColor().ToString() << ",");
28     IF_TRUE(opt.updateFontSize, ss << "FS" << style.GetFontSize().ConvertToFp() << ",");
29     IF_TRUE(opt.updateItalicFontStyle, ss << StringUtils::ToString(style.GetFontStyle()) << ",");
30     IF_TRUE(opt.updateFontWeight, ss << StringUtils::ToString(style.GetFontWeight()) << ",");
31     IF_TRUE(opt.updateTextDecoration, ss << StringUtils::ToString(style.GetTextDecoration()) << ",");
32     IF_TRUE(opt.updateLineHeight, ss << "LH" << style.GetLineHeight().ConvertToFp() << ",");
33     IF_TRUE(opt.updateLetterSpacing, ss << "LS" << style.GetLetterSpacing().ConvertToFp() << ",");
34     ss << "},";
35 
36     /* symbol style */
37     ss << "sb={";
38     IF_TRUE(opt.updateSymbolFontSize, ss << opt.updateSymbolFontSize->ConvertToFp() << ",");
39     IF_TRUE(opt.updateSymbolFontWeight, ss  << StringUtils::ToString(*opt.updateSymbolFontWeight) << ",");
40     IF_TRUE(opt.updateSymbolRenderingStrategy, ss << "RS" << *opt.updateSymbolRenderingStrategy  << ",");
41     IF_TRUE(opt.updateSymbolEffectStrategy, ss << "ES" << *opt.updateSymbolEffectStrategy  << ",");
42     ss << "},";
43 
44     /* image style */
45     ss << "im={[";
46     IF_TRUE(opt.updateImageWidth, ss << opt.updateImageWidth->ToString() << ",");
47     IF_TRUE(opt.updateImageHeight, ss << opt.updateImageHeight->ToString());
48     ss << "],";
49     IF_TRUE(opt.updateImageFit, ss << StringUtils::ToString(*opt.updateImageFit) << ",");
50     IF_TRUE(opt.updateImageVerticalAlign, ss << StringUtils::ToString(*opt.updateImageVerticalAlign) << ",");
51     ss << "}";
52     return ss.str();
53 }
54 
ToBriefString(const TextStyle & style)55 static std::string ToBriefString(const TextStyle& style)
56 {
57     std::stringstream ss;
58     ss << "{";
59     ss << style.GetTextColor().ToString() << ",";
60     ss << "FS" << style.GetFontSize().ConvertToFp() << ",";
61     ss << StringUtils::ToString(style.GetFontStyle()) << ",";
62     ss << StringUtils::ToString(style.GetFontWeight()) << ",";
63     ss << StringUtils::ToString(style.GetTextDecoration()) << ",";
64     ss << "LH" << style.GetLineHeight().ConvertToFp() << ",";
65     ss << "LS" << style.GetLetterSpacing().ConvertToFp();
66     ss << "}";
67     return ss.str();
68 }
69 
ToBriefString(const TextSpanOptions & opts)70 static std::string ToBriefString(const TextSpanOptions& opts)
71 {
72     std::stringstream ss;
73     ss << "{";
74     ss << "index=" << opts.offset.value_or(-1) << ", ";
75     ss << "len=" << opts.value.size() << ", ";
76     if (opts.style) {
77         ss << "ts=" << ToBriefString(opts.style.value()) << ", ";
78     }
79     if (opts.paraStyle) {
80         ss << "ps={" << opts.paraStyle->ToString() << "}, ";
81     }
82     ss << "themeFC=" << static_cast<int32_t>(opts.useThemeFontColor);
83     ss << "}";
84     return ss.str();
85 }
86 
87 }
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RICH_EDITOR_UTILS_H