Store font family when serializing android fonts.
Review URL: https://codereview.appspot.com/6259063
git-svn-id: http://skia.googlecode.com/svn/trunk@4114 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp
index 70f1c7b..e4215e2 100644
--- a/src/ports/SkFontHost_android.cpp
+++ b/src/ports/SkFontHost_android.cpp
@@ -139,6 +139,27 @@
return NULL;
}
+// gFamilyHeadAndNameListMutex must already be acquired
+static const char* find_family_name(const SkTypeface* member) {
+ FamilyRec* family = find_family(member);
+ if (NULL == family) {
+ return NULL;
+ }
+
+ NameFamilyPairList& namelist = GetNameList();
+ NameFamilyPair* list = namelist.begin();
+ int count = namelist.count();
+
+ for (int i = 0; i < count; i++) {
+ NameFamilyPair* pair = &list[i];
+ if (pair->fFamily == family) {
+ return pair->fName;
+ }
+ }
+
+ return NULL;
+}
+
/* Returns the matching typeface, or NULL. If a typeface is found, its refcnt
is not modified.
*/
@@ -699,9 +720,12 @@
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
SkFontDescriptor descriptor;
- //descriptor.setFontFamilyName();
- descriptor.setFontStyle(face->style());
- descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString());
+ {
+ SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
+ descriptor.setFamilyName(find_family_name(face));
+ descriptor.setStyle(face->style());
+ descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString());
+ }
descriptor.serialize(stream);
@@ -727,9 +751,9 @@
}
SkFontDescriptor descriptor(stream);
- const char* familyName = descriptor.getFontFamilyName();
+ const char* familyName = descriptor.getFamilyName();
const char* fontFileName = descriptor.getFontFileName();
- const SkTypeface::Style style = descriptor.getFontStyle();
+ const SkTypeface::Style style = descriptor.getStyle();
const uint32_t customFontDataLength = stream->readPackedUInt();
if (customFontDataLength > 0) {