Skip to content

Commit

Permalink
Revert "route getFontMetrics to SkFont"
Browse files Browse the repository at this point in the history
This reverts commit 445148d.

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 <[email protected]>
> Reviewed-by: Mike Reed <[email protected]>

[email protected]

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 <[email protected]>
Commit-Queue: Mike Reed <[email protected]>
  • Loading branch information
reed-at-google authored and Skia Commit-Bot committed Nov 12, 2018
1 parent 477fb91 commit 0243949
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/core/SkPaint_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 18 additions & 0 deletions tests/FontObjTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 0243949

Please sign in to comment.