Fix testGetVisitedHistoryCallbackAfterDestroy
[chromium-blink-merge.git] / ui / gfx / font_list.h
blob1ba8ad1aff9f0511bcf3c17421f15655766e14f1
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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_FONT_LIST_H_
6 #define UI_GFX_FONT_LIST_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "ui/gfx/font.h"
13 #include "ui/gfx/gfx_export.h"
15 namespace gfx {
17 class FontListImpl;
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.
22 // The format of font description string complies with that of Pango detailed at
23 // http://developer.gnome.org/pango/stable/pango-Fonts.html#pango-font-description-from-string
24 // The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>" where
25 // FONT_FAMILY_LIST is a comma-separated list of font family names,
26 // STYLES is a space-separated list of style names ("Bold" and "Italic"),
27 // SIZE is a font size in pixel with the suffix "px".
28 // Here are examples of font description string:
29 // "Arial, Helvetica, Bold Italic 14px"
30 // "Arial, 14px"
31 class GFX_EXPORT FontList {
32 public:
33 // Creates a font list with default font names, size and style, which are
34 // specified by SetDefaultFontDescription().
35 FontList();
37 // Creates a font list that is a clone of another font list.
38 FontList(const FontList& other);
40 // Creates a font list from a string representing font names, styles, and
41 // size.
42 explicit FontList(const std::string& font_description_string);
44 // Creates a font list from font names, styles and size.
45 FontList(const std::vector<std::string>& font_names,
46 int font_style,
47 int font_size);
49 // Creates a font list from a Font vector.
50 // All fonts in this vector should have the same style and size.
51 explicit FontList(const std::vector<Font>& fonts);
53 // Creates a font list from a Font.
54 explicit FontList(const Font& font);
56 ~FontList();
58 // Copies the given font list into this object.
59 FontList& operator=(const FontList& other);
61 // Sets the description string for default FontList construction. If it's
62 // empty, FontList will initialize using the default Font constructor.
64 // The client code must call this function before any call of the default
65 // constructor. This should be done on the UI thread.
67 // ui::ResourceBundle may call this function more than once when UI language
68 // is changed.
69 static void SetDefaultFontDescription(const std::string& font_description);
71 // Returns a new FontList with the same font names but resized and the given
72 // style. |size_delta| is the size in pixels to add to the current font size.
73 // |font_style| specifies the new style, which is a bitmask of the values:
74 // Font::BOLD, Font::ITALIC and Font::UNDERLINE.
75 FontList Derive(int size_delta, int font_style) const;
77 // Returns a new FontList with the same font names and style but resized.
78 // |size_delta| is the size in pixels to add to the current font size.
79 FontList DeriveWithSizeDelta(int size_delta) const;
81 // Returns a new FontList with the same font names and size but the given
82 // style. |font_style| specifies the new style, which is a bitmask of the
83 // values: Font::BOLD, Font::ITALIC and Font::UNDERLINE.
84 FontList DeriveWithStyle(int font_style) const;
86 // Returns the height of this font list, which is max(ascent) + max(descent)
87 // for all the fonts in the font list.
88 int GetHeight() const;
90 // Returns the baseline of this font list, which is max(baseline) for all the
91 // fonts in the font list.
92 int GetBaseline() const;
94 // Returns the cap height of this font list.
95 // Currently returns the cap height of the primary font.
96 int GetCapHeight() const;
98 // Returns the expected number of horizontal pixels needed to display the
99 // specified length of characters. Call GetStringWidth() to retrieve the
100 // actual number.
101 int GetExpectedTextWidth(int length) const;
103 // Returns the |gfx::Font::FontStyle| style flags for this font list.
104 int GetFontStyle() const;
106 // Returns a string representing font names, styles, and size. If the FontList
107 // is initialized by a vector of Font, use the first font's style and size
108 // for the description.
109 const std::string& GetFontDescriptionString() const;
111 // Returns the font size in pixels.
112 int GetFontSize() const;
114 // Returns the Font vector.
115 const std::vector<Font>& GetFonts() const;
117 // Returns the first font in the list.
118 const Font& GetPrimaryFont() const;
120 private:
121 explicit FontList(FontListImpl* impl);
123 static const scoped_refptr<FontListImpl>& GetDefaultImpl();
125 scoped_refptr<FontListImpl> impl_;
128 } // namespace gfx
130 #endif // UI_GFX_FONT_LIST_H_