aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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, 165 insertions, 76 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 2d066d90f2..3e7f447f9f 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,6 +327,14 @@ 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);
@@ -343,7 +351,10 @@ protected:
virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const = 0;
virtual void onFilterRec(SkScalerContextRec*) const = 0;
- virtual std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const = 0;
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const = 0;
virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0;
// TODO: make pure virtual.
@@ -385,8 +396,20 @@ private:
friend class GrPathRendering;
friend class GrGLPathRendering;
- /** Retrieve detailed typeface metrics. Used by the PDF backend. */
- std::unique_ptr<SkAdvancedTypefaceMetrics> getAdvancedMetrics() const;
+ /** 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;
private:
SkFontID fUniqueID;
@@ -400,4 +423,9 @@ 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 2bc09d8323..61f1f1e9bd 100644
--- a/src/core/SkAdvancedTypefaceMetrics.h
+++ b/src/core/SkAdvancedTypefaceMetrics.h
@@ -18,12 +18,22 @@
The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
embed typefaces. This class is created and filled in with information by
- SkTypeface::getAdvancedMetrics.
+ SkTypeface::getAdvancedTypefaceMetrics.
*/
-struct SkAdvancedTypefaceMetrics {
- SkAdvancedTypefaceMetrics() {}
- SkAdvancedTypefaceMetrics(const SkAdvancedTypefaceMetrics&) = delete;
- SkAdvancedTypefaceMetrics& operator=(const SkAdvancedTypefaceMetrics&) = delete;
+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()) {}
+
~SkAdvancedTypefaceMetrics() {}
SkString fFontName;
@@ -38,14 +48,14 @@ struct SkAdvancedTypefaceMetrics {
// 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 = kOther_Font;
+ FontType fType;
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 = (FontFlags)0; // Global font flags.
+ FontFlags fFlags; // Global font flags.
// These enum values match the values used in the PDF file format.
enum StyleFlags : uint32_t {
@@ -57,23 +67,27 @@ struct SkAdvancedTypefaceMetrics {
kSmallCaps_Style = 0x00020000,
kForceBold_Style = 0x00040000
};
- StyleFlags fStyle = (StyleFlags)0; // Font style characteristics.
+ StyleFlags fStyle; // Font style characteristics.
- int16_t fItalicAngle = 0; // Counterclockwise degrees from vertical of the
- // dominant vertical stroke for an Italic face.
+ int16_t fItalicAngle; // Counterclockwise degrees from vertical of the
+ // dominant vertical stroke for an Italic face.
// The following fields are all in font units.
- 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.
+ 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.
- SkIRect fBBox = {0, 0, 0, 0}; // The bounding box of all glyphs (in font units).
+ SkIRect fBBox; // 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; array indices are glyph ids.
+ // The mapping from glyph to Unicode, only populated if
+ // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics.
SkTDArray<SkUnichar> fGlyphToUnicode;
+
+private:
+ typedef SkRefCnt INHERITED;
};
namespace skstd {
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index be92804e4d..2d8f920ba9 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -50,9 +50,9 @@ protected:
return nullptr;
}
void onFilterRec(SkScalerContextRec*) const override { }
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
- return nullptr;
- }
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t*, uint32_t) 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,8 +296,12 @@ void SkTypeface::getFamilyName(SkString* name) const {
this->onGetFamilyName(name);
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface::getAdvancedMetrics() const {
- std::unique_ptr<SkAdvancedTypefaceMetrics> result = this->onGetAdvancedMetrics();
+SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
+ PerGlyphInfo info,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
+ SkAdvancedTypefaceMetrics* result =
+ this->onGetAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
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 49d9ab43ff..a38f695563 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
-#include "SkAdvancedTypefaceMetrics.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkGlyph.h"
@@ -207,8 +206,11 @@ void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {
rec->fMaskFormat = SkMask::kARGB32_Format;
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> SkRandomTypeface::onGetAdvancedMetrics() const {
- return fProxy->getAdvancedMetrics();
+SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo info,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
+ return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
}
SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const {
diff --git a/src/fonts/SkRandomScalerContext.h b/src/fonts/SkRandomScalerContext.h
index b71689d9e2..c84b76470e 100644
--- a/src/fonts/SkRandomScalerContext.h
+++ b/src/fonts/SkRandomScalerContext.h
@@ -27,7 +27,10 @@ protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) 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 ec53c54fa2..db726376f1 100644
--- a/src/fonts/SkTestScalerContext.cpp
+++ b/src/fonts/SkTestScalerContext.cpp
@@ -146,8 +146,12 @@ void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const {
rec->setHinting(SkPaint::kNo_Hinting);
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> SkTestTypeface::onGetAdvancedMetrics() const { // pdf only
- std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
+SkAdvancedTypefaceMetrics* SkTestTypeface::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo ,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
+// pdf only
+ 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 ec7ee853c7..5b2ec4f5a2 100644
--- a/src/fonts/SkTestScalerContext.h
+++ b/src/fonts/SkTestScalerContext.h
@@ -65,7 +65,10 @@ protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
return nullptr;
diff --git a/src/pdf/SkPDFCanon.h b/src/pdf/SkPDFCanon.h
index 0aac2b5789..248e17833f 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, std::unique_ptr<SkAdvancedTypefaceMetrics>> fTypefaceMetrics;
+ SkTHashMap<uint32_t, sk_sp<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 f94dba7080..b373514808 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -7,15 +7,14 @@
#include "SkData.h"
#include "SkGlyphCache.h"
-#include "SkMakeUnique.h"
+#include "SkPaint.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"
@@ -143,7 +142,7 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface,
SkPDFCanon* canon) {
SkASSERT(typeface);
SkFontID id = typeface->uniqueID();
- if (std::unique_ptr<SkAdvancedTypefaceMetrics>* ptr = canon->fTypefaceMetrics.find(id)) {
+ if (sk_sp<SkAdvancedTypefaceMetrics>* ptr = canon->fTypefaceMetrics.find(id)) {
return ptr->get(); // canon retains ownership.
}
int count = typeface->countGlyphs();
@@ -152,9 +151,12 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface,
canon->fTypefaceMetrics.set(id, nullptr);
return nullptr;
}
- std::unique_ptr<SkAdvancedTypefaceMetrics> metrics = typeface->getAdvancedMetrics();
+ sk_sp<SkAdvancedTypefaceMetrics> metrics(
+ typeface->getAdvancedTypefaceMetrics(
+ SkTypeface::kGlyphNames_PerGlyphInfo | SkTypeface::kToUnicode_PerGlyphInfo,
+ nullptr, 0));
if (!metrics) {
- metrics = skstd::make_unique<SkAdvancedTypefaceMetrics>();
+ metrics = sk_make_sp<SkAdvancedTypefaceMetrics>();
}
return canon->fTypefaceMetrics.set(id, std::move(metrics))->get();
}
diff --git a/src/pdf/SkPDFFont.h b/src/pdf/SkPDFFont.h
index 5639d87b67..6151279248 100644
--- a/src/pdf/SkPDFFont.h
+++ b/src/pdf/SkPDFFont.h
@@ -87,7 +87,8 @@ public:
SkTypeface* typeface,
SkGlyphID glyphID);
- /** Gets SkAdvancedTypefaceMetrics, and caches the result.
+ /** Uses (kGlyphNames_PerGlyphInfo | kToUnicode_PerGlyphInfo) to get
+ * 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 b87af6ff04..91801cdbd0 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -540,14 +540,17 @@ static void populate_glyph_to_unicode(FT_Face& face, SkTDArray<SkUnichar>* glyph
}
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_FreeType::onGetAdvancedMetrics() const {
+SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
AutoFTAccess fta(this);
FT_Face face = fta.face();
if (!face) {
return nullptr;
}
- std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
+ SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
info->fFontName.set(FT_Get_Postscript_Name(face));
if (FT_HAS_MULTIPLE_MASTERS(face)) {
@@ -647,9 +650,13 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_FreeType::onGetAdvancedMet
info->fBBox = SkIRect::MakeLTRB(face->bbox.xMin, face->bbox.yMax,
face->bbox.xMax, face->bbox.yMin);
- bool perGlyphInfo = FT_IS_SCALABLE(face);
+ if (!FT_IS_SCALABLE(face)) {
+ perGlyphInfo = kNo_PerGlyphInfo;
+ }
- if (perGlyphInfo && info->fType == SkAdvancedTypefaceMetrics::kType1_Font) {
+ if (perGlyphInfo & kGlyphNames_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.
@@ -661,7 +668,7 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_FreeType::onGetAdvancedMet
}
}
- if (perGlyphInfo &&
+ if (perGlyphInfo & kToUnicode_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 5270745581..b9e8b13d7f 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -80,7 +80,8 @@ protected:
virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) 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 92334cb6bc..a43cf22c98 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -526,7 +526,8 @@ protected:
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const override;
int onCharsToGlyphs(const void* chars, Encoding,
uint16_t glyphs[], int glyphCount) const override;
int onCountGlyphs() const override;
@@ -1490,14 +1491,17 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) {
dst->resize(strlen(dst->c_str()));
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_Mac::onGetAdvancedMetrics() const {
+SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
AUTO_CG_LOCK();
UniqueCFRef<CTFontRef> ctFont =
ctfont_create_exact_copy(fFontRef.get(), CTFontGetUnitsPerEm(fFontRef.get()), nullptr);
- std::unique_ptr<SkAdvancedTypefaceMetrics> info(new SkAdvancedTypefaceMetrics);
+ SkAdvancedTypefaceMetrics* info = new SkAdvancedTypefaceMetrics;
{
UniqueCFRef<CFStringRef> fontName(CTFontCopyPostScriptName(ctFont.get()));
@@ -1520,7 +1524,9 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> SkTypeface_Mac::onGetAdvancedMetrics(
CFIndex glyphCount = CTFontGetGlyphCount(ctFont.get());
- populate_glyph_to_unicode(ctFont.get(), glyphCount, &info->fGlyphToUnicode);
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
+ 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 4a0aabede9..25c608878d 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -259,7 +259,8 @@ protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;
@@ -1724,9 +1725,12 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
*isLocalStream = this->fSerializeAsStream;
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics() const {
+SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
LOGFONT lf = fLogFont;
- std::unique_ptr<SkAdvancedTypefaceMetrics> info(nullptr);
+ SkAdvancedTypefaceMetrics* info = nullptr;
HDC hdc = CreateCompatibleDC(nullptr);
HFONT font = CreateFontIndirect(&lf);
@@ -1756,7 +1760,7 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics
}
glyphCount = calculateGlyphCount(hdc, fLogFont);
- info.reset(new SkAdvancedTypefaceMetrics);
+ info = 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.
@@ -1765,7 +1769,9 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> LogFontTypeface::onGetAdvancedMetrics
info->fFlags |= SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag;
}
- populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode));
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
+ 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 be4b17dd12..f27ad40da6 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -489,9 +489,12 @@ public:
this->INHERITED::onFilterRec(rec);
}
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
- std::unique_ptr<SkAdvancedTypefaceMetrics> info =
- this->INHERITED::onGetAdvancedMetrics();
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const override
+ {
+ SkAdvancedTypefaceMetrics* info =
+ this->INHERITED::onGetAdvancedTypefaceMetrics(perGlyphInfo, glyphIDs, glyphIDsCount);
// 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 fe20cc9699..ae4e3f7105 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -319,9 +319,12 @@ static void populate_glyph_to_unicode(IDWriteFontFace* fontFace,
SkTDArray<SkUnichar>(glyphToUni, maxGlyph + 1).swap(*glyphToUnicode);
}
-std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetrics() const {
+SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount) const {
- std::unique_ptr<SkAdvancedTypefaceMetrics> info(nullptr);
+ SkAdvancedTypefaceMetrics* info = nullptr;
HRESULT hr = S_OK;
@@ -330,7 +333,7 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetr
DWRITE_FONT_METRICS dwfm;
fDWriteFontFace->GetMetrics(&dwfm);
- info.reset(new SkAdvancedTypefaceMetrics);
+ info = new SkAdvancedTypefaceMetrics;
info->fAscent = SkToS16(dwfm.ascent);
info->fDescent = SkToS16(dwfm.descent);
@@ -350,7 +353,9 @@ std::unique_ptr<SkAdvancedTypefaceMetrics> DWriteFontTypeface::onGetAdvancedMetr
hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName);
- populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode));
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
+ 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 7abbde55aa..d7c73e2697 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -104,7 +104,8 @@ protected:
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) 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 ef420f3b1d..251eb154a0 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 { }
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
- return nullptr;
- }
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t*, uint32_t) 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 1da94bb8a6..8d7ac31b99 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
-#include "SkAdvancedTypefaceMetrics.h"
#include "SkData.h"
#include "SkFixed.h"
#include "SkFontMgr.h"
@@ -197,9 +196,9 @@ protected:
return nullptr;
}
void onFilterRec(SkScalerContextRec*) const override { }
- std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
- return nullptr;
- }
+ virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo,
+ const uint32_t*, uint32_t) 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 {