Commit 7cbdf7c9 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Test for font family on mac using NSFontManager::availableFontsForFamily

On Mac OS 10.15 Catalina, NSFontManager::availableFamilies does not list
"Hiragino Kaku Gothic ProN" any more but only lists it as "Hiragino
Sans". However, NSFontManager::availableFontsForFamily still shows
results when searching for this name. Use this as a workaround for
finding a result for the standard "sans-serif" Japanese font that is
stored in the preferences, which is "Hiragino Kaku Gothic ProN", until
we update this font matching code to be only CoreText based.

Since the previous code mentions enumerating families being essential
for performing case-insensitive comparisons, add a test to ensure that
the new API actually performs case-insensitive matches on all Mac OS
versions (at this point back to 10.10) that we support.

Bug: 1000542
Change-Id: I43aac2ce74cdc40a50d11ff075bad71a7e7a5d38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872055
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarBen Wagner <bungeman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708317}
parent f116c65c
...@@ -194,16 +194,19 @@ NSFont* MatchNSFontFamily(const AtomicString& desired_family_string, ...@@ -194,16 +194,19 @@ NSFont* MatchNSFontFamily(const AtomicString& desired_family_string,
NSString* desired_family = desired_family_string; NSString* desired_family = desired_family_string;
NSFontManager* font_manager = [NSFontManager sharedFontManager]; NSFontManager* font_manager = [NSFontManager sharedFontManager];
// Do a simple case insensitive search for a matching font family. // From Mac OS 10.15 [NSFontManager availableFonts] does not list certain
// NSFontManager requires exact name matches. // fonts that availableMembersOfFontFamily actually shows results for, for
// This addresses the problem of matching arial to Arial, etc., but perhaps // example "Hiragino Kaku Gothic ProN" is not listed, only Hiragino Sans is
// not all the issues. // listed. We previously enumerated availableFontFamilies and looked for a
NSEnumerator* e = [[font_manager availableFontFamilies] objectEnumerator]; // case-insensitive string match here, but instead, we can rely on
NSString* available_family; // availableMembersOfFontFamily here to do a case-insensitive comparison, then
while ((available_family = [e nextObject])) { // set available_family to desired_family if the result was not empty.
if ([desired_family caseInsensitiveCompare:available_family] == // See https://crbug.com/1000542
NSOrderedSame) NSString* available_family = nil;
break; NSArray* fonts_in_family =
[font_manager availableMembersOfFontFamily:desired_family];
if (fonts_in_family && [fonts_in_family count]) {
available_family = desired_family;
} }
int app_kit_font_weight = ToAppKitFontWeight(desired_weight); int app_kit_font_weight = ToAppKitFontWeight(desired_weight);
......
...@@ -144,6 +144,10 @@ crbug.com/1012590 [ Linux ] fast/overflow/rtl-scrollbar-drag-origin.html [ WontF ...@@ -144,6 +144,10 @@ crbug.com/1012590 [ Linux ] fast/overflow/rtl-scrollbar-drag-origin.html [ WontF
# Linux layout tests do not have a Myanmar fallback font. # Linux layout tests do not have a Myanmar fallback font.
[ Linux ] inspector-protocol/layout-fonts/fallback-myanmar.js [ WontFix ] [ Linux ] inspector-protocol/layout-fonts/fallback-myanmar.js [ WontFix ]
# Mac only test for case-insensitive font-matching.
[ Linux ] inspector-protocol/layout-fonts/mac-case-insensitive-matching.js [ WontFix ]
[ Win ] inspector-protocol/layout-fonts/mac-case-insensitive-matching.js [ WontFix ]
# Segoe UI matching is only relevant on Windows # Segoe UI matching is only relevant on Windows
[ Mac ] inspector-protocol/layout-fonts/font-weight-granularity-matching.js [ WontFix ] [ Mac ] inspector-protocol/layout-fonts/font-weight-granularity-matching.js [ WontFix ]
[ Linux ] inspector-protocol/layout-fonts/font-weight-granularity-matching.js [ WontFix ] [ Linux ] inspector-protocol/layout-fonts/font-weight-granularity-matching.js [ WontFix ]
......
(async function(testRunner) {
var page = await testRunner.createPage();
await page.loadHTML(`
<html>
<meta charset="UTF-8">
<style>
</style>
<body>
<div class="test">
<!-- Use a different font size in order to avoid caching the FontDescriptions and skipping matching. -->
<div id="mixed_case_1" style="font-family: HIragINO KakU GothiC ProN; font-size: 12px;">クローミアム</div>
<div id="mixed_case_2" style="font-family: hiRAGino kAKu gOTHIc pROn; font-size: 13px;">クローミアム</div>
<div id="all_lower_case" style="font-family: hiragino kaku gothic pron; font-size: 14px;">クローミアム</div>
<div id="all_upper_case" style="font-family: HIRAGINO KAKU GOTHIC PRON; font-size: 15px;">クローミアム</div>
<div id="exact_case" style="font-family: Hiragino Kaku Gothic ProN; font-size: 16px;">クローミアム</div>
</div>
</body>
</html>
`);
var session = await page.createSession();
testRunner.log('Test passes if each of the test divs uses the Hiragino Kaku Gothic ProN ' +
'independently of capitalization of the font family name..');
var helper = await testRunner.loadScript('./resources/layout-font-test.js');
var results = await helper(testRunner, session);
var passed = results.length == 5;
const reduce_match_regexp = (passed, currentValue) => {
var current_value_passes = /Hiragino Kaku Gothic ProN/.test(currentValue.usedFonts[0].familyName)
&& currentValue.usedFonts[0].glyphCount == 6;
return passed && current_value_passes;
}
passed = passed && results.reduce(reduce_match_regexp);
testRunner.log(passed ? 'PASS' : 'FAIL');
testRunner.completeTest();
})
Test passes if each of the test divs uses the Hiragino Kaku Gothic ProN independently of capitalization of the font family name..
クローミアム
#mixed_case_1:
"Hiragino Kaku Gothic ProN" : 6
クローミアム
#mixed_case_2:
"Hiragino Kaku Gothic ProN" : 6
クローミアム
#all_lower_case:
"Hiragino Kaku Gothic ProN" : 6
クローミアム
#all_upper_case:
"Hiragino Kaku Gothic ProN" : 6
クローミアム
#exact_case:
"Hiragino Kaku Gothic ProN" : 6
PASS
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