Center distiller results on desktop
[chromium-blink-merge.git] / ui / gfx / platform_font_mac.h
blob54c97cd7929eee3fc55b95191f82d40e617e033e
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_PLATFORM_FONT_MAC_H_
6 #define UI_GFX_PLATFORM_FONT_MAC_H_
8 #include "base/compiler_specific.h"
9 #include "base/mac/scoped_nsobject.h"
10 #include "ui/gfx/font_render_params.h"
11 #include "ui/gfx/platform_font.h"
13 namespace gfx {
15 class PlatformFontMac : public PlatformFont {
16 public:
17 PlatformFontMac();
18 explicit PlatformFontMac(NativeFont native_font);
19 PlatformFontMac(const std::string& font_name,
20 int font_size);
22 // Overridden from PlatformFont:
23 Font DeriveFont(int size_delta, int style) const override;
24 int GetHeight() const override;
25 int GetBaseline() const override;
26 int GetCapHeight() const override;
27 int GetExpectedTextWidth(int length) const override;
28 int GetStyle() const override;
29 std::string GetFontName() const override;
30 std::string GetActualFontNameForTesting() const override;
31 int GetFontSize() const override;
32 const FontRenderParams& GetFontRenderParams() override;
33 NativeFont GetNativeFont() const override;
35 private:
36 PlatformFontMac(const std::string& font_name, int font_size, int font_style);
37 ~PlatformFontMac() override;
39 // Calculates and caches the font metrics and inits |render_params_|.
40 void CalculateMetricsAndInitRenderParams();
42 // The NSFont instance for this object. If this object was constructed from an
43 // NSFont instance, this holds that NSFont instance. Otherwise this NSFont
44 // instance is constructed from the name, size, and style, and if there is no
45 // active font that matched those criteria, this object may be nil.
46 base::scoped_nsobject<NSFont> native_font_;
48 // The name/size/style trio that specify the font. Initialized in the
49 // constructors.
50 std::string font_name_; // Corresponds to -[NSFont fontFamily].
51 int font_size_;
52 int font_style_;
54 // Cached metrics, generated in CalculateMetrics().
55 int height_;
56 int ascent_;
57 int cap_height_;
58 int average_width_;
60 // Details about how the font should be rendered.
61 FontRenderParams render_params_;
63 DISALLOW_COPY_AND_ASSIGN(PlatformFontMac);
66 } // namespace gfx
68 #endif // UI_GFX_PLATFORM_FONT_MAC_H_