Add more components tests to GN build.
[chromium-blink-merge.git] / ui / gfx / font_list_impl.h
blobcd8e58c9110ce772b96aa9381a1389b0b697ada0
1 // Copyright 2014 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_IMPL_H_
6 #define UI_GFX_FONT_LIST_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
13 namespace gfx {
15 class Font;
17 // FontListImpl is designed to provide the implementation of FontList and
18 // intended to be used only from FontList. You must not use this class
19 // directly.
21 // FontListImpl represents a list of fonts either in the form of Font vector or
22 // in the form of a string representing font names, styles, and size.
24 // FontListImpl could be initialized either way without conversion to the other
25 // form. The conversion to the other form is done only when asked to get the
26 // other form.
28 // For the format of font description string, see font_list.h for details.
29 class FontListImpl : public base::RefCounted<FontListImpl> {
30 public:
31 // Creates a font list from a string representing font names, styles, and
32 // size.
33 explicit FontListImpl(const std::string& font_description_string);
35 // Creates a font list from font names, styles and size.
36 FontListImpl(const std::vector<std::string>& font_names,
37 int font_style,
38 int font_size);
40 // Creates a font list from a Font vector.
41 // All fonts in this vector should have the same style and size.
42 explicit FontListImpl(const std::vector<Font>& fonts);
44 // Creates a font list from a Font.
45 explicit FontListImpl(const Font& font);
47 // Returns a new FontListImpl with the same font names but resized and the
48 // given style. |size_delta| is the size in pixels to add to the current font
49 // size. |font_style| specifies the new style, which is a bitmask of the
50 // values: Font::BOLD, Font::ITALIC and Font::UNDERLINE.
51 FontListImpl* Derive(int size_delta, int font_style) const;
53 // Returns the height of this font list, which is max(ascent) + max(descent)
54 // for all the fonts in the font list.
55 int GetHeight() const;
57 // Returns the baseline of this font list, which is max(baseline) for all the
58 // fonts in the font list.
59 int GetBaseline() const;
61 // Returns the cap height of this font list.
62 // Currently returns the cap height of the primary font.
63 int GetCapHeight() const;
65 // Returns the expected number of horizontal pixels needed to display the
66 // specified length of characters. Call GetStringWidth() to retrieve the
67 // actual number.
68 int GetExpectedTextWidth(int length) const;
70 // Returns the |gfx::Font::FontStyle| style flags for this font list.
71 int GetFontStyle() const;
73 // Returns the font size in pixels.
74 int GetFontSize() const;
76 // Returns the Font vector.
77 const std::vector<Font>& GetFonts() const;
79 // Returns the first font in the list.
80 const Font& GetPrimaryFont() const;
82 private:
83 friend class base::RefCounted<FontListImpl>;
85 ~FontListImpl();
87 // Extracts common font height and baseline into |common_height_| and
88 // |common_baseline_|.
89 void CacheCommonFontHeightAndBaseline() const;
91 // Extracts font style and size into |font_style_| and |font_size_|.
92 void CacheFontStyleAndSize() const;
94 // A vector of Font. If FontListImpl is constructed with font description
95 // string, |fonts_| is not initialized during construction. Instead, it is
96 // computed lazily when user asked to get the font vector.
97 mutable std::vector<Font> fonts_;
99 // A string representing font names, styles, and sizes.
100 // Please refer to the comments before class declaration for details on string
101 // format.
102 // If FontListImpl is constructed with a vector of font,
103 // |font_description_string_| is not initialized during construction. Instead,
104 // it is computed lazily when user asked to get the font description string.
106 // TODO(derat): Remove laziness so that this can be removed.
107 mutable std::string font_description_string_;
109 // The cached common height and baseline of the fonts in the font list.
110 mutable int common_height_;
111 mutable int common_baseline_;
113 // Cached font style and size.
114 mutable int font_style_;
115 mutable int font_size_;
118 } // namespace gfx
120 #endif // UI_GFX_FONT_LIST_IMPL_H_