• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_GFX_PLATFORM_FONT_MAC_H_
6 #define UI_GFX_PLATFORM_FONT_MAC_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/mac/scoped_nsobject.h"
10 #include "ui/gfx/platform_font.h"
11 
12 namespace gfx {
13 
14 class PlatformFontMac : public PlatformFont {
15  public:
16   PlatformFontMac();
17   explicit PlatformFontMac(NativeFont native_font);
18   PlatformFontMac(const std::string& font_name,
19                   int font_size);
20 
21   // Overridden from PlatformFont:
22   virtual Font DeriveFont(int size_delta, int style) const OVERRIDE;
23   virtual int GetHeight() const OVERRIDE;
24   virtual int GetBaseline() const OVERRIDE;
25   virtual int GetCapHeight() const OVERRIDE;
26   virtual int GetExpectedTextWidth(int length) const OVERRIDE;
27   virtual int GetStyle() const OVERRIDE;
28   virtual std::string GetFontName() const OVERRIDE;
29   virtual std::string GetActualFontNameForTesting() const OVERRIDE;
30   virtual int GetFontSize() const OVERRIDE;
31   virtual NativeFont GetNativeFont() const OVERRIDE;
32 
33  private:
34   PlatformFontMac(const std::string& font_name, int font_size, int font_style);
35   virtual ~PlatformFontMac();
36 
37   // Calculates and caches the font metrics.
38   void CalculateMetrics();
39 
40   // The NSFont instance for this object. If this object was constructed from an
41   // NSFont instance, this holds that NSFont instance. Otherwise this NSFont
42   // instance is constructed from the name, size, and style, and if there is no
43   // active font that matched those criteria, this object may be nil.
44   base::scoped_nsobject<NSFont> native_font_;
45 
46   // The name/size/style trio that specify the font. Initialized in the
47   // constructors.
48   std::string font_name_;  // Corresponds to -[NSFont fontFamily].
49   int font_size_;
50   int font_style_;
51 
52   // Cached metrics, generated in CalculateMetrics().
53   int height_;
54   int ascent_;
55   int cap_height_;
56   int average_width_;
57 
58   DISALLOW_COPY_AND_ASSIGN(PlatformFontMac);
59 };
60 
61 }  // namespace gfx
62 
63 #endif  // UI_GFX_PLATFORM_FONT_MAC_H_
64