Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_IMPL_H_ | 5 #ifndef UI_GFX_FONT_LIST_IMPL_H_ |
| 6 #define UI_GFX_FONT_LIST_IMPL_H_ | 6 #define UI_GFX_FONT_LIST_IMPL_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 | 13 |
| 13 namespace gfx { | 14 namespace gfx { |
| 14 | 15 |
| 15 class Font; | |
| 16 | |
| 17 // FontListImpl is designed to provide the implementation of FontList and | 16 // FontListImpl is designed to provide the implementation of FontList and |
| 18 // intended to be used only from FontList. You must not use this class | 17 // intended to be used only from FontList. You must not use this class |
| 19 // directly. | 18 // directly. |
| 20 // | 19 // |
| 21 // FontListImpl represents a list of fonts either in the form of Font vector or | 20 // 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. | 21 // in the form of a string representing font names, styles, and size. |
| 23 // | 22 // |
| 24 // FontListImpl could be initialized either way without conversion to the other | 23 // 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 | 24 // form. The conversion to the other form is done only when asked to get the |
| 26 // other form. | 25 // other form. |
| 27 // | 26 // |
| 28 // For the format of font description string, see font_list.h for details. | 27 // For the format of font description string, see font_list.h for details. |
| 29 class FontListImpl : public base::RefCounted<FontListImpl> { | 28 class FontListImpl : public base::RefCounted<FontListImpl> { |
| 30 public: | 29 public: |
| 31 // Creates a font list from a string representing font names, styles, and | 30 // Creates a font list from a string representing font names, styles, and |
| 32 // size. | 31 // size. |
| 33 explicit FontListImpl(const std::string& font_description_string); | 32 explicit FontListImpl(const std::string& font_description_string); |
| 34 | 33 |
| 35 // Creates a font list from font names, styles and size. | 34 // Creates a font list from font names, styles, size and weight. |
| 36 FontListImpl(const std::vector<std::string>& font_names, | 35 FontListImpl(const std::vector<std::string>& font_names, |
| 37 int font_style, | 36 int font_style, |
| 38 int font_size); | 37 int font_size, |
| 38 gfx::Font::Weight font_weight); | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:51
Remove gfx::
| |
| 39 | 39 |
| 40 // Creates a font list from a Font vector. | 40 // Creates a font list from a Font vector. |
| 41 // All fonts in this vector should have the same style and size. | 41 // All fonts in this vector should have the same style and size. |
| 42 explicit FontListImpl(const std::vector<Font>& fonts); | 42 explicit FontListImpl(const std::vector<Font>& fonts); |
| 43 | 43 |
| 44 // Creates a font list from a Font. | 44 // Creates a font list from a Font. |
| 45 explicit FontListImpl(const Font& font); | 45 explicit FontListImpl(const Font& font); |
| 46 | 46 |
| 47 // Returns a new FontListImpl with the same font names but resized and the | 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 | 48 // given style and weight. |size_delta| is the size in pixels to add to the |
| 49 // size. |font_style| specifies the new style, which is a bitmask of the | 49 // current font size. |font_style| specifies the new style, which is a |
| 50 // values: Font::BOLD, Font::ITALIC and Font::UNDERLINE. | 50 // bitmask of the values: Font::ITALIC and Font::UNDERLINE. |
| 51 FontListImpl* Derive(int size_delta, int font_style) const; | 51 FontListImpl* Derive(int size_delta, |
| 52 int font_style, | |
| 53 gfx::Font::Weight weight) const; | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:51
Remove gfx::
| |
| 52 | 54 |
| 53 // Returns the height of this font list, which is max(ascent) + max(descent) | 55 // Returns the height of this font list, which is max(ascent) + max(descent) |
| 54 // for all the fonts in the font list. | 56 // for all the fonts in the font list. |
| 55 int GetHeight() const; | 57 int GetHeight() const; |
| 56 | 58 |
| 57 // Returns the baseline of this font list, which is max(baseline) for all the | 59 // Returns the baseline of this font list, which is max(baseline) for all the |
| 58 // fonts in the font list. | 60 // fonts in the font list. |
| 59 int GetBaseline() const; | 61 int GetBaseline() const; |
| 60 | 62 |
| 61 // Returns the cap height of this font list. | 63 // Returns the cap height of this font list. |
| 62 // Currently returns the cap height of the primary font. | 64 // Currently returns the cap height of the primary font. |
| 63 int GetCapHeight() const; | 65 int GetCapHeight() const; |
| 64 | 66 |
| 65 // Returns the expected number of horizontal pixels needed to display the | 67 // Returns the expected number of horizontal pixels needed to display the |
| 66 // specified length of characters. Call GetStringWidth() to retrieve the | 68 // specified length of characters. Call GetStringWidth() to retrieve the |
| 67 // actual number. | 69 // actual number. |
| 68 int GetExpectedTextWidth(int length) const; | 70 int GetExpectedTextWidth(int length) const; |
| 69 | 71 |
| 70 // Returns the |gfx::Font::FontStyle| style flags for this font list. | 72 // Returns the |gfx::Font::FontStyle| style flags for this font list. |
| 71 int GetFontStyle() const; | 73 int GetFontStyle() const; |
| 72 | 74 |
| 73 // Returns the font size in pixels. | 75 // Returns the font size in pixels. |
| 74 int GetFontSize() const; | 76 int GetFontSize() const; |
| 75 | 77 |
| 78 // Returns the font weight. | |
| 79 gfx::Font::Weight GetFontWeight() const; | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:51
Remove gfx::
| |
| 80 | |
| 76 // Returns the Font vector. | 81 // Returns the Font vector. |
| 77 const std::vector<Font>& GetFonts() const; | 82 const std::vector<Font>& GetFonts() const; |
| 78 | 83 |
| 79 // Returns the first font in the list. | 84 // Returns the first font in the list. |
| 80 const Font& GetPrimaryFont() const; | 85 const Font& GetPrimaryFont() const; |
| 81 | 86 |
| 82 private: | 87 private: |
| 83 friend class base::RefCounted<FontListImpl>; | 88 friend class base::RefCounted<FontListImpl>; |
| 84 | 89 |
| 85 ~FontListImpl(); | 90 ~FontListImpl(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 106 // TODO(derat): Remove laziness so that this can be removed. | 111 // TODO(derat): Remove laziness so that this can be removed. |
| 107 mutable std::string font_description_string_; | 112 mutable std::string font_description_string_; |
| 108 | 113 |
| 109 // The cached common height and baseline of the fonts in the font list. | 114 // The cached common height and baseline of the fonts in the font list. |
| 110 mutable int common_height_; | 115 mutable int common_height_; |
| 111 mutable int common_baseline_; | 116 mutable int common_baseline_; |
| 112 | 117 |
| 113 // Cached font style and size. | 118 // Cached font style and size. |
| 114 mutable int font_style_; | 119 mutable int font_style_; |
| 115 mutable int font_size_; | 120 mutable int font_size_; |
| 121 mutable gfx::Font::Weight font_weight_; | |
|
Alexei Svitkine (slow)
2016/04/05 16:38:51
Remove gfx::
| |
| 116 }; | 122 }; |
| 117 | 123 |
| 118 } // namespace gfx | 124 } // namespace gfx |
| 119 | 125 |
| 120 #endif // UI_GFX_FONT_LIST_IMPL_H_ | 126 #endif // UI_GFX_FONT_LIST_IMPL_H_ |
| OLD | NEW |