aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-05-04 10:10:05 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-04 16:57:43 +0000
commitcef018896e5cad8eb46a536b60cdf79ebe2b0191 (patch)
tree2085d6071e90287f8dcacc31d801eaa99f35c035
parentba9028440be7cd651759be3ff517809aad189de3 (diff)
SkTypeface::getAdvancedMetrics(): cleanup
- 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: I37571ebcc383ba9eb21bc20c60c734e3ca317582 Reviewed-on: https://skia-review.googlesource.com/15311 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
-rw-r--r--include/core/SkTypeface.h40
-rw-r--r--src/core/SkAdvancedTypefaceMetrics.h46
-rw-r--r--src/core/SkTypeface.cpp14
-rw-r--r--src/fonts/SkRandomScalerContext.cpp8
-rw-r--r--src/fonts/SkRandomScalerContext.h5
-rw-r--r--src/fonts/SkTestScalerContext.cpp8
-rw-r--r--src/fonts/SkTestScalerContext.h5
-rw-r--r--src/pdf/SkPDFCanon.h4
-rw-r--r--src/pdf/SkPDFFont.cpp14
-rw-r--r--src/pdf/SkPDFFont.h3
-rw-r--r--src/ports/SkFontHost_FreeType.cpp17
-rw-r--r--src/ports/SkFontHost_FreeType_common.h3
-rw-r--r--src/ports/SkFontHost_mac.cpp14
-rw-r--r--src/ports/SkFontHost_win.cpp16
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp9
-rw-r--r--src/ports/SkTypeface_win_dw.cpp13
-rw-r--r--src/ports/SkTypeface_win_dw.h3
-rw-r--r--tests/FontMgrTest.cpp12
-rw-r--r--tests/TypefaceTest.cpp7
19 files changed, 76 insertions, 165 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 3e7f447f9f..2d066d90f2 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,7 @@ protected:
virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0;
- virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- PerGlyphInfo,
- const uint32_t* glyphIDs,
- uint32_t glyphIDsCount) const = 0;
+ virtual std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const = 0;
virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0;
// TODO: make pure virtual.
@@ -396,20 +385,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 +400,4 @@ private:
typedef SkWeakRefCnt INHERITED;
};
-
-namespace skstd {
-template <> struct is_bitmask_enum<SkTypeface::PerGlyphInfo> : 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, //!<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 {
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 2d8f920ba9..be92804e4d 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<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);
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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> SkTestTypeface::onGetAdvancedMetrics() const { // pdf only
+ std::unique_ptr<SkAdvancedTypefaceMetrics> 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<SkAdvancedTypefaceMetrics> 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<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;
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<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();
}
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<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)
{
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<SkAdvancedTypefaceMetrics> 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<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
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<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)) {
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<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)) {
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<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 &&
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<SkAdvancedTypefaceMetrics> 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 <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 {
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<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 {