Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: skia/ext/SkFontHost_fontconfig.cpp

Issue 10837077: implement Serialize/Deserialize, so we can serialize pictures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698