Commit 2f7c32d8 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Revert "Do clean up in PlatformFontMac"

This reverts commit c2e39ede.

Reason for revert: Breaks Mac builder (https://ci.chromium.org/p/chromium/builders/ci/Mac%20Builder/119092)

Original change's description:
> Do clean up in PlatformFontMac
> 
> Do not try to derive one weight of font from another.
> Use the API to directly generate them.
> 
> PlatformFontMacTest.FontWeightAPIConsistency tested that
> our understanding of shifting weights up and down was
> correct. The code no longer shifts weights up and down
> as that is unreliable and version-specific, so there is
> no need to test weight shifting and it is removed.
> 
> This also fixes Big Sur issues.
> 
> Bug: 1101426
> Change-Id: I2165c3550ad295b3ee7742f3289874ed2bb89c68
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340262
> Commit-Queue: Avi Drissman <avi@chromium.org>
> Auto-Submit: Avi Drissman <avi@chromium.org>
> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#796044}

TBR=ellyjones@chromium.org,avi@chromium.org

Change-Id: I7a7d792d80eadfab524fc7235c3b9a349a34c970
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1101426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343490Reviewed-by: default avatarDominique Fauteux-Chapleau <domfc@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796059}
parent cfbe56f1
...@@ -8,39 +8,18 @@ ...@@ -8,39 +8,18 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "ui/gfx/font_render_params.h" #include "ui/gfx/font_render_params.h"
#include "ui/gfx/platform_font.h" #include "ui/gfx/platform_font.h"
namespace gfx { namespace gfx {
class GFX_EXPORT PlatformFontMac : public PlatformFont { class PlatformFontMac : public PlatformFont {
public: public:
// An enum indicating a type of system-specified font. PlatformFontMac();
// - kGeneral: +[NSFont systemFontOfSize:(weight:)]
// - kMenu: +[NSFont menuFontOfSize:]
// - kToolTip: +[NSFont toolTipsFontOfSize:]
enum class SystemFontType { kGeneral, kMenu, kToolTip };
// Constructs a PlatformFontMac for a system-specified font of
// |system_font_type| type. For a non-system-specified font, use any other
// constructor.
explicit PlatformFontMac(SystemFontType system_font_type);
// Constructs a PlatformFontMac for containing the NSFont* |native_font|. Do
// not call this for a system-specified font; use the |SystemFontType|
// constructor for that. |native_font| must not be null.
explicit PlatformFontMac(NativeFont native_font); explicit PlatformFontMac(NativeFont native_font);
// Constructs a PlatformFontMac representing the font with name |font_name|
// and the size |font_size|. Do not call this for a system-specified font; use
// the |SystemFontType| constructor for that.
PlatformFontMac(const std::string& font_name, PlatformFontMac(const std::string& font_name,
int font_size); int font_size);
// Constructs a PlatformFontMac representing the font specified by |typeface|
// and the size |font_size_pixels|. Do not call this for a system-specified
// font; use the |SystemFontType| constructor for that.
PlatformFontMac(sk_sp<SkTypeface> typeface, PlatformFontMac(sk_sp<SkTypeface> typeface,
int font_size_pixels, int font_size_pixels,
const base::Optional<FontRenderParams>& params); const base::Optional<FontRenderParams>& params);
...@@ -62,44 +41,35 @@ class GFX_EXPORT PlatformFontMac : public PlatformFont { ...@@ -62,44 +41,35 @@ class GFX_EXPORT PlatformFontMac : public PlatformFont {
NativeFont GetNativeFont() const override; NativeFont GetNativeFont() const override;
sk_sp<SkTypeface> GetNativeSkTypeface() const override; sk_sp<SkTypeface> GetNativeSkTypeface() const override;
// A utility function to get the weight of an NSFont. Used by the unit test.
static Font::Weight GetFontWeightFromNSFontForTesting(NSFont* font);
private: private:
struct FontSpec { PlatformFontMac(const std::string& font_name,
std::string name; // Corresponds to -[NSFont fontFamily]. int font_size,
int size; int font_style,
int style; Font::Weight font_weight);
Font::Weight weight;
};
PlatformFontMac(NativeFont font,
base::Optional<SystemFontType> system_font_type);
PlatformFontMac(NativeFont font, PlatformFontMac(NativeFont font,
base::Optional<SystemFontType> system_font_type, const std::string& font_name,
FontSpec spec); int font_size,
int font_style,
Font::Weight font_weight);
~PlatformFontMac() override; ~PlatformFontMac() override;
// Calculates and caches the font metrics and initializes |render_params_|. // Calculates and caches the font metrics and inits |render_params_|.
void CalculateMetricsAndInitRenderParams(); void CalculateMetricsAndInitRenderParams();
// Returns an autoreleased NSFont created with the passed-in specifications.
NSFont* NSFontWithSpec(FontSpec font_spec) const;
// The NSFont instance for this object. If this object was constructed from an // The NSFont instance for this object. If this object was constructed from an
// NSFont instance, this holds that NSFont instance. Otherwise this NSFont // NSFont instance, this holds that NSFont instance. Otherwise this NSFont
// instance is constructed from the name, size, and style. If there is no // instance is constructed from the name, size, and style. If there is no
// active font that matched those criteria a default font is used. // active font that matched those criteria a default font is used.
base::scoped_nsobject<NSFont> native_font_; base::scoped_nsobject<NSFont> native_font_;
// If the font is a system font, and if so, what kind. // The name/size/style trio that specify the font. Initialized in the
const base::Optional<SystemFontType> system_font_type_; // constructors.
const std::string font_name_; // Corresponds to -[NSFont fontFamily].
// The name/size/style/weight quartet that specify the font. Initialized in const int font_size_;
// the constructors. const int font_style_;
const FontSpec font_spec_; const Font::Weight font_weight_;
// Cached metrics, generated in CalculateMetrics(). // Cached metrics, generated in CalculateMetrics().
int height_; int height_;
......
This diff is collapsed.
This diff is collapsed.
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "ui/base/cocoa/cocoa_base_utils.h" #include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#import "ui/gfx/mac/coordinate_conversion.h" #import "ui/gfx/mac/coordinate_conversion.h"
#include "ui/gfx/platform_font_mac.h"
namespace { namespace {
...@@ -33,10 +32,8 @@ int TooltipManagerMac::GetMaxWidth(const gfx::Point& location) const { ...@@ -33,10 +32,8 @@ int TooltipManagerMac::GetMaxWidth(const gfx::Point& location) const {
} }
const gfx::FontList& TooltipManagerMac::GetFontList() const { const gfx::FontList& TooltipManagerMac::GetFontList() const {
static base::NoDestructor<gfx::FontList> font_list([]() { static base::NoDestructor<gfx::FontList> font_list(
return gfx::Font(new gfx::PlatformFontMac( []() { return gfx::Font([NSFont toolTipsFontOfSize:0]); }());
gfx::PlatformFontMac::SystemFontType::kToolTip));
}());
return *font_list; return *font_list;
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "ui/gfx/platform_font_mac.h"
namespace { namespace {
...@@ -43,8 +42,7 @@ void InitMaterialMenuConfig(views::MenuConfig* config) { ...@@ -43,8 +42,7 @@ void InitMaterialMenuConfig(views::MenuConfig* config) {
namespace views { namespace views {
void MenuConfig::Init() { void MenuConfig::Init() {
font_list = gfx::FontList(gfx::Font( font_list = gfx::FontList(gfx::Font([NSFont menuFontOfSize:0.0]));
new gfx::PlatformFontMac(gfx::PlatformFontMac::SystemFontType::kMenu)));
check_selected_combobox_item = true; check_selected_combobox_item = true;
arrow_key_selection_wraps = false; arrow_key_selection_wraps = false;
use_mnemonics = false; use_mnemonics = false;
......
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