Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blueboxd committed Feb 9, 2024
1 parent 3487b2a commit 5385c7a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ base::apple::ScopedCFTypeRef<CTFontRef> 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_
19 changes: 19 additions & 0 deletions third_party/blink/renderer/platform/fonts/mac/font_matcher_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTFontRef> MatchUniqueFont(const AtomicString& unique_font_name,
Expand Down Expand Up @@ -145,6 +161,9 @@ void ClampVariationValuesToFontAcceptableRange(
FontSelectionValue& weight,
FontSelectionValue& width) {
ScopedCFTypeRef<CFArrayRef> 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<CFDictionaryRef>(
CFArrayGetValueAtIndex(all_axes.get(), i));
Expand Down

0 comments on commit 5385c7a

Please sign in to comment.