blob: 2fcb8591ae8b3797eb351af8673b2cc7b47a152c [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"
Mike Klein48e08aa2019-08-26 11:24:50 -05008#include <string> // std::u16string
Julia Lavrovaa3552c52019-05-30 16:12:56 -04009
10namespace skia {
11namespace textlayout {
12
13struct StrutStyle {
14 StrutStyle();
15
16 const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; }
17 void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); }
18
19 SkFontStyle getFontStyle() const { return fFontStyle; }
20 void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; }
21
22 SkScalar getFontSize() const { return fFontSize; }
23 void setFontSize(SkScalar size) { fFontSize = size; }
24
25 void setHeight(SkScalar height) { fHeight = height; }
26 SkScalar getHeight() const { return fHeight; }
27
28 void setLeading(SkScalar Leading) { fLeading = Leading; }
29 SkScalar getLeading() const { return fLeading; }
30
Julia Lavrovadb9f6692019-08-01 16:02:17 -040031 bool getStrutEnabled() const { return fEnabled; }
32 void setStrutEnabled(bool v) { fEnabled = v; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040033
Julia Lavrovadb9f6692019-08-01 16:02:17 -040034 bool getForceStrutHeight() const { return fForceHeight; }
35 void setForceStrutHeight(bool v) { fForceHeight = v; }
36
37 bool getHeightOverride() const { return fHeightOverride; }
38 void setHeightOverride(bool v) { fHeightOverride = v; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040039
Julia Lavrovac0360582020-02-05 10:17:53 -050040 bool operator==(const StrutStyle& rhs) const {
41 return this->fEnabled == rhs.fEnabled &&
42 this->fHeightOverride == rhs.fHeightOverride &&
43 this->fForceHeight == rhs.fForceHeight &&
44 nearlyEqual(this->fLeading, rhs.fLeading) &&
45 nearlyEqual(this->fHeight, rhs.fHeight) &&
46 nearlyEqual(this->fFontSize, rhs.fFontSize) &&
47 this->fFontStyle == rhs.fFontStyle &&
48 this->fFontFamilies == rhs.fFontFamilies;
49 }
50
Julia Lavrovaa3552c52019-05-30 16:12:56 -040051private:
52
53 std::vector<SkString> fFontFamilies;
54 SkFontStyle fFontStyle;
55 SkScalar fFontSize;
56 SkScalar fHeight;
57 SkScalar fLeading;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040058 bool fForceHeight;
59 bool fEnabled;
60 bool fHeightOverride;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040061};
62
63struct ParagraphStyle {
64 ParagraphStyle();
65
66 bool operator==(const ParagraphStyle& rhs) const {
67 return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
68 this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
69 this->fDefaultTextStyle == rhs.fDefaultTextStyle;
70 }
71
72 const StrutStyle& getStrutStyle() const { return fStrutStyle; }
73 void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
74
75 const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
76 void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
77
78 TextDirection getTextDirection() const { return fTextDirection; }
79 void setTextDirection(TextDirection direction) { fTextDirection = direction; }
80
81 TextAlign getTextAlign() const { return fTextAlign; }
82 void setTextAlign(TextAlign align) { fTextAlign = align; }
83
84 size_t getMaxLines() const { return fLinesLimit; }
85 void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
86
87 const SkString& getEllipsis() const { return fEllipsis; }
88 void setEllipsis(const std::u16string& ellipsis);
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040089 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040090
91 SkScalar getHeight() const { return fHeight; }
92 void setHeight(SkScalar height) { fHeight = height; }
93
Julia Lavrova9588a642020-04-30 11:31:25 -040094
95 TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
96 void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
97
Julia Lavrovaa3552c52019-05-30 16:12:56 -040098 bool unlimited_lines() const {
99 return fLinesLimit == std::numeric_limits<size_t>::max();
100 }
101 bool ellipsized() const { return fEllipsis.size() != 0; }
102 TextAlign effective_align() const;
103 bool hintingIsOn() const { return fHintingIsOn; }
104 void turnHintingOff() { fHintingIsOn = false; }
105
106private:
107 StrutStyle fStrutStyle;
108 TextStyle fDefaultTextStyle;
109 TextAlign fTextAlign;
110 TextDirection fTextDirection;
111 size_t fLinesLimit;
112 SkString fEllipsis;
113 SkScalar fHeight;
Julia Lavrova9588a642020-04-30 11:31:25 -0400114 TextHeightBehavior fTextHeightBehavior;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400115 bool fHintingIsOn;
116};
117} // namespace textlayout
118} // namespace skia
119
120#endif // ParagraphStyle_DEFINED