Call _set_FMA3_enable(0); to work around VS 2013 CRT AVX bug.
[chromium-blink-merge.git] / ui / gfx / platform_font.h
blob42f46ea1360248ce060ef98bdefe2a6dd734dc7d
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_H_
6 #define UI_GFX_PLATFORM_FONT_H_
8 #include <string>
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"
15 namespace gfx {
17 class Font;
18 struct FontRenderParams;
20 class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
21 public:
22 // Creates an appropriate PlatformFont implementation.
23 static PlatformFont* CreateDefault();
24 static PlatformFont* CreateFromNativeFont(NativeFont native_font);
25 // Creates a PlatformFont implementation with the specified |font_name|
26 // (encoded in UTF-8) and |font_size| in pixels.
27 static PlatformFont* CreateFromNameAndSize(const std::string& font_name,
28 int font_size);
30 // Returns a new Font derived from the existing font.
31 // |size_delta| is the size in pixels to add to the current font.
32 // The style parameter specifies the new style for the font, and is a
33 // bitmask of the values: BOLD, ITALIC and UNDERLINE.
34 virtual Font DeriveFont(int size_delta, int style) const = 0;
36 // Returns the number of vertical pixels needed to display characters from
37 // the specified font. This may include some leading, i.e. height may be
38 // greater than just ascent + descent. Specifically, the Windows and Mac
39 // implementations include leading and the Linux one does not. This may
40 // need to be revisited in the future.
41 virtual int GetHeight() const = 0;
43 // Returns the baseline, or ascent, of the font.
44 virtual int GetBaseline() const = 0;
46 // Returns the cap height of the font.
47 virtual int GetCapHeight() const = 0;
49 // Returns the expected number of horizontal pixels needed to display the
50 // specified length of characters. Call GetStringWidth() to retrieve the
51 // actual number.
52 virtual int GetExpectedTextWidth(int length) const = 0;
54 // Returns the style of the font.
55 virtual int GetStyle() const = 0;
57 // Returns the specified font name in UTF-8.
58 virtual std::string GetFontName() const = 0;
60 // Returns the actually used font name in UTF-8.
61 virtual std::string GetActualFontNameForTesting() const = 0;
63 // Returns the font size in pixels.
64 virtual int GetFontSize() const = 0;
66 // Returns an object describing how the font should be rendered.
67 virtual const FontRenderParams& GetFontRenderParams() const = 0;
69 // Returns the native font handle.
70 virtual NativeFont GetNativeFont() const = 0;
72 protected:
73 virtual ~PlatformFont() {}
75 private:
76 friend class base::RefCounted<PlatformFont>;
79 } // namespace gfx
81 #endif // UI_GFX_PLATFORM_FONT_H_