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

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: Add a lost comment and modify a render text unittest to not test black because of test env font con… Created 4 years, 6 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
« no previous file with comments | « ui/gfx/font.cc ('k') | ui/gfx/font_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
32 // - SIZE is an integer font size in pixels with the suffix "px". 32 // "Heavy" are 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), |size_pixels_out| and |weight_out|.
41 // if the string is properly-formed. 42 // Returns true 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 Font::Weight* weight_out);
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, 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 Font::Weight 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
86 // style. |size_delta| is the size in pixels to add to the current font size. 89 // style and weight. |size_delta| is the size in pixels to add to the current
87 // |font_style| specifies the new style, which is a bitmask of the values: 90 // font size. |font_style| specifies the new style, which is a bitmask of the
88 // Font::BOLD, Font::ITALIC and Font::UNDERLINE. 91 // values: Font::ITALIC and Font::UNDERLINE. |weight| is the requested font
89 FontList Derive(int size_delta, int font_style) const; 92 // weight.
93 FontList Derive(int size_delta,
94 int font_style,
95 Font::Weight weight) const;
90 96
91 // Returns a new FontList with the same font names and style but resized. 97 // 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. 98 // |size_delta| is the size in pixels to add to the current font size.
93 FontList DeriveWithSizeDelta(int size_delta) const; 99 FontList DeriveWithSizeDelta(int size_delta) const;
94 100
95 // Returns a new FontList with the same font names and size but the given 101 // 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 102 // given style. |font_style| specifies the new style, which is a bitmask of
97 // values: Font::BOLD, Font::ITALIC and Font::UNDERLINE. 103 // the values: Font::ITALIC and Font::UNDERLINE.
98 FontList DeriveWithStyle(int font_style) const; 104 FontList DeriveWithStyle(int font_style) const;
99 105
106 // Returns a new FontList with the same font name, size and style but with
107 // the given weight.
108 FontList DeriveWithWeight(Font::Weight weight) const;
109
100 // Shrinks the font size until the font list fits within |height| while 110 // Shrinks the font size until the font list fits within |height| while
101 // having its cap height vertically centered. Returns a new FontList with 111 // having its cap height vertically centered. Returns a new FontList with
102 // the correct height. 112 // the correct height.
103 // 113 //
104 // The expected layout: 114 // The expected layout:
105 // +--------+-----------------------------------------------+------------+ 115 // +--------+-----------------------------------------------+------------+
106 // | | y offset | space | 116 // | | y offset | space |
107 // | +--------+-------------------+------------------+ above | 117 // | +--------+-------------------+------------------+ above |
108 // | | | | internal leading | cap height | 118 // | | | | internal leading | cap height |
109 // | box | font | ascent (baseline) +------------------+------------+ 119 // | box | font | ascent (baseline) +------------------+------------+
110 // | height | height | | cap height | 120 // | height | height | | cap height |
111 // | | |-------------------+------------------+------------+ 121 // | | |-------------------+------------------+------------+
112 // | | | descent (height - baseline) | space | 122 // | | | descent (height - baseline) | space |
113 // | +--------+--------------------------------------+ below | 123 // | +--------+--------------------------------------+ below |
114 // | | space at bottom | cap height | 124 // | | space at bottom | cap height |
115 // +--------+-----------------------------------------------+------------+ 125 // +--------+-----------------------------------------------+------------+
116 // Goal: 126 // Goal:
117 // center of box height == center of cap height 127 // center of box height == center of cap height
118 // (i.e. space above cap height == space below cap height) 128 // (i.e. space above cap height == space below cap height)
119 // Restrictions: 129 // Restrictions:
120 // y offset >= 0 130 // y offset >= 0
121 // space at bottom >= 0 131 // space at bottom >= 0
122 // (i.e. Entire font must be visible inside the box.) 132 // (i.e. Entire font must be visible inside the box.)
123 gfx::FontList DeriveWithHeightUpperBound(int height) const; 133 FontList DeriveWithHeightUpperBound(int height) const;
124 134
125 // Returns the height of this font list, which is max(ascent) + max(descent) 135 // Returns the height of this font list, which is max(ascent) + max(descent)
126 // for all the fonts in the font list. 136 // for all the fonts in the font list.
127 int GetHeight() const; 137 int GetHeight() const;
128 138
129 // Returns the baseline of this font list, which is max(baseline) for all the 139 // Returns the baseline of this font list, which is max(baseline) for all the
130 // fonts in the font list. 140 // fonts in the font list.
131 int GetBaseline() const; 141 int GetBaseline() const;
132 142
133 // Returns the cap height of this font list. 143 // Returns the cap height of this font list.
134 // Currently returns the cap height of the primary font. 144 // Currently returns the cap height of the primary font.
135 int GetCapHeight() const; 145 int GetCapHeight() const;
136 146
137 // Returns the expected number of horizontal pixels needed to display the 147 // Returns the expected number of horizontal pixels needed to display the
138 // specified length of characters. Call GetStringWidth() to retrieve the 148 // specified length of characters. Call GetStringWidth() to retrieve the
139 // actual number. 149 // actual number.
140 int GetExpectedTextWidth(int length) const; 150 int GetExpectedTextWidth(int length) const;
141 151
142 // Returns the |gfx::Font::FontStyle| style flags for this font list. 152 // Returns the |Font::FontStyle| style flags for this font list.
143 int GetFontStyle() const; 153 int GetFontStyle() const;
144 154
145 // Returns the font size in pixels. 155 // Returns the font size in pixels.
146 int GetFontSize() const; 156 int GetFontSize() const;
147 157
158 // Returns the font weight.
159 Font::Weight GetFontWeight() const;
160
148 // Returns the Font vector. 161 // Returns the Font vector.
149 const std::vector<Font>& GetFonts() const; 162 const std::vector<Font>& GetFonts() const;
150 163
151 // Returns the first font in the list. 164 // Returns the first font in the list.
152 const Font& GetPrimaryFont() const; 165 const Font& GetPrimaryFont() const;
153 166
154 private: 167 private:
155 explicit FontList(FontListImpl* impl); 168 explicit FontList(FontListImpl* impl);
156 169
157 static const scoped_refptr<FontListImpl>& GetDefaultImpl(); 170 static const scoped_refptr<FontListImpl>& GetDefaultImpl();
158 171
159 scoped_refptr<FontListImpl> impl_; 172 scoped_refptr<FontListImpl> impl_;
160 }; 173 };
161 174
162 } // namespace gfx 175 } // namespace gfx
163 176
164 #endif // UI_GFX_FONT_LIST_H_ 177 #endif // UI_GFX_FONT_LIST_H_
OLDNEW
« no previous file with comments | « ui/gfx/font.cc ('k') | ui/gfx/font_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698