| 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 |
|
| 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 |
|
| 39 |
bool getStrutEnabled() const { return fEnabled; } |
| 40 |
void setStrutEnabled(bool v) { fEnabled = v; } |
| 41 |
|
| 42 |
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; } |
| 47 |
|
| 48 |
void setHalfLeading(bool halfLeading) { fHalfLeading = halfLeading; } |
| 49 |
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 |
this->fFakeMissingFontStyles == rhs.fFakeMissingFontStyles; |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
const StrutStyle& getStrutStyle() const { return fStrutStyle; } |
| 93 |
void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); } |
| 94 |
|
| 95 |
const TextStyle& getTextStyle() const { return fDefaultTextStyle; } |
| 96 |
void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; } |
| 97 |
|
| 98 |
TextDirection getTextDirection() const { return fTextDirection; } |
| 99 |
void setTextDirection(TextDirection direction) { fTextDirection = direction; } |
| 100 |
|
| 101 |
TextAlign getTextAlign() const { return fTextAlign; } |
| 102 |
void setTextAlign(TextAlign align) { fTextAlign = align; } |
| 103 |
|
| 104 |
size_t getMaxLines() const { return fLinesLimit; } |
| 105 |
void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; } |
| 106 |
|
| 107 |
SkString getEllipsis() const { return fEllipsis; } |
| 108 |
std::u16string getEllipsisUtf16() const { return fEllipsisUtf16; } |
| 109 |
void setEllipsis(const std::u16string& ellipsis) { fEllipsisUtf16 = ellipsis; } |
| 110 |
void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; } |
| 111 |
|
| 112 |
SkScalar getHeight() const { return fHeight; } |
| 113 |
void setHeight(SkScalar height) { fHeight = height; } |
| 114 |
|
| 115 |
TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; } |
| 116 |
void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; } |
| 117 |
|
| 118 |
bool unlimited_lines() const { |
| 119 |
return fLinesLimit == std::numeric_limits<size_t>::max(); |
| 120 |
} |
| 121 |
bool ellipsized() const { return !fEllipsis.isEmpty() || !fEllipsisUtf16.empty(); } |
| 122 |
TextAlign effective_align() const; |
| 123 |
bool hintingIsOn() const { return fHintingIsOn; } |
| 124 |
void turnHintingOff() { fHintingIsOn = false; } |
| 125 |
|
| 126 |
bool fakeMissingFontStyles() const { return fFakeMissingFontStyles; } |
| 127 |
void setFakeMissingFontStyles(bool value) { fFakeMissingFontStyles = value; } |
| 128 |
|
| 129 |
bool getReplaceTabCharacters() const { return fReplaceTabCharacters; } |
| 130 |
void setReplaceTabCharacters(bool value) { fReplaceTabCharacters = value; } |
| 131 |
|
| 132 |
bool getApplyRoundingHack() const { return fApplyRoundingHack; } |
| 133 |
void setApplyRoundingHack(bool value) { fApplyRoundingHack = value; } |
| 134 |
|
| 135 |
private: |
| 136 |
StrutStyle fStrutStyle; |
| 137 |
TextStyle fDefaultTextStyle; |
| 138 |
TextAlign fTextAlign; |
| 139 |
TextDirection fTextDirection; |
| 140 |
size_t fLinesLimit; |
| 141 |
std::u16string fEllipsisUtf16; |
| 142 |
SkString fEllipsis; |
| 143 |
SkScalar fHeight; |
| 144 |
TextHeightBehavior fTextHeightBehavior; |
| 145 |
bool fHintingIsOn; |
| 146 |
bool fReplaceTabCharacters; |
| 147 |
bool fFakeMissingFontStyles; |
| 148 |
bool fApplyRoundingHack = true; |
| 149 |
}; |
| 150 |
} // namespace textlayout |
| 151 |
} // namespace skia |
| 152 |
|
| 153 |
#endif // ParagraphStyle_DEFINED |