Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Friends | List of all members
skia::textlayout::Run Class Reference

#include <Run.h>

Public Types

using ClusterVisitor = std::function< void(Cluster *cluster)>
 

Public Member Functions

 Run (ParagraphImpl *owner, const SkShaper::RunHandler::RunInfo &info, size_t firstChar, SkScalar heightMultiplier, bool useHalfLeading, SkScalar baselineShift, size_t index, SkScalar shiftX)
 
 Run (const Run &)=default
 
Runoperator= (const Run &)=delete
 
 Run (Run &&)=default
 
Runoperator= (Run &&)=delete
 
 ~Run ()=default
 
void setOwner (ParagraphImpl *owner)
 
SkShaper::RunHandler::Buffer newRunBuffer ()
 
SkScalar posX (size_t index) const
 
void addX (size_t index, SkScalar shift)
 
SkScalar posY (size_t index) const
 
size_t size () const
 
void setWidth (SkScalar width)
 
void setHeight (SkScalar height)
 
void shift (SkScalar shiftX, SkScalar shiftY)
 
SkVector advance () const
 
SkVector offset () const
 
SkScalar ascent () const
 
SkScalar descent () const
 
SkScalar leading () const
 
SkScalar correctAscent () const
 
SkScalar correctDescent () const
 
SkScalar correctLeading () const
 
const SkFontfont () const
 
bool leftToRight () const
 
TextDirection getTextDirection () const
 
size_t index () const
 
SkScalar heightMultiplier () const
 
bool useHalfLeading () const
 
SkScalar baselineShift () const
 
PlaceholderStyleplaceholderStyle () const
 
bool isPlaceholder () const
 
size_t clusterIndex (size_t pos) const
 
size_t globalClusterIndex (size_t pos) const
 
SkScalar positionX (size_t pos) const
 
TextRange textRange () const
 
ClusterRange clusterRange () const
 
ParagraphImplowner () const
 
bool isEllipsis () const
 
void calculateMetrics ()
 
void updateMetrics (InternalLineMetrics *endlineMetrics)
 
void setClusterRange (size_t from, size_t to)
 
SkRect clip () const
 
void addSpacesAtTheEnd (SkScalar space, Cluster *cluster)
 
SkScalar addSpacesEvenly (SkScalar space, Cluster *cluster)
 
SkScalar addSpacesEvenly (SkScalar space)
 
void shift (const Cluster *cluster, SkScalar offset)
 
void extend (const Cluster *cluster, SkScalar offset)
 
SkScalar calculateHeight (LineMetricStyle ascentStyle, LineMetricStyle descentStyle) const
 
SkScalar calculateWidth (size_t start, size_t end, bool clip) const
 
void copyTo (SkTextBlobBuilder &builder, size_t pos, size_t size) const
 
template<typename Visitor >
void iterateThroughClustersInTextOrder (Visitor visitor)
 
void iterateThroughClusters (const ClusterVisitor &visitor)
 
std::tuple< bool, ClusterIndex, ClusterIndexfindLimitingClusters (TextRange text) const
 
std::tuple< bool, TextIndex, TextIndexfindLimitingGlyphClusters (TextRange text) const
 
std::tuple< bool, TextIndex, TextIndexfindLimitingGraphemes (TextRange text) const
 
SkSpan< const SkGlyphIDglyphs () const
 
SkSpan< const SkPointpositions () const
 
SkSpan< const SkPointoffsets () const
 
SkSpan< const uint32_t > clusterIndexes () const
 
void commit ()
 
void resetJustificationShifts ()
 
bool isResolved () const
 

Friends

class ParagraphImpl
 
class TextLine
 
class InternalLineMetrics
 
class ParagraphCache
 
class OneLineShaper
 

Detailed Description

Definition at line 55 of file Run.h.

Member Typedef Documentation

◆ ClusterVisitor

Definition at line 143 of file Run.h.

Constructor & Destructor Documentation

◆ Run() [1/3]

skia::textlayout::Run::Run ( ParagraphImpl owner,
const SkShaper::RunHandler::RunInfo info,
size_t  firstChar,
SkScalar  heightMultiplier,
bool  useHalfLeading,
SkScalar  baselineShift,
size_t  index,
SkScalar  shiftX 
)

Definition at line 17 of file Run.cpp.

