Revert "Revert "migrate to passing paint/ctm for bounds""
Fix: pass real paint to FindOrCreateStrikeWithNoDeviceExclusive
This reverts commit 914d319a02fcadc6d9d74c69ffd9d27f7aeddb2d.
Bug: skia:
Change-Id: I2d618a868ae57e34cba5964aadd4a365481cb4cd
Reviewed-on: https://skia-review.googlesource.com/c/172976
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index e55dd3a..3a8dd8d 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -405,63 +405,11 @@
///////////////////////////////////////////////////////////////////////////////
-static void set_bounds(const SkGlyph& g, SkRect* bounds, SkScalar scale) {
- bounds->set(g.fLeft * scale,
- g.fTop * scale,
- (g.fLeft + g.fWidth) * scale,
- (g.fTop + g.fHeight) * scale);
-}
-
-int SkPaint::getTextWidths(const void* textData, size_t byteLength,
- SkScalar widths[], SkRect bounds[]) const {
- if (0 == byteLength) {
- return 0;
- }
-
- SkASSERT(textData);
-
- if (nullptr == widths && nullptr == bounds) {
- return this->countText(textData, byteLength);
- }
-
- SkCanonicalizePaint canon(*this);
- const SkPaint& paint = canon.getPaint();
- SkScalar scale = canon.getScale();
-
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
- SkFontPriv::GlyphCacheProc glyphCacheProc = SkFontPriv::GetGlyphCacheProc(
- static_cast<SkTextEncoding>(paint.getTextEncoding()), nullptr != bounds);
-
- const char* text = (const char*)textData;
- const char* stop = text + byteLength;
- int count = 0;
-
- if (scale) {
- while (text < stop) {
- const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
- if (widths) {
- *widths++ = advance(g) * scale;
- }
- if (bounds) {
- set_bounds(g, bounds++, scale);
- }
- ++count;
- }
- } else {
- while (text < stop) {
- const SkGlyph& g = glyphCacheProc(cache.get(), &text, stop);
- if (widths) {
- *widths++ = advance(g);
- }
- if (bounds) {
- set_bounds(g, bounds++);
- }
- ++count;
- }
- }
-
- SkASSERT(text == stop);
- return count;
+int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRect bounds[]) const {
+ const SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
+ SkAutoToGlyphs gly(font, text, len, (SkTextEncoding)this->getTextEncoding());
+ font.getWidthsBounds(gly.glyphs(), gly.count(), widths, bounds, this);
+ return gly.count();
}
///////////////////////////////////////////////////////////////////////////////