| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 GFX_FONT_H_ | 5 #ifndef GFX_FONT_H_ |
| 6 #define GFX_FONT_H_ | 6 #define GFX_FONT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include "ui/gfx/font.h" |
| 10 | 10 // TODO(sail): remove this file once all includes have been updated. |
| 11 #include "base/ref_counted.h" | |
| 12 #include "base/string16.h" | |
| 13 #include "gfx/native_widget_types.h" | |
| 14 | |
| 15 namespace gfx { | |
| 16 | |
| 17 class PlatformFont; | |
| 18 | |
| 19 // Font provides a wrapper around an underlying font. Copy and assignment | |
| 20 // operators are explicitly allowed, and cheap. | |
| 21 class Font { | |
| 22 public: | |
| 23 // The following constants indicate the font style. | |
| 24 enum FontStyle { | |
| 25 NORMAL = 0, | |
| 26 BOLD = 1, | |
| 27 ITALIC = 2, | |
| 28 UNDERLINED = 4, | |
| 29 }; | |
| 30 | |
| 31 // Creates a font with the default name and style. | |
| 32 Font(); | |
| 33 | |
| 34 // Creates a font that is a clone of another font object. | |
| 35 Font(const Font& other); | |
| 36 gfx::Font& operator=(const Font& other); | |
| 37 | |
| 38 // Creates a font from the specified native font. | |
| 39 explicit Font(NativeFont native_font); | |
| 40 | |
| 41 // Construct a Font object with the specified PlatformFont object. The Font | |
| 42 // object takes ownership of the PlatformFont object. | |
| 43 explicit Font(PlatformFont* platform_font); | |
| 44 | |
| 45 // Creates a font with the specified name and size. | |
| 46 Font(const string16& font_name, int font_size); | |
| 47 | |
| 48 ~Font(); | |
| 49 | |
| 50 // Returns a new Font derived from the existing font. | |
| 51 // size_deta is the size to add to the current font. For example, a value | |
| 52 // of 5 results in a font 5 units bigger than this font. | |
| 53 Font DeriveFont(int size_delta) const; | |
| 54 | |
| 55 // Returns a new Font derived from the existing font. | |
| 56 // size_delta is the size to add to the current font. See the single | |
| 57 // argument version of this method for an example. | |
| 58 // The style parameter specifies the new style for the font, and is a | |
| 59 // bitmask of the values: BOLD, ITALIC and UNDERLINED. | |
| 60 Font DeriveFont(int size_delta, int style) const; | |
| 61 | |
| 62 // Returns the number of vertical pixels needed to display characters from | |
| 63 // the specified font. This may include some leading, i.e. height may be | |
| 64 // greater than just ascent + descent. Specifically, the Windows and Mac | |
| 65 // implementations include leading and the Linux one does not. This may | |
| 66 // need to be revisited in the future. | |
| 67 int GetHeight() const; | |
| 68 | |
| 69 // Returns the baseline, or ascent, of the font. | |
| 70 int GetBaseline() const; | |
| 71 | |
| 72 // Returns the average character width for the font. | |
| 73 int GetAverageCharacterWidth() const; | |
| 74 | |
| 75 // Returns the number of horizontal pixels needed to display the specified | |
| 76 // string. | |
| 77 int GetStringWidth(const string16& text) const; | |
| 78 | |
| 79 // Returns the expected number of horizontal pixels needed to display the | |
| 80 // specified length of characters. Call GetStringWidth() to retrieve the | |
| 81 // actual number. | |
| 82 int GetExpectedTextWidth(int length) const; | |
| 83 | |
| 84 // Returns the style of the font. | |
| 85 int GetStyle() const; | |
| 86 | |
| 87 // Returns the font name. | |
| 88 string16 GetFontName() const; | |
| 89 | |
| 90 // Returns the font size in pixels. | |
| 91 int GetFontSize() const; | |
| 92 | |
| 93 // Returns the native font handle. | |
| 94 // Lifetime lore: | |
| 95 // Windows: This handle is owned by the Font object, and should not be | |
| 96 // destroyed by the caller. | |
| 97 // Mac: Caller must release this object. | |
| 98 // Gtk: This handle is created on demand, and must be freed by calling | |
| 99 // pango_font_description_free() when the caller is done using it. | |
| 100 NativeFont GetNativeFont() const; | |
| 101 | |
| 102 // Raw access to the underlying platform font implementation. Can be | |
| 103 // static_cast to a known implementation type if needed. | |
| 104 PlatformFont* platform_font() const { return platform_font_.get(); } | |
| 105 | |
| 106 private: | |
| 107 // Wrapped platform font implementation. | |
| 108 scoped_refptr<PlatformFont> platform_font_; | |
| 109 }; | |
| 110 | |
| 111 } // namespace gfx | |
| 112 | 11 |
| 113 #endif // GFX_FONT_H_ | 12 #endif // GFX_FONT_H_ |
| OLD | NEW |