25 : fOwner(owner)
26 , fTextRange(firstChar + info.utf8Range.begin(), firstChar + info.utf8Range.end())
27 , fClusterRange(EMPTY_CLUSTERS)
28 , fFont(info.fFont)
29 , fClusterStart(firstChar)
30 , fGlyphData(std::make_shared<GlyphData>())
31 , fGlyphs(fGlyphData->glyphs)
32 , fPositions(fGlyphData->positions)
33 , fOffsets(fGlyphData->offsets)
34 , fClusterIndexes(fGlyphData->clusterIndexes)
35 , fHeightMultiplier(heightMultiplier)
36 , fUseHalfLeading(useHalfLeading)
37 , fBaselineShift(baselineShift)
38{
39 fBidiLevel = info.fBidiLevel;
40 fAdvance = info.fAdvance;
41 fIndex = index;
42 fUtf8Range = info.utf8Range;
43 fOffset = SkVector::Make(offsetX, 0);
44
45 fGlyphs.push_back_n(info.glyphCount);
46 fPositions.push_back_n(info.glyphCount + 1);
47 fOffsets.push_back_n(info.glyphCount + 1);
48 fClusterIndexes.push_back_n(info.glyphCount + 1);
49 info.fFont.getMetrics(&fFontMetrics);
50
51 this->calculateMetrics();
52
53 // To make edge cases easier:
54 fPositions[info.glyphCount] = fOffset + fAdvance;
55 fOffsets[info.glyphCount] = {0, 0};
56 fClusterIndexes[info.glyphCount] = this->leftToRight() ? info.utf8Range.end() : info.utf8Range.begin();
57 fEllipsis = false;
58 fPlaceholderIndex = std::numeric_limits<size_t>::max();
59}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
void calculateMetrics()
Definition: Run.cpp:61
size_t index() const
Definition: Run.h:98
bool useHalfLeading() const
Definition: Run.h:100
SkScalar baselineShift() const
Definition: Run.h:101
ParagraphImpl * owner() const
Definition: Run.h:111
SkScalar heightMultiplier() const
Definition: Run.h:99
bool leftToRight() const
Definition: Run.h:96
T * push_back_n(int n)
Definition: SkTArray.h:267
static float max(float r, float g, float b)
Definition: hsl.cpp:49
const SkRange< size_t > EMPTY_CLUSTERS
Definition: Run.h:38
SkScalar offsetX
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
constexpr size_t end() const
Definition: SkShaper.h:204

◆ Run() [2/3]

skia::textlayout::Run::Run ( const Run )
default

◆ Run() [3/3]

skia::textlayout::Run::Run ( Run &&  )
default

◆ ~Run()

skia::textlayout::Run::~Run ( )
default

Member Function Documentation

◆ addSpacesAtTheEnd()

void skia::textlayout::Run::addSpacesAtTheEnd ( SkScalar  space,
Cluster cluster 
)

Definition at line 164 of file Run.cpp.

164 {
165 // Increment the run width
166 fAdvance.fX += space;
167 // Increment the cluster width
168 cluster->space(space);
169}
float fX
x-axis value
Definition: SkPoint_impl.h:164

◆ addSpacesEvenly() [1/2]

SkScalar skia::textlayout::Run::addSpacesEvenly ( SkScalar  space)

Definition at line 171 of file Run.cpp.

171 {
172 SkScalar shift = 0;
173 for (size_t i = 0; i < this->size(); ++i) {
174 fPositions[i].fX += shift;
175 shift += space;
176 }
177 fPositions[this->size()].fX += shift;
178 fAdvance.fX += shift;
179 return shift;
180}
void shift(SkScalar shiftX, SkScalar shiftY)
Definition: Run.h:81
size_t size() const
Definition: Run.h:78
float SkScalar
Definition: extension.cpp:12

◆ addSpacesEvenly() [2/2]

SkScalar skia::textlayout::Run::addSpacesEvenly ( SkScalar  space,
Cluster cluster 
)

Definition at line 182 of file Run.cpp.

182 {
183 // Offset all the glyphs in the cluster
184 SkScalar shift = 0;
185 for (size_t i = cluster->startPos(); i < cluster->endPos(); ++i) {
186 fPositions[i].fX += shift;
187 shift += space;
188 }
189 if (this->size() == cluster->endPos()) {
190 // To make calculations easier
191 fPositions[cluster->endPos()].fX += shift;
192 }
193 // Increment the run width
194 fAdvance.fX += shift;
195 // Increment the cluster width
196 cluster->space(shift);
197 cluster->setHalfLetterSpacing(space / 2);
198
199 return shift;
200}

