Commit 7b62b986 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

[GoogleSans] Index by ICU case folded font names

Use ICU case folded full font names as keys for the font lookup table to
be consistent with the local unique name matching done by Blink for
firmware font files.

Bug: 1111148
Change-Id: Ia94b11e10ffa53582c46020eeafb5524108e9914
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2389224
Auto-Submit: Natalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804063}
parent 4875cc42
...@@ -45,9 +45,7 @@ public class AndroidFontLookupImpl implements AndroidFontLookup { ...@@ -45,9 +45,7 @@ public class AndroidFontLookupImpl implements AndroidFontLookup {
private final Context mAppContext; private final Context mAppContext;
private FontsContractWrapper mFontsContract = new FontsContractWrapper(); private FontsContractWrapper mFontsContract = new FontsContractWrapper();
/** /**
* Map from unique full font names to GMS Core font provider query format. * Map from ICU case folded full font name to GMS Core font provider query format.
*
* TODO(crbug.com/1111148): Consider using ICU-case folded names as keys instead.
*/ */
private Map<String, String> mFullFontNameToQuery = createFullFontNameToQueryMap(); private Map<String, String> mFullFontNameToQuery = createFullFontNameToQueryMap();
...@@ -139,10 +137,22 @@ public class AndroidFontLookupImpl implements AndroidFontLookup { ...@@ -139,10 +137,22 @@ public class AndroidFontLookupImpl implements AndroidFontLookup {
} }
} }
/**
* Creates the map from ICU case folded full font name to GMS Core font provider query format,
* for a selected subset of Android Downloadable fonts.
*
* Note: Because the CaseMap.Fold Java API is only available in Android API 29+, these keys have
* been manually converted from full font name (i.e. "Google Sans") to ICU case folded full font
* name using `third_party/blink/common/font_unique_name_lookup/icu_fold_case_util.cc`. When
* further map entries are added in future, consider importing ICU4J as a third_party library to
* do this case folding explicitly in Java code instead, or using the native utility via JNI.
*
* @return The created map from font names to queries.
*/
private static Map<String, String> createFullFontNameToQueryMap() { private static Map<String, String> createFullFontNameToQueryMap() {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("Google Sans", "name=Google Sans&weight=400"); map.put("google sans", "name=Google Sans&weight=400");
map.put("Google Sans Medium", "name=Google Sans&weight=500"); map.put("google sans medium", "name=Google Sans&weight=500");
return map; return map;
} }
...@@ -153,13 +163,13 @@ public class AndroidFontLookupImpl implements AndroidFontLookup { ...@@ -153,13 +163,13 @@ public class AndroidFontLookupImpl implements AndroidFontLookup {
public void onConnectionError(MojoException e) {} public void onConnectionError(MojoException e) {}
@VisibleForTesting @VisibleForTesting
void setFontsContractForTest(FontsContractWrapper mFontsContract) { void setFontsContractForTest(FontsContractWrapper fontsContract) {
this.mFontsContract = mFontsContract; mFontsContract = fontsContract;
} }
@VisibleForTesting @VisibleForTesting
void setFullFontNameToQueryMapForTest(Map<String, String> mFullFontNameToQuery) { void setFullFontNameToQueryMapForTest(Map<String, String> fullFontNameToQuery) {
this.mFullFontNameToQuery = mFullFontNameToQuery; mFullFontNameToQuery = fullFontNameToQuery;
} }
/** /**
......
...@@ -50,7 +50,7 @@ import org.chromium.mojo_base.mojom.File; ...@@ -50,7 +50,7 @@ import org.chromium.mojo_base.mojom.File;
*/ */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public final class AndroidFontLookupImplTest { public final class AndroidFontLookupImplTest {
private static final String FULL_FONT_NAME = "Foo"; private static final String FULL_FONT_NAME = "foo";
private static final String FONT_QUERY = "name=Foo&weight=400"; private static final String FONT_QUERY = "name=Foo&weight=400";
private static final String AUTHORITY = "com.google.android.gms.fonts"; private static final String AUTHORITY = "com.google.android.gms.fonts";
private static final Uri URI = Uri.parse("content://com.google.android.gms.fonts/123"); private static final Uri URI = Uri.parse("content://com.google.android.gms.fonts/123");
......
file://content/public/android/java/src/org/chromium/content/browser/font/OWNERS
...@@ -9,15 +9,15 @@ import "mojo/public/mojom/base/file.mojom"; ...@@ -9,15 +9,15 @@ import "mojo/public/mojom/base/file.mojom";
// Interface for renderer to request Android downloaded fonts from font // Interface for renderer to request Android downloaded fonts from font
// providers on-device. // providers on-device.
interface AndroidFontLookup { interface AndroidFontLookup {
// Returns a list of unique full font names available to be fetched locally // Returns a list of ICU case folded full font names available to be fetched
// from on-device storage, without a network roundtrip. // locally from on-device storage, without a network roundtrip.
// TODO(crbug.com/1111148): Complete implementation of this method in // TODO(crbug.com/1111148): Complete implementation of this method in
// AndroidFontLookupImpl.java. Currently returns empty list. // AndroidFontLookupImpl.java. Currently returns empty list.
GetUniqueNameLookupTable() GetUniqueNameLookupTable()
=> (array<string> available_unique_font_names); => (array<string> available_unique_font_names);
// Returns an opened read-only File for a font with the given unique full // Returns an opened read-only File for a font with the given ICU case folded
// font name or null if the font is not available. // full font name or null if the font is not available.
[Sync] [Sync]
MatchLocalFontByUniqueName(string font_unique_name) MatchLocalFontByUniqueName(string font_unique_name)
=> (mojo_base.mojom.File? font_file_handle); => (mojo_base.mojom.File? font_file_handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment