• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 namespace skia {
19 namespace textlayout {
20 
21 struct StrutStyle {
22     StrutStyle();
23 
getFontFamiliesStrutStyle24     const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; }
setFontFamiliesStrutStyle25     void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); }
26 
getFontStyleStrutStyle27     SkFontStyle getFontStyle() const { return fFontStyle; }
setFontStyleStrutStyle28     void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; }
29 
getFontSizeStrutStyle30     SkScalar getFontSize() const { return fFontSize; }
setFontSizeStrutStyle31     void setFontSize(SkScalar size) { fFontSize = size; }
32 
setHeightStrutStyle33     void setHeight(SkScalar height) { fHeight = height; }
getHeightStrutStyle34     SkScalar getHeight() const { return fHeight; }
35 
setLeadingStrutStyle36     void setLeading(SkScalar Leading) { fLeading = Leading; }
getLeadingStrutStyle37     SkScalar getLeading() const { return fLeading; }
38 
getStrutEnabledStrutStyle39     bool getStrutEnabled() const { return fEnabled; }
setStrutEnabledStrutStyle40     void setStrutEnabled(bool v) { fEnabled = v; }
41 
getForceStrutHeightStrutStyle42     bool getForceStrutHeight() const { return fForceHeight; }
setForceStrutHeightStrutStyle43     void setForceStrutHeight(bool v) { fForceHeight = v; }
44 
getHeightOverrideStrutStyle45     bool getHeightOverride() const { return fHeightOverride; }
setHeightOverrideStrutStyle46     void setHeightOverride(bool v) { fHeightOverride = v; }
47 
setHalfLeadingStrutStyle48     void setHalfLeading(bool halfLeading) { fHalfLeading = halfLeading; }
getHalfLeadingStrutStyle49     bool getHalfLeading() const { return fHalfLeading; }
50 
51     bool operator==(const StrutStyle& rhs) const {
52         return this->fEnabled == rhs.fEnabled &&
53                this->fHeightOverride == rhs.fHeightOverride &&
54                this->fForceHeight == rhs.fForceHeight &&
55                this->fHalfLeading == rhs.fHalfLeading &&
56                nearlyEqual(this->fLeading, rhs.fLeading) &&
57                nearlyEqual(this->fHeight, rhs.fHeight) &&
58                nearlyEqual(this->fFontSize, rhs.fFontSize) &&
59                this->fFontStyle == rhs.fFontStyle &&
60                this->fFontFamilies == rhs.fFontFamilies;
61     }
62 
63 private:
64 
65     std::vector<SkString> fFontFamilies;
66     SkFontStyle fFontStyle;
67     SkScalar fFontSize;
68     SkScalar fHeight;
69     SkScalar fLeading;
70     bool fForceHeight;
71     bool fEnabled;
72     bool fHeightOverride;
73     // true: half leading.
74     // false: scale ascent/descent with fHeight.
75     bool fHalfLeading;
76 };
77 
78 struct ParagraphStyle {
79     ParagraphStyle();
80 
81     bool operator==(const ParagraphStyle& rhs) const {
82         return this->fHeight == rhs.fHeight &&
83                this->fEllipsis == rhs.fEllipsis &&
84                this->fEllipsisUtf16 == rhs.fEllipsisUtf16 &&
85                this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
86                this->fDefaultTextStyle == rhs.fDefaultTextStyle;
87     }
88 
getStrutStyleParagraphStyle89     const StrutStyle& getStrutStyle() const { return fStrutStyle; }
setStrutStyleParagraphStyle90     void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
91 
getTextStyleParagraphStyle92     const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
setTextStyleParagraphStyle93     void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
94 
getTextDirectionParagraphStyle95     TextDirection getTextDirection() const { return fTextDirection; }
setTextDirectionParagraphStyle96     void setTextDirection(TextDirection direction) { fTextDirection = direction; }
97 
getTextAlignParagraphStyle98     TextAlign getTextAlign() const { return fTextAlign; }
setTextAlignParagraphStyle99     void setTextAlign(TextAlign align) { fTextAlign = align; }
100 
getMaxLinesParagraphStyle101     size_t getMaxLines() const { return fLinesLimit; }
setMaxLinesParagraphStyle102     void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
103 
getEllipsisParagraphStyle104     SkString getEllipsis() const { return fEllipsis; }
getEllipsisUtf16ParagraphStyle105     std::u16string getEllipsisUtf16() const { return fEllipsisUtf16; }
setEllipsisParagraphStyle106     void setEllipsis(const std::u16string& ellipsis) {  fEllipsisUtf16 = ellipsis; }
setEllipsisParagraphStyle107     void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
108 
getHeightParagraphStyle109     SkScalar getHeight() const { return fHeight; }
setHeightParagraphStyle110     void setHeight(SkScalar height) { fHeight = height; }
111 
getTextHeightBehaviorParagraphStyle112     TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
setTextHeightBehaviorParagraphStyle113     void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
114 
unlimited_linesParagraphStyle115     bool unlimited_lines() const {
116         return fLinesLimit == std::numeric_limits<size_t>::max();
117     }
ellipsizedParagraphStyle118     bool ellipsized() const { return !fEllipsis.isEmpty() || !fEllipsisUtf16.empty(); }
119     TextAlign effective_align() const;
hintingIsOnParagraphStyle120     bool hintingIsOn() const { return fHintingIsOn; }
turnHintingOffParagraphStyle121     void turnHintingOff() { fHintingIsOn = false; }
getDrawOptionsParagraphStyle122     DrawOptions getDrawOptions() { return fDrawingOptions; }
setDrawOptionsParagraphStyle123     void setDrawOptions(DrawOptions value) { fDrawingOptions = value; }
124 
125 private:
126     StrutStyle fStrutStyle;
127     TextStyle fDefaultTextStyle;
128     TextAlign fTextAlign;
129     TextDirection fTextDirection;
130     size_t fLinesLimit;
131     std::u16string fEllipsisUtf16;
132     SkString fEllipsis;
133     SkScalar fHeight;
134     TextHeightBehavior fTextHeightBehavior;
135     bool fHintingIsOn;
136     DrawOptions fDrawingOptions = DrawOptions::kDirect;
137 };
138 }  // namespace textlayout
139 }  // namespace skia
140 
141 #endif  // ParagraphStyle_DEFINED
142