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/SkFont.cpp b/src/core/SkFont.cpp
index 7f1b9ea..eee88af 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -302,7 +302,8 @@
}
template <typename HANDLER>
-void VisitGlyphs(const SkFont& origFont, const uint16_t glyphs[], int count, HANDLER handler) {
+void VisitGlyphs(const SkFont& origFont, const SkPaint* paint, const uint16_t glyphs[], int count,
+ HANDLER handler) {
if (count <= 0) {
return;
}
@@ -314,12 +315,14 @@
scale = 1;
}
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font);
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font,
+ paint ? *paint : SkPaint());
handler(cache.get(), glyphs, count, scale);
}
-void SkFont::getWidths(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[]) const {
- VisitGlyphs(*this, glyphs, count, [widths, bounds]
+void SkFont::getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
+ const SkPaint* paint) const {
+ VisitGlyphs(*this, paint, glyphs, count, [widths, bounds]
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
for (int i = 0; i < count; ++i) {
const SkGlyph* g;
@@ -337,7 +340,7 @@
}
void SkFont::getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin) const {
- VisitGlyphs(*this, glyphs, count, [pos, origin]
+ VisitGlyphs(*this, nullptr, glyphs, count, [pos, origin]
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
SkPoint loc = origin;
for (int i = 0; i < count; ++i) {
@@ -348,7 +351,7 @@
}
void SkFont::getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin) const {
- VisitGlyphs(*this, glyphs, count, [xpos, origin]
+ VisitGlyphs(*this, nullptr, glyphs, count, [xpos, origin]
(SkGlyphCache* cache, const uint16_t glyphs[], int count, SkScalar scale) {
SkScalar x = origin;
for (int i = 0; i < count; ++i) {
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();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index c37d634..3e71a1a 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -196,18 +196,20 @@
}
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint) {
- return FindOrCreateStrikeExclusive(
- paint, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
- kFakeGammaAndBoostContrast, SkMatrix::I());
+ return FindOrCreateStrikeWithNoDeviceExclusive(SkFont::LEGACY_ExtractFromPaint(paint), paint);
}
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font) {
+ return FindOrCreateStrikeWithNoDeviceExclusive(font, SkPaint());
+}
+
+SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
+ const SkPaint& paint) {
SkAutoDescriptor ad;
SkScalerContextEffects effects;
- auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font,
- SkPaint(),
- SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
- kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
+ auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(font, paint,
+ SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
+ kFakeGammaAndBoostContrast, SkMatrix::I(), &ad, &effects);
auto typeface = SkFontPriv::GetTypefaceOrDefault(font);
return SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface);
}
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index df7f61e..d6b2d89 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -136,6 +136,9 @@
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont&);
+ static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
+ const SkPaint& paint);
+
static std::unique_ptr<SkScalerContext> CreateScalerContext(
const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&);