summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 14:32:02 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 14:32:02 +0000
commit7cc9e9f7f247ed853dc75cf8a1c3e508b745efec (patch)
tree6f5934f645c82fcbf1723b72a53a4ef3f25e4107 /ui/gfx
parentff8e0619ee011a2cb8d1fd4d51f7b7c7ceb59995 (diff)
downloadchromium_src-7cc9e9f7f247ed853dc75cf8a1c3e508b745efec.zip
chromium_src-7cc9e9f7f247ed853dc75cf8a1c3e508b745efec.tar.gz
chromium_src-7cc9e9f7f247ed853dc75cf8a1c3e508b745efec.tar.bz2
Re-add GetStringWidth to PlatformFont, and use that from Font
Font is supposed to be an abstraction, so shouldn't depend directly on Skia. Partially reverses http://codereview.chromium.org/9117009 BUG=None TEST=None Review URL: http://codereview.chromium.org/9465002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/font.cc3
-rw-r--r--ui/gfx/platform_font.h4
-rw-r--r--ui/gfx/platform_font_mac.h1
-rw-r--r--ui/gfx/platform_font_mac.mm6
-rw-r--r--ui/gfx/platform_font_pango.cc10
-rw-r--r--ui/gfx/platform_font_pango.h1
-rw-r--r--ui/gfx/platform_font_win.cc6
-rw-r--r--ui/gfx/platform_font_win.h1
8 files changed, 27 insertions, 5 deletions
diff --git a/ui/gfx/font.cc b/ui/gfx/font.cc
index fffaaf6..424d585 100644
--- a/ui/gfx/font.cc
+++ b/ui/gfx/font.cc
@@ -5,7 +5,6 @@
#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 {
@@ -60,7 +59,7 @@ int Font::GetAverageCharacterWidth() const {
}
int Font::GetStringWidth(const string16& text) const {
- return CanvasSkia::GetStringWidth(text, *this);
+ return platform_font_->GetStringWidth(text);
}
int Font::GetExpectedTextWidth(int length) const {
diff --git a/ui/gfx/platform_font.h b/ui/gfx/platform_font.h
index 190b421..b90d05b 100644
--- a/ui/gfx/platform_font.h
+++ b/ui/gfx/platform_font.h
@@ -47,6 +47,10 @@ 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 c29b4c7..6e89cb3 100644
--- a/ui/gfx/platform_font_mac.h
+++ b/ui/gfx/platform_font_mac.h
@@ -24,6 +24,7 @@ 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 898ab57..d433f7b 100644
--- a/ui/gfx/platform_font_mac.mm
+++ b/ui/gfx/platform_font_mac.mm
@@ -10,6 +10,7 @@
#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 {
@@ -55,6 +56,11 @@ int PlatformFontMac::GetAverageCharacterWidth() const {
return average_width_;
}
+int PlatformFontMac::GetStringWidth(const string16& text) const {
+ return CanvasSkia::GetStringWidth(text,
+ Font(const_cast<PlatformFontMac*>(this)));
+}
+
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 5037829..70e7680 100644
--- a/ui/gfx/platform_font_pango.cc
+++ b/ui/gfx/platform_font_pango.cc
@@ -234,6 +234,11 @@ int PlatformFontPango::GetAverageCharacterWidth() const {
return SkScalarRound(average_width_pixels_);
}
+int PlatformFontPango::GetStringWidth(const string16& text) const {
+ return CanvasSkia::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);
@@ -393,9 +398,8 @@ void PlatformFontPango::InitPangoMetrics() {
// Yes, this is how Microsoft recommends calculating the dialog unit
// conversions.
- const int text_width_pixels = CanvasSkia::GetStringWidth(
- ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"),
- Font(this));
+ const int text_width_pixels = GetStringWidth(
+ ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
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 3161966..7e154f5 100644
--- a/ui/gfx/platform_font_pango.h
+++ b/ui/gfx/platform_font_pango.h
@@ -44,6 +44,7 @@ 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 1cca192..532b7b4 100644
--- a/ui/gfx/platform_font_win.cc
+++ b/ui/gfx/platform_font_win.cc
@@ -13,6 +13,7 @@
#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 {
@@ -101,6 +102,11 @@ int PlatformFontWin::GetAverageCharacterWidth() const {
return font_ref_->ave_char_width();
}
+int PlatformFontWin::GetStringWidth(const string16& text) const {
+ return CanvasSkia::GetStringWidth(text,
+ Font(const_cast<PlatformFontWin*>(this)));
+}
+
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 ce23105..0e770fb 100644
--- a/ui/gfx/platform_font_win.h
+++ b/ui/gfx/platform_font_win.h
@@ -46,6 +46,7 @@ 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;