Add onGetFamilyName to SkTypeface.
This speeds up and documents this particular feature of SkTypeface and also frees up SkFontDescriptor to be used only in serialization. R=reed@google.com Author: bungeman@google.com Review URL: https://codereview.chromium.org/574873002
This commit is contained in:
parent
3850971d54
commit
b374d6a62c
@ -312,6 +312,12 @@ protected:
|
||||
virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
|
||||
int32_t adjustments[]) const;
|
||||
|
||||
/** Returns the family name of the typeface as known by its font manager.
|
||||
* This name may or may not be produced by the family name iterator.
|
||||
*/
|
||||
virtual void onGetFamilyName(SkString* familyName) const = 0;
|
||||
|
||||
/** Returns an iterator over the family names in the font. */
|
||||
virtual LocalizedStrings* onCreateFamilyNameIterator() const = 0;
|
||||
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const = 0;
|
||||
|
@ -67,6 +67,9 @@ protected:
|
||||
public:
|
||||
virtual bool next(SkTypeface::LocalizedString*) SK_OVERRIDE { return false; }
|
||||
};
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
|
||||
familyName->reset();
|
||||
}
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE {
|
||||
return SkNEW(EmptyLocalizedStrings);
|
||||
};
|
||||
@ -273,10 +276,8 @@ SkTypeface::LocalizedStrings* SkTypeface::createFamilyNameIterator() const {
|
||||
}
|
||||
|
||||
void SkTypeface::getFamilyName(SkString* name) const {
|
||||
bool isLocal = false;
|
||||
SkFontDescriptor desc(this->style());
|
||||
this->onGetFontDescriptor(&desc, &isLocal);
|
||||
name->set(desc.getFamilyName());
|
||||
SkASSERT(name);
|
||||
this->onGetFamilyName(name);
|
||||
}
|
||||
|
||||
SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
|
||||
|
@ -206,6 +206,10 @@ int SkGTypeface::onGetUPEM() const {
|
||||
return fProxy->getUnitsPerEm();
|
||||
}
|
||||
|
||||
void SkGTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
fProxy->getFamilyName(familyName);
|
||||
}
|
||||
|
||||
SkTypeface::LocalizedStrings* SkGTypeface::onCreateFamilyNameIterator() const {
|
||||
return fProxy->createFamilyNameIterator();
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ protected:
|
||||
virtual int onCountGlyphs() const SK_OVERRIDE;
|
||||
virtual int onGetUPEM() const SK_OVERRIDE;
|
||||
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
|
||||
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
|
||||
|
@ -175,6 +175,10 @@ int SkTestTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
|
||||
return glyphCount;
|
||||
}
|
||||
|
||||
void SkTestTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
*familyName = fTestFont->fName;
|
||||
}
|
||||
|
||||
SkTypeface::LocalizedStrings* SkTestTypeface::onCreateFamilyNameIterator() const {
|
||||
SkString familyName(fTestFont->fName);
|
||||
SkString language("und"); //undetermined
|
||||
|
@ -92,6 +92,7 @@ protected:
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
|
||||
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE {
|
||||
|
@ -65,6 +65,7 @@ protected:
|
||||
SkSafeRef(localStream);
|
||||
}
|
||||
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE;
|
||||
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
|
||||
|
||||
|
@ -162,6 +162,10 @@ SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
|
||||
return stream;
|
||||
}
|
||||
|
||||
void FontConfigTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
*familyName = this->getFamilyName();
|
||||
}
|
||||
|
||||
void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
desc->setFamilyName(this->getFamilyName());
|
||||
|
@ -40,6 +40,10 @@ public:
|
||||
virtual const char* getUniqueString() const = 0;
|
||||
|
||||
protected:
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
|
||||
*familyName = fFamilyName;
|
||||
}
|
||||
|
||||
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const SK_OVERRIDE {
|
||||
desc->setFamilyName(fFamilyName.c_str());
|
||||
desc->setFontFileName(this->getUniqueString());
|
||||
|
@ -452,6 +452,7 @@ protected:
|
||||
|
||||
virtual int onGetUPEM() const SK_OVERRIDE;
|
||||
virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
|
||||
virtual size_t onGetTableData(SkFontTableTag, size_t offset,
|
||||
@ -1900,6 +1901,10 @@ static const char* get_str(CFStringRef ref, SkString* str) {
|
||||
return str->c_str();
|
||||
}
|
||||
|
||||
void SkTypeface_Mac::onGetFamilyName(SkString* familyName) const {
|
||||
get_str(CTFontCopyFamilyName(fFontRef), familyName);
|
||||
}
|
||||
|
||||
void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
SkString tmpStr;
|
||||
|
@ -276,6 +276,7 @@ protected:
|
||||
uint16_t glyphs[], int glyphCount) const SK_OVERRIDE;
|
||||
virtual int onCountGlyphs() const SK_OVERRIDE;
|
||||
virtual int onGetUPEM() const SK_OVERRIDE;
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
|
||||
virtual size_t onGetTableData(SkFontTableTag, size_t offset,
|
||||
@ -1761,16 +1762,14 @@ static void logfont_for_name(const char* familyName, LOGFONT* lf) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
void LogFontTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
// Get the actual name of the typeface. The logfont may not know this.
|
||||
HFONT font = CreateFontIndirect(&fLogFont);
|
||||
|
||||
HDC deviceContext = ::CreateCompatibleDC(NULL);
|
||||
HFONT savefont = (HFONT)SelectObject(deviceContext, font);
|
||||
|
||||
SkString familyName;
|
||||
dcfontname_to_skstring(deviceContext, fLogFont, &familyName);
|
||||
dcfontname_to_skstring(deviceContext, fLogFont, familyName);
|
||||
|
||||
if (deviceContext) {
|
||||
::SelectObject(deviceContext, savefont);
|
||||
@ -1779,7 +1778,12 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
if (font) {
|
||||
::DeleteObject(font);
|
||||
}
|
||||
}
|
||||
|
||||
void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
SkString familyName;
|
||||
this->onGetFamilyName(&familyName);
|
||||
desc->setFamilyName(familyName.c_str());
|
||||
*isLocalStream = this->fSerializeAsStream;
|
||||
}
|
||||
|
@ -49,9 +49,11 @@ public:
|
||||
, fIndex(index)
|
||||
, fFamilyName(familyName) { }
|
||||
|
||||
const SkString& name() const { return fFamilyName; }
|
||||
|
||||
protected:
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
|
||||
*familyName = fFamilyName;
|
||||
}
|
||||
|
||||
int fIndex;
|
||||
SkString fFamilyName;
|
||||
|
||||
|
@ -389,6 +389,10 @@ public:
|
||||
, fIndex(ttcIndex)
|
||||
{ };
|
||||
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
|
||||
familyName->reset();
|
||||
}
|
||||
|
||||
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE {
|
||||
desc->setStyle(this->style());
|
||||
*serialize = true;
|
||||
@ -414,6 +418,10 @@ public:
|
||||
}
|
||||
mutable SkAutoFcPattern fPattern;
|
||||
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE {
|
||||
*familyName = get_string(fPattern, FC_FAMILY);
|
||||
}
|
||||
|
||||
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const SK_OVERRIDE {
|
||||
FCLocker lock;
|
||||
desc->setFamilyName(get_string(fPattern, FC_FAMILY));
|
||||
|
@ -12,6 +12,7 @@
|
||||
// not use GDI, undefing GetGlyphIndices makes things less confusing.
|
||||
#undef GetGlyphIndices
|
||||
|
||||
#include "SkDWrite.h"
|
||||
#include "SkDWriteFontFileStream.h"
|
||||
#include "SkFontDescriptor.h"
|
||||
#include "SkFontStream.h"
|
||||
@ -24,20 +25,21 @@
|
||||
#include "SkTypeface_win_dw.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
void DWriteFontTypeface::onGetFamilyName(SkString* familyName) const {
|
||||
SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
|
||||
HRV(fDWriteFontFamily->GetFamilyNames(&familyNames));
|
||||
|
||||
sk_get_locale_string(familyNames.get(), NULL/*fMgr->fLocaleName.get()*/, familyName);
|
||||
}
|
||||
|
||||
void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
|
||||
bool* isLocalStream) const {
|
||||
// Get the family name.
|
||||
SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
|
||||
HRV(fDWriteFontFamily->GetFamilyNames(&familyNames));
|
||||
|
||||
UINT32 familyNamesLen;
|
||||
HRV(familyNames->GetStringLength(0, &familyNamesLen));
|
||||
|
||||
SkSMallocWCHAR familyName(familyNamesLen+1);
|
||||
HRV(familyNames->GetString(0, familyName.get(), familyNamesLen+1));
|
||||
|
||||
SkString utf8FamilyName;
|
||||
HRV(sk_wchar_to_skstring(familyName.get(), familyNamesLen, &utf8FamilyName));
|
||||
sk_get_locale_string(familyNames.get(), NULL/*fMgr->fLocaleName.get()*/, &utf8FamilyName);
|
||||
|
||||
desc->setFamilyName(utf8FamilyName.c_str());
|
||||
*isLocalStream = SkToBool(fDWriteFontFileLoader.get());
|
||||
|
@ -111,6 +111,7 @@ protected:
|
||||
uint16_t glyphs[], int glyphCount) const SK_OVERRIDE;
|
||||
virtual int onCountGlyphs() const SK_OVERRIDE;
|
||||
virtual int onGetUPEM() const SK_OVERRIDE;
|
||||
virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE;
|
||||
virtual SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const SK_OVERRIDE;
|
||||
virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
|
||||
virtual size_t onGetTableData(SkFontTableTag, size_t offset,
|
||||
|
Loading…
Reference in New Issue
Block a user