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

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

Issue 903423002: Make FontList description-parsing public. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge and apply review feedback Created 5 years, 10 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
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "ui/gfx/font.h" 12 #include "ui/gfx/font.h"
13 #include "ui/gfx/gfx_export.h" 13 #include "ui/gfx/gfx_export.h"
14 14
15 namespace gfx { 15 namespace gfx {
16 16
17 class FontListImpl; 17 class FontListImpl;
18 18
19 // FontList represents a list of fonts and provides metrics which are common 19 // FontList represents a list of fonts and provides metrics which are common
20 // in the fonts. FontList is copyable and it's quite cheap to copy. 20 // across the fonts. FontList is copyable and quite cheap to copy.
21 // 21 //
22 // The format of font description string complies with that of Pango detailed at 22 // The format of font description strings is a subset of that used by Pango, as
23 // described at
23 // 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
24 // The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>" where 25 //
25 // FONT_FAMILY_LIST is a comma-separated list of font family names, 26 // Pango font description strings should not be passed directly into FontLists.
26 // STYLES is a space-separated list of style names ("Bold" and "Italic"), 27 //
27 // SIZE is a font size in pixel with the suffix "px". 28 // The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>", where:
28 // Here are examples of font description string: 29 // - FONT_FAMILY_LIST is a comma-separated list of font family names,
29 // "Arial, Helvetica, Bold Italic 14px" 30 // - STYLES is an optional space-separated list of style names (case-sensitive
30 // "Arial, 14px" 31 // "Bold" and "Italic" are supported), and
32 // - SIZE is an integer font size in pixels with the suffix "px".
33 //
34 // Here are examples of valid font description strings:
35 // - "Arial, Helvetica, Bold Italic 14px"
36 // - "Arial, 14px"
31 class GFX_EXPORT FontList { 37 class GFX_EXPORT FontList {
32 public: 38 public:
39 // 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 // if the string is properly-formed.
42 static bool ParseDescription(const std::string& description,
43 std::vector<std::string>* families_out,
44 int* style_out,
45 int* size_pixels_out);
46
33 // Creates a font list with default font names, size and style, which are 47 // Creates a font list with default font names, size and style, which are
34 // specified by SetDefaultFontDescription(). 48 // specified by SetDefaultFontDescription().
35 FontList(); 49 FontList();
36 50
37 // Creates a font list that is a clone of another font list. 51 // Creates a font list that is a clone of another font list.
38 FontList(const FontList& other); 52 FontList(const FontList& other);
39 53
40 // Creates a font list from a string representing font names, styles, and 54 // Creates a font list from a string representing font names, styles, and
41 // size. 55 // size.
42 explicit FontList(const std::string& font_description_string); 56 explicit FontList(const std::string& font_description_string);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 int GetCapHeight() const; 135 int GetCapHeight() const;
122 136
123 // Returns the expected number of horizontal pixels needed to display the 137 // Returns the expected number of horizontal pixels needed to display the
124 // specified length of characters. Call GetStringWidth() to retrieve the 138 // specified length of characters. Call GetStringWidth() to retrieve the
125 // actual number. 139 // actual number.
126 int GetExpectedTextWidth(int length) const; 140 int GetExpectedTextWidth(int length) const;
127 141
128 // Returns the |gfx::Font::FontStyle| style flags for this font list. 142 // Returns the |gfx::Font::FontStyle| style flags for this font list.
129 int GetFontStyle() const; 143 int GetFontStyle() const;
130 144
131 // Returns a string representing font names, styles, and size. If the FontList
132 // is initialized by a vector of Font, use the first font's style and size
133 // for the description.
134 const std::string& GetFontDescriptionString() const;
135
136 // Returns the font size in pixels. 145 // Returns the font size in pixels.
137 int GetFontSize() const; 146 int GetFontSize() const;
138 147
139 // Returns the Font vector. 148 // Returns the Font vector.
140 const std::vector<Font>& GetFonts() const; 149 const std::vector<Font>& GetFonts() const;
141 150
142 // Returns the first font in the list. 151 // Returns the first font in the list.
143 const Font& GetPrimaryFont() const; 152 const Font& GetPrimaryFont() const;
144 153
145 private: 154 private:
146 explicit FontList(FontListImpl* impl); 155 explicit FontList(FontListImpl* impl);
147 156
148 static const scoped_refptr<FontListImpl>& GetDefaultImpl(); 157 static const scoped_refptr<FontListImpl>& GetDefaultImpl();
149 158
150 scoped_refptr<FontListImpl> impl_; 159 scoped_refptr<FontListImpl> impl_;
151 }; 160 };
152 161
153 } // namespace gfx 162 } // namespace gfx
154 163
155 #endif // UI_GFX_FONT_LIST_H_ 164 #endif // UI_GFX_FONT_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698