◆ addX()

void skia::textlayout::Run::addX ( size_t  index,
SkScalar  shift 
)
inline

Definition at line 76 of file Run.h.

76{ fPositions[index].fX += shift; }

◆ advance()

SkVector skia::textlayout::Run::advance ( ) const
inline

Definition at line 85 of file Run.h.

85 {
86 return SkVector::Make(fAdvance.fX, fFontMetrics.fDescent - fFontMetrics.fAscent + fFontMetrics.fLeading);
87 }
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55

◆ ascent()

SkScalar skia::textlayout::Run::ascent ( ) const
inline

Definition at line 89 of file Run.h.

89{ return fFontMetrics.fAscent + fBaselineShift; }

◆ baselineShift()

SkScalar skia::textlayout::Run::baselineShift ( ) const
inline

Definition at line 101 of file Run.h.

101{ return fBaselineShift; }

◆ calculateHeight()

SkScalar skia::textlayout::Run::calculateHeight ( LineMetricStyle  ascentStyle,
LineMetricStyle  descentStyle 
) const
inline

Definition at line 129 of file Run.h.

129 {
130 auto ascent = ascentStyle == LineMetricStyle::Typographic ? this->ascent()
131 : this->correctAscent();
132 auto descent = descentStyle == LineMetricStyle::Typographic ? this->descent()
133 : this->correctDescent();
134 return descent - ascent;
135 }
SkScalar descent() const
Definition: Run.h:90
SkScalar correctDescent() const
Definition: Run.h:93
SkScalar ascent() const
Definition: Run.h:89
SkScalar correctAscent() const
Definition: Run.h:92

◆ calculateMetrics()

void skia::textlayout::Run::calculateMetrics ( )

Definition at line 61 of file Run.cpp.

61 {
62 fCorrectAscent = fFontMetrics.fAscent - fFontMetrics.fLeading * 0.5;
63 fCorrectDescent = fFontMetrics.fDescent + fFontMetrics.fLeading * 0.5;
64 fCorrectLeading = 0;
65 if (SkScalarNearlyZero(fHeightMultiplier)) {
66 return;
67 }
68 const auto runHeight = fHeightMultiplier * fFont.getSize();
69 const auto fontIntrinsicHeight = fCorrectDescent - fCorrectAscent;
70 if (fUseHalfLeading) {
71 const auto extraLeading = (runHeight - fontIntrinsicHeight) / 2;
72 fCorrectAscent -= extraLeading;
73 fCorrectDescent += extraLeading;
74 } else {
75 const auto multiplier = runHeight / fontIntrinsicHeight;
76 fCorrectAscent *= multiplier;
77 fCorrectDescent *= multiplier;
78 }
79 // If we shift the baseline we need to make sure the shifted text fits the line
80 fCorrectAscent += fBaselineShift;
81 fCorrectDescent += fBaselineShift;
82}
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
SkScalar getSize() const
Definition: SkFont.h:217

◆ calculateWidth()

SkScalar skia::textlayout::Run::calculateWidth ( size_t  start,
size_t  end,
bool  clip 
) const

Definition at line 383 of file ParagraphImpl.cpp.

383 {
384 SkASSERT(start <= end);
385 // clip |= end == size(); // Clip at the end of the run?
386 auto correction = 0.0f;
387 if (end > start && !fJustificationShifts.empty()) {
388 // This is not a typo: we are using Point as a pair of SkScalars
389 correction = fJustificationShifts[end - 1].fX -
390 fJustificationShifts[start].fY;
391 }
392 return posX(end) - posX(start) + correction;
393}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkScalar posX(size_t index) const
Definition: Run.h:75
bool empty() const
Definition: SkTArray.h:199
glong glong end

◆ clip()

SkRect skia::textlayout::Run::clip ( ) const
inline

Definition at line 119 of file Run.h.

119 {
120 return SkRect::MakeXYWH(fOffset.fX, fOffset.fY, fAdvance.fX, fAdvance.fY);
121 }
float fY
y-axis value
Definition: SkPoint_impl.h:165
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ clusterIndex()

size_t skia::textlayout::Run::clusterIndex ( size_t  pos) const
inline

Definition at line 104 of file Run.h.

104{ return fClusterIndexes[pos]; }
SkPoint pos

◆ clusterIndexes()

SkSpan< const uint32_t > skia::textlayout::Run::clusterIndexes ( ) const
inline

Definition at line 158 of file Run.h.

158 {
159 return SkSpan<const uint32_t>(fClusterIndexes.begin(), fClusterIndexes.size());
160 }
int size() const
Definition: SkTArray.h:421

◆ clusterRange()

ClusterRange skia::textlayout::Run::clusterRange ( ) const
inline

Definition at line 109 of file Run.h.

109{ return fClusterRange; }

◆ commit()

void skia::textlayout::Run::commit ( )
inline

Definition at line 162 of file Run.h.

162{ }

◆ copyTo()

void skia::textlayout::Run::copyTo ( SkTextBlobBuilder builder,
size_t  pos,
size_t  size 
) const

Definition at line 88 of file Run.cpp.

88 {
89 SkASSERT(pos + size <= this->size());
90 const auto& blobBuffer = builder.allocRunPos(fFont, SkToInt(size));
91 sk_careful_memcpy(blobBuffer.glyphs, fGlyphs.data() + pos, size * sizeof(SkGlyphID));
92
93 for (size_t i = 0; i < size; ++i) {
94 auto point = fPositions[i + pos];
95 if (!fJustificationShifts.empty()) {
96 point.fX += fJustificationShifts[i + pos].fX;
97 }
98 point += fOffsets[i + pos];
99 blobBuffer.points()[i] = point;
100 }
101}
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125
constexpr int SkToInt(S x)
Definition: SkTo.h:29
uint16_t SkGlyphID
Definition: SkTypes.h:179

◆ correctAscent()

SkScalar skia::textlayout::Run::correctAscent ( ) const
inline

Definition at line 92 of file Run.h.

92{ return fCorrectAscent + fBaselineShift; }

◆ correctDescent()

SkScalar skia::textlayout::Run::correctDescent ( ) const
inline

Definition at line 93 of file Run.h.

93{ return fCorrectDescent + fBaselineShift; }

◆ correctLeading()

SkScalar skia::textlayout::Run::correctLeading ( ) const
inline

Definition at line 94 of file Run.h.

94{ return fCorrectLeading; }

◆ descent()

SkScalar skia::textlayout::Run::descent ( ) const
inline

Definition at line 90 of file Run.h.

90{ return fFontMetrics.fDescent + fBaselineShift; }

◆ extend()

void skia::textlayout::Run::extend ( const Cluster cluster,
SkScalar  offset 
)

Definition at line 215 of file Run.cpp.

215 {
216 // Extend the cluster at the end
217 fPositions[cluster->endPos()].fX += offset;
218}
SkVector offset() const
Definition: Run.h:88

◆ findLimitingClusters()

std::tuple< bool, ClusterIndex, ClusterIndex > skia::textlayout::Run::findLimitingClusters ( TextRange  text) const

Definition at line 106 of file Run.cpp.

106 {
107 if (text.width() == 0) {
108 // Special Flutter case for "\n" and "...\n"
109 if (text.end > this->fTextRange.start) {
110 ClusterIndex index = fOwner->clusterIndex(text.end - 1);
111 return std::make_tuple(true, index, index);
112 } else {
113 return std::make_tuple(false, 0, 0);
114 }
115 }
116
118 bool found = true;
119 // Deal with the case when either start or end are not align with glyph cluster edge
120 // In such case we shift the text range to the right
121 // (cutting from the left and adding to the right)
122 if (leftToRight()) {
123 // LTR: [start:end)
124 found = clusterRange.start != fClusterRange.end;
125 clusterRange.start = fOwner->clusterIndex(text.start);
126 clusterRange.end = fOwner->clusterIndex(text.end - 1);
127 } else {
128 // RTL: (start:end]
129 clusterRange.start = fOwner->clusterIndex(text.end);
130 clusterRange.end = fOwner->clusterIndex(text.start + 1);
131 found = clusterRange.end != fClusterRange.start;
132 }
133
134 return std::make_tuple(
135 found,
138}
ClusterIndex clusterIndex(TextIndex textIndex)
ClusterRange clusterRange() const
Definition: Run.h:109
std::u16string text
SkRange< size_t > ClusterRange
Definition: Run.h:36
size_t ClusterIndex
Definition: Run.h:35

◆ findLimitingGlyphClusters()

std::tuple< bool, TextIndex, TextIndex > skia::textlayout::Run::findLimitingGlyphClusters ( TextRange  text) const

Definition at line 140 of file Run.cpp.

140 {
143 return std::make_tuple(true, start, end);
144}
TextIndex findNextGlyphClusterBoundary(TextIndex utf8) const
TextIndex findPreviousGlyphClusterBoundary(TextIndex utf8) const
size_t TextIndex
Definition: TextStyle.h:336

◆ findLimitingGraphemes()

std::tuple< bool, TextIndex, TextIndex > skia::textlayout::Run::findLimitingGraphemes ( TextRange  text) const

Definition at line 149 of file Run.cpp.

149 {
152 return std::make_tuple(true, start, end);
153}
TextIndex findPreviousGraphemeBoundary(TextIndex utf8) const
TextIndex findNextGraphemeBoundary(TextIndex utf8) const

◆ font()

const SkFont & skia::textlayout::Run::font ( ) const
inline

Definition at line 95 of file Run.h.

95{ return fFont; }

◆ getTextDirection()

TextDirection skia::textlayout::Run::getTextDirection ( ) const
inline

◆ globalClusterIndex()

size_t skia::textlayout::Run::globalClusterIndex ( size_t  pos) const
inline

Definition at line 105 of file Run.h.

105{ return fClusterStart + fClusterIndexes[pos]; }

◆ glyphs()

SkSpan< const SkGlyphID > skia::textlayout::Run::glyphs ( ) const
inline

Definition at line 149 of file Run.h.

149 {
150 return SkSpan<const SkGlyphID>(fGlyphs.begin(), fGlyphs.size());
151 }

◆ heightMultiplier()

SkScalar skia::textlayout::Run::heightMultiplier ( ) const
inline

Definition at line 99 of file Run.h.

99{ return fHeightMultiplier; }

◆ index()

size_t skia::textlayout::Run::index ( ) const
inline

Definition at line 98 of file Run.h.

98{ return fIndex; }

◆ isEllipsis()

bool skia::textlayout::Run::isEllipsis ( ) const
inline

Definition at line 113 of file Run.h.

113{ return fEllipsis; }

◆ isPlaceholder()

bool skia::textlayout::Run::isPlaceholder ( ) const
inline

Definition at line 103 of file Run.h.

103{ return fPlaceholderIndex != std::numeric_limits<size_t>::max(); }

◆ isResolved()

bool skia::textlayout::Run::isResolved ( ) const

Definition at line 320 of file Run.cpp.

320 {
321 for (auto& glyph :fGlyphs) {
322 if (glyph == 0) {
323 return false;
324 }
325 }
326 return true;
327}

◆ iterateThroughClusters()

void skia::textlayout::Run::iterateThroughClusters ( const ClusterVisitor visitor)

Definition at line 155 of file Run.cpp.

155 {
156
157 for (size_t index = 0; index < fClusterRange.width(); ++index) {
158 auto correctIndex = leftToRight() ? fClusterRange.start + index : fClusterRange.end - index - 1;
159 auto cluster = &fOwner->cluster(correctIndex);
160 visitor(cluster);
161 }
162}
Cluster & cluster(ClusterIndex clusterIndex)

◆ iterateThroughClustersInTextOrder()

template<typename Visitor >
void skia::textlayout::Run::iterateThroughClustersInTextOrder ( Visitor  visitor)

Definition at line 218 of file Run.h.

218 {
219 // Can't figure out how to do it with one code for both cases without 100 ifs
220 // Can't go through clusters because there are no cluster table yet
221 if (leftToRight()) {
222 size_t start = 0;
223 size_t cluster = this->clusterIndex(start);
224 for (size_t glyph = 1; glyph <= this->size(); ++glyph) {
225 auto nextCluster = this->clusterIndex(glyph);
226 if (nextCluster <= cluster) {
227 continue;
228 }
229
230 visitor(start,
231 glyph,
232 fClusterStart + cluster,
233 fClusterStart + nextCluster,
234 this->calculateWidth(start, glyph, glyph == size()),
236
237 start = glyph;
238 cluster = nextCluster;
239 }
240 } else {
241 size_t glyph = this->size();
242 size_t cluster = this->fUtf8Range.begin();
243 for (int32_t start = this->size() - 1; start >= 0; --start) {
244 size_t nextCluster =
245 start == 0 ? this->fUtf8Range.end() : this->clusterIndex(start - 1);
246 if (nextCluster <= cluster) {
247 continue;
248 }
249
250 visitor(start,
251 glyph,
252 fClusterStart + cluster,
253 fClusterStart + nextCluster,
254 this->calculateWidth(start, glyph, glyph == 0),
256
257 glyph = start;
258 cluster = nextCluster;
259 }
260 }
261}
SkScalar calculateHeight(LineMetricStyle ascentStyle, LineMetricStyle descentStyle) const
Definition: Run.h:129
size_t clusterIndex(size_t pos) const
Definition: Run.h:104
SkScalar calculateWidth(size_t start, size_t end, bool clip) const
constexpr size_t begin() const
Definition: SkShaper.h:203

◆ leading()

SkScalar skia::textlayout::Run::leading ( ) const
inline

Definition at line 91 of file Run.h.

91{ return fFontMetrics.fLeading; }

◆ leftToRight()

bool skia::textlayout::Run::leftToRight ( ) const
inline

Definition at line 96 of file Run.h.

96{ return fBidiLevel % 2 == 0; }

◆ newRunBuffer()

SkShaper::RunHandler::Buffer skia::textlayout::Run::newRunBuffer ( )

Definition at line 84 of file Run.cpp.

84 {
85 return {fGlyphs.data(), fPositions.data(), fOffsets.data(), fClusterIndexes.data(), fOffset};
86}

◆ offset()

SkVector skia::textlayout::Run::offset ( ) const
inline

Definition at line 88 of file Run.h.

88{ return fOffset; }

◆ offsets()

SkSpan< const SkPoint > skia::textlayout::Run::offsets ( ) const
inline

Definition at line 155 of file Run.h.

155 {
156 return SkSpan<const SkPoint>(fOffsets.begin(), fOffsets.size());
157 }

◆ operator=() [1/2]

Run & skia::textlayout::Run::operator= ( const Run )
delete

◆ operator=() [2/2]

Run & skia::textlayout::Run::operator= ( Run &&  )
delete

◆ owner()

ParagraphImpl * skia::textlayout::Run::owner ( ) const
inline

Definition at line 111 of file Run.h.

111{ return fOwner; }

◆ placeholderStyle()

PlaceholderStyle * skia::textlayout::Run::placeholderStyle ( ) const

Definition at line 312 of file Run.cpp.

312 {
313 if (isPlaceholder()) {
314 return &fOwner->placeholders()[fPlaceholderIndex].fStyle;
315 } else {
316 return nullptr;
317 }
318}
SkSpan< Placeholder > placeholders()
bool isPlaceholder() const
Definition: Run.h:103

◆ positions()

SkSpan< const SkPoint > skia::textlayout::Run::positions ( ) const
inline

Definition at line 152 of file Run.h.

152 {
153 return SkSpan<const SkPoint>(fPositions.begin(), fPositions.size());
154 }

◆ positionX()

SkScalar skia::textlayout::Run::positionX ( size_t  pos) const

Definition at line 308 of file Run.cpp.

308 {
309 return posX(pos) + (fJustificationShifts.empty() ? 0 : fJustificationShifts[pos].fY);
310}

◆ posX()

SkScalar skia::textlayout::Run::posX ( size_t  index) const
inline

Definition at line 75 of file Run.h.

75{ return fPositions[index].fX; }

◆ posY()

SkScalar skia::textlayout::Run::posY ( size_t  index) const
inline

Definition at line 77 of file Run.h.

77{ return fPositions[index].fY; }

◆ resetJustificationShifts()

void skia::textlayout::Run::resetJustificationShifts ( )
inline

Definition at line 164 of file Run.h.

164 {
165 fJustificationShifts.clear();
166 }

◆ setClusterRange()

void skia::textlayout::Run::setClusterRange ( size_t  from,
size_t  to 
)
inline

Definition at line 118 of file Run.h.

118{ fClusterRange = ClusterRange(from, to); }

◆ setHeight()

void skia::textlayout::Run::setHeight ( SkScalar  height)
inline

Definition at line 80 of file Run.h.

80{ fAdvance.fY = height; }
int32_t height

◆ setOwner()

void skia::textlayout::Run::setOwner ( ParagraphImpl owner)
inline

Definition at line 71 of file Run.h.

71{ fOwner = owner; }

◆ setWidth()

void skia::textlayout::Run::setWidth ( SkScalar  width)
inline

Definition at line 79 of file Run.h.

79{ fAdvance.fX = width; }
int32_t width

◆ shift() [1/2]

void skia::textlayout::Run::shift ( const Cluster cluster,
SkScalar  offset 
)

Definition at line 202 of file Run.cpp.

202 {
203 if (offset == 0) {
204 return;
205 }
206 for (size_t i = cluster->startPos(); i < cluster->endPos(); ++i) {
207 fPositions[i].fX += offset;
208 }
209 if (this->size() == cluster->endPos()) {
210 // To make calculations easier
211 fPositions[cluster->endPos()].fX += offset;
212 }
213}

◆ shift() [2/2]

void skia::textlayout::Run::shift ( SkScalar  shiftX,
SkScalar  shiftY 
)
inline

Definition at line 81 of file Run.h.

81 {
82 fOffset.fX += shiftX;
83 fOffset.fY += shiftY;
84 }

◆ size()

size_t skia::textlayout::Run::size ( ) const
inline

Definition at line 78 of file Run.h.

78{ return fGlyphs.size(); }

◆ textRange()

TextRange skia::textlayout::Run::textRange ( ) const
inline

Definition at line 108 of file Run.h.

108{ return fTextRange; }

◆ updateMetrics()

void skia::textlayout::Run::updateMetrics ( InternalLineMetrics endlineMetrics)

Definition at line 220 of file Run.cpp.

220 {
221
223 auto placeholderStyle = this->placeholderStyle();
224 // Difference between the placeholder baseline and the line bottom
225 SkScalar baselineAdjustment = 0;
226 switch (placeholderStyle->fBaseline) {
228 break;
229
231 baselineAdjustment = endlineMetrics->deltaBaselines() / 2;
232 break;
233 }
234
237
238 fFontMetrics.fLeading = 0;
239 switch (placeholderStyle->fAlignment) {
241 fFontMetrics.fAscent = baselineAdjustment - offset;
242 fFontMetrics.fDescent = baselineAdjustment + height - offset;
243 break;
244
246 fFontMetrics.fAscent = baselineAdjustment - height;
247 fFontMetrics.fDescent = baselineAdjustment;
248 break;
249
251 fFontMetrics.fAscent = baselineAdjustment;
252 fFontMetrics.fDescent = baselineAdjustment + height;
253 break;
254
256 fFontMetrics.fDescent = height + fFontMetrics.fAscent;
257 break;
258
260 fFontMetrics.fAscent = fFontMetrics.fDescent - height;
261 break;
262
264 auto mid = (-fFontMetrics.fDescent - fFontMetrics.fAscent)/2.0;
265 fFontMetrics.fDescent = height/2.0 - mid;
266 fFontMetrics.fAscent = - height/2.0 - mid;
267 break;
268 }
269
270 this->calculateMetrics();
271
272 // Make sure the placeholder can fit the line
273 endlineMetrics->add(this);
274}
PlaceholderStyle * placeholderStyle() const
Definition: Run.cpp:312
@ kBaseline
Match the baseline of the placeholder with the baseline.
PlaceholderAlignment fAlignment
Definition: TextStyle.h:138

◆ useHalfLeading()

bool skia::textlayout::Run::useHalfLeading ( ) const
inline

Definition at line 100 of file Run.h.

100{ return fUseHalfLeading; }

Friends And Related Function Documentation

◆ InternalLineMetrics

friend class InternalLineMetrics
friend

Definition at line 172 of file Run.h.

◆ OneLineShaper

friend class OneLineShaper
friend

Definition at line 174 of file Run.h.

◆ ParagraphCache

friend class ParagraphCache
friend

Definition at line 173 of file Run.h.

◆ ParagraphImpl

friend class ParagraphImpl
friend

Definition at line 170 of file Run.h.

◆ TextLine

friend class TextLine
friend

Definition at line 171 of file Run.h.


The documentation for this class was generated from the following files: