blob: 43fb71f590573372e6658e832dbdc11c5e1720ac [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 Lavrova05ce2812020-09-01 20:51:05 +000075 return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
Julia Lavrovaa3552c52019-05-30 16:12:56 -040076 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
Julia Lavrova05ce2812020-09-01 20:51:05 +000095 const SkString& getEllipsis() const { return fEllipsis; }
96 void setEllipsis(const std::u16string& ellipsis);
Kevin Lubickd3b1fe62019-10-21 10:50:26 -040097 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -040098
99 SkScalar getHeight() const { return fHeight; }
100 void setHeight(SkScalar height) { fHeight = height; }
101
Julia Lavrova9588a642020-04-30 11:31:25 -0400102 TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
103 void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
104
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400105 bool unlimited_lines() const {
106 return fLinesLimit == std::numeric_limits<size_t>::max();
107 }
Julia Lavrova05ce2812020-09-01 20:51:05 +0000108 bool ellipsized() const { return fEllipsis.size() != 0; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400109 TextAlign effective_align() const;
110 bool hintingIsOn() const { return fHintingIsOn; }
111 void turnHintingOff() { fHintingIsOn = false; }
Julia Lavrovad279cee2020-07-28 13:44:27 -0400112 DrawOptions getDrawOptions() { return fDrawingOptions; }
113 void setDrawOptions(DrawOptions value) { fDrawingOptions = value; }
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400114
115private:
116 StrutStyle fStrutStyle;
117 TextStyle fDefaultTextStyle;
118 TextAlign fTextAlign;
119 TextDirection fTextDirection;
120 size_t fLinesLimit;
121 SkString fEllipsis;
122 SkScalar fHeight;
Julia Lavrova9588a642020-04-30 11:31:25 -0400123 TextHeightBehavior fTextHeightBehavior;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400124 bool fHintingIsOn;
Julia Lavrovab6030fb2020-09-08 11:01:49 -0400125 DrawOptions fDrawingOptions = DrawOptions::kDirect;
Julia Lavrovaa3552c52019-05-30 16:12:56 -0400126};
127} // namespace textlayout
128} // namespace skia
129
130#endif // ParagraphStyle_DEFINED