diff options
-rw-r--r-- | gfx/canvas_mac.mm | 10 | ||||
-rw-r--r-- | gfx/font_mac.mm | 11 | ||||
-rw-r--r-- | gfx/font_skia.cc | 5 | ||||
-rw-r--r-- | gfx/font_win.cc | 17 | ||||
-rw-r--r-- | views/controls/label.cc | 6 |
5 files changed, 22 insertions, 27 deletions
diff --git a/gfx/canvas_mac.mm b/gfx/canvas_mac.mm index bffa91f..87ff09b 100644 --- a/gfx/canvas_mac.mm +++ b/gfx/canvas_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -28,7 +28,13 @@ Canvas::~Canvas() { void Canvas::SizeStringInt(const std::wstring& text, const gfx::Font& font, int *width, int *height, int flags) { - *width = font.GetStringWidth(text); + NSFont* native_font = font.nativeFont(); + NSString* ns_string = base::SysWideToNSString(text); + NSDictionary* attributes = + [NSDictionary dictionaryWithObject:native_font + forKey:NSFontAttributeName]; + NSSize string_size = [ns_string sizeWithAttributes:attributes]; + *width = string_size.width; *height = font.height(); } diff --git a/gfx/font_mac.mm b/gfx/font_mac.mm index fcc85833..9a1695b 100644 --- a/gfx/font_mac.mm +++ b/gfx/font_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -58,12 +58,9 @@ int Font::ave_char_width() const { } int Font::GetStringWidth(const std::wstring& text) const { - NSFont* font = nativeFont(); - NSString* ns_string = base::SysWideToNSString(text); - NSDictionary* attributes = - [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; - NSSize string_size = [ns_string sizeWithAttributes:attributes]; - return string_size.width; + int width = 0, height = 0; + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); + return width; } int Font::GetExpectedTextWidth(int length) const { diff --git a/gfx/font_skia.cc b/gfx/font_skia.cc index fffc53e..97a3c85 100644 --- a/gfx/font_skia.cc +++ b/gfx/font_skia.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -177,8 +177,7 @@ void Font::PaintSetup(SkPaint* paint) const { int Font::GetStringWidth(const std::wstring& text) const { int width = 0, height = 0; - - Canvas::SizeStringInt(text, *this, &width, &height, 0); + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); return width; } diff --git a/gfx/font_win.cc b/gfx/font_win.cc index b55057c..4d4d28e 100644 --- a/gfx/font_win.cc +++ b/gfx/font_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -12,6 +12,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "base/win_util.h" +#include "gfx/canvas.h" namespace gfx { @@ -169,18 +170,8 @@ Font Font::DeriveFont(int size_delta, int style) const { } int Font::GetStringWidth(const std::wstring& text) const { - int width = 0; - HDC dc = GetDC(NULL); - HFONT previous_font = static_cast<HFONT>(SelectObject(dc, hfont())); - SIZE size; - if (GetTextExtentPoint32(dc, text.c_str(), static_cast<int>(text.size()), - &size)) { - width = size.cx; - } else { - width = 0; - } - SelectObject(dc, previous_font); - ReleaseDC(NULL, dc); + int width = 0, height = 0; + Canvas::SizeStringInt(text, *this, &width, &height, gfx::Canvas::NO_ELLIPSIS); return width; } diff --git a/views/controls/label.cc b/views/controls/label.cc index a9d74ac..2aff154 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -342,8 +342,10 @@ gfx::Rect Label::GetTextBounds() const { case ALIGN_LEFT: break; case ALIGN_CENTER: - // We put any extra margin pixel on the left rather than the right, since - // GetTextExtentPoint32() can report a value one too large on the right. + // We put any extra margin pixel on the left rather than the right. We + // used to do this because measurement on Windows used + // GetTextExtentPoint32(), which could report a value one too large on the + // right; we now use DrawText(), and who knows if it can also do this. text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2, 0); break; |