aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkTypeface.h6
-rw-r--r--src/core/SkTypeface.cpp9
-rw-r--r--src/fonts/SkGScalerContext.cpp4
-rw-r--r--src/fonts/SkGScalerContext.h1
-rw-r--r--src/fonts/SkTestScalerContext.cpp4
-rw-r--r--src/fonts/SkTestScalerContext.h1
-rw-r--r--src/ports/SkFontConfigTypeface.h1
-rw-r--r--src/ports/SkFontHost_fontconfig.cpp4
-rw-r--r--src/ports/SkFontHost_linux.cpp4
-rwxr-xr-xsrc/ports/SkFontHost_mac.cpp5
-rwxr-xr-xsrc/ports/SkFontHost_win.cpp12
-rw-r--r--src/ports/SkFontMgr_android.cpp6
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp8
-rw-r--r--src/ports/SkTypeface_win_dw.cpp16
-rw-r--r--src/ports/SkTypeface_win_dw.h1
15 files changed, 65 insertions, 17 deletions
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 0b1c1f24ac..1df467a0e5 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -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;
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index fcb2b8e2b1..74dd5d96b9 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -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(
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp
index e543fdbd0a..34a788a9c9 100644
--- a/src/fonts/SkGScalerContext.cpp
+++ b/src/fonts/SkGScalerContext.cpp
@@ -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();
}
diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h
index faca50ed6b..8ad28173c0 100644
--- a/src/fonts/SkGScalerContext.h
+++ b/src/fonts/SkGScalerContext.h
@@ -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;
diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp
index 854c980904..ee379f0a38 100644
--- a/src/fonts/SkTestScalerContext.cpp
+++ b/src/fonts/SkTestScalerContext.cpp
@@ -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
diff --git a/src/fonts/SkTestScalerContext.h b/src/fonts/SkTestScalerContext.h
index aed64e7e43..42f604952f 100644
--- a/src/fonts/SkTestScalerContext.h
+++ b/src/fonts/SkTestScalerContext.h
@@ -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 {
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index b6f8797eb7..f62d99d2f4 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -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;
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index ace7058714..57252d0c18 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -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());
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontHost_linux.cpp
index 72a6399612..2904cac9bc 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontHost_linux.cpp
@@ -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());
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 3c73493b41..5386ac3f3e 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -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;
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 6f8669e40c..1290c007a5 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -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;
}
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index bcf544cd43..2fee7356f1 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -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;
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index b8a3fe5b0d..f4cae23e03 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -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));
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index 9c727e715e..9c2b41d44c 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -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());
diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h
index 650685825d..531dc51a11 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -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,