summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/fonts/mac
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/fonts/mac')
-rw-r--r--chromium/third_party/blink/renderer/platform/fonts/mac/font_cache_mac.mm8
-rw-r--r--chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm75
-rw-r--r--chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac_test.mm16
-rw-r--r--chromium/third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac_test.mm19
4 files changed, 39 insertions, 79 deletions
diff --git a/chromium/third_party/blink/renderer/platform/fonts/mac/font_cache_mac.mm b/chromium/third_party/blink/renderer/platform/fonts/mac/font_cache_mac.mm
index 1671d612dd0..fb5629f9596 100644
--- a/chromium/third_party/blink/renderer/platform/fonts/mac/font_cache_mac.mm
+++ b/chromium/third_party/blink/renderer/platform/fonts/mac/font_cache_mac.mm
@@ -140,16 +140,14 @@ scoped_refptr<SimpleFontData> FontCache::PlatformFallbackFontForCharacter(
font_data_to_substitute->PlatformData();
NSFont* ns_font = base::mac::CFToNSCast(platform_data.CtFont());
- NSString* string =
- [[NSString alloc] initWithCharactersNoCopy:code_units
- length:code_units_length
- freeWhenDone:NO];
+ NSString* string = [[[NSString alloc]
+ initWithCharacters:reinterpret_cast<UniChar*>(code_units)
+ length:code_units_length] autorelease];
NSFont* substitute_font =
[NSFont findFontLike:ns_font
forString:string
withRange:NSMakeRange(0, code_units_length)
inLanguage:nil];
- [string release];
// FIXME: Remove this SPI usage: http://crbug.com/255122
if (!substitute_font && code_units_length == 1)
diff --git a/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm b/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm
index aafddac6d3b..7144caba9ef 100644
--- a/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm
+++ b/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm
@@ -33,7 +33,6 @@
#import <Foundation/Foundation.h>
#import <math.h>
-#include "base/bit_cast.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/mac/scoped_nsobject.h"
@@ -42,37 +41,10 @@
#import "third_party/blink/renderer/platform/wtf/hash_set.h"
#import "third_party/blink/renderer/platform/wtf/text/atomic_string_hash.h"
-@interface NSFont (YosemiteAdditions)
-+ (NSFont*)systemFontOfSize:(CGFloat)size weight:(CGFloat)weight;
-@end
+namespace blink {
namespace {
-static CGFloat toFontWeight(blink::FontSelectionValue font_weight) {
- static uint64_t ns_font_weights[] = {
- 0xbfe99999a0000000, // NSFontWeightUltraLight
- 0xbfe3333340000000, // NSFontWeightThin
- 0xbfd99999a0000000, // NSFontWeightLight
- 0x0000000000000000, // NSFontWeightRegular
- 0x3fcd70a3e0000000, // NSFontWeightMedium
- 0x3fd3333340000000, // NSFontWeightSemibold
- 0x3fd99999a0000000, // NSFontWeightBold
- 0x3fe1eb8520000000, // NSFontWeightHeavy
- 0x3fe3d70a40000000, // NSFontWeightBlack
- };
- if (font_weight <= 50 || font_weight >= 950)
- return bit_cast<CGFloat>(ns_font_weights[3]);
-
- size_t select_weight = roundf(font_weight / 100) - 1;
- DCHECK_GE(select_weight, 0ul);
- DCHECK_LE(select_weight, base::size(ns_font_weights));
- return bit_cast<CGFloat>(ns_font_weights[select_weight]);
-}
-
-} // namespace
-
-namespace blink {
-
const NSFontTraitMask SYNTHESIZED_FONT_TRAITS =
(NSBoldFontMask | NSItalicFontMask);
@@ -81,18 +53,18 @@ const NSFontTraitMask IMPORTANT_FONT_TRAITS =
NSItalicFontMask | NSNarrowFontMask | NSPosterFontMask |
NSSmallCapsFontMask);
-static BOOL AcceptableChoice(NSFontTraitMask desired_traits,
- NSFontTraitMask candidate_traits) {
+BOOL AcceptableChoice(NSFontTraitMask desired_traits,
+ NSFontTraitMask candidate_traits) {
desired_traits &= ~SYNTHESIZED_FONT_TRAITS;
return (candidate_traits & desired_traits) == desired_traits;
}
-static BOOL BetterChoice(NSFontTraitMask desired_traits,
- int desired_weight,
- NSFontTraitMask chosen_traits,
- int chosen_weight,
- NSFontTraitMask candidate_traits,
- int candidate_weight) {
+BOOL BetterChoice(NSFontTraitMask desired_traits,
+ int desired_weight,
+ NSFontTraitMask chosen_traits,
+ int chosen_weight,
+ NSFontTraitMask candidate_traits,
+ int candidate_weight) {
if (!AcceptableChoice(desired_traits, candidate_traits))
return NO;
@@ -129,6 +101,23 @@ static BOOL BetterChoice(NSFontTraitMask desired_traits,
return candidate_weight_delta_magnitude < chosen_weight_delta_magnitude;
}
+NSFontWeight ToFontWeight(blink::FontSelectionValue font_weight) {
+ if (font_weight <= 50 || font_weight >= 950)
+ return NSFontWeightRegular;
+
+ const NSFontWeight ns_font_weights[] = {
+ NSFontWeightUltraLight, NSFontWeightThin, NSFontWeightLight,
+ NSFontWeightRegular, NSFontWeightMedium, NSFontWeightSemibold,
+ NSFontWeightBold, NSFontWeightHeavy, NSFontWeightBlack,
+ };
+ size_t select_weight = roundf(font_weight / 100) - 1;
+ DCHECK_GE(select_weight, 0ul);
+ DCHECK_LE(select_weight, base::size(ns_font_weights));
+ return ns_font_weights[select_weight];
+}
+
+} // namespace
+
NSFont* MatchUniqueFont(const AtomicString& unique_font_name, float size) {
// Testing with a large list of fonts available on Mac OS shows that matching
// for kCTFontNameAttribute matches postscript name as well as full font name.
@@ -175,16 +164,8 @@ NSFont* MatchNSFontFamily(const AtomicString& desired_family_string,
DCHECK_NE(desired_family_string, FontCache::LegacySystemFontFamily());
if (desired_family_string == font_family_names::kSystemUi) {
- NSFont* font = nil;
-// Normally we'd use an availability macro here, but
-// systemFontOfSize:weight: is available but not visible on macOS 10.10,
-// so it's been forward declared earlier in this file.
-// On OSX 10.10+, the default system font has more weights.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunguarded-availability"
- font = [NSFont systemFontOfSize:size weight:toFontWeight(desired_weight)];
-#pragma clang diagnostic pop
-
+ NSFont* font = [NSFont systemFontOfSize:size
+ weight:ToFontWeight(desired_weight)];
if (desired_traits & IMPORTANT_FONT_TRAITS)
font = [[NSFontManager sharedFontManager] convertFont:font
toHaveTrait:desired_traits];
diff --git a/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac_test.mm b/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac_test.mm
index 0636b18ae4b..c3c3e678de9 100644
--- a/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac_test.mm
+++ b/chromium/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac_test.mm
@@ -6,7 +6,6 @@
#include <AppKit/AppKit.h>
-#include "base/mac/mac_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/font_family_names.h"
@@ -19,21 +18,6 @@ void TestSystemFontContainsString(FontSelectionValue desired_weight,
EXPECT_TRUE([font.description containsString:substring]);
}
-TEST(FontMatcherMacTest, YosemiteFontWeights) {
- if (!base::mac::IsOS10_10())
- return;
-
- TestSystemFontContainsString(FontSelectionValue(100), @"-UltraLight");
- TestSystemFontContainsString(FontSelectionValue(200), @"-Thin");
- TestSystemFontContainsString(FontSelectionValue(300), @"-Light");
- TestSystemFontContainsString(FontSelectionValue(400), @"-Regular");
- TestSystemFontContainsString(FontSelectionValue(500), @"-Medium");
- TestSystemFontContainsString(FontSelectionValue(600), @"-Bold");
- TestSystemFontContainsString(FontSelectionValue(700), @"-Bold");
- TestSystemFontContainsString(FontSelectionValue(800), @"-Heavy");
- TestSystemFontContainsString(FontSelectionValue(900), @"-Heavy");
-}
-
TEST(FontMatcherMacTest, NoUniqueFontMatchOnUnavailableFont) {
NSFont* font = MatchUniqueFont(
"ThisFontNameDoesNotExist07F444B9-4DDF-4A41-8F30-C80D4ED4CCA2", 12);
diff --git a/chromium/third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac_test.mm b/chromium/third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac_test.mm
index 018743cf00d..e8a32bd8bbd 100644
--- a/chromium/third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac_test.mm
+++ b/chromium/third_party/blink/renderer/platform/fonts/mac/font_platform_data_mac_test.mm
@@ -7,7 +7,6 @@
#include "third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.h"
#include "base/mac/foundation_util.h"
-#include "base/mac/mac_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/font_family_names.h"
@@ -33,9 +32,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
// Below the 11.0 axis minimum.
sk_sp<SkTypeface> system_font(MakeSystemFontOfSize(12));
- // TODO(https://crbug.com/1115294, https://crbug.com/1105187): Switch back to
- // @available when it works.
- if (base::mac::IsOS11()) {
+ if (@available(macOS 11.0, *)) {
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -48,7 +45,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 72));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 96));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 97));
- } else if (base::mac::IsOS10_15()) {
+ } else if (@available(macOS 10.15, *)) {
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -78,7 +75,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
// Just smaller than the switch-over size in 10.15, which is 19.9.
system_font = MakeSystemFontOfSize(19);
- if (base::mac::IsOS11()) {
+ if (@available(macOS 11.0, *)) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -91,7 +88,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 72));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 96));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 97));
- } else if (base::mac::IsOS10_15()) {
+ } else if (@available(macOS 10.15, *)) {
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -121,7 +118,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
// Just larger than the switch-over size in 10.15, which is 19.9.
system_font = MakeSystemFontOfSize(20);
- if (base::mac::IsOS11()) {
+ if (@available(macOS 11.0, *)) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -134,7 +131,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 72));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 96));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 97));
- } else if (base::mac::IsOS10_15()) {
+ } else if (@available(macOS 10.15, *)) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -164,7 +161,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
// Above the 11.0 axis maximum.
system_font = MakeSystemFontOfSize(128);
- if (base::mac::IsOS11()) {
+ if (@available(macOS 11.0, *)) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));
@@ -177,7 +174,7 @@ TEST(FontPlatformDataMacTest, VariableOpticalSizingThreshold) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 72));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 96));
EXPECT_FALSE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 97));
- } else if (base::mac::IsOS10_15()) {
+ } else if (@available(macOS 10.15, *)) {
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 6));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 12));
EXPECT_TRUE(VariableAxisChangeEffective(system_font.get(), kOpszTag, 17));