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 #include <string> // std::u16string 9 10 namespace skia { 11 namespace textlayout { 12 13 struct StrutStyle { 14 StrutStyle(); 15 getFontFamiliesStrutStyle16 const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; } setFontFamiliesStrutStyle17 void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); } 18 getFontStyleStrutStyle19 SkFontStyle getFontStyle() const { return fFontStyle; } setFontStyleStrutStyle20 void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; } 21 getFontSizeStrutStyle22 SkScalar getFontSize() const { return fFontSize; } setFontSizeStrutStyle23 void setFontSize(SkScalar size) { fFontSize = size; } 24 setHeightStrutStyle25 void setHeight(SkScalar height) { fHeight = height; } getHeightStrutStyle26 SkScalar getHeight() const { return fHeight; } 27 setLeadingStrutStyle28 void setLeading(SkScalar Leading) { fLeading = Leading; } getLeadingStrutStyle29 SkScalar getLeading() const { return fLeading; } 30 getStrutEnabledStrutStyle31 bool getStrutEnabled() const { return fEnabled; } setStrutEnabledStrutStyle32 void setStrutEnabled(bool v) { fEnabled = v; } 33 getForceStrutHeightStrutStyle34 bool getForceStrutHeight() const { return fForceHeight; } setForceStrutHeightStrutStyle35 void setForceStrutHeight(bool v) { fForceHeight = v; } 36 getHeightOverrideStrutStyle37 bool getHeightOverride() const { return fHeightOverride; } setHeightOverrideStrutStyle38 void setHeightOverride(bool v) { fHeightOverride = v; } 39 40 bool operator==(const StrutStyle& rhs) const { 41 return this->fEnabled == rhs.fEnabled && 42 this->fHeightOverride == rhs.fHeightOverride && 43 this->fForceHeight == rhs.fForceHeight && 44 nearlyEqual(this->fLeading, rhs.fLeading) && 45 nearlyEqual(this->fHeight, rhs.fHeight) && 46 nearlyEqual(this->fFontSize, rhs.fFontSize) && 47 this->fFontStyle == rhs.fFontStyle && 48 this->fFontFamilies == rhs.fFontFamilies; 49 } 50 51 private: 52 53 std::vector<SkString> fFontFamilies; 54 SkFontStyle fFontStyle; 55 SkScalar fFontSize; 56 SkScalar fHeight; 57 SkScalar fLeading; 58 bool fForceHeight; 59 bool fEnabled; 60 bool fHeightOverride; 61 }; 62 63 struct ParagraphStyle { 64 ParagraphStyle(); 65 66 bool operator==(const ParagraphStyle& rhs) const { 67 return this->fHeight == rhs.fHeight && this->fEllipsis == rhs.fEllipsis && 68 this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign && 69 this->fDefaultTextStyle == rhs.fDefaultTextStyle; 70 } 71 getStrutStyleParagraphStyle72 const StrutStyle& getStrutStyle() const { return fStrutStyle; } setStrutStyleParagraphStyle73 void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); } 74 getTextStyleParagraphStyle75 const TextStyle& getTextStyle() const { return fDefaultTextStyle; } setTextStyleParagraphStyle76 void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; } 77 getTextDirectionParagraphStyle78 TextDirection getTextDirection() const { return fTextDirection; } setTextDirectionParagraphStyle79 void setTextDirection(TextDirection direction) { fTextDirection = direction; } 80 getTextAlignParagraphStyle81 TextAlign getTextAlign() const { return fTextAlign; } setTextAlignParagraphStyle82 void setTextAlign(TextAlign align) { fTextAlign = align; } 83 getMaxLinesParagraphStyle84 size_t getMaxLines() const { return fLinesLimit; } setMaxLinesParagraphStyle85 void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; } 86 getEllipsisParagraphStyle87 const SkString& getEllipsis() const { return fEllipsis; } 88 void setEllipsis(const std::u16string& ellipsis); setEllipsisParagraphStyle89 void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; } 90 getHeightParagraphStyle91 SkScalar getHeight() const { return fHeight; } setHeightParagraphStyle92 void setHeight(SkScalar height) { fHeight = height; } 93 unlimited_linesParagraphStyle94 bool unlimited_lines() const { 95 return fLinesLimit == std::numeric_limits<size_t>::max(); 96 } ellipsizedParagraphStyle97 bool ellipsized() const { return fEllipsis.size() != 0; } 98 TextAlign effective_align() const; hintingIsOnParagraphStyle99 bool hintingIsOn() const { return fHintingIsOn; } turnHintingOffParagraphStyle100 void turnHintingOff() { fHintingIsOn = false; } 101 102 private: 103 StrutStyle fStrutStyle; 104 TextStyle fDefaultTextStyle; 105 TextAlign fTextAlign; 106 TextDirection fTextDirection; 107 size_t fLinesLimit; 108 SkString fEllipsis; 109 SkScalar fHeight; 110 bool fHintingIsOn; 111 }; 112 } // namespace textlayout 113 } // namespace skia 114 115 #endif // ParagraphStyle_DEFINED 116