• 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                this->fReplaceTabCharacters == rhs.fReplaceTabCharacters;
88     }
89 
getStrutStyleParagraphStyle90     const StrutStyle& getStrutStyle() const { return fStrutStyle; }
setStrutStyleParagraphStyle91     void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
92 
getTextStyleParagraphStyle93     const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
setTextStyleParagraphStyle94     void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
95 
getTextDirectionParagraphStyle96     TextDirection getTextDirection() const { return fTextDirection; }
setTextDirectionParagraphStyle97     void setTextDirection(TextDirection direction) { fTextDirection = direction; }
98 
getTextAlignParagraphStyle99     TextAlign getTextAlign() const { return fTextAlign; }
setTextAlignParagraphStyle100     void setTextAlign(TextAlign align) { fTextAlign = align; }
101 
getMaxLinesParagraphStyle102     size_t getMaxLines() const { return fLinesLimit; }
setMaxLinesParagraphStyle103     void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
104 
getEllipsisParagraphStyle105     SkString getEllipsis() const { return fEllipsis; }
getEllipsisUtf16ParagraphStyle106     std::u16string getEllipsisUtf16() const { return fEllipsisUtf16; }
setEllipsisParagraphStyle107     void setEllipsis(const std::u16string& ellipsis) {  fEllipsisUtf16 = ellipsis; }
setEllipsisParagraphStyle108     void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
109 
getHeightParagraphStyle110     SkScalar getHeight() const { return fHeight; }
setHeightParagraphStyle111     void setHeight(SkScalar height) { fHeight = height; }
112 
getTextHeightBehaviorParagraphStyle113     TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
setTextHeightBehaviorParagraphStyle114     void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
115 
unlimited_linesParagraphStyle116     bool unlimited_lines() const {
117         return fLinesLimit == std::numeric_limits<size_t>::max();
118     }
ellipsizedParagraphStyle119     bool ellipsized() const { return !fEllipsis.isEmpty() || !fEllipsisUtf16.empty(); }
120     TextAlign effective_align() const;
hintingIsOnParagraphStyle121     bool hintingIsOn() const { return fHintingIsOn; }
turnHintingOffParagraphStyle122     void turnHintingOff() { fHintingIsOn = false; }
123 
getReplaceTabCharactersParagraphStyle124     bool getReplaceTabCharacters() const { return fReplaceTabCharacters; }
setReplaceTabCharactersParagraphStyle125     void setReplaceTabCharacters(bool value) { fReplaceTabCharacters = value; }
126 
127 private:
128     StrutStyle fStrutStyle;
129     TextStyle fDefaultTextStyle;
130     TextAlign fTextAlign;
131     TextDirection fTextDirection;
132     size_t fLinesLimit;
133     std::u16string fEllipsisUtf16;
134     SkString fEllipsis;
135     SkScalar fHeight;
136     TextHeightBehavior fTextHeightBehavior;
137     bool fHintingIsOn;
138     bool fReplaceTabCharacters;
139 };
140 }  // namespace textlayout
141 }  // namespace skia
142 
143 #endif  // ParagraphStyle_DEFINED
144