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