From 25272300c308335f2d87c2a70e249965b268bcb0 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Wed, 25 Jan 2017 11:15:50 -0500 Subject: [PATCH] Implement getFamilyName for stream fonts on Linux. When SkFontMgr_fontconfig and SkFontMgr_FontConfigInterface create a typeface from data they do not store the default font name and getFamilyName will return the empty string. All of the code to handle this properly now exists, it just needs to be hooked up. BUG=skia:1508 Change-Id: I75f2a598a5451babb4a9ceb5e9a9e9d3daa41d60 Reviewed-on: https://skia-review.googlesource.com/7506 Reviewed-by: Florin Malita Commit-Queue: Ben Wagner --- src/ports/SkFontConfigTypeface.h | 16 +++++++++------- src/ports/SkFontMgr_FontConfigInterface.cpp | 9 +++++---- src/ports/SkFontMgr_fontconfig.cpp | 19 ++++++++++++------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h index 0da78ae..e27fbb3 100644 --- a/src/ports/SkFontConfigTypeface.h +++ b/src/ports/SkFontConfigTypeface.h @@ -22,16 +22,16 @@ class SkTypeface_FCI : public SkTypeface_FreeType { public: static SkTypeface_FCI* Create(sk_sp fci, const SkFontConfigInterface::FontIdentity& fi, - const SkString& familyName, + SkString familyName, const SkFontStyle& style) { - return new SkTypeface_FCI(std::move(fci), fi, familyName, style); + return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style); } static SkTypeface_FCI* Create(std::unique_ptr data, - SkFontStyle style, bool isFixedPitch) + SkString familyName, SkFontStyle style, bool isFixedPitch) { - return new SkTypeface_FCI(std::move(data), style, isFixedPitch); + return new SkTypeface_FCI(std::move(data), std::move(familyName), style, isFixedPitch); } const SkFontConfigInterface::FontIdentity& getIdentity() const { @@ -41,16 +41,18 @@ public: protected: SkTypeface_FCI(sk_sp fci, const SkFontConfigInterface::FontIdentity& fi, - const SkString& familyName, + SkString familyName, const SkFontStyle& style) : INHERITED(style, false) , fFCI(std::move(fci)) , fIdentity(fi) - , fFamilyName(familyName) + , fFamilyName(std::move(familyName)) , fFontData(nullptr) {} - SkTypeface_FCI(std::unique_ptr data, SkFontStyle style, bool isFixedPitch) + SkTypeface_FCI(std::unique_ptr data, + SkString familyName, SkFontStyle style, bool isFixedPitch) : INHERITED(style, isFixedPitch) + , fFamilyName(std::move(familyName)) , fFontData(std::move(data)) { SkASSERT(fFontData); diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index 4795ba5..81c4868 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -211,14 +211,15 @@ protected: } // TODO should the caller give us the style or should we get it from freetype? + SkString name; SkFontStyle style; bool isFixedPitch = false; - if (!fScanner.scanFont(stream.get(), 0, nullptr, &style, &isFixedPitch, nullptr)) { + if (!fScanner.scanFont(stream.get(), 0, &name, &style, &isFixedPitch, nullptr)) { return nullptr; } auto fontData = skstd::make_unique(std::move(stream), ttcIndex, nullptr, 0); - return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); + return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch); } SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override { @@ -251,7 +252,7 @@ protected: params.getCollectionIndex(), axisValues.get(), axisDefinitions.count()); - return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); + return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch); } SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override { @@ -284,7 +285,7 @@ protected: // Check if a typeface with this FontIdentity is already in the FontIdentity cache. face = fTFCache.findByProcAndRef(find_by_FontIdentity, &identity); if (!face) { - face = SkTypeface_FCI::Create(fFCI, identity, outFamilyName, outStyle); + face = SkTypeface_FCI::Create(fFCI, identity, std::move(outFamilyName), outStyle); // Add this FontIdentity to the FontIdentity cache. fTFCache.add(face); } diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index 0fe352a..63d720b 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -406,13 +406,15 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) { class SkTypeface_stream : public SkTypeface_FreeType { public: /** @param data takes ownership of the font data.*/ - SkTypeface_stream(std::unique_ptr data, const SkFontStyle& style, bool fixedWidth) + SkTypeface_stream(std::unique_ptr data, + SkString familyName, const SkFontStyle& style, bool fixedWidth) : INHERITED(style, fixedWidth) + , fFamilyName(std::move(familyName)) , fData(std::move(data)) { } void onGetFamilyName(SkString* familyName) const override { - familyName->reset(); + *familyName = fFamilyName; } void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override { @@ -429,6 +431,7 @@ public: } private: + SkString fFamilyName; const std::unique_ptr fData; typedef SkTypeface_FreeType INHERITED; @@ -885,14 +888,15 @@ protected: return nullptr; } + SkString name; SkFontStyle style; bool isFixedWidth = false; - if (!fScanner.scanFont(stream.get(), ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) { + if (!fScanner.scanFont(stream.get(), ttcIndex, &name, &style, &isFixedWidth, nullptr)) { return nullptr; } auto data = skstd::make_unique(std::move(stream), ttcIndex, nullptr, 0); - return new SkTypeface_stream(std::move(data), style, isFixedWidth); + return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth); } SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override { @@ -915,7 +919,7 @@ protected: auto data = skstd::make_unique(std::move(stream), params.getCollectionIndex(), axisValues.get(), axisDefinitions.count()); - return new SkTypeface_stream(std::move(data), style, isFixedPitch); + return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch); } SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { @@ -934,13 +938,14 @@ protected: } const int ttcIndex = fontData->getIndex(); + SkString name; SkFontStyle style; bool isFixedWidth = false; - if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) { + if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedWidth, nullptr)) { return nullptr; } - return new SkTypeface_stream(std::move(fontData), style, isFixedWidth); + return new SkTypeface_stream(std::move(fontData), std::move(name), style, isFixedWidth); } SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override { -- 2.7.4