diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 3e7f447f9f..d3c84c9574 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -20,12 +20,12 @@ class SkDescriptor; class SkFontData; class SkFontDescriptor; class SkScalerContext; -struct SkScalerContextRec; -struct SkScalerContextEffects; class SkStream; class SkStreamAsset; -class SkAdvancedTypefaceMetrics; class SkWStream; +struct SkAdvancedTypefaceMetrics; +struct SkScalerContextEffects; +struct SkScalerContextRec; typedef uint32_t SkFontID; /** Machine endian. */ @@ -327,14 +327,6 @@ public: } protected: - // The type of advance data wanted. - enum PerGlyphInfo { - kNo_PerGlyphInfo = 0x0, // Don't populate any per glyph info. - kGlyphNames_PerGlyphInfo = 0x1, // Populate glyph names (Type 1 only). - kToUnicode_PerGlyphInfo = 0x2 // Populate ToUnicode table, ignored - // for Type 1 fonts - }; - /** uniqueID must be unique and non-zero */ SkTypeface(const SkFontStyle& style, bool isFixedPitch = false); @@ -351,10 +343,17 @@ protected: virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const = 0; virtual void onFilterRec(SkScalerContextRec*) const = 0; + virtual std::unique_ptr onGetAdvancedMetrics() const; + + enum PerGlyphInfo { + kNo_PerGlyphInfo = 0x0, + kGlyphNames_PerGlyphInfo = 0x1, + kToUnicode_PerGlyphInfo = 0x2 + }; virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const = 0; + PerGlyphInfo, const uint32_t*, uint32_t) const { + return nullptr; + } virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0; // TODO: make pure virtual. @@ -396,20 +395,8 @@ private: friend class GrPathRendering; friend class GrGLPathRendering; - /** Retrieve detailed typeface metrics. Used by the PDF backend. - @param perGlyphInfo Indicate what glyph specific information (advances, - names, etc.) should be populated. - @param glyphIDs For per-glyph info, specify subset of the font by - giving glyph ids. Each integer represents a glyph - id. Passing NULL means all glyphs in the font. - @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if - glyphIDs is NULL. - @return The returned object has already been referenced. - */ - SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t* glyphIDs = NULL, - uint32_t glyphIDsCount = 0) const; + /** Retrieve detailed typeface metrics. Used by the PDF backend. */ + std::unique_ptr getAdvancedMetrics() const; private: SkFontID fUniqueID; @@ -423,9 +410,4 @@ private: typedef SkWeakRefCnt INHERITED; }; - -namespace skstd { -template <> struct is_bitmask_enum : std::true_type {}; -} - #endif diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h index 61f1f1e9bd..2bc09d8323 100644 --- a/src/core/SkAdvancedTypefaceMetrics.h +++ b/src/core/SkAdvancedTypefaceMetrics.h @@ -18,22 +18,12 @@ The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly embed typefaces. This class is created and filled in with information by - SkTypeface::getAdvancedTypefaceMetrics. + SkTypeface::getAdvancedMetrics. */ -class SkAdvancedTypefaceMetrics : public SkRefCnt { -public: - - SkAdvancedTypefaceMetrics() - : fType(SkAdvancedTypefaceMetrics::kOther_Font) - , fFlags((FontFlags)0) - , fStyle((StyleFlags)0) - , fItalicAngle(0) - , fAscent(0) - , fDescent(0) - , fStemV(0) - , fCapHeight(0) - , fBBox(SkIRect::MakeEmpty()) {} - +struct SkAdvancedTypefaceMetrics { + SkAdvancedTypefaceMetrics() {} + SkAdvancedTypefaceMetrics(const SkAdvancedTypefaceMetrics&) = delete; + SkAdvancedTypefaceMetrics& operator=(const SkAdvancedTypefaceMetrics&) = delete; ~SkAdvancedTypefaceMetrics() {} SkString fFontName; @@ -48,14 +38,14 @@ public: // The type of the underlying font program. This field determines which // of the following fields are valid. If it is kOther_Font the per glyph // information will never be populated. - FontType fType; + FontType fType = kOther_Font; enum FontFlags : uint8_t { kMultiMaster_FontFlag = 0x01, //! fGlyphNames; - // The mapping from glyph to Unicode, only populated if - // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics. + // The mapping from glyph to Unicode; array indices are glyph ids. SkTDArray fGlyphToUnicode; - -private: - typedef SkRefCnt INHERITED; }; namespace skstd { diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 2d8f920ba9..58d7c52979 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -50,9 +50,9 @@ protected: return nullptr; } void onFilterRec(SkScalerContextRec*) const override { } - virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t*, uint32_t) const override { return nullptr; } + std::unique_ptr onGetAdvancedMetrics() const override { + return nullptr; + } void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } virtual int onCharsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], int glyphCount) const override { @@ -296,12 +296,8 @@ void SkTypeface::getFamilyName(SkString* name) const { this->onGetFamilyName(name); } -SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics( - PerGlyphInfo info, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { - SkAdvancedTypefaceMetrics* result = - this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); +std::unique_ptr SkTypeface::getAdvancedMetrics() const { + std::unique_ptr result = this->onGetAdvancedMetrics(); if (result && result->fType == SkAdvancedTypefaceMetrics::kTrueType_Font) { SkOTTableOS2::Version::V2::Type::Field fsType; constexpr SkFontTableTag os2Tag = SkTEndian_SwapBE32(SkOTTableOS2::TAG); @@ -368,3 +364,7 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const { fm.fXMax * invTextSize, fm.fBottom * invTextSize); return true; } + +std::unique_ptr SkTypeface::onGetAdvancedMetrics() const { + return nullptr; +} diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp index a38f695563..49d9ab43ff 100644 --- a/src/fonts/SkRandomScalerContext.cpp +++ b/src/fonts/SkRandomScalerContext.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkAdvancedTypefaceMetrics.h" #include "SkBitmap.h" #include "SkCanvas.h" #include "SkGlyph.h" @@ -206,11 +207,8 @@ void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const { rec->fMaskFormat = SkMask::kARGB32_Format; } -SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics( - PerGlyphInfo info, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { - return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); +std::unique_ptr SkRandomTypeface::onGetAdvancedMetrics() const { + return fProxy->getAdvancedMetrics(); } SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const { diff --git a/src/fonts/SkRandomScalerContext.h b/src/fonts/SkRandomScalerContext.h index c84b76470e..b71689d9e2 100644 --- a/src/fonts/SkRandomScalerContext.h +++ b/src/fonts/SkRandomScalerContext.h @@ -27,10 +27,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const override; + std::unique_ptr onGetAdvancedMetrics() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override; void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override; diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp index db726376f1..ec53c54fa2 100644 --- a/src/fonts/SkTestScalerContext.cpp +++ b/src/fonts/SkTestScalerContext.cpp @@ -146,12 +146,8 @@ void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { rec->setHinting(SkPaint::kNo_Hinting); } -SkAdvancedTypefaceMetrics* SkTestTypeface::onGetAdvancedTypefaceMetrics( - PerGlyphInfo , - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { -// pdf only - SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; +std::unique_ptr SkTestTypeface::onGetAdvancedMetrics() const { // pdf only + std::unique_ptr info(new SkAdvancedTypefaceMetrics); info->fFontName.set(fTestFont->fName); int glyphCount = this->onCountGlyphs(); diff --git a/src/fonts/SkTestScalerContext.h b/src/fonts/SkTestScalerContext.h index 5b2ec4f5a2..ec7ee853c7 100644 --- a/src/fonts/SkTestScalerContext.h +++ b/src/fonts/SkTestScalerContext.h @@ -65,10 +65,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor* desc) const override; void onFilterRec(SkScalerContextRec* rec) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const override; + std::unique_ptr onGetAdvancedMetrics() const override; SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h index 248e17833f..0aac2b5789 100644 --- a/src/pdf/SkPDFCanon.h +++ b/src/pdf/SkPDFCanon.h @@ -14,8 +14,8 @@ #include "SkTHash.h" #include "SkBitmapKey.h" -class SkAdvancedTypefaceMetrics; class SkPDFFont; +struct SkAdvancedTypefaceMetrics; /** * The SkPDFCanon canonicalizes objects across PDF pages @@ -52,7 +52,7 @@ public: SkTHashMap> fPDFBitmapMap; - SkTHashMap> fTypefaceMetrics; + SkTHashMap> fTypefaceMetrics; SkTHashMap> fFontDescriptors; SkTHashMap> fFontMap; diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index b373514808..f94dba7080 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -7,14 +7,15 @@ #include "SkData.h" #include "SkGlyphCache.h" -#include "SkPaint.h" +#include "SkMakeUnique.h" #include "SkPDFCanon.h" #include "SkPDFConvertType1FontStream.h" #include "SkPDFDevice.h" +#include "SkPDFFont.h" #include "SkPDFMakeCIDGlyphWidthsArray.h" #include "SkPDFMakeToUnicodeCmap.h" -#include "SkPDFFont.h" #include "SkPDFUtils.h" +#include "SkPaint.h" #include "SkRefCnt.h" #include "SkScalar.h" #include "SkStream.h" @@ -142,7 +143,7 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface, SkPDFCanon* canon) { SkASSERT(typeface); SkFontID id = typeface->uniqueID(); - if (sk_sp* ptr = canon->fTypefaceMetrics.find(id)) { + if (std::unique_ptr* ptr = canon->fTypefaceMetrics.find(id)) { return ptr->get(); // canon retains ownership. } int count = typeface->countGlyphs(); @@ -151,12 +152,9 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface, canon->fTypefaceMetrics.set(id, nullptr); return nullptr; } - sk_sp metrics( - typeface->getAdvancedTypefaceMetrics( - SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicode_PerGlyphInfo, - nullptr, 0)); + std::unique_ptr metrics = typeface->getAdvancedMetrics(); if (!metrics) { - metrics = sk_make_sp(); + metrics = skstd::make_unique(); } return canon->fTypefaceMetrics.set(id, std::move(metrics))->get(); } diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h index 6151279248..5639d87b67 100644 --- a/src/pdf/SkPDFFont.h +++ b/src/pdf/SkPDFFont.h @@ -87,8 +87,7 @@ public: SkTypeface* typeface, SkGlyphID glyphID); - /** Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo) to get - * SkAdvancedTypefaceMetrics, and caches the result. + /** Gets SkAdvancedTypefaceMetrics, and caches the result. * @param typeface can not be nullptr. * @return nullptr only when typeface is bad. */ diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 91801cdbd0..b87af6ff04 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -540,17 +540,14 @@ static void populate_glyph_to_unicode(FT_Face& face, SkTDArray* glyph } } -SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( - PerGlyphInfo perGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { +std::unique_ptr SkTypeface_FreeType::onGetAdvancedMetrics() const { AutoFTAccess fta(this); FT_Face face = fta.face(); if (!face) { return nullptr; } - SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; + std::unique_ptr info(new SkAdvancedTypefaceMetrics); info->fFontName.set(FT_Get_Postscript_Name(face)); if (FT_HAS_MULTIPLE_MASTERS(face)) { @@ -650,13 +647,9 @@ SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax, face->bbox.xMax, face->bbox.yMin); - if (!FT_IS_SCALABLE(face)) { - perGlyphInfo = kNo_PerGlyphInfo; - } + bool perGlyphInfo = FT_IS_SCALABLE(face); - if (perGlyphInfo & kGlyphNames_PerGlyphInfo && - info->fType == SkAdvancedTypefaceMetrics::kType1_Font) - { + if (perGlyphInfo && info->fType == SkAdvancedTypefaceMetrics::kType1_Font) { // Postscript fonts may contain more than 255 glyphs, so we end up // using multiple font descriptions with a glyph ordering. Record // the name of each glyph. @@ -668,7 +661,7 @@ SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( } } - if (perGlyphInfo & kToUnicode_PerGlyphInfo && + if (perGlyphInfo && info->fType != SkAdvancedTypefaceMetrics::kType1_Font && face->num_charmaps) { diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h index b9e8b13d7f..5270745581 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -80,8 +80,7 @@ protected: virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, const uint32_t*, uint32_t) const override; + std::unique_ptr onGetAdvancedMetrics() const override; int onGetUPEM() const override; bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count, int32_t adjustments[]) const override; diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index a43cf22c98..92334cb6bc 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -526,8 +526,7 @@ protected: const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const override; + std::unique_ptr onGetAdvancedMetrics() const override; int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[], int glyphCount) const override; int onCountGlyphs() const override; @@ -1491,17 +1490,14 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) { dst->resize(strlen(dst->c_str())); } -SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( - PerGlyphInfo perGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { +std::unique_ptr SkTypeface_Mac::onGetAdvancedMetrics() const { AUTO_CG_LOCK(); UniqueCFRef ctFont = ctfont_create_exact_copy(fFontRef.get(), CTFontGetUnitsPerEm(fFontRef.get()), nullptr); - SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics; + std::unique_ptr info(new SkAdvancedTypefaceMetrics); { UniqueCFRef fontName(CTFontCopyPostScriptName(ctFont.get())); @@ -1524,9 +1520,7 @@ SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( CFIndex glyphCount = CTFontGetGlyphCount(ctFont.get()); - if (perGlyphInfo & kToUnicode_PerGlyphInfo) { - populate_glyph_to_unicode(ctFont.get(), glyphCount, &info->fGlyphToUnicode); - } + populate_glyph_to_unicode(ctFont.get(), glyphCount, &info->fGlyphToUnicode); // If it's not a truetype font, mark it as 'other'. Assume that TrueType // fonts always have both glyf and loca tables. At the least, this is what diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 25c608878d..4a0aabede9 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -259,8 +259,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, const uint32_t*, uint32_t) const override; + std::unique_ptr onGetAdvancedMetrics() const override; void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; int onCharsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], int glyphCount) const override; @@ -1725,12 +1724,9 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, *isLocalStream = this->fSerializeAsStream; } -SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( - PerGlyphInfo perGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { +std::unique_ptr LogFontTypeface::onGetAdvancedMetrics() const { LOGFONT lf = fLogFont; - SkAdvancedTypefaceMetrics* info = nullptr; + std::unique_ptr info(nullptr); HDC hdc = CreateCompatibleDC(nullptr); HFONT font = CreateFontIndirect(&lf); @@ -1760,7 +1756,7 @@ SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( } glyphCount = calculateGlyphCount(hdc, fLogFont); - info = new SkAdvancedTypefaceMetrics; + info.reset(new SkAdvancedTypefaceMetrics); tchar_to_skstring(lf.lfFaceName, &info->fFontName); // If bit 1 is set, the font may not be embedded in a document. // If bit 1 is clear, the font can be embedded. @@ -1769,9 +1765,7 @@ SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( info->fFlags |= SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag; } - if (perGlyphInfo & kToUnicode_PerGlyphInfo) { - populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode)); - } + populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode)); if (glyphCount > 0 && (otm.otmTextMetrics.tmPitchAndFamily & TMPF_TRUETYPE)) { diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index f27ad40da6..be4b17dd12 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -489,12 +489,9 @@ public: this->INHERITED::onFilterRec(rec); } - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(PerGlyphInfo perGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const override - { - SkAdvancedTypefaceMetrics* info = - this->INHERITED::onGetAdvancedTypefaceMetrics(perGlyphInfo, glyphIDs, glyphIDsCount); + std::unique_ptr onGetAdvancedMetrics() const override { + std::unique_ptr info = + this->INHERITED::onGetAdvancedMetrics(); // Simulated fonts shouldn't be considered to be of the type of their data. if (get_matrix(fPattern, FC_MATRIX) || get_bool(fPattern, FC_EMBOLDEN)) { diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp index ae4e3f7105..fe20cc9699 100644 --- a/src/ports/SkTypeface_win_dw.cpp +++ b/src/ports/SkTypeface_win_dw.cpp @@ -319,12 +319,9 @@ static void populate_glyph_to_unicode(IDWriteFontFace* fontFace, SkTDArray(glyphToUni, maxGlyph + 1).swap(*glyphToUnicode); } -SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( - PerGlyphInfo perGlyphInfo, - const uint32_t* glyphIDs, - uint32_t glyphIDsCount) const { +std::unique_ptr DWriteFontTypeface::onGetAdvancedMetrics() const { - SkAdvancedTypefaceMetrics* info = nullptr; + std::unique_ptr info(nullptr); HRESULT hr = S_OK; @@ -333,7 +330,7 @@ SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( DWRITE_FONT_METRICS dwfm; fDWriteFontFace->GetMetrics(&dwfm); - info = new SkAdvancedTypefaceMetrics; + info.reset(new SkAdvancedTypefaceMetrics); info->fAscent = SkToS16(dwfm.ascent); info->fDescent = SkToS16(dwfm.descent); @@ -353,9 +350,7 @@ SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName); - if (perGlyphInfo & kToUnicode_PerGlyphInfo) { - populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode)); - } + populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode)); DWRITE_FONT_FACE_TYPE fontType = fDWriteFontFace->GetType(); if (fontType != DWRITE_FONT_FACE_TYPE_TRUETYPE && diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h index d7c73e2697..7abbde55aa 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -104,8 +104,7 @@ protected: SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, const SkDescriptor*) const override; void onFilterRec(SkScalerContextRec*) const override; - SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, const uint32_t*, uint32_t) const override; + std::unique_ptr onGetAdvancedMetrics() const override; void onGetFontDescriptor(SkFontDescriptor*, bool*) const override; int onCharsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], int glyphCount) const override; diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp index 251eb154a0..ef420f3b1d 100644 --- a/tests/FontMgrTest.cpp +++ b/tests/FontMgrTest.cpp @@ -5,14 +5,14 @@ * found in the LICENSE file. */ +#include "SkAdvancedTypefaceMetrics.h" #include "SkCommandLineFlags.h" +#include "SkFont.h" #include "SkFontMgr.h" +#include "SkPaint.h" #include "SkTypeface.h" #include "Test.h" -#include "SkFont.h" -#include "SkPaint.h" - #include #include #include @@ -133,9 +133,9 @@ static void test_matchStyleCSS3(skiatest::Reporter* reporter) { return nullptr; } void onFilterRec(SkScalerContextRec*) const override { } - virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t*, uint32_t) const override { return nullptr; } + std::unique_ptr onGetAdvancedMetrics() const override { + return nullptr; + } void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } virtual int onCharsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], int glyphCount) const override { diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp index 8d7ac31b99..1da94bb8a6 100644 --- a/tests/TypefaceTest.cpp +++ b/tests/TypefaceTest.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkAdvancedTypefaceMetrics.h" #include "SkData.h" #include "SkFixed.h" #include "SkFontMgr.h" @@ -196,9 +197,9 @@ protected: return nullptr; } void onFilterRec(SkScalerContextRec*) const override { } - virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - PerGlyphInfo, - const uint32_t*, uint32_t) const override { return nullptr; } + std::unique_ptr onGetAdvancedMetrics() const override { + return nullptr; + } void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } virtual int onCharsToGlyphs(const void* chars, Encoding encoding, uint16_t glyphs[], int glyphCount) const override {