summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/gfx/chrome_canvas.cc2
-rw-r--r--app/gfx/chrome_canvas.h10
-rw-r--r--app/gfx/chrome_canvas_linux.cc18
-rw-r--r--app/gfx/chrome_canvas_win.cc6
-rw-r--r--app/gfx/chrome_font.h56
-rw-r--r--app/gfx/chrome_font_gtk.cc12
-rw-r--r--app/gfx/chrome_font_mac.mm37
-rw-r--r--app/gfx/chrome_font_skia.cc51
-rw-r--r--app/gfx/chrome_font_unittest.cc34
-rw-r--r--app/gfx/chrome_font_win.cc59
-rw-r--r--app/gfx/text_elider.cc6
-rw-r--r--app/gfx/text_elider.h6
-rw-r--r--app/gfx/text_elider_unittest.cc6
-rw-r--r--app/resource_bundle.cc14
-rw-r--r--app/resource_bundle.h22
-rw-r--r--app/win_util.cc4
-rw-r--r--app/win_util.h2
17 files changed, 182 insertions, 163 deletions
diff --git a/app/gfx/chrome_canvas.cc b/app/gfx/chrome_canvas.cc
index 9898168..4419b0f 100644
--- a/app/gfx/chrome_canvas.cc
+++ b/app/gfx/chrome_canvas.cc
@@ -217,7 +217,7 @@ void ChromeCanvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y,
}
void ChromeCanvas::DrawStringInt(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
const SkColor& color,
int x, int y,
int w, int h) {
diff --git a/app/gfx/chrome_canvas.h b/app/gfx/chrome_canvas.h
index 3f2932a..84c5320 100644
--- a/app/gfx/chrome_canvas.h
+++ b/app/gfx/chrome_canvas.h
@@ -14,8 +14,8 @@
#include "base/basictypes.h"
#include "skia/ext/platform_canvas.h"
-class ChromeFont;
namespace gfx {
+class Font;
class Rect;
}
@@ -152,13 +152,13 @@ class ChromeCanvas : public skia::PlatformCanvas {
// Draws text with the specified color, font and location. The text is
// aligned to the left, vertically centered, clipped to the region. If the
// text is too big, it is truncated and '...' is added to the end.
- void DrawStringInt(const std::wstring& text, const ChromeFont& font,
+ void DrawStringInt(const std::wstring& text, const gfx::Font& font,
const SkColor& color, int x, int y, int w, int h);
// Draws text with the specified color, font and location. The last argument
// specifies flags for how the text should be rendered. It can be one of
// TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
- void DrawStringInt(const std::wstring& text, const ChromeFont& font,
+ void DrawStringInt(const std::wstring& text, const gfx::Font& font,
const SkColor& color, int x, int y, int w, int h,
int flags);
@@ -167,7 +167,7 @@ class ChromeCanvas : public skia::PlatformCanvas {
// ClearType to be drawn to an otherwise transparenct bitmap for drag images.
// Drag images have only 1-bit of transparency, so we don't do any fancy
// blurring.
- void DrawStringWithHalo(const std::wstring& text, const ChromeFont& font,
+ void DrawStringWithHalo(const std::wstring& text, const gfx::Font& font,
const SkColor& text_color, const SkColor& halo_color,
int x, int y, int w, int h, int flags);
#endif
@@ -194,7 +194,7 @@ class ChromeCanvas : public skia::PlatformCanvas {
// Attempts to fit the text with the provided width and height. Increases
// height and then width as needed to make the text fit. This method
// supports multiple lines.
- static void SizeStringInt(const std::wstring& test, const ChromeFont& font,
+ static void SizeStringInt(const std::wstring& test, const gfx::Font& font,
int *width, int* height, int flags);
private:
diff --git a/app/gfx/chrome_canvas_linux.cc b/app/gfx/chrome_canvas_linux.cc
index d875f2d..12602d9 100644
--- a/app/gfx/chrome_canvas_linux.cc
+++ b/app/gfx/chrome_canvas_linux.cc
@@ -14,23 +14,23 @@
namespace {
// Returns a new pango font, free with pango_font_description_free().
-PangoFontDescription* PangoFontFromChromeFont(const ChromeFont& chrome_font) {
- ChromeFont font = chrome_font; // Copy so we can call non-const methods.
+PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font) {
+ gfx::Font font = gfx_font; // Copy so we can call non-const methods.
PangoFontDescription* pfd = pango_font_description_new();
pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str());
pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE);
switch (font.style()) {
- case ChromeFont::NORMAL:
+ case gfx::Font::NORMAL:
// Nothing to do, should already be PANGO_STYLE_NORMAL.
break;
- case ChromeFont::BOLD:
+ case gfx::Font::BOLD:
pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
break;
- case ChromeFont::ITALIC:
+ case gfx::Font::ITALIC:
pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
break;
- case ChromeFont::UNDERLINED:
+ case gfx::Font::UNDERLINED:
// TODO(deanm): How to do underlined? Where do we use it? Probably have
// to paint it ourselves, see pango_font_metrics_get_underline_position.
break;
@@ -53,7 +53,7 @@ ChromeCanvas::~ChromeCanvas() {
// static
void ChromeCanvas::SizeStringInt(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
int* width, int* height, int flags) {
NOTIMPLEMENTED();
}
@@ -72,7 +72,7 @@ void ChromeCanvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) {
}
void ChromeCanvas::DrawStringInt(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
const SkColor& color, int x, int y, int w,
int h, int flags) {
cairo_surface_t* surface = beginPlatformPaint();
@@ -112,7 +112,7 @@ void ChromeCanvas::DrawStringInt(const std::wstring& text,
std::string utf8 = WideToUTF8(text);
pango_layout_set_text(layout, utf8.data(), utf8.size());
- PangoFontDescription* desc = PangoFontFromChromeFont(font);
+ PangoFontDescription* desc = PangoFontFromGfxFont(font);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
diff --git a/app/gfx/chrome_canvas_win.cc b/app/gfx/chrome_canvas_win.cc
index e1d2da85a..267a510 100644
--- a/app/gfx/chrome_canvas_win.cc
+++ b/app/gfx/chrome_canvas_win.cc
@@ -129,7 +129,7 @@ ChromeCanvas::~ChromeCanvas() {
// static
void ChromeCanvas::SizeStringInt(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
int *width, int *height, int flags) {
HDC dc = GetDC(NULL);
HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.hfont()));
@@ -182,7 +182,7 @@ void ChromeCanvas::DrawStringInt(const std::wstring& text, HFONT font,
}
void ChromeCanvas::DrawStringInt(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
const SkColor& color,
int x, int y, int w, int h, int flags) {
DrawStringInt(text, font.hfont(), color, x, y, w, h, flags);
@@ -216,7 +216,7 @@ static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y,
}
void ChromeCanvas::DrawStringWithHalo(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
const SkColor& text_color,
const SkColor& halo_color_in,
int x, int y, int w, int h,
diff --git a/app/gfx/chrome_font.h b/app/gfx/chrome_font.h
index e0479f4..a4b14e9 100644
--- a/app/gfx/chrome_font.h
+++ b/app/gfx/chrome_font.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef APP_GFX_CHROME_FONT_H_
-#define APP_GFX_CHROME_FONT_H_
+#ifndef APP_GFX_FONT_H_
+#define APP_GFX_FONT_H_
#include "build/build_config.h"
@@ -37,9 +37,11 @@ typedef SkTypeface* NativeFont;
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
-// ChromeFont provides a wrapper around an underlying font. Copy and assignment
+namespace gfx {
+
+// Font provides a wrapper around an underlying font. Copy and assignment
// operators are explicitly allowed, and cheap.
-class ChromeFont {
+class Font {
public:
// The following constants indicate the font style.
enum {
@@ -49,16 +51,16 @@ class ChromeFont {
UNDERLINED = 4,
};
- // Creates a ChromeFont given font name (e.g. arial), font size (e.g. 12).
+ // Creates a Font given font name (e.g. arial), font size (e.g. 12).
// Skia actually expects a family name and not a font name.
- static ChromeFont CreateFont(const std::wstring& font_name, int font_size);
+ static Font CreateFont(const std::wstring& font_name, int font_size);
- ~ChromeFont() { }
+ ~Font() { }
// Returns a new Font derived from the existing font.
// size_deta is the size to add to the current font. For example, a value
// of 5 results in a font 5 units bigger than this font.
- ChromeFont DeriveFont(int size_delta) const {
+ Font DeriveFont(int size_delta) const {
return DeriveFont(size_delta, style());
}
@@ -67,7 +69,7 @@ class ChromeFont {
// 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 UNDERLINED.
- ChromeFont DeriveFont(int size_delta, int style) const;
+ Font DeriveFont(int size_delta, int style) const;
// Returns the number of vertical pixels needed to display characters from
// the specified font.
@@ -102,12 +104,12 @@ class ChromeFont {
NativeFont nativeFont() const;
// Creates a font with the default name and style.
- ChromeFont();
+ Font();
#if defined(OS_WIN)
- // Creates a ChromeFont from the specified HFONT. The supplied HFONT is
- // effectively copied.
- static ChromeFont CreateFont(HFONT hfont);
+ // Creates a Font from the specified HFONT. The supplied HFONT is effectively
+ // copied.
+ static Font CreateFont(HFONT hfont);
// Returns the handle to the underlying HFONT. This is used by ChromeCanvas to
// draw text.
@@ -124,8 +126,8 @@ class ChromeFont {
#elif defined(OS_LINUX)
// We need a copy constructor and assignment operator to deal with
// the Skia reference counting.
- ChromeFont(const ChromeFont& other);
- ChromeFont& operator=(const ChromeFont& other);
+ Font(const Font& other);
+ Font& operator=(const Font& other);
// Setup a Skia context to use the current typeface
void PaintSetup(SkPaint* paint) const;
#endif
@@ -135,14 +137,12 @@ class ChromeFont {
#if defined(OS_WIN)
// Chrome text drawing bottoms out in the Windows GDI functions that take an
// HFONT (an opaque handle into Windows). To avoid lots of GDI object
- // allocation and destruction, ChromeFont indirectly refers to the HFONT
- // by way of an HFontRef. That is, every ChromeFont has an HFontRef, which
- // has an HFONT.
+ // allocation and destruction, Font indirectly refers to the HFONT by way of
+ // an HFontRef. That is, every Font has an HFontRef, which has an HFONT.
//
// HFontRef is reference counted. Upon deletion, it deletes the HFONT.
// By making HFontRef maintain the reference to the HFONT, multiple
- // HFontRefs can share the same HFONT, and ChromeFont can provide value
- // semantics.
+ // HFontRefs can share the same HFONT, and Font can provide value semantics.
class HFontRef : public base::RefCounted<HFontRef> {
public:
// This constructor takes control of the HFONT, and will delete it when
@@ -182,7 +182,7 @@ class ChromeFont {
// Creates and returns a new HFONTRef from the specified HFONT.
static HFontRef* CreateHFontRef(HFONT font);
- explicit ChromeFont(HFontRef* font_ref) : font_ref_(font_ref) { }
+ explicit Font(HFontRef* font_ref) : font_ref_(font_ref) { }
// Reference to the base font all fonts are derived from.
static HFontRef* base_font_ref_;
@@ -190,15 +190,15 @@ class ChromeFont {
// Indirect reference to the HFontRef, which references the underlying HFONT.
scoped_refptr<HFontRef> font_ref_;
#elif defined(OS_LINUX)
- explicit ChromeFont(SkTypeface* typeface, const std::wstring& name,
- int size, int style);
+ explicit Font(SkTypeface* typeface, const std::wstring& name,
+ int size, int style);
// Calculate and cache the font metrics.
void calculateMetrics();
// Make |this| a copy of |other|.
- void CopyChromeFont(const ChromeFont& other);
+ void CopyFont(const Font& other);
// The default font, used for the default constructor.
- static ChromeFont* default_font_;
+ static Font* default_font_;
// These two both point to the same SkTypeface. We use the SkAutoUnref to
// handle the reference counting, but without @typeface_ we would have to
@@ -217,7 +217,7 @@ class ChromeFont {
int ascent_;
int avg_width_;
#elif defined(OS_MACOSX)
- explicit ChromeFont(const std::wstring& font_name, int font_size, int style);
+ explicit Font(const std::wstring& font_name, int font_size, int style);
// Calculate and cache the font metrics.
void calculateMetrics();
@@ -234,4 +234,6 @@ class ChromeFont {
};
-#endif // APP_GFX_CHROME_FONT_H_
+} // namespace gfx
+
+#endif // APP_GFX_FONT_H_
diff --git a/app/gfx/chrome_font_gtk.cc b/app/gfx/chrome_font_gtk.cc
index 39acf85..babeff5 100644
--- a/app/gfx/chrome_font_gtk.cc
+++ b/app/gfx/chrome_font_gtk.cc
@@ -9,7 +9,9 @@
#include "base/string_util.h"
-ChromeFont* ChromeFont::default_font_ = NULL;
+namespace gfx {
+
+Font* Font::default_font_ = NULL;
// Find the best match font for |family_name| in the same way as Skia
// to make sure CreateFont() successfully creates default font.
@@ -45,7 +47,7 @@ static std::wstring FindBestMatchFontFamilyName(const char* family_name) {
}
// Get the default gtk system font (name and size).
-ChromeFont::ChromeFont() {
+Font::Font() {
if (default_font_ == NULL) {
gtk_init(NULL, NULL);
GtkSettings* settings = gtk_settings_get_default();
@@ -72,7 +74,7 @@ ChromeFont::ChromeFont() {
// TODO(agl): remove this.
std::wstring font_family = FindBestMatchFontFamilyName(family_name);
- default_font_ = new ChromeFont(CreateFont(font_family, size / PANGO_SCALE));
+ default_font_ = new Font(CreateFont(font_family, size / PANGO_SCALE));
pango_font_description_free(desc);
g_free(font_name);
@@ -81,5 +83,7 @@ ChromeFont::ChromeFont() {
DCHECK(default_font_);
}
- CopyChromeFont(*default_font_);
+ CopyFont(*default_font_);
}
+
+} // namespace gfx
diff --git a/app/gfx/chrome_font_mac.mm b/app/gfx/chrome_font_mac.mm
index 87605ad..885c3b1 100644
--- a/app/gfx/chrome_font_mac.mm
+++ b/app/gfx/chrome_font_mac.mm
@@ -9,20 +9,21 @@
#include "base/logging.h"
#include "base/sys_string_conversions.h"
+namespace gfx {
+
// static
-ChromeFont ChromeFont::CreateFont(const std::wstring& font_name,
- int font_size) {
- return ChromeFont(font_name, font_size, NORMAL);
+Font Font::CreateFont(const std::wstring& font_name, int font_size) {
+ return Font(font_name, font_size, NORMAL);
}
-ChromeFont::ChromeFont(const std::wstring& font_name, int font_size, int style)
+Font::Font(const std::wstring& font_name, int font_size, int style)
: font_name_(font_name),
font_size_(font_size),
style_(style) {
calculateMetrics();
}
-ChromeFont::ChromeFont()
+Font::Font()
: font_size_([NSFont systemFontSize]),
style_(NORMAL) {
NSFont* system_font = [NSFont systemFontOfSize:font_size_];
@@ -30,30 +31,30 @@ ChromeFont::ChromeFont()
calculateMetrics();
}
-void ChromeFont::calculateMetrics() {
+void Font::calculateMetrics() {
NSFont* font = nativeFont();
height_ = [font xHeight];
ascent_ = [font ascender];
avg_width_ = [font boundingRectForGlyph:[font glyphWithName:@"x"]].size.width;
}
-ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
- return ChromeFont(font_name_, font_size_ + size_delta, style);
+Font Font::DeriveFont(int size_delta, int style) const {
+ return Font(font_name_, font_size_ + size_delta, style);
}
-int ChromeFont::height() const {
+int Font::height() const {
return height_;
}
-int ChromeFont::baseline() const {
+int Font::baseline() const {
return ascent_;
}
-int ChromeFont::ave_char_width() const {
+int Font::ave_char_width() const {
return avg_width_;
}
-int ChromeFont::GetStringWidth(const std::wstring& text) const {
+int Font::GetStringWidth(const std::wstring& text) const {
NSFont* font = nativeFont();
NSString* ns_string = base::SysWideToNSString(text);
NSDictionary* attributes =
@@ -62,26 +63,28 @@ int ChromeFont::GetStringWidth(const std::wstring& text) const {
return string_size.width;
}
-int ChromeFont::GetExpectedTextWidth(int length) const {
+int Font::GetExpectedTextWidth(int length) const {
return length * avg_width_;
}
-int ChromeFont::style() const {
+int Font::style() const {
return style_;
}
-std::wstring ChromeFont::FontName() {
+std::wstring Font::FontName() {
return font_name_;
}
-int ChromeFont::FontSize() {
+int Font::FontSize() {
return font_size_;
}
-NativeFont ChromeFont::nativeFont() const {
+NativeFont Font::nativeFont() const {
// TODO(pinkerton): apply |style_| to font.
// We could cache this, but then we'd have to conditionally change the
// dtor just for MacOS. Not sure if we want to/need to do that.
return [NSFont fontWithName:base::SysWideToNSString(font_name_)
size:font_size_];
}
+
+} // namespace gfx
diff --git a/app/gfx/chrome_font_skia.cc b/app/gfx/chrome_font_skia.cc
index 6c1b6d5..9622a70 100644
--- a/app/gfx/chrome_font_skia.cc
+++ b/app/gfx/chrome_font_skia.cc
@@ -10,17 +10,19 @@
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/core/SkPaint.h"
-ChromeFont::ChromeFont(const ChromeFont& other) {
- CopyChromeFont(other);
+namespace gfx {
+
+Font::Font(const Font& other) {
+ CopyFont(other);
}
-ChromeFont& ChromeFont::operator=(const ChromeFont& other) {
- CopyChromeFont(other);
+Font& Font::operator=(const Font& other) {
+ CopyFont(other);
return *this;
}
-ChromeFont::ChromeFont(SkTypeface* tf, const std::wstring& font_family,
- int font_size, int style)
+Font::Font(SkTypeface* tf, const std::wstring& font_family, int font_size,
+ int style)
: typeface_helper_(new SkAutoUnref(tf)),
typeface_(tf),
font_family_(font_family),
@@ -30,7 +32,7 @@ ChromeFont::ChromeFont(SkTypeface* tf, const std::wstring& font_family,
calculateMetrics();
}
-void ChromeFont::calculateMetrics() {
+void Font::calculateMetrics() {
SkPaint paint;
SkPaint::FontMetrics metrics;
@@ -52,7 +54,7 @@ void ChromeFont::calculateMetrics() {
}
}
-void ChromeFont::CopyChromeFont(const ChromeFont& other) {
+void Font::CopyFont(const Font& other) {
typeface_helper_.reset(new SkAutoUnref(other.typeface_));
typeface_ = other.typeface_;
typeface_->ref();
@@ -64,20 +66,19 @@ void ChromeFont::CopyChromeFont(const ChromeFont& other) {
avg_width_ = other.avg_width_;
}
-int ChromeFont::height() const {
+int Font::height() const {
return height_;
}
-int ChromeFont::baseline() const {
+int Font::baseline() const {
return ascent_;
}
-int ChromeFont::ave_char_width() const {
+int Font::ave_char_width() const {
return avg_width_;
}
-ChromeFont ChromeFont::CreateFont(const std::wstring& font_family,
- int font_size) {
+Font Font::CreateFont(const std::wstring& font_family, int font_size) {
DCHECK_GT(font_size, 0);
SkTypeface* tf = SkTypeface::CreateFromName(
@@ -85,10 +86,10 @@ ChromeFont ChromeFont::CreateFont(const std::wstring& font_family,
DCHECK(tf) << "Could not find font: " << base::SysWideToUTF8(font_family);
SkAutoUnref tf_helper(tf);
- return ChromeFont(tf, font_family, font_size, NORMAL);
+ return Font(tf, font_family, font_size, NORMAL);
}
-ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
+Font Font::DeriveFont(int size_delta, int style) const {
// If the delta is negative, if must not push the size below 1
if (size_delta < 0) {
DCHECK_LT(-size_delta, font_size_);
@@ -96,7 +97,7 @@ ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
if (style == style_) {
// Fast path, we just use the same typeface at a different size
- return ChromeFont(typeface_, font_family_, font_size_ + size_delta, style_);
+ return Font(typeface_, font_family_, font_size_ + size_delta, style_);
}
// If the style has changed we may need to load a new face
@@ -111,10 +112,10 @@ ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
static_cast<SkTypeface::Style>(skstyle));
SkAutoUnref tf_helper(tf);
- return ChromeFont(tf, font_family_, font_size_ + size_delta, skstyle);
+ return Font(tf, font_family_, font_size_ + size_delta, skstyle);
}
-void ChromeFont::PaintSetup(SkPaint* paint) const {
+void Font::PaintSetup(SkPaint* paint) const {
paint->setAntiAlias(false);
paint->setSubpixelText(false);
paint->setTextSize(SkFloatToScalar(font_size_));
@@ -124,7 +125,7 @@ void ChromeFont::PaintSetup(SkPaint* paint) const {
-SK_Scalar1/4 : 0);
}
-int ChromeFont::GetStringWidth(const std::wstring& text) const {
+int Font::GetStringWidth(const std::wstring& text) const {
const std::string utf8(base::SysWideToUTF8(text));
SkPaint paint;
@@ -142,23 +143,25 @@ int ChromeFont::GetStringWidth(const std::wstring& text) const {
return breadth;
}
-int ChromeFont::GetExpectedTextWidth(int length) const {
+int Font::GetExpectedTextWidth(int length) const {
return length * avg_width_;
}
-int ChromeFont::style() const {
+int Font::style() const {
return style_;
}
-std::wstring ChromeFont::FontName() {
+std::wstring Font::FontName() {
return font_family_;
}
-int ChromeFont::FontSize() {
+int Font::FontSize() {
return font_size_;
}
-NativeFont ChromeFont::nativeFont() const {
+NativeFont Font::nativeFont() const {
return typeface_;
}
+
+} // namespace gfx
diff --git a/app/gfx/chrome_font_unittest.cc b/app/gfx/chrome_font_unittest.cc
index 5ad7973..0bb840b4 100644
--- a/app/gfx/chrome_font_unittest.cc
+++ b/app/gfx/chrome_font_unittest.cc
@@ -8,46 +8,48 @@
namespace {
-class ChromeFontTest : public testing::Test {
+using gfx::Font;
+
+class FontTest : public testing::Test {
};
-TEST_F(ChromeFontTest, LoadArial) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
+TEST_F(FontTest, LoadArial) {
+ Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_TRUE(cf.nativeFont());
- ASSERT_EQ(cf.style(), ChromeFont::NORMAL);
+ ASSERT_EQ(cf.style(), Font::NORMAL);
ASSERT_EQ(cf.FontSize(), 16);
ASSERT_EQ(cf.FontName(), L"Arial");
}
-TEST_F(ChromeFontTest, LoadArialBold) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
- ChromeFont bold(cf.DeriveFont(0, ChromeFont::BOLD));
+TEST_F(FontTest, LoadArialBold) {
+ Font cf(Font::CreateFont(L"Arial", 16));
+ Font bold(cf.DeriveFont(0, Font::BOLD));
ASSERT_TRUE(bold.nativeFont());
- ASSERT_EQ(bold.style(), ChromeFont::BOLD);
+ ASSERT_EQ(bold.style(), Font::BOLD);
}
-TEST_F(ChromeFontTest, Ascent) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
+TEST_F(FontTest, Ascent) {
+ Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_GT(cf.baseline(), 2);
ASSERT_LT(cf.baseline(), 20);
}
-TEST_F(ChromeFontTest, Height) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
+TEST_F(FontTest, Height) {
+ Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_GT(cf.baseline(), 2);
ASSERT_LT(cf.baseline(), 20);
}
-TEST_F(ChromeFontTest, AvgWidths) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
+TEST_F(FontTest, AvgWidths) {
+ Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_EQ(cf.GetExpectedTextWidth(0), 0);
ASSERT_GT(cf.GetExpectedTextWidth(1), cf.GetExpectedTextWidth(0));
ASSERT_GT(cf.GetExpectedTextWidth(2), cf.GetExpectedTextWidth(1));
ASSERT_GT(cf.GetExpectedTextWidth(3), cf.GetExpectedTextWidth(2));
}
-TEST_F(ChromeFontTest, Widths) {
- ChromeFont cf(ChromeFont::CreateFont(L"Arial", 16));
+TEST_F(FontTest, Widths) {
+ Font cf(Font::CreateFont(L"Arial", 16));
ASSERT_EQ(cf.GetStringWidth(L""), 0);
ASSERT_GT(cf.GetStringWidth(L"a"), cf.GetStringWidth(L""));
ASSERT_GT(cf.GetStringWidth(L"ab"), cf.GetStringWidth(L"a"));
diff --git a/app/gfx/chrome_font_win.cc b/app/gfx/chrome_font_win.cc
index b5ddb18..1cbe500 100644
--- a/app/gfx/chrome_font_win.cc
+++ b/app/gfx/chrome_font_win.cc
@@ -15,92 +15,93 @@
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+namespace gfx {
+
/*static*/
-ChromeFont::HFontRef* ChromeFont::base_font_ref_;
+Font::HFontRef* Font::base_font_ref_;
// If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
// font is bold.
static const int kTextMetricWeightBold = 700;
//
-// ChromeFont
+// Font
//
-ChromeFont::ChromeFont()
+Font::Font()
: font_ref_(GetBaseFontRef()) {
}
-int ChromeFont::height() const {
+int Font::height() const {
return font_ref_->height();
}
-int ChromeFont::baseline() const {
+int Font::baseline() const {
return font_ref_->baseline();
}
-int ChromeFont::ave_char_width() const {
+int Font::ave_char_width() const {
return font_ref_->ave_char_width();
}
-int ChromeFont::GetExpectedTextWidth(int length) const {
+int Font::GetExpectedTextWidth(int length) const {
return length * std::min(font_ref_->dlu_base_x(), ave_char_width());
}
-int ChromeFont::style() const {
+int Font::style() const {
return font_ref_->style();
}
-NativeFont ChromeFont::nativeFont() const {
+NativeFont Font::nativeFont() const {
return hfont();
}
// static
-ChromeFont ChromeFont::CreateFont(HFONT font) {
+Font Font::CreateFont(HFONT font) {
DCHECK(font);
LOGFONT font_info;
GetObject(font, sizeof(LOGFONT), &font_info);
- return ChromeFont(CreateHFontRef(CreateFontIndirect(&font_info)));
+ return Font(CreateHFontRef(CreateFontIndirect(&font_info)));
}
-ChromeFont ChromeFont::CreateFont(const std::wstring& font_name,
- int font_size) {
+Font Font::CreateFont(const std::wstring& font_name, int font_size) {
HDC hdc = GetDC(NULL);
long lf_height = -MulDiv(font_size, GetDeviceCaps(hdc, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
HFONT hf = ::CreateFont(lf_height, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
font_name.c_str());
- return ChromeFont::CreateFont(hf);
+ return Font::CreateFont(hf);
}
// static
-ChromeFont::HFontRef* ChromeFont::GetBaseFontRef() {
+Font::HFontRef* Font::GetBaseFontRef() {
if (base_font_ref_ == NULL) {
NONCLIENTMETRICS metrics;
win_util::GetNonClientMetrics(&metrics);
l10n_util::AdjustUIFont(&metrics.lfMessageFont);
- // See comment in ChromeFont::DeriveFont() about font size.
+ // See comment in Font::DeriveFont() about font size.
// TODO(jungshik): Add a per-locale resource entry for the minimum
// font size and actually enforce the lower-bound. 5 is way too small
// for CJK, Thai, and Indian locales.
DCHECK_GE(abs(metrics.lfMessageFont.lfHeight), 5);
HFONT font = CreateFontIndirect(&metrics.lfMessageFont);
DLOG_ASSERT(font);
- base_font_ref_ = ChromeFont::CreateHFontRef(font);
+ base_font_ref_ = Font::CreateHFontRef(font);
// base_font_ref_ is global, up the ref count so it's never deleted.
base_font_ref_->AddRef();
}
return base_font_ref_;
}
-std::wstring ChromeFont::FontName() {
+std::wstring Font::FontName() {
LOGFONT font_info;
GetObject(hfont(), sizeof(LOGFONT), &font_info);
return (std::wstring(font_info.lfFaceName));
}
-int ChromeFont::FontSize() {
+int Font::FontSize() {
LOGFONT font_info;
GetObject(hfont(), sizeof(LOGFONT), &font_info);
long lf_height = font_info.lfHeight;
@@ -115,7 +116,7 @@ int ChromeFont::FontSize() {
return font_size;
}
-ChromeFont::HFontRef::HFontRef(HFONT hfont,
+Font::HFontRef::HFontRef(HFONT hfont,
int height,
int baseline,
int ave_char_width,
@@ -130,12 +131,12 @@ ChromeFont::HFontRef::HFontRef(HFONT hfont,
DLOG_ASSERT(hfont);
}
-ChromeFont::HFontRef::~HFontRef() {
+Font::HFontRef::~HFontRef() {
DeleteObject(hfont_);
}
-ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
+Font Font::DeriveFont(int size_delta, int style) const {
LOGFONT font_info;
GetObject(hfont(), sizeof(LOGFONT), &font_info);
// LOGFONT returns two types of font heights, negative is measured slightly
@@ -154,10 +155,10 @@ ChromeFont ChromeFont::DeriveFont(int size_delta, int style) const {
font_info.lfWeight = (style & BOLD) ? FW_BOLD : FW_NORMAL;
HFONT hfont = CreateFontIndirect(&font_info);
- return ChromeFont(CreateHFontRef(hfont));
+ return Font(CreateHFontRef(hfont));
}
-int ChromeFont::GetStringWidth(const std::wstring& text) 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()));
@@ -173,7 +174,7 @@ int ChromeFont::GetStringWidth(const std::wstring& text) const {
return width;
}
-ChromeFont::HFontRef* ChromeFont::CreateHFontRef(HFONT font) {
+Font::HFontRef* Font::CreateHFontRef(HFONT font) {
TEXTMETRIC font_metrics;
HDC screen_dc = GetDC(NULL);
HFONT previous_font = static_cast<HFONT>(SelectObject(screen_dc, font));
@@ -197,15 +198,17 @@ ChromeFont::HFontRef* ChromeFont::CreateHFontRef(HFONT font) {
std::max(1, static_cast<int>(font_metrics.tmAveCharWidth));
int style = 0;
if (font_metrics.tmItalic) {
- style |= ChromeFont::ITALIC;
+ style |= Font::ITALIC;
}
if (font_metrics.tmUnderlined) {
- style |= ChromeFont::UNDERLINED;
+ style |= Font::UNDERLINED;
}
if (font_metrics.tmWeight >= kTextMetricWeightBold) {
- style |= ChromeFont::BOLD;
+ style |= Font::BOLD;
}
return new HFontRef(font, height, baseline, ave_char_width, style,
dlu_base_x);
}
+
+} // namespace gfx
diff --git a/app/gfx/text_elider.cc b/app/gfx/text_elider.cc
index 6e20314..93653e0 100644
--- a/app/gfx/text_elider.cc
+++ b/app/gfx/text_elider.cc
@@ -44,7 +44,7 @@ static void AppendFormattedComponent(const std::string& spec,
// a rendered string is always the sum of the widths of its substrings. Also I
// suspect it could be made simpler.
std::wstring ElideUrl(const GURL& url,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width,
const std::wstring& languages) {
// Get a formatted string and corresponding parsing of the url.
@@ -271,7 +271,7 @@ std::wstring ElideUrl(const GURL& url,
}
std::wstring ElideFilename(const FilePath& filename,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width) {
int full_width = font.GetStringWidth(filename.ToWStringHack());
if (full_width <= available_pixel_width)
@@ -302,7 +302,7 @@ std::wstring ElideFilename(const FilePath& filename,
// This function adds an ellipsis at the end of the text if the text
// does not fit the given pixel width.
std::wstring ElideText(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width){
if (text.empty())
return text;
diff --git a/app/gfx/text_elider.h b/app/gfx/text_elider.h
index 61bfada..5872ed4 100644
--- a/app/gfx/text_elider.h
+++ b/app/gfx/text_elider.h
@@ -47,19 +47,19 @@ std::wstring GetCleanStringFromUrl(const GURL& url,
// is displayed properly in an RTL context. Please refer to
// http://crbug.com/6487 for more information.
std::wstring ElideUrl(const GURL& url,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width,
const std::wstring& languages);
std::wstring ElideText(const std::wstring& text,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width);
// Elide a filename to fit a given pixel width, with an emphasis on not hiding
// the extension unless we have to. If filename contains a path, the path will
// be removed if filename doesn't fit into available_pixel_width.
std::wstring ElideFilename(const FilePath& filename,
- const ChromeFont& font,
+ const gfx::Font& font,
int available_pixel_width);
// SortedDisplayURL maintains a string from a URL suitable for display to the
diff --git a/app/gfx/text_elider_unittest.cc b/app/gfx/text_elider_unittest.cc
index 0f17f9f..28691d7 100644
--- a/app/gfx/text_elider_unittest.cc
+++ b/app/gfx/text_elider_unittest.cc
@@ -37,7 +37,7 @@ struct TestData {
};
void RunTest(Testcase* testcases, size_t num_testcases) {
- static const ChromeFont font;
+ static const gfx::Font font;
for (size_t i = 0; i < num_testcases; ++i) {
const GURL url(testcases[i].input);
// Should we test with non-empty language list?
@@ -175,7 +175,7 @@ TEST(TextEliderTest, TestFilenameEliding) {
L"filename.mid" + kEllipsisStr + L".longext"}
};
- static const ChromeFont font;
+ static const gfx::Font font;
for (size_t i = 0; i < arraysize(testcases); ++i) {
FilePath filepath(testcases[i].input);
EXPECT_EQ(testcases[i].output, ElideFilename(filepath,
@@ -210,7 +210,7 @@ TEST(TextEliderTest, ElideTextLongStrings) {
data_scheme + std::wstring(156, L'a') + kEllipsisStr},
};
- const ChromeFont font;
+ const gfx::Font font;
int ellipsis_width = font.GetStringWidth(kEllipsisStr);
for (size_t i = 0; i < arraysize(testcases); ++i) {
// Compare sizes rather than actual contents because if the test fails,
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index 85fd0b9..96bc714 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -159,24 +159,24 @@ SkBitmap* ResourceBundle::GetBitmapNamed(int resource_id) {
void ResourceBundle::LoadFontsIfNecessary() {
AutoLock lock_scope(lock_);
if (!base_font_.get()) {
- base_font_.reset(new ChromeFont());
+ base_font_.reset(new gfx::Font());
- small_font_.reset(new ChromeFont());
+ small_font_.reset(new gfx::Font());
*small_font_ = base_font_->DeriveFont(-2);
- medium_font_.reset(new ChromeFont());
+ medium_font_.reset(new gfx::Font());
*medium_font_ = base_font_->DeriveFont(3);
- medium_bold_font_.reset(new ChromeFont());
+ medium_bold_font_.reset(new gfx::Font());
*medium_bold_font_ =
- base_font_->DeriveFont(3, base_font_->style() | ChromeFont::BOLD);
+ base_font_->DeriveFont(3, base_font_->style() | gfx::Font::BOLD);
- large_font_.reset(new ChromeFont());
+ large_font_.reset(new gfx::Font());
*large_font_ = base_font_->DeriveFont(8);
}
}
-ChromeFont ResourceBundle::GetFont(FontStyle style) {
+gfx::Font ResourceBundle::GetFont(FontStyle style) {
LoadFontsIfNecessary();
switch(style) {
case SmallFont:
diff --git a/app/resource_bundle.h b/app/resource_bundle.h
index 1ed44b0..ed17616 100644
--- a/app/resource_bundle.h
+++ b/app/resource_bundle.h
@@ -23,12 +23,14 @@
#if defined(OS_LINUX) || defined(OS_MACOSX)
namespace base {
class DataPack;
-};
+}
#endif
#if defined(OS_LINUX)
typedef struct _GdkPixbuf GdkPixbuf;
#endif
-class ChromeFont;
+namespace gfx{
+class Font;
+}
class SkBitmap;
typedef uint32 SkColor;
class StringPiece;
@@ -102,7 +104,7 @@ class ResourceBundle {
string16 GetLocalizedString(int message_id);
// Returns the font for the specified style.
- ChromeFont GetFont(FontStyle style);
+ gfx::Font GetFont(FontStyle style);
#if defined(OS_WIN)
// Loads and returns an icon from the theme dll.
@@ -154,7 +156,7 @@ class ResourceBundle {
// external data module.
void LoadResources(const std::wstring& pref_locale);
- // Initialize all the ChromeFont members if they haven't yet been initialized.
+ // Initialize all the gfx::Font members if they haven't yet been initialized.
void LoadFontsIfNecessary();
// Returns the full pathname of the locale file to load. May return an empty
@@ -192,12 +194,12 @@ class ResourceBundle {
#endif
// The various fonts used. Cached to avoid repeated GDI creation/destruction.
- scoped_ptr<ChromeFont> base_font_;
- scoped_ptr<ChromeFont> small_font_;
- scoped_ptr<ChromeFont> medium_font_;
- scoped_ptr<ChromeFont> medium_bold_font_;
- scoped_ptr<ChromeFont> large_font_;
- scoped_ptr<ChromeFont> web_font_;
+ scoped_ptr<gfx::Font> base_font_;
+ scoped_ptr<gfx::Font> small_font_;
+ scoped_ptr<gfx::Font> medium_font_;
+ scoped_ptr<gfx::Font> medium_bold_font_;
+ scoped_ptr<gfx::Font> large_font_;
+ scoped_ptr<gfx::Font> web_font_;
static ResourceBundle* g_shared_instance_;
diff --git a/app/win_util.cc b/app/win_util.cc
index 511b965..ace5f52 100644
--- a/app/win_util.cc
+++ b/app/win_util.cc
@@ -813,12 +813,12 @@ int MessageBox(HWND hwnd,
return ::MessageBox(hwnd, text_ptr, caption_ptr, actual_flags);
}
-ChromeFont GetWindowTitleFont() {
+gfx::Font GetWindowTitleFont() {
NONCLIENTMETRICS ncm;
win_util::GetNonClientMetrics(&ncm);
l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
- return ChromeFont::CreateFont(caption_font);
+ return gfx::Font::CreateFont(caption_font);
}
} // namespace win_util
diff --git a/app/win_util.h b/app/win_util.h
index 1c384c9..2b5bdce 100644
--- a/app/win_util.h
+++ b/app/win_util.h
@@ -285,7 +285,7 @@ int MessageBox(HWND hwnd,
UINT flags);
// Returns the system set window title font.
-ChromeFont GetWindowTitleFont();
+gfx::Font GetWindowTitleFont();
// The thickness of an auto-hide taskbar in pixels.
extern const int kAutoHideTaskbarThicknessPx;