summaryrefslogtreecommitdiffstats
path: root/ui/gfx/platform_font_win.h
diff options
context:
space:
mode:
authorananta <ananta@chromium.org>2014-11-14 15:30:31 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-14 23:30:56 +0000
commit420c045db8d79e2b114ef6339e1adc4d614ec96e (patch)
treea5b8a208bb16e18e65d2a8f23f648078113a352c /ui/gfx/platform_font_win.h
parentdcaa24e38a7d9b62b0449d1a025d5b9d2a9e3c8a (diff)
downloadchromium_src-420c045db8d79e2b114ef6339e1adc4d614ec96e.zip
chromium_src-420c045db8d79e2b114ef6339e1adc4d614ec96e.tar.gz
chromium_src-420c045db8d79e2b114ef6339e1adc4d614ec96e.tar.bz2
Fixed font metrics calculations if DirectWrite font rendering is enabled in the browser.
Fixes as below:- 1. The current code in the PlatformFontWin::CreateHFontRefFromSkia function was ceiling the ascent and descent before calculating the height of the font. We now use std::round(Descent - ascent) to mirror the logic in skia and RenderTextHarfBuzz. 2. Skia does not return all metrics we need like the capHeight which indicates the height of capital letters. This information is returned by DirectWrite. I added code to retrieve the font metrics from DirectWrite in the CreateFontRefFromSkia function and used this to calculate the cap height. The rest of the metrics are retrieved from skia as before. 3. We use the capHeight calculated in step 2 to calculate the internal leading value which is the leading space in the bounds for the glyph. The internal leading value is not returned by DirectWrite. We use this to calculate the font size which ensures that characters now show up in the desired size instead of giant size as seen today. 4. I removed the set_use_skia_for_font_metrics function from PlatformFontWin and added a new function SetDirectWriteFactory which is used to pass in the global directwrite factory by content. We use the factory to retrieve metrics from DirectWrite. BUG=432086, 431377, 432105 Review URL: https://codereview.chromium.org/721163003 Cr-Commit-Position: refs/heads/master@{#304293}
Diffstat (limited to 'ui/gfx/platform_font_win.h')
-rw-r--r--ui/gfx/platform_font_win.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h
index 483dc89..f327978 100644
--- a/ui/gfx/platform_font_win.h
+++ b/ui/gfx/platform_font_win.h
@@ -13,6 +13,8 @@
#include "ui/gfx/gfx_export.h"
#include "ui/gfx/platform_font.h"
+__interface IDWriteFactory;
+
namespace gfx {
class GFX_EXPORT PlatformFontWin : public PlatformFont {
@@ -67,11 +69,9 @@ class GFX_EXPORT PlatformFontWin : public PlatformFont {
virtual const FontRenderParams& GetFontRenderParams() const override;
virtual NativeFont GetNativeFont() const override;
- // Called once during initialization if should be retrieving font metrics
- // from skia.
- static void set_use_skia_for_font_metrics(bool use_skia_for_font_metrics) {
- use_skia_for_font_metrics_ = use_skia_for_font_metrics;
- }
+ // Called once during initialization if we should be retrieving font metrics
+ // from skia and DirectWrite.
+ static void SetDirectWriteFactory(IDWriteFactory* factory);
private:
FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_UniscribeFallback);
@@ -168,8 +168,8 @@ class GFX_EXPORT PlatformFontWin : public PlatformFont {
// Creates and returns a new HFontRef from the specified HFONT using metrics
// from skia. Currently this is only used if we use DirectWrite for font
// metrics.
- static PlatformFontWin::HFontRef* CreateHFontRefFromSkia(
- HFONT gdi_font);
+ // |gdi_font| : Handle to the GDI font created via CreateFontIndirect.
+ static PlatformFontWin::HFontRef* CreateHFontRefFromSkia(HFONT gdi_font);
// Creates a new PlatformFontWin with the specified HFontRef. Used when
// constructing a Font from a HFONT we don't want to copy.
@@ -181,9 +181,8 @@ class GFX_EXPORT PlatformFontWin : public PlatformFont {
// Indirect reference to the HFontRef, which references the underlying HFONT.
scoped_refptr<HFontRef> font_ref_;
- // Set to true if font metrics are to be retrieved from skia. Defaults to
- // false.
- static bool use_skia_for_font_metrics_;
+ // Pointer to the global IDWriteFactory interface.
+ static IDWriteFactory* direct_write_factory_;
DISALLOW_COPY_AND_ASSIGN(PlatformFontWin);
};