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 16 #ifndef ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TYPOGRAPHY_STYLE_H 17 #define ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TYPOGRAPHY_STYLE_H 18 19 #include <memory> 20 #include <optional> 21 #include <string> 22 #include <vector> 23 24 #include "texgine/font_providers.h" 25 #include "texgine/text_style.h" 26 #include "texgine/typography_types.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace TextEngine { 31 /* 32 * @brief TypographyStyle is a collection of parameters that control how Typography is displayed, 33 * including parameters for default TextStyle, multi-text, and line style. 34 */ 35 struct TypographyStyle { 36 // default TextStyle 37 FontWeight fontWeight = FontWeight::W400; 38 FontStyle fontStyle = FontStyle::NORMAL; 39 std::vector<std::string> fontFamilies = {}; 40 double fontSize = 16.0; 41 double heightScale = 1.0; 42 bool heightOnly = false; 43 std::string locale; 44 45 // multi-text 46 size_t maxLines = 1e9; 47 std::u16string ellipsis = u"..."; 48 BreakStrategy breakStrategy = BreakStrategy::GREEDY; 49 WordBreakType wordBreakType = WordBreakType::BREAK_WORD; 50 TextAlign align = TextAlign::START; 51 TextDirection direction = TextDirection::LTR; 52 53 // lineStyle 54 bool useLineStyle = false; 55 struct LineStyle { 56 bool only = false; 57 FontWeight fontWeight = FontWeight::W400; 58 FontStyle fontStyle = FontStyle::NORMAL; 59 std::vector<std::string> fontFamilies = {}; 60 bool heightOnly = false; 61 double fontSize = 16.0; 62 double heightScale = 1; 63 std::optional<double> spacingScale = std::nullopt; 64 } lineStyle; 65 66 /* 67 * @brief Returns the equivalent align by TextAlign and TextDirection. 68 */ 69 TextAlign GetEquivalentAlign() const; 70 71 /* 72 * @brief Returns the default TextStyle. 73 */ 74 TextStyle ConvertToTextStyle() const; 75 }; 76 } // namespace TextEngine 77 } // namespace Rosen 78 } // namespace OHOS 79 80 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TYPOGRAPHY_STYLE_H 81