From 8cd1e22f8dc624deb80de9a730a21ef8d8cc503e Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:53:41 +0200 Subject: [PATCH] android/ohos: fonts: Ignore ascii case when searching for font family (#32725) The input for this function commonly comes from a `LowercaseString`, while our actual font family name has cases. Since font family lookup should be case-neutral, we do a compare ignoring the ascii case. I'm not too familiar with the CSS standard so I'm not 100% sure if this is sufficient, or if we need to use a different method to compare strings for arbitrary non-ascii font names. Signed-off-by: Jonathan Schwender --- components/fonts/platform/freetype/android/font_list.rs | 8 ++++++-- components/fonts/platform/freetype/ohos/font_list.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/components/fonts/platform/freetype/android/font_list.rs b/components/fonts/platform/freetype/android/font_list.rs index 3343c7c3788..0fd0c336487 100644 --- a/components/fonts/platform/freetype/android/font_list.rs +++ b/components/fonts/platform/freetype/android/font_list.rs @@ -259,11 +259,15 @@ impl FontList { } fn find_family(&self, name: &str) -> Option<&FontFamily> { - self.families.iter().find(|f| f.name == name) + self.families + .iter() + .find(|family| family.name.eq_ignore_ascii_case(name)) } fn find_alias(&self, name: &str) -> Option<&FontAlias> { - self.aliases.iter().find(|f| f.from == name) + self.aliases + .iter() + .find(|family| family.from.eq_ignore_ascii_case(name)) } // Parse family and font file names diff --git a/components/fonts/platform/freetype/ohos/font_list.rs b/components/fonts/platform/freetype/ohos/font_list.rs index f4d9ec6200a..819535a618d 100644 --- a/components/fonts/platform/freetype/ohos/font_list.rs +++ b/components/fonts/platform/freetype/ohos/font_list.rs @@ -108,11 +108,15 @@ impl FontList { } fn find_family(&self, name: &str) -> Option<&FontFamily> { - self.families.iter().find(|f| f.name == name) + self.families + .iter() + .find(|family| family.name.eq_ignore_ascii_case(name)) } fn find_alias(&self, name: &str) -> Option<&FontAlias> { - self.aliases.iter().find(|f| f.from == name) + self.aliases + .iter() + .find(|family| family.from.eq_ignore_ascii_case(name)) } }