Revert "Revert "SkTypeface::getAdvancedMetrics(): cleanup""
authorHal Canary <halcanary@google.com>
Thu, 4 May 2017 18:23:55 +0000 (14:23 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 5 May 2017 13:53:40 +0000 (13:53 +0000)
This reverts commit 59ad782b2b05b07aa6eb961aa4d62e934093cbd1.

   - SkAdvancedTypefaceMetrics is a struct not a class
   - SkTypeface::PerGlyphInfo is gone
   - s/getAdvancedTypefaceMetrics/getAdvancedMetrics/g
   - s/onGetAdvancedTypefaceMetrics/onGetAdvancedMetrics/g
   - [on]getAdvancedMetrics now return unique_ptr rather than bare ptr.
   - [on]getAdvancedMetrics no longer has parameters. (Only caller always
     used same arguments.)
   - SkAdvancedTypefaceMetrics uses C++11 in-class member initializers.
   - SkAdvancedTypefaceMetrics no longer inherits from SkRefCnt

Change-Id: I91b56e60f7d9de7d46c426c6bd34ce124e0cf00e
Reviewed-on: https://skia-review.googlesource.com/15360
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>

19 files changed:
include/core/SkTypeface.h
src/core/SkAdvancedTypefaceMetrics.h
src/core/SkTypeface.cpp
src/fonts/SkRandomScalerContext.cpp
src/fonts/SkRandomScalerContext.h
src/fonts/SkTestScalerContext.cpp
src/fonts/SkTestScalerContext.h
src/pdf/SkPDFCanon.h
src/pdf/SkPDFFont.cpp
src/pdf/SkPDFFont.h
src/ports/SkFontHost_FreeType.cpp
src/ports/SkFontHost_FreeType_common.h
src/ports/SkFontHost_mac.cpp
src/ports/SkFontHost_win.cpp
src/ports/SkFontMgr_fontconfig.cpp
src/ports/SkTypeface_win_dw.cpp
src/ports/SkTypeface_win_dw.h
tests/FontMgrTest.cpp
tests/TypefaceTest.cpp

index 3e7f447..d3c84c9 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> getAdvancedMetrics() const;
 
 private:
     SkFontID            fUniqueID;
@@ -423,9 +410,4 @@ private:
 
     typedef SkWeakRefCnt INHERITED;
 };
-
-namespace skstd {
-template <> struct is_bitmask_enum<SkTypeface::PerGlyphInfo> : std::true_type {};
-}
-
 #endif
index 61f1f1e..2bc09d8 100644 (file)
 
     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,  //!<May be true for Type1, CFF, or TrueType fonts.
         kNotEmbeddable_FontFlag  = 0x02,  //!<May not be embedded.
         kNotSubsettable_FontFlag = 0x04,  //!<May not be subset.
     };
-    FontFlags fFlags;  // Global font flags.
+    FontFlags fFlags = (FontFlags)0;  // Global font flags.
 
     // These enum values match the values used in the PDF file format.
     enum StyleFlags : uint32_t {
@@ -67,27 +57,23 @@ public:
         kSmallCaps_Style   = 0x00020000,
         kForceBold_Style   = 0x00040000
     };
-    StyleFlags fStyle;        // Font style characteristics.
+    StyleFlags fStyle = (StyleFlags)0;        // Font style characteristics.
 
-    int16_t fItalicAngle  // Counterclockwise degrees from vertical of the
-                            // dominant vertical stroke for an Italic face.
+    int16_t fItalicAngle = 0;  // Counterclockwise degrees from vertical of the
+                               // dominant vertical stroke for an Italic face.
     // The following fields are all in font units.
-    int16_t fAscent;       // Max height above baseline, not including accents.
-    int16_t fDescent;      // Max depth below baseline (negative).
-    int16_t fStemV;        // Thickness of dominant vertical stem.
-    int16_t fCapHeight;    // Height (from baseline) of top of flat capitals.
+    int16_t fAscent = 0;       // Max height above baseline, not including accents.
+    int16_t fDescent = 0;      // Max depth below baseline (negative).
+    int16_t fStemV = 0;        // Thickness of dominant vertical stem.
+    int16_t fCapHeight = 0;    // Height (from baseline) of top of flat capitals.
 
-    SkIRect fBBox;  // The bounding box of all glyphs (in font units).
+    SkIRect fBBox = {0, 0, 0, 0};  // The bounding box of all glyphs (in font units).
 
     // The names of each glyph, only populated for postscript fonts.
     SkTArray<SkString> 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<SkUnichar> fGlyphToUnicode;
-
-private:
-    typedef SkRefCnt INHERITED;
 };
 
 namespace skstd {
index 2d8f920..58d7c52 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> SkTypeface::getAdvancedMetrics() const {
+    std::unique_ptr<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> SkTypeface::onGetAdvancedMetrics() const {
+    return nullptr;
+}
index a38f695..49d9ab4 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> SkRandomTypeface::onGetAdvancedMetrics() const {
+    return fProxy->getAdvancedMetrics();
 }
 
 SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const {
index c84b764..b71689d 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
     SkStreamAsset* onOpenStream(int* ttcIndex) const override;
     void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override;
 
index db72637..ec53c54 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> SkTestTypeface::onGetAdvancedMetrics() const { // pdf only
+    std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
     info->fFontName.set(fTestFont->fName);
     int glyphCount = this->onCountGlyphs();
 
index 5b2ec4f..ec7ee85 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
 
     SkStreamAsset* onOpenStream(int* ttcIndex) const override {
         return nullptr;
index 248e178..0aac2b5 100644 (file)
@@ -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<SkBitmapKey, sk_sp<SkPDFObject>> fPDFBitmapMap;
 
-    SkTHashMap<uint32_t, sk_sp<SkAdvancedTypefaceMetrics>> fTypefaceMetrics;
+    SkTHashMap<uint32_t, std::unique_ptr<SkAdvancedTypefaceMetrics>> fTypefaceMetrics;
     SkTHashMap<uint32_t, sk_sp<SkPDFDict>> fFontDescriptors;
     SkTHashMap<uint64_t, sk_sp<SkPDFFont>> fFontMap;
 
index b373514..f94dba7 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics>* ptr = canon->fTypefaceMetrics.find(id)) {
+    if (std::unique_ptr<SkAdvancedTypefaceMetrics>* 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<SkAdvancedTypefaceMetrics> metrics(
-            typeface->getAdvancedTypefaceMetrics(
-                    SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicode_PerGlyphInfo,
-                    nullptr, 0));
+    std::unique_ptr<SkAdvancedTypefaceMetrics> metrics = typeface->getAdvancedMetrics();
     if (!metrics) {
-        metrics = sk_make_sp<SkAdvancedTypefaceMetrics>();
+        metrics = skstd::make_unique<SkAdvancedTypefaceMetrics>();
     }
     return canon->fTypefaceMetrics.set(id, std::move(metrics))->get();
 }
index 6151279..5639d87 100644 (file)
@@ -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.
      */
index 91801cd..b87af6f 100644 (file)
@@ -540,17 +540,14 @@ static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyph
     }
 }
 
-SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics(
-        PerGlyphInfo perGlyphInfo,
-        const uint32_t* glyphIDs,
-        uint32_t glyphIDsCount) const {
+std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_FreeType::onGetAdvancedMetrics() const {
     AutoFTAccess fta(this);
     FT_Face face = fta.face();
     if (!face) {
         return nullptr;
     }
 
-    SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
+    std::unique_ptr<SkAdvancedTypefaceMetrics> 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)
     {
index b9e8b13..5270745 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
     int onGetUPEM() const override;
     bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
                                      int32_t adjustments[]) const override;
index a43cf22..92334cb 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> SkTypeface_Mac::onGetAdvancedMetrics() const {
 
     AUTO_CG_LOCK();
 
     UniqueCFRef<CTFontRef> ctFont =
             ctfont_create_exact_copy(fFontRef.get(), CTFontGetUnitsPerEm(fFontRef.get()), nullptr);
 
-    SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
+    std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
 
     {
         UniqueCFRef<CFStringRef> 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
index 25c6088..4a0aabe 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics() const {
     LOGFONT lf = fLogFont;
-    SkAdvancedTypefaceMetrics* info = nullptr;
+    std::unique_ptr<SkAdvancedTypefaceMetrics> 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)) {
index f27ad40..be4b17d 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
+        std::unique_ptr<SkAdvancedTypefaceMetrics> 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)) {
index ae4e3f7..fe20cc9 100644 (file)
@@ -319,12 +319,9 @@ static void populate_glyph_to_unicode(IDWriteFontFace* fontFace,
     SkTDArray<SkUnichar>(glyphToUni, maxGlyph + 1).swap(*glyphToUnicode);
 }
 
-SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
-        PerGlyphInfo perGlyphInfo,
-        const uint32_t* glyphIDs,
-        uint32_t glyphIDsCount) const {
+std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetrics() const {
 
-    SkAdvancedTypefaceMetrics* info = nullptr;
+    std::unique_ptr<SkAdvancedTypefaceMetrics> 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 &&
index d7c73e2..7abbde5 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
     void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
     int onCharsToGlyphs(const void* chars, Encoding encoding,
                         uint16_t glyphs[], int glyphCount) const override;
index 251eb15..ef420f3 100644 (file)
@@ -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 <initializer_list>
 #include <limits>
 #include <vector>
@@ -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<SkAdvancedTypefaceMetrics> 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 {
index 8d7ac31..1da94bb 100644 (file)
@@ -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<SkAdvancedTypefaceMetrics> 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 {