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" |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 8 | |
| 9 | namespace skia { |
| 10 | namespace textlayout { |
| 11 | |
| 12 | struct StrutStyle { |
| 13 | StrutStyle(); |
| 14 | |
| 15 | const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; } |
| 16 | void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); } |
| 17 | |
| 18 | SkFontStyle getFontStyle() const { return fFontStyle; } |
| 19 | void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; } |
| 20 | |
| 21 | SkScalar getFontSize() const { return fFontSize; } |
| 22 | void setFontSize(SkScalar size) { fFontSize = size; } |
| 23 | |
| 24 | void setHeight(SkScalar height) { fHeight = height; } |
| 25 | SkScalar getHeight() const { return fHeight; } |
| 26 | |
| 27 | void setLeading(SkScalar Leading) { fLeading = Leading; } |
| 28 | SkScalar getLeading() const { return fLeading; } |
| 29 | |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame^] | 30 | bool getStrutEnabled() const { return fEnabled; } |
| 31 | void setStrutEnabled(bool v) { fEnabled = v; } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 32 | |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame^] | 33 | bool getForceStrutHeight() const { return fForceHeight; } |
| 34 | void setForceStrutHeight(bool v) { fForceHeight = v; } |
| 35 | |
| 36 | bool getHeightOverride() const { return fHeightOverride; } |
| 37 | void setHeightOverride(bool v) { fHeightOverride = v; } |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 38 | |
| 39 | private: |
| 40 | |
| 41 | std::vector<SkString> fFontFamilies; |
| 42 | SkFontStyle fFontStyle; |
| 43 | SkScalar fFontSize; |
| 44 | SkScalar fHeight; |
| 45 | SkScalar fLeading; |
Julia Lavrova | db9f669 | 2019-08-01 16:02:17 -0400 | [diff] [blame^] | 46 | bool fForceHeight; |
| 47 | bool fEnabled; |
| 48 | bool fHeightOverride; |
Julia Lavrova | a3552c5 | 2019-05-30 16:12:56 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct ParagraphStyle { |
| 52 | ParagraphStyle(); |
| 53 | |
| 54 | bool operator==(const ParagraphStyle& rhs) const { |
| 55 | return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis && |
| 56 | this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign && |
| 57 | this->fDefaultTextStyle == rhs.fDefaultTextStyle; |
| 58 | } |
| 59 | |
| 60 | const StrutStyle& getStrutStyle() const { return fStrutStyle; } |
| 61 | void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); } |
| 62 | |
| 63 | const TextStyle& getTextStyle() const { return fDefaultTextStyle; } |
| 64 | void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; } |
| 65 | |
| 66 | TextDirection getTextDirection() const { return fTextDirection; } |
| 67 | void setTextDirection(TextDirection direction) { fTextDirection = direction; } |
| 68 | |
| 69 | TextAlign getTextAlign() const { return fTextAlign; } |
| 70 | void setTextAlign(TextAlign align) { fTextAlign = align; } |
| 71 | |
| 72 | size_t getMaxLines() const { return fLinesLimit; } |
| 73 | void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; } |
| 74 | |
| 75 | const SkString& getEllipsis() const { return fEllipsis; } |
| 76 | void setEllipsis(const std::u16string& ellipsis); |
| 77 | |
| 78 | SkScalar getHeight() const { return fHeight; } |
| 79 | void setHeight(SkScalar height) { fHeight = height; } |
| 80 | |
| 81 | bool unlimited_lines() const { |
| 82 | return fLinesLimit == std::numeric_limits<size_t>::max(); |
| 83 | } |
| 84 | bool ellipsized() const { return fEllipsis.size() != 0; } |
| 85 | TextAlign effective_align() const; |
| 86 | bool hintingIsOn() const { return fHintingIsOn; } |
| 87 | void turnHintingOff() { fHintingIsOn = false; } |
| 88 | |
| 89 | private: |
| 90 | StrutStyle fStrutStyle; |
| 91 | TextStyle fDefaultTextStyle; |
| 92 | TextAlign fTextAlign; |
| 93 | TextDirection fTextDirection; |
| 94 | size_t fLinesLimit; |
| 95 | SkString fEllipsis; |
| 96 | SkScalar fHeight; |
| 97 | bool fHintingIsOn; |
| 98 | }; |
| 99 | } // namespace textlayout |
| 100 | } // namespace skia |
| 101 | |
| 102 | #endif // ParagraphStyle_DEFINED |