OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_PLATFORM_FONT_WIN_ | 5 #ifndef GFX_PLATFORM_FONT_WIN_ |
6 #define GFX_PLATFORM_FONT_WIN_ | 6 #define GFX_PLATFORM_FONT_WIN_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "gfx/platform_font.h" | 10 #include "gfx/platform_font.h" |
11 | 11 |
12 namespace gfx { | 12 namespace gfx { |
13 | 13 |
14 class PlatformFontWin : public PlatformFont { | 14 class PlatformFontWin : public PlatformFont { |
15 public: | 15 public: |
16 PlatformFontWin(); | 16 PlatformFontWin(); |
17 explicit PlatformFontWin(const Font& other); | 17 explicit PlatformFontWin(const Font& other); |
18 explicit PlatformFontWin(NativeFont native_font); | 18 explicit PlatformFontWin(NativeFont native_font); |
19 PlatformFontWin(const std::wstring& font_name, | 19 PlatformFontWin(const string16& font_name, |
20 int font_size); | 20 int font_size); |
21 | 21 |
22 // Dialog units to pixels conversion. | 22 // Dialog units to pixels conversion. |
23 // See http://support.microsoft.com/kb/145994 for details. | 23 // See http://support.microsoft.com/kb/145994 for details. |
24 int horizontal_dlus_to_pixels(int dlus) const { | 24 int horizontal_dlus_to_pixels(int dlus) const { |
25 return dlus * font_ref_->dlu_base_x() / 4; | 25 return dlus * font_ref_->dlu_base_x() / 4; |
26 } | 26 } |
27 int vertical_dlus_to_pixels(int dlus) const { | 27 int vertical_dlus_to_pixels(int dlus) const { |
28 return dlus * font_ref_->height() / 8; | 28 return dlus * font_ref_->height() / 8; |
29 } | 29 } |
(...skipping 11 matching lines...) Expand all Loading... |
41 static AdjustFontCallback adjust_font_callback; | 41 static AdjustFontCallback adjust_font_callback; |
42 | 42 |
43 // Overridden from PlatformFont: | 43 // Overridden from PlatformFont: |
44 virtual Font DeriveFont(int size_delta, int style) const; | 44 virtual Font DeriveFont(int size_delta, int style) const; |
45 virtual int GetHeight() const; | 45 virtual int GetHeight() const; |
46 virtual int GetBaseline() const; | 46 virtual int GetBaseline() const; |
47 virtual int GetAverageCharacterWidth() const; | 47 virtual int GetAverageCharacterWidth() const; |
48 virtual int GetStringWidth(const string16& text) const; | 48 virtual int GetStringWidth(const string16& text) const; |
49 virtual int GetExpectedTextWidth(int length) const; | 49 virtual int GetExpectedTextWidth(int length) const; |
50 virtual int GetStyle() const; | 50 virtual int GetStyle() const; |
51 virtual const std::wstring& GetFontName() const; | 51 virtual string16 GetFontName() const; |
52 virtual int GetFontSize() const; | 52 virtual int GetFontSize() const; |
53 virtual NativeFont GetNativeFont() const; | 53 virtual NativeFont GetNativeFont() const; |
54 | 54 |
55 private: | 55 private: |
56 virtual ~PlatformFontWin() {} | 56 virtual ~PlatformFontWin() {} |
57 | 57 |
58 // Chrome text drawing bottoms out in the Windows GDI functions that take an | 58 // Chrome text drawing bottoms out in the Windows GDI functions that take an |
59 // HFONT (an opaque handle into Windows). To avoid lots of GDI object | 59 // HFONT (an opaque handle into Windows). To avoid lots of GDI object |
60 // allocation and destruction, Font indirectly refers to the HFONT by way of | 60 // allocation and destruction, Font indirectly refers to the HFONT by way of |
61 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. | 61 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. |
(...skipping 12 matching lines...) Expand all Loading... |
74 int style, | 74 int style, |
75 int dlu_base_x); | 75 int dlu_base_x); |
76 | 76 |
77 // Accessors | 77 // Accessors |
78 HFONT hfont() const { return hfont_; } | 78 HFONT hfont() const { return hfont_; } |
79 int height() const { return height_; } | 79 int height() const { return height_; } |
80 int baseline() const { return baseline_; } | 80 int baseline() const { return baseline_; } |
81 int ave_char_width() const { return ave_char_width_; } | 81 int ave_char_width() const { return ave_char_width_; } |
82 int style() const { return style_; } | 82 int style() const { return style_; } |
83 int dlu_base_x() const { return dlu_base_x_; } | 83 int dlu_base_x() const { return dlu_base_x_; } |
84 const std::wstring& font_name() const { return font_name_; } | 84 const string16& font_name() const { return font_name_; } |
85 | 85 |
86 private: | 86 private: |
87 friend class base::RefCounted<HFontRef>; | 87 friend class base::RefCounted<HFontRef>; |
88 | 88 |
89 ~HFontRef(); | 89 ~HFontRef(); |
90 | 90 |
91 const HFONT hfont_; | 91 const HFONT hfont_; |
92 const int height_; | 92 const int height_; |
93 const int baseline_; | 93 const int baseline_; |
94 const int ave_char_width_; | 94 const int ave_char_width_; |
95 const int style_; | 95 const int style_; |
96 // Constants used in converting dialog units to pixels. | 96 // Constants used in converting dialog units to pixels. |
97 const int dlu_base_x_; | 97 const int dlu_base_x_; |
98 std::wstring font_name_; | 98 string16 font_name_; |
99 | 99 |
100 DISALLOW_COPY_AND_ASSIGN(HFontRef); | 100 DISALLOW_COPY_AND_ASSIGN(HFontRef); |
101 }; | 101 }; |
102 | 102 |
103 // Initializes this object with a copy of the specified HFONT. | 103 // Initializes this object with a copy of the specified HFONT. |
104 void InitWithCopyOfHFONT(HFONT hfont); | 104 void InitWithCopyOfHFONT(HFONT hfont); |
105 | 105 |
106 // Initializes this object with the specified font name and size. | 106 // Initializes this object with the specified font name and size. |
107 void InitWithFontNameAndSize(const std::wstring& font_name, | 107 void InitWithFontNameAndSize(const string16& font_name, |
108 int font_size); | 108 int font_size); |
109 | 109 |
110 // Returns the base font ref. This should ONLY be invoked on the | 110 // Returns the base font ref. This should ONLY be invoked on the |
111 // UI thread. | 111 // UI thread. |
112 static HFontRef* GetBaseFontRef(); | 112 static HFontRef* GetBaseFontRef(); |
113 | 113 |
114 // Creates and returns a new HFONTRef from the specified HFONT. | 114 // Creates and returns a new HFONTRef from the specified HFONT. |
115 static HFontRef* CreateHFontRef(HFONT font); | 115 static HFontRef* CreateHFontRef(HFONT font); |
116 | 116 |
117 // Creates a new PlatformFontWin with the specified HFontRef. Used when | 117 // Creates a new PlatformFontWin with the specified HFontRef. Used when |
118 // constructing a Font from a HFONT we don't want to copy. | 118 // constructing a Font from a HFONT we don't want to copy. |
119 explicit PlatformFontWin(HFontRef* hfont_ref); | 119 explicit PlatformFontWin(HFontRef* hfont_ref); |
120 | 120 |
121 // Reference to the base font all fonts are derived from. | 121 // Reference to the base font all fonts are derived from. |
122 static HFontRef* base_font_ref_; | 122 static HFontRef* base_font_ref_; |
123 | 123 |
124 // Indirect reference to the HFontRef, which references the underlying HFONT. | 124 // Indirect reference to the HFontRef, which references the underlying HFONT. |
125 scoped_refptr<HFontRef> font_ref_; | 125 scoped_refptr<HFontRef> font_ref_; |
126 }; | 126 }; |
127 | 127 |
128 } // namespace gfx | 128 } // namespace gfx |
129 | 129 |
130 #endif // GFX_PLATFORM_FONT_WIN_ | 130 #endif // GFX_PLATFORM_FONT_WIN_ |
131 | 131 |
OLD | NEW |