blob: b6f3b055d404786bf02ba38666ca1caa92995044 [file] [log] [blame]
Julia Lavrovaa3552c52019-05-30 16:12:56 -04001// Copyright 2019 Google LLC.
2#ifndef ParagraphStyle_DEFINED
3#define ParagraphStyle_DEFINED
4
Greg Danielf91aeb22019-06-18 09:58:02 -04005#include "include/core/SkFontStyle.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -04006#include "modules/skparagraph/include/DartTypes.h"
7#include "modules/skparagraph/include/TextStyle.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -04008
9namespace skia {
10namespace textlayout {
11
12struct 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 Lavrovadb9f6692019-08-01 16:02:17 -040030 bool getStrutEnabled() const { return fEnabled; }
31 void setStrutEnabled(bool v) { fEnabled = v; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040032
Julia Lavrovadb9f6692019-08-01 16:02:17 -040033 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 Lavrovaa3552c52019-05-30 16:12:56 -040038
39private:
40
41 std::vector<SkString> fFontFamilies;
42 SkFontStyle fFontStyle;
43 SkScalar fFontSize;
44 SkScalar fHeight;
45 SkScalar fLeading;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040046 bool fForceHeight;
47 bool fEnabled;
48 bool fHeightOverride;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040049};
50
51struct 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
89private:
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