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|. | |
msw
2012/04/26 21:04:42
It's unclear (from the comment) why the resulting
Alexei Svitkine (slow)
2012/04/26 21:45:56
I've expanded the comment to explain that.
| |
54 Font DeriveFontWithHeight(int height, int style); | |
55 | |
50 // Overridden from PlatformFont: | 56 // Overridden from PlatformFont: |
51 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE; | 57 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE; |
52 virtual int GetHeight() const OVERRIDE; | 58 virtual int GetHeight() const OVERRIDE; |
53 virtual int GetBaseline() const OVERRIDE; | 59 virtual int GetBaseline() const OVERRIDE; |
54 virtual int GetAverageCharacterWidth() const OVERRIDE; | 60 virtual int GetAverageCharacterWidth() const OVERRIDE; |
55 virtual int GetStringWidth(const string16& text) const OVERRIDE; | 61 virtual int GetStringWidth(const string16& text) const OVERRIDE; |
56 virtual int GetExpectedTextWidth(int length) const OVERRIDE; | 62 virtual int GetExpectedTextWidth(int length) const OVERRIDE; |
57 virtual int GetStyle() const OVERRIDE; | 63 virtual int GetStyle() const OVERRIDE; |
58 virtual std::string GetFontName() const OVERRIDE; | 64 virtual std::string GetFontName() const OVERRIDE; |
59 virtual int GetFontSize() const OVERRIDE; | 65 virtual int GetFontSize() const OVERRIDE; |
60 virtual NativeFont GetNativeFont() const OVERRIDE; | 66 virtual NativeFont GetNativeFont() const OVERRIDE; |
61 | 67 |
62 private: | 68 private: |
63 virtual ~PlatformFontWin() {} | 69 virtual ~PlatformFontWin() {} |
64 | 70 |
65 // Chrome text drawing bottoms out in the Windows GDI functions that take an | 71 // 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 | 72 // 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 | 73 // 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. | 74 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. |
69 // | 75 // |
70 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. | 76 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. |
71 // By making HFontRef maintain the reference to the HFONT, multiple | 77 // By making HFontRef maintain the reference to the HFONT, multiple |
72 // HFontRefs can share the same HFONT, and Font can provide value semantics. | 78 // HFontRefs can share the same HFONT, and Font can provide value semantics. |
73 class HFontRef : public base::RefCounted<HFontRef> { | 79 class HFontRef : public base::RefCounted<HFontRef> { |
74 public: | 80 public: |
75 // This constructor takes control of the HFONT, and will delete it when | 81 // This constructor takes control of the HFONT, and will delete it when |
76 // the HFontRef is deleted. | 82 // the HFontRef is deleted. |
77 HFontRef(HFONT hfont, | 83 HFontRef(HFONT hfont, |
84 int font_size, | |
78 int height, | 85 int height, |
79 int baseline, | 86 int baseline, |
80 int ave_char_width, | 87 int ave_char_width, |
81 int style); | 88 int style); |
82 | 89 |
83 // Accessors | 90 // Accessors |
84 HFONT hfont() const { return hfont_; } | 91 HFONT hfont() const { return hfont_; } |
85 int height() const { return height_; } | 92 int height() const { return height_; } |
86 int baseline() const { return baseline_; } | 93 int baseline() const { return baseline_; } |
87 int ave_char_width() const { return ave_char_width_; } | 94 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_; | 140 static HFontRef* base_font_ref_; |
134 | 141 |
135 // Indirect reference to the HFontRef, which references the underlying HFONT. | 142 // Indirect reference to the HFontRef, which references the underlying HFONT. |
136 scoped_refptr<HFontRef> font_ref_; | 143 scoped_refptr<HFontRef> font_ref_; |
137 }; | 144 }; |
138 | 145 |
139 } // namespace gfx | 146 } // namespace gfx |
140 | 147 |
141 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ | 148 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ |
142 | 149 |
OLD | NEW |