diff options
-rw-r--r-- | build/android/pylib/gtest/filter/ui_unittests_disabled | 3 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc | 7 | ||||
-rw-r--r-- | ui/gfx/font.cc | 16 | ||||
-rw-r--r-- | ui/gfx/font.h | 20 | ||||
-rw-r--r-- | ui/gfx/font_list_impl.cc | 4 | ||||
-rw-r--r-- | ui/gfx/font_list_unittest.cc | 30 | ||||
-rw-r--r-- | ui/gfx/font_unittest.cc | 28 | ||||
-rw-r--r-- | ui/gfx/platform_font.h | 7 | ||||
-rw-r--r-- | ui/gfx/platform_font_ios.h | 2 | ||||
-rw-r--r-- | ui/gfx/platform_font_ios.mm | 9 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac.h | 2 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac.mm | 9 | ||||
-rw-r--r-- | ui/gfx/platform_font_mac_unittest.mm | 8 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.cc | 18 | ||||
-rw-r--r-- | ui/gfx/platform_font_pango.h | 2 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.cc | 13 | ||||
-rw-r--r-- | ui/gfx/platform_font_win.h | 2 | ||||
-rw-r--r-- | ui/gfx/platform_font_win_unittest.cc | 8 | ||||
-rw-r--r-- | ui/gfx/render_text_win.cc | 2 | ||||
-rw-r--r-- | ui/gfx/text_utils_unittest.cc | 12 |
20 files changed, 61 insertions, 141 deletions
diff --git a/build/android/pylib/gtest/filter/ui_unittests_disabled b/build/android/pylib/gtest/filter/ui_unittests_disabled index 841eebd8..de04dba 100644 --- a/build/android/pylib/gtest/filter/ui_unittests_disabled +++ b/build/android/pylib/gtest/filter/ui_unittests_disabled @@ -21,12 +21,11 @@ FontListTest.Fonts_FromFontWithNonNormalStyle FontListTest.Fonts_GetHeight_GetBaseline FontListTest.Fonts_GetStyle FontTest.Ascent -FontTest.AvgCharWidth FontTest.AvgWidths FontTest.CapHeight FontTest.GetActualFontNameForTesting FontTest.Height FontTest.LoadArial FontTest.LoadArialBold -FontTest.Widths ResourceBundleTest.DelegateGetFontList +TextUtilsTest.GetStringWidth diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc index 00bdb40..049bbca 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc @@ -32,12 +32,11 @@ #include "ui/base/gtk/gtk_screen_util.h" #include "ui/base/gtk/gtk_windowing.h" #include "ui/gfx/color_utils.h" -#include "ui/gfx/font.h" +#include "ui/gfx/geometry/rect.h" #include "ui/gfx/gtk_compat.h" #include "ui/gfx/gtk_util.h" #include "ui/gfx/image/cairo_cached_surface.h" #include "ui/gfx/image/image.h" -#include "ui/gfx/rect.h" #include "ui/gfx/skia_utils_gtk.h" namespace { @@ -84,7 +83,7 @@ const float kContentWidthPercentage = 0.7; const int kVerticalOffset = 3; // The size delta between the font used for the edit and the result rows. Passed -// to gfx::Font::DeriveFont. +// to gfx::Font::Derive. const int kEditFontAdjust = -1; // UTF-8 Left-to-right embedding. @@ -169,7 +168,7 @@ OmniboxPopupViewGtk::OmniboxPopupViewGtk(const gfx::Font& font, window_(gtk_window_new(GTK_WINDOW_POPUP)), layout_(NULL), theme_service_(NULL), - font_(font.DeriveFont(kEditFontAdjust)), + font_(font.Derive(kEditFontAdjust, font.GetStyle())), ignore_mouse_drag_(false), opened_(false) { // edit_model may be NULL in unit tests. diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc index 9eea73b..31f27b4 100644 --- a/ui/gfx/font.cc +++ b/ui/gfx/font.cc @@ -18,7 +18,7 @@ Font::Font() : platform_font_(PlatformFont::CreateDefault()) { Font::Font(const Font& other) : platform_font_(other.platform_font_) { } -gfx::Font& Font::operator=(const Font& other) { +Font& Font::operator=(const Font& other) { platform_font_ = other.platform_font_; return *this; } @@ -38,11 +38,7 @@ Font::Font(const std::string& font_name, int font_size) Font::~Font() { } -Font Font::DeriveFont(int size_delta) const { - return DeriveFont(size_delta, GetStyle()); -} - -Font Font::DeriveFont(int size_delta, int style) const { +Font Font::Derive(int size_delta, int style) const { return platform_font_->DeriveFont(size_delta, style); } @@ -58,14 +54,6 @@ int Font::GetCapHeight() const { return platform_font_->GetCapHeight(); } -int Font::GetAverageCharacterWidth() const { - return platform_font_->GetAverageCharacterWidth(); -} - -int Font::GetStringWidth(const base::string16& text) const { - return platform_font_->GetStringWidth(text); -} - int Font::GetExpectedTextWidth(int length) const { return platform_font_->GetExpectedTextWidth(length); } diff --git a/ui/gfx/font.h b/ui/gfx/font.h index 963dde7..5ab0f17 100644 --- a/ui/gfx/font.h +++ b/ui/gfx/font.h @@ -42,7 +42,7 @@ class GFX_EXPORT Font { // Creates a font that is a clone of another font object. Font(const Font& other); - gfx::Font& operator=(const Font& other); + Font& operator=(const Font& other); // Creates a font from the specified native font. explicit Font(NativeFont native_font); @@ -57,16 +57,11 @@ class GFX_EXPORT Font { ~Font(); // Returns a new Font derived from the existing font. - // |size_deta| is the size in pixels to add to the current font. For example, + // |size_delta| 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 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 UNDERLINE. - Font DeriveFont(int size_delta, int style) const; + Font Derive(int size_delta, int style) const; // Returns the number of vertical pixels needed to display characters from // the specified font. This may include some leading, i.e. height may be @@ -81,15 +76,8 @@ class GFX_EXPORT Font { // Returns the cap height of the font. int GetCapHeight() const; - // Returns the average character width for the font. - int GetAverageCharacterWidth() const; - - // Returns the number of horizontal pixels needed to display the specified - // string. - int GetStringWidth(const base::string16& text) const; - // Returns the expected number of horizontal pixels needed to display the - // specified length of characters. Call GetStringWidth() to retrieve the + // specified length of characters. Call gfx::GetStringWidth() to retrieve the // actual number. int GetExpectedTextWidth(int length) const; diff --git a/ui/gfx/font_list_impl.cc b/ui/gfx/font_list_impl.cc index b6e88948..b08d395 100644 --- a/ui/gfx/font_list_impl.cc +++ b/ui/gfx/font_list_impl.cc @@ -125,7 +125,7 @@ FontListImpl* FontListImpl::Derive(int size_delta, int font_style) const { if (!fonts_.empty()) { std::vector<Font> fonts = fonts_; for (size_t i = 0; i < fonts.size(); ++i) - fonts[i] = fonts[i].DeriveFont(size_delta, font_style); + fonts[i] = fonts[i].Derive(size_delta, font_style); return new FontListImpl(fonts); } @@ -209,7 +209,7 @@ const std::vector<Font>& FontListImpl::GetFonts() const { if (font_style_ == Font::NORMAL) fonts_.push_back(font); else - fonts_.push_back(font.DeriveFont(0, font_style_)); + fonts_.push_back(font.Derive(0, font_style_)); } } return fonts_; diff --git a/ui/gfx/font_list_unittest.cc b/ui/gfx/font_list_unittest.cc index b13e736..b96de46 100644 --- a/ui/gfx/font_list_unittest.cc +++ b/ui/gfx/font_list_unittest.cc @@ -63,14 +63,14 @@ TEST(FontListTest, FontDescString_FromFont) { TEST(FontListTest, FontDescString_FromFontWithNonNormalStyle) { // Test init from Font with non-normal style. Font font("Arial", 8); - FontList font_list = FontList(font.DeriveFont(2, Font::BOLD)); + FontList font_list = FontList(font.Derive(2, Font::BOLD)); EXPECT_EQ("Arial,Bold 10px", font_list.GetFontDescriptionString()); - font_list = FontList(font.DeriveFont(-2, Font::ITALIC)); + font_list = FontList(font.Derive(-2, Font::ITALIC)); EXPECT_EQ("Arial,Italic 6px", font_list.GetFontDescriptionString()); // "Underline" doesn't appear in the font description string. - font_list = FontList(font.DeriveFont(-4, Font::UNDERLINE)); + font_list = FontList(font.Derive(-4, Font::UNDERLINE)); EXPECT_EQ("Arial,4px", font_list.GetFontDescriptionString()); } @@ -79,8 +79,8 @@ TEST(FontListTest, FontDescString_FromFontVector) { Font font("Arial", 8); Font font_1("Sans serif", 10); std::vector<Font> fonts; - fonts.push_back(font.DeriveFont(0, Font::BOLD)); - fonts.push_back(font_1.DeriveFont(-2, Font::BOLD)); + fonts.push_back(font.Derive(0, Font::BOLD)); + fonts.push_back(font_1.Derive(-2, Font::BOLD)); FontList font_list = FontList(fonts); EXPECT_EQ("Arial,Sans serif,Bold 8px", font_list.GetFontDescriptionString()); } @@ -125,12 +125,12 @@ TEST(FontListTest, Fonts_FromFont) { TEST(FontListTest, Fonts_FromFontWithNonNormalStyle) { // Test init from Font with non-normal style. Font font("Arial", 8); - FontList font_list = FontList(font.DeriveFont(2, Font::BOLD)); + FontList font_list = FontList(font.Derive(2, Font::BOLD)); std::vector<Font> fonts = font_list.GetFonts(); EXPECT_EQ(1U, fonts.size()); EXPECT_EQ("Arial|10|bold", FontToString(fonts[0])); - font_list = FontList(font.DeriveFont(-2, Font::ITALIC)); + font_list = FontList(font.Derive(-2, Font::ITALIC)); fonts = font_list.GetFonts(); EXPECT_EQ(1U, fonts.size()); EXPECT_EQ("Arial|6|italic", FontToString(fonts[0])); @@ -141,8 +141,8 @@ TEST(FontListTest, Fonts_FromFontVector) { Font font("Arial", 8); Font font_1("Sans serif", 10); std::vector<Font> input_fonts; - input_fonts.push_back(font.DeriveFont(0, Font::BOLD)); - input_fonts.push_back(font_1.DeriveFont(-2, Font::BOLD)); + input_fonts.push_back(font.Derive(0, Font::BOLD)); + input_fonts.push_back(font_1.Derive(-2, Font::BOLD)); FontList font_list = FontList(input_fonts); const std::vector<Font>& fonts = font_list.GetFonts(); EXPECT_EQ(2U, fonts.size()); @@ -168,8 +168,8 @@ TEST(FontListTest, Fonts_FontVector_RoundTrip) { Font font("Arial", 8); Font font_1("Sans serif", 10); std::vector<Font> input_fonts; - input_fonts.push_back(font.DeriveFont(0, Font::BOLD)); - input_fonts.push_back(font_1.DeriveFont(-2, Font::BOLD)); + input_fonts.push_back(font.Derive(0, Font::BOLD)); + input_fonts.push_back(font_1.Derive(-2, Font::BOLD)); FontList font_list = FontList(input_fonts); const std::string& desc_string = font_list.GetFontDescriptionString(); @@ -201,8 +201,8 @@ TEST(FontListTest, Fonts_GetStyle) { fonts.push_back(gfx::Font("Sans serif", 8)); FontList font_list = FontList(fonts); EXPECT_EQ(Font::NORMAL, font_list.GetFontStyle()); - fonts[0] = fonts[0].DeriveFont(0, Font::ITALIC | Font::BOLD); - fonts[1] = fonts[1].DeriveFont(0, Font::ITALIC | Font::BOLD); + fonts[0] = fonts[0].Derive(0, Font::ITALIC | Font::BOLD); + fonts[1] = fonts[1].Derive(0, Font::ITALIC | Font::BOLD); font_list = FontList(fonts); EXPECT_EQ(Font::ITALIC | Font::BOLD, font_list.GetFontStyle()); } @@ -244,8 +244,8 @@ TEST(FontListTest, FontDescString_DeriveWithSizeDelta) { TEST(FontListTest, Fonts_DeriveWithSizeDelta) { std::vector<Font> fonts; - fonts.push_back(gfx::Font("Arial", 18).DeriveFont(0, Font::ITALIC)); - fonts.push_back(gfx::Font("Sans serif", 18).DeriveFont(0, Font::ITALIC)); + fonts.push_back(gfx::Font("Arial", 18).Derive(0, Font::ITALIC)); + fonts.push_back(gfx::Font("Sans serif", 18).Derive(0, Font::ITALIC)); FontList font_list = FontList(fonts); FontList derived = font_list.DeriveWithSizeDelta(-5); diff --git a/ui/gfx/font_unittest.cc b/ui/gfx/font_unittest.cc index 32216d6..9188735 100644 --- a/ui/gfx/font_unittest.cc +++ b/ui/gfx/font_unittest.cc @@ -15,8 +15,6 @@ #include "ui/gfx/platform_font_win.h" #endif -using base::ASCIIToUTF16; - namespace gfx { namespace { @@ -72,7 +70,7 @@ TEST_F(FontTest, LoadArial) { TEST_F(FontTest, LoadArialBold) { Font cf("Arial", 16); - Font bold(cf.DeriveFont(0, Font::BOLD)); + Font bold(cf.Derive(0, Font::BOLD)); NativeFont native = bold.GetNativeFont(); EXPECT_TRUE(native); EXPECT_EQ(bold.GetStyle(), Font::BOLD); @@ -108,22 +106,6 @@ TEST_F(FontTest, AvgWidths) { EXPECT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2)); } -TEST_F(FontTest, AvgCharWidth) { - Font cf("Arial", 16); - EXPECT_GT(cf.GetAverageCharacterWidth(), 0); -} - -TEST_F(FontTest, Widths) { - Font cf("Arial", 16); - EXPECT_EQ(cf.GetStringWidth(base::string16()), 0); - EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("a")), - cf.GetStringWidth(base::string16())); - EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("ab")), - cf.GetStringWidth(ASCIIToUTF16("a"))); - EXPECT_GT(cf.GetStringWidth(ASCIIToUTF16("abc")), - cf.GetStringWidth(ASCIIToUTF16("ab"))); -} - #if !defined(OS_WIN) // On Windows, Font::GetActualFontNameForTesting() doesn't work well for now. // http://crbug.com/327287 @@ -141,21 +123,21 @@ TEST_F(FontTest, GetActualFontNameForTesting) { #endif #if defined(OS_WIN) -TEST_F(FontTest, DeriveFontResizesIfSizeTooSmall) { +TEST_F(FontTest, DeriveResizesIfSizeTooSmall) { Font cf("Arial", 8); // The minimum font size is set to 5 in browser_main.cc. ScopedMinimumFontSizeCallback minimum_size(5); - Font derived_font = cf.DeriveFont(-4); + Font derived_font = cf.Derive(-4, cf.GetStyle()); EXPECT_EQ(5, derived_font.GetFontSize()); } -TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) { +TEST_F(FontTest, DeriveKeepsOriginalSizeIfHeightOk) { Font cf("Arial", 8); // The minimum font size is set to 5 in browser_main.cc. ScopedMinimumFontSizeCallback minimum_size(5); - Font derived_font = cf.DeriveFont(-2); + Font derived_font = cf.Derive(-2, cf.GetStyle()); 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 bf47098..27f39b7 100644 --- a/ui/gfx/platform_font.h +++ b/ui/gfx/platform_font.h @@ -45,13 +45,6 @@ class GFX_EXPORT PlatformFont : public base::RefCounted<PlatformFont> { // Returns the cap height of the font. virtual int GetCapHeight() const = 0; - // Returns the average character width for the font. - virtual int GetAverageCharacterWidth() const = 0; - - // Returns the number of horizontal pixels needed to display the specified - // string. - virtual int GetStringWidth(const base::string16& text) const = 0; - // Returns the expected number of horizontal pixels needed to display the // specified length of characters. Call GetStringWidth() to retrieve the // actual number. diff --git a/ui/gfx/platform_font_ios.h b/ui/gfx/platform_font_ios.h index ed93a6b..3323f82 100644 --- a/ui/gfx/platform_font_ios.h +++ b/ui/gfx/platform_font_ios.h @@ -21,8 +21,6 @@ class PlatformFontIOS : public PlatformFont { virtual int GetHeight() const OVERRIDE; virtual int GetBaseline() const OVERRIDE; virtual int GetCapHeight() const OVERRIDE; - virtual int GetAverageCharacterWidth() const OVERRIDE; - virtual int GetStringWidth(const base::string16& text) const OVERRIDE; virtual int GetExpectedTextWidth(int length) const OVERRIDE; virtual int GetStyle() const OVERRIDE; virtual std::string GetFontName() const OVERRIDE; diff --git a/ui/gfx/platform_font_ios.mm b/ui/gfx/platform_font_ios.mm index 32dcca4..aba239b 100644 --- a/ui/gfx/platform_font_ios.mm +++ b/ui/gfx/platform_font_ios.mm @@ -55,15 +55,6 @@ int PlatformFontIOS::GetCapHeight() const { return cap_height_; } -int PlatformFontIOS::GetAverageCharacterWidth() const { - return average_width_; -} - -int PlatformFontIOS::GetStringWidth(const base::string16& text) const { - NSString* ns_text = base::SysUTF16ToNSString(text); - return [ns_text sizeWithFont:GetNativeFont()].width; -} - int PlatformFontIOS::GetExpectedTextWidth(int length) const { return length * average_width_; } diff --git a/ui/gfx/platform_font_mac.h b/ui/gfx/platform_font_mac.h index 2f5f8de..8c46988 100644 --- a/ui/gfx/platform_font_mac.h +++ b/ui/gfx/platform_font_mac.h @@ -23,8 +23,6 @@ class PlatformFontMac : public PlatformFont { virtual int GetHeight() const OVERRIDE; virtual int GetBaseline() const OVERRIDE; virtual int GetCapHeight() const OVERRIDE; - virtual int GetAverageCharacterWidth() const OVERRIDE; - virtual int GetStringWidth(const base::string16& text) const OVERRIDE; virtual int GetExpectedTextWidth(int length) const OVERRIDE; virtual int GetStyle() const OVERRIDE; virtual std::string GetFontName() const OVERRIDE; diff --git a/ui/gfx/platform_font_mac.mm b/ui/gfx/platform_font_mac.mm index 877507e..53e3013 100644 --- a/ui/gfx/platform_font_mac.mm +++ b/ui/gfx/platform_font_mac.mm @@ -105,15 +105,6 @@ int PlatformFontMac::GetCapHeight() const { return cap_height_; } -int PlatformFontMac::GetAverageCharacterWidth() const { - return average_width_; -} - -int PlatformFontMac::GetStringWidth(const base::string16& text) const { - return Canvas::GetStringWidth(text, - Font(const_cast<PlatformFontMac*>(this))); -} - int PlatformFontMac::GetExpectedTextWidth(int length) const { return length * average_width_; } diff --git a/ui/gfx/platform_font_mac_unittest.mm b/ui/gfx/platform_font_mac_unittest.mm index 088d4a9..2584cb5 100644 --- a/ui/gfx/platform_font_mac_unittest.mm +++ b/ui/gfx/platform_font_mac_unittest.mm @@ -12,20 +12,20 @@ TEST(PlatformFontMacTest, DeriveFont) { gfx::Font base_font("Helvetica", 13); // Bold - gfx::Font bold_font(base_font.DeriveFont(0, gfx::Font::BOLD)); + gfx::Font bold_font(base_font.Derive(0, gfx::Font::BOLD)); NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:bold_font.GetNativeFont()]; EXPECT_EQ(NSBoldFontMask, traits); // Italic - gfx::Font italic_font(base_font.DeriveFont(0, gfx::Font::ITALIC)); + gfx::Font italic_font(base_font.Derive(0, gfx::Font::ITALIC)); traits = [[NSFontManager sharedFontManager] traitsOfFont:italic_font.GetNativeFont()]; EXPECT_EQ(NSItalicFontMask, traits); // Bold italic - gfx::Font bold_italic_font(base_font.DeriveFont(0, gfx::Font::BOLD | - gfx::Font::ITALIC)); + gfx::Font bold_italic_font(base_font.Derive( + 0, gfx::Font::BOLD | gfx::Font::ITALIC)); traits = [[NSFontManager sharedFontManager] traitsOfFont:bold_italic_font.GetNativeFont()]; EXPECT_EQ(static_cast<NSFontTraitMask>(NSBoldFontMask | NSItalicFontMask), diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc index c0c1914..956be2d 100644 --- a/ui/gfx/platform_font_pango.cc +++ b/ui/gfx/platform_font_pango.cc @@ -19,8 +19,10 @@ #include "third_party/skia/include/core/SkTypeface.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" +#include "ui/gfx/font_list.h" #include "ui/gfx/linux_font_delegate.h" #include "ui/gfx/pango_util.h" +#include "ui/gfx/text_utils.h" #if defined(TOOLKIT_GTK) #include <gdk/gdk.h> @@ -188,16 +190,6 @@ int PlatformFontPango::GetCapHeight() const { return cap_height_pixels_; } -int PlatformFontPango::GetAverageCharacterWidth() const { - const_cast<PlatformFontPango*>(this)->InitPangoMetrics(); - return SkScalarRoundToInt(average_width_pixels_); -} - -int PlatformFontPango::GetStringWidth(const base::string16& text) const { - return Canvas::GetStringWidth(text, - Font(const_cast<PlatformFontPango*>(this))); -} - int PlatformFontPango::GetExpectedTextWidth(int length) const { double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth(); return round(static_cast<float>(length) * char_width); @@ -392,8 +384,10 @@ void PlatformFontPango::InitPangoMetrics() { // Yes, this is how Microsoft recommends calculating the dialog unit // conversions. - const int text_width_pixels = GetStringWidth(base::ASCIIToUTF16( - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); + const int text_width_pixels = GetStringWidth( + base::ASCIIToUTF16( + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), + FontList(Font(this))); const double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2; average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels); } diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h index f79162c..548b3ac 100644 --- a/ui/gfx/platform_font_pango.h +++ b/ui/gfx/platform_font_pango.h @@ -50,8 +50,6 @@ class GFX_EXPORT PlatformFontPango : public PlatformFont { virtual int GetHeight() const OVERRIDE; virtual int GetBaseline() const OVERRIDE; virtual int GetCapHeight() const OVERRIDE; - virtual int GetAverageCharacterWidth() const OVERRIDE; - virtual int GetStringWidth(const base::string16& text) const OVERRIDE; virtual int GetExpectedTextWidth(int length) const OVERRIDE; virtual int GetStyle() const OVERRIDE; virtual std::string GetFontName() const OVERRIDE; diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc index 5f9a137..4acaf64 100644 --- a/ui/gfx/platform_font_win.cc +++ b/ui/gfx/platform_font_win.cc @@ -101,7 +101,7 @@ Font PlatformFontWin::DeriveFontWithHeight(int height, int style) { int font_height = font.GetHeight(); int font_size = font.GetFontSize(); while (font_height > height && font_size != min_font_size) { - font = font.DeriveFont(-1, style); + font = font.Derive(-1, style); if (font_height == font.GetHeight() && font_size == font.GetFontSize()) break; font_height = font.GetHeight(); @@ -145,18 +145,9 @@ int PlatformFontWin::GetCapHeight() const { return font_ref_->cap_height(); } -int PlatformFontWin::GetAverageCharacterWidth() const { - return font_ref_->ave_char_width(); -} - -int PlatformFontWin::GetStringWidth(const base::string16& text) const { - return Canvas::GetStringWidth(text, - Font(const_cast<PlatformFontWin*>(this))); -} - int PlatformFontWin::GetExpectedTextWidth(int length) const { return length * std::min(font_ref_->GetDluBaseX(), - GetAverageCharacterWidth()); + font_ref_->ave_char_width()); } int PlatformFontWin::GetStyle() const { diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h index 4826f77..2c6f51e 100644 --- a/ui/gfx/platform_font_win.h +++ b/ui/gfx/platform_font_win.h @@ -58,8 +58,6 @@ class GFX_EXPORT PlatformFontWin : public PlatformFont { virtual int GetHeight() const OVERRIDE; virtual int GetBaseline() const OVERRIDE; virtual int GetCapHeight() const OVERRIDE; - virtual int GetAverageCharacterWidth() const OVERRIDE; - virtual int GetStringWidth(const base::string16& text) const OVERRIDE; virtual int GetExpectedTextWidth(int length) const OVERRIDE; virtual int GetStyle() const OVERRIDE; virtual std::string GetFontName() const OVERRIDE; diff --git a/ui/gfx/platform_font_win_unittest.cc b/ui/gfx/platform_font_win_unittest.cc index bfbe9220..1ecdde1 100644 --- a/ui/gfx/platform_font_win_unittest.cc +++ b/ui/gfx/platform_font_win_unittest.cc @@ -20,15 +20,15 @@ gfx::Font AdjustFontSizeForHeight(const gfx::Font& base_font, Font expected_font = base_font; if (base_font.GetHeight() < target_height) { // Increase size while height is <= |target_height|. - Font larger_font = base_font.DeriveFont(1, 0); + Font larger_font = base_font.Derive(1, 0); while (larger_font.GetHeight() <= target_height) { expected_font = larger_font; - larger_font = larger_font.DeriveFont(1, 0); + larger_font = larger_font.Derive(1, 0); } } else if (expected_font.GetHeight() > target_height) { // Decrease size until height is <= |target_height|. do { - expected_font = expected_font.DeriveFont(-1, 0); + expected_font = expected_font.Derive(-1, 0); } while (expected_font.GetHeight() > target_height); } return expected_font; @@ -60,7 +60,7 @@ TEST(PlatformFontWinTest, DeriveFontWithHeight) { EXPECT_EQ(Font::BOLD, derived_font.GetStyle()); // Test that deriving from the new font has the expected result. - Font rederived_font = derived_font.DeriveFont(1, 0); + Font rederived_font = derived_font.Derive(1, 0); expected_font = Font(derived_font.GetFontName(), derived_font.GetFontSize() + 1); EXPECT_EQ(expected_font.GetFontName(), rederived_font.GetFontName()); diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index 58ee2c7..0f880c1 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -118,7 +118,7 @@ void DeriveFontIfNecessary(int font_size, const int current_style = (font->GetStyle() & kStyleMask); const int current_size = font->GetFontSize(); if (current_style != target_style || current_size != font_size) - *font = font->DeriveFont(font_size - current_size, target_style); + *font = font->Derive(font_size - current_size, target_style); } // Returns true if |c| is a Unicode BiDi control character. diff --git a/ui/gfx/text_utils_unittest.cc b/ui/gfx/text_utils_unittest.cc index 74c3ad4..bc4953f 100644 --- a/ui/gfx/text_utils_unittest.cc +++ b/ui/gfx/text_utils_unittest.cc @@ -6,6 +6,7 @@ #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/font_list.h" namespace gfx { namespace { @@ -59,5 +60,16 @@ TEST(TextUtilsTest, RemoveAcceleratorChar) { } } +TEST(TextUtilsTest, GetStringWidth) { + FontList font_list; + EXPECT_EQ(GetStringWidth(base::string16(), font_list), 0); + EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("a"), font_list), + GetStringWidth(base::string16(), font_list)); + EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("ab"), font_list), + GetStringWidth(base::ASCIIToUTF16("a"), font_list)); + EXPECT_GT(GetStringWidth(base::ASCIIToUTF16("abc"), font_list), + GetStringWidth(base::ASCIIToUTF16("ab"), font_list)); +} + } // namespace } // namespace gfx |