diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 14:35:15 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-19 14:35:15 +0000 |
commit | c8703bbf78eb4a8b9bcd3ae9371298cdbb678653 (patch) | |
tree | 807b51c17e3f5c5f548d4a27e15cef97d47add50 /ui | |
parent | b4031640e8f24285115bf9244fd4c65b2157fa46 (diff) | |
download | chromium_src-c8703bbf78eb4a8b9bcd3ae9371298cdbb678653.zip chromium_src-c8703bbf78eb4a8b9bcd3ae9371298cdbb678653.tar.gz chromium_src-c8703bbf78eb4a8b9bcd3ae9371298cdbb678653.tar.bz2 |
Use pixel sizes in PlatformFontWin instead of point sizes.
This matches the PlatformFontPango implementation and the comments for
|GetFontSize()|. Update users of this API appropriately and update header
comments to clarify that sizes are in pixels. Also, a few misc cleanup
changes.
BUG=none
TEST=Existing unit tests pass. Font sizes in Chromium UI do not change.
Review URL: http://codereview.chromium.org/8267009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/font.h | 10 | ||||
-rw-r--r-- | ui/gfx/font_unittest.cc | 14 | ||||
-rw-r--r-- | ui/gfx/platform_font.h | 13 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac.h | 8 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.h | 11 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.cc | 19 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.h | 9 | ||||
-rw-r--r-- | ui/gfx/render_text_win.cc | 8 |
8 files changed, 34 insertions, 58 deletions
diff --git a/ui/gfx/font.h b/ui/gfx/font.h index b5f61d2..cdb9542 100644 --- a/ui/gfx/font.h +++ b/ui/gfx/font.h @@ -43,19 +43,19 @@ class UI_EXPORT Font { // object takes ownership of the PlatformFont object. explicit Font(PlatformFont* platform_font); - // Creates a font with the specified name and size. + // Creates a font with the specified name and size in pixels. Font(const string16& font_name, int font_size); ~Font(); // Returns a new Font derived from the existing font. - // size_deta is the size to add to the current font. For example, a value - // of 5 results in a font 5 units bigger than this font. + // |size_deta| is the size in pixels to add to the current font. For example, + // a value of 5 results in a font 5 pixels bigger than this font. Font DeriveFont(int size_delta) const; // Returns a new Font derived from the existing font. - // size_delta is the size to add to the current font. See the single - // argument version of this method for an example. + // |size_delta| is the size in pixels to add to the current font. See the + // single argument version of this method for an example. // The style parameter specifies the new style for the font, and is a // bitmask of the values: BOLD, ITALIC and UNDERLINED. Font DeriveFont(int size_delta, int style) const; diff --git a/ui/gfx/font_unittest.cc b/ui/gfx/font_unittest.cc index 75f7916..06e260e 100644 --- a/ui/gfx/font_unittest.cc +++ b/ui/gfx/font_unittest.cc @@ -114,27 +114,21 @@ TEST_F(FontTest, Widths) { #if defined(OS_WIN) TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { - // This creates font of height -8. - Font cf(L"Arial", 6); + Font cf(L"Arial", 8); // The minimum font size is set to 5 in browser_main.cc. ScopedMinimumFontSizeCallback minimum_size(5); Font derived_font = cf.DeriveFont(-4); - LOGFONT font_info; - GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info); - EXPECT_EQ(-5, font_info.lfHeight); + EXPECT_EQ(5, derived_font.GetFontSize()); } TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { - // This creates font of height -8. - Font cf(L"Arial", 6); + Font cf(L"Arial", 8); // The minimum font size is set to 5 in browser_main.cc. ScopedMinimumFontSizeCallback minimum_size(5); Font derived_font = cf.DeriveFont(-2); - LOGFONT font_info; - GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info); - EXPECT_EQ(-6, font_info.lfHeight); + EXPECT_EQ(6, derived_font.GetFontSize()); } #endif // defined(OS_WIN) diff --git a/ui/gfx/platform_font.h b/ui/gfx/platform_font.h index 38fc779..7e316fe 100644 --- a/ui/gfx/platform_font.h +++ b/ui/gfx/platform_font.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_GFX_PLATFORM_FONT_ -#define UI_GFX_PLATFORM_FONT_ +#ifndef UI_GFX_PLATFORM_FONT_H_ +#define UI_GFX_PLATFORM_FONT_H_ #pragma once #include <string> @@ -19,16 +19,17 @@ class Font; class UI_EXPORT PlatformFont : public base::RefCounted<PlatformFont> { public: - // Create an appropriate PlatformFont implementation. + // Creates an appropriate PlatformFont implementation. static PlatformFont* CreateDefault(); static PlatformFont* CreateFromFont(const Font& other); static PlatformFont* CreateFromNativeFont(NativeFont native_font); + // Creates a PlatformFont implementation with the specified |font_name| and + // |font_size| in pixels. static PlatformFont* CreateFromNameAndSize(const string16& font_name, int font_size); // Returns a new Font derived from the existing font. - // size_delta is the size to add to the current font. See the single - // argument version of this method for an example. + // |size_delta| is the size in pixels to add to the current font. // The style parameter specifies the new style for the font, and is a // bitmask of the values: BOLD, ITALIC and UNDERLINED. virtual Font DeriveFont(int size_delta, int style) const = 0; @@ -76,5 +77,5 @@ class UI_EXPORT PlatformFont : public base::RefCounted<PlatformFont> { } // namespace gfx -#endif // UI_GFX_PLATFORM_FONT_ +#endif // UI_GFX_PLATFORM_FONT_H_ diff --git a/ui/gfx/platform_font_mac.h b/ui/gfx/platform_font_mac.h index 9dd576f..6196137 100644 --- a/ui/gfx/platform_font_mac.h +++ b/ui/gfx/platform_font_mac.h @@ -1,9 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_GFX_PLATFORM_FONT_MAC_ -#define UI_GFX_PLATFORM_FONT_MAC_ +#ifndef UI_GFX_PLATFORM_FONT_MAC_H_ +#define UI_GFX_PLATFORM_FONT_MAC_H_ #pragma once #include "ui/gfx/platform_font.h" @@ -54,4 +54,4 @@ class PlatformFontMac : public PlatformFont { } // namespace gfx -#endif // UI_GFX_PLATFORM_FONT_MAC_ +#endif // UI_GFX_PLATFORM_FONT_MAC_H_ diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h index 41301bf..eedfad0 100644 --- a/ui/gfx/platform_font_pango.h +++ b/ui/gfx/platform_font_pango.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_GFX_PLATFORM_FONT_GTK_ -#define UI_GFX_PLATFORM_FONT_GTK_ +#ifndef UI_GFX_PLATFORM_FONT_PANGO_H_ +#define UI_GFX_PLATFORM_FONT_PANGO_H_ #pragma once #include "base/memory/scoped_ptr.h" @@ -20,8 +20,7 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { PlatformFontPango(); explicit PlatformFontPango(const Font& other); explicit PlatformFontPango(NativeFont native_font); - PlatformFontPango(const string16& font_name, - int font_size); + PlatformFontPango(const string16& font_name, int font_size); // Converts |gfx_font| to a new pango font. Free the returned font with // pango_font_description_free(). @@ -84,7 +83,7 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { // handle the reference counting, but without @typeface_ we would have to // cast the SkRefCnt from @typeface_helper_ every time. scoped_ptr<SkAutoUnref> typeface_helper_; - SkTypeface *typeface_; + SkTypeface* typeface_; // Additional information about the face // Skia actually expects a family name and not a font name. @@ -109,4 +108,4 @@ class UI_EXPORT PlatformFontPango : public PlatformFont { } // namespace gfx -#endif // UI_GFX_PLATFORM_FONT_GTK_ +#endif // UI_GFX_PLATFORM_FONT_PANGO_H_ diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc index 3402f0d..e8fb93d 100644 --- a/ui/gfx/platform_font_win.cc +++ b/ui/gfx/platform_font_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -124,16 +124,8 @@ string16 PlatformFontWin::GetFontName() const { int PlatformFontWin::GetFontSize() const { LOGFONT font_info; GetObject(font_ref_->hfont(), sizeof(LOGFONT), &font_info); - long lf_height = font_info.lfHeight; - HDC hdc = GetDC(NULL); - int device_caps = GetDeviceCaps(hdc, LOGPIXELSY); - int font_size = 0; - if (device_caps != 0) { - float font_size_float = -static_cast<float>(lf_height)*72/device_caps; - font_size = static_cast<int>(::ceil(font_size_float - 0.5)); - } - ReleaseDC(NULL, hdc); - return font_size; + DCHECK_LT(font_info.lfHeight, 0); + return -font_info.lfHeight; } NativeFont PlatformFontWin::GetNativeFont() const { @@ -152,10 +144,7 @@ void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) { void PlatformFontWin::InitWithFontNameAndSize(const string16& font_name, int font_size) { - HDC hdc = GetDC(NULL); - long lf_height = -MulDiv(font_size, GetDeviceCaps(hdc, LOGPIXELSY), 72); - ReleaseDC(NULL, hdc); - HFONT hf = ::CreateFont(lf_height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + HFONT hf = ::CreateFont(-font_size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, font_name.c_str()); font_ref_ = CreateHFontRef(hf); } diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h index e4be0de..56f3340 100644 --- a/ui/gfx/platform_font_win.h +++ b/ui/gfx/platform_font_win.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef UI_GFX_PLATFORM_FONT_WIN_ -#define UI_GFX_PLATFORM_FONT_WIN_ +#ifndef UI_GFX_PLATFORM_FONT_WIN_H_ +#define UI_GFX_PLATFORM_FONT_WIN_H_ #pragma once #include "base/memory/ref_counted.h" @@ -17,8 +17,7 @@ class UI_EXPORT PlatformFontWin : public PlatformFont { PlatformFontWin(); explicit PlatformFontWin(const Font& other); explicit PlatformFontWin(NativeFont native_font); - PlatformFontWin(const string16& font_name, - int font_size); + PlatformFontWin(const string16& font_name, int font_size); // Dialog units to pixels conversion. // See http://support.microsoft.com/kb/145994 for details. @@ -128,5 +127,5 @@ class UI_EXPORT PlatformFontWin : public PlatformFont { } // namespace gfx -#endif // UI_GFX_PLATFORM_FONT_WIN_ +#endif // UI_GFX_PLATFORM_FONT_WIN_H_ diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index 114a963..765de86 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -24,9 +24,6 @@ const int kMaxItems = 10000; // TODO(msw): Review memory use/failure? Max string length? Alternate approach? const int kMaxGlyphs = 100000; -// TODO(msw): Solve gfx/Uniscribe/Skia text size unit conversion issues. -const float kSkiaFontScale = 1.375; - } // namespace namespace gfx { @@ -607,7 +604,6 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) { paint.setLCDRenderText(true); SkPoint point(SkPoint::Make(SkIntToScalar(offset.x()), SkIntToScalar(display_rect().height() - offset.y()))); - RECT rect = display_rect().ToRECT(); scoped_array<SkPoint> pos; for (size_t i = 0; i < runs_.size(); ++i) { // Get the run specified by the visual-to-logical map. @@ -622,9 +618,7 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) { // |paint| adds its own ref. Release the ref from CreateFromName. typeface->unref(); } - // TODO(msw): Skia font size units? Set OmniboxViewViews gfx::Font size? - int font_size = run->font.GetFontSize(); - paint.setTextSize(SkFloatToScalar(font_size * kSkiaFontScale)); + paint.setTextSize(run->font.GetFontSize()); paint.setColor(run->foreground); // Based on WebCore::skiaDrawText. |