• 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 "modules/skparagraph/include/DartTypes.h"
7 #include "modules/skparagraph/include/TextStyle.h"
8 
9 namespace skia {
10 namespace textlayout {
11 
12 struct StrutStyle {
13     StrutStyle();
14 
getFontFamiliesStrutStyle15     const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; }
setFontFamiliesStrutStyle16     void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); }
17 
getFontStyleStrutStyle18     SkFontStyle getFontStyle() const { return fFontStyle; }
setFontStyleStrutStyle19     void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; }
20 
getFontSizeStrutStyle21     SkScalar getFontSize() const { return fFontSize; }
setFontSizeStrutStyle22     void setFontSize(SkScalar size) { fFontSize = size; }
23 
setHeightStrutStyle24     void setHeight(SkScalar height) { fHeight = height; }
getHeightStrutStyle25     SkScalar getHeight() const { return fHeight; }
26 
setLeadingStrutStyle27     void setLeading(SkScalar Leading) { fLeading = Leading; }
getLeadingStrutStyle28     SkScalar getLeading() const { return fLeading; }
29 
getStrutEnabledStrutStyle30     bool getStrutEnabled() const { return fEnabled; }
setStrutEnabledStrutStyle31     void setStrutEnabled(bool v) { fEnabled = v; }
32 
getForceStrutHeightStrutStyle33     bool getForceStrutHeight() const { return fForceHeight; }
setForceStrutHeightStrutStyle34     void setForceStrutHeight(bool v) { fForceHeight = v; }
35 
getHeightOverrideStrutStyle36     bool getHeightOverride() const { return fHeightOverride; }
setHeightOverrideStrutStyle37     void setHeightOverride(bool v) { fHeightOverride = v; }
38 
39 private:
40 
41     std::vector<SkString> fFontFamilies;
42     SkFontStyle fFontStyle;
43     SkScalar fFontSize;
44     SkScalar fHeight;
45     SkScalar fLeading;
46     bool fForceHeight;
47     bool fEnabled;
48     bool fHeightOverride;
49 };
50 
51 struct ParagraphStyle {
52     ParagraphStyle();
53 
54     bool operator==(const ParagraphStyle& rhs) const {
55         return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis &&
56                this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
57                this->fDefaultTextStyle == rhs.fDefaultTextStyle;
58     }
59 
getStrutStyleParagraphStyle60     const StrutStyle& getStrutStyle() const { return fStrutStyle; }
setStrutStyleParagraphStyle61     void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
62 
getTextStyleParagraphStyle63     const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
setTextStyleParagraphStyle64     void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
65 
getTextDirectionParagraphStyle66     TextDirection getTextDirection() const { return fTextDirection; }
setTextDirectionParagraphStyle67     void setTextDirection(TextDirection direction) { fTextDirection = direction; }
68 
getTextAlignParagraphStyle69     TextAlign getTextAlign() const { return fTextAlign; }
setTextAlignParagraphStyle70     void setTextAlign(TextAlign align) { fTextAlign = align; }
71 
getMaxLinesParagraphStyle72     size_t getMaxLines() const { return fLinesLimit; }
setMaxLinesParagraphStyle73     void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
74 
getEllipsisParagraphStyle75     const SkString& getEllipsis() const { return fEllipsis; }
76     void setEllipsis(const std::u16string& ellipsis);
77 
getHeightParagraphStyle78     SkScalar getHeight() const { return fHeight; }
setHeightParagraphStyle79     void setHeight(SkScalar height) { fHeight = height; }
80 
unlimited_linesParagraphStyle81     bool unlimited_lines() const {
82         return fLinesLimit == std::numeric_limits<size_t>::max();
83     }
ellipsizedParagraphStyle84     bool ellipsized() const { return fEllipsis.size() != 0; }
85     TextAlign effective_align() const;
hintingIsOnParagraphStyle86     bool hintingIsOn() const { return fHintingIsOn; }
turnHintingOffParagraphStyle87     void turnHintingOff() { fHintingIsOn = false; }
88 
89 private:
90     StrutStyle fStrutStyle;
91     TextStyle fDefaultTextStyle;
92     TextAlign fTextAlign;
93     TextDirection fTextDirection;
94     size_t fLinesLimit;
95     SkString fEllipsis;
96     SkScalar fHeight;
97     bool fHintingIsOn;
98 };
99 }  // namespace textlayout
100 }  // namespace skia
101 
102 #endif  // ParagraphStyle_DEFINED
103