Index: skia/ext/SkFontHost_fontconfig.cpp |
=================================================================== |
--- skia/ext/SkFontHost_fontconfig.cpp (revision 150609) |
+++ skia/ext/SkFontHost_fontconfig.cpp (working copy) |
@@ -31,6 +31,7 @@ |
#include <sys/stat.h> |
#include <unistd.h> |
+#include "third_party/skia/src/ports/SkFontDescriptor.h" |
#include "SkFontHost.h" |
#include "SkStream.h" |
#include "SkFontHost_fontconfig_control.h" |
@@ -210,19 +211,47 @@ |
return NULL; |
} |
-void SkFontHost::Serialize(const SkTypeface*, SkWStream*) { |
- SkASSERT(!"SkFontHost::Serialize unimplemented"); |
+uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) { |
+ // We don't handle font fallback, WebKit does. |
+ return 0; |
} |
-SkTypeface* SkFontHost::Deserialize(SkStream* stream) { |
- SkASSERT(!"SkFontHost::Deserialize unimplemented"); |
- return NULL; |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+// Serialize, Deserialize need to be compatible across platforms, hence the use |
+// of SkFontDescriptor. |
+ |
+void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { |
+ SkFontDescriptor desc(face->style()); |
+ |
+ std::string resolved_family_name; |
+ |
+ const unsigned filefaceid = UniqueIdToFileFaceId(face->uniqueID()); |
+ if (GetFcImpl()->Match(&resolved_family_name, NULL, |
+ true /* filefaceid valid */, filefaceid, "", NULL, 0, NULL, NULL)) |
+ desc.setFamilyName(resolved_family_name.c_str()); |
+ else |
+ desc.setFamilyName("sans-serif"); |
+ |
+ // would also like other names (see SkFontDescriptor.h) |
+ |
+ desc.serialize(stream); |
+ |
+ // by convention, we also write out the actual sfnt data, preceeded by |
+ // a packed-length. For now we skip that, so we just write the zero. |
+ stream->writePackedUInt(0); |
} |
-// static |
-uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) { |
- // We don't handle font fallback, WebKit does. |
- return 0; |
+SkTypeface* SkFontHost::Deserialize(SkStream* stream) { |
+ SkFontDescriptor desc(stream); |
+ |
+ // by convention, Serialize will have also written the actual sfnt data. |
+ // for now, we just want to skip it. |
+ size_t size = stream->readPackedUInt(); |
+ stream->skip(size); |
+ |
+ return SkFontHost::CreateTypeface(NULL, desc.getFamilyName(), |
+ desc.getStyle()); |
} |
/////////////////////////////////////////////////////////////////////////////// |