1 /*
2 * Copyright (c) 2022 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 "core/components_ng/pattern/text/text_styles.h"
17
18 namespace OHOS::Ace::NG {
19 #define UPDATE_TEXT_STYLE(group, name, func) \
20 do { \
21 if ((group)->prop##name.has_value()) { \
22 textStyle.func((group)->prop##name.value()); \
23 } \
24 } while (false)
25
CreateTextStyleUsingTheme(const std::unique_ptr<FontStyle> & fontStyle,const std::unique_ptr<TextLineStyle> & textLineStyle,const RefPtr<TextTheme> & textTheme)26 TextStyle CreateTextStyleUsingTheme(const std::unique_ptr<FontStyle>& fontStyle,
27 const std::unique_ptr<TextLineStyle>& textLineStyle, const RefPtr<TextTheme>& textTheme)
28 {
29 TextStyle textStyle = textTheme ? textTheme->GetTextStyle() : TextStyle();
30 if (fontStyle) {
31 UPDATE_TEXT_STYLE(fontStyle, FontSize, SetFontSize);
32 UPDATE_TEXT_STYLE(fontStyle, TextColor, SetTextColor);
33 UPDATE_TEXT_STYLE(fontStyle, ItalicFontStyle, SetFontStyle);
34 UPDATE_TEXT_STYLE(fontStyle, FontWeight, SetFontWeight);
35 UPDATE_TEXT_STYLE(fontStyle, FontFamily, SetFontFamilies);
36 UPDATE_TEXT_STYLE(fontStyle, TextDecoration, SetTextDecoration);
37 UPDATE_TEXT_STYLE(fontStyle, TextDecorationColor, SetTextDecorationColor);
38 UPDATE_TEXT_STYLE(fontStyle, TextCase, SetTextCase);
39 UPDATE_TEXT_STYLE(fontStyle, AdaptMinFontSize, SetAdaptMinFontSize);
40 UPDATE_TEXT_STYLE(fontStyle, AdaptMaxFontSize, SetAdaptMaxFontSize);
41 UPDATE_TEXT_STYLE(fontStyle, LetterSpacing, SetLetterSpacing);
42 }
43 if (textLineStyle) {
44 UPDATE_TEXT_STYLE(textLineStyle, LineHeight, SetLineHeight);
45 UPDATE_TEXT_STYLE(textLineStyle, TextBaseline, SetTextBaseline);
46 UPDATE_TEXT_STYLE(textLineStyle, BaselineOffset, SetBaselineOffset);
47 UPDATE_TEXT_STYLE(textLineStyle, TextOverflow, SetTextOverflow);
48 UPDATE_TEXT_STYLE(textLineStyle, TextAlign, SetTextAlign);
49 UPDATE_TEXT_STYLE(textLineStyle, MaxLines, SetMaxLines);
50 }
51 return textStyle;
52 }
53 } // namespace OHOS::Ace::NG
54