summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-09 15:11:46 +0000
committerreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-09 15:11:46 +0000
commit12c3ee69a3c5cd105f8c2833b8c4082b38d098e3 (patch)
treed06575a3ae12840e52e7822671f3922e80b99948
parentee8ee54093f47b773eeb8195501a12af99a64288 (diff)
downloadchromium_src-12c3ee69a3c5cd105f8c2833b8c4082b38d098e3.zip
chromium_src-12c3ee69a3c5cd105f8c2833b8c4082b38d098e3.tar.gz
chromium_src-12c3ee69a3c5cd105f8c2833b8c4082b38d098e3.tar.bz2
implement Serialize/Deserialize, so we can serialize pictures
Review URL: https://chromiumcodereview.appspot.com/10837077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150794 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--skia/ext/SkFontHost_fontconfig.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/skia/ext/SkFontHost_fontconfig.cpp b/skia/ext/SkFontHost_fontconfig.cpp
index 8c28dba..ce20e52 100644
--- a/skia/ext/SkFontHost_fontconfig.cpp
+++ b/skia/ext/SkFontHost_fontconfig.cpp
@@ -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 @@ SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[])
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());
}
///////////////////////////////////////////////////////////////////////////////