OLD | NEW |
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_PLATFORM_FONT_WIN_H_ | 5 #ifndef UI_GFX_PLATFORM_FONT_WIN_H_ |
6 #define UI_GFX_PLATFORM_FONT_WIN_H_ | 6 #define UI_GFX_PLATFORM_FONT_WIN_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 // performed other than clamping to a minimum font height if | 40 // performed other than clamping to a minimum font height if |
41 // |get_minimum_font_size_callback| is specified. | 41 // |get_minimum_font_size_callback| is specified. |
42 typedef void (*AdjustFontCallback)(LOGFONT* lf); | 42 typedef void (*AdjustFontCallback)(LOGFONT* lf); |
43 static AdjustFontCallback adjust_font_callback; | 43 static AdjustFontCallback adjust_font_callback; |
44 | 44 |
45 // Returns the font name for the system locale. Some fonts, particularly | 45 // Returns the font name for the system locale. Some fonts, particularly |
46 // East Asian fonts, have different names per locale. If the localized font | 46 // East Asian fonts, have different names per locale. If the localized font |
47 // name could not be retrieved, returns GetFontName(). | 47 // name could not be retrieved, returns GetFontName(). |
48 std::string GetLocalizedFontName() const; | 48 std::string GetLocalizedFontName() const; |
49 | 49 |
| 50 // Returns a derived Font with the specified |style| and with height at most |
| 51 // |height|. If the height and style of the receiver already match, it is |
| 52 // returned. Otherwise, the returned Font will have the largest size such that |
| 53 // its height is less than or equal to |height| (since there may not exist a |
| 54 // size that matches the exact |height| specified). |
| 55 Font DeriveFontWithHeight(int height, int style); |
| 56 |
50 // Overridden from PlatformFont: | 57 // Overridden from PlatformFont: |
51 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE; | 58 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE; |
52 virtual int GetHeight() const OVERRIDE; | 59 virtual int GetHeight() const OVERRIDE; |
53 virtual int GetBaseline() const OVERRIDE; | 60 virtual int GetBaseline() const OVERRIDE; |
54 virtual int GetAverageCharacterWidth() const OVERRIDE; | 61 virtual int GetAverageCharacterWidth() const OVERRIDE; |
55 virtual int GetStringWidth(const string16& text) const OVERRIDE; | 62 virtual int GetStringWidth(const string16& text) const OVERRIDE; |
56 virtual int GetExpectedTextWidth(int length) const OVERRIDE; | 63 virtual int GetExpectedTextWidth(int length) const OVERRIDE; |
57 virtual int GetStyle() const OVERRIDE; | 64 virtual int GetStyle() const OVERRIDE; |
58 virtual std::string GetFontName() const OVERRIDE; | 65 virtual std::string GetFontName() const OVERRIDE; |
59 virtual int GetFontSize() const OVERRIDE; | 66 virtual int GetFontSize() const OVERRIDE; |
60 virtual NativeFont GetNativeFont() const OVERRIDE; | 67 virtual NativeFont GetNativeFont() const OVERRIDE; |
61 | 68 |
62 private: | 69 private: |
63 virtual ~PlatformFontWin() {} | 70 virtual ~PlatformFontWin() {} |
64 | 71 |
65 // Chrome text drawing bottoms out in the Windows GDI functions that take an | 72 // Chrome text drawing bottoms out in the Windows GDI functions that take an |
66 // HFONT (an opaque handle into Windows). To avoid lots of GDI object | 73 // HFONT (an opaque handle into Windows). To avoid lots of GDI object |
67 // allocation and destruction, Font indirectly refers to the HFONT by way of | 74 // allocation and destruction, Font indirectly refers to the HFONT by way of |
68 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. | 75 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. |
69 // | 76 // |
70 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. | 77 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. |
71 // By making HFontRef maintain the reference to the HFONT, multiple | 78 // By making HFontRef maintain the reference to the HFONT, multiple |
72 // HFontRefs can share the same HFONT, and Font can provide value semantics. | 79 // HFontRefs can share the same HFONT, and Font can provide value semantics. |
73 class HFontRef : public base::RefCounted<HFontRef> { | 80 class HFontRef : public base::RefCounted<HFontRef> { |
74 public: | 81 public: |
75 // This constructor takes control of the HFONT, and will delete it when | 82 // This constructor takes control of the HFONT, and will delete it when |
76 // the HFontRef is deleted. | 83 // the HFontRef is deleted. |
77 HFontRef(HFONT hfont, | 84 HFontRef(HFONT hfont, |
| 85 int font_size, |
78 int height, | 86 int height, |
79 int baseline, | 87 int baseline, |
80 int ave_char_width, | 88 int ave_char_width, |
81 int style); | 89 int style); |
82 | 90 |
83 // Accessors | 91 // Accessors |
84 HFONT hfont() const { return hfont_; } | 92 HFONT hfont() const { return hfont_; } |
85 int height() const { return height_; } | 93 int height() const { return height_; } |
86 int baseline() const { return baseline_; } | 94 int baseline() const { return baseline_; } |
87 int ave_char_width() const { return ave_char_width_; } | 95 int ave_char_width() const { return ave_char_width_; } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 static HFontRef* base_font_ref_; | 141 static HFontRef* base_font_ref_; |
134 | 142 |
135 // Indirect reference to the HFontRef, which references the underlying HFONT. | 143 // Indirect reference to the HFontRef, which references the underlying HFONT. |
136 scoped_refptr<HFontRef> font_ref_; | 144 scoped_refptr<HFontRef> font_ref_; |
137 }; | 145 }; |
138 | 146 |
139 } // namespace gfx | 147 } // namespace gfx |
140 | 148 |
141 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ | 149 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ |
142 | 150 |
OLD | NEW |