blob: 871e67489543f4c9d653419a32761f92ba5cd6a6 [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"
Ben Wagnerb985b4b2020-05-28 15:59:42 -04006#include "include/core/SkScalar.h"
7#include "include/core/SkString.h"
Julia Lavrovaa3552c52019-05-30 16:12:56 -04008#include "modules/skparagraph/include/DartTypes.h"
9#include "modules/skparagraph/include/TextStyle.h"
Ben Wagnerb985b4b2020-05-28 15:59:42 -040010
11#include <stddef.h>
12#include <algorithm>
13#include <limits>
14#include <string>
15#include <utility>
16#include <vector>
Julia Lavrovaa3552c52019-05-30 16:12:56 -040017
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
Julia Lavrovadb9f6692019-08-01 16:02:17 -040039 bool getStrutEnabled() const { return fEnabled; }
40 void setStrutEnabled(bool v) { fEnabled = v; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040041
Julia Lavrovadb9f6692019-08-01 16:02:17 -040042 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; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040047
Julia Lavrovac0360582020-02-05 10:17:53 -050048 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
Julia Lavrovaa3552c52019-05-30 16:12:56 -040059private:
60
61 std::vector<SkString> fFontFamilies;
62 SkFontStyle fFontStyle;
63 SkScalar fFontSize;
64 SkScalar fHeight;
65 SkScalar fLeading;
Julia Lavrovadb9f6692019-08-01 16:02:17 -040066 bool fForceHeight;
67 bool fEnabled;
68 bool fHeightOverride;
Julia Lavrovaa3552c52019-05-30 16:12:56 -040069};
70
71struct ParagraphStyle {
72 ParagraphStyle();
73
74 bool operator==(const ParagraphStyle& rhs) const {
Julia Lavrovab6b7fff2020-09-11 13:59:49 +000075 return this->fHeight == rhs.fHeight &&
76 this->fEllipsis == rhs.fEllipsis &&
77 this->fEllipsisUtf16 == rhs.fEllipsisUtf16 &&
Julia Lavrovaa3552c52019-05-30 16:12:56 -040078 this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
79 this->fDefaultTextStyle == rhs.fDefaultTextStyle;
80 }
81
82 const StrutStyle& getStrutStyle() const { return fStrutStyle; }
83 void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
84
85 const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
86 void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
87
88 TextDirection getTextDirection() const { return fTextDirection; }
89 void setTextDirection(TextDirection direction) { fTextDirection = direction; }
90
91 TextAlign getTextAlign() const { return fTextAlign; }
92 void setTextAlign(TextAlign align) { fTextAlign = align; }
93
94 size_t getMaxLines() const { return fLinesLimit; }
95 void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
96
Julia Lavrovab6b7fff2020-09-11 13:59:49 +000097 SkString getEllipsis() const { return fEllipsis; }
98 std::u16string getEllipsisUtf16() const { return fEllipsisUtf16; }
99 void setEllipsis(const std::u16string& ellipsis) { fEllipsisUtf16 = ellipsis; }
Kevin Lubickd3b1fe62019-10-21 10:50:26 -0400100 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400101
102 SkScalar getHeight() const { return fHeight; }
103 void setHeight(SkScalar height) { fHeight = height; }
104
Julia Lavrova9588a642020-04-30 11:31:25 -0400105 TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
106 void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
107
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400108 bool unlimited_lines() const {
109 return fLinesLimit == std::numeric_limits<size_t>::max();
110 }
Julia Lavrovab6b7fff2020-09-11 13:59:49 +0000111 bool ellipsized() const { return !fEllipsis.isEmpty() || !fEllipsisUtf16.empty(); }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400112 TextAlign effective_align() const;
113 bool hintingIsOn() const { return fHintingIsOn; }
114 void turnHintingOff() { fHintingIsOn = false; }
Julia Lavrovad279cee2020-07-28 13:44:27 -0400115 DrawOptions getDrawOptions() { return fDrawingOptions; }
116 void setDrawOptions(DrawOptions value) { fDrawingOptions = value; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400117
118private:
119 StrutStyle fStrutStyle;
120 TextStyle fDefaultTextStyle;
121 TextAlign fTextAlign;
122 TextDirection fTextDirection;
123 size_t fLinesLimit;
Julia Lavrovab6b7fff2020-09-11 13:59:49 +0000124 std::u16string fEllipsisUtf16;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400125 SkString fEllipsis;
126 SkScalar fHeight;
Julia Lavrova9588a642020-04-30 11:31:25 -0400127 TextHeightBehavior fTextHeightBehavior;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400128 bool fHintingIsOn;
Julia Lavrovab6030fb2020-09-08 11:01:49 -0400129 DrawOptions fDrawingOptions = DrawOptions::kDirect;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400130};
131} // namespace textlayout
132} // namespace skia
133
134#endif // ParagraphStyle_DEFINED