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_; } |
88 int style() const { return style_; } | 96 int style() const { return style_; } |
89 const std::string& font_name() const { return font_name_; } | 97 const std::string& font_name() const { return font_name_; } |
90 int font_size() const { return font_size_; } | 98 int font_size() const { return font_size_; } |
99 int requested_font_size() const { return requested_font_size_; } | |
91 | 100 |
92 // Returns the average character width in dialog units. | 101 // Returns the average character width in dialog units. |
93 int GetDluBaseX(); | 102 int GetDluBaseX(); |
94 | 103 |
95 private: | 104 private: |
96 friend class base::RefCounted<HFontRef>; | 105 friend class base::RefCounted<HFontRef>; |
97 | 106 |
98 ~HFontRef(); | 107 ~HFontRef(); |
99 | 108 |
100 const HFONT hfont_; | 109 const HFONT hfont_; |
110 const int font_size_; | |
101 const int height_; | 111 const int height_; |
102 const int baseline_; | 112 const int baseline_; |
103 const int ave_char_width_; | 113 const int ave_char_width_; |
104 const int style_; | 114 const int style_; |
105 // Average character width in dialog units. This is queried lazily from the | 115 // Average character width in dialog units. This is queried lazily from the |
106 // system, with an initial value of -1 meaning it hasn't yet been queried. | 116 // system, with an initial value of -1 meaning it hasn't yet been queried. |
107 int dlu_base_x_; | 117 int dlu_base_x_; |
108 std::string font_name_; | 118 std::string font_name_; |
109 int font_size_; | 119 |
120 // If the requested font size is not possible for the font, |font_size_| | |
121 // will be different than |requested_font_size_|. This is stored separately | |
122 // so that code that increases the font size in a loop (as is done in some | |
123 // tests) will not cause the loop to get stuck on the same size. | |
124 int requested_font_size_; | |
msw
2012/04/30 17:40:01
If this condition is limited to tests, and it's kn
Alexei Svitkine (slow)
2012/04/30 17:49:14
It's not just test code, actually. I'm using it in
msw
2012/04/30 18:55:39
Oh wow, it took me a minute to fully grok why this
| |
110 | 125 |
111 DISALLOW_COPY_AND_ASSIGN(HFontRef); | 126 DISALLOW_COPY_AND_ASSIGN(HFontRef); |
112 }; | 127 }; |
113 | 128 |
114 // Initializes this object with a copy of the specified HFONT. | 129 // Initializes this object with a copy of the specified HFONT. |
115 void InitWithCopyOfHFONT(HFONT hfont); | 130 void InitWithCopyOfHFONT(HFONT hfont); |
116 | 131 |
117 // Initializes this object with the specified font name and size. | 132 // Initializes this object with the specified font name and size. |
118 void InitWithFontNameAndSize(const std::string& font_name, | 133 void InitWithFontNameAndSize(const std::string& font_name, |
119 int font_size); | 134 int font_size); |
(...skipping 13 matching lines...) Expand all Loading... | |
133 static HFontRef* base_font_ref_; | 148 static HFontRef* base_font_ref_; |
134 | 149 |
135 // Indirect reference to the HFontRef, which references the underlying HFONT. | 150 // Indirect reference to the HFontRef, which references the underlying HFONT. |
136 scoped_refptr<HFontRef> font_ref_; | 151 scoped_refptr<HFontRef> font_ref_; |
137 }; | 152 }; |
138 | 153 |
139 } // namespace gfx | 154 } // namespace gfx |
140 | 155 |
141 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ | 156 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ |
142 | 157 |
OLD | NEW |