Add SkTypeface::getPostScriptName.
Bug: skia:10234 Change-Id: Idfa1261e36174a4b4223b8eb62c872448fc58b14 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322680 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
d6cfe72549
commit
59637dd6f9
@ -300,6 +300,13 @@ public:
|
||||
*/
|
||||
void getFamilyName(SkString* name) const;
|
||||
|
||||
/**
|
||||
* Return the PostScript name for this typeface.
|
||||
* Value may change based on variation parameters.
|
||||
* Returns false if no PostScript name is available.
|
||||
*/
|
||||
bool getPostScriptName(SkString* name) const;
|
||||
|
||||
/**
|
||||
* Return a stream for the contents of the font data, or NULL on failure.
|
||||
* If ttcIndex is not null, it is set to the TrueTypeCollection index
|
||||
@ -387,6 +394,7 @@ protected:
|
||||
* This name may or may not be produced by the family name iterator.
|
||||
*/
|
||||
virtual void onGetFamilyName(SkString* familyName) const = 0;
|
||||
virtual bool onGetPostScriptName(SkString*) const = 0;
|
||||
|
||||
/** Returns an iterator over the family names in the font. */
|
||||
virtual LocalizedStrings* onCreateFamilyNameIterator() const = 0;
|
||||
|
@ -63,6 +63,9 @@ protected:
|
||||
void onGetFamilyName(SkString* familyName) const override {
|
||||
familyName->reset();
|
||||
}
|
||||
bool onGetPostScriptName(SkString*) const override {
|
||||
return false;
|
||||
}
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
|
||||
return new EmptyLocalizedStrings;
|
||||
}
|
||||
@ -332,6 +335,10 @@ void SkTypeface::getFamilyName(SkString* name) const {
|
||||
this->onGetFamilyName(name);
|
||||
}
|
||||
|
||||
bool SkTypeface::getPostScriptName(SkString* name) const {
|
||||
return this->onGetPostScriptName(name);
|
||||
}
|
||||
|
||||
void SkTypeface::getGlyphToUnicodeMap(SkUnichar* dst) const {
|
||||
sk_bzero(dst, sizeof(SkUnichar) * this->countGlyphs());
|
||||
}
|
||||
|
@ -78,6 +78,9 @@ protected:
|
||||
// Used by SkStrikeCache::DumpMemoryStatistics.
|
||||
*familyName = "";
|
||||
}
|
||||
bool onGetPostScriptName(SkString*) const override {
|
||||
SK_ABORT("Should never be called.");
|
||||
}
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
|
||||
SK_ABORT("Should never be called.");
|
||||
}
|
||||
|
@ -696,6 +696,23 @@ void SkTypeface_FreeType::getPostScriptGlyphNames(SkString* dstArray) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool SkTypeface_FreeType::onGetPostScriptName(SkString* skPostScriptName) const {
|
||||
AutoFTAccess fta(this);
|
||||
FT_Face face = fta.face();
|
||||
if (!face) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* ftPostScriptName = FT_Get_Postscript_Name(face);
|
||||
if (!ftPostScriptName) {
|
||||
return false;
|
||||
}
|
||||
if (skPostScriptName) {
|
||||
*skPostScriptName = ftPostScriptName;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool bothZero(SkScalar a, SkScalar b) {
|
||||
|
@ -106,6 +106,7 @@ protected:
|
||||
void getGlyphToUnicodeMap(SkUnichar*) const override;
|
||||
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
|
||||
void getPostScriptGlyphNames(SkString* dstArray) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
int onGetUPEM() const override;
|
||||
bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
|
||||
int32_t adjustments[]) const override;
|
||||
|
@ -285,6 +285,7 @@ protected:
|
||||
void getPostScriptGlyphNames(SkString*) const override;
|
||||
int onGetUPEM() const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override { return false; }
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
int coordinateCount) const override
|
||||
|
@ -1096,6 +1096,17 @@ void SkTypeface_Mac::onGetFamilyName(SkString* familyName) const {
|
||||
get_str(CTFontCopyFamilyName(fFontRef.get()), familyName);
|
||||
}
|
||||
|
||||
bool SkTypeface_Mac::onGetPostScriptName(SkString* skPostScriptName) const {
|
||||
SkUniqueCFRef<CFStringRef> ctPostScriptName(CTFontCopyPostScriptName(fFontRef.get()));
|
||||
if (!ctPostScriptName) {
|
||||
return false;
|
||||
}
|
||||
if (skPostScriptName) {
|
||||
SkStringFromCFString(ctPostScriptName.get(), skPostScriptName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
SkString tmpStr;
|
||||
|
@ -96,6 +96,7 @@ protected:
|
||||
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
int coordinateCount) const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
int onGetTableTags(SkFontTableTag tags[]) const override;
|
||||
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;
|
||||
|
@ -54,6 +54,25 @@ void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, familyName);
|
||||
}
|
||||
|
||||
bool DWriteFontTypeface::onGetPostScriptName(SkString* skPostScriptName) const {
|
||||
SkString localSkPostScriptName;
|
||||
SkTScopedComPtr<IDWriteLocalizedStrings> postScriptNames;
|
||||
BOOL exists = FALSE;
|
||||
if (FAILED(fDWriteFont->GetInformationalStrings(
|
||||
DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME,
|
||||
&postScriptNames,
|
||||
&exists)) ||
|
||||
!exists ||
|
||||
FAILED(sk_get_locale_string(postScriptNames.get(), nullptr, &localSkPostScriptName)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (skPostScriptName) {
|
||||
*skPostScriptName = localSkPostScriptName;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
// Get the family name.
|
||||
|
@ -134,6 +134,7 @@ protected:
|
||||
void getPostScriptGlyphNames(SkString*) const override;
|
||||
int onGetUPEM() const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
int coordinateCount) const override;
|
||||
|
@ -62,6 +62,7 @@ private:
|
||||
void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
|
||||
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int*) const override;
|
||||
@ -173,6 +174,10 @@ void SkUserTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
*familyName = "";
|
||||
}
|
||||
|
||||
bool SkUserTypeface::onGetPostScriptName(SkString*) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkTypeface::LocalizedStrings* SkUserTypeface::onCreateFamilyNameIterator() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -154,6 +154,7 @@ DEF_TEST(FontMgr_MatchStyleCSS3, reporter) {
|
||||
void onGetFamilyName(SkString* familyName) const override {
|
||||
familyName->reset();
|
||||
}
|
||||
bool onGetPostScriptName(SkString*) const override { return false; }
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
|
||||
return new EmptyLocalizedStrings;
|
||||
}
|
||||
|
@ -100,6 +100,22 @@ DEF_TEST(TypefaceStyle, reporter) {
|
||||
}
|
||||
}
|
||||
|
||||
DEF_TEST(TypefacePostScriptName, reporter) {
|
||||
sk_sp<SkTypeface> typeface(MakeResourceAsTypeface("fonts/Em.ttf"));
|
||||
if (!typeface) {
|
||||
// Not all SkFontMgr can MakeFromStream().
|
||||
return;
|
||||
}
|
||||
|
||||
SkString postScriptName;
|
||||
bool hasName = typeface->getPostScriptName(&postScriptName);
|
||||
bool hasName2 = typeface->getPostScriptName(nullptr);
|
||||
REPORTER_ASSERT(reporter, hasName == hasName2);
|
||||
if (hasName) {
|
||||
REPORTER_ASSERT(reporter, postScriptName == SkString("Em"));
|
||||
}
|
||||
}
|
||||
|
||||
DEF_TEST(TypefaceRoundTrip, reporter) {
|
||||
sk_sp<SkTypeface> typeface(MakeResourceAsTypeface("fonts/7630.otf"));
|
||||
if (!typeface) {
|
||||
|
@ -193,6 +193,10 @@ void SkRandomTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
fProxy->getFamilyName(familyName);
|
||||
}
|
||||
|
||||
bool SkRandomTypeface::onGetPostScriptName(SkString* postScriptName) const {
|
||||
return fProxy->getPostScriptName(postScriptName);
|
||||
}
|
||||
|
||||
SkTypeface::LocalizedStrings* SkRandomTypeface::onCreateFamilyNameIterator() const {
|
||||
return fProxy->createFamilyNameIterator();
|
||||
}
|
||||
|
@ -20,24 +20,25 @@ class SkRandomTypeface : public SkTypeface {
|
||||
public:
|
||||
SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint&, bool fakeit);
|
||||
|
||||
SkTypeface* proxy() const { return fProxy.get(); }
|
||||
SkTypeface* proxy() const { return fProxy.get(); }
|
||||
const SkPaint& paint() const { return fPaint; }
|
||||
|
||||
protected:
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor*) const override;
|
||||
void onFilterRec(SkScalerContextRec*) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar*) const override;
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor*) const override;
|
||||
void onFilterRec(SkScalerContextRec*) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar*) const override;
|
||||
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override;
|
||||
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override;
|
||||
void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override;
|
||||
void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const override;
|
||||
|
||||
void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
|
||||
int onCountGlyphs() const override;
|
||||
int onGetUPEM() const override;
|
||||
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
|
||||
void getPostScriptGlyphNames(SkString*) const override;
|
||||
|
@ -21,7 +21,7 @@ protected:
|
||||
TestEmptyTypeface() : SkTypeface(SkFontStyle(), true) {}
|
||||
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
|
||||
sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
|
||||
return sk_ref_sp(this);
|
||||
}
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects& effects,
|
||||
@ -30,11 +30,11 @@ protected:
|
||||
sk_ref_sp(const_cast<TestEmptyTypeface*>(this)), effects, desc);
|
||||
|
||||
}
|
||||
void onFilterRec(SkScalerContextRec*) const override {}
|
||||
void onFilterRec(SkScalerContextRec*) const override {}
|
||||
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
|
||||
return nullptr;
|
||||
}
|
||||
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {}
|
||||
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {}
|
||||
void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override {
|
||||
sk_bzero(glyphs, count * sizeof(glyphs[0]));
|
||||
}
|
||||
@ -47,6 +47,7 @@ protected:
|
||||
bool next(SkTypeface::LocalizedString*) override { return false; }
|
||||
};
|
||||
void onGetFamilyName(SkString* familyName) const override { familyName->reset(); }
|
||||
bool onGetPostScriptName(SkString*) const override { return false; }
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
|
||||
return new EmptyLocalizedStrings;
|
||||
}
|
||||
|
@ -159,6 +159,8 @@ void TestSVGTypeface::onCharsToGlyphs(const SkUnichar uni[], int count, SkGlyphI
|
||||
|
||||
void TestSVGTypeface::onGetFamilyName(SkString* familyName) const { *familyName = fName; }
|
||||
|
||||
bool TestSVGTypeface::onGetPostScriptName(SkString*) const { return false; }
|
||||
|
||||
SkTypeface::LocalizedStrings* TestSVGTypeface::onCreateFamilyNameIterator() const {
|
||||
SkString familyName(fName);
|
||||
SkString language("und"); // undetermined
|
||||
|
@ -80,10 +80,10 @@ public:
|
||||
protected:
|
||||
void exportTtxCommon(SkWStream*, const char* type, const SkTArray<GlyfInfo>* = nullptr) const;
|
||||
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor* desc) const override;
|
||||
void onFilterRec(SkScalerContextRec* rec) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar*) const override;
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor* desc) const override;
|
||||
void onFilterRec(SkScalerContextRec* rec) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar*) const override;
|
||||
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
|
||||
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
@ -102,7 +102,8 @@ protected:
|
||||
|
||||
int onGetUPEM() const override { return fUpem; }
|
||||
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
|
||||
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
|
@ -137,6 +137,8 @@ void TestTypeface::onCharsToGlyphs(const SkUnichar* uni, int count, SkGlyphID gl
|
||||
|
||||
void TestTypeface::onGetFamilyName(SkString* familyName) const { *familyName = fTestFont->fName; }
|
||||
|
||||
bool TestTypeface::onGetPostScriptName(SkString*) const { return false; }
|
||||
|
||||
SkTypeface::LocalizedStrings* TestTypeface::onCreateFamilyNameIterator() const {
|
||||
SkString familyName(fTestFont->fName);
|
||||
SkString language("und"); // undetermined
|
||||
|
@ -72,8 +72,8 @@ public:
|
||||
protected:
|
||||
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
|
||||
const SkDescriptor* desc) const override;
|
||||
void onFilterRec(SkScalerContextRec* rec) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
|
||||
void onFilterRec(SkScalerContextRec* rec) const override;
|
||||
void getGlyphToUnicodeMap(SkUnichar* glyphToUnicode) const override;
|
||||
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
|
||||
|
||||
std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override { return nullptr; }
|
||||
@ -92,7 +92,8 @@ protected:
|
||||
|
||||
int onGetUPEM() const override { return 2048; }
|
||||
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
void onGetFamilyName(SkString* familyName) const override;
|
||||
bool onGetPostScriptName(SkString*) const override;
|
||||
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
|
||||
|
||||
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
|
||||
|
Loading…
Reference in New Issue
Block a user