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

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: correct comment to multiply by two 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
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | src/core/SkTextToPathIter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPaint.cpp
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index b9f5cedc1531c7115b64f31eaef5d9b46f6c67b5..cea3d0fc8dde623e16bfa8a538166438a43ea264 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -1259,6 +1259,23 @@ void SkPaint::getTextPath(const void* textData, size_t length,
}
}
+int SkPaint::getTextIntercepts(const void* textData, size_t length,
+ SkScalar x, SkScalar y, const 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);
@@ -1288,6 +1305,25 @@ void SkPaint::getPosTextPath(const void* textData, size_t length,
}
}
+int SkPaint::getPosTextIntercepts(const void* textData, size_t length, const SkPoint pos[],
+ const 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);
@@ -2352,7 +2388,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) {
@@ -2415,7 +2451,7 @@ SkTextToPathIter::SkTextToPathIter(const char text[], size_t length,
fXYIndex = paint.isVerticalText() ? 1 : 0;
}
-SkTextToPathIter::~SkTextToPathIter() {
+SkTextBaseIter::~SkTextBaseIter() {
SkGlyphCache::AttachCache(fCache);
}
@@ -2443,6 +2479,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
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | src/core/SkTextToPathIter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698