summaryrefslogtreecommitdiffstats
path: root/gfx/font_win.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 21:07:17 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 21:07:17 +0000
commitbd0979609230cc9b1026e98f17f629bf0cfb6b8c (patch)
tree033fffdd50b98823f70a174e66dbe7af17ef99e1 /gfx/font_win.cc
parent26ef58b74eb86e3520542ecd1eb768d71a374601 (diff)
downloadchromium_src-bd0979609230cc9b1026e98f17f629bf0cfb6b8c.zip
chromium_src-bd0979609230cc9b1026e98f17f629bf0cfb6b8c.tar.gz
chromium_src-bd0979609230cc9b1026e98f17f629bf0cfb6b8c.tar.bz2
Make Font::GetStringWidth() a shortcut for gfx::Canvas::SizeStringInt() on Windows. These two functions already did the same thing on Mac and Linux. If they ever returned different results on Windows, it would lead to subtle bugs, since measurement and drawing would slightly disagree.
Clean up a few other things so that all three implementations of GetStringWidth() are identical. BUG=38717 TEST=none Review URL: http://codereview.chromium.org/1928003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46492 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/font_win.cc')
-rw-r--r--gfx/font_win.cc17
1 files changed, 4 insertions, 13 deletions
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;
}