diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index bf5820945f4566..0bcd7f45b80bc9 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -1884,6 +1884,8 @@ config("default_warnings") { # TODO(https://crbug.com/1490607): Fix and re-enable. "-Wno-thread-safety-reference-return", + + "-Wno-c++11-narrowing-const-reference", ] } } diff --git a/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.h b/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.h index 2345ef0c9bfb35..f05255bae76483 100644 --- a/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.h +++ b/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.h @@ -56,6 +56,12 @@ base::apple::ScopedCFTypeRef MatchSystemUIFont( // Converts a blink::FontSelectionValue to the nearest AppKit font weight if // possible, otherwise returns the default font weight. int ToAppKitFontWeight(FontSelectionValue); + +PLATFORM_EXPORT +int ToCSSFontWeight(float ct_font_weight); + +float ToCTFontWeight(int css_weight); + } // namespace blink #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_MAC_FONT_MATCHER_MAC_H_ diff --git a/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm b/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm index f80070e2a1c595..321bebdf5c4ab9 100644 --- a/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm +++ b/third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm @@ -108,6 +108,22 @@ 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, std::size(ns_font_weights)); + return ns_font_weights[select_weight]; +} + } // namespace ScopedCFTypeRef MatchUniqueFont(const AtomicString& unique_font_name, @@ -145,6 +161,9 @@ void ClampVariationValuesToFontAcceptableRange( FontSelectionValue& weight, FontSelectionValue& width) { ScopedCFTypeRef all_axes(CTFontCopyVariationAxes(ct_font.get())); + if (!all_axes) { + return; + } for (CFIndex i = 0; i < CFArrayGetCount(all_axes.get()); ++i) { CFDictionaryRef axis = base::apple::CFCast( CFArrayGetValueAtIndex(all_axes.get(), i));