summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/gfx/font_util.cc2
-rw-r--r--app/resource_bundle.cc4
-rw-r--r--app/resource_bundle_dummy.cc10
-rw-r--r--app/text_elider_unittest.cc1
-rw-r--r--app/win_util.cc2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc16
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm10
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm6
-rw-r--r--chrome/browser/browser_main.cc5
-rw-r--r--chrome/browser/chromeos/options/internet_page_view.cc2
-rw-r--r--chrome/browser/chromeos/wm_overview_title.cc4
-rw-r--r--chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm5
-rw-r--r--chrome/browser/cocoa/download_item_cell.mm10
-rw-r--r--chrome/browser/cocoa/location_bar/ev_bubble_decoration.mm4
-rw-r--r--chrome/browser/cocoa/status_bubble_mac.mm5
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.cc2
-rw-r--r--chrome/browser/gtk/options/fonts_page_gtk.cc4
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.cc4
-rw-r--r--chrome/browser/gtk/tabs/tab_renderer_gtk.h1
-rw-r--r--chrome/browser/remoting/setup_flow.cc2
-rw-r--r--chrome/browser/sync/sync_setup_flow.cc2
-rw-r--r--chrome/browser/views/about_chrome_view.cc4
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc6
-rw-r--r--chrome/browser/views/constrained_window_win.cc2
-rw-r--r--chrome/browser/views/download_item_view.cc17
-rw-r--r--chrome/browser/views/frame/app_panel_browser_frame_view.cc2
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.cc4
-rw-r--r--chrome/browser/views/location_bar/location_bar_view.cc2
-rw-r--r--chrome/browser/views/options/advanced_contents_view.cc2
-rw-r--r--chrome/browser/views/options/content_exceptions_table_view.cc2
-rw-r--r--chrome/browser/views/options/fonts_page_view.cc15
-rw-r--r--chrome/browser/views/options/languages_page_view.cc4
-rw-r--r--chrome/browser/views/sad_tab_view.cc2
-rw-r--r--chrome/browser/views/shell_dialogs_win.cc2
-rw-r--r--chrome/browser/views/status_bubble_views.cc2
-rw-r--r--chrome/browser/views/tabs/base_tab.cc2
-rw-r--r--chrome/browser/views/theme_install_bubble_view.cc2
-rw-r--r--chrome/common/extensions/extension_action.cc2
-rw-r--r--gfx/canvas_skia_linux.cc11
-rw-r--r--gfx/canvas_skia_mac.mm6
-rw-r--r--gfx/canvas_skia_win.cc4
-rw-r--r--gfx/font.cc85
-rw-r--r--gfx/font.h268
-rw-r--r--gfx/font_gtk.cc152
-rw-r--r--gfx/font_mac.mm92
-rw-r--r--gfx/font_skia.cc255
-rw-r--r--gfx/font_unittest.cc42
-rw-r--r--gfx/font_win.cc216
-rw-r--r--gfx/gfx.gyp12
-rw-r--r--gfx/native_widget_types.h7
-rw-r--r--gfx/platform_font.h78
-rw-r--r--gfx/platform_font_gtk.cc434
-rw-r--r--gfx/platform_font_gtk.h111
-rw-r--r--gfx/platform_font_mac.h57
-rw-r--r--gfx/platform_font_mac.mm142
-rw-r--r--gfx/platform_font_win.cc268
-rw-r--r--gfx/platform_font_win.h131
-rw-r--r--printing/printed_document.cc2
-rw-r--r--printing/printed_document_win.cc4
-rw-r--r--views/controls/button/checkbox.cc2
-rw-r--r--views/controls/button/native_button.cc25
-rw-r--r--views/controls/button/native_button_gtk.cc9
-rw-r--r--views/controls/button/native_button_win.cc2
-rw-r--r--views/controls/button/text_button.cc2
-rw-r--r--views/controls/combobox/native_combobox_win.cc2
-rw-r--r--views/controls/label.cc6
-rw-r--r--views/controls/label_unittest.cc6
-rw-r--r--views/controls/link.cc8
-rw-r--r--views/controls/listbox/native_listbox_win.cc2
-rw-r--r--views/controls/menu/menu_config_win.cc2
-rw-r--r--views/controls/menu/menu_item_view_gtk.cc6
-rw-r--r--views/controls/menu/menu_item_view_win.cc4
-rw-r--r--views/controls/menu/menu_win.cc7
-rw-r--r--views/controls/menu/native_menu_gtk.cc5
-rw-r--r--views/controls/menu/native_menu_win.cc7
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_win.cc2
-rw-r--r--views/controls/table/table_view.cc2
-rw-r--r--views/controls/textfield/gtk_views_entry.cc2
-rw-r--r--views/controls/textfield/gtk_views_textview.cc2
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc3
-rw-r--r--views/controls/textfield/native_textfield_win.cc3
-rw-r--r--views/controls/textfield/textfield.cc2
-rw-r--r--views/drag_utils.cc6
-rw-r--r--views/view_text_utils.cc12
-rw-r--r--views/widget/tooltip_manager_gtk.cc2
-rw-r--r--views/widget/tooltip_manager_win.cc4
-rw-r--r--views/window/custom_frame_view.cc4
89 files changed, 1570 insertions, 1127 deletions
diff --git a/app/gfx/font_util.cc b/app/gfx/font_util.cc
index 61e1b52dd..1c3cfca 100644
--- a/app/gfx/font_util.cc
+++ b/app/gfx/font_util.cc
@@ -27,7 +27,7 @@ int GetLocalizedContentsHeightForFont(int row_resource_id,
double lines = 0;
base::StringToDouble(WideToUTF8(l10n_util::GetString(row_resource_id)),
&lines);
- int height = static_cast<int>(font.height() * lines);
+ int height = static_cast<int>(font.GetHeight() * lines);
DCHECK_GT(height, 0);
return height;
}
diff --git a/app/resource_bundle.cc b/app/resource_bundle.cc
index 25b0d81..4b97c90 100644
--- a/app/resource_bundle.cc
+++ b/app/resource_bundle.cc
@@ -172,7 +172,7 @@ void ResourceBundle::LoadFontsIfNecessary() {
bold_font_.reset(new gfx::Font());
*bold_font_ =
- base_font_->DeriveFont(0, base_font_->style() | gfx::Font::BOLD);
+ base_font_->DeriveFont(0, base_font_->GetStyle() | gfx::Font::BOLD);
small_font_.reset(new gfx::Font());
*small_font_ = base_font_->DeriveFont(-2);
@@ -182,7 +182,7 @@ void ResourceBundle::LoadFontsIfNecessary() {
medium_bold_font_.reset(new gfx::Font());
*medium_bold_font_ =
- base_font_->DeriveFont(3, base_font_->style() | gfx::Font::BOLD);
+ base_font_->DeriveFont(3, base_font_->GetStyle() | gfx::Font::BOLD);
large_font_.reset(new gfx::Font());
*large_font_ = base_font_->DeriveFont(8);
diff --git a/app/resource_bundle_dummy.cc b/app/resource_bundle_dummy.cc
index 9a22afd..e93df01 100644
--- a/app/resource_bundle_dummy.cc
+++ b/app/resource_bundle_dummy.cc
@@ -9,6 +9,7 @@
#include "base/lock.h"
#include "base/logging.h"
#include "gfx/font.h"
+#include "gfx/platform_font_win.h"
ResourceBundle* ResourceBundle::g_shared_instance_ = NULL;
@@ -16,9 +17,12 @@ ResourceBundle* ResourceBundle::g_shared_instance_ = NULL;
// files. The font members of ResourceBundle are never initialized in our code
// so this destructor is never called.
namespace gfx {
- Font::HFontRef::~HFontRef() {
- NOTREACHED();
- }
+Font::~Font() {
+ NOTREACHED();
+}
+PlatformFontWin::HFontRef::~HFontRef() {
+ NOTREACHED();
+}
}
diff --git a/app/text_elider_unittest.cc b/app/text_elider_unittest.cc
index 253eb13..627c556 100644
--- a/app/text_elider_unittest.cc
+++ b/app/text_elider_unittest.cc
@@ -5,6 +5,7 @@
#include "app/text_elider.h"
#include "base/file_path.h"
#include "base/i18n/rtl.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "gfx/font.h"
#include "googleurl/src/gurl.h"
diff --git a/app/win_util.cc b/app/win_util.cc
index e760a24..302f2b8 100644
--- a/app/win_util.cc
+++ b/app/win_util.cc
@@ -541,7 +541,7 @@ gfx::Font GetWindowTitleFont() {
win_util::GetNonClientMetrics(&ncm);
l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
- return gfx::Font::CreateFont(caption_font);
+ return gfx::Font(caption_font);
}
void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) {
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index fcf882e..2fa3540 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -920,5 +920,5 @@ std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
// static
NSFont* AutocompleteEditViewMac::GetFieldFont() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- return rb.GetFont(ResourceBundle::BaseFont).nativeFont();
+ return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont();
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 189723a..f7204a5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -429,7 +429,7 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
Create(hwnd, 0, 0, 0, l10n_util::GetExtendedStyles());
SetReadOnly(popup_window_mode_);
- SetFont(font_.hfont());
+ SetFont(font_.GetNativeFont());
// NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as
// of Rich Edit 2.0 onward.
@@ -438,7 +438,7 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
// Get the metrics for the font.
HDC dc = ::GetDC(NULL);
- SelectObject(dc, font_.hfont());
+ SelectObject(dc, font_.GetNativeFont());
TEXTMETRIC tm = {0};
GetTextMetrics(dc, &tm);
const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its
@@ -446,12 +446,12 @@ AutocompleteEditViewWin::AutocompleteEditViewWin(
// provide a true value for a font's
// x-height in its text metrics, so we
// approximate.
- font_x_height_ = static_cast<int>((static_cast<float>(font_.baseline() -
+ font_x_height_ = static_cast<int>((static_cast<float>(font_.GetBaseline() -
tm.tmInternalLeading) * kXHeightRatio) + 0.5);
// The distance from the top of the field to the desired baseline of the
// rendered text.
const int kTextBaseline = popup_window_mode_ ? 15 : 18;
- font_y_adjustment_ = kTextBaseline - font_.baseline();
+ font_y_adjustment_ = kTextBaseline - font_.GetBaseline();
// Get the number of twips per pixel, which we need below to offset our text
// by the desired number of pixels.
@@ -2149,10 +2149,10 @@ void AutocompleteEditViewWin::DrawSlashForInsecureScheme(
const int kAdditionalSpaceOutsideFont =
static_cast<int>(ceil(kStrokeWidthPixels * 1.5f));
const CRect scheme_rect(PosFromChar(insecure_scheme_component_.begin).x,
- font_top + font_.baseline() - font_x_height_ -
+ font_top + font_.GetBaseline() - font_x_height_ -
kAdditionalSpaceOutsideFont,
PosFromChar(insecure_scheme_component_.end()).x,
- font_top + font_.baseline() +
+ font_top + font_.GetBaseline() +
kAdditionalSpaceOutsideFont);
// Clip to the portion we care about and translate to canvas coordinates
@@ -2233,7 +2233,7 @@ void AutocompleteEditViewWin::DrawDropHighlight(
const CRect highlight_rect(highlight_x,
highlight_y,
highlight_x + 1,
- highlight_y + font_.height());
+ highlight_y + font_.GetHeight());
// Clip the highlight to the region being painted.
CRect clip_rect;
@@ -2430,7 +2430,7 @@ void AutocompleteEditViewWin::RepaintDropHighlight(int position) {
if ((position != -1) && (position <= GetTextLength())) {
const POINT min_loc(PosFromChar(position));
const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_,
- min_loc.x + 2, font_.height() + font_y_adjustment_};
+ min_loc.x + 2, font_.GetHeight() + font_y_adjustment_};
InvalidateRect(&highlight_bounds, false);
}
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 0d5a526..89929b2 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -285,9 +285,9 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
// plumb a gfx::Font through. This is because popup windows have a
// different font size, although we could just derive that font here.
// For now, force the font size.
- gfx::Font font = gfx::Font::CreateFont(
- gfx::Font().FontName(), browser_defaults::kAutocompletePopupFontSize);
- PangoFontDescription* pfd = gfx::Font::PangoFontFromGfxFont(font);
+ gfx::Font font(gfx::Font().GetFontName(),
+ browser_defaults::kAutocompletePopupFontSize);
+ PangoFontDescription* pfd = font.GetNativeFont();
pango_layout_set_font_description(layout_, pfd);
pango_font_description_free(pfd);
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index 76e1bd1..5adc929 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -103,7 +103,7 @@ NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString(
// Start out with a string using the default style info.
NSString* s = base::SysWideToNSString(matchString);
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
- font.nativeFont(), NSFontAttributeName,
+ font.GetNativeFont(), NSFontAttributeName,
textColor, NSForegroundColorAttributeName,
nil];
NSMutableAttributedString* as =
@@ -128,7 +128,7 @@ NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString(
if (0 != (i->style & ACMatchClassification::MATCH)) {
if (!boldFont) {
NSFontManager* fontManager = [NSFontManager sharedFontManager];
- boldFont = [fontManager convertFont:font.nativeFont()
+ boldFont = [fontManager convertFont:font.GetNativeFont()
toHaveTrait:NSBoldFontMask];
}
[as addAttribute:NSFontAttributeName value:boldFont range:range];
@@ -197,7 +197,7 @@ NSAttributedString* AutocompletePopupViewMac::MatchText(
NSDictionary* attributes =
[NSDictionary dictionaryWithObjectsAndKeys:
- font.nativeFont(), NSFontAttributeName,
+ font.GetNativeFont(), NSFontAttributeName,
ContentTextColor(), NSForegroundColorAttributeName,
nil];
NSString* rawEnDash = [NSString stringWithFormat:@" %C ", 0x2013];
@@ -405,8 +405,8 @@ void AutocompletePopupViewMac::UpdatePopupAppearance() {
// The popup's font is a slightly smaller version of the field's.
NSFont* fieldFont = AutocompleteEditViewMac::GetFieldFont();
const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust;
- gfx::Font resultFont = gfx::Font::CreateFont(
- base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize);
+ gfx::Font resultFont(base::SysNSStringToWide([fieldFont fontName]),
+ static_cast<int>(resultFontSize));
AutocompleteMatrix* matrix = [popup_ contentView];
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
index a715248..b6be8dc 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
@@ -24,7 +24,7 @@ class AutocompletePopupViewMacTest : public PlatformTest {
// These are here because there is no autorelease pool for the
// constructor.
color_ = [NSColor blackColor];
- font_ = gfx::Font::CreateFont(
+ font_ = gfx::Font(
base::SysNSStringToWide([[NSFont userFontOfSize:12] fontName]), 12);
}
@@ -427,7 +427,7 @@ TEST_F(AutocompletePopupViewMacTest, ElideString) {
const float kNarrow = 20.0;
NSDictionary* attributes =
- [NSDictionary dictionaryWithObject:font_.nativeFont()
+ [NSDictionary dictionaryWithObject:font_.GetNativeFont()
forKey:NSFontAttributeName];
scoped_nsobject<NSMutableAttributedString> as(
[[NSMutableAttributedString alloc] initWithString:contents
@@ -476,7 +476,7 @@ TEST_F(AutocompletePopupViewMacTest, MatchTextElide) {
// Figure out the width of the contents.
NSDictionary* attributes =
- [NSDictionary dictionaryWithObject:font_.nativeFont()
+ [NSDictionary dictionaryWithObject:font_.GetNativeFont()
forKey:NSFontAttributeName];
const float contentsWidth = [contents sizeWithAttributes:attributes].width;
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index eff0c33..b5fa926 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -123,6 +123,7 @@
#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/shell_util.h"
#include "chrome/installer/util/version.h"
+#include "gfx/platform_font_win.h"
#include "net/base/net_util.h"
#include "net/base/sdch_manager.h"
#include "printing/printed_document.h"
@@ -706,8 +707,8 @@ void InitializeToolkit() {
views::ViewsDelegate::views_delegate = new ChromeViewsDelegate;
#if defined(OS_WIN)
- gfx::Font::adjust_font_callback = &AdjustUIFont;
- gfx::Font::get_minimum_font_size_callback = &GetMinimumFontSize;
+ gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
+ gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
// Init common control sex.
INITCOMMONCONTROLSEX config;
diff --git a/chrome/browser/chromeos/options/internet_page_view.cc b/chrome/browser/chromeos/options/internet_page_view.cc
index 2a934f9..91de274 100644
--- a/chrome/browser/chromeos/options/internet_page_view.cc
+++ b/chrome/browser/chromeos/options/internet_page_view.cc
@@ -525,7 +525,7 @@ class InternetPageContentView : public SettingsPageView {
InternetPageContentView::InternetPageContentView(Profile* profile)
: SettingsPageView(profile) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- line_height_ = rb.GetFont(ResourceBundle::BaseFont).height();
+ line_height_ = rb.GetFont(ResourceBundle::BaseFont).GetHeight();
}
void InternetPageContentView::RefreshContents() {
diff --git a/chrome/browser/chromeos/wm_overview_title.cc b/chrome/browser/chromeos/wm_overview_title.cc
index 17bdb40..0325065 100644
--- a/chrome/browser/chromeos/wm_overview_title.cc
+++ b/chrome/browser/chromeos/wm_overview_title.cc
@@ -43,9 +43,9 @@ namespace {
// given value (well, unless the font at size 1 is taller than the
// given value).
Font FindFontThisHigh(int pixels, Font base) {
- Font font = Font::CreateFont(base.FontName(), 1);
+ Font font(base.GetFontName(), 1);
Font last_font = font;
- while (font.height() < pixels) {
+ while (font.GetHeight() < pixels) {
last_font = font;
font = font.DeriveFont(1, Font::BOLD);
}
diff --git a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
index ff5306d..adae210 100644
--- a/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
+++ b/chrome/browser/cocoa/bookmark_menu_cocoa_controller.mm
@@ -28,9 +28,8 @@ const NSUInteger kMaximumMenuPixelsWide = 300;
+ (NSString*)menuTitleForNode:(const BookmarkNode*)node {
NSFont* nsfont = [NSFont menuBarFontOfSize:0]; // 0 means "default"
- gfx::Font font = gfx::Font::CreateFont(base::SysNSStringToWide([nsfont
- fontName]),
- (int)[nsfont pointSize]);
+ gfx::Font font(base::SysNSStringToWide([nsfont fontName]),
+ static_cast<int>([nsfont pointSize]));
std::wstring title = gfx::ElideText(node->GetTitle(),
font,
kMaximumMenuPixelsWide,
diff --git a/chrome/browser/cocoa/download_item_cell.mm b/chrome/browser/cocoa/download_item_cell.mm
index 8ae9fd9..1338615 100644
--- a/chrome/browser/cocoa/download_item_cell.mm
+++ b/chrome/browser/cocoa/download_item_cell.mm
@@ -395,9 +395,8 @@ NSGradient* BackgroundTheme::GetNSGradient(int id) const {
- (NSString*)elideTitle:(int)availableWidth {
NSFont* font = [self font];
- gfx::Font font_chr =
- gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]),
- [font pointSize]);
+ gfx::Font font_chr(base::SysNSStringToWide([font fontName]),
+ [font pointSize]);
return base::SysWideToNSString(
ElideFilename(downloadPath_, font_chr, availableWidth));
@@ -405,9 +404,8 @@ NSGradient* BackgroundTheme::GetNSGradient(int id) const {
- (NSString*)elideStatus:(int)availableWidth {
NSFont* font = [self secondaryFont];
- gfx::Font font_chr =
- gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]),
- [font pointSize]);
+ gfx::Font font_chr(base::SysNSStringToWide([font fontName]),
+ [font pointSize]);
return base::SysWideToNSString(ElideText(
base::SysNSStringToWide([self secondaryTitle]),
diff --git a/chrome/browser/cocoa/location_bar/ev_bubble_decoration.mm b/chrome/browser/cocoa/location_bar/ev_bubble_decoration.mm
index 434009a..d2bfe63 100644
--- a/chrome/browser/cocoa/location_bar/ev_bubble_decoration.mm
+++ b/chrome/browser/cocoa/location_bar/ev_bubble_decoration.mm
@@ -79,8 +79,8 @@ CGFloat EVBubbleDecoration::GetWidthForSpace(CGFloat width) {
// Middle-elide the label to fit |width_left|. This leaves the
// prefix and the trailing country code in place.
- gfx::Font font = gfx::Font::CreateFont(
- base::SysNSStringToWide([font_ fontName]), [font_ pointSize]);
+ gfx::Font font(base::SysNSStringToWide([font_ fontName]),
+ [font_ pointSize]);
NSString* elided_label = base::SysWideToNSString(
ElideText(base::SysNSStringToWide(full_label_), font, width_left, true));
diff --git a/chrome/browser/cocoa/status_bubble_mac.mm b/chrome/browser/cocoa/status_bubble_mac.mm
index 3f5c0a8..9b6e063d4 100644
--- a/chrome/browser/cocoa/status_bubble_mac.mm
+++ b/chrome/browser/cocoa/status_bubble_mac.mm
@@ -126,9 +126,8 @@ void StatusBubbleMac::SetURL(const GURL& url, const std::wstring& languages) {
kBubbleViewTextPositionX -
kTextPadding);
NSFont* font = [[window_ contentView] font];
- gfx::Font font_chr =
- gfx::Font::CreateFont(base::SysNSStringToWide([font fontName]),
- [font pointSize]);
+ gfx::Font font_chr(base::SysNSStringToWide([font fontName]),
+ [font pointSize]);
std::wstring status = gfx::ElideUrl(url, font_chr, text_width, languages);
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc
index 85ebd8d..38c16df 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.cc
+++ b/chrome/browser/gtk/bookmark_utils_gtk.cc
@@ -197,7 +197,7 @@ GtkWidget* GetDragRepresentation(GdkPixbuf* pixbuf,
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
gtk_widget_set_size_request(window, kDragRepresentationWidth,
- base_font.height());
+ base_font.GetHeight());
} else {
if (!provider->UseGtkTheme()) {
// TODO(erg): Theme wise, which color should I be picking here?
diff --git a/chrome/browser/gtk/options/fonts_page_gtk.cc b/chrome/browser/gtk/options/fonts_page_gtk.cc
index abb544d..f9c254a 100644
--- a/chrome/browser/gtk/options/fonts_page_gtk.cc
+++ b/chrome/browser/gtk/options/fonts_page_gtk.cc
@@ -22,8 +22,8 @@ std::string MakeFontName(std::string family_name, int pixel_size) {
// The given font might not be available (the default fonts we use are not
// installed by default on some distros). So figure out which font we are
// actually falling back to and display that. (See crbug.com/31381.)
- std::wstring actual_family_name = gfx::Font::CreateFont(
- UTF8ToWide(family_name), pixel_size).FontName();
+ std::wstring actual_family_name = gfx::Font(
+ UTF8ToWide(family_name), pixel_size).GetFontName();
std::string fontname;
// TODO(mattm): We can pass in the size in pixels (px), and the font button
// actually honors it, but when you open the selector it interprets it as
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
index eac4a38..4dc40a7 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc
@@ -1078,8 +1078,8 @@ void TabRendererGtk::InitResources() {
// Force the font size to 9pt, which matches Windows' default font size
// (taken from the system).
const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
- title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 9));
- title_font_height_ = title_font_->height();
+ title_font_ = new gfx::Font(base_font.GetFontName(), 9);
+ title_font_height_ = title_font_->GetHeight();
crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
index 0a03a8a6..092843d 100644
--- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h
+++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h
@@ -13,6 +13,7 @@
#include "app/gtk_signal.h"
#include "app/slide_animation.h"
#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/gtk/owned_widget_gtk.h"
#include "chrome/common/notification_observer.h"
diff --git a/chrome/browser/remoting/setup_flow.cc b/chrome/browser/remoting/setup_flow.cc
index 5b945e9..5e71c99 100644
--- a/chrome/browser/remoting/setup_flow.cc
+++ b/chrome/browser/remoting/setup_flow.cc
@@ -41,7 +41,7 @@ SetupFlow::~SetupFlow() {
void SetupFlow::GetDialogSize(gfx::Size* size) const {
PrefService* prefs = profile_->GetPrefs();
- gfx::Font approximate_web_font = gfx::Font::CreateFont(
+ gfx::Font approximate_web_font(
UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)),
prefs->GetInteger(prefs::kWebKitDefaultFontSize));
diff --git a/chrome/browser/sync/sync_setup_flow.cc b/chrome/browser/sync/sync_setup_flow.cc
index d23d2b4..75497e6 100644
--- a/chrome/browser/sync/sync_setup_flow.cc
+++ b/chrome/browser/sync/sync_setup_flow.cc
@@ -253,7 +253,7 @@ SyncSetupFlow::~SyncSetupFlow() {
void SyncSetupFlow::GetDialogSize(gfx::Size* size) const {
PrefService* prefs = service_->profile()->GetPrefs();
- gfx::Font approximate_web_font = gfx::Font::CreateFont(
+ gfx::Font approximate_web_font = gfx::Font(
UTF8ToWide(prefs->GetString(prefs::kWebKitSansSerifFontFamily)),
prefs->GetInteger(prefs::kWebKitDefaultFontSize));
diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc
index 8352acd..fd60495 100644
--- a/chrome/browser/views/about_chrome_view.cc
+++ b/chrome/browser/views/about_chrome_view.cc
@@ -287,7 +287,7 @@ void AboutChromeView::Init() {
int height = about_background_logo->height() +
kRelatedControlVerticalSpacing +
// Copyright line.
- font.height() +
+ font.GetHeight() +
// Main label.
dummy_text.GetHeightForWidth(
dialog_dimensions_.width() - (2 * kPanelHorizMargin)) +
@@ -497,7 +497,7 @@ void AboutChromeView::Paint(gfx::Canvas* canvas) {
open_source_url_rect_.height());
// Save the height so we can set the bounds correctly.
- main_text_label_height_ = position.height() + font.height();
+ main_text_label_height_ = position.height() + font.GetHeight();
}
void AboutChromeView::ViewHierarchyChanged(bool is_add,
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 917e308..f3290f1 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -313,7 +313,7 @@ void AutocompleteResultView::Layout() {
icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding,
(height() - icon_size_) / 2, icon_size_, icon_size_);
int text_x = icon_bounds_.right() + LocationBarView::kItemPadding;
- int font_height = std::max(normal_font_.height(), bold_font_.height());
+ int font_height = std::max(normal_font_.GetHeight(), bold_font_.GetHeight());
text_bounds_.SetRect(text_x, std::max(0, (height() - font_height) / 2),
std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding,
0), font_height);
@@ -327,7 +327,7 @@ gfx::Size AutocompleteResultView::GetPreferredSize() {
int AutocompleteResultView::GetPreferredHeight(
const gfx::Font& font,
const gfx::Font& bold_font) {
- int text_height = std::max(font.height(), bold_font.height()) +
+ int text_height = std::max(font.GetHeight(), bold_font.GetHeight()) +
(kTextVerticalPadding * 2);
int icon_height = icon_size_ + (kIconVerticalPadding * 2);
return std::max(icon_height, text_height);
@@ -509,7 +509,7 @@ int AutocompleteResultView::DrawString(
j != i->classifications.end(); ++j) {
int left = mirroring_context_->mirrored_left_coord(x, x + j->pixel_width);
canvas->DrawStringInt(j->text, *j->font, j->color, left, y,
- j->pixel_width, j->font->height(), flags);
+ j->pixel_width, j->font->GetHeight(), flags);
x += j->pixel_width;
}
}
diff --git a/chrome/browser/views/constrained_window_win.cc b/chrome/browser/views/constrained_window_win.cc
index bb2bffa..f3e9637 100644
--- a/chrome/browser/views/constrained_window_win.cc
+++ b/chrome/browser/views/constrained_window_win.cc
@@ -527,7 +527,7 @@ void ConstrainedWindowFrameView::LayoutTitleBar() {
// there is no icon in constrained windows.
gfx::Rect icon_bounds(IconBounds());
int title_x = icon_bounds.x();
- int title_height = title_font_->height();
+ int title_height = title_font_->GetHeight();
// We bias the title position so that when the difference between the icon and
// title heights is odd, the extra pixel of the title is above the vertical
// midline rather than below. This compensates for how the icon is already
diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc
index 70ae46e..b496742 100644
--- a/chrome/browser/views/download_item_view.cc
+++ b/chrome/browser/views/download_item_view.cc
@@ -211,8 +211,8 @@ DownloadItemView::DownloadItemView(DownloadItem* download,
tooltip_text_ = download_->GetFileName().ToWStringHack();
font_ = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
- box_height_ = std::max<int>(2 * kVerticalPadding + font_.height() +
- kVerticalTextPadding + font_.height(),
+ box_height_ = std::max<int>(2 * kVerticalPadding + font_.GetHeight() +
+ kVerticalTextPadding + font_.GetHeight(),
2 * kVerticalPadding +
normal_body_image_set_.top_left->height() +
normal_body_image_set_.bottom_left->height());
@@ -486,7 +486,7 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) {
int mirrored_x = MirroredXWithWidthInsideView(
download_util::kSmallProgressIconSize, kTextWidth);
// Add font_.height() to compensate for title, which is drawn later.
- int y = box_y_ + kVerticalPadding + font_.height() +
+ int y = box_y_ + kVerticalPadding + font_.GetHeight() +
kVerticalTextPadding;
SkColor file_name_color = GetThemeProvider()->GetColor(
BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
@@ -501,7 +501,7 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) {
static_cast<int>(kDownloadItemLuminanceMod *
SkColorGetB(file_name_color)));
canvas->DrawStringInt(status_text_, font_, file_name_color,
- mirrored_x, y, kTextWidth, font_.height());
+ mirrored_x, y, kTextWidth, font_.GetHeight());
}
}
@@ -624,14 +624,15 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) {
download_util::kSmallProgressIconSize, kTextWidth);
SkColor file_name_color = GetThemeProvider()->GetColor(
BrowserThemeProvider::COLOR_BOOKMARK_TEXT);
- int y = box_y_ + (show_status_text_ ? kVerticalPadding :
- (box_height_ - font_.height()) / 2);
+ int y =
+ box_y_ + (show_status_text_ ? kVerticalPadding :
+ (box_height_ - font_.GetHeight()) / 2);
// Draw the file's name.
canvas->DrawStringInt(filename, font_,
IsEnabled() ? file_name_color :
kFileNameDisabledColor,
- mirrored_x, y, kTextWidth, font_.height());
+ mirrored_x, y, kTextWidth, font_.GetHeight());
}
// Paint the icon.
@@ -738,7 +739,7 @@ gfx::Size DownloadItemView::GetPreferredSize() {
int width, height;
// First, we set the height to the height of two rows or text plus margins.
- height = 2 * kVerticalPadding + 2 * font_.height() + kVerticalTextPadding;
+ height = 2 * kVerticalPadding + 2 * font_.GetHeight() + kVerticalTextPadding;
// Then we increase the size if the progress icon doesn't fit.
height = std::max<int>(height, download_util::kSmallProgressIconSize);
diff --git a/chrome/browser/views/frame/app_panel_browser_frame_view.cc b/chrome/browser/views/frame/app_panel_browser_frame_view.cc
index 16ebec3..b8a1b33 100644
--- a/chrome/browser/views/frame/app_panel_browser_frame_view.cc
+++ b/chrome/browser/views/frame/app_panel_browser_frame_view.cc
@@ -477,7 +477,7 @@ void AppPanelBrowserFrameView::LayoutTitleBar() {
// Size the title.
int title_x = icon_bounds.right() + kIconTitleSpacing;
- int title_height = BrowserFrame::GetTitleFont().height();
+ int title_height = BrowserFrame::GetTitleFont().GetHeight();
// We bias the title position so that when the difference between the icon
// and title heights is odd, the extra pixel of the title is above the
// vertical midline rather than below. This compensates for how the icon is
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc
index f52000b..bb2fcfa 100644
--- a/chrome/browser/views/frame/opaque_browser_frame_view.cc
+++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc
@@ -508,7 +508,7 @@ int OpaqueBrowserFrameView::IconSize() const {
// size are increased.
return GetSystemMetrics(SM_CYSMICON);
#else
- return std::max(BrowserFrame::GetTitleFont().height(), kIconMinimumSize);
+ return std::max(BrowserFrame::GetTitleFont().GetHeight(), kIconMinimumSize);
#endif
}
@@ -1017,7 +1017,7 @@ void OpaqueBrowserFrameView::LayoutTitleBar() {
if (d->ShouldShowWindowTitle()) {
int title_x = d->ShouldShowWindowIcon() ?
icon_bounds.right() + kIconTitleSpacing : icon_bounds.x();
- int title_height = BrowserFrame::GetTitleFont().height();
+ int title_height = BrowserFrame::GetTitleFont().GetHeight();
// We bias the title position so that when the difference between the icon
// and title heights is odd, the extra pixel of the title is above the
// vertical midline rather than below. This compensates for how the icon is
diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc
index e8d8e05..d452069 100644
--- a/chrome/browser/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/views/location_bar/location_bar_view.cc
@@ -118,7 +118,7 @@ void LocationBarView::Init() {
// If this makes the font too big, try to make it smaller so it will fit.
const int height =
std::max(GetPreferredSize().height() - (kVerticalEdgeThickness * 2), 0);
- while ((font_.height() > height) && (font_.FontSize() > 1))
+ while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1))
font_ = font_.DeriveFont(-1);
location_icon_view_ = new LocationIconView(this);
diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc
index f6869db..1546482 100644
--- a/chrome/browser/views/options/advanced_contents_view.cc
+++ b/chrome/browser/views/options/advanced_contents_view.cc
@@ -1383,7 +1383,7 @@ void AdvancedContentsView::InitClass() {
static bool initialized = false;
if (!initialized) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- line_height_ = rb.GetFont(ResourceBundle::BaseFont).height();
+ line_height_ = rb.GetFont(ResourceBundle::BaseFont).GetHeight();
initialized = true;
}
}
diff --git a/chrome/browser/views/options/content_exceptions_table_view.cc b/chrome/browser/views/options/content_exceptions_table_view.cc
index 0f7fa6a..1b81aa1 100644
--- a/chrome/browser/views/options/content_exceptions_table_view.cc
+++ b/chrome/browser/views/options/content_exceptions_table_view.cc
@@ -27,7 +27,7 @@ bool ContentExceptionsTableView::GetCellColors(int model_row,
gfx::Font font;
font = font.DeriveFont(0, gfx::Font::ITALIC);
- HFONT hf = font.hfont();
+ HFONT hf = font.GetNativeFont();
GetObject(hf, sizeof(LOGFONT), logfont);
return true;
}
diff --git a/chrome/browser/views/options/fonts_page_view.cc b/chrome/browser/views/options/fonts_page_view.cc
index 7ad53e3..261913c 100644
--- a/chrome/browser/views/options/fonts_page_view.cc
+++ b/chrome/browser/views/options/fonts_page_view.cc
@@ -90,7 +90,7 @@ void FontDisplayView::SetFontType(const std::wstring& font_name,
displayed_text += UTF8ToWide(::StringPrintf("%d", font_size_));
HDC hdc = GetDC(NULL);
int font_size_point = MulDiv(font_size, 72, GetDeviceCaps(hdc, LOGPIXELSY));
- gfx::Font font = gfx::Font::CreateFont(font_name, font_size_point);
+ gfx::Font font = gfx::Font(font_name, font_size_point);
font_text_label_->SetFont(font);
font_text_label_->SetText(displayed_text);
}
@@ -206,18 +206,17 @@ void FontsPageView::ItemChanged(views::Combobox* combo_box,
}
}
-void FontsPageView::FontSelected(const gfx::Font& const_font, void* params) {
- gfx::Font font(const_font);
- if (gfx::Font(font).FontName().empty())
+void FontsPageView::FontSelected(const gfx::Font& font, void* params) {
+ if (font.GetFontName().empty())
return;
- int font_size = gfx::Font(font).FontSize();
+ int font_size = font.GetFontSize();
// Currently we do not have separate font sizes for Serif and Sans Serif.
// Therefore, when Serif font size is changed, Sans-Serif font size changes,
// and vice versa.
if (font_type_being_changed_ == SERIF) {
sans_serif_font_size_pixel_ = serif_font_size_pixel_ = font_size;
serif_font_display_view_->SetFontType(
- font.FontName(),
+ font.GetFontName(),
serif_font_size_pixel_);
sans_serif_font_display_view_->SetFontType(
sans_serif_font_display_view_->font_name(),
@@ -225,14 +224,14 @@ void FontsPageView::FontSelected(const gfx::Font& const_font, void* params) {
} else if (font_type_being_changed_ == SANS_SERIF) {
sans_serif_font_size_pixel_ = serif_font_size_pixel_ = font_size;
sans_serif_font_display_view_->SetFontType(
- font.FontName(),
+ font.GetFontName(),
sans_serif_font_size_pixel_);
serif_font_display_view_->SetFontType(
serif_font_display_view_->font_name(),
sans_serif_font_size_pixel_);
} else if (font_type_being_changed_ == FIXED_WIDTH) {
fixed_width_font_size_pixel_ = font_size;
- fixed_width_font_display_view_->SetFontType(font.FontName(), font_size);
+ fixed_width_font_display_view_->SetFontType(font.GetFontName(), font_size);
}
font_changed_ = true;
}
diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc
index 68db592..f189d4f 100644
--- a/chrome/browser/views/options/languages_page_view.cc
+++ b/chrome/browser/views/options/languages_page_view.cc
@@ -142,8 +142,8 @@ void AddLanguageWindowView::Layout() {
gfx::Size AddLanguageWindowView::GetPreferredSize() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont);
- return gfx::Size(font.ave_char_width() * kDefaultWindowWidthChars,
- font.height() * kDefaultWindowHeightLines);
+ return gfx::Size(font.GetAverageCharacterWidth() * kDefaultWindowWidthChars,
+ font.GetHeight() * kDefaultWindowHeightLines);
}
void AddLanguageWindowView::ViewHierarchyChanged(bool is_add,
diff --git a/chrome/browser/views/sad_tab_view.cc b/chrome/browser/views/sad_tab_view.cc
index e02d975..09fdaab 100644
--- a/chrome/browser/views/sad_tab_view.cc
+++ b/chrome/browser/views/sad_tab_view.cc
@@ -86,7 +86,7 @@ void SadTabView::Layout() {
int title_x = (width() - title_width_) / 2;
int title_y = icon_bounds_.bottom() + kIconTitleSpacing;
- int title_height = title_font_->height();
+ int title_height = title_font_->GetHeight();
title_bounds_.SetRect(title_x, title_y, title_width_, title_height);
gfx::CanvasSkia cc(0, 0, true);
diff --git a/chrome/browser/views/shell_dialogs_win.cc b/chrome/browser/views/shell_dialogs_win.cc
index 17d5b1e..fc8b96c 100644
--- a/chrome/browser/views/shell_dialogs_win.cc
+++ b/chrome/browser/views/shell_dialogs_win.cc
@@ -1107,7 +1107,7 @@ void SelectFontDialogImpl::FontSelected(LOGFONT logfont,
if (listener_) {
HFONT font = CreateFontIndirect(&logfont);
if (font) {
- listener_->FontSelected(gfx::Font::CreateFont(font), params);
+ listener_->FontSelected(gfx::Font(font), params);
DeleteObject(font);
} else {
listener_->FontSelectionCanceled(params);
diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc
index cf53efc..1c40f54 100644
--- a/chrome/browser/views/status_bubble_views.cc
+++ b/chrome/browser/views/status_bubble_views.cc
@@ -594,7 +594,7 @@ void StatusBubbleViews::Reposition() {
gfx::Size StatusBubbleViews::GetPreferredSize() {
return gfx::Size(0, ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::BaseFont).height() + kTotalVerticalPadding);
+ ResourceBundle::BaseFont).GetHeight() + kTotalVerticalPadding);
}
void StatusBubbleViews::SetBounds(int x, int y, int w, int h) {
diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc
index eb2a5b5..4d89a6a 100644
--- a/chrome/browser/views/tabs/base_tab.cc
+++ b/chrome/browser/views/tabs/base_tab.cc
@@ -480,6 +480,6 @@ void BaseTab::InitResources() {
initialized = true;
font_ = new gfx::Font(
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
- font_height_ = font_->height();
+ font_height_ = font_->GetHeight();
}
}
diff --git a/chrome/browser/views/theme_install_bubble_view.cc b/chrome/browser/views/theme_install_bubble_view.cc
index 4e54812..7593fc7 100644
--- a/chrome/browser/views/theme_install_bubble_view.cc
+++ b/chrome/browser/views/theme_install_bubble_view.cc
@@ -90,7 +90,7 @@ gfx::Size ThemeInstallBubbleView::GetPreferredSize() {
return gfx::Size(views::Label::font().GetStringWidth(text_) +
kTextHorizPadding,
ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::LargeFont).height() + kTextVertPadding);
+ ResourceBundle::LargeFont).GetHeight() + kTextVertPadding);
}
void ThemeInstallBubbleView::Reposition() {
diff --git a/chrome/common/extensions/extension_action.cc b/chrome/common/extensions/extension_action.cc
index 7e7503f..e73cf8d 100644
--- a/chrome/common/extensions/extension_action.cc
+++ b/chrome/common/extensions/extension_action.cc
@@ -76,7 +76,7 @@ SkPaint* GetTextPaint() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
typeface = SkTypeface::CreateFromName(
- WideToUTF8(base_font.FontName()).c_str(), SkTypeface::kNormal);
+ WideToUTF8(base_font.GetFontName()).c_str(), SkTypeface::kNormal);
}
text_paint->setTypeface(typeface);
diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc
index d63f9b4..1a22af5 100644
--- a/gfx/canvas_skia_linux.cc
+++ b/gfx/canvas_skia_linux.cc
@@ -14,6 +14,7 @@
#include "base/utf_string_conversions.h"
#include "gfx/font.h"
#include "gfx/gtk_util.h"
+#include "gfx/platform_font_gtk.h"
#include "gfx/rect.h"
namespace {
@@ -149,7 +150,7 @@ static void SetupPangoLayout(PangoLayout* layout,
resolution);
}
- PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font);
+ PangoFontDescription* desc = font.GetNativeFont();
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);
@@ -246,10 +247,12 @@ void CanvasSkia::DrawStringInt(const std::wstring& text,
cairo_move_to(cr, x, y);
pango_cairo_show_layout(cr, layout);
- if (font.style() & gfx::Font::UNDERLINED) {
+ if (font.GetStyle() & gfx::Font::UNDERLINED) {
+ gfx::PlatformFontGtk* platform_font =
+ static_cast<gfx::PlatformFontGtk*>(font.platform_font());
double underline_y =
- static_cast<double>(y) + height + font.underline_position();
- cairo_set_line_width(cr, font.underline_thickness());
+ static_cast<double>(y) + height + platform_font->underline_position();
+ cairo_set_line_width(cr, platform_font->underline_thickness());
cairo_move_to(cr, x, underline_y);
cairo_line_to(cr, x + width, underline_y);
cairo_stroke(cr);
diff --git a/gfx/canvas_skia_mac.mm b/gfx/canvas_skia_mac.mm
index 7836869..e2cb553 100644
--- a/gfx/canvas_skia_mac.mm
+++ b/gfx/canvas_skia_mac.mm
@@ -28,14 +28,14 @@ CanvasSkia::~CanvasSkia() {
void CanvasSkia::SizeStringInt(const std::wstring& text,
const gfx::Font& font,
int *width, int *height, int flags) {
- NSFont* native_font = font.nativeFont();
+ NSFont* native_font = font.GetNativeFont();
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();
+ *height = font.GetHeight();
}
void CanvasSkia::DrawStringInt(const std::wstring& text, const gfx::Font& font,
@@ -59,7 +59,7 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, const gfx::Font& font,
NSDictionary* attributes =
[NSDictionary dictionaryWithObjectsAndKeys:
- font.nativeFont(), NSFontAttributeName,
+ font.GetNativeFont(), NSFontAttributeName,
ns_color, NSForegroundColorAttributeName,
ns_style, NSParagraphStyleAttributeName,
nil];
diff --git a/gfx/canvas_skia_win.cc b/gfx/canvas_skia_win.cc
index f3c5f8f..cc8a7eb 100644
--- a/gfx/canvas_skia_win.cc
+++ b/gfx/canvas_skia_win.cc
@@ -163,7 +163,7 @@ void CanvasSkia::SizeStringInt(const std::wstring& text,
RECT r = { 0, 0, *width, *height };
HDC dc = GetDC(NULL);
- HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.hfont()));
+ HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.GetNativeFont()));
DoDrawText(dc, clamped_string, &r,
ComputeFormatFlags(flags, clamped_string) | DT_CALCRECT);
SelectObject(dc, old_font);
@@ -212,7 +212,7 @@ void CanvasSkia::DrawStringInt(const std::wstring& text,
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);
+ DrawStringInt(text, font.GetNativeFont(), color, x, y, w, h, flags);
}
// Checks each pixel immediately adjacent to the given pixel in the bitmap. If
diff --git a/gfx/font.cc b/gfx/font.cc
new file mode 100644
index 0000000..625968a
--- /dev/null
+++ b/gfx/font.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2006-2008 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 "gfx/font.h"
+
+#include "gfx/platform_font.h"
+
+namespace gfx {
+
+////////////////////////////////////////////////////////////////////////////////
+// Font, public:
+
+Font::Font() : platform_font_(PlatformFont::CreateDefault()) {
+}
+
+Font::Font(const Font& other) : platform_font_(other.platform_font_) {
+}
+
+gfx::Font& Font::operator=(const Font& other) {
+ platform_font_ = other.platform_font_;
+ return *this;
+}
+
+Font::Font(NativeFont native_font)
+ : platform_font_(PlatformFont::CreateFromNativeFont(native_font)) {
+}
+
+Font::Font(PlatformFont* platform_font) : platform_font_(platform_font) {
+}
+
+Font::Font(const std::wstring& font_name, int font_size)
+ : platform_font_(PlatformFont::CreateFromNameAndSize(font_name,
+ font_size)) {
+}
+
+Font::~Font() {
+}
+
+Font Font::DeriveFont(int size_delta) const {
+ return DeriveFont(size_delta, GetStyle());
+}
+
+Font Font::DeriveFont(int size_delta, int style) const {
+ return platform_font_->DeriveFont(size_delta, style);
+}
+
+int Font::GetHeight() const {
+ return platform_font_->GetHeight();
+}
+
+int Font::GetBaseline() const {
+ return platform_font_->GetBaseline();
+}
+
+int Font::GetAverageCharacterWidth() const {
+ return platform_font_->GetAverageCharacterWidth();
+}
+
+int Font::GetStringWidth(const std::wstring& text) const {
+ return platform_font_->GetStringWidth(text);
+}
+
+int Font::GetExpectedTextWidth(int length) const {
+ return platform_font_->GetExpectedTextWidth(length);
+}
+
+int Font::GetStyle() const {
+ return platform_font_->GetStyle();
+}
+
+const std::wstring& Font::GetFontName() const {
+ return platform_font_->GetFontName();
+}
+
+int Font::GetFontSize() const {
+ return platform_font_->GetFontSize();
+}
+
+NativeFont Font::GetNativeFont() const {
+ return platform_font_->GetNativeFont();
+}
+
+} // namespace gfx
+
diff --git a/gfx/font.h b/gfx/font.h
index 9ee40b6..9d9276b 100644
--- a/gfx/font.h
+++ b/gfx/font.h
@@ -6,63 +6,50 @@
#define GFX_FONT_H_
#pragma once
-#include "build/build_config.h"
-
#include <string>
-#if defined(OS_WIN)
-typedef struct HFONT__* HFONT;
-#elif !defined(OS_MACOSX)
-#include "third_party/skia/include/core/SkRefCnt.h"
-class SkPaint;
-class SkTypeface;
-#endif
-
-#if defined(OS_WIN)
-typedef struct HFONT__* NativeFont;
-#elif defined(OS_MACOSX)
-#ifdef __OBJC__
-@class NSFont;
-#else
-class NSFont;
-#endif
-typedef NSFont* NativeFont;
-#else
-typedef struct _PangoFontDescription PangoFontDescription;
-class SkTypeface;
-typedef SkTypeface* NativeFont;
-#endif
-
-#include "base/basictypes.h"
#include "base/ref_counted.h"
-#include "base/scoped_ptr.h"
+#include "gfx/native_widget_types.h"
namespace gfx {
+class PlatformFont;
+
// Font provides a wrapper around an underlying font. Copy and assignment
// operators are explicitly allowed, and cheap.
class Font {
public:
// The following constants indicate the font style.
- enum {
+ enum FontStyle {
NORMAL = 0,
BOLD = 1,
ITALIC = 2,
UNDERLINED = 4,
};
- // 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 Font CreateFont(const std::wstring& font_name, int font_size);
+ // Creates a font with the default name and style.
+ Font();
+
+ // Creates a font that is a clone of another font object.
+ Font(const Font& other);
+ gfx::Font& operator=(const Font& other);
+
+ // Creates a font from the specified native font.
+ explicit Font(NativeFont native_font);
- ~Font() { }
+ // Construct a Font object with the specified PlatformFont object. The Font
+ // object takes ownership of the PlatformFont object.
+ explicit Font(PlatformFont* platform_font);
+
+ // Creates a font with the specified name and size.
+ Font(const std::wstring& font_name, int font_size);
+
+ ~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.
- Font DeriveFont(int size_delta) const {
- return DeriveFont(size_delta, style());
- }
+ Font DeriveFont(int size_delta) const;
// Returns a new Font derived from the existing font.
// size_delta is the size to add to the current font. See the single
@@ -76,212 +63,51 @@ class Font {
// greater than just ascent + descent. Specifically, the Windows and Mac
// implementations include leading and the Linux one does not. This may
// need to be revisited in the future.
- int height() const;
+ int GetHeight() const;
// Returns the baseline, or ascent, of the font.
- int baseline() const;
+ int GetBaseline() const;
// Returns the average character width for the font.
- int ave_char_width() const;
+ int GetAverageCharacterWidth() const;
// Returns the number of horizontal pixels needed to display the specified
// string.
int GetStringWidth(const std::wstring& text) const;
- // Returns the expected number of horizontal pixels needed to display
- // the specified length of characters.
- // Call GetStringWidth() to retrieve the actual number.
+ // Returns the expected number of horizontal pixels needed to display the
+ // specified length of characters. Call GetStringWidth() to retrieve the
+ // actual number.
int GetExpectedTextWidth(int length) const;
// Returns the style of the font.
- int style() const;
-
- // Font Name.
- // It is actually a font family name, because Skia expects a family name
- // and not a font name.
- const std::wstring& FontName() const;
+ int GetStyle() const;
- // Font Size.
- int FontSize();
+ // Returns the font name.
+ const std::wstring& GetFontName() const;
- NativeFont nativeFont() const;
+ // Returns the font size in pixels.
+ int GetFontSize() const;
- // Creates a font with the default name and style.
- Font();
-
-#if defined(OS_WIN)
- // 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 gfx::Canvas to
- // draw text.
- HFONT hfont() const { return font_ref_->hfont(); }
-
- // Dialog units to pixels conversion.
- // See http://support.microsoft.com/kb/145994 for details.
- int horizontal_dlus_to_pixels(int dlus) {
- return dlus * font_ref_->dlu_base_x() / 4;
- }
- int vertical_dlus_to_pixels(int dlus) {
- return dlus * font_ref_->height() / 8;
- }
-
- // Callback that returns the minimum height that should be used for
- // gfx::Fonts. Optional. If not specified, the minimum font size is 0.
- typedef int (*GetMinimumFontSizeCallback)();
- static GetMinimumFontSizeCallback get_minimum_font_size_callback;
+ // Returns the native font handle.
+ // Lifetime lore:
+ // Windows: This handle is owned by the Font object, and should not be
+ // destroyed by the caller.
+ // Mac: Caller must release this object.
+ // Gtk: This handle is created on demand, and must be freed by calling
+ // pango_font_description_free() when the caller is done using it.
+ NativeFont GetNativeFont() const;
- // Callback that adjusts a LOGFONT to meet suitability requirements of the
- // embedding application. Optional. If not specified, no adjustments are
- // performed other than clamping to a minimum font height if
- // |get_minimum_font_size_callback| is specified.
- typedef void (*AdjustFontCallback)(LOGFONT* lf);
- static AdjustFontCallback adjust_font_callback;
-
-#elif !defined(OS_MACOSX)
- static Font CreateFont(PangoFontDescription* desc);
- // We need a copy constructor and assignment operator to deal with
- // the Skia reference counting.
- Font(const Font& other);
- Font& operator=(const Font& other);
- // Setup a Skia context to use the current typeface
- void PaintSetup(SkPaint* paint) const;
-
- // Converts |gfx_font| to a new pango font. Free the returned font with
- // pango_font_description_free().
- static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
-
- // Position as an offset from the height of the drawn text, used to draw
- // an underline. This is a negative number, so the underline would be
- // drawn at y + height + underline_position;
- double underline_position() const;
- // The thickness to draw the underline.
- double underline_thickness() const;
-#endif
+ // Raw access to the underlying platform font implementation. Can be
+ // static_cast to a known implementation type if needed.
+ PlatformFont* platform_font() const { return platform_font_.get(); }
private:
-
-#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, 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 Font can provide value semantics.
- class HFontRef : public base::RefCounted<HFontRef> {
- public:
- // This constructor takes control of the HFONT, and will delete it when
- // the HFontRef is deleted.
- HFontRef(HFONT hfont,
- int height,
- int baseline,
- int ave_char_width,
- int style,
- int dlu_base_x);
-
- // Accessors
- HFONT hfont() const { return hfont_; }
- int height() const { return height_; }
- int baseline() const { return baseline_; }
- int ave_char_width() const { return ave_char_width_; }
- int style() const { return style_; }
- int dlu_base_x() const { return dlu_base_x_; }
- const std::wstring& font_name() const { return font_name_; }
-
- private:
- friend class base::RefCounted<HFontRef>;
-
- ~HFontRef();
-
- const HFONT hfont_;
- const int height_;
- const int baseline_;
- const int ave_char_width_;
- const int style_;
- // Constants used in converting dialog units to pixels.
- const int dlu_base_x_;
- std::wstring font_name_;
-
- DISALLOW_COPY_AND_ASSIGN(HFontRef);
- };
-
- // Returns the base font ref. This should ONLY be invoked on the
- // UI thread.
- static HFontRef* GetBaseFontRef();
-
- // Creates and returns a new HFONTRef from the specified HFONT.
- static HFontRef* CreateHFontRef(HFONT font);
-
- explicit Font(HFontRef* font_ref) : font_ref_(font_ref) { }
-
- // Reference to the base font all fonts are derived from.
- static HFontRef* base_font_ref_;
-
- // Indirect reference to the HFontRef, which references the underlying HFONT.
- scoped_refptr<HFontRef> font_ref_;
-#elif !defined(OS_MACOSX)
- 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 CopyFont(const Font& other);
-
- // The default font, used for the default constructor.
- static Font* default_font_;
-
- // Return the scale factor for fonts that account for DPI.
- static float GetPangoScaleFactor();
-
- // The average width of a character, initialized and cached if needed.
- double avg_width() const;
-
- // Potentially slow call to get pango metrics (avg width, underline info).
- void InitPangoMetrics();
-
- // These two both point to the same SkTypeface. We use the SkAutoUnref to
- // handle the reference counting, but without @typeface_ we would have to
- // cast the SkRefCnt from @typeface_helper_ every time.
- scoped_ptr<SkAutoUnref> typeface_helper_;
- SkTypeface *typeface_;
-
- // Additional information about the face
- // Skia actually expects a family name and not a font name.
- std::wstring font_family_;
- int font_size_;
- int style_;
-
- // Cached metrics, generated at construction
- int height_;
- int ascent_;
-
- // The pango metrics are much more expensive so we wait until we need them
- // to compute them.
- bool pango_metrics_inited_;
- double avg_width_;
- double underline_position_;
- double underline_thickness_;
-#else // OS_MACOSX
- explicit Font(const std::wstring& font_name, int font_size, int style);
-
- // Calculate and cache the font metrics.
- void calculateMetrics();
-
- std::wstring font_name_;
- int font_size_;
- int style_;
-
- // Cached metrics, generated at construction
- int height_;
- int ascent_;
- int avg_width_;
-#endif
-
+ // Wrapped platform font implementation.
+ scoped_refptr<PlatformFont> platform_font_;
};
} // namespace gfx
#endif // GFX_FONT_H_
+
diff --git a/gfx/font_gtk.cc b/gfx/font_gtk.cc
index 644a7ff..e69de29 100644
--- a/gfx/font_gtk.cc
+++ b/gfx/font_gtk.cc
@@ -1,152 +0,0 @@
-// Copyright (c) 2006-2008 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 "gfx/font.h"
-
-#include <algorithm>
-#include <fontconfig/fontconfig.h>
-#include <gtk/gtk.h>
-
-#include "base/logging.h"
-#include "base/string_piece.h"
-#include "base/utf_string_conversions.h"
-#include "gfx/gtk_util.h"
-
-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 a default font. In
-// Skia, it only checks the best match font. If it failed to find
-// one, SkTypeface will be NULL for that font family. It eventually
-// causes a segfault. For example, family_name = "Sans" and system
-// may have various fonts. The first font family in FcPattern will be
-// "DejaVu Sans" but a font family returned by FcFontMatch will be "VL
-// PGothic". In this case, SkTypeface for "Sans" returns NULL even if
-// the system has a font for "Sans" font family. See FontMatch() in
-// skia/ports/SkFontHost_fontconfig.cpp for more detail.
-static std::wstring FindBestMatchFontFamilyName(const char* family_name) {
- FcPattern* pattern = FcPatternCreate();
- FcValue fcvalue;
- fcvalue.type = FcTypeString;
- char* family_name_copy = strdup(family_name);
- fcvalue.u.s = reinterpret_cast<FcChar8*>(family_name_copy);
- FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
- FcConfigSubstitute(0, pattern, FcMatchPattern);
- FcDefaultSubstitute(pattern);
- FcResult result;
- FcPattern* match = FcFontMatch(0, pattern, &result);
- DCHECK(match) << "Could not find font: " << family_name;
- FcChar8* match_family;
- FcPatternGetString(match, FC_FAMILY, 0, &match_family);
-
- std::wstring font_family = UTF8ToWide(
- reinterpret_cast<char*>(match_family));
- FcPatternDestroy(match);
- FcPatternDestroy(pattern);
- free(family_name_copy);
- return font_family;
-}
-
-// Pango scales font sizes. This returns the scale factor. See
-// pango_cairo_context_set_resolution for details.
-// NOTE: this isn't entirely accurate, in that Pango also consults the
-// FC_PIXEL_SIZE first (see get_font_size in pangocairo-fcfont), but this
-// seems to give us the same sizes as used by Pango for all our fonts in both
-// English and Thai.
-float Font::GetPangoScaleFactor() {
- static float scale_factor = gfx::GetPangoResolution();
- static bool determined_scale = false;
- if (!determined_scale) {
- if (scale_factor <= 0)
- scale_factor = 1;
- else
- scale_factor /= 72.0;
- determined_scale = true;
- }
- return scale_factor;
-}
-
-// static
-Font Font::CreateFont(PangoFontDescription* desc) {
- gint size = pango_font_description_get_size(desc);
- const char* family_name = pango_font_description_get_family(desc);
-
- // Find best match font for |family_name| to make sure we can get
- // a SkTypeface for the default font.
- // TODO(agl): remove this.
- std::wstring font_family = FindBestMatchFontFamilyName(family_name);
-
- Font font = CreateFont(font_family, size / PANGO_SCALE);
- int style = 0;
- if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) {
- // TODO(davemoore) What should we do about other weights? We currently
- // only support BOLD.
- style |= BOLD;
- }
- if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) {
- // TODO(davemoore) What about PANGO_STYLE_OBLIQUE?
- style |= ITALIC;
- }
- if (style != 0) {
- font = font.DeriveFont(0, style);
- }
- return Font(font);
-}
-
-// Get the default gtk system font (name and size).
-Font::Font() {
- if (default_font_ == NULL) {
- GtkSettings* settings = gtk_settings_get_default();
-
- gchar* font_name = NULL;
- g_object_get(settings, "gtk-font-name", &font_name, NULL);
-
- // Temporary CHECK for helping track down
- // http://code.google.com/p/chromium/issues/detail?id=12530
- CHECK(font_name) << " Unable to get gtk-font-name for default font.";
-
- PangoFontDescription* desc =
- pango_font_description_from_string(font_name);
- default_font_ = new Font(CreateFont(desc));
- pango_font_description_free(desc);
- g_free(font_name);
-
- DCHECK(default_font_);
- }
-
- CopyFont(*default_font_);
-}
-
-// static
-PangoFontDescription* Font::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());
- // Set the absolute size to avoid overflowing UI elements.
- pango_font_description_set_absolute_size(pfd,
- font.FontSize() * PANGO_SCALE * Font::GetPangoScaleFactor());
-
- switch (font.style()) {
- case gfx::Font::NORMAL:
- // Nothing to do, should already be PANGO_STYLE_NORMAL.
- break;
- case gfx::Font::BOLD:
- pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
- break;
- case gfx::Font::ITALIC:
- pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
- break;
- 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;
- }
-
- return pfd;
-}
-
-} // namespace gfx
diff --git a/gfx/font_mac.mm b/gfx/font_mac.mm
deleted file mode 100644
index e569a35..0000000
--- a/gfx/font_mac.mm
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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.
-
-#include "gfx/font.h"
-
-#include <Cocoa/Cocoa.h>
-
-#include "base/logging.h"
-#include "base/scoped_nsobject.h"
-#include "base/sys_string_conversions.h"
-#include "gfx/canvas_skia.h"
-
-namespace gfx {
-
-// static
-Font Font::CreateFont(const std::wstring& font_name, int font_size) {
- return Font(font_name, font_size, NORMAL);
-}
-
-Font::Font(const std::wstring& font_name, int font_size, int style)
- : font_name_(font_name),
- font_size_(font_size),
- style_(style) {
- calculateMetrics();
-}
-
-Font::Font()
- : font_size_([NSFont systemFontSize]),
- style_(NORMAL) {
- NSFont* system_font = [NSFont systemFontOfSize:font_size_];
- font_name_ = base::SysNSStringToWide([system_font fontName]);
- calculateMetrics();
-}
-
-void Font::calculateMetrics() {
- NSFont* font = nativeFont();
- scoped_nsobject<NSLayoutManager> layout_manager(
- [[NSLayoutManager alloc] init]);
- height_ = [layout_manager defaultLineHeightForFont:font];
- ascent_ = [font ascender];
- avg_width_ = [font boundingRectForGlyph:[font glyphWithName:@"x"]].size.width;
-}
-
-Font Font::DeriveFont(int size_delta, int style) const {
- return Font(font_name_, font_size_ + size_delta, style);
-}
-
-int Font::height() const {
- return height_;
-}
-
-int Font::baseline() const {
- return ascent_;
-}
-
-int Font::ave_char_width() const {
- return avg_width_;
-}
-
-int Font::GetStringWidth(const std::wstring& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, *this, &width, &height,
- gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
-int Font::GetExpectedTextWidth(int length) const {
- return length * avg_width_;
-}
-
-int Font::style() const {
- return style_;
-}
-
-const std::wstring& Font::FontName() const {
- return font_name_;
-}
-
-int Font::FontSize() {
- return font_size_;
-}
-
-NativeFont Font::nativeFont() const {
- // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667
- // 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/gfx/font_skia.cc b/gfx/font_skia.cc
deleted file mode 100644
index 0289cdb..0000000
--- a/gfx/font_skia.cc
+++ /dev/null
@@ -1,255 +0,0 @@
-// 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.
-
-#include "gfx/font.h"
-
-#include <gdk/gdk.h>
-#include <map>
-#include <pango/pango.h>
-
-#include "base/logging.h"
-#include "base/string_piece.h"
-#include "base/sys_string_conversions.h"
-#include "gfx/canvas_skia.h"
-#include "third_party/skia/include/core/SkTypeface.h"
-#include "third_party/skia/include/core/SkPaint.h"
-
-namespace {
-
-// The font family name which is used when a user's application font for
-// GNOME/KDE is a non-scalable one. The name should be listed in the
-// IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
-const char* kFallbackFontFamilyName = "sans";
-
-// Retrieves the pango metrics for a pango font description. Caches the metrics
-// and never frees them. The metrics objects are relatively small and
-// very expensive to look up.
-static PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
- static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
- static PangoContext* context = NULL;
-
- if (!context) {
- context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
- pango_context_set_language(context, pango_language_get_default());
- }
-
- if (!desc_to_metrics) {
- desc_to_metrics = new std::map<int, PangoFontMetrics*>();
- }
-
- int desc_hash = pango_font_description_hash(desc);
- std::map<int, PangoFontMetrics*>::iterator i =
- desc_to_metrics->find(desc_hash);
-
- if (i == desc_to_metrics->end()) {
- PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL);
- (*desc_to_metrics)[desc_hash] = metrics;
- return metrics;
- } else {
- return i->second;
- }
-}
-
-} // namespace
-
-namespace gfx {
-
-Font::Font(const Font& other) {
- CopyFont(other);
-}
-
-Font& Font::operator=(const Font& other) {
- CopyFont(other);
- return *this;
-}
-
-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),
- font_size_(font_size),
- style_(style),
- pango_metrics_inited_(false),
- avg_width_(0.0),
- underline_position_(0.0),
- underline_thickness_(0.0) {
- tf->ref();
- calculateMetrics();
-}
-
-void Font::calculateMetrics() {
- SkPaint paint;
- SkPaint::FontMetrics metrics;
- PaintSetup(&paint);
- paint.getFontMetrics(&metrics);
-
- ascent_ = SkScalarCeil(-metrics.fAscent);
- height_ = ascent_ + SkScalarCeil(metrics.fDescent);
-
-}
-
-void Font::CopyFont(const Font& other) {
- typeface_helper_.reset(new SkAutoUnref(other.typeface_));
- typeface_ = other.typeface_;
- typeface_->ref();
- font_family_ = other.font_family_;
- font_size_ = other.font_size_;
- style_ = other.style_;
- height_ = other.height_;
- ascent_ = other.ascent_;
- pango_metrics_inited_ = other.pango_metrics_inited_;
- avg_width_ = other.avg_width_;
- underline_position_ = other.underline_position_;
- underline_thickness_ = other.underline_thickness_;
-}
-
-int Font::height() const {
- return height_;
-}
-
-int Font::baseline() const {
- return ascent_;
-}
-
-int Font::ave_char_width() const {
- return SkScalarRound(avg_width());
-}
-
-Font Font::CreateFont(const std::wstring& font_family, int font_size) {
- DCHECK_GT(font_size, 0);
- std::wstring fallback;
-
- SkTypeface* tf = SkTypeface::CreateFromName(
- base::SysWideToUTF8(font_family).c_str(), SkTypeface::kNormal);
- if (!tf) {
- // A non-scalable font such as .pcf is specified. Falls back to a default
- // scalable font.
- tf = SkTypeface::CreateFromName(
- kFallbackFontFamilyName, SkTypeface::kNormal);
- CHECK(tf) << "Could not find any font: "
- << base::SysWideToUTF8(font_family)
- << ", " << kFallbackFontFamilyName;
- fallback = base::SysUTF8ToWide(kFallbackFontFamilyName);
- }
- SkAutoUnref tf_helper(tf);
-
- return Font(
- tf, fallback.empty() ? font_family : fallback, font_size, NORMAL);
-}
-
-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_);
- }
-
- if (style == style_) {
- // Fast path, we just use the same typeface at a different size
- return Font(typeface_, font_family_, font_size_ + size_delta, style_);
- }
-
- // If the style has changed we may need to load a new face
- int skstyle = SkTypeface::kNormal;
- if (BOLD & style)
- skstyle |= SkTypeface::kBold;
- if (ITALIC & style)
- skstyle |= SkTypeface::kItalic;
-
- SkTypeface* tf = SkTypeface::CreateFromName(
- base::SysWideToUTF8(font_family_).c_str(),
- static_cast<SkTypeface::Style>(skstyle));
- SkAutoUnref tf_helper(tf);
-
- return Font(tf, font_family_, font_size_ + size_delta, style);
-}
-
-void Font::PaintSetup(SkPaint* paint) const {
- paint->setAntiAlias(false);
- paint->setSubpixelText(false);
- paint->setTextSize(SkFloatToScalar(font_size_ * Font::GetPangoScaleFactor()));
- paint->setTypeface(typeface_);
- paint->setFakeBoldText((BOLD & style_) && !typeface_->isBold());
- paint->setTextSkewX((ITALIC & style_) && !typeface_->isItalic() ?
- -SK_Scalar1/4 : 0);
-}
-
-int Font::GetStringWidth(const std::wstring& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, *this, &width, &height,
- gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
-void Font::InitPangoMetrics() {
- if (!pango_metrics_inited_) {
- pango_metrics_inited_ = true;
- PangoFontDescription* pango_desc = PangoFontFromGfxFont(*this);
- PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc);
-
- underline_position_ =
- pango_font_metrics_get_underline_position(pango_metrics);
- underline_position_ /= PANGO_SCALE;
-
- // todo(davemoore) Come up with a better solution.
- // This is a hack, but without doing this the underlines
- // we get end up fuzzy. So we align to the midpoint of a pixel.
- underline_position_ /= 2;
-
- underline_thickness_ =
- pango_font_metrics_get_underline_thickness(pango_metrics);
- underline_thickness_ /= PANGO_SCALE;
-
- // First get the pango based width
- double pango_width =
- pango_font_metrics_get_approximate_char_width(pango_metrics);
- pango_width /= PANGO_SCALE;
-
- // Yes, this is how Microsoft recommends calculating the dialog unit
- // conversions.
- int text_width = GetStringWidth(
- L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
- double dialog_units = (text_width / 26 + 1) / 2;
- avg_width_ = std::min(pango_width, dialog_units);
- pango_font_description_free(pango_desc);
- }
-}
-
-double Font::avg_width() const {
- const_cast<Font*>(this)->InitPangoMetrics();
- return avg_width_;
-}
-
-double Font::underline_position() const {
- const_cast<Font*>(this)->InitPangoMetrics();
- return underline_position_;
-}
-
-double Font::underline_thickness() const {
- const_cast<Font*>(this)->InitPangoMetrics();
- return underline_thickness_;
-}
-
-int Font::GetExpectedTextWidth(int length) const {
- double char_width = const_cast<Font*>(this)->avg_width();
- return round(static_cast<float>(length) * char_width);
-}
-
-int Font::style() const {
- return style_;
-}
-
-const std::wstring& Font::FontName() const {
- return font_family_;
-}
-
-int Font::FontSize() {
- return font_size_;
-}
-
-NativeFont Font::nativeFont() const {
- return typeface_;
-}
-
-} // namespace gfx
diff --git a/gfx/font_unittest.cc b/gfx/font_unittest.cc
index 6e63951..d2eda1c 100644
--- a/gfx/font_unittest.cc
+++ b/gfx/font_unittest.cc
@@ -14,35 +14,35 @@ class FontTest : public testing::Test {
};
TEST_F(FontTest, LoadArial) {
- Font cf(Font::CreateFont(L"Arial", 16));
- ASSERT_TRUE(cf.nativeFont());
- ASSERT_EQ(cf.style(), Font::NORMAL);
- ASSERT_EQ(cf.FontSize(), 16);
- ASSERT_EQ(cf.FontName(), L"Arial");
+ Font cf(L"Arial", 16);
+ ASSERT_TRUE(cf.GetNativeFont());
+ ASSERT_EQ(cf.GetStyle(), Font::NORMAL);
+ ASSERT_EQ(cf.GetFontSize(), 16);
+ ASSERT_EQ(cf.GetFontName(), L"Arial");
}
TEST_F(FontTest, LoadArialBold) {
- Font cf(Font::CreateFont(L"Arial", 16));
+ Font cf(L"Arial", 16);
Font bold(cf.DeriveFont(0, Font::BOLD));
- ASSERT_TRUE(bold.nativeFont());
- ASSERT_EQ(bold.style(), Font::BOLD);
+ ASSERT_TRUE(bold.GetNativeFont());
+ ASSERT_EQ(bold.GetStyle(), Font::BOLD);
}
TEST_F(FontTest, Ascent) {
- Font cf(Font::CreateFont(L"Arial", 16));
- ASSERT_GT(cf.baseline(), 2);
- ASSERT_LE(cf.baseline(), 22);
+ Font cf(L"Arial", 16);
+ ASSERT_GT(cf.GetBaseline(), 2);
+ ASSERT_LE(cf.GetBaseline(), 22);
}
TEST_F(FontTest, Height) {
- Font cf(Font::CreateFont(L"Arial", 16));
- ASSERT_GE(cf.height(), 16);
+ Font cf(L"Arial", 16);
+ ASSERT_GE(cf.GetHeight(), 16);
// TODO(akalin): Figure out why height is so large on Linux.
- ASSERT_LE(cf.height(), 26);
+ ASSERT_LE(cf.GetHeight(), 26);
}
TEST_F(FontTest, AvgWidths) {
- Font cf(Font::CreateFont(L"Arial", 16));
+ Font cf(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));
@@ -50,7 +50,7 @@ TEST_F(FontTest, AvgWidths) {
}
TEST_F(FontTest, Widths) {
- Font cf(Font::CreateFont(L"Arial", 16));
+ Font cf(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"));
@@ -61,20 +61,20 @@ TEST_F(FontTest, Widths) {
// http://crbug.com/46733
TEST_F(FontTest, FAILS_DeriveFontResizesIfSizeTooSmall) {
// This creates font of height -8.
- Font cf(Font::CreateFont(L"Arial", 6));
+ Font cf(L"Arial", 6);
Font derived_font = cf.DeriveFont(-4);
LOGFONT font_info;
- GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info);
+ GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info);
EXPECT_EQ(-5, font_info.lfHeight);
}
TEST_F(FontTest, DeriveFontKeepsOriginalSizeIfHeightOk) {
// This creates font of height -8.
- Font cf(Font::CreateFont(L"Arial", 6));
+ Font cf(L"Arial", 6);
Font derived_font = cf.DeriveFont(-2);
LOGFONT font_info;
- GetObject(derived_font.hfont(), sizeof(LOGFONT), &font_info);
+ GetObject(derived_font.GetNativeFont(), sizeof(LOGFONT), &font_info);
EXPECT_EQ(-6, font_info.lfHeight);
}
#endif
-} // anonymous namespace
+} // namespace
diff --git a/gfx/font_win.cc b/gfx/font_win.cc
deleted file mode 100644
index f9b7243..0000000
--- a/gfx/font_win.cc
+++ /dev/null
@@ -1,216 +0,0 @@
-// 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.
-
-#include "gfx/font.h"
-
-#include <windows.h>
-#include <math.h>
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "base/string_util.h"
-#include "base/win_util.h"
-#include "gfx/canvas_skia.h"
-
-namespace gfx {
-
-// static
-Font::HFontRef* Font::base_font_ref_;
-
-// static
-Font::AdjustFontCallback Font::adjust_font_callback = NULL;
-Font::GetMinimumFontSizeCallback Font::get_minimum_font_size_callback = NULL;
-
-// If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
-// font is bold.
-static const int kTextMetricWeightBold = 700;
-
-// Returns either minimum font allowed for a current locale or
-// lf_height + size_delta value.
-static int AdjustFontSize(int lf_height, int size_delta) {
- if (lf_height < 0) {
- lf_height -= size_delta;
- } else {
- lf_height += size_delta;
- }
- int min_font_size = 0;
- if (Font::get_minimum_font_size_callback)
- min_font_size = Font::get_minimum_font_size_callback();
- // Make sure lf_height is not smaller than allowed min font size for current
- // locale.
- if (abs(lf_height) < min_font_size) {
- return lf_height < 0 ? -min_font_size : min_font_size;
- } else {
- return lf_height;
- }
-}
-
-//
-// Font
-//
-
-Font::Font()
- : font_ref_(GetBaseFontRef()) {
-}
-
-int Font::height() const {
- return font_ref_->height();
-}
-
-int Font::baseline() const {
- return font_ref_->baseline();
-}
-
-int Font::ave_char_width() const {
- return font_ref_->ave_char_width();
-}
-
-int Font::GetExpectedTextWidth(int length) const {
- return length * std::min(font_ref_->dlu_base_x(), ave_char_width());
-}
-
-int Font::style() const {
- return font_ref_->style();
-}
-
-NativeFont Font::nativeFont() const {
- return hfont();
-}
-
-// static
-Font Font::CreateFont(HFONT font) {
- DCHECK(font);
- LOGFONT font_info;
- GetObject(font, sizeof(LOGFONT), &font_info);
- return Font(CreateHFontRef(CreateFontIndirect(&font_info)));
-}
-
-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 Font::CreateFont(hf);
-}
-
-// static
-Font::HFontRef* Font::GetBaseFontRef() {
- if (base_font_ref_ == NULL) {
- NONCLIENTMETRICS metrics;
- win_util::GetNonClientMetrics(&metrics);
-
- if (adjust_font_callback)
- adjust_font_callback(&metrics.lfMessageFont);
- metrics.lfMessageFont.lfHeight =
- AdjustFontSize(metrics.lfMessageFont.lfHeight, 0);
- HFONT font = CreateFontIndirect(&metrics.lfMessageFont);
- DLOG_ASSERT(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_;
-}
-
-const std::wstring& Font::FontName() const {
- return font_ref_->font_name();
-}
-
-int Font::FontSize() {
- LOGFONT font_info;
- GetObject(hfont(), sizeof(LOGFONT), &font_info);
- long lf_height = font_info.lfHeight;
- HDC hdc = GetDC(NULL);
- int device_caps = GetDeviceCaps(hdc, LOGPIXELSY);
- int font_size = 0;
- if (device_caps != 0) {
- float font_size_float = -static_cast<float>(lf_height)*72/device_caps;
- font_size = static_cast<int>(::ceil(font_size_float - 0.5));
- }
- ReleaseDC(NULL, hdc);
- return font_size;
-}
-
-Font::HFontRef::HFontRef(HFONT hfont,
- int height,
- int baseline,
- int ave_char_width,
- int style,
- int dlu_base_x)
- : hfont_(hfont),
- height_(height),
- baseline_(baseline),
- ave_char_width_(ave_char_width),
- style_(style),
- dlu_base_x_(dlu_base_x) {
- DLOG_ASSERT(hfont);
-
- LOGFONT font_info;
- GetObject(hfont_, sizeof(LOGFONT), &font_info);
- font_name_ = std::wstring(font_info.lfFaceName);
-}
-
-Font::HFontRef::~HFontRef() {
- DeleteObject(hfont_);
-}
-
-Font Font::DeriveFont(int size_delta, int style) const {
- LOGFONT font_info;
- GetObject(hfont(), sizeof(LOGFONT), &font_info);
- font_info.lfHeight = AdjustFontSize(font_info.lfHeight, size_delta);
- font_info.lfUnderline = ((style & UNDERLINED) == UNDERLINED);
- font_info.lfItalic = ((style & ITALIC) == ITALIC);
- font_info.lfWeight = (style & BOLD) ? FW_BOLD : FW_NORMAL;
-
- HFONT hfont = CreateFontIndirect(&font_info);
- return Font(CreateHFontRef(hfont));
-}
-
-int Font::GetStringWidth(const std::wstring& text) const {
- int width = 0, height = 0;
- CanvasSkia::SizeStringInt(text, *this, &width, &height,
- gfx::Canvas::NO_ELLIPSIS);
- return width;
-}
-
-Font::HFontRef* Font::CreateHFontRef(HFONT font) {
- TEXTMETRIC font_metrics;
- HDC screen_dc = GetDC(NULL);
- HFONT previous_font = static_cast<HFONT>(SelectObject(screen_dc, font));
- int last_map_mode = SetMapMode(screen_dc, MM_TEXT);
- GetTextMetrics(screen_dc, &font_metrics);
- // Yes, this is how Microsoft recommends calculating the dialog unit
- // conversions.
- SIZE ave_text_size;
- GetTextExtentPoint32(screen_dc,
- L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
- 52, &ave_text_size);
- const int dlu_base_x = (ave_text_size.cx / 26 + 1) / 2;
- // To avoid the DC referencing font_handle_, select the previous font.
- SelectObject(screen_dc, previous_font);
- SetMapMode(screen_dc, last_map_mode);
- ReleaseDC(NULL, screen_dc);
-
- const int height = std::max(1, static_cast<int>(font_metrics.tmHeight));
- const int baseline = std::max(1, static_cast<int>(font_metrics.tmAscent));
- const int ave_char_width =
- std::max(1, static_cast<int>(font_metrics.tmAveCharWidth));
- int style = 0;
- if (font_metrics.tmItalic) {
- style |= Font::ITALIC;
- }
- if (font_metrics.tmUnderlined) {
- style |= Font::UNDERLINED;
- }
- if (font_metrics.tmWeight >= kTextMetricWeightBold) {
- style |= Font::BOLD;
- }
-
- return new HFontRef(font, height, baseline, ave_char_width, style,
- dlu_base_x);
-}
-
-} // namespace gfx
diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp
index 5947c4a..9b7e4aa 100644
--- a/gfx/gfx.gyp
+++ b/gfx/gfx.gyp
@@ -97,9 +97,7 @@
'color_utils.h',
'favicon_size.h',
'font.h',
- 'font_gtk.cc',
- 'font_mac.mm',
- 'font_win.cc',
+ 'font.cc',
'gfx_paths.cc',
'gfx_paths.h',
'insets.cc',
@@ -109,6 +107,13 @@
'path.h',
'path_gtk.cc',
'path_win.cc',
+ 'platform_font.h',
+ 'platform_font_gtk.h',
+ 'platform_font_gtk.cc',
+ 'platform_font_mac.h',
+ 'platform_font_mac.mm',
+ 'platform_font_win.h',
+ 'platform_font_win.cc',
'point.cc',
'point.h',
'rect.cc',
@@ -151,7 +156,6 @@
'../build/linux/system.gyp:gtk',
],
'sources': [
- 'font_skia.cc',
'gtk_native_view_id_manager.cc',
'gtk_native_view_id_manager.h',
'gtk_util.cc',
diff --git a/gfx/native_widget_types.h b/gfx/native_widget_types.h
index 5cc032a..51b0885 100644
--- a/gfx/native_widget_types.h
+++ b/gfx/native_widget_types.h
@@ -35,18 +35,22 @@
#if defined(OS_WIN)
#include <windows.h>
+typedef struct HFONT__* HFONT;
#elif defined(OS_MACOSX)
struct CGContext;
#ifdef __OBJC__
+@class NSFont;
@class NSView;
@class NSWindow;
@class NSTextField;
#else
+class NSFont;
class NSView;
class NSWindow;
class NSTextField;
#endif // __OBJC__
#elif defined(TOOLKIT_USES_GTK)
+typedef struct _PangoFontDescription PangoFontDescription;
typedef struct _GdkCursor GdkCursor;
typedef struct _GdkRegion GdkRegion;
typedef struct _GtkWidget GtkWidget;
@@ -57,6 +61,7 @@ typedef struct _cairo cairo_t;
namespace gfx {
#if defined(OS_WIN)
+typedef HFONT NativeFont;
typedef HWND NativeView;
typedef HWND NativeWindow;
typedef HWND NativeEditView;
@@ -65,6 +70,7 @@ typedef HCURSOR NativeCursor;
typedef HMENU NativeMenu;
typedef HRGN NativeRegion;
#elif defined(OS_MACOSX)
+typedef NSFont* NativeFont;
typedef NSView* NativeView;
typedef NSWindow* NativeWindow;
typedef NSTextField* NativeEditView;
@@ -72,6 +78,7 @@ typedef CGContext* NativeDrawingContext;
typedef void* NativeCursor;
typedef void* NativeMenu;
#elif defined(USE_X11)
+typedef PangoFontDescription* NativeFont;
typedef GtkWidget* NativeView;
typedef GtkWindow* NativeWindow;
typedef GtkWidget* NativeEditView;
diff --git a/gfx/platform_font.h b/gfx/platform_font.h
new file mode 100644
index 0000000..df3c7f2
--- /dev/null
+++ b/gfx/platform_font.h
@@ -0,0 +1,78 @@
+// 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.
+
+#ifndef GFX_PLATFORM_FONT_
+#define GFX_PLATFORM_FONT_
+#pragma once
+
+#include <string>
+
+#include "base/ref_counted.h"
+#include "gfx/native_widget_types.h"
+
+namespace gfx {
+
+class Font;
+
+class PlatformFont : public base::RefCounted<PlatformFont> {
+ public:
+ // Create an appropriate PlatformFont implementation.
+ static PlatformFont* CreateDefault();
+ static PlatformFont* CreateFromFont(const Font& other);
+ static PlatformFont* CreateFromNativeFont(NativeFont native_font);
+ static PlatformFont* CreateFromNameAndSize(const std::wstring& font_name,
+ int font_size);
+
+ // Returns a new Font derived from the existing font.
+ // size_delta is the size to add to the current font. See the single
+ // 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.
+ virtual Font DeriveFont(int size_delta, int style) const = 0;
+
+ // Returns the number of vertical pixels needed to display characters from
+ // the specified font. This may include some leading, i.e. height may be
+ // greater than just ascent + descent. Specifically, the Windows and Mac
+ // implementations include leading and the Linux one does not. This may
+ // need to be revisited in the future.
+ virtual int GetHeight() const = 0;
+
+ // Returns the baseline, or ascent, of the font.
+ virtual int GetBaseline() const = 0;
+
+ // 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 std::wstring& 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.
+ virtual int GetExpectedTextWidth(int length) const = 0;
+
+ // Returns the style of the font.
+ virtual int GetStyle() const = 0;
+
+ // Returns the font name.
+ virtual const std::wstring& GetFontName() const = 0;
+
+ // Returns the font size in pixels.
+ virtual int GetFontSize() const = 0;
+
+ // Returns the native font handle.
+ virtual NativeFont GetNativeFont() const = 0;
+
+ protected:
+ virtual ~PlatformFont() {}
+
+ private:
+ friend class base::RefCounted<PlatformFont>;
+};
+
+} // namespace gfx
+
+#endif // GFX_PLATFORM_FONT_
+
diff --git a/gfx/platform_font_gtk.cc b/gfx/platform_font_gtk.cc
new file mode 100644
index 0000000..db2e0c0
--- /dev/null
+++ b/gfx/platform_font_gtk.cc
@@ -0,0 +1,434 @@
+// 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.
+
+#include "gfx/platform_font_gtk.h"
+
+#include <algorithm>
+#include <fontconfig/fontconfig.h>
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <map>
+#include <pango/pango.h>
+
+#include "base/logging.h"
+#include "base/string_piece.h"
+#include "base/sys_string_conversions.h"
+#include "base/utf_string_conversions.h"
+#include "gfx/canvas_skia.h"
+#include "gfx/font.h"
+#include "gfx/gtk_util.h"
+#include "third_party/skia/include/core/SkTypeface.h"
+#include "third_party/skia/include/core/SkPaint.h"
+
+namespace {
+
+// The font family name which is used when a user's application font for
+// GNOME/KDE is a non-scalable one. The name should be listed in the
+// IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
+const char* kFallbackFontFamilyName = "sans";
+
+// Retrieves the pango metrics for a pango font description. Caches the metrics
+// and never frees them. The metrics objects are relatively small and
+// very expensive to look up.
+PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
+ static std::map<int, PangoFontMetrics*>* desc_to_metrics = NULL;
+ static PangoContext* context = NULL;
+
+ if (!context) {
+ context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
+ pango_context_set_language(context, pango_language_get_default());
+ }
+
+ if (!desc_to_metrics) {
+ desc_to_metrics = new std::map<int, PangoFontMetrics*>();
+ }
+
+ int desc_hash = pango_font_description_hash(desc);
+ std::map<int, PangoFontMetrics*>::iterator i =
+ desc_to_metrics->find(desc_hash);
+
+ if (i == desc_to_metrics->end()) {
+ PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL);
+ (*desc_to_metrics)[desc_hash] = metrics;
+ return metrics;
+ } else {
+ return i->second;
+ }
+}
+
+// Find the best match font for |family_name| in the same way as Skia
+// to make sure CreateFont() successfully creates a default font. In
+// Skia, it only checks the best match font. If it failed to find
+// one, SkTypeface will be NULL for that font family. It eventually
+// causes a segfault. For example, family_name = "Sans" and system
+// may have various fonts. The first font family in FcPattern will be
+// "DejaVu Sans" but a font family returned by FcFontMatch will be "VL
+// PGothic". In this case, SkTypeface for "Sans" returns NULL even if
+// the system has a font for "Sans" font family. See FontMatch() in
+// skia/ports/SkFontHost_fontconfig.cpp for more detail.
+std::wstring FindBestMatchFontFamilyName(const char* family_name) {
+ FcPattern* pattern = FcPatternCreate();
+ FcValue fcvalue;
+ fcvalue.type = FcTypeString;
+ char* family_name_copy = strdup(family_name);
+ fcvalue.u.s = reinterpret_cast<FcChar8*>(family_name_copy);
+ FcPatternAdd(pattern, FC_FAMILY, fcvalue, 0);
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+ FcResult result;
+ FcPattern* match = FcFontMatch(0, pattern, &result);
+ DCHECK(match) << "Could not find font: " << family_name;
+ FcChar8* match_family;
+ FcPatternGetString(match, FC_FAMILY, 0, &match_family);
+
+ std::wstring font_family = UTF8ToWide(reinterpret_cast<char*>(match_family));
+ FcPatternDestroy(match);
+ FcPatternDestroy(pattern);
+ free(family_name_copy);
+ return font_family;
+}
+
+} // namespace
+
+namespace gfx {
+
+Font* PlatformFontGtk::default_font_ = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontGtk, public:
+
+PlatformFontGtk::PlatformFontGtk() {
+ if (default_font_ == NULL) {
+ GtkSettings* settings = gtk_settings_get_default();
+
+ gchar* font_name = NULL;
+ g_object_get(settings, "gtk-font-name", &font_name, NULL);
+
+ // Temporary CHECK for helping track down
+ // http://code.google.com/p/chromium/issues/detail?id=12530
+ CHECK(font_name) << " Unable to get gtk-font-name for default font.";
+
+ PangoFontDescription* desc =
+ pango_font_description_from_string(font_name);
+ default_font_ = new Font(desc);
+ pango_font_description_free(desc);
+ g_free(font_name);
+
+ DCHECK(default_font_);
+ }
+
+ InitFromPlatformFont(
+ static_cast<PlatformFontGtk*>(default_font_->platform_font()));
+}
+
+PlatformFontGtk::PlatformFontGtk(const Font& other) {
+ InitFromPlatformFont(
+ static_cast<PlatformFontGtk*>(other.platform_font()));
+}
+
+PlatformFontGtk::PlatformFontGtk(NativeFont native_font) {
+ gint size = pango_font_description_get_size(native_font);
+ const char* family_name = pango_font_description_get_family(native_font);
+
+ // Find best match font for |family_name| to make sure we can get
+ // a SkTypeface for the default font.
+ // TODO(agl): remove this.
+ std::wstring font_family = FindBestMatchFontFamilyName(family_name);
+
+ InitWithNameAndSize(font_family, size / PANGO_SCALE);
+ int style = 0;
+ if (pango_font_description_get_weight(native_font) == PANGO_WEIGHT_BOLD) {
+ // TODO(davemoore) What should we do about other weights? We currently
+ // only support BOLD.
+ style |= gfx::Font::BOLD;
+ }
+ if (pango_font_description_get_style(native_font) == PANGO_STYLE_ITALIC) {
+ // TODO(davemoore) What about PANGO_STYLE_OBLIQUE?
+ style |= gfx::Font::ITALIC;
+ }
+ if (style != 0)
+ style_ = style;
+}
+
+PlatformFontGtk::PlatformFontGtk(const std::wstring& font_name,
+ int font_size) {
+ InitWithNameAndSize(font_name, font_size);
+}
+
+double PlatformFontGtk::underline_position() const {
+ const_cast<PlatformFontGtk*>(this)->InitPangoMetrics();
+ return underline_position_;
+}
+
+double PlatformFontGtk::underline_thickness() const {
+ const_cast<PlatformFontGtk*>(this)->InitPangoMetrics();
+ return underline_thickness_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontGtk, PlatformFont implementation:
+
+Font PlatformFontGtk::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_);
+
+ if (style == style_) {
+ // Fast path, we just use the same typeface at a different size
+ return Font(new PlatformFontGtk(typeface_,
+ font_family_,
+ font_size_ + size_delta,
+ style_));
+ }
+
+ // If the style has changed we may need to load a new face
+ int skstyle = SkTypeface::kNormal;
+ if (gfx::Font::BOLD & style)
+ skstyle |= SkTypeface::kBold;
+ if (gfx::Font::ITALIC & style)
+ skstyle |= SkTypeface::kItalic;
+
+ SkTypeface* typeface = SkTypeface::CreateFromName(
+ base::SysWideToUTF8(font_family_).c_str(),
+ static_cast<SkTypeface::Style>(skstyle));
+ SkAutoUnref tf_helper(typeface);
+
+ return Font(new PlatformFontGtk(typeface,
+ font_family_,
+ font_size_ + size_delta,
+ style));
+}
+
+int PlatformFontGtk::GetHeight() const {
+ return height_;
+}
+
+int PlatformFontGtk::GetBaseline() const {
+ return ascent_;
+}
+
+int PlatformFontGtk::GetAverageCharacterWidth() const {
+ return SkScalarRound(average_width_);
+}
+
+int PlatformFontGtk::GetStringWidth(const std::wstring& text) const {
+ int width = 0, height = 0;
+ CanvasSkia::SizeStringInt(text, Font(const_cast<PlatformFontGtk*>(this)),
+ &width, &height, gfx::Canvas::NO_ELLIPSIS);
+ return width;
+}
+
+int PlatformFontGtk::GetExpectedTextWidth(int length) const {
+ double char_width = const_cast<PlatformFontGtk*>(this)->GetAverageWidth();
+ return round(static_cast<float>(length) * char_width);
+}
+
+int PlatformFontGtk::GetStyle() const {
+ return style_;
+}
+
+const std::wstring& PlatformFontGtk::GetFontName() const {
+ return font_family_;
+}
+
+int PlatformFontGtk::GetFontSize() const {
+ return font_size_;
+}
+
+NativeFont PlatformFontGtk::GetNativeFont() const {
+ PangoFontDescription* pfd = pango_font_description_new();
+ pango_font_description_set_family(pfd, WideToUTF8(GetFontName()).c_str());
+ // Set the absolute size to avoid overflowing UI elements.
+ pango_font_description_set_absolute_size(pfd,
+ GetFontSize() * PANGO_SCALE * GetPangoScaleFactor());
+
+ switch (GetStyle()) {
+ case gfx::Font::NORMAL:
+ // Nothing to do, should already be PANGO_STYLE_NORMAL.
+ break;
+ case gfx::Font::BOLD:
+ pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD);
+ break;
+ case gfx::Font::ITALIC:
+ pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC);
+ break;
+ 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;
+ }
+
+ return pfd;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontGtk, private:
+
+PlatformFontGtk::PlatformFontGtk(SkTypeface* typeface,
+ const std::wstring& name,
+ int size,
+ int style) {
+ InitWithTypefaceNameSizeAndStyle(typeface, name, size, style);
+}
+
+void PlatformFontGtk::InitWithNameAndSize(const std::wstring& font_name,
+ int font_size) {
+ DCHECK_GT(font_size, 0);
+ std::wstring fallback;
+
+ SkTypeface* typeface = SkTypeface::CreateFromName(
+ base::SysWideToUTF8(font_name).c_str(), SkTypeface::kNormal);
+ if (!typeface) {
+ // A non-scalable font such as .pcf is specified. Falls back to a default
+ // scalable font.
+ typeface = SkTypeface::CreateFromName(
+ kFallbackFontFamilyName, SkTypeface::kNormal);
+ CHECK(typeface) << "Could not find any font: "
+ << base::SysWideToUTF8(font_name)
+ << ", " << kFallbackFontFamilyName;
+ fallback = base::SysUTF8ToWide(kFallbackFontFamilyName);
+ }
+ SkAutoUnref typeface_helper(typeface);
+
+ InitWithTypefaceNameSizeAndStyle(typeface,
+ fallback.empty() ? font_name : fallback,
+ font_size,
+ gfx::Font::NORMAL);
+}
+
+void PlatformFontGtk::InitWithTypefaceNameSizeAndStyle(
+ SkTypeface* typeface,
+ const std::wstring& font_family,
+ int font_size,
+ int style) {
+ typeface_helper_.reset(new SkAutoUnref(typeface));
+ typeface_ = typeface;
+ typeface_->ref();
+ font_family_ = font_family;
+ font_size_ = font_size;
+ style_ = style;
+ pango_metrics_inited_ = false;
+ average_width_ = 0.0f;
+ underline_position_ = 0.0f;
+ underline_thickness_ = 0.0f;
+
+ SkPaint paint;
+ SkPaint::FontMetrics metrics;
+ PaintSetup(&paint);
+ paint.getFontMetrics(&metrics);
+
+ ascent_ = SkScalarCeil(-metrics.fAscent);
+ height_ = ascent_ + SkScalarCeil(metrics.fDescent);
+}
+
+void PlatformFontGtk::InitFromPlatformFont(const PlatformFontGtk* other) {
+ typeface_helper_.reset(new SkAutoUnref(other->typeface_));
+ typeface_ = other->typeface_;
+ typeface_->ref();
+ font_family_ = other->font_family_;
+ font_size_ = other->font_size_;
+ style_ = other->style_;
+ height_ = other->height_;
+ ascent_ = other->ascent_;
+ pango_metrics_inited_ = other->pango_metrics_inited_;
+ average_width_ = other->average_width_;
+ underline_position_ = other->underline_position_;
+ underline_thickness_ = other->underline_thickness_;
+}
+
+void PlatformFontGtk::PaintSetup(SkPaint* paint) const {
+ paint->setAntiAlias(false);
+ paint->setSubpixelText(false);
+ paint->setTextSize(
+ SkFloatToScalar(font_size_ * PlatformFontGtk::GetPangoScaleFactor()));
+ paint->setTypeface(typeface_);
+ paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold());
+ paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ?
+ -SK_Scalar1/4 : 0);
+}
+
+void PlatformFontGtk::InitPangoMetrics() {
+ if (!pango_metrics_inited_) {
+ pango_metrics_inited_ = true;
+ PangoFontDescription* pango_desc = GetNativeFont();
+ PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc);
+
+ underline_position_ =
+ pango_font_metrics_get_underline_position(pango_metrics);
+ underline_position_ /= PANGO_SCALE;
+
+ // todo(davemoore) Come up with a better solution.
+ // This is a hack, but without doing this the underlines
+ // we get end up fuzzy. So we align to the midpoint of a pixel.
+ underline_position_ /= 2;
+
+ underline_thickness_ =
+ pango_font_metrics_get_underline_thickness(pango_metrics);
+ underline_thickness_ /= PANGO_SCALE;
+
+ // First get the pango based width
+ double pango_width =
+ pango_font_metrics_get_approximate_char_width(pango_metrics);
+ pango_width /= PANGO_SCALE;
+
+ // Yes, this is how Microsoft recommends calculating the dialog unit
+ // conversions.
+ int text_width = GetStringWidth(
+ L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
+ double dialog_units = (text_width / 26 + 1) / 2;
+ average_width_ = std::min(pango_width, dialog_units);
+ pango_font_description_free(pango_desc);
+ }
+}
+
+
+float PlatformFontGtk::GetPangoScaleFactor() {
+ // Pango scales font sizes. This returns the scale factor. See
+ // pango_cairo_context_set_resolution for details.
+ // NOTE: this isn't entirely accurate, in that Pango also consults the
+ // FC_PIXEL_SIZE first (see get_font_size in pangocairo-fcfont), but this
+ // seems to give us the same sizes as used by Pango for all our fonts in both
+ // English and Thai.
+ static float scale_factor = gfx::GetPangoResolution();
+ static bool determined_scale = false;
+ if (!determined_scale) {
+ if (scale_factor <= 0)
+ scale_factor = 1;
+ else
+ scale_factor /= 72.0;
+ determined_scale = true;
+ }
+ return scale_factor;
+}
+
+double PlatformFontGtk::GetAverageWidth() const {
+ const_cast<PlatformFontGtk*>(this)->InitPangoMetrics();
+ return average_width_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFont, public:
+
+// static
+PlatformFont* PlatformFont::CreateDefault() {
+ return new PlatformFontGtk;
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromFont(const Font& other) {
+ return new PlatformFontGtk(other);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
+ return new PlatformFontGtk(native_font);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNameAndSize(const std::wstring& font_name,
+ int font_size) {
+ return new PlatformFontGtk(font_name, font_size);
+}
+
+} // namespace gfx
diff --git a/gfx/platform_font_gtk.h b/gfx/platform_font_gtk.h
new file mode 100644
index 0000000..3c507fb
--- /dev/null
+++ b/gfx/platform_font_gtk.h
@@ -0,0 +1,111 @@
+// 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.
+
+#ifndef GFX_PLATFORM_FONT_GTK_
+#define GFX_PLATFORM_FONT_GTK_
+#pragma once
+
+#include "base/scoped_ptr.h"
+#include "gfx/platform_font.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+
+class SkTypeface;
+class SkPaint;
+
+namespace gfx {
+
+class PlatformFontGtk : public PlatformFont {
+ public:
+ PlatformFontGtk();
+ explicit PlatformFontGtk(const Font& other);
+ explicit PlatformFontGtk(NativeFont native_font);
+ PlatformFontGtk(const std::wstring& font_name,
+ int font_size);
+
+ // Converts |gfx_font| to a new pango font. Free the returned font with
+ // pango_font_description_free().
+ static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
+
+ // Position as an offset from the height of the drawn text, used to draw
+ // an underline. This is a negative number, so the underline would be
+ // drawn at y + height + underline_position;
+ double underline_position() const;
+ // The thickness to draw the underline.
+ double underline_thickness() const;
+
+ // Overridden from PlatformFont:
+ virtual Font DeriveFont(int size_delta, int style) const;
+ virtual int GetHeight() const;
+ virtual int GetBaseline() const;
+ virtual int GetAverageCharacterWidth() const;
+ virtual int GetStringWidth(const std::wstring& text) const;
+ virtual int GetExpectedTextWidth(int length) const;
+ virtual int GetStyle() const;
+ virtual const std::wstring& GetFontName() const;
+ virtual int GetFontSize() const;
+ virtual NativeFont GetNativeFont() const;
+
+ private:
+ // Create a new instance of this object with the specified properties. Called
+ // from DeriveFont.
+ PlatformFontGtk(SkTypeface* typeface,
+ const std::wstring& name,
+ int size,
+ int style);
+ virtual ~PlatformFontGtk() {}
+
+ // Initialize this object.
+ void InitWithNameAndSize(const std::wstring& font_name, int font_size);
+ void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface,
+ const std::wstring& name,
+ int size,
+ int style);
+ void InitFromPlatformFont(const PlatformFontGtk* other);
+
+ // Potentially slow call to get pango metrics (average width, underline info).
+ void InitPangoMetrics();
+
+ // Setup a Skia context to use the current typeface
+ void PaintSetup(SkPaint* paint) const;
+
+ // Make |this| a copy of |other|.
+ void CopyFont(const Font& other);
+
+ // Return the scale factor for fonts that account for DPI.
+ static float GetPangoScaleFactor();
+
+ // The average width of a character, initialized and cached if needed.
+ double GetAverageWidth() const;
+
+ // These two both point to the same SkTypeface. We use the SkAutoUnref to
+ // handle the reference counting, but without @typeface_ we would have to
+ // cast the SkRefCnt from @typeface_helper_ every time.
+ scoped_ptr<SkAutoUnref> typeface_helper_;
+ SkTypeface *typeface_;
+
+ // Additional information about the face
+ // Skia actually expects a family name and not a font name.
+ std::wstring font_family_;
+ int font_size_;
+ int style_;
+
+ // Cached metrics, generated at construction
+ int height_;
+ int ascent_;
+
+ // The pango metrics are much more expensive so we wait until we need them
+ // to compute them.
+ bool pango_metrics_inited_;
+ double average_width_;
+ double underline_position_;
+ double underline_thickness_;
+
+ // The default font, used for the default constructor.
+ static Font* default_font_;
+};
+
+} // namespace gfx
+
+#endif // GFX_PLATFORM_FONT_GTK_
+
diff --git a/gfx/platform_font_mac.h b/gfx/platform_font_mac.h
new file mode 100644
index 0000000..71a8262
--- /dev/null
+++ b/gfx/platform_font_mac.h
@@ -0,0 +1,57 @@
+// 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.
+
+#ifndef GFX_PLATFORM_FONT_MAC_
+#define GFX_PLATFORM_FONT_MAC_
+#pragma once
+
+#include "gfx/platform_font.h"
+
+namespace gfx {
+
+class PlatformFontMac : public PlatformFont {
+ public:
+ PlatformFontMac();
+ explicit PlatformFontMac(const Font& other);
+ explicit PlatformFontMac(NativeFont native_font);
+ PlatformFontMac(const std::wstring& font_name,
+ int font_size);
+
+ // Overridden from PlatformFont:
+ virtual Font DeriveFont(int size_delta, int style) const;
+ virtual int GetHeight() const;
+ virtual int GetBaseline() const;
+ virtual int GetAverageCharacterWidth() const;
+ virtual int GetStringWidth(const std::wstring& text) const;
+ virtual int GetExpectedTextWidth(int length) const;
+ virtual int GetStyle() const;
+ virtual const std::wstring& GetFontName() const;
+ virtual int GetFontSize() const;
+ virtual NativeFont GetNativeFont() const;
+
+ private:
+ PlatformFontMac(const std::wstring& font_name, int font_size, int style);
+ virtual ~PlatformFontMac() {}
+
+ // Initialize the object with the specified parameters.
+ void InitWithNameSizeAndStyle(const std::wstring& font_name,
+ int font_size,
+ int style);
+
+ // Calculate and cache the font metrics.
+ void CalculateMetrics();
+
+ std::wstring font_name_;
+ int font_size_;
+ int style_;
+
+ // Cached metrics, generated at construction
+ int height_;
+ int ascent_;
+ int average_width_;
+};
+
+} // namespace gfx
+
+#endif // GFX_PLATFORM_FONT_MAC_
diff --git a/gfx/platform_font_mac.mm b/gfx/platform_font_mac.mm
new file mode 100644
index 0000000..89616c5
--- /dev/null
+++ b/gfx/platform_font_mac.mm
@@ -0,0 +1,142 @@
+// 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.
+
+#include "gfx/platform_font_mac.h"
+
+#include <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#include "base/scoped_nsobject.h"
+#include "base/sys_string_conversions.h"
+#include "gfx/canvas_skia.h"
+#include "gfx/font.h"
+
+namespace gfx {
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontMac, public:
+
+PlatformFontMac::PlatformFontMac() {
+ font_size_ = [NSFont systemFontSize];
+ style_ = gfx::Font::NORMAL;
+ NSFont* system_font = [NSFont systemFontOfSize:font_size_];
+ font_name_ = base::SysNSStringToWide([system_font fontName]);
+ CalculateMetrics();
+}
+
+PlatformFontMac::PlatformFontMac(const Font& other) {
+}
+
+PlatformFontMac::PlatformFontMac(NativeFont native_font) {
+}
+
+PlatformFontMac::PlatformFontMac(const std::wstring& font_name,
+ int font_size) {
+ InitWithNameSizeAndStyle(font_name, font_size, gfx::Font::NORMAL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontMac, PlatformFont implementation:
+
+Font PlatformFontMac::DeriveFont(int size_delta, int style) const {
+ return Font(new PlatformFontMac(font_name_, font_size_ + size_delta, style));
+}
+
+int PlatformFontMac::GetHeight() const {
+ return height_;
+}
+
+int PlatformFontMac::GetBaseline() const {
+ return ascent_;
+}
+
+int PlatformFontMac::GetAverageCharacterWidth() const {
+ return average_width_;
+}
+
+int PlatformFontMac::GetStringWidth(const std::wstring& 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_;
+}
+
+int PlatformFontMac::GetStyle() const {
+ return style_;
+}
+
+const std::wstring& PlatformFontMac::GetFontName() const {
+ return font_name_;
+}
+
+int PlatformFontMac::GetFontSize() const {
+ return font_size_;
+}
+
+NativeFont PlatformFontMac::GetNativeFont() const {
+ // TODO(pinkerton): apply |style_| to font. http://crbug.com/34667
+ // 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_];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontMac, private:
+
+PlatformFontMac::PlatformFontMac(const std::wstring& font_name,
+ int font_size,
+ int style) {
+ InitWithNameSizeAndStyle(font_name, font_size, style);
+}
+
+void PlatformFontMac::InitWithNameSizeAndStyle(const std::wstring& font_name,
+ int font_size,
+ int style) {
+ font_name_ = font_name;
+ font_size_ = font_size;
+ style_ = style;
+ CalculateMetrics();
+}
+
+void PlatformFontMac::CalculateMetrics() {
+ NSFont* font = GetNativeFont();
+ scoped_nsobject<NSLayoutManager> layout_manager(
+ [[NSLayoutManager alloc] init]);
+ height_ = [layout_manager defaultLineHeightForFont:font];
+ ascent_ = [font ascender];
+ average_width_ =
+ [font boundingRectForGlyph:[font glyphWithName:@"x"]].size.width;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFont, public:
+
+// static
+PlatformFont* PlatformFont::CreateDefault() {
+ return new PlatformFontMac;
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromFont(const Font& other) {
+ return new PlatformFontMac(other);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
+ return new PlatformFontMac(native_font);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNameAndSize(const std::wstring& font_name,
+ int font_size) {
+ return new PlatformFontMac(font_name, font_size);
+}
+
+} // namespace gfx
+
diff --git a/gfx/platform_font_win.cc b/gfx/platform_font_win.cc
new file mode 100644
index 0000000..41cadde
--- /dev/null
+++ b/gfx/platform_font_win.cc
@@ -0,0 +1,268 @@
+// 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.
+
+#include "gfx/platform_font_win.h"
+
+#include <windows.h>
+#include <math.h>
+
+#include <algorithm>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/win_util.h"
+#include "gfx/canvas_skia.h"
+#include "gfx/font.h"
+
+namespace {
+
+// If the tmWeight field of a TEXTMETRIC structure has a value >= this, the
+// font is bold.
+const int kTextMetricWeightBold = 700;
+
+// Returns either minimum font allowed for a current locale or
+// lf_height + size_delta value.
+int AdjustFontSize(int lf_height, int size_delta) {
+ if (lf_height < 0) {
+ lf_height -= size_delta;
+ } else {
+ lf_height += size_delta;
+ }
+ int min_font_size = 0;
+ if (gfx::PlatformFontWin::get_minimum_font_size_callback)
+ min_font_size = gfx::PlatformFontWin::get_minimum_font_size_callback();
+ // Make sure lf_height is not smaller than allowed min font size for current
+ // locale.
+ if (abs(lf_height) < min_font_size) {
+ return lf_height < 0 ? -min_font_size : min_font_size;
+ } else {
+ return lf_height;
+ }
+}
+
+} // namespace
+
+namespace gfx {
+
+// static
+PlatformFontWin::HFontRef* PlatformFontWin::base_font_ref_;
+
+// static
+PlatformFontWin::AdjustFontCallback
+ PlatformFontWin::adjust_font_callback = NULL;
+PlatformFontWin::GetMinimumFontSizeCallback
+ PlatformFontWin::get_minimum_font_size_callback = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontWin, public
+
+PlatformFontWin::PlatformFontWin() : font_ref_(GetBaseFontRef()) {
+}
+
+PlatformFontWin::PlatformFontWin(const Font& other) {
+ InitWithCopyOfHFONT(other.GetNativeFont());
+}
+
+PlatformFontWin::PlatformFontWin(NativeFont native_font) {
+ InitWithCopyOfHFONT(native_font);
+}
+
+PlatformFontWin::PlatformFontWin(const std::wstring& font_name,
+ int font_size) {
+ InitWithFontNameAndSize(font_name, font_size);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontWin, PlatformFont implementation:
+
+Font PlatformFontWin::DeriveFont(int size_delta, int style) const {
+ LOGFONT font_info;
+ GetObject(GetNativeFont(), sizeof(LOGFONT), &font_info);
+ font_info.lfHeight = AdjustFontSize(font_info.lfHeight, size_delta);
+ font_info.lfUnderline =
+ ((style & gfx::Font::UNDERLINED) == gfx::Font::UNDERLINED);
+ font_info.lfItalic = ((style & gfx::Font::ITALIC) == gfx::Font::ITALIC);
+ font_info.lfWeight = (style & gfx::Font::BOLD) ? FW_BOLD : FW_NORMAL;
+
+ HFONT hfont = CreateFontIndirect(&font_info);
+ return Font(new PlatformFontWin(CreateHFontRef(hfont)));
+}
+
+int PlatformFontWin::GetHeight() const {
+ return font_ref_->height();
+}
+
+int PlatformFontWin::GetBaseline() const {
+ return font_ref_->baseline();
+}
+
+int PlatformFontWin::GetAverageCharacterWidth() const {
+ return font_ref_->ave_char_width();
+}
+
+int PlatformFontWin::GetStringWidth(const std::wstring& 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());
+}
+
+int PlatformFontWin::GetStyle() const {
+ return font_ref_->style();
+}
+
+const std::wstring& PlatformFontWin::GetFontName() const {
+ return font_ref_->font_name();
+}
+
+int PlatformFontWin::GetFontSize() const {
+ LOGFONT font_info;
+ GetObject(font_ref_->hfont(), sizeof(LOGFONT), &font_info);
+ long lf_height = font_info.lfHeight;
+ HDC hdc = GetDC(NULL);
+ int device_caps = GetDeviceCaps(hdc, LOGPIXELSY);
+ int font_size = 0;
+ if (device_caps != 0) {
+ float font_size_float = -static_cast<float>(lf_height)*72/device_caps;
+ font_size = static_cast<int>(::ceil(font_size_float - 0.5));
+ }
+ ReleaseDC(NULL, hdc);
+ return font_size;
+}
+
+NativeFont PlatformFontWin::GetNativeFont() const {
+ return font_ref_->hfont();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Font, private:
+
+void PlatformFontWin::InitWithCopyOfHFONT(HFONT hfont) {
+ DCHECK(hfont);
+ LOGFONT font_info;
+ GetObject(hfont, sizeof(LOGFONT), &font_info);
+ font_ref_ = CreateHFontRef(CreateFontIndirect(&font_info));
+}
+
+void PlatformFontWin::InitWithFontNameAndSize(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());
+ font_ref_ = CreateHFontRef(hf);
+}
+
+// static
+PlatformFontWin::HFontRef* PlatformFontWin::GetBaseFontRef() {
+ if (base_font_ref_ == NULL) {
+ NONCLIENTMETRICS metrics;
+ win_util::GetNonClientMetrics(&metrics);
+
+ if (adjust_font_callback)
+ adjust_font_callback(&metrics.lfMessageFont);
+ metrics.lfMessageFont.lfHeight =
+ AdjustFontSize(metrics.lfMessageFont.lfHeight, 0);
+ HFONT font = CreateFontIndirect(&metrics.lfMessageFont);
+ DLOG_ASSERT(font);
+ base_font_ref_ = PlatformFontWin::CreateHFontRef(font);
+ // base_font_ref_ is global, up the ref count so it's never deleted.
+ base_font_ref_->AddRef();
+ }
+ return base_font_ref_;
+}
+
+PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRef(HFONT font) {
+ TEXTMETRIC font_metrics;
+ HDC screen_dc = GetDC(NULL);
+ HFONT previous_font = static_cast<HFONT>(SelectObject(screen_dc, font));
+ int last_map_mode = SetMapMode(screen_dc, MM_TEXT);
+ GetTextMetrics(screen_dc, &font_metrics);
+ // Yes, this is how Microsoft recommends calculating the dialog unit
+ // conversions.
+ SIZE ave_text_size;
+ GetTextExtentPoint32(screen_dc,
+ L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+ 52, &ave_text_size);
+ const int dlu_base_x = (ave_text_size.cx / 26 + 1) / 2;
+ // To avoid the DC referencing font_handle_, select the previous font.
+ SelectObject(screen_dc, previous_font);
+ SetMapMode(screen_dc, last_map_mode);
+ ReleaseDC(NULL, screen_dc);
+
+ const int height = std::max(1, static_cast<int>(font_metrics.tmHeight));
+ const int baseline = std::max(1, static_cast<int>(font_metrics.tmAscent));
+ const int ave_char_width =
+ std::max(1, static_cast<int>(font_metrics.tmAveCharWidth));
+ int style = 0;
+ if (font_metrics.tmItalic)
+ style |= Font::ITALIC;
+ if (font_metrics.tmUnderlined)
+ style |= Font::UNDERLINED;
+ if (font_metrics.tmWeight >= kTextMetricWeightBold)
+ style |= Font::BOLD;
+
+ return new HFontRef(font, height, baseline, ave_char_width, style,
+ dlu_base_x);
+}
+
+PlatformFontWin::PlatformFontWin(HFontRef* hfont_ref) : font_ref_(hfont_ref) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFontWin::HFontRef:
+
+PlatformFontWin::HFontRef::HFontRef(HFONT hfont,
+ int height,
+ int baseline,
+ int ave_char_width,
+ int style,
+ int dlu_base_x)
+ : hfont_(hfont),
+ height_(height),
+ baseline_(baseline),
+ ave_char_width_(ave_char_width),
+ style_(style),
+ dlu_base_x_(dlu_base_x) {
+ DLOG_ASSERT(hfont);
+
+ LOGFONT font_info;
+ GetObject(hfont_, sizeof(LOGFONT), &font_info);
+ font_name_ = std::wstring(font_info.lfFaceName);
+}
+
+PlatformFontWin::HFontRef::~HFontRef() {
+ DeleteObject(hfont_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PlatformFont, public:
+
+// static
+PlatformFont* PlatformFont::CreateDefault() {
+ return new PlatformFontWin;
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromFont(const Font& other) {
+ return new PlatformFontWin(other);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNativeFont(NativeFont native_font) {
+ return new PlatformFontWin(native_font);
+}
+
+// static
+PlatformFont* PlatformFont::CreateFromNameAndSize(const std::wstring& font_name,
+ int font_size) {
+ return new PlatformFontWin(font_name, font_size);
+}
+
+} // namespace gfx
diff --git a/gfx/platform_font_win.h b/gfx/platform_font_win.h
new file mode 100644
index 0000000..1fd89166
--- /dev/null
+++ b/gfx/platform_font_win.h
@@ -0,0 +1,131 @@
+// 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.
+
+#ifndef GFX_PLATFORM_FONT_WIN_
+#define GFX_PLATFORM_FONT_WIN_
+#pragma once
+
+#include "base/ref_counted.h"
+#include "gfx/platform_font.h"
+
+namespace gfx {
+
+class PlatformFontWin : public PlatformFont {
+ public:
+ PlatformFontWin();
+ explicit PlatformFontWin(const Font& other);
+ explicit PlatformFontWin(NativeFont native_font);
+ PlatformFontWin(const std::wstring& font_name,
+ int font_size);
+
+ // Dialog units to pixels conversion.
+ // See http://support.microsoft.com/kb/145994 for details.
+ int horizontal_dlus_to_pixels(int dlus) const {
+ return dlus * font_ref_->dlu_base_x() / 4;
+ }
+ int vertical_dlus_to_pixels(int dlus) const {
+ return dlus * font_ref_->height() / 8;
+ }
+
+ // Callback that returns the minimum height that should be used for
+ // gfx::Fonts. Optional. If not specified, the minimum font size is 0.
+ typedef int (*GetMinimumFontSizeCallback)();
+ static GetMinimumFontSizeCallback get_minimum_font_size_callback;
+
+ // Callback that adjusts a LOGFONT to meet suitability requirements of the
+ // embedding application. Optional. If not specified, no adjustments are
+ // performed other than clamping to a minimum font height if
+ // |get_minimum_font_size_callback| is specified.
+ typedef void (*AdjustFontCallback)(LOGFONT* lf);
+ static AdjustFontCallback adjust_font_callback;
+
+ // Overridden from PlatformFont:
+ virtual Font DeriveFont(int size_delta, int style) const;
+ virtual int GetHeight() const;
+ virtual int GetBaseline() const;
+ virtual int GetAverageCharacterWidth() const;
+ virtual int GetStringWidth(const std::wstring& text) const;
+ virtual int GetExpectedTextWidth(int length) const;
+ virtual int GetStyle() const;
+ virtual const std::wstring& GetFontName() const;
+ virtual int GetFontSize() const;
+ virtual NativeFont GetNativeFont() const;
+
+ private:
+ virtual ~PlatformFontWin() {}
+
+ // 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, 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 Font can provide value semantics.
+ class HFontRef : public base::RefCounted<HFontRef> {
+ public:
+ // This constructor takes control of the HFONT, and will delete it when
+ // the HFontRef is deleted.
+ HFontRef(HFONT hfont,
+ int height,
+ int baseline,
+ int ave_char_width,
+ int style,
+ int dlu_base_x);
+
+ // Accessors
+ HFONT hfont() const { return hfont_; }
+ int height() const { return height_; }
+ int baseline() const { return baseline_; }
+ int ave_char_width() const { return ave_char_width_; }
+ int style() const { return style_; }
+ int dlu_base_x() const { return dlu_base_x_; }
+ const std::wstring& font_name() const { return font_name_; }
+
+ private:
+ friend class base::RefCounted<HFontRef>;
+
+ ~HFontRef();
+
+ const HFONT hfont_;
+ const int height_;
+ const int baseline_;
+ const int ave_char_width_;
+ const int style_;
+ // Constants used in converting dialog units to pixels.
+ const int dlu_base_x_;
+ std::wstring font_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(HFontRef);
+ };
+
+ // Initializes this object with a copy of the specified HFONT.
+ void InitWithCopyOfHFONT(HFONT hfont);
+
+ // Initializes this object with the specified font name and size.
+ void InitWithFontNameAndSize(const std::wstring& font_name,
+ int font_size);
+
+ // Returns the base font ref. This should ONLY be invoked on the
+ // UI thread.
+ static HFontRef* GetBaseFontRef();
+
+ // Creates and returns a new HFONTRef from the specified HFONT.
+ static HFontRef* CreateHFontRef(HFONT font);
+
+ // Creates a new PlatformFontWin with the specified HFontRef. Used when
+ // constructing a Font from a HFONT we don't want to copy.
+ explicit PlatformFontWin(HFontRef* hfont_ref);
+
+ // Reference to the base font all fonts are derived from.
+ static HFontRef* base_font_ref_;
+
+ // Indirect reference to the HFontRef, which references the underlying HFONT.
+ scoped_refptr<HFontRef> font_ref_;
+};
+
+} // namespace gfx
+
+#endif // GFX_PLATFORM_FONT_WIN_
+
diff --git a/printing/printed_document.cc b/printing/printed_document.cc
index ec040d4..f75a716 100644
--- a/printing/printed_document.cc
+++ b/printing/printed_document.cc
@@ -198,7 +198,7 @@ void PrintedDocument::PrintHeaderFooter(gfx::NativeDrawingContext context,
// May happen if document name or url is empty.
return;
}
- const gfx::Size string_size(font.GetStringWidth(output), font.height());
+ const gfx::Size string_size(font.GetStringWidth(output), font.GetHeight());
gfx::Rect bounding;
bounding.set_height(string_size.height());
const gfx::Rect& overlay_area(
diff --git a/printing/printed_document_win.cc b/printing/printed_document_win.cc
index 5d7ab5f..3a57b94 100644
--- a/printing/printed_document_win.cc
+++ b/printing/printed_document_win.cc
@@ -114,13 +114,13 @@ void PrintedDocument::RenderPrintedPage(
-page_setup.printable_area().x(),
-page_setup.printable_area().y(),
1);
- int base_font_size = gfx::Font().height();
+ int base_font_size = gfx::Font().GetHeight();
int new_font_size = ConvertUnit(10,
immutable_.settings_.desired_dpi,
immutable_.settings_.device_units_per_inch());
DCHECK_GT(new_font_size, base_font_size);
gfx::Font font(gfx::Font().DeriveFont(new_font_size - base_font_size));
- HGDIOBJ old_font = SelectObject(context, font.hfont());
+ HGDIOBJ old_font = SelectObject(context, font.GetNativeFont());
DCHECK(old_font != NULL);
// We don't want a white square around the text ever if overflowing.
SetBkMode(context, TRANSPARENT);
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index 0899e58..404a0ea 100644
--- a/views/controls/button/checkbox.cc
+++ b/views/controls/button/checkbox.cc
@@ -103,7 +103,7 @@ void Checkbox::Layout() {
label_x, 0, std::max(0, width() - label_x -
kLabelFocusPaddingHorizontal),
height());
- int first_line_height = label_->font().height();
+ int first_line_height = label_->font().GetHeight();
native_wrapper_->GetView()->SetBounds(
0, ((first_line_height - checkmark_prefsize.height()) / 2),
checkmark_prefsize.width(), checkmark_prefsize.height());
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc
index 542030a..756cc20 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -4,16 +4,19 @@
#include "views/controls/button/native_button.h"
-#if defined(OS_LINUX)
-#include <gdk/gdkkeysyms.h>
-#include "views/screen.h"
-#endif
-
#include "base/i18n/rtl.h"
#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "views/controls/native/native_view_host.h"
+#if defined(OS_WIN)
+#include "gfx/platform_font_win.h"
+#elif defined(OS_LINUX)
+#include <gdk/gdkkeysyms.h>
+#include "views/screen.h"
+#endif
+
+
namespace views {
#if defined(OS_WIN)
@@ -144,10 +147,14 @@ gfx::Size NativeButton::GetPreferredSize() {
#if defined(OS_WIN)
// Clamp the size returned to at least the minimum size.
if (!ignore_minimum_size_) {
- sz.set_width(std::max(sz.width(),
- font_.horizontal_dlus_to_pixels(kMinWidthDLUs)));
- sz.set_height(std::max(sz.height(),
- font_.vertical_dlus_to_pixels(kMinHeightDLUs)));
+ gfx::PlatformFontWin* platform_font =
+ static_cast<gfx::PlatformFontWin*>(font_.platform_font());
+ sz.set_width(std::max(
+ sz.width(),
+ platform_font->horizontal_dlus_to_pixels(kMinWidthDLUs)));
+ sz.set_height(std::max(
+ sz.height(),
+ platform_font->vertical_dlus_to_pixels(kMinHeightDLUs)));
}
// GTK returns a meaningful preferred size so that we don't need to adjust
// the preferred size as we do on windows.
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index d25f444..6720a50 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -1,6 +1,6 @@
-// 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.
+// 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.
#include "views/controls/button/native_button_gtk.h"
@@ -42,8 +42,7 @@ void NativeButtonGtk::UpdateFont() {
if (!native_view())
return;
- PangoFontDescription* pfd =
- gfx::Font::PangoFontFromGfxFont(native_button_->font());
+ PangoFontDescription* pfd = native_button_->font().GetNativeFont();
gtk_widget_modify_font(native_view(), pfd);
pango_font_description_free(pfd);
preferred_size_ = gfx::Size();
diff --git a/views/controls/button/native_button_win.cc b/views/controls/button/native_button_win.cc
index 9e24fc3..eae509c 100644
--- a/views/controls/button/native_button_win.cc
+++ b/views/controls/button/native_button_win.cc
@@ -49,7 +49,7 @@ void NativeButtonWin::UpdateLabel() {
void NativeButtonWin::UpdateFont() {
SendMessage(native_view(), WM_SETFONT,
- reinterpret_cast<WPARAM>(native_button_->font().hfont()),
+ reinterpret_cast<WPARAM>(native_button_->font().GetNativeFont()),
FALSE);
button_size_valid_ = false;
}
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc
index 2125a02..bcff70d 100644
--- a/views/controls/button/text_button.cc
+++ b/views/controls/button/text_button.cc
@@ -390,7 +390,7 @@ void TextButton::UpdateTextSize() {
gfx::CanvasSkia::SizeStringInt(
text_, font_, &width, &height,
gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_));
- text_size_.SetSize(width, font_.height());
+ text_size_.SetSize(width, font_.GetHeight());
max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()),
std::max(max_text_size_.height(),
text_size_.height()));
diff --git a/views/controls/combobox/native_combobox_win.cc b/views/controls/combobox/native_combobox_win.cc
index a936b0c..b1bc88f 100644
--- a/views/controls/combobox/native_combobox_win.cc
+++ b/views/controls/combobox/native_combobox_win.cc
@@ -182,7 +182,7 @@ void NativeComboboxWin::NativeControlCreated(HWND native_control) {
void NativeComboboxWin::UpdateFont() {
HFONT font = ResourceBundle::GetSharedInstance().
- GetFont(ResourceBundle::BaseFont).hfont();
+ GetFont(ResourceBundle::BaseFont).GetNativeFont();
SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE);
}
diff --git a/views/controls/label.cc b/views/controls/label.cc
index b8d3adc..7953d18 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -58,7 +58,7 @@ gfx::Size Label::GetPreferredSize() {
}
int Label::GetBaseline() {
- return GetInsets().top() + font_.baseline();
+ return GetInsets().top() + font_.GetBaseline();
}
int Label::GetHeightForWidth(int w) {
@@ -66,7 +66,7 @@ int Label::GetHeightForWidth(int w) {
return View::GetHeightForWidth(w);
w = std::max(0, w - GetInsets().width());
- int h = font_.height();
+ int h = font_.GetHeight();
gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags());
return h + GetInsets().height();
}
@@ -292,7 +292,7 @@ gfx::Size Label::GetTextSize() const {
// on Linux.
int w = is_multi_line_ ?
GetAvailableRect().width() : std::numeric_limits<int>::max();
- int h = font_.height();
+ int h = font_.GetHeight();
// For single-line strings, ignore the available width and calculate how
// wide the text wants to be.
int flags = ComputeMultiLineFlags();
diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc
index e072b80..65ed4c9 100644
--- a/views/controls/label_unittest.cc
+++ b/views/controls/label_unittest.cc
@@ -31,11 +31,11 @@ TEST(LabelTest, FontPropertyCourier) {
TEST(LabelTest, FontPropertyArial) {
Label label;
std::wstring font_name(L"arial");
- gfx::Font font = gfx::Font::CreateFont(font_name, 30);
+ gfx::Font font(font_name, 30);
label.SetFont(font);
gfx::Font font_used = label.font();
- EXPECT_EQ(font_name, font_used.FontName());
- EXPECT_EQ(30, font_used.FontSize());
+ EXPECT_EQ(font_name, font_used.GetFontName());
+ EXPECT_EQ(30, font_used.GetFontSize());
}
TEST(LabelTest, TextProperty) {
diff --git a/views/controls/link.cc b/views/controls/link.cc
index b258217..97dc01f 100644
--- a/views/controls/link.cc
+++ b/views/controls/link.cc
@@ -211,15 +211,15 @@ void Link::SetHighlighted(bool f) {
void Link::ValidateStyle() {
if (enabled_) {
- if (!(font().style() & gfx::Font::UNDERLINED)) {
+ if (!(font().GetStyle() & gfx::Font::UNDERLINED)) {
Label::SetFont(
- font().DeriveFont(0, font().style() | gfx::Font::UNDERLINED));
+ font().DeriveFont(0, font().GetStyle() | gfx::Font::UNDERLINED));
}
Label::SetColor(highlighted_ ? highlighted_color_ : normal_color_);
} else {
- if (font().style() & gfx::Font::UNDERLINED) {
+ if (font().GetStyle() & gfx::Font::UNDERLINED) {
Label::SetFont(
- font().DeriveFont(0, font().style() & ~gfx::Font::UNDERLINED));
+ font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED));
}
Label::SetColor(disabled_color_);
}
diff --git a/views/controls/listbox/native_listbox_win.cc b/views/controls/listbox/native_listbox_win.cc
index 5ec5542..76db003 100644
--- a/views/controls/listbox/native_listbox_win.cc
+++ b/views/controls/listbox/native_listbox_win.cc
@@ -105,7 +105,7 @@ void NativeListboxWin::CreateNativeControl() {
listbox_->GetWidget()->GetNativeView(),
NULL, NULL, NULL);
HFONT font = ResourceBundle::GetSharedInstance().
- GetFont(ResourceBundle::BaseFont).hfont();
+ GetFont(ResourceBundle::BaseFont).GetNativeFont();
SendMessage(hwnd, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE);
l10n_util::AdjustUIFontForWindow(hwnd);
diff --git a/views/controls/menu/menu_config_win.cc b/views/controls/menu/menu_config_win.cc
index 5adf9eb..35ab9e2 100644
--- a/views/controls/menu/menu_config_win.cc
+++ b/views/controls/menu/menu_config_win.cc
@@ -30,7 +30,7 @@ MenuConfig* MenuConfig::Create() {
l10n_util::AdjustUIFont(&(metrics.lfMenuFont));
HFONT font = CreateFontIndirect(&metrics.lfMenuFont);
DLOG_ASSERT(font);
- config->font = gfx::Font::CreateFont(font);
+ config->font = gfx::Font(font);
HDC dc = GetDC(NULL);
RECT bounds = { 0, 0, 200, 200 };
diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc
index 5526966..9f77390 100644
--- a/views/controls/menu/menu_item_view_gtk.cc
+++ b/views/controls/menu/menu_item_view_gtk.cc
@@ -44,7 +44,7 @@ gfx::Size MenuItemView::GetPreferredSize() {
// TODO(sky): this is a workaround until I figure out why font.height()
// isn't returning the right thing. We really only want to include
// kFavIconSize if we're showing icons.
- int content_height = std::max(kFavIconSize, font.height());
+ int content_height = std::max(kFavIconSize, font.GetHeight());
return gfx::Size(
font.GetStringWidth(title_) + label_start_ + item_right_margin_ +
GetChildPreferredWidth(),
@@ -155,8 +155,8 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
gfx::Rect text_bounds(label_start_, top_margin +
- (available_height - font.height()) / 2, width,
- font.height());
+ (available_height - font.GetHeight()) / 2, width,
+ font.GetHeight());
text_bounds.set_x(MirroredLeftPointForRect(text_bounds));
canvas->DrawStringInt(GetTitle(), font, fg_color,
text_bounds.x(), text_bounds.y(), text_bounds.width(),
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index 1e36a8c..f2ad60e 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -22,7 +22,7 @@ gfx::Size MenuItemView::GetPreferredSize() {
return gfx::Size(
font.GetStringWidth(title_) + label_start_ + item_right_margin_ +
GetChildPreferredWidth(),
- font.height() + GetBottomMargin() + GetTopMargin());
+ font.GetHeight() + GetBottomMargin() + GetTopMargin());
}
void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
@@ -87,7 +87,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
const gfx::Font& font = MenuConfig::instance().font;
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
int width = this->width() - item_right_margin_ - label_start_ - accel_width;
- gfx::Rect text_bounds(label_start_, top_margin, width, font.height());
+ gfx::Rect text_bounds(label_start_, top_margin, width, font.GetHeight());
text_bounds.set_x(MirroredLeftPointForRect(text_bounds));
if (for_drag) {
// With different themes, it's difficult to tell what the correct
diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc
index 05ada25..90637a0 100644
--- a/views/controls/menu/menu_win.cc
+++ b/views/controls/menu/menu_win.cc
@@ -112,7 +112,7 @@ class MenuHostWindow : public gfx::WindowImpl {
// If the label contains an accelerator, make room for tab.
if (data->label.find(L'\t') != std::wstring::npos)
lpmis->itemWidth += font.GetStringWidth(L" ");
- lpmis->itemHeight = font.height() + kItemBottomMargin + kItemTopMargin;
+ lpmis->itemHeight = font.GetHeight() + kItemBottomMargin + kItemTopMargin;
} else {
// Measure separator size.
lpmis->itemHeight = GetSystemMetrics(SM_CYMENU) / 2;
@@ -158,8 +158,9 @@ class MenuHostWindow : public gfx::WindowImpl {
if (!underline_mnemonics)
format |= DT_HIDEPREFIX;
gfx::Font font;
- HGDIOBJ old_font = static_cast<HFONT>(SelectObject(hDC, font.hfont()));
- int fontsize = font.FontSize();
+ HGDIOBJ old_font =
+ static_cast<HFONT>(SelectObject(hDC, font.GetNativeFont()));
+ int fontsize = font.GetFontSize();
// If an accelerator is specified (with a tab delimiting the rest of the
// label from the accelerator), we have to justify the fist part on the
diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc
index a89fa63..2ddf336 100644
--- a/views/controls/menu/native_menu_gtk.cc
+++ b/views/controls/menu/native_menu_gtk.cc
@@ -316,8 +316,9 @@ GtkWidget* NativeMenuGtk::AddMenuItemAt(int index,
// The label item is the first child of the menu item.
GtkWidget* label_widget = GTK_BIN(menu_item)->child;
DCHECK(label_widget && GTK_IS_LABEL(label_widget));
- gtk_widget_modify_font(label_widget,
- gfx::Font::PangoFontFromGfxFont(*font));
+ PangoFontDescription* pfd = font->GetNativeFont();
+ gtk_widget_modify_font(label_widget, pfd);
+ pango_font_description_free(pfd);
}
if (type == menus::MenuModel::TYPE_SUBMENU) {
diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc
index cc528e3..f65cfcd 100644
--- a/views/controls/menu/native_menu_win.cc
+++ b/views/controls/menu/native_menu_win.cc
@@ -151,7 +151,7 @@ class NativeMenuWin::MenuHostWindow {
if (data->label.find(L'\t') != std::wstring::npos)
measure_item_struct->itemWidth += font.GetStringWidth(L" ");
measure_item_struct->itemHeight =
- font.height() + kItemBottomMargin + kItemTopMargin;
+ font.GetHeight() + kItemBottomMargin + kItemTopMargin;
} else {
// Measure separator size.
measure_item_struct->itemHeight = GetSystemMetrics(SM_CYMENU) / 2;
@@ -196,8 +196,9 @@ class NativeMenuWin::MenuHostWindow {
if (!underline_mnemonics)
format |= DT_HIDEPREFIX;
gfx::Font font;
- HGDIOBJ old_font = static_cast<HFONT>(SelectObject(dc, font.hfont()));
- int fontsize = font.FontSize();
+ HGDIOBJ old_font =
+ static_cast<HFONT>(SelectObject(dc, font.GetNativeFont()));
+ int fontsize = font.GetFontSize();
// If an accelerator is specified (with a tab delimiting the rest of the
// label from the accelerator), we have to justify the fist part on the
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
index 23b2c50..8abc73c 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
@@ -284,7 +284,7 @@ void NativeTabbedPaneWin::CreateNativeControl() {
NULL);
HFONT font = ResourceBundle::GetSharedInstance().
- GetFont(ResourceBundle::BaseFont).hfont();
+ GetFont(ResourceBundle::BaseFont).GetNativeFont();
SendMessage(tab_control, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE);
// Create the view container which is a child of the TabControl.
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index 726283c..510d536 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -1544,7 +1544,7 @@ gfx::Rect TableView::GetAltTextBounds() {
gfx::Font font = GetAltTextFont();
// Pad height by 2 for halo.
return gfx::Rect(kXOffset, content_offset(), client_rect.width() - kXOffset,
- std::max(kImageSize, font.height() + 2));
+ std::max(kImageSize, font.GetHeight() + 2));
}
gfx::Font TableView::GetAltTextFont() {
diff --git a/views/controls/textfield/gtk_views_entry.cc b/views/controls/textfield/gtk_views_entry.cc
index a068009..eaf4459 100644
--- a/views/controls/textfield/gtk_views_entry.cc
+++ b/views/controls/textfield/gtk_views_entry.cc
@@ -38,7 +38,7 @@ static gint gtk_views_entry_expose_event(GtkWidget *widget,
UTF16ToWide(text), font,
gfx::GdkColorToSkColor(widget->style->text[GTK_STATE_INSENSITIVE]),
insets.left(), insets.top(),
- widget->allocation.width - insets.width(), font.height());
+ widget->allocation.width - insets.width(), font.GetHeight());
}
}
diff --git a/views/controls/textfield/gtk_views_textview.cc b/views/controls/textfield/gtk_views_textview.cc
index da43d93..b7ec107 100644
--- a/views/controls/textfield/gtk_views_textview.cc
+++ b/views/controls/textfield/gtk_views_textview.cc
@@ -53,7 +53,7 @@ static gint gtk_views_textview_expose_event(GtkWidget *widget,
UTF16ToWide(text), font,
gfx::GdkColorToSkColor(widget->style->text[GTK_STATE_INSENSITIVE]),
insets.left(), insets.top(),
- widget->allocation.width - insets.width(), font.height());
+ widget->allocation.width - insets.width(), font.GetHeight());
}
}
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 7fd05ad..9cf4832 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -235,8 +235,7 @@ void NativeTextfieldGtk::UpdateReadOnly() {
void NativeTextfieldGtk::UpdateFont() {
if (!native_view())
return;
- PangoFontDescription* pfd =
- gfx::Font::PangoFontFromGfxFont(textfield_->font());
+ PangoFontDescription* pfd = textfield_->font().GetNativeFont();
gtk_widget_modify_font(native_view(), pfd);
pango_font_description_free(pfd);
}
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index be1a0bae..fc4ad8b 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -226,7 +226,8 @@ void NativeTextfieldWin::UpdateReadOnly() {
void NativeTextfieldWin::UpdateFont() {
SendMessage(m_hWnd, WM_SETFONT,
- reinterpret_cast<WPARAM>(textfield_->font().hfont()), TRUE);
+ reinterpret_cast<WPARAM>(textfield_->font().GetNativeFont()),
+ TRUE);
// Setting the font blows away any text color we've set, so reset it.
UpdateTextColor();
}
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index c98fcc6..43f0897 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -225,7 +225,7 @@ gfx::Size Textfield::GetPreferredSize() {
insets = native_wrapper_->CalculateInsets();
return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) +
insets.width(),
- num_lines_ * font_.height() + insets.height());
+ num_lines_ * font_.GetHeight() + insets.height());
}
bool Textfield::IsFocusable() const {
diff --git a/views/drag_utils.cc b/views/drag_utils.cc
index 6bec1a6..0579ba5 100644
--- a/views/drag_utils.cc
+++ b/views/drag_utils.cc
@@ -65,7 +65,7 @@ void CreateDragImageForFile(const FilePath::StringType& file_name,
const int width = kFileDragImageMaxWidth;
// Add +2 here to allow room for the halo.
- const int height = font.height() + icon->height() +
+ const int height = font.GetHeight() + icon->height() +
kLinkDragImageVPadding + 2;
gfx::CanvasSkia canvas(width, height, false /* translucent */);
@@ -77,13 +77,13 @@ void CreateDragImageForFile(const FilePath::StringType& file_name,
std::wstring name = file_util::GetFilenameFromPath(file_name);
canvas.DrawStringWithHalo(name, font, kFileDragImageTextColor, SK_ColorWHITE,
1, icon->height() + kLinkDragImageVPadding + 1,
- width - 2, font.height(),
+ width - 2, font.GetHeight(),
gfx::Canvas::TEXT_ALIGN_CENTER);
#else
std::wstring name = FilePath(file_name).BaseName().ToWStringHack();
canvas.DrawStringInt(name, font, kFileDragImageTextColor,
0, icon->height() + kLinkDragImageVPadding,
- width, font.height(), gfx::Canvas::TEXT_ALIGN_CENTER);
+ width, font.GetHeight(), gfx::Canvas::TEXT_ALIGN_CENTER);
#endif
SetDragImageOnDataObject(canvas, gfx::Size(width, height),
diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc
index c42472a..9b4442d 100644
--- a/views/view_text_utils.cc
+++ b/views/view_text_utils.cc
@@ -62,7 +62,7 @@ void DrawTextAndPositionUrl(gfx::Canvas* canvas,
if (link && rect) {
gfx::Size sz = link->GetPreferredSize();
gfx::Insets insets = link->GetInsets();
- WrapIfWordDoesntFit(sz.width(), font.height(), position, bounds);
+ WrapIfWordDoesntFit(sz.width(), font.GetHeight(), position, bounds);
int x = position->width();
int y = position->height();
@@ -116,11 +116,11 @@ void DrawTextStartingFrom(gfx::Canvas* canvas,
else
word = text; // Draw the whole text at once.
- int w = font.GetStringWidth(word), h = font.height();
+ int w = font.GetStringWidth(word), h = font.GetHeight();
gfx::CanvasSkia::SizeStringInt(word, font, &w, &h, flags);
// If we exceed the boundaries, we need to wrap.
- WrapIfWordDoesntFit(w, font.height(), position, bounds);
+ WrapIfWordDoesntFit(w, font.GetHeight(), position, bounds);
int x = label->MirroredXCoordinateInsideView(position->width()) +
bounds.x();
@@ -130,7 +130,7 @@ void DrawTextStartingFrom(gfx::Canvas* canvas,
// draw the trailing space (if one exists after the LTR text) to the
// left of the LTR string.
if (ltr_within_rtl && word[word.size() - 1] == L' ') {
- int space_w = font.GetStringWidth(L" "), space_h = font.height();
+ int space_w = font.GetStringWidth(L" "), space_h = font.GetHeight();
gfx::CanvasSkia::SizeStringInt(L" ", font, &space_w, &space_h, flags);
x += space_w;
}
@@ -138,13 +138,13 @@ void DrawTextStartingFrom(gfx::Canvas* canvas,
int y = position->height() + bounds.y();
// Draw the text on the screen (mirrored, if RTL run).
- canvas->DrawStringInt(word, font, text_color, x, y, w, font.height(),
+ canvas->DrawStringInt(word, font, text_color, x, y, w, font.GetHeight(),
flags);
if (word.size() > 0 && word[word.size() - 1] == L'\x0a') {
// When we come across '\n', we move to the beginning of the next line.
position->set_width(0);
- position->Enlarge(0, font.height());
+ position->Enlarge(0, font.GetHeight());
} else {
// Otherwise, we advance position to the next word.
position->Enlarge(w, 0);
diff --git a/views/widget/tooltip_manager_gtk.cc b/views/widget/tooltip_manager_gtk.cc
index 9ea6a00..8099272 100644
--- a/views/widget/tooltip_manager_gtk.cc
+++ b/views/widget/tooltip_manager_gtk.cc
@@ -30,7 +30,7 @@ static gfx::Font* LoadDefaultFont() {
gtk_widget_realize(window);
GtkStyle* style = gtk_widget_get_style(label);
- gfx::Font* font = new gfx::Font(gfx::Font::CreateFont(style->font_desc));
+ gfx::Font* font = new gfx::Font(style->font_desc);
gtk_widget_destroy(window);
diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc
index 5a1e4bf..3ee1f23 100644
--- a/views/widget/tooltip_manager_win.cc
+++ b/views/widget/tooltip_manager_win.cc
@@ -37,7 +37,7 @@ static gfx::Font DetermineDefaultFont() {
WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(),
TOOLTIPS_CLASS, NULL, 0 , 0, 0, 0, 0, NULL, NULL, NULL, NULL);
HFONT hfont = reinterpret_cast<HFONT>(SendMessage(window, WM_GETFONT, 0, 0));
- gfx::Font font = hfont ? gfx::Font::CreateFont(hfont) : gfx::Font();
+ gfx::Font font = hfont ? gfx::Font(hfont) : gfx::Font();
DestroyWindow(window);
return font;
}
@@ -260,7 +260,7 @@ int TooltipManagerWin::CalcTooltipHeight() {
} else {
// Tooltip is using the system font. Use gfx::Font, which should pick
// up the system font.
- height = gfx::Font().height();
+ height = gfx::Font().GetHeight();
}
// Get the margins from the tooltip
RECT tooltip_margin;
diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc
index ed83578..89d9491 100644
--- a/views/window/custom_frame_view.cc
+++ b/views/window/custom_frame_view.cc
@@ -280,7 +280,7 @@ int CustomFrameView::IconSize() const {
// size are increased.
return GetSystemMetrics(SM_CYSMICON);
#else
- return std::max(title_font_->height(), kIconMinimumSize);
+ return std::max(title_font_->GetHeight(), kIconMinimumSize);
#endif
}
@@ -541,7 +541,7 @@ void CustomFrameView::LayoutTitleBar() {
// Size the title.
int title_x = d->ShouldShowWindowIcon() ?
icon_bounds.right() + kIconTitleSpacing : icon_bounds.x();
- int title_height = title_font_->height();
+ int title_height = title_font_->GetHeight();
// We bias the title position so that when the difference between the icon and
// title heights is odd, the extra pixel of the title is above the vertical
// midline rather than below. This compensates for how the icon is already