| 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 | 7 |
| 8 #include <dwrite.h> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "ui/gfx/gfx_export.h" | 13 #include "ui/gfx/gfx_export.h" |
| 13 #include "ui/gfx/platform_font.h" | 14 #include "ui/gfx/platform_font.h" |
| 14 | 15 |
| 15 namespace gfx { | 16 namespace gfx { |
| 16 | 17 |
| 17 class GFX_EXPORT PlatformFontWin : public PlatformFont { | 18 class GFX_EXPORT PlatformFontWin : public PlatformFont { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 virtual int GetBaseline() const override; | 60 virtual int GetBaseline() const override; |
| 60 virtual int GetCapHeight() const override; | 61 virtual int GetCapHeight() const override; |
| 61 virtual int GetExpectedTextWidth(int length) const override; | 62 virtual int GetExpectedTextWidth(int length) const override; |
| 62 virtual int GetStyle() const override; | 63 virtual int GetStyle() const override; |
| 63 virtual std::string GetFontName() const override; | 64 virtual std::string GetFontName() const override; |
| 64 virtual std::string GetActualFontNameForTesting() const override; | 65 virtual std::string GetActualFontNameForTesting() const override; |
| 65 virtual int GetFontSize() const override; | 66 virtual int GetFontSize() const override; |
| 66 virtual const FontRenderParams& GetFontRenderParams() const override; | 67 virtual const FontRenderParams& GetFontRenderParams() const override; |
| 67 virtual NativeFont GetNativeFont() const override; | 68 virtual NativeFont GetNativeFont() const override; |
| 68 | 69 |
| 70 // Called once during initialization if we are using DirectWrite for fonts. |
| 71 static void set_direct_write_factory(IDWriteFactory* factory) { |
| 72 direct_write_factory_ = factory; |
| 73 } |
| 74 |
| 69 private: | 75 private: |
| 70 virtual ~PlatformFontWin() {} | 76 virtual ~PlatformFontWin() {} |
| 71 | 77 |
| 72 // Chrome text drawing bottoms out in the Windows GDI functions that take an | 78 // Chrome text drawing bottoms out in the Windows GDI functions that take an |
| 73 // HFONT (an opaque handle into Windows). To avoid lots of GDI object | 79 // HFONT (an opaque handle into Windows). To avoid lots of GDI object |
| 74 // allocation and destruction, Font indirectly refers to the HFONT by way of | 80 // allocation and destruction, Font indirectly refers to the HFONT by way of |
| 75 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. | 81 // an HFontRef. That is, every Font has an HFontRef, which has an HFONT. |
| 76 // | 82 // |
| 77 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. | 83 // HFontRef is reference counted. Upon deletion, it deletes the HFONT. |
| 78 // By making HFontRef maintain the reference to the HFONT, multiple | 84 // By making HFontRef maintain the reference to the HFONT, multiple |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 static HFontRef* CreateHFontRef(HFONT font); | 150 static HFontRef* CreateHFontRef(HFONT font); |
| 145 | 151 |
| 146 // Creates and returns a new HFONTRef from the specified HFONT. Uses provided | 152 // Creates and returns a new HFONTRef from the specified HFONT. Uses provided |
| 147 // |font_metrics| instead of calculating new one. | 153 // |font_metrics| instead of calculating new one. |
| 148 static HFontRef* CreateHFontRef(HFONT font, const TEXTMETRIC& font_metrics); | 154 static HFontRef* CreateHFontRef(HFONT font, const TEXTMETRIC& font_metrics); |
| 149 | 155 |
| 150 // Returns a largest derived Font whose height does not exceed the height of | 156 // Returns a largest derived Font whose height does not exceed the height of |
| 151 // |base_font|. | 157 // |base_font|. |
| 152 static Font DeriveWithCorrectedSize(HFONT base_font); | 158 static Font DeriveWithCorrectedSize(HFONT base_font); |
| 153 | 159 |
| 160 // Converts the GDI font identified by the |gdi_font| parameter to a |
| 161 // DirectWrite compatible HFONT, i.e with metrics compatible with |
| 162 // DirectWrite. |
| 163 // Returns the HFONT which is created from DirectWrite compatible font |
| 164 // metrics. |
| 165 static HFONT ConvertGDIFontToDirectWriteFont(HFONT gdi_font); |
| 166 |
| 154 // Creates a new PlatformFontWin with the specified HFontRef. Used when | 167 // Creates a new PlatformFontWin with the specified HFontRef. Used when |
| 155 // constructing a Font from a HFONT we don't want to copy. | 168 // constructing a Font from a HFONT we don't want to copy. |
| 156 explicit PlatformFontWin(HFontRef* hfont_ref); | 169 explicit PlatformFontWin(HFontRef* hfont_ref); |
| 157 | 170 |
| 158 // Reference to the base font all fonts are derived from. | 171 // Reference to the base font all fonts are derived from. |
| 159 static HFontRef* base_font_ref_; | 172 static HFontRef* base_font_ref_; |
| 160 | 173 |
| 161 // Indirect reference to the HFontRef, which references the underlying HFONT. | 174 // Indirect reference to the HFontRef, which references the underlying HFONT. |
| 162 scoped_refptr<HFontRef> font_ref_; | 175 scoped_refptr<HFontRef> font_ref_; |
| 163 | 176 |
| 177 // Pointer to the global IDWriteFactory interface. This is only set if we are |
| 178 // using DirectWrite for fonts. Defaults to NULL. |
| 179 static IDWriteFactory* direct_write_factory_; |
| 180 |
| 164 DISALLOW_COPY_AND_ASSIGN(PlatformFontWin); | 181 DISALLOW_COPY_AND_ASSIGN(PlatformFontWin); |
| 165 }; | 182 }; |
| 166 | 183 |
| 167 } // namespace gfx | 184 } // namespace gfx |
| 168 | 185 |
| 169 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ | 186 #endif // UI_GFX_PLATFORM_FONT_WIN_H_ |
| OLD | NEW |