From 1a4900e8be6086a824488dc98d4822e440815657 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 11 Dec 2014 11:06:00 -0800 Subject: [PATCH] Force embedding full font when serializing pictures. We can't do this unconditionally or pipe will become stupidly slow. DM's serialize mode fails subtly on Mac when we force embedding, so I've #ifdef'd that away. Other platforms look fine. BUG=skia: Review URL: https://codereview.chromium.org/796523002 --- include/core/SkTypeface.h | 4 ++++ src/core/SkPictureData.cpp | 5 +++++ src/core/SkTypeface.cpp | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index c3ff364..c2aa543 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -137,6 +137,10 @@ public: */ void serialize(SkWStream*) const; + /** Like serialize, but write the whole font (not just a signature) if possible. + */ + void serializeForcingEmbedding(SkWStream*) const; + /** Given the data previously written by serialize(), return a new instance to a typeface referring to the same font. If that font is not available, return null. If an instance is returned, the caller is responsible for diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 938274a..7fc165d 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -180,7 +180,12 @@ void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { rec.copyToArray((SkRefCnt**)array); for (int i = 0; i < count; i++) { +#ifdef SK_BUILD_FOR_UNIX + array[i]->serializeForcingEmbedding(stream); +#else + // FIXME: Macs and Windows don't draw pixel-perfect if we embed fonts in the SKP. array[i]->serialize(stream); +#endif } } diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index c537d4a..02d2bc8 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -155,12 +155,26 @@ void SkTypeface::serialize(SkWStream* wstream) const { SkFontDescriptor desc(this->style()); this->onGetFontDescriptor(&desc, &isLocal); + // Embed font data if it's a local font. if (isLocal && NULL == desc.getFontData()) { int ttcIndex; desc.setFontData(this->onOpenStream(&ttcIndex)); desc.setFontIndex(ttcIndex); } + desc.serialize(wstream); +} + +void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { + bool ignoredIsLocal; + SkFontDescriptor desc(this->style()); + this->onGetFontDescriptor(&desc, &ignoredIsLocal); + // Always embed font data. + if (NULL == desc.getFontData()) { + int ttcIndex; + desc.setFontData(this->onOpenStream(&ttcIndex)); + desc.setFontIndex(ttcIndex); + } desc.serialize(wstream); } -- 2.7.4