Revert "route getFontMetrics to SkFont"

This reverts commit 445148df00.

Reason for revert: win layout failure

browser/ui/views/layout_provider_unittest.cc

Original change's description:
> route getFontMetrics to SkFont
> 
> Bug: skia:2664
> Change-Id: I6ce7ff1a99101c7b4c8902a7d80e4a6338c9ed97
> Reviewed-on: https://skia-review.googlesource.com/c/170278
> Commit-Queue: Mike Reed <reed@google.com>
> Reviewed-by: Mike Reed <reed@google.com>

TBR=reed@google.com

Change-Id: I7c22d18f7e6755dca059a68007c22cd1667162dc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:2664
Reviewed-on: https://skia-review.googlesource.com/c/170343
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-11-12 12:03:58 +00:00 committed by Skia Commit-Bot
parent 477fb91163
commit 0243949545
2 changed files with 44 additions and 1 deletions

View File

@ -473,7 +473,32 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
///////////////////////////////////////////////////////////////////////////////
SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
return SkFont::LEGACY_ExtractFromPaint(*this).getMetrics(metrics);
SkCanonicalizePaint canon(*this);
const SkPaint& paint = canon.getPaint();
SkScalar scale = canon.getScale();
FontMetrics storage;
if (nullptr == metrics) {
metrics = &storage;
}
SkAutoDescriptor ad;
SkScalerContextEffects effects;
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I(), &ad, &effects);
{
auto typeface = SkPaintPriv::GetTypefaceOrDefault(paint);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface);
*metrics = cache->getFontMetrics();
}
if (scale) {
SkPaintPriv::ScaleFontMetrics(metrics, scale);
}
return metrics->fDescent - metrics->fAscent + metrics->fLeading;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -34,6 +34,23 @@ static void test_cachedfont(skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, paint.getHinting() == p.getHinting());
}
static void test_fontmetrics(skiatest::Reporter* reporter,
const SkPaint& paint, const SkFont& font) {
SkFontMetrics fm0, fm1;
SkScalar h0 = paint.getFontMetrics(&fm0);
SkScalar h1 = font.getMetrics(&fm1);
REPORTER_ASSERT(reporter, h0 == h1);
#define CMP(field) REPORTER_ASSERT(reporter, fm0.field == fm1.field)
CMP(fFlags);
CMP(fTop);
CMP(fAscent);
CMP(fDescent);
CMP(fBottom);
CMP(fLeading);
#undef CMP
}
static void test_cachedfont(skiatest::Reporter* reporter) {
static const char* const faces[] = {
nullptr, // default font
@ -85,6 +102,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) {
const SkFont font(SkFont::LEGACY_ExtractFromPaint(paint));
test_cachedfont(reporter, paint, font);
test_fontmetrics(reporter, paint, font);
SkRect bounds;