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 | |
| 30 | bool getStrutEnabled() const { return fStrutEnabled; } |
| 31 | void setStrutEnabled(bool v) { fStrutEnabled = v; } |
| 32 | |
| 33 | bool getForceStrutHeight() const { return fForceStrutHeight; } |
| 34 | void setForceStrutHeight(bool v) { fForceStrutHeight = v; } |
| 35 | |
| 36 | private: |
| 37 | |
| 38 | std::vector<SkString> fFontFamilies; |
| 39 | SkFontStyle fFontStyle; |
| 40 | SkScalar fFontSize; |
| 41 | SkScalar fHeight; |
| 42 | SkScalar fLeading; |
| 43 | bool fForceStrutHeight; |
| 44 | bool fStrutEnabled; |
| 45 | }; |
| 46 | |
| 47 | struct ParagraphStyle { |
| 48 | ParagraphStyle(); |
| 49 | |
| 50 | bool operator==(const ParagraphStyle& rhs) const { |
| 51 | return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis && |
| 52 | this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign && |
| 53 | this->fDefaultTextStyle == rhs.fDefaultTextStyle; |
| 54 | } |
| 55 | |
| 56 | const StrutStyle& getStrutStyle() const { return fStrutStyle; } |
| 57 | void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); } |
| 58 | |
| 59 | const TextStyle& getTextStyle() const { return fDefaultTextStyle; } |
| 60 | void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; } |
| 61 | |
| 62 | TextDirection getTextDirection() const { return fTextDirection; } |
| 63 | void setTextDirection(TextDirection direction) { fTextDirection = direction; } |
| 64 | |
| 65 | TextAlign getTextAlign() const { return fTextAlign; } |
| 66 | void setTextAlign(TextAlign align) { fTextAlign = align; } |
| 67 | |
| 68 | size_t getMaxLines() const { return fLinesLimit; } |
| 69 | void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; } |
| 70 | |
| 71 | const SkString& getEllipsis() const { return fEllipsis; } |
| 72 | void setEllipsis(const std::u16string& ellipsis); |
| 73 | |
| 74 | SkScalar getHeight() const { return fHeight; } |
| 75 | void setHeight(SkScalar height) { fHeight = height; } |
| 76 | |
| 77 | bool unlimited_lines() const { |
| 78 | return fLinesLimit == std::numeric_limits<size_t>::max(); |
| 79 | } |
| 80 | bool ellipsized() const { return fEllipsis.size() != 0; } |
| 81 | TextAlign effective_align() const; |
| 82 | bool hintingIsOn() const { return fHintingIsOn; } |
| 83 | void turnHintingOff() { fHintingIsOn = false; } |
| 84 | |
| 85 | private: |
| 86 | StrutStyle fStrutStyle; |
| 87 | TextStyle fDefaultTextStyle; |
| 88 | TextAlign fTextAlign; |
| 89 | TextDirection fTextDirection; |
| 90 | size_t fLinesLimit; |
| 91 | SkString fEllipsis; |
| 92 | SkScalar fHeight; |
| 93 | bool fHintingIsOn; |
| 94 | }; |
| 95 | } // namespace textlayout |
| 96 | } // namespace skia |
| 97 | |
| 98 | #endif // ParagraphStyle_DEFINED |