diff options
author | bungeman <bungeman@google.com> | 2016-06-13 10:35:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-13 10:35:05 -0700 |
commit | 7ae1c72e593823e6e300e4199558555765bcec17 (patch) | |
tree | 348622db2a485d12acd8c328eb27c3b3992f4a79 /src | |
parent | 398e3f4b9f67e0c7f635e68cae1ff7f42213bbfc (diff) |
Update typeface serialization style.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2030683002
Review-Url: https://codereview.chromium.org/2030683002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkFontDescriptor.cpp | 15 | ||||
-rw-r--r-- | src/core/SkFontDescriptor.h | 8 | ||||
-rw-r--r-- | src/core/SkTypeface.cpp | 5 | ||||
-rw-r--r-- | src/fonts/SkFontMgr_fontconfig.cpp | 1 | ||||
-rw-r--r-- | src/fonts/SkTestScalerContext.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontHost_win.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontMgr_custom.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkFontMgr_fontconfig.cpp | 1 | ||||
-rw-r--r-- | src/ports/SkTypeface_win_dw.cpp | 1 | ||||
-rw-r--r-- | src/utils/SkWhitelistTypefaces.cpp | 15 |
12 files changed, 34 insertions, 17 deletions
diff --git a/src/core/SkFontDescriptor.cpp b/src/core/SkFontDescriptor.cpp index 69fdc15432..85629efa7e 100644 --- a/src/core/SkFontDescriptor.cpp +++ b/src/core/SkFontDescriptor.cpp @@ -23,7 +23,7 @@ enum { kSentinel = 0xFF, }; -SkFontDescriptor::SkFontDescriptor(SkTypeface::Style style) : fStyle(style) { } +SkFontDescriptor::SkFontDescriptor() { } static void read_string(SkStream* stream, SkString* string) { const uint32_t length = SkToU32(stream->readPackedUInt()); @@ -59,7 +59,15 @@ static void write_uint(SkWStream* stream, size_t n, uint32_t id) { } bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) { - result->fStyle = (SkTypeface::Style)stream->readPackedUInt(); + size_t styleBits = stream->readPackedUInt(); + if (styleBits <= 2) { + // Remove this branch when MIN_PICTURE_VERSION > 45 + result->fStyle = SkFontStyle::FromOldStyle(styleBits); + } else { + result->fStyle = SkFontStyle((styleBits >> 16) & 0xFFFF, + (styleBits >> 8 ) & 0xFF, + static_cast<SkFontStyle::Slant>(styleBits & 0xFF)); + } SkAutoSTMalloc<4, SkFixed> axis; size_t axisCount = 0; @@ -109,7 +117,8 @@ bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) { } void SkFontDescriptor::serialize(SkWStream* stream) { - stream->writePackedUInt(fStyle); + uint32_t styleBits = (fStyle.weight() << 16) | (fStyle.width() << 8) | (fStyle.slant()); + stream->writePackedUInt(styleBits); write_string(stream, fFamilyName, kFontFamilyName); write_string(stream, fFullName, kFullName); diff --git a/src/core/SkFontDescriptor.h b/src/core/SkFontDescriptor.h index 9b87365ed5..cb8d2f4f03 100644 --- a/src/core/SkFontDescriptor.h +++ b/src/core/SkFontDescriptor.h @@ -50,14 +50,14 @@ private: class SkFontDescriptor : SkNoncopyable { public: - SkFontDescriptor(SkTypeface::Style = SkTypeface::kNormal); + SkFontDescriptor(); // Does not affect ownership of SkStream. static bool Deserialize(SkStream*, SkFontDescriptor* result); void serialize(SkWStream*); - SkTypeface::Style getStyle() { return fStyle; } - void setStyle(SkTypeface::Style style) { fStyle = style; } + SkFontStyle getStyle() { return fStyle; } + void setStyle(SkFontStyle style) { fStyle = style; } const char* getFamilyName() const { return fFamilyName.c_str(); } const char* getFullName() const { return fFullName.c_str(); } @@ -78,7 +78,7 @@ private: SkString fPostscriptName; SkAutoTDelete<SkFontData> fFontData; - SkTypeface::Style fStyle; + SkFontStyle fStyle; }; #endif // SkFontDescriptor_DEFINED diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index 90a1eaabec..9ab37a80df 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -167,7 +167,7 @@ void SkTypeface::serialize(SkWStream* wstream) const { return; } bool isLocal = false; - SkFontDescriptor desc(this->style()); + SkFontDescriptor desc; this->onGetFontDescriptor(&desc, &isLocal); // Embed font data if it's a local font. @@ -195,8 +195,7 @@ sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) { } } - return SkTypeface::MakeFromName(desc.getFamilyName(), - SkFontStyle::FromOldStyle(desc.getStyle())); + return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle()); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/fonts/SkFontMgr_fontconfig.cpp b/src/fonts/SkFontMgr_fontconfig.cpp index 937696468e..09b4d13dd4 100644 --- a/src/fonts/SkFontMgr_fontconfig.cpp +++ b/src/fonts/SkFontMgr_fontconfig.cpp @@ -31,6 +31,7 @@ void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalSt SkString name; this->getFamilyName(&name); desc->setFamilyName(name.c_str()); + desc->setStyle(this->fontStyle()); *isLocalStream = SkToBool(this->getLocalStream()); } diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp index a2748564a5..6cfcb738da 100644 --- a/src/fonts/SkTestScalerContext.cpp +++ b/src/fonts/SkTestScalerContext.cpp @@ -156,6 +156,7 @@ SkAdvancedTypefaceMetrics* SkTestTypeface::onGetAdvancedTypefaceMetrics( void SkTestTypeface::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const { desc->setFamilyName(fTestFont->fName); + desc->setStyle(this->fontStyle()); *isLocal = false; } diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index c129a6b24b..153783add6 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -2036,6 +2036,7 @@ void SkTypeface_Mac::onGetFontDescriptor(SkFontDescriptor* desc, desc->setFamilyName(get_str(CTFontCopyFamilyName(fFontRef), &tmpStr)); desc->setFullName(get_str(CTFontCopyFullName(fFontRef), &tmpStr)); desc->setPostscriptName(get_str(CTFontCopyPostScriptName(fFontRef), &tmpStr)); + desc->setStyle(this->fontStyle()); *isLocalStream = fIsLocalStream; } diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 25038dcf38..8b7801ba78 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -1714,6 +1714,7 @@ void LogFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, SkString familyName; this->onGetFamilyName(&familyName); desc->setFamilyName(familyName.c_str()); + desc->setStyle(this->fontStyle()); *isLocalStream = this->fSerializeAsStream; } diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 2e619af0fb..4e8a1808f5 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -85,6 +85,7 @@ public: SkASSERT(desc); SkASSERT(serialize); desc->setFamilyName(fFamilyName.c_str()); + desc->setStyle(this->fontStyle()); *serialize = false; } SkStreamAsset* onOpenStream(int* ttcIndex) const override { diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp index 0fc5180dd4..1c99353b07 100644 --- a/src/ports/SkFontMgr_custom.cpp +++ b/src/ports/SkFontMgr_custom.cpp @@ -43,6 +43,7 @@ protected: void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override { desc->setFamilyName(fFamilyName.c_str()); + desc->setStyle(this->fontStyle()); *isLocal = !this->isSysFont(); } diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index 610a3001fb..4e1bee8766 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -449,6 +449,7 @@ public: desc->setFamilyName(get_string(fPattern, FC_FAMILY)); desc->setFullName(get_string(fPattern, FC_FULLNAME)); desc->setPostscriptName(get_string(fPattern, FC_POSTSCRIPT_NAME)); + desc->setStyle(this->fontStyle()); *serialize = false; } diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp index a12438c88f..11e5727e38 100644 --- a/src/ports/SkTypeface_win_dw.cpp +++ b/src/ports/SkTypeface_win_dw.cpp @@ -45,6 +45,7 @@ void DWriteFontTypeface::onGetFontDescriptor(SkFontDescriptor* desc, sk_get_locale_string(familyNames.get(), nullptr/*fMgr->fLocaleName.get()*/, &utf8FamilyName); desc->setFamilyName(utf8FamilyName.c_str()); + desc->setStyle(this->fontStyle()); *isLocalStream = SkToBool(fDWriteFontFileLoader.get()); } diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp index bc454bfe1d..2912fe2501 100644 --- a/src/utils/SkWhitelistTypefaces.cpp +++ b/src/utils/SkWhitelistTypefaces.cpp @@ -83,12 +83,13 @@ static uint32_t compute_checksum(const SkTypeface* tf) { return SkChecksum::Murmur3(data.begin(), length); } -static void serialize_sub(const char* fontName, SkTypeface::Style style, SkWStream* wstream) { - SkFontDescriptor desc(style); +static void serialize_sub(const char* fontName, SkFontStyle style, SkWStream* wstream) { + SkFontDescriptor desc; SkString subName(SUBNAME_PREFIX); subName.append(fontName); const char* familyName = subName.c_str(); desc.setFamilyName(familyName); + desc.setStyle(style); desc.serialize(wstream); #if WHITELIST_DEBUG for (int i = 0; i < whitelistCount; ++i) { @@ -105,14 +106,14 @@ static void serialize_sub(const char* fontName, SkTypeface::Style style, SkWStre static bool is_local(const SkTypeface* tf) { bool isLocal = false; - SkFontDescriptor desc(tf->style()); + SkFontDescriptor desc; tf->getFontDescriptor(&desc, &isLocal); return isLocal; } static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { bool isLocal = false; - SkFontDescriptor desc(tf->style()); + SkFontDescriptor desc; tf->getFontDescriptor(&desc, &isLocal); // Embed font data if it's a local font. @@ -124,7 +125,7 @@ static void serialize_full(const SkTypeface* tf, SkWStream* wstream) { static void serialize_name_only(const SkTypeface* tf, SkWStream* wstream) { bool isLocal = false; - SkFontDescriptor desc(tf->style()); + SkFontDescriptor desc; tf->getFontDescriptor(&desc, &isLocal); SkASSERT(!isLocal); #if WHITELIST_DEBUG @@ -180,7 +181,7 @@ void WhitelistSerializeTypeface(const SkTypeface* tf, SkWStream* wstream) { #endif whitelist[whitelistIndex].fChecksum = checksum; } - serialize_sub(fontName, tf->style(), wstream); + serialize_sub(fontName, tf->fontStyle(), wstream); } sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { @@ -200,7 +201,7 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { familyName += sizeof(SUBNAME_PREFIX) - 1; } - return SkTypeface::MakeFromName(familyName, SkFontStyle::FromOldStyle(desc.getStyle())); + return SkTypeface::MakeFromName(familyName, desc.getStyle()); } bool CheckChecksums() { |