Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / platform_font.h
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_H_
6 #define UI_GFX_PLATFORM_FONT_H_
7
8 #include <string>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h"
12 #include "ui/gfx/gfx_export.h"
13 #include "ui/gfx/native_widget_types.h"
14
15 namespace gfx {
16
17 class Font;
18
19 class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
20  public:
21   // Creates an appropriate PlatformFont implementation.
22   static PlatformFont* CreateDefault();
23   static PlatformFont* CreateFromNativeFont(NativeFont native_font);
24   // Creates a PlatformFont implementation with the specified |font_name|
25   // (encoded in UTF-8) and |font_size| in pixels.
26   static PlatformFont* CreateFromNameAndSize(const std::string& font_name,
27                                              int font_size);
28
29   // Returns a new Font derived from the existing font.
30   // |size_delta| is the size in pixels to add to the current font.
31   // The style parameter specifies the new style for the font, and is a
32   // bitmask of the values: BOLD, ITALIC and UNDERLINE.
33   virtual Font DeriveFont(int size_delta, int style) const = 0;
34
35   // Returns the number of vertical pixels needed to display characters from
36   // the specified font.  This may include some leading, i.e. height may be
37   // greater than just ascent + descent.  Specifically, the Windows and Mac
38   // implementations include leading and the Linux one does not.  This may
39   // need to be revisited in the future.
40   virtual int GetHeight() const = 0;
41
42   // Returns the baseline, or ascent, of the font.
43   virtual int GetBaseline() const = 0;
44
45   // Returns the cap height of the font.
46   virtual int GetCapHeight() const = 0;
47
48   // Returns the expected number of horizontal pixels needed to display the
49   // specified length of characters. Call GetStringWidth() to retrieve the
50   // actual number.
51   virtual int GetExpectedTextWidth(int length) const = 0;
52
53   // Returns the style of the font.
54   virtual int GetStyle() const = 0;
55
56   // Returns the specified font name in UTF-8.
57   virtual std::string GetFontName() const = 0;
58
59   // Returns the actually used font name in UTF-8.
60   virtual std::string GetActualFontNameForTesting() const = 0;
61
62   // Returns the font size in pixels.
63   virtual int GetFontSize() const = 0;
64
65   // Returns the native font handle.
66   virtual NativeFont GetNativeFont() const = 0;
67
68  protected:
69   virtual ~PlatformFont() {}
70
71  private:
72   friend class base::RefCounted<PlatformFont>;
73 };
74
75 }  // namespace gfx
76
77 #endif  // UI_GFX_PLATFORM_FONT_H_