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

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

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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_LIST_H_ 5 #ifndef UI_GFX_FONT_LIST_H_
6 #define UI_GFX_FONT_LIST_H_ 6 #define UI_GFX_FONT_LIST_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 // 21 //
22 // The format of font description strings is a subset of that used by Pango, as 22 // The format of font description strings is a subset of that used by Pango, as
23 // described at 23 // described at
24 // http://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-descripti on-from-string 24 // http://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-descripti on-from-string
25 // 25 //
26 // Pango font description strings should not be passed directly into FontLists. 26 // Pango font description strings should not be passed directly into FontLists.
27 // 27 //
28 // The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>", where: 28 // The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>", where:
29 // - FONT_FAMILY_LIST is a comma-separated list of font family names, 29 // - FONT_FAMILY_LIST is a comma-separated list of font family names,
30 // - STYLES is an optional space-separated list of style names (case-sensitive 30 // - STYLES is an optional space-separated list of style names (case-sensitive
31 // "Bold" and "Italic" are supported), and 31 // "Italic Ultra-Light Light Normal Semi-Bold Bold Ultra-Bold Heavy" are
msw 2016/03/22 01:53:43 nit: use quotes for each style, right? (ie. "Itali
Mikus 2016/03/22 14:19:51 Done.
32 // - SIZE is an integer font size in pixels with the suffix "px". 32 // supported), and
33 // - SIZE is an integer font size in pixels with the suffix "px"
33 // 34 //
34 // Here are examples of valid font description strings: 35 // Here are examples of valid font description strings:
35 // - "Arial, Helvetica, Bold Italic 14px" 36 // - "Arial, Helvetica, Italic Semi-Bold 14px"
36 // - "Arial, 14px" 37 // - "Arial, 14px"
37 class GFX_EXPORT FontList { 38 class GFX_EXPORT FontList {
38 public: 39 public:
39 // Parses a FontList description string into |families_out|, |style_out| (a 40 // Parses a FontList description string into |families_out|, |style_out| (a
40 // bitfield of gfx::Font::Style values), and |size_pixels_out|. Returns true 41 // bitfield of gfx::Font::Style values), and |size_pixels_out|. Returns true
41 // if the string is properly-formed. 42 // if the string is properly-formed.
42 static bool ParseDescription(const std::string& description, 43 static bool ParseDescription(const std::string& description,
43 std::vector<std::string>* families_out, 44 std::vector<std::string>* families_out,
44 int* style_out, 45 int* style_out,
45 int* size_pixels_out); 46 int* size_pixels_out,
47 gfx::Font::FontWeight* weight);
msw 2016/03/22 01:53:43 nit: rename |weight_out|, and mention it in the co
Mikus 2016/03/22 14:19:51 Done.
46 48
47 // Creates a font list with default font names, size and style, which are 49 // Creates a font list with default font names, size and style, which are
48 // specified by SetDefaultFontDescription(). 50 // specified by SetDefaultFontDescription().
49 FontList(); 51 FontList();
50 52
51 // Creates a font list that is a clone of another font list. 53 // Creates a font list that is a clone of another font list.
52 FontList(const FontList& other); 54 FontList(const FontList& other);
53 55
54 // Creates a font list from a string representing font names, styles, and 56 // Creates a font list from a string representing font names, styles, and
55 // size. 57 // size.
56 explicit FontList(const std::string& font_description_string); 58 explicit FontList(const std::string& font_description_string);
57 59
58 // Creates a font list from font names, styles and size. 60 // Creates a font list from font names, styles and size.
msw 2016/03/22 01:53:43 nit: "styles, size, and weight."
59 FontList(const std::vector<std::string>& font_names, 61 FontList(const std::vector<std::string>& font_names,
60 int font_style, 62 int font_style,
61 int font_size); 63 int font_size,
64 int font_weight);
62 65
63 // Creates a font list from a Font vector. 66 // Creates a font list from a Font vector.
64 // All fonts in this vector should have the same style and size. 67 // All fonts in this vector should have the same style and size.
65 explicit FontList(const std::vector<Font>& fonts); 68 explicit FontList(const std::vector<Font>& fonts);
66 69
67 // Creates a font list from a Font. 70 // Creates a font list from a Font.
68 explicit FontList(const Font& font); 71 explicit FontList(const Font& font);
69 72
70 ~FontList(); 73 ~FontList();
71 74
72 // Copies the given font list into this object. 75 // Copies the given font list into this object.
73 FontList& operator=(const FontList& other); 76 FontList& operator=(const FontList& other);
74 77
75 // Sets the description string for default FontList construction. If it's 78 // Sets the description string for default FontList construction. If it's
76 // empty, FontList will initialize using the default Font constructor. 79 // empty, FontList will initialize using the default Font constructor.
77 // 80 //
78 // The client code must call this function before any call of the default 81 // The client code must call this function before any call of the default
79 // constructor. This should be done on the UI thread. 82 // constructor. This should be done on the UI thread.
80 // 83 //
81 // ui::ResourceBundle may call this function more than once when UI language 84 // ui::ResourceBundle may call this function more than once when UI language
82 // is changed. 85 // is changed.
83 static void SetDefaultFontDescription(const std::string& font_description); 86 static void SetDefaultFontDescription(const std::string& font_description);
84 87
85 // Returns a new FontList with the same font names but resized and the given 88 // Returns a new FontList with the same font names but resized and the given
msw 2016/03/22 01:53:43 nit: "and with the given style and weight"
Mikus 2016/03/22 14:19:51 Done.
86 // style. |size_delta| is the size in pixels to add to the current font size. 89 // style. |size_delta| is the size in pixels to add to the current font size.
87 // |font_style| specifies the new style, which is a bitmask of the values: 90 // |font_style| specifies the new style, which is a bitmask of the values:
88 // Font::BOLD, Font::ITALIC and Font::UNDERLINE. 91 // Font::ITALIC and Font::UNDERLINE.
89 FontList Derive(int size_delta, int font_style) const; 92 FontList Derive(int size_delta,
93 int font_style,
94 gfx::Font::FontWeight weight) const;
90 95
91 // Returns a new FontList with the same font names and style but resized. 96 // Returns a new FontList with the same font names and style but resized.
92 // |size_delta| is the size in pixels to add to the current font size. 97 // |size_delta| is the size in pixels to add to the current font size.
93 FontList DeriveWithSizeDelta(int size_delta) const; 98 FontList DeriveWithSizeDelta(int size_delta) const;
94 99
95 // Returns a new FontList with the same font names and size but the given 100 // Returns a new FontList with the same font names, weight and size but the
96 // style. |font_style| specifies the new style, which is a bitmask of the 101 // given style. |font_style| specifies the new style, which is a bitmask of
97 // values: Font::BOLD, Font::ITALIC and Font::UNDERLINE. 102 // the values: Font::ITALIC and Font::UNDERLINE.
98 FontList DeriveWithStyle(int font_style) const; 103 FontList DeriveWithStyle(int font_style) const;
99 104
105 // Returns a new FontList with the same font name, size and style but with
106 // the given weight.
107 FontList DeriveWithWeight(gfx::Font::FontWeight weight) const;
108
100 // Shrinks the font size until the font list fits within |height| while 109 // Shrinks the font size until the font list fits within |height| while
101 // having its cap height vertically centered. Returns a new FontList with 110 // having its cap height vertically centered. Returns a new FontList with
102 // the correct height. 111 // the correct height.
103 // 112 //
104 // The expected layout: 113 // The expected layout:
105 // +--------+-----------------------------------------------+------------+ 114 // +--------+-----------------------------------------------+------------+
106 // | | y offset | space | 115 // | | y offset | space |
107 // | +--------+-------------------+------------------+ above | 116 // | +--------+-------------------+------------------+ above |
108 // | | | | internal leading | cap height | 117 // | | | | internal leading | cap height |
109 // | box | font | ascent (baseline) +------------------+------------+ 118 // | box | font | ascent (baseline) +------------------+------------+
(...skipping 28 matching lines...) Expand all
138 // specified length of characters. Call GetStringWidth() to retrieve the 147 // specified length of characters. Call GetStringWidth() to retrieve the
139 // actual number. 148 // actual number.
140 int GetExpectedTextWidth(int length) const; 149 int GetExpectedTextWidth(int length) const;
141 150
142 // Returns the |gfx::Font::FontStyle| style flags for this font list. 151 // Returns the |gfx::Font::FontStyle| style flags for this font list.
143 int GetFontStyle() const; 152 int GetFontStyle() const;
144 153
145 // Returns the font size in pixels. 154 // Returns the font size in pixels.
146 int GetFontSize() const; 155 int GetFontSize() const;
147 156
157 // Returns the font weight.
158 gfx::Font::FontWeight GetFontWeight() const;
159
148 // Returns the Font vector. 160 // Returns the Font vector.
149 const std::vector<Font>& GetFonts() const; 161 const std::vector<Font>& GetFonts() const;
150 162
151 // Returns the first font in the list. 163 // Returns the first font in the list.
152 const Font& GetPrimaryFont() const; 164 const Font& GetPrimaryFont() const;
153 165
154 private: 166 private:
155 explicit FontList(FontListImpl* impl); 167 explicit FontList(FontListImpl* impl);
156 168
157 static const scoped_refptr<FontListImpl>& GetDefaultImpl(); 169 static const scoped_refptr<FontListImpl>& GetDefaultImpl();
158 170
159 scoped_refptr<FontListImpl> impl_; 171 scoped_refptr<FontListImpl> impl_;
160 }; 172 };
161 173
162 } // namespace gfx 174 } // namespace gfx
163 175
164 #endif // UI_GFX_FONT_LIST_H_ 176 #endif // UI_GFX_FONT_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698