Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_FONT_H_ | 5 #ifndef UI_GFX_FONT_H_ |
| 6 #define UI_GFX_FONT_H_ | 6 #define UI_GFX_FONT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 // | | ascent (baseline) +------------------+ | 27 // | | ascent (baseline) +------------------+ |
| 28 // | height | | cap height | | 28 // | height | | cap height | |
| 29 // | |-------------------+------------------+ | 29 // | |-------------------+------------------+ |
| 30 // | | descent (height - baseline) | | 30 // | | descent (height - baseline) | |
| 31 // +--------+--------------------------------------+ | 31 // +--------+--------------------------------------+ |
| 32 class GFX_EXPORT Font { | 32 class GFX_EXPORT Font { |
| 33 public: | 33 public: |
| 34 // The following constants indicate the font style. | 34 // The following constants indicate the font style. |
| 35 enum FontStyle { | 35 enum FontStyle { |
| 36 NORMAL = 0, | 36 NORMAL = 0, |
| 37 BOLD = 1, | 37 ITALIC = 1, |
| 38 ITALIC = 2, | 38 UNDERLINE = 2, |
| 39 UNDERLINE = 4, | 39 }; |
| 40 | |
| 41 // Standard font weights as used in Pango and Windows. The values must match | |
| 42 // https://msdn.microsoft.com/en-us/library/system.windows.fontweights(v=vs.11 0).aspx | |
| 43 enum class Weight { | |
| 44 INVALID = -1, | |
| 45 THIN = 100, | |
| 46 EXTRA_LIGHT = 200, | |
| 47 LIGHT = 300, | |
| 48 NORMAL = 400, | |
| 49 MEDIUM = 500, | |
| 50 SEMIBOLD = 600, | |
| 51 BOLD = 700, | |
| 52 EXTRA_BOLD = 800, | |
| 53 BLACK = 900, | |
| 40 }; | 54 }; |
| 41 | 55 |
| 42 // Creates a font with the default name and style. | 56 // Creates a font with the default name and style. |
| 43 Font(); | 57 Font(); |
| 44 | 58 |
| 45 // Creates a font that is a clone of another font object. | 59 // Creates a font that is a clone of another font object. |
| 46 Font(const Font& other); | 60 Font(const Font& other); |
| 47 Font& operator=(const Font& other); | 61 Font& operator=(const Font& other); |
| 48 | 62 |
| 49 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) | 63 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) |
| 50 // Creates a font from the specified native font. | 64 // Creates a font from the specified native font. |
| 51 explicit Font(NativeFont native_font); | 65 explicit Font(NativeFont native_font); |
| 52 #endif | 66 #endif |
| 53 | 67 |
| 54 // Constructs a Font object with the specified PlatformFont object. The Font | 68 // Constructs a Font object with the specified PlatformFont object. The Font |
| 55 // object takes ownership of the PlatformFont object. | 69 // object takes ownership of the PlatformFont object. |
| 56 explicit Font(PlatformFont* platform_font); | 70 explicit Font(PlatformFont* platform_font); |
| 57 | 71 |
| 58 // Creates a font with the specified name in UTF-8 and size in pixels. | 72 // Creates a font with the specified name in UTF-8 and size in pixels. |
| 59 Font(const std::string& font_name, int font_size); | 73 Font(const std::string& font_name, int font_size); |
| 60 | 74 |
| 61 ~Font(); | 75 ~Font(); |
| 62 | 76 |
| 63 // Returns a new Font derived from the existing font. | 77 // Returns a new Font derived from the existing font. |
| 64 // |size_delta| is the size in pixels to add to the current font. For example, | 78 // |size_delta| is the size in pixels to add to the current font. For example, |
| 65 // a value of 5 results in a font 5 pixels bigger than this font. | 79 // a value of 5 results in a font 5 pixels bigger than this font. |
| 66 // The style parameter specifies the new style for the font, and is a | 80 // The style parameter specifies the new style for the font, and is a |
| 67 // bitmask of the values: BOLD, ITALIC and UNDERLINE. | 81 // bitmask of the values: ITALIC and UNDERLINE. |
| 68 Font Derive(int size_delta, int style) const; | 82 Font Derive(int size_delta, int style, gfx::Font::Weight weight) const; |
|
Alexei Svitkine (slow)
2016/04/05 16:38:50
Remove gfx::
| |
| 69 | 83 |
| 70 // Returns the number of vertical pixels needed to display characters from | 84 // Returns the number of vertical pixels needed to display characters from |
| 71 // the specified font. This may include some leading, i.e. height may be | 85 // the specified font. This may include some leading, i.e. height may be |
| 72 // greater than just ascent + descent. Specifically, the Windows and Mac | 86 // greater than just ascent + descent. Specifically, the Windows and Mac |
| 73 // implementations include leading and the Linux one does not. This may | 87 // implementations include leading and the Linux one does not. This may |
| 74 // need to be revisited in the future. | 88 // need to be revisited in the future. |
| 75 int GetHeight() const; | 89 int GetHeight() const; |
| 76 | 90 |
| 91 // Returns the font weight. | |
| 92 gfx::Font::Weight GetWeight() const; | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:50
Remove gfx::
| |
| 93 | |
| 77 // Returns the baseline, or ascent, of the font. | 94 // Returns the baseline, or ascent, of the font. |
| 78 int GetBaseline() const; | 95 int GetBaseline() const; |
| 79 | 96 |
| 80 // Returns the cap height of the font. | 97 // Returns the cap height of the font. |
| 81 int GetCapHeight() const; | 98 int GetCapHeight() const; |
| 82 | 99 |
| 83 // Returns the expected number of horizontal pixels needed to display the | 100 // Returns the expected number of horizontal pixels needed to display the |
| 84 // specified length of characters. Call gfx::GetStringWidth() to retrieve the | 101 // specified length of characters. Call gfx::GetStringWidth() to retrieve the |
| 85 // actual number. | 102 // actual number. |
| 86 int GetExpectedTextWidth(int length) const; | 103 int GetExpectedTextWidth(int length) const; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 111 | 128 |
| 112 // Raw access to the underlying platform font implementation. Can be | 129 // Raw access to the underlying platform font implementation. Can be |
| 113 // static_cast to a known implementation type if needed. | 130 // static_cast to a known implementation type if needed. |
| 114 PlatformFont* platform_font() const { return platform_font_.get(); } | 131 PlatformFont* platform_font() const { return platform_font_.get(); } |
| 115 | 132 |
| 116 private: | 133 private: |
| 117 // Wrapped platform font implementation. | 134 // Wrapped platform font implementation. |
| 118 scoped_refptr<PlatformFont> platform_font_; | 135 scoped_refptr<PlatformFont> platform_font_; |
| 119 }; | 136 }; |
| 120 | 137 |
| 138 #ifndef NDEBUG | |
| 139 GFX_EXPORT std::ostream& operator<<(std::ostream& stream, | |
| 140 const gfx::Font::Weight weight); | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:50
Remove gfx::
| |
| 141 #endif | |
| 142 | |
| 121 } // namespace gfx | 143 } // namespace gfx |
| 122 | 144 |
| 123 #endif // UI_GFX_FONT_H_ | 145 #endif // UI_GFX_FONT_H_ |
| OLD | NEW |