summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/gfx/canvas_skia.cc7
-rw-r--r--ui/gfx/canvas_skia.h4
-rw-r--r--ui/gfx/font.cc5
-rw-r--r--ui/gfx/platform_font.h6
-rw-r--r--ui/gfx/platform_font_mac.h3
-rw-r--r--ui/gfx/platform_font_mac.mm10
-rw-r--r--ui/gfx/platform_font_pango.cc16
-rw-r--r--ui/gfx/platform_font_pango.h3
-rw-r--r--ui/gfx/platform_font_win.cc10
-rw-r--r--ui/gfx/platform_font_win.h3
10 files changed, 25 insertions, 42 deletions
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index b8ca78a..0520634 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -77,6 +77,13 @@ CanvasSkia::~CanvasSkia() {
}
// static
+int CanvasSkia::GetStringWidth(const string16& text, const gfx::Font& font) {
+ int width = 0, height = 0;
+ CanvasSkia::SizeStringInt(text, font, &width, &height, Canvas::NO_ELLIPSIS);
+ return width;
+}
+
+// static
int CanvasSkia::DefaultCanvasTextAlignment() {
if (!base::i18n::IsRTL())
return gfx::Canvas::TEXT_ALIGN_LEFT;
diff --git a/ui/gfx/canvas_skia.h b/ui/gfx/canvas_skia.h
index 263b823..6a8bd3b 100644
--- a/ui/gfx/canvas_skia.h
+++ b/ui/gfx/canvas_skia.h
@@ -70,6 +70,10 @@ class UI_EXPORT CanvasSkia : public Canvas {
int* width, int* height,
int flags);
+ // Returns the number of horizontal pixels needed to display the specified
+ // |text| with |font|.
+ static int GetStringWidth(const string16& text, const gfx::Font& font);
+
// Returns the default text alignment to be used when drawing text on a
// gfx::CanvasSkia based on the directionality of the system locale language.
// This function is used by gfx::Canvas::DrawStringInt when the text alignment
diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc
index 51e2ff4..fffaaf6 100644
--- a/ui/gfx/font.cc
+++ b/ui/gfx/font.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
#include "ui/gfx/font.h"
#include "base/utf_string_conversions.h"
+#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/platform_font.h"
namespace gfx {
@@ -59,7 +60,7 @@ int Font::GetAverageCharacterWidth() const {
}
int Font::GetStringWidth(const string16& text) const {
- return platform_font_->GetStringWidth(text);
+ return CanvasSkia::GetStringWidth(text, *this);
}
int Font::GetExpectedTextWidth(int length) const {
diff --git a/ui/gfx/platform_font.h b/ui/gfx/platform_font.h
index bd4e0ae..190b421 100644
--- a/ui/gfx/platform_font.h
+++ b/ui/gfx/platform_font.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -47,10 +47,6 @@ class UI_EXPORT PlatformFont : public base::RefCounted<PlatformFont> {
// 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 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_mac.h b/ui/gfx/platform_font_mac.h
index 60076152..c29b4c7 100644
--- a/ui/gfx/platform_font_mac.h
+++ b/ui/gfx/platform_font_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -24,7 +24,6 @@ class PlatformFontMac : public PlatformFont {
virtual int GetHeight() const OVERRIDE;
virtual int GetBaseline() const OVERRIDE;
virtual int GetAverageCharacterWidth() const OVERRIDE;
- virtual int GetStringWidth(const 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 ee12a33..898ab57 100644
--- a/ui/gfx/platform_font_mac.mm
+++ b/ui/gfx/platform_font_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -10,7 +10,6 @@
#include "base/memory/scoped_nsobject.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
-#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/font.h"
namespace gfx {
@@ -56,13 +55,6 @@ int PlatformFontMac::GetAverageCharacterWidth() const {
return average_width_;
}
-int PlatformFontMac::GetStringWidth(const string16& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontMac*>(this)),
- &width, &height, gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
int PlatformFontMac::GetExpectedTextWidth(int length) const {
return length * average_width_;
}
diff --git a/ui/gfx/platform_font_pango.cc b/ui/gfx/platform_font_pango.cc
index 201da16..9ce18d1 100644
--- a/ui/gfx/platform_font_pango.cc
+++ b/ui/gfx/platform_font_pango.cc
@@ -239,13 +239,6 @@ int PlatformFontPango::GetAverageCharacterWidth() const {
return SkScalarRound(average_width_pixels_);
}
-int PlatformFontPango::GetStringWidth(const string16& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontPango*>(this)),
- &width, &height, gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
int PlatformFontPango::GetExpectedTextWidth(int length) const {
double char_width = const_cast<PlatformFontPango*>(this)->GetAverageWidth();
return round(static_cast<float>(length) * char_width);
@@ -399,15 +392,16 @@ void PlatformFontPango::InitPangoMetrics() {
PANGO_SCALE;
// First get the Pango-based width (converting from Pango units to pixels).
- double pango_width_pixels =
+ const double pango_width_pixels =
pango_font_metrics_get_approximate_char_width(pango_metrics) /
PANGO_SCALE;
// Yes, this is how Microsoft recommends calculating the dialog unit
// conversions.
- int text_width_pixels = GetStringWidth(
- ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
- double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2;
+ const int text_width_pixels = CanvasSkia::GetStringWidth(
+ ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),
+ Font(this));
+ const double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2;
average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels);
pango_font_description_free(pango_desc);
}
diff --git a/ui/gfx/platform_font_pango.h b/ui/gfx/platform_font_pango.h
index 7f81939..3161966 100644
--- a/ui/gfx/platform_font_pango.h
+++ b/ui/gfx/platform_font_pango.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -44,7 +44,6 @@ class UI_EXPORT PlatformFontPango : public PlatformFont {
virtual int GetHeight() const OVERRIDE;
virtual int GetBaseline() const OVERRIDE;
virtual int GetAverageCharacterWidth() const OVERRIDE;
- virtual int GetStringWidth(const 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 04375aa..b188677 100644
--- a/ui/gfx/platform_font_win.cc
+++ b/ui/gfx/platform_font_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -13,7 +13,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win/win_util.h"
-#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/font.h"
namespace {
@@ -102,13 +101,6 @@ int PlatformFontWin::GetAverageCharacterWidth() const {
return font_ref_->ave_char_width();
}
-int PlatformFontWin::GetStringWidth(const string16& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontWin*>(this)),
- &width, &height, gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
int PlatformFontWin::GetExpectedTextWidth(int length) const {
return length * std::min(font_ref_->dlu_base_x(), GetAverageCharacterWidth());
}
diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h
index 6914b8a..17178de 100644
--- a/ui/gfx/platform_font_win.h
+++ b/ui/gfx/platform_font_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -46,7 +46,6 @@ class UI_EXPORT PlatformFontWin : public PlatformFont {
virtual int GetHeight() const OVERRIDE;
virtual int GetBaseline() const OVERRIDE;
virtual int GetAverageCharacterWidth() const OVERRIDE;
- virtual int GetStringWidth(const string16& text) const OVERRIDE;
virtual int GetExpectedTextWidth(int length) const OVERRIDE;
virtual int GetStyle() const OVERRIDE;
virtual std::string GetFontName() const OVERRIDE;