Coverage Report

Created: 2024-05-20 07:14

/src/skia/modules/skparagraph/include/ParagraphStyle.h
Line
Count
Source (jump to first uncovered line)
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
0
    const std::vector<SkString>& getFontFamilies() const { return fFontFamilies; }
25
0
    void setFontFamilies(std::vector<SkString> families) { fFontFamilies = std::move(families); }
26
27
0
    SkFontStyle getFontStyle() const { return fFontStyle; }
28
0
    void setFontStyle(SkFontStyle fontStyle) { fFontStyle = fontStyle; }
29
30
0
    SkScalar getFontSize() const { return fFontSize; }
31
0
    void setFontSize(SkScalar size) { fFontSize = size; }
32
33
0
    void setHeight(SkScalar height) { fHeight = height; }
34
0
    SkScalar getHeight() const { return fHeight; }
35
36
0
    void setLeading(SkScalar Leading) { fLeading = Leading; }
37
0
    SkScalar getLeading() const { return fLeading; }
38
39
0
    bool getStrutEnabled() const { return fEnabled; }
40
0
    void setStrutEnabled(bool v) { fEnabled = v; }
41
42
0
    bool getForceStrutHeight() const { return fForceHeight; }
43
0
    void setForceStrutHeight(bool v) { fForceHeight = v; }
44
45
0
    bool getHeightOverride() const { return fHeightOverride; }
46
0
    void setHeightOverride(bool v) { fHeightOverride = v; }
47
48
0
    void setHalfLeading(bool halfLeading) { fHalfLeading = halfLeading; }
49
0
    bool getHalfLeading() const { return fHalfLeading; }
50
51
0
    bool operator==(const StrutStyle& rhs) const {
52
0
        return this->fEnabled == rhs.fEnabled &&
53
0
               this->fHeightOverride == rhs.fHeightOverride &&
54
0
               this->fForceHeight == rhs.fForceHeight &&
55
0
               this->fHalfLeading == rhs.fHalfLeading &&
56
0
               nearlyEqual(this->fLeading, rhs.fLeading) &&
57
0
               nearlyEqual(this->fHeight, rhs.fHeight) &&
58
0
               nearlyEqual(this->fFontSize, rhs.fFontSize) &&
59
0
               this->fFontStyle == rhs.fFontStyle &&
60
0
               this->fFontFamilies == rhs.fFontFamilies;
61
0
    }
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
0
    bool operator==(const ParagraphStyle& rhs) const {
82
0
        return this->fHeight == rhs.fHeight &&
83
0
               this->fEllipsis == rhs.fEllipsis &&
84
0
               this->fEllipsisUtf16 == rhs.fEllipsisUtf16 &&
85
0
               this->fTextDirection == rhs.fTextDirection && this->fTextAlign == rhs.fTextAlign &&
86
0
               this->fDefaultTextStyle == rhs.fDefaultTextStyle &&
87
0
               this->fReplaceTabCharacters == rhs.fReplaceTabCharacters;
88
0
    }
89
90
0
    const StrutStyle& getStrutStyle() const { return fStrutStyle; }
91
0
    void setStrutStyle(StrutStyle strutStyle) { fStrutStyle = std::move(strutStyle); }
92
93
0
    const TextStyle& getTextStyle() const { return fDefaultTextStyle; }
94
0
    void setTextStyle(const TextStyle& textStyle) { fDefaultTextStyle = textStyle; }
95
96
0
    TextDirection getTextDirection() const { return fTextDirection; }
97
0
    void setTextDirection(TextDirection direction) { fTextDirection = direction; }
98
99
0
    TextAlign getTextAlign() const { return fTextAlign; }
100
0
    void setTextAlign(TextAlign align) { fTextAlign = align; }
101
102
0
    size_t getMaxLines() const { return fLinesLimit; }
103
0
    void setMaxLines(size_t maxLines) { fLinesLimit = maxLines; }
104
105
0
    SkString getEllipsis() const { return fEllipsis; }
106
0
    std::u16string getEllipsisUtf16() const { return fEllipsisUtf16; }
107
0
    void setEllipsis(const std::u16string& ellipsis) {  fEllipsisUtf16 = ellipsis; }
108
0
    void setEllipsis(const SkString& ellipsis) { fEllipsis = ellipsis; }
109
110
0
    SkScalar getHeight() const { return fHeight; }
111
0
    void setHeight(SkScalar height) { fHeight = height; }
112
113
0
    TextHeightBehavior getTextHeightBehavior() const { return fTextHeightBehavior; }
114
0
    void setTextHeightBehavior(TextHeightBehavior v) { fTextHeightBehavior = v; }
115
116
0
    bool unlimited_lines() const {
117
0
        return fLinesLimit == std::numeric_limits<size_t>::max();
118
0
    }
119
0
    bool ellipsized() const { return !fEllipsis.isEmpty() || !fEllipsisUtf16.empty(); }
120
    TextAlign effective_align() const;
121
0
    bool hintingIsOn() const { return fHintingIsOn; }
122
0
    void turnHintingOff() { fHintingIsOn = false; }
123
124
0
    bool getReplaceTabCharacters() const { return fReplaceTabCharacters; }
125
0
    void setReplaceTabCharacters(bool value) { fReplaceTabCharacters = value; }
126
127
0
    bool getApplyRoundingHack() const { return fApplyRoundingHack; }
128
0
    void setApplyRoundingHack(bool value) { fApplyRoundingHack = value; }
129
130
private:
131
    StrutStyle fStrutStyle;
132
    TextStyle fDefaultTextStyle;
133
    TextAlign fTextAlign;
134
    TextDirection fTextDirection;
135
    size_t fLinesLimit;
136
    std::u16string fEllipsisUtf16;
137
    SkString fEllipsis;
138
    SkScalar fHeight;
139
    TextHeightBehavior fTextHeightBehavior;
140
    bool fHintingIsOn;
141
    bool fReplaceTabCharacters;
142
    bool fApplyRoundingHack = true;
143
};
144
}  // namespace textlayout
145
}  // namespace skia
146
147
#endif  // ParagraphStyle_DEFINED