Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: src/core/SkPaint.cpp

Issue 1654883003: add helper to create fancy underlines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix uninitialized var Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index e5fe975bcd7db719b5ef7e4018919e4bbc36f74e..e2675742d1e654c1080a8f4649845700e895aa98 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1199,6 +1199,23 @@ void SkPaint::getTextPath(const void* textData, size_t length,
}
}
+int SkPaint::getTextIntercepts(const void* textData, size_t length,
+ SkScalar x, SkScalar y, SkScalar bounds[2],
+ SkScalar* array) const {
+ SkASSERT(length == 0 || textData != nullptr);
+ if (!length) {
+ return 0;
+ }
+
+ const char* text = (const char*) textData;
+ SkTextInterceptsIter iter(text, length, *this, bounds, x, y,
+ SkTextInterceptsIter::TextType::kText);
+ int count = 0;
+ while (iter.next(array, &count)) {
+ }
+ return count;
+}
+
void SkPaint::getPosTextPath(const void* textData, size_t length,
const SkPoint pos[], SkPath* path) const {
SkASSERT(length == 0 || textData != nullptr);
@@ -1228,6 +1245,25 @@ void SkPaint::getPosTextPath(const void* textData, size_t length,
}
}
+int SkPaint::getPosTextIntercepts(const void* textData, size_t length, const SkPoint pos[],
+ SkScalar bounds[2], SkScalar* array) const {
+ SkASSERT(length == 0 || textData != nullptr);
+ if (!length) {
+ return 0;
+ }
+
+ const char* text = (const char*) textData;
+ SkTextInterceptsIter iter(text, length, *this, bounds, pos[0].fX, pos[0].fY,
+ SkTextInterceptsIter::TextType::kPosText);
+ int i = 0;
+ int count = 0;
+ while (iter.next(array, &count)) {
+ i++;
+ iter.setPosition(pos[i].fX, pos[i].fY);
+ }
+ return count;
+}
+
SkRect SkPaint::getFontBounds() const {
SkMatrix m;
m.setScale(fTextSize * fTextScaleX, fTextSize);
@@ -2292,7 +2328,7 @@ static bool has_thick_frame(const SkPaint& paint) {
paint.getStyle() != SkPaint::kFill_Style;
}
-SkTextToPathIter::SkTextToPathIter(const char text[], size_t length,
+SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
const SkPaint& paint,
bool applyStrokeAndPathEffects)
: fPaint(paint) {
@@ -2355,7 +2391,7 @@ SkTextToPathIter::SkTextToPathIter(const char text[], size_t length,
fXYIndex = paint.isVerticalText() ? 1 : 0;
}
-SkTextToPathIter::~SkTextToPathIter() {
+SkTextBaseIter::~SkTextBaseIter() {
SkGlyphCache::AttachCache(fCache);
}
@@ -2383,6 +2419,17 @@ bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
return false;
}
+bool SkTextInterceptsIter::next(SkScalar* array, int* count) {
+ const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
+ fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(glyph)), fScale);
+ fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
+ if (fCache->findPath(glyph)) {
+ fCache->findIntercepts(fBounds, fScale, fXPos, SkToBool(fXYIndex),
+ const_cast<SkGlyph*>(&glyph), array, count);
+ }
+ return fText < fStop;
+}
+
///////////////////////////////////////////////////////////////////////////////
// return true if the filter exists, and may affect alpha
« src/core/SkGlyph.h ('K') | « src/core/SkGlyphCache.cpp ('k') | src/core/SkTextToPathIter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698