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