Skip to content

Commit ae0d860

Browse files
reed-at-googleSkia Commit-Bot
authored andcommitted
move intercepts call to textblob
Bug: skia: Change-Id: Ic7cd8ec1b33bd278ed489cbc1ccca35bd4776e27 Reviewed-on: https://skia-review.googlesource.com/c/175833 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
1 parent 376a748 commit ae0d860

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

gm/texteffects.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ static void find_intercepts(const char* text, size_t len, SkScalar x, SkScalar y
4545

4646
SkScalar uPos = uWidth;
4747
SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 };
48-
int count = paint.getTextBlobIntercepts(blob.get(), bounds, nullptr);
48+
int count = blob->getIntercepts(bounds, nullptr, &paint);
4949
SkASSERT(!(count % 2));
5050
if (count) {
5151
intersections->setCount(count);
52-
paint.getTextBlobIntercepts(blob.get(), bounds, intersections->begin());
52+
blob->getIntercepts(bounds, intersections->begin(), &paint);
5353
for (int i = 0; i < count; ++i) {
5454
(*intersections)[i] += x;
5555
}
@@ -95,11 +95,11 @@ static void find_intercepts(const char* text, size_t len, const SkPoint* pos, co
9595

9696
SkScalar uPos = pos[0].fY + uWidth;
9797
SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 };
98-
int count = paint.getTextBlobIntercepts(blob.get(), bounds, nullptr);
98+
int count = blob->getIntercepts(bounds, nullptr, &paint);
9999
SkASSERT(!(count % 2));
100100
if (count) {
101101
intersections->setCount(count);
102-
paint.getTextBlobIntercepts(blob.get(), bounds, intersections->begin());
102+
blob->getIntercepts(bounds, intersections->begin(), &paint);
103103
}
104104
}
105105

@@ -227,12 +227,12 @@ DEF_SIMPLE_GM(fancyblobunderline, canvas, 1480, 1380) {
227227

228228
const SkScalar uPos = uWidth;
229229
const SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 };
230-
const int interceptCount = paint.getTextBlobIntercepts(blob.get(), bounds, nullptr);
230+
const int interceptCount = blob->getIntercepts(bounds, nullptr, &paint);
231231
SkASSERT(!(interceptCount % 2));
232232

233233
SkTDArray<SkScalar> intercepts;
234234
intercepts.setCount(interceptCount);
235-
paint.getTextBlobIntercepts(blob.get(), bounds, intercepts.begin());
235+
blob->getIntercepts(bounds, intercepts.begin(), &paint);
236236

237237
const SkScalar start = blob->bounds().left();
238238
const SkScalar end = blob->bounds().right();

include/core/SkTextBlob.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ class SK_API SkTextBlob final : public SkNVRefCnt<SkTextBlob> {
5151
*/
5252
uint32_t uniqueID() const { return fUniqueID; }
5353

54+
/** Returns the number of intervals that intersect bounds.
55+
bounds describes a pair of lines parallel to the text advance.
56+
The return count is zero or a multiple of two, and is at most twice the number of glyphs in
57+
the the blob.
58+
59+
Pass nullptr for intervals to determine the size of the interval array.
60+
61+
@param bounds lower and upper line parallel to the advance
62+
@param intervals returned intersections; may be nullptr
63+
@param paint specifies stroking, patheffect that may affect the result; may be nullptr
64+
@return number of intersections; may be zero
65+
*/
66+
int getIntercepts(const SkScalar bounds[2], SkScalar intervals[],
67+
const SkPaint* paint = nullptr) const;
68+
5469
/** Creates SkTextBlob with a single run.
5570
5671
font contains attributes used to define the run text.

src/core/SkTextBlob.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,15 @@ sk_sp<SkTextBlob> SkTextBlobBuilder::make() {
587587

588588
///////////////////////////////////////////////////////////////////////////////////////////////////
589589

590+
int SkTextBlob::getIntercepts(const SkScalar bounds[2], SkScalar intervals[],
591+
const SkPaint* paint) const {
592+
SkPaint defaultPaint;
593+
if (!paint) {
594+
paint = &defaultPaint;
595+
}
596+
return paint->getTextBlobIntercepts(this, bounds, intervals);
597+
}
598+
590599
void SkTextBlobPriv::Flatten(const SkTextBlob& blob, SkWriteBuffer& buffer) {
591600
buffer.writeRect(blob.fBounds);
592601

0 commit comments

Comments
 (0)