From cb6940bf42e39271afe0fb3c2bfdd9e28d12f504 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 9 Nov 2017 13:45:10 -0500 Subject: DM FontMgr updates - return nullptr for the various makeFromFoo() that we can't support, and tweak a few unit tests to bail out early when they do - create FontStyleSet and SkTypefaces once - abort early from FontHostStream if we can't openStream() - implement SkTestTypeface::onCreateFamilyNameIterator() with SkOTUtils::LocalizedStrings_SingleName() so FontNames passes - pin out-of-range glyph IDs to zero in SkTestTypeface Change-Id: Iac53265e331fc1c5c507513af3ab299063e6610a Reviewed-on: https://skia-review.googlesource.com/69501 Reviewed-by: Ben Wagner Commit-Queue: Mike Klein --- src/fonts/SkTestScalerContext.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/fonts') diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp index ec53c54fa2..34ec6af849 100644 --- a/src/fonts/SkTestScalerContext.cpp +++ b/src/fonts/SkTestScalerContext.cpp @@ -13,6 +13,7 @@ #include "SkGlyph.h" #include "SkMakeUnique.h" #include "SkMask.h" +#include "SkOTUtils.h" #include "SkPaintPriv.h" #include "SkScalerContext.h" #include "SkTestScalerContext.h" @@ -133,13 +134,17 @@ void SkTestTypeface::getFontMetrics(SkPaint::FontMetrics* metrics) { } void SkTestTypeface::getMetrics(SkGlyph* glyph) { + SkGlyphID glyphID = glyph->getGlyphID(); + glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0; + // TODO(benjaminwagner): Update users to use floats. - glyph->fAdvanceX = SkFixedToFloat(fTestFont->fWidths[glyph->getGlyphID()]); + glyph->fAdvanceX = SkFixedToFloat(fTestFont->fWidths[glyphID]); glyph->fAdvanceY = 0; } -void SkTestTypeface::getPath(SkGlyphID glyph, SkPath* path) { - *path = *fTestFont->fPaths[glyph]; +void SkTestTypeface::getPath(SkGlyphID glyphID, SkPath* path) { + glyphID = glyphID < fTestFont->fCharCodesCount ? glyphID : 0; + *path = *fTestFont->fPaths[glyphID]; } void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { @@ -183,9 +188,7 @@ void SkTestTypeface::onGetFamilyName(SkString* familyName) const { SkTypeface::LocalizedStrings* SkTestTypeface::onCreateFamilyNameIterator() const { SkString familyName(fTestFont->fName); SkString language("und"); //undetermined -//SkASSERT(0); // incomplete - return nullptr; -// return new SkOTUtils::LocalizedStrings_SingleName(familyName, language); + return new SkOTUtils::LocalizedStrings_SingleName(familyName, language); } class SkTestScalerContext : public SkScalerContext { -- cgit v1.2.3