hide paint's getFontBounds
Bug: skia:
Change-Id: I26b693e32d0dadfe47710a29296eceb8ec90ee0c
Reviewed-on: https://skia-review.googlesource.com/c/174308
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Herb Derby <herb@google.com>
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index efa75a9..ef149f9 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2530,13 +2530,14 @@
}
// These call the (virtual) onDraw... method
-void SkCanvas::drawSimpleText(const void* text, size_t byteLength, SkTextEncoding,
+void SkCanvas::drawSimpleText(const void* text, size_t byteLength, SkTextEncoding encoding,
SkScalar x, SkScalar y, const SkFont& font, const SkPaint& paint) {
TRACE_EVENT0("skia", TRACE_FUNC);
if (byteLength) {
sk_msan_assert_initialized(text, SkTAddOffset<const void>(text, byteLength));
SkPaint tmp(paint);
font.LEGACY_applyToPaint(&tmp);
+ tmp.setTextEncoding(encoding);
this->onDrawText(text, byteLength, x, y, tmp);
}
}
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index f19ba59..1b0a86b 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -527,3 +527,18 @@
}
this->setEdging(edging);
}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+SkRect SkFontPriv::GetFontBounds(const SkFont& font) {
+ SkMatrix m;
+ m.setScale(font.getSize() * font.getScaleX(), font.getSize());
+ m.postSkew(font.getSkewX(), 0);
+
+ SkTypeface* typeface = SkFontPriv::GetTypefaceOrDefault(font);
+
+ SkRect bounds;
+ m.mapRect(&bounds, typeface->getBounds());
+ return bounds;
+}
+
diff --git a/src/core/SkFontPriv.h b/src/core/SkFontPriv.h
index eeeb930..1d1cfc1 100644
--- a/src/core/SkFontPriv.h
+++ b/src/core/SkFontPriv.h
@@ -45,6 +45,19 @@
typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**, const char*);
static GlyphCacheProc GetGlyphCacheProc(SkTextEncoding encoding, bool needFullMetrics);
+
+ /**
+ Returns the union of bounds of all glyphs.
+ Returned dimensions are computed by font manager from font data,
+ ignoring SkPaint::Hinting. Includes font metrics, but not fake bold or SkPathEffect.
+
+ If text size is large, text scale is one, and text skew is zero,
+ returns the bounds as:
+ { SkFontMetrics::fXMin, SkFontMetrics::fTop, SkFontMetrics::fXMax, SkFontMetrics::fBottom }.
+
+ @return union of bounds of all glyphs
+ */
+ static SkRect GetFontBounds(const SkFont&);
};
class SkAutoToGlyphs {
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index 91e92f7..0d94a4f 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -541,18 +541,6 @@
return count;
}
-SkRect SkPaint::getFontBounds() const {
- SkMatrix m;
- m.setScale(fTextSize * fTextScaleX, fTextSize);
- m.postSkew(fTextSkewX, 0);
-
- SkTypeface* typeface = SkPaintPriv::GetTypefaceOrDefault(*this);
-
- SkRect bounds;
- m.mapRect(&bounds, typeface->getBounds());
- return bounds;
-}
-
// return true if the paint is just a single color (i.e. not a shader). If its
// a shader, then we can't compute a const luminance for it :(
static bool just_a_color(const SkPaint& paint, SkColor* color) {
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index f050838..aa8bd69 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -6,7 +6,7 @@
*/
#include "SkTextBlob.h"
-
+#include "SkFontPriv.h"
#include "SkGlyphRun.h"
#include "SkPaintPriv.h"
#include "SkReadBuffer.h"
@@ -328,7 +328,8 @@
SkPaint paint;
run.font().applyToPaint(&paint);
- const SkRect fontBounds = paint.getFontBounds();
+ SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
+ const SkRect fontBounds = SkFontPriv::GetFontBounds(font);
if (fontBounds.isEmpty()) {
// Empty font bounds are likely a font bug. TightBounds has a better chance of
// producing useful results in this case.