Skip to content

Commit 59637dd

Browse files
Ben WagnerSkia Commit-Bot
authored andcommitted
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>
1 parent d6cfe72 commit 59637dd

20 files changed

+122
-19
lines changed

include/core/SkTypeface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ class SK_API SkTypeface : public SkWeakRefCnt {
300300
*/
301301
void getFamilyName(SkString* name) const;
302302

303+
/**
304+
* Return the PostScript name for this typeface.
305+
* Value may change based on variation parameters.
306+
* Returns false if no PostScript name is available.
307+
*/
308+
bool getPostScriptName(SkString* name) const;
309+
303310
/**
304311
* Return a stream for the contents of the font data, or NULL on failure.
305312
* If ttcIndex is not null, it is set to the TrueTypeCollection index
@@ -387,6 +394,7 @@ class SK_API SkTypeface : public SkWeakRefCnt {
387394
* This name may or may not be produced by the family name iterator.
388395
*/
389396
virtual void onGetFamilyName(SkString* familyName) const = 0;
397+
virtual bool onGetPostScriptName(SkString*) const = 0;
390398

391399
/** Returns an iterator over the family names in the font. */
392400
virtual LocalizedStrings* onCreateFamilyNameIterator() const = 0;

src/core/SkTypeface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class SkEmptyTypeface : public SkTypeface {
6363
void onGetFamilyName(SkString* familyName) const override {
6464
familyName->reset();
6565
}
66+
bool onGetPostScriptName(SkString*) const override {
67+
return false;
68+
}
6669
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
6770
return new EmptyLocalizedStrings;
6871
}
@@ -332,6 +335,10 @@ void SkTypeface::getFamilyName(SkString* name) const {
332335
this->onGetFamilyName(name);
333336
}
334337

338+
bool SkTypeface::getPostScriptName(SkString* name) const {
339+
return this->onGetPostScriptName(name);
340+
}
341+
335342
void SkTypeface::getGlyphToUnicodeMap(SkUnichar* dst) const {
336343
sk_bzero(dst, sizeof(SkUnichar) * this->countGlyphs());
337344
}

src/core/SkTypeface_remote.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class SkTypefaceProxy : public SkTypeface {
7878
// Used by SkStrikeCache::DumpMemoryStatistics.
7979
*familyName = "";
8080
}
81+
bool onGetPostScriptName(SkString*) const override {
82+
SK_ABORT("Should never be called.");
83+
}
8184
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
8285
SK_ABORT("Should never be called.");
8386
}

src/ports/SkFontHost_FreeType.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,23 @@ void SkTypeface_FreeType::getPostScriptGlyphNames(SkString* dstArray) const {
696696
}
697697
}
698698

699+
bool SkTypeface_FreeType::onGetPostScriptName(SkString* skPostScriptName) const {
700+
AutoFTAccess fta(this);
701+
FT_Face face = fta.face();
702+
if (!face) {
703+
return false;
704+
}
705+
706+
const char* ftPostScriptName = FT_Get_Postscript_Name(face);
707+
if (!ftPostScriptName) {
708+
return false;
709+
}
710+
if (skPostScriptName) {
711+
*skPostScriptName = ftPostScriptName;
712+
}
713+
return true;
714+
}
715+
699716
///////////////////////////////////////////////////////////////////////////
700717

701718
static bool bothZero(SkScalar a, SkScalar b) {

src/ports/SkFontHost_FreeType_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class SkTypeface_FreeType : public SkTypeface {
106106
void getGlyphToUnicodeMap(SkUnichar*) const override;
107107
std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
108108
void getPostScriptGlyphNames(SkString* dstArray) const override;
109+
bool onGetPostScriptName(SkString*) const override;
109110
int onGetUPEM() const override;
110111
bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
111112
int32_t adjustments[]) const override;

src/ports/SkFontHost_win.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class LogFontTypeface : public SkTypeface {
285285
void getPostScriptGlyphNames(SkString*) const override;
286286
int onGetUPEM() const override;
287287
void onGetFamilyName(SkString* familyName) const override;
288+
bool onGetPostScriptName(SkString*) const override { return false; }
288289
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
289290
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
290291
int coordinateCount) const override

src/ports/SkTypeface_mac_ct.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,17 @@ void SkTypeface_Mac::onGetFamilyName(SkString* familyName) const {
10961096
get_str(CTFontCopyFamilyName(fFontRef.get()), familyName);
10971097
}
10981098

1099+
bool SkTypeface_Mac::onGetPostScriptName(SkString* skPostScriptName) const {
1100+
SkUniqueCFRef<CFStringRef> ctPostScriptName(CTFontCopyPostScriptName(fFontRef.get()));
1101+
if (!ctPostScriptName) {
1102+
return false;
1103+
}
1104+
if (skPostScriptName) {
1105+
SkStringFromCFString(ctPostScriptName.get(), skPostScriptName);
1106+
}
1107+
return true;
1108+
}
1109+
10991110
void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc,
11001111
bool* isLocalStream) const {
11011112
SkString tmpStr;

src/ports/SkTypeface_mac_ct.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class SkTypeface_Mac : public SkTypeface {
9696
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
9797
int coordinateCount) const override;
9898
void onGetFamilyName(SkString* familyName) const override;
99+
bool onGetPostScriptName(SkString*) const override;
99100
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
100101
int onGetTableTags(SkFontTableTag tags[]) const override;
101102
size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override;

src/ports/SkTypeface_win_dw.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const {
5454
sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, familyName);
5555
}
5656

57+
bool DWriteFontTypeface::onGetPostScriptName(SkString* skPostScriptName) const {
58+
SkString localSkPostScriptName;
59+
SkTScopedComPtr<IDWriteLocalizedStrings> postScriptNames;
60+
BOOL exists = FALSE;
61+
if (FAILED(fDWriteFont->GetInformationalStrings(
62+
DWRITE_INFORMATIONAL_STRING_POSTSCRIPT_NAME,
63+
&postScriptNames,
64+
&exists)) ||
65+
!exists ||
66+
FAILED(sk_get_locale_string(postScriptNames.get(), nullptr, &localSkPostScriptName)))
67+
{
68+
return false;
69+
}
70+
if (skPostScriptName) {
71+
*skPostScriptName = localSkPostScriptName;
72+
}
73+
return true;
74+
}
75+
5776
void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
5877
bool* isLocalStream) const {
5978
// Get the family name.

src/ports/SkTypeface_win_dw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class DWriteFontTypeface : public SkTypeface {
134134
void getPostScriptGlyphNames(SkString*) const override;
135135
int onGetUPEM() const override;
136136
void onGetFamilyName(SkString* familyName) const override;
137+
bool onGetPostScriptName(SkString*) const override;
137138
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
138139
int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
139140
int coordinateCount) const override;

0 commit comments

Comments
 (0)