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

Unified Diff: third_party/WebKit/Source/platform/fonts/Font.cpp

Issue 2416603002: Add ability to compute text intercepts to Font (Closed)
Patch Set: Addressing fmalita's review comments Created 4 years, 2 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: third_party/WebKit/Source/platform/fonts/Font.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/Font.cpp b/third_party/WebKit/Source/platform/fonts/Font.cpp
index 271ed83045017fa02b64325d4b2f92c8b443bf4d..c2cb57fce9e0e63ac3df6f63e6a8bd36f85f513a 100644
--- a/third_party/WebKit/Source/platform/fonts/Font.cpp
+++ b/third_party/WebKit/Source/platform/fonts/Font.cpp
@@ -407,6 +407,74 @@ void Font::drawGlyphBuffer(SkCanvas* canvas,
}
}
+static int getInterceptsFromBloberizer(const GlyphBuffer& glyphBuffer,
+ const Font* font,
+ const SkPaint& paint,
+ float deviceScaleFactor,
+ const std::tuple<float, float>& bounds,
+ SkScalar* interceptsBuffer) {
+ SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)};
+ GlyphBufferBloberizer bloberizer(glyphBuffer, font, deviceScaleFactor);
+ std::pair<sk_sp<SkTextBlob>, BlobRotation> blob;
+
+ int numIntervals = 0;
+ while (!bloberizer.done()) {
+ blob = bloberizer.next();
+ DCHECK(blob.first);
+
+ // GlyphBufferBloberizer splits for a new blob rotation, but does not split
+ // for a change in font. A TextBlob can contain runs with differing fonts
+ // and the getTextBlobIntercepts method handles multiple fonts for us. For
+ // upright in vertical blobs we currently have to bail, see crbug.com/655154
+ if (blob.second == BlobRotation::CCWRotation)
+ continue;
+
+ SkScalar* offsetInterceptsBuffer = nullptr;
+ if (interceptsBuffer)
+ offsetInterceptsBuffer = &interceptsBuffer[numIntervals];
+ numIntervals += paint.getTextBlobIntercepts(blob.first.get(), boundsArray,
+ interceptsBuffer);
f(malita) 2016/10/14 15:39:21 Ah, the bots caught this one: I think we want offs
+ }
+ return numIntervals;
+}
+
+void Font::getTextIntercepts(const TextRunPaintInfo& runInfo,
+ float deviceScaleFactor,
+ const SkPaint& paint,
+ const std::tuple<float, float>& bounds,
+ Vector<TextIntercept>& intercepts) const {
+ if (shouldSkipDrawing())
+ return;
+
+ int numIntervals = 0;
f(malita) 2016/10/14 15:36:48 nit: no need to decl/initialize numIntervals here
drott 2016/10/14 16:36:45 Yes, moved the second declaration down to line 468
+
+ if (runInfo.cachedTextBlob && runInfo.cachedTextBlob->get()) {
+ SkScalar boundsArray[2] = {std::get<0>(bounds), std::get<1>(bounds)};
+ int numIntervals = paint.getTextBlobIntercepts(
+ runInfo.cachedTextBlob->get(), boundsArray, nullptr);
+ DCHECK_EQ(numIntervals % 2, 0);
+ intercepts.resize(numIntervals / 2);
+ paint.getTextBlobIntercepts(runInfo.cachedTextBlob->get(), boundsArray,
f(malita) 2016/10/14 15:36:48 nit: not sure how common this is in practice, but
drott 2016/10/14 16:36:45 Done.
+ reinterpret_cast<SkScalar*>(intercepts.data()));
+ return;
+ }
+
+ GlyphBuffer glyphBuffer;
+ buildGlyphBuffer(runInfo, glyphBuffer);
+
+ // Get the number of intervals, without copying the actual values by
+ // specifying nullptr for the buffer, following the Skia allocation model for
+ // retrieving text intercepts.
+ numIntervals = getInterceptsFromBloberizer(
+ glyphBuffer, this, paint, deviceScaleFactor, bounds, nullptr);
+ DCHECK_EQ(numIntervals % 2, 0);
+ intercepts.resize(numIntervals / 2);
+
+ getInterceptsFromBloberizer(glyphBuffer, this, paint, deviceScaleFactor,
f(malita) 2016/10/14 15:36:48 nit: ditto
drott 2016/10/14 16:36:46 Done here as well.
+ bounds,
+ reinterpret_cast<SkScalar*>(intercepts.data()));
+}
+
static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) {
// Using roundf() rather than ceilf() for the right edge as a compromise to
// ensure correct caret positioning.
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/Font.h ('k') | third_party/WebKit/Source/platform/fonts/FontTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698