blob: 528c30bfe80c5502228a896fd396ddac3cce64c7 [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
40private:
41
42 std::vector<SkString> fFontFamilies;
43 SkFontStyle fFontStyle;
44 SkScalar fFontSize;
45 SkScalar fHeight;
46 SkScalar fLeading;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040047 bool fForceHeight;
48 bool fEnabled;
49 bool fHeightOverride;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040050};
51
52struct ParagraphStyle {
53 ParagraphStyle();
54
55 bool operator==(const ParagraphStyle& rhs) const {
56 return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
57 this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
58 this->fDefaultTextStyle == rhs.fDefaultTextStyle;
59 }
60
61 const StrutStyle& getStrutStyle() const { return fStrutStyle; }
62 void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
63
64 const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
65 void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
66
67 TextDirection getTextDirection() const { return fTextDirection; }
68 void setTextDirection(TextDirection direction) { fTextDirection = direction; }
69
70 TextAlign getTextAlign() const { return fTextAlign; }
71 void setTextAlign(TextAlign align) { fTextAlign = align; }
72
73 size_t getMaxLines() const { return fLinesLimit; }
74 void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
75
76 const SkString& getEllipsis() const { return fEllipsis; }
77 void setEllipsis(const std::u16string& ellipsis);
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040078 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040079
80 SkScalar getHeight() const { return fHeight; }
81 void setHeight(SkScalar height) { fHeight = height; }
82
83 bool unlimited_lines() const {
84 return fLinesLimit == std::numeric_limits<size_t>::max();
85 }
86 bool ellipsized() const { return fEllipsis.size() != 0; }
87 TextAlign effective_align() const;
88 bool hintingIsOn() const { return fHintingIsOn; }
89 void turnHintingOff() { fHintingIsOn = false; }
90
91private:
92 StrutStyle fStrutStyle;
93 TextStyle fDefaultTextStyle;
94 TextAlign fTextAlign;
95 TextDirection fTextDirection;
96 size_t fLinesLimit;
97 SkString fEllipsis;
98 SkScalar fHeight;
99 bool fHintingIsOn;
100};
101} // namespace textlayout
102} // namespace skia
103
104#endif // ParagraphStyle_DEFINED