Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Side by Side Diff: ui/gfx/font.h

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit addressed Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 enum class Weight {
42 INVALID = -1,
43 THIN = 100,
44 EXTRA_LIGHT = 200,
45 LIGHT = 300,
46 NORMAL = 400,
47 MEDIUM = 500,
48 SEMIBOLD = 600,
49 BOLD = 700,
50 EXTRA_BOLD = 800,
51 BLACK = 900,
40 }; 52 };
41 53
42 // Creates a font with the default name and style. 54 // Creates a font with the default name and style.
43 Font(); 55 Font();
44 56
45 // Creates a font that is a clone of another font object. 57 // Creates a font that is a clone of another font object.
46 Font(const Font& other); 58 Font(const Font& other);
47 Font& operator=(const Font& other); 59 Font& operator=(const Font& other);
48 60
49 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS) 61 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_IOS)
50 // Creates a font from the specified native font. 62 // Creates a font from the specified native font.
51 explicit Font(NativeFont native_font); 63 explicit Font(NativeFont native_font);
52 #endif 64 #endif
53 65
54 // Constructs a Font object with the specified PlatformFont object. The Font 66 // Constructs a Font object with the specified PlatformFont object. The Font
55 // object takes ownership of the PlatformFont object. 67 // object takes ownership of the PlatformFont object.
56 explicit Font(PlatformFont* platform_font); 68 explicit Font(PlatformFont* platform_font);
57 69
58 // Creates a font with the specified name in UTF-8 and size in pixels. 70 // Creates a font with the specified name in UTF-8 and size in pixels.
59 Font(const std::string& font_name, int font_size); 71 Font(const std::string& font_name, int font_size);
60 72
61 ~Font(); 73 ~Font();
62 74
63 // Returns a new Font derived from the existing font. 75 // 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, 76 // |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. 77 // 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 78 // The style parameter specifies the new style for the font, and is a
67 // bitmask of the values: BOLD, ITALIC and UNDERLINE. 79 // bitmask of the values: ITALIC and UNDERLINE.
68 Font Derive(int size_delta, int style) const; 80 Font Derive(int size_delta, int style, gfx::Font::Weight weight) const;
69 81
70 // Returns the number of vertical pixels needed to display characters from 82 // 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 83 // the specified font. This may include some leading, i.e. height may be
72 // greater than just ascent + descent. Specifically, the Windows and Mac 84 // greater than just ascent + descent. Specifically, the Windows and Mac
73 // implementations include leading and the Linux one does not. This may 85 // implementations include leading and the Linux one does not. This may
74 // need to be revisited in the future. 86 // need to be revisited in the future.
75 int GetHeight() const; 87 int GetHeight() const;
76 88
89 // Returns the font weight.
90 gfx::Font::Weight GetWeight() const;
91
77 // Returns the baseline, or ascent, of the font. 92 // Returns the baseline, or ascent, of the font.
78 int GetBaseline() const; 93 int GetBaseline() const;
79 94
80 // Returns the cap height of the font. 95 // Returns the cap height of the font.
81 int GetCapHeight() const; 96 int GetCapHeight() const;
82 97
83 // Returns the expected number of horizontal pixels needed to display the 98 // Returns the expected number of horizontal pixels needed to display the
84 // specified length of characters. Call gfx::GetStringWidth() to retrieve the 99 // specified length of characters. Call gfx::GetStringWidth() to retrieve the
85 // actual number. 100 // actual number.
86 int GetExpectedTextWidth(int length) const; 101 int GetExpectedTextWidth(int length) const;
(...skipping 24 matching lines...) Expand all
111 126
112 // Raw access to the underlying platform font implementation. Can be 127 // Raw access to the underlying platform font implementation. Can be
113 // static_cast to a known implementation type if needed. 128 // static_cast to a known implementation type if needed.
114 PlatformFont* platform_font() const { return platform_font_.get(); } 129 PlatformFont* platform_font() const { return platform_font_.get(); }
115 130
116 private: 131 private:
117 // Wrapped platform font implementation. 132 // Wrapped platform font implementation.
118 scoped_refptr<PlatformFont> platform_font_; 133 scoped_refptr<PlatformFont> platform_font_;
119 }; 134 };
120 135
136 #ifndef NDEBUG
137 GFX_EXPORT std::ostream& operator<<(std::ostream& stream,
138 const gfx::Font::Weight weight);
139 #endif
140
121 } // namespace gfx 141 } // namespace gfx
122 142
123 #endif // UI_GFX_FONT_H_ 143 #endif // UI_GFX_FONT_H_
OLDNEW
« ui/base/resource/resource_bundle.cc ('K') | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/font.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698