Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ FILE: ../../../flutter/third_party/txt/src/minikin/WordBreaker.cpp
FILE: ../../../flutter/third_party/txt/src/minikin/WordBreaker.h
FILE: ../../../flutter/third_party/txt/src/txt/asset_font_manager.cc
FILE: ../../../flutter/third_party/txt/src/txt/asset_font_manager.h
FILE: ../../../flutter/third_party/txt/src/txt/font_asset_provider.cc
FILE: ../../../flutter/third_party/txt/src/txt/font_asset_provider.h
FILE: ../../../flutter/third_party/txt/src/txt/font_collection.cc
FILE: ../../../flutter/third_party/txt/src/txt/font_collection.h
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/text/asset_manager_font_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ std::string AssetManagerFontProvider::GetFamilyName(int index) const {
// |FontAssetProvider|
SkFontStyleSet* AssetManagerFontProvider::MatchFamily(
const std::string& family_name) {
auto found = registered_families_.find(family_name);
auto found = registered_families_.find(CanonicalFamilyName(family_name));
if (found == registered_families_.end()) {
return nullptr;
}
Expand All @@ -49,13 +49,14 @@ SkFontStyleSet* AssetManagerFontProvider::MatchFamily(

void AssetManagerFontProvider::RegisterAsset(std::string family_name,
std::string asset) {
auto family_it = registered_families_.find(family_name);
std::string canonical_name = CanonicalFamilyName(family_name);
auto family_it = registered_families_.find(canonical_name);

if (family_it == registered_families_.end()) {
family_names_.push_back(family_name);
family_it = registered_families_
.emplace(std::piecewise_construct,
std::forward_as_tuple(family_name),
std::forward_as_tuple(canonical_name),
std::forward_as_tuple(asset_manager_))
.first;
}
Expand Down
1 change: 1 addition & 0 deletions third_party/txt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ source_set("txt") {
"src/minikin/WordBreaker.h",
"src/txt/asset_font_manager.cc",
"src/txt/asset_font_manager.h",
"src/txt/font_asset_provider.cc",
"src/txt/font_asset_provider.h",
"src/txt/font_collection.cc",
"src/txt/font_collection.h",
Expand Down
36 changes: 36 additions & 0 deletions third_party/txt/src/txt/font_asset_provider.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <algorithm>
#include <string>

#include "txt/font_asset_provider.h"

namespace txt {

// Return a canonicalized version of a family name that is suitable for
// matching.
std::string FontAssetProvider::CanonicalFamilyName(std::string family_name) {
std::string result(family_name.length(), 0);

// Convert ASCII characters to lower case.
std::transform(family_name.begin(), family_name.end(), result.begin(),
[](char c) { return (c & 0x80) ? c : ::tolower(c); });

return result;
}

} // namespace txt
3 changes: 3 additions & 0 deletions third_party/txt/src/txt/font_asset_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ 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;

protected:
static std::string CanonicalFamilyName(std::string family_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this method implemented? I don't seem to see it anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to add that file - PTAL

};

} // namespace txt
Expand Down
7 changes: 4 additions & 3 deletions third_party/txt/src/txt/typeface_font_asset_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::string TypefaceFontAssetProvider::GetFamilyName(int index) const {
// |FontAssetProvider|
SkFontStyleSet* TypefaceFontAssetProvider::MatchFamily(
const std::string& family_name) {
auto found = registered_families_.find(family_name);
auto found = registered_families_.find(CanonicalFamilyName(family_name));
if (found == registered_families_.end()) {
return nullptr;
}
Expand All @@ -65,12 +65,13 @@ void TypefaceFontAssetProvider::RegisterTypeface(
return;
}

auto family_it = registered_families_.find(family_name_alias);
std::string canonical_name = CanonicalFamilyName(family_name_alias);
auto family_it = registered_families_.find(canonical_name);
if (family_it == registered_families_.end()) {
family_names_.push_back(family_name_alias);
family_it = registered_families_
.emplace(std::piecewise_construct,
std::forward_as_tuple(family_name_alias),
std::forward_as_tuple(canonical_name),
std::forward_as_tuple())
.first;
}
Expand Down