From 0a01f5a2c44f3d6a7fa2d3c837f46894d9b29e5d Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 8 May 2013 14:19:08 +0000 Subject: [PATCH] we only need one fontmetrics, since the paint (and fontcache) now know explicitly if they are horizontal or vertical. Review URL: https://codereview.chromium.org/14940018 git-svn-id: http://skia.googlecode.com/svn/trunk@9058 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkGlyphCache.cpp | 2 +- src/core/SkGlyphCache.h | 6 +++--- src/core/SkPaint.cpp | 11 +++++------ src/core/SkScalerContext.cpp | 12 ++++++++++-- src/core/SkScalerContext.h | 3 +-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index d33a13f4b..a1f738e81 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -62,7 +62,7 @@ SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc) fDesc = desc->copy(); fScalerContext = typeface->createScalerContext(desc); - fScalerContext->getFontMetrics(NULL, &fFontMetricsY); + fScalerContext->getFontMetrics(&fFontMetrics); // init to 0 so that all of the pointers will be null memset(fGlyphHash, 0, sizeof(fGlyphHash)); diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index 39a1c389c..bbf3eb3f2 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -95,8 +95,8 @@ public: /** Return the vertical metrics for this strike. */ - const SkPaint::FontMetrics& getFontMetricsY() const { - return fFontMetricsY; + const SkPaint::FontMetrics& getFontMetrics() const { + return fFontMetrics; } const SkDescriptor& getDescriptor() const { return *fDesc; } @@ -220,7 +220,7 @@ private: SkGlyphCache* fNext, *fPrev; SkDescriptor* fDesc; SkScalerContext* fScalerContext; - SkPaint::FontMetrics fFontMetricsY; + SkPaint::FontMetrics fFontMetrics; enum { kHashBits = 12, diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index aa1b8e480..6c16428d8 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -1203,7 +1203,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth, /////////////////////////////////////////////////////////////////////////////// static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) { - *(SkPaint::FontMetrics*)context = cache->getFontMetricsY(); + *(SkPaint::FontMetrics*)context = cache->getFontMetrics(); return false; // don't detach the cache } @@ -1228,11 +1228,6 @@ SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { zoomPtr = &zoomMatrix; } -#if 0 - SkAutoGlyphCache autoCache(*this, zoomPtr); - SkGlyphCache* cache = autoCache.getCache(); - const FontMetrics& my = cache->getFontMetricsY(); -#endif FontMetrics storage; if (NULL == metrics) { metrics = &storage; @@ -1246,6 +1241,10 @@ SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { metrics->fDescent = SkScalarMul(metrics->fDescent, scale); metrics->fBottom = SkScalarMul(metrics->fBottom, scale); metrics->fLeading = SkScalarMul(metrics->fLeading, scale); + metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); + metrics->fXMin = SkScalarMul(metrics->fXMin, scale); + metrics->fXMax = SkScalarMul(metrics->fXMax, scale); + metrics->fXHeight = SkScalarMul(metrics->fXHeight, scale); } return metrics->fDescent - metrics->fAscent + metrics->fLeading; } diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index 93abf6b3c..ba14908c2 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -663,8 +663,16 @@ void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) { this->internalGetPath(glyph, NULL, path, NULL); } -void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* mx, - SkPaint::FontMetrics* my) { +void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* fm) { + // All of this complexity should go away when we change generateFontMetrics + // to just take one parameter (since it knows if it is vertical or not) + SkPaint::FontMetrics* mx = NULL; + SkPaint::FontMetrics* my = NULL; + if (fRec.fFlags & kVertical_Flag) { + mx = fm; + } else { + my = fm; + } this->generateFontMetrics(mx, my); } diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h index dceabc18d..d17b42349 100644 --- a/src/core/SkScalerContext.h +++ b/src/core/SkScalerContext.h @@ -180,8 +180,7 @@ public: void getMetrics(SkGlyph*); void getImage(const SkGlyph&); void getPath(const SkGlyph&, SkPath*); - void getFontMetrics(SkPaint::FontMetrics* mX, - SkPaint::FontMetrics* mY); + void getFontMetrics(SkPaint::FontMetrics*); #ifdef SK_BUILD_FOR_ANDROID unsigned getBaseGlyphCount(SkUnichar charCode);