Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | #ifndef ParagraphStyle_DEFINED |
| 3 | #define ParagraphStyle_DEFINED |
| 4 | |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 5 | #include "include/core/SkFontStyle.h" |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 6 | #include "modules/skparagraph/include/DartTypes.h" |
| 7 | #include "modules/skparagraph/include/TextStyle.h" |
Mike Klein | 48e08aa | 2019-08-26 11:24:50 -0500 | [diff] [blame] | 8 | #include <string> // std::u16string |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 9 | |
| 10 | namespace skia { |
| 11 | namespace textlayout { |
| 12 | |
| 13 | struct StrutStyle { |
| 14 | StrutStyle(); |
| 15 | |
| 16 | const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; } |
| 17 | void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); } |
| 18 | |
| 19 | SkFontStyle getFontStyle() const { return fFontStyle; } |
| 20 | void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; } |
| 21 | |
| 22 | SkScalar getFontSize() const { return fFontSize; } |
| 23 | void setFontSize(SkScalar size) { fFontSize = size; } |
| 24 | |
| 25 | void setHeight(SkScalar height) { fHeight = height; } |
| 26 | SkScalar getHeight() const { return fHeight; } |
| 27 | |
| 28 | void setLeading(SkScalar Leading) { fLeading = Leading; } |
| 29 | SkScalar getLeading() const { return fLeading; } |
| 30 | |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 31 | bool getStrutEnabled() const { return fEnabled; } |
| 32 | void setStrutEnabled(bool v) { fEnabled = v; } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 33 | |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 34 | bool getForceStrutHeight() const { return fForceHeight; } |
| 35 | void setForceStrutHeight(bool v) { fForceHeight = v; } |
| 36 | |
| 37 | bool getHeightOverride() const { return fHeightOverride; } |
| 38 | void setHeightOverride(bool v) { fHeightOverride = v; } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 39 | |
Julia Lavrova | c036058 | 2020-02-05 10:17:53 -0500 | [diff] [blame] | 40 | bool operator==(const StrutStyle& rhs) const { |
| 41 | return this->fEnabled == rhs.fEnabled && |
| 42 | this->fHeightOverride == rhs.fHeightOverride && |
| 43 | this->fForceHeight == rhs.fForceHeight && |
| 44 | nearlyEqual(this->fLeading, rhs.fLeading) && |
| 45 | nearlyEqual(this->fHeight, rhs.fHeight) && |
| 46 | nearlyEqual(this->fFontSize, rhs.fFontSize) && |
| 47 | this->fFontStyle == rhs.fFontStyle && |
| 48 | this->fFontFamilies == rhs.fFontFamilies; |
| 49 | } |
| 50 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 51 | private: |
| 52 | |
| 53 | std::vector<SkString> fFontFamilies; |
| 54 | SkFontStyle fFontStyle; |
| 55 | SkScalar fFontSize; |
| 56 | SkScalar fHeight; |
| 57 | SkScalar fLeading; |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame] | 58 | bool fForceHeight; |
| 59 | bool fEnabled; |
| 60 | bool fHeightOverride; |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct ParagraphStyle { |
| 64 | ParagraphStyle(); |
| 65 | |
| 66 | bool operator==(const ParagraphStyle& rhs) const { |
| 67 | return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis && |
| 68 | this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign && |
| 69 | this->fDefaultTextStyle == rhs.fDefaultTextStyle; |
| 70 | } |
| 71 | |
| 72 | const StrutStyle& getStrutStyle() const { return fStrutStyle; } |
| 73 | void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); } |
| 74 | |
| 75 | const TextStyle& getTextStyle() const { return fDefaultTextStyle; } |
| 76 | void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; } |
| 77 | |
| 78 | TextDirection getTextDirection() const { return fTextDirection; } |
| 79 | void setTextDirection(TextDirection direction) { fTextDirection = direction; } |
| 80 | |
| 81 | TextAlign getTextAlign() const { return fTextAlign; } |
| 82 | void setTextAlign(TextAlign align) { fTextAlign = align; } |
| 83 | |
| 84 | size_t getMaxLines() const { return fLinesLimit; } |
| 85 | void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; } |
| 86 | |
| 87 | const SkString& getEllipsis() const { return fEllipsis; } |
| 88 | void setEllipsis(const std::u16string& ellipsis); |
Kevin Lubick | d3b1fe6 | 2019-10-21 10:50:26 -0400 | [diff] [blame] | 89 | void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 90 | |
| 91 | SkScalar getHeight() const { return fHeight; } |
| 92 | void setHeight(SkScalar height) { fHeight = height; } |
| 93 | |
Julia Lavrova | 9588a64 | 2020-04-30 11:31:25 -0400 | [diff] [blame^] | 94 | |
| 95 | TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; } |
| 96 | void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; } |
| 97 | |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 98 | bool unlimited_lines() const { |
| 99 | return fLinesLimit == std::numeric_limits<size_t>::max(); |
| 100 | } |
| 101 | bool ellipsized() const { return fEllipsis.size() != 0; } |
| 102 | TextAlign effective_align() const; |
| 103 | bool hintingIsOn() const { return fHintingIsOn; } |
| 104 | void turnHintingOff() { fHintingIsOn = false; } |
| 105 | |
| 106 | private: |
| 107 | StrutStyle fStrutStyle; |
| 108 | TextStyle fDefaultTextStyle; |
| 109 | TextAlign fTextAlign; |
| 110 | TextDirection fTextDirection; |
| 111 | size_t fLinesLimit; |
| 112 | SkString fEllipsis; |
| 113 | SkScalar fHeight; |
Julia Lavrova | 9588a64 | 2020-04-30 11:31:25 -0400 | [diff] [blame^] | 114 | TextHeightBehavior fTextHeightBehavior; |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 115 | bool fHintingIsOn; |
| 116 | }; |
| 117 | } // namespace textlayout |
| 118 | } // namespace skia |
| 119 | |
| 120 | #endif // ParagraphStyle_DEFINED |