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 halfLeading = false; 43 bool heightOnly = false; 44 std::string locale; 45 46 // multi-text 47 size_t maxLines = std::numeric_limits<size_t>::max(); 48 std::u16string ellipsis; 49 BreakStrategy breakStrategy = BreakStrategy::GREEDY; 50 WordBreakType wordBreakType = WordBreakType::BREAK_WORD; 51 TextAlign align = TextAlign::START; 52 TextDirection direction = TextDirection::LTR; 53 EllipsisModal ellipsisModal = EllipsisModal::TAIL; 54 55 // lineStyle 56 bool useLineStyle = false; 57 struct LineStyle { 58 bool only = false; 59 FontWeight fontWeight = FontWeight::W400; 60 FontStyle fontStyle = FontStyle::NORMAL; 61 std::vector<std::string> fontFamilies = {}; 62 bool halfLeading = false; 63 bool heightOnly = false; 64 double fontSize = 16.0; 65 double heightScale = 1; 66 std::optional<double> spacingScale = std::nullopt; 67 } lineStyle; 68 69 float textSplitRatio = 0.5f; 70 71 /* 72 * @brief Returns the equivalent align by TextAlign and TextDirection. 73 */ 74 TextAlign GetEquivalentAlign() const; 75 76 /* 77 * @brief Returns the default TextStyle. 78 */ 79 TextStyle ConvertToTextStyle() const; 80 }; 81 } // namespace TextEngine 82 } // namespace Rosen 83 } // namespace OHOS 84 85 #endif // ROSEN_MODULES_TEXGINE_EXPORT_TEXGINE_TYPOGRAPHY_STYLE_H 86