1// Copyright 2019 Google LLC.
2#ifndef ParagraphStyle_DEFINED
3#define ParagraphStyle_DEFINED
4
5#include "include/core/SkFontStyle.h"
6#include "include/core/SkScalar.h"
7#include "include/core/SkString.h"
8#include "modules/skparagraph/include/DartTypes.h"
9#include "modules/skparagraph/include/TextStyle.h"
10
11#include <stddef.h>
12#include <algorithm>
13#include <limits>
14#include <string>
15#include <utility>
16#include <vector>
17
18namespace skia {
19namespace textlayout {
20
21struct 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
39 bool getStrutEnabled() const { return fEnabled; }
40 void setStrutEnabled(bool v) { fEnabled = v; }
41
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; }
47
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
59private:
60
61 std::vector<SkString> fFontFamilies;
62 SkFontStyle fFontStyle;
63 SkScalar fFontSize;
64 SkScalar fHeight;
65 SkScalar fLeading;
66 bool fForceHeight;
67 bool fEnabled;
68 bool fHeightOverride;
69};
70
71struct ParagraphStyle {
72 ParagraphStyle();
73
74 bool operator==(const ParagraphStyle& rhs) const {
75 return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
76 this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
77 this->fDefaultTextStyle == rhs.fDefaultTextStyle;
78 }
79
80 const StrutStyle& getStrutStyle() const { return fStrutStyle; }
81 void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
82
83 const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
84 void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
85
86 TextDirection getTextDirection() const { return fTextDirection; }
87 void setTextDirection(TextDirection direction) { fTextDirection = direction; }
88
89 TextAlign getTextAlign() const { return fTextAlign; }
90 void setTextAlign(TextAlign align) { fTextAlign = align; }
91
92 size_t getMaxLines() const { return fLinesLimit; }
93 void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
94
95 const SkString& getEllipsis() const { return fEllipsis; }
96 void setEllipsis(const std::u16string& ellipsis);
97 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
98
99 SkScalar getHeight() const { return fHeight; }
100 void setHeight(SkScalar height) { fHeight = height; }
101
102
103 TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
104 void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
105
106 bool unlimited_lines() const {
107 return fLinesLimit == std::numeric_limits<size_t>::max();
108 }
109 bool ellipsized() const { return fEllipsis.size() != 0; }
110 TextAlign effective_align() const;
111 bool hintingIsOn() const { return fHintingIsOn; }
112 void turnHintingOff() { fHintingIsOn = false; }
113
114private:
115 StrutStyle fStrutStyle;
116 TextStyle fDefaultTextStyle;
117 TextAlign fTextAlign;
118 TextDirection fTextDirection;
119 size_t fLinesLimit;
120 SkString fEllipsis;
121 SkScalar fHeight;
122 TextHeightBehavior fTextHeightBehavior;
123 bool fHintingIsOn;
124};
125} // namespace textlayout
126} // namespace skia
127
128#endif // ParagraphStyle_DEFINED
129