aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-07-25 16:54:59 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-25 16:54:59 -0700
commitb8113780c3cfed640016b263194b7f1531d43312 (patch)
treee677f7b762ad7d981f74f366075d3c5c8fbf9988
parent0f7748ab388c3a07b71e41d8042313b6744f3cae (diff)
Update typeface serialization style.
-rw-r--r--include/core/SkPicture.h5
-rw-r--r--src/core/SkFontDescriptor.cpp15
-rw-r--r--src/core/SkFontDescriptor.h8
-rw-r--r--src/core/SkTypeface.cpp5
-rw-r--r--src/fonts/SkFontMgr_fontconfig.cpp1
-rw-r--r--src/fonts/SkTestScalerContext.cpp1
-rw-r--r--src/ports/SkFontHost_mac.cpp1
-rw-r--r--src/ports/SkFontHost_win.cpp1
-rw-r--r--src/ports/SkFontMgr_android.cpp1
-rw-r--r--src/ports/SkFontMgr_custom.cpp1
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp1
-rw-r--r--src/ports/SkTypeface_win_dw.cpp1
-rw-r--r--src/utils/SkWhitelistTypefaces.cpp15
13 files changed, 38 insertions, 18 deletions
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 8e3d1c8019..75fe66d2bf 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -220,7 +220,10 @@ private:
static_assert(MIN_PICTURE_VERSION <= 43,
"Remove SkBitmapSourceDeserializer.");
-
+
+ static_assert(MIN_PICTURE_VERSION <= 45,
+ "Remove decoding of old SkTypeface::Style from SkFontDescriptor.cpp.");
+
static bool IsValidPictInfo(const SkPictInfo& info);
static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
const SkPictureData*,
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 4b0dd0831b..24e1a67864 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -168,7 +168,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.
@@ -196,8 +196,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 bab6b893e2..fcb65a83c1 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 41cb52b660..d95ebbb272 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -2087,6 +2087,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 226f2196f0..aa6a3ce341 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 a8d5b12a43..23c950d01d 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 a05cc9b650..65887662b0 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 d4d873744f..b5c31c7fdf 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() {