1 /* 2 * Copyright (c) 2023 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 #ifndef ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H 17 #define ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H 18 19 #include <string> 20 #include <vector> 21 22 #include "text_style.h" 23 #include "typography_types.h" 24 #include "modules/skparagraph/include/TextStyle.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 struct TypographyStyle { 29 const static inline std::u16string ELLIPSIS = u"\u2026"; 30 31 FontWeight fontWeight = FontWeight::W400; 32 FontWidth fontWidth = FontWidth::NORMAL; 33 FontStyle fontStyle = FontStyle::NORMAL; 34 std::string fontFamily = ""; 35 double fontSize = 14.0; // default is libtxt text style fonst size 36 double heightScale = 1.0; 37 bool halfLeading = false; 38 bool heightOnly = false; 39 bool useLineStyle = false; 40 41 FontWeight lineStyleFontWeight = FontWeight::W400; 42 FontWidth lineStyleFontWidth = FontWidth::NORMAL; 43 FontStyle lineStyleFontStyle = FontStyle::NORMAL; 44 std::vector<std::string> lineStyleFontFamilies; 45 double lineStyleFontSize = 14.0; // default is libtxt text style font size 46 double lineStyleHeightScale = 1.0; 47 bool lineStyleHeightOnlyInit = false; 48 bool lineStyleHeightOnly = false; 49 bool lineStyleHalfLeading = false; 50 double lineStyleSpacingScale = -1.0; 51 bool lineStyleOnly = false; 52 53 TextAlign textAlign = TextAlign::START; 54 TextDirection textDirection = TextDirection::LTR; 55 size_t maxLines = 1e9; 56 std::u16string ellipsis; 57 std::string locale; 58 59 BreakStrategy breakStrategy = BreakStrategy::GREEDY; 60 WordBreakType wordBreakType = WordBreakType::BREAK_WORD; 61 EllipsisModal ellipsisModal = EllipsisModal::TAIL; 62 float textSplitRatio = 0.5f; 63 64 bool operator==(const TypographyStyle &rhs) const 65 { 66 return 67 this->ELLIPSIS == rhs.ELLIPSIS && 68 this->fontWeight == rhs.fontWeight && 69 this->fontStyle == rhs.fontStyle && 70 this->fontFamily == rhs.fontFamily && 71 skia::textlayout::nearlyEqual(this->fontSize, rhs.fontSize) && 72 skia::textlayout::nearlyEqual(this->heightScale, rhs.heightScale) && 73 this->halfLeading == rhs.halfLeading && 74 this->heightOnly == rhs.heightOnly && 75 this->useLineStyle == rhs.useLineStyle && 76 this->lineStyleFontWeight == rhs.lineStyleFontWeight && 77 this->lineStyleFontStyle == rhs.lineStyleFontStyle && 78 this->lineStyleFontFamilies == rhs.lineStyleFontFamilies && 79 skia::textlayout::nearlyEqual(this->lineStyleFontSize, rhs.lineStyleFontSize) && 80 skia::textlayout::nearlyEqual(this->lineStyleHeightScale, rhs.lineStyleHeightScale) && 81 this->lineStyleHeightOnlyInit == rhs.lineStyleHeightOnlyInit && 82 this->lineStyleHeightOnly == rhs.lineStyleHeightOnly && 83 this->lineStyleHalfLeading == rhs.lineStyleHalfLeading && 84 skia::textlayout::nearlyEqual(this->lineStyleSpacingScale, rhs.lineStyleSpacingScale) && 85 this->lineStyleOnly == rhs.lineStyleOnly && 86 this->textAlign == rhs.textAlign && 87 this->textDirection == rhs.textDirection && 88 this->maxLines == rhs.maxLines && 89 this->ellipsis == rhs.ellipsis && 90 this->locale == rhs.locale && 91 this->breakStrategy == rhs.breakStrategy && 92 this->wordBreakType == rhs.wordBreakType && 93 this->ellipsisModal == rhs.ellipsisModal && 94 skia::textlayout::nearlyEqual(this->textSplitRatio, rhs.textSplitRatio); 95 } 96 TextStyle GetTextStyle() const; 97 void SetTextStyle(TextStyle& textstyle); 98 TextAlign GetEffectiveAlign() const; 99 bool IsUnlimitedLines() const; 100 bool IsEllipsized() const; EllipsizedTypographyStyle101 bool Ellipsized() const 102 { 103 return !ellipsis.empty(); 104 } 105 TextStyle insideTextStyle; 106 bool customTextStyle = false; 107 TextHeightBehavior textHeightBehavior = TextHeightBehavior::ALL; 108 bool hintingIsOn = false; 109 }; 110 } // namespace Rosen 111 } // namespace OHOS 112 #endif // ROSEN_TEXT_EXPORT_ROSEN_TEXT_TYPOGRAPHY_STYLE_H 113