diff --git a/lib/ui/text/asset_manager_font_provider.cc b/lib/ui/text/asset_manager_font_provider.cc index 2975406ceda28..92f9b88c55bf6 100644 --- a/lib/ui/text/asset_manager_font_provider.cc +++ b/lib/ui/text/asset_manager_font_provider.cc @@ -40,14 +40,13 @@ std::string AssetManagerFontProvider::GetFamilyName(int index) const { } // |FontAssetProvider| -SkFontStyleSet* AssetManagerFontProvider::MatchFamily( +sk_sp AssetManagerFontProvider::MatchFamily( const std::string& family_name) { auto found = registered_families_.find(CanonicalFamilyName(family_name)); if (found == registered_families_.end()) { return nullptr; } - sk_sp font_style_set = found->second; - return font_style_set.release(); + return found->second; } void AssetManagerFontProvider::RegisterAsset(const std::string& family_name, diff --git a/lib/ui/text/asset_manager_font_provider.h b/lib/ui/text/asset_manager_font_provider.h index 759ddcc924b76..6ff5322c7548d 100644 --- a/lib/ui/text/asset_manager_font_provider.h +++ b/lib/ui/text/asset_manager_font_provider.h @@ -78,7 +78,7 @@ class AssetManagerFontProvider : public txt::FontAssetProvider { std::string GetFamilyName(int index) const override; // |FontAssetProvider| - SkFontStyleSet* MatchFamily(const std::string& family_name) override; + sk_sp MatchFamily(const std::string& family_name) override; private: std::shared_ptr asset_manager_; diff --git a/third_party/txt/src/txt/asset_font_manager.cc b/third_party/txt/src/txt/asset_font_manager.cc index 593a9bde3bd98..c9952e85e8dad 100644 --- a/third_party/txt/src/txt/asset_font_manager.cc +++ b/third_party/txt/src/txt/asset_font_manager.cc @@ -40,34 +40,33 @@ void AssetFontManager::onGetFamilyName(int index, SkString* familyName) const { familyName->set(font_provider_->GetFamilyName(index).c_str()); } -auto AssetFontManager::onCreateStyleSet(int index) const - -> OnCreateStyleSetRet { +sk_sp AssetFontManager::onCreateStyleSet(int index) const { FML_DCHECK(false); return nullptr; } -auto AssetFontManager::onMatchFamily(const char family_name_string[]) const - -> OnMatchFamilyRet { +sk_sp AssetFontManager::onMatchFamily( + const char family_name_string[]) const { std::string family_name(family_name_string); - return OnMatchFamilyRet(font_provider_->MatchFamily(family_name)); + return font_provider_->MatchFamily(family_name); } -auto AssetFontManager::onMatchFamilyStyle(const char familyName[], - const SkFontStyle& style) const - -> OnMatchFamilyStyleRet { - SkFontStyleSet* font_style_set = +sk_sp AssetFontManager::onMatchFamilyStyle( + const char familyName[], + const SkFontStyle& style) const { + sk_sp font_style_set = font_provider_->MatchFamily(std::string(familyName)); if (font_style_set == nullptr) return nullptr; return font_style_set->matchStyle(style); } -auto AssetFontManager::onMatchFamilyStyleCharacter(const char familyName[], - const SkFontStyle&, - const char* bcp47[], - int bcp47Count, - SkUnichar character) const - -> OnMatchFamilyStyleCharacterRet { +sk_sp AssetFontManager::onMatchFamilyStyleCharacter( + const char familyName[], + const SkFontStyle&, + const char* bcp47[], + int bcp47Count, + SkUnichar character) const { return nullptr; } diff --git a/third_party/txt/src/txt/asset_font_manager.h b/third_party/txt/src/txt/asset_font_manager.h index cc7692ed51a2d..cc1c92711e793 100644 --- a/third_party/txt/src/txt/asset_font_manager.h +++ b/third_party/txt/src/txt/asset_font_manager.h @@ -36,10 +36,7 @@ class AssetFontManager : public SkFontMgr { protected: // |SkFontMgr| - using OnMatchFamilyRet = - decltype((std::declval().* - (&AssetFontManager::onMatchFamily))(std::declval())); - OnMatchFamilyRet onMatchFamily(const char familyName[]) const override; + sk_sp onMatchFamily(const char familyName[]) const override; std::unique_ptr font_provider_; @@ -51,28 +48,14 @@ class AssetFontManager : public SkFontMgr { void onGetFamilyName(int index, SkString* familyName) const override; // |SkFontMgr| - using OnCreateStyleSetRet = decltype(( - std::declval().*(&AssetFontManager::onCreateStyleSet))(0)); - OnCreateStyleSetRet onCreateStyleSet(int index) const override; + sk_sp onCreateStyleSet(int index) const override; // |SkFontMgr| - using OnMatchFamilyStyleRet = decltype(( - std::declval().*(&AssetFontManager::onMatchFamilyStyle))( - std::declval(), - std::declval())); - OnMatchFamilyStyleRet onMatchFamilyStyle(const char familyName[], - const SkFontStyle&) const override; + sk_sp onMatchFamilyStyle(const char familyName[], + const SkFontStyle&) const override; // |SkFontMgr| - using OnMatchFamilyStyleCharacterRet = - decltype((std::declval().* - (&AssetFontManager::onMatchFamilyStyleCharacter))( - std::declval(), - std::declval(), - std::declval(), - 0, - 0)); - OnMatchFamilyStyleCharacterRet onMatchFamilyStyleCharacter( + sk_sp onMatchFamilyStyleCharacter( const char familyName[], const SkFontStyle&, const char* bcp47[], diff --git a/third_party/txt/src/txt/font_asset_provider.h b/third_party/txt/src/txt/font_asset_provider.h index 45a076293aa2c..f43aacd68bb02 100644 --- a/third_party/txt/src/txt/font_asset_provider.h +++ b/third_party/txt/src/txt/font_asset_provider.h @@ -29,7 +29,7 @@ class FontAssetProvider { virtual size_t GetFamilyCount() const = 0; virtual std::string GetFamilyName(int index) const = 0; - virtual SkFontStyleSet* MatchFamily(const std::string& family_name) = 0; + virtual sk_sp MatchFamily(const std::string& family_name) = 0; protected: static std::string CanonicalFamilyName(std::string family_name); diff --git a/third_party/txt/src/txt/test_font_manager.cc b/third_party/txt/src/txt/test_font_manager.cc index 5a072ba9f087f..4fe5e33e0ef35 100644 --- a/third_party/txt/src/txt/test_font_manager.cc +++ b/third_party/txt/src/txt/test_font_manager.cc @@ -27,8 +27,8 @@ TestFontManager::TestFontManager( TestFontManager::~TestFontManager() = default; -auto TestFontManager::onMatchFamily(const char family_name[]) const - -> OnMatchFamilyRet { +sk_sp TestFontManager::onMatchFamily( + const char family_name[]) const { // Find the requested name in the list, if not found, default to the first // font family in the test font family list. std::string requested_name(family_name); diff --git a/third_party/txt/src/txt/test_font_manager.h b/third_party/txt/src/txt/test_font_manager.h index cc6b8d0a846d6..ffd1d566604d1 100644 --- a/third_party/txt/src/txt/test_font_manager.h +++ b/third_party/txt/src/txt/test_font_manager.h @@ -40,10 +40,7 @@ class TestFontManager : public AssetFontManager { private: std::vector test_font_family_names_; - using OnMatchFamilyRet = - decltype((std::declval().* - (&TestFontManager::onMatchFamily))(std::declval())); - OnMatchFamilyRet onMatchFamily(const char family_name[]) const override; + sk_sp onMatchFamily(const char family_name[]) const override; FML_DISALLOW_COPY_AND_ASSIGN(TestFontManager); }; diff --git a/third_party/txt/src/txt/typeface_font_asset_provider.cc b/third_party/txt/src/txt/typeface_font_asset_provider.cc index 48e8837a0ba01..a43acdd60bcee 100644 --- a/third_party/txt/src/txt/typeface_font_asset_provider.cc +++ b/third_party/txt/src/txt/typeface_font_asset_provider.cc @@ -37,14 +37,13 @@ std::string TypefaceFontAssetProvider::GetFamilyName(int index) const { } // |FontAssetProvider| -SkFontStyleSet* TypefaceFontAssetProvider::MatchFamily( +sk_sp TypefaceFontAssetProvider::MatchFamily( const std::string& family_name) { auto found = registered_families_.find(CanonicalFamilyName(family_name)); if (found == registered_families_.end()) { return nullptr; } - sk_sp font_style_set = found->second; - return font_style_set.release(); + return found->second; } void TypefaceFontAssetProvider::RegisterTypeface(sk_sp typeface) { @@ -104,16 +103,15 @@ void TypefaceFontStyleSet::getStyle(int index, } } -auto TypefaceFontStyleSet::createTypeface(int i) -> CreateTypefaceRet { +sk_sp TypefaceFontStyleSet::createTypeface(int i) { size_t index = i; if (index >= typefaces_.size()) { return nullptr; } - return CreateTypefaceRet(SkRef(typefaces_[index].get())); + return typefaces_[index]; } -auto TypefaceFontStyleSet::matchStyle(const SkFontStyle& pattern) - -> MatchStyleRet { +sk_sp TypefaceFontStyleSet::matchStyle(const SkFontStyle& pattern) { return matchStyleCSS3(pattern); } diff --git a/third_party/txt/src/txt/typeface_font_asset_provider.h b/third_party/txt/src/txt/typeface_font_asset_provider.h index 246162d476056..6421ad6abfca2 100644 --- a/third_party/txt/src/txt/typeface_font_asset_provider.h +++ b/third_party/txt/src/txt/typeface_font_asset_provider.h @@ -42,14 +42,10 @@ class TypefaceFontStyleSet : public SkFontStyleSet { void getStyle(int index, SkFontStyle* style, SkString* name) override; // |SkFontStyleSet| - using CreateTypefaceRet = - decltype(std::declval().createTypeface(0)); - CreateTypefaceRet createTypeface(int index) override; + sk_sp createTypeface(int index) override; // |SkFontStyleSet| - using MatchStyleRet = decltype(std::declval().matchStyle( - std::declval())); - MatchStyleRet matchStyle(const SkFontStyle& pattern) override; + sk_sp matchStyle(const SkFontStyle& pattern) override; private: std::vector> typefaces_; @@ -74,7 +70,7 @@ class TypefaceFontAssetProvider : public FontAssetProvider { std::string GetFamilyName(int index) const override; // |FontAssetProvider| - SkFontStyleSet* MatchFamily(const std::string& family_name) override; + sk_sp MatchFamily(const std::string& family_name) override; private: std::unordered_map>