summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 18:54:50 +0000
committerderat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-28 18:54:50 +0000
commitc8a5c738737660e788c6f30455406546362cace1 (patch)
tree74f4519ea7d7c18c0e847d3d529086e91ee80a71
parentebb54a416dd427df5f2c51eb71ac89f1a7e936dc (diff)
downloadchromium_src-c8a5c738737660e788c6f30455406546362cace1.zip
chromium_src-c8a5c738737660e788c6f30455406546362cace1.tar.gz
chromium_src-c8a5c738737660e788c6f30455406546362cace1.tar.bz2
linux: Make PlatformFontGtk deal only in pixels.
gfx::Font deals with pixels (at least, its GetFontSize() method is documented as returning them and that's what all of the metrics-related methods return; I'm assuming that the |font_size| argument in its constructors deals with the same units). PlatformFontGtk's constructor treated |font_size| as points, though, and mostly used points internally. This change makes PlatformFontGtk use pixels internally and renames all of the variables to describe their units. It also changes the size of the omnibox suggestion text: - on Chrome OS, it matches the size of the omnibox text - on Linux, it's slightly smaller (similar to Windows) It also makes us update the suggestion text size when switching between standard and GTK+ themes (the omnibox itself already handled this correctly). Tested with the following configurations in a regular GTK+ build: 120 DPI, GTK+ theme: - 13-pixel tab text - 16-pixel omnibox text - 13-pixel omnibox popup text - 16-pixel popup location text 96 DPI, GTK+ theme: - 13-pixel tab text - 13-pixel omnibox popup text - 12-pixel omnibox popup text - 13-pixel popup location text 72 DPI, GTK+ theme: - 13-pixel tab text - 9-pixel omnibox popup text - 9-pixel omnibox popup text - 9-pixel popup location text 120 DPI, Classic theme: - 13-pixel tab text - 13-pixel omnibox text - 12-pixel omnibox popup text - 10-pixel popup location text 96 DPI, Classic theme: - 13-pixel tab text - 13-pixel omnibox text - 12-pixel omnibox popup text - 10-pixel popup location text 72 DPI, Classic theme: - 13-pixel tab text - 13-pixel omnibox text - 12-pixel omnibox popup text - 10-pixel popup location text Put more simply: - Regular themes use hardcoded font sizes. - The GTK+ theme uses a hardcoded font size for tabs and sizes based on the DPI for the omnibox. BUG=61433,26354,chromium-os:8658 TEST=see above. also took screenshots and checked that the onscreen font size matches that passed to gfx::Font and that the computed metrics are correct, and built a Chrome OS image to verify that things look reasonable, and verified that text isn't clipped on the "Aw, Snap!" page Review URL: http://codereview.chromium.org/6378007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72985 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc64
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc19
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.h8
-rw-r--r--chrome/browser/chromeos/login/background_view.cc8
-rw-r--r--chrome/browser/chromeos/login/helper.h16
-rw-r--r--chrome/browser/chromeos/login/network_selection_view.cc9
-rw-r--r--chrome/browser/chromeos/login/new_user_view.cc2
-rw-r--r--chrome/browser/chromeos/login/screen_lock_view.cc3
-rw-r--r--chrome/browser/chromeos/login/user_controller.cc3
-rw-r--r--chrome/browser/defaults.cc17
-rw-r--r--chrome/browser/defaults.h11
-rw-r--r--chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc6
-rw-r--r--chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc4
-rw-r--r--gfx/font.cc1
-rw-r--r--gfx/font.h1
-rw-r--r--gfx/gtk_util.cc4
-rw-r--r--gfx/platform_font_gtk.cc140
-rw-r--r--gfx/platform_font_gtk.h16
19 files changed, 182 insertions, 156 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 30db56a..f59e00d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -36,6 +36,7 @@
#include "third_party/undoview/undo_view.h"
#include "ui/base/animation/multi_animation.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
#if defined(TOOLKIT_VIEWS)
#include "chrome/browser/autocomplete/autocomplete_edit_view_views.h"
@@ -161,13 +162,6 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
instant_view_(NULL),
instant_mark_(NULL),
model_(new AutocompleteEditModel(this, controller, profile)),
-#if defined(TOOLKIT_VIEWS)
- popup_view_(new AutocompletePopupContentsView(
- gfx::Font(), this, model_.get(), profile, location_bar)),
-#else
- popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile,
- location_bar)),
-#endif
controller_(controller),
toolbar_model_(toolbar_model),
command_updater_(command_updater),
@@ -195,6 +189,14 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
preedit_size_before_change_(0),
#endif
going_to_focus_(NULL) {
+ popup_view_.reset(
+#if defined(TOOLKIT_VIEWS)
+ new AutocompletePopupContentsView
+#else
+ new AutocompletePopupViewGtk
+#endif
+ (GetFont(), this, model_.get(), profile, location_bar));
+
model_->SetPopupModel(popup_view_->GetModel());
}
@@ -426,12 +428,6 @@ int AutocompleteEditViewGtk::WidthOfTextAfterCursor() {
return -1;
}
-gfx::Font AutocompleteEditViewGtk::GetFont() {
- GtkRcStyle* rc_style = gtk_widget_get_modifier_style(text_view_);
- return gfx::Font((rc_style && rc_style->font_desc) ?
- rc_style->font_desc : text_view_->style->font_desc);
-}
-
AutocompleteEditModel* AutocompleteEditViewGtk::model() {
return model_.get();
}
@@ -975,15 +971,8 @@ void AutocompleteEditViewGtk::SetBaseColor() {
#endif
// Until we switch to vector graphics, force the font size.
- gtk_util::ForceFontSizePixels(text_view_,
- popup_window_mode_ ?
- browser_defaults::kAutocompleteEditFontPixelSizeInPopup :
- browser_defaults::kAutocompleteEditFontPixelSize);
-
- gtk_util::ForceFontSizePixels(instant_view_,
- popup_window_mode_ ?
- browser_defaults::kAutocompleteEditFontPixelSizeInPopup :
- browser_defaults::kAutocompleteEditFontPixelSize);
+ gtk_util::ForceFontSizePixels(text_view_, GetFont().GetFontSize());
+ gtk_util::ForceFontSizePixels(instant_view_, GetFont().GetFontSize());
g_object_set(faded_text_tag_, "foreground", kTextBaseColor, NULL);
g_object_set(normal_text_tag_, "foreground", "#000000", NULL);
@@ -1712,6 +1701,37 @@ void AutocompleteEditViewGtk::HandleCopyOrCutClipboard(bool copy) {
OwnPrimarySelection(UTF16ToUTF8(text));
}
+gfx::Font AutocompleteEditViewGtk::GetFont() {
+#if defined(TOOLKIT_VIEWS)
+ bool use_gtk = false;
+#else
+ bool use_gtk = theme_provider_->UseGtkTheme();
+#endif
+
+ if (use_gtk) {
+ // If we haven't initialized the text view yet, just create a temporary one
+ // whose style we can grab.
+ GtkWidget* widget = text_view_ ? text_view_ : gtk_text_view_new();
+ GtkRcStyle* rc_style = gtk_widget_get_modifier_style(widget);
+ gfx::Font font((rc_style && rc_style->font_desc) ?
+ rc_style->font_desc :
+ widget->style->font_desc);
+ if (!text_view_)
+ g_object_unref(g_object_ref_sink(widget));
+
+ // Scaling the font down for popup windows doesn't help here, since we just
+ // use the normal unforced font size when using the GTK theme.
+ return font;
+ } else {
+ return gfx::Font(
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont).
+ GetFontName(),
+ popup_window_mode_ ?
+ browser_defaults::kAutocompleteEditFontPixelSizeInPopup :
+ browser_defaults::kAutocompleteEditFontPixelSize);
+ }
+}
+
void AutocompleteEditViewGtk::OwnPrimarySelection(const std::string& text) {
primary_selection_text_ = text;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 27a3aaa..edbe907 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -89,9 +89,6 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
// LocationBarView::Layout as to why this uses -1.
int WidthOfTextAfterCursor();
- // Returns the font.
- gfx::Font GetFont();
-
// Implement the AutocompleteEditView interface.
virtual AutocompleteEditModel* model();
virtual const AutocompleteEditModel* model() const;
@@ -273,6 +270,9 @@ class AutocompleteEditViewGtk : public AutocompleteEditView,
void HandleCopyOrCutClipboard(bool copy);
+ // Returns the font used in |text_view_|.
+ gfx::Font GetFont();
+
// Take control of the PRIMARY selection clipboard with |text|. Use
// |text_buffer_| as the owner, so that this doesn't remove the selection on
// it. This makes use of the above callbacks.
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 0ffc036..aebe830 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -76,6 +76,10 @@ const float kContentWidthPercentage = 0.7;
// How much to offset the popup from the bottom of the location bar.
const int kVerticalOffset = 3;
+// The size delta between the font used for the edit and the result rows. Passed
+// to gfx::Font::DeriveFont.
+const int kEditFontAdjust = -1;
+
// UTF-8 Left-to-right embedding.
const char* kLRE = "\xe2\x80\xaa";
@@ -256,6 +260,7 @@ void AutocompletePopupViewGtk::SetupLayoutForMatch(
}
AutocompletePopupViewGtk::AutocompletePopupViewGtk(
+ const gfx::Font& font,
AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
@@ -266,6 +271,7 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
window_(gtk_window_new(GTK_WINDOW_POPUP)),
layout_(NULL),
theme_provider_(GtkThemeProvider::GetFrom(profile)),
+ font_(font.DeriveFont(kEditFontAdjust)),
ignore_mouse_drag_(false),
opened_(false) {
GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS);
@@ -284,15 +290,6 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
pango_layout_set_auto_dir(layout_, FALSE);
// We always ellipsize when drawing our text runs.
pango_layout_set_ellipsize(layout_, PANGO_ELLIPSIZE_END);
- // TODO(deanm): We might want to eventually follow what Windows does and
- // 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().GetFontName(),
- browser_defaults::kAutocompletePopupFontSize);
- PangoFontDescription* pfd = font.GetNativeFont();
- pango_layout_set_font_description(layout_, pfd);
- pango_font_description_free(pfd);
gtk_widget_add_events(window_, GDK_BUTTON_MOTION_MASK |
GDK_POINTER_MOTION_MASK |
@@ -395,6 +392,8 @@ void AutocompletePopupViewGtk::Observe(NotificationType type,
DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
if (theme_provider_->UseGtkTheme()) {
+ gtk_util::UndoForceFontSize(window_);
+
border_color_ = theme_provider_->GetBorderColor();
gtk_util::GetTextColors(
@@ -407,6 +406,8 @@ void AutocompletePopupViewGtk::Observe(NotificationType type,
url_selected_text_color_ = SelectedURLColor(selected_content_text_color_,
selected_background_color_);
} else {
+ gtk_util::ForceFontSizePixels(window_, font_.GetFontSize());
+
border_color_ = kBorderColor;
background_color_ = kBackgroundColor;
selected_background_color_ = kSelectedBackgroundColor;
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index 0d97341..341783c 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -16,6 +16,7 @@
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+#include "gfx/font.h"
#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditModel;
@@ -28,7 +29,8 @@ class SkBitmap;
class AutocompletePopupViewGtk : public AutocompletePopupView,
public NotificationObserver {
public:
- AutocompletePopupViewGtk(AutocompleteEditView* edit_view,
+ AutocompletePopupViewGtk(const gfx::Font& font,
+ AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
Profile* profile,
GtkWidget* location_bar);
@@ -117,6 +119,10 @@ class AutocompletePopupViewGtk : public AutocompletePopupView,
GtkThemeProvider* theme_provider_;
NotificationRegistrar registrar_;
+ // Font used for suggestions after being derived from the constructor's
+ // |font|.
+ gfx::Font font_;
+
// Used to cache GdkPixbufs and map them from the SkBitmaps they were created
// from.
typedef std::map<const SkBitmap*, GdkPixbuf*> PixbufMap;
diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc
index 2feeccd..2506a00e 100644
--- a/chrome/browser/chromeos/login/background_view.cc
+++ b/chrome/browser/chromeos/login/background_view.cc
@@ -253,9 +253,9 @@ void BackgroundView::Paint(gfx::Canvas* canvas) {
void BackgroundView::Layout() {
const int kCornerPadding = 5;
- const int kInfoLeftPadding = 15;
- const int kInfoBottomPadding = 15;
- const int kInfoBetweenLinesPadding = 4;
+ const int kInfoLeftPadding = 10;
+ const int kInfoBottomPadding = 10;
+ const int kInfoBetweenLinesPadding = 1;
const int kProgressBarBottomPadding = 20;
const int kProgressBarWidth = 750;
const int kProgressBarHeight = 70;
@@ -268,7 +268,7 @@ void BackgroundView::Layout() {
gfx::Size version_size = os_version_label_->GetPreferredSize();
int os_version_y = height() - version_size.height() - kInfoBottomPadding;
if (!is_official_build_)
- os_version_y -= version_size.height() - kInfoBetweenLinesPadding;
+ os_version_y -= (version_size.height() + kInfoBetweenLinesPadding);
os_version_label_->SetBounds(
kInfoLeftPadding,
os_version_y,
diff --git a/chrome/browser/chromeos/login/helper.h b/chrome/browser/chromeos/login/helper.h
index b613032..5a23224 100644
--- a/chrome/browser/chromeos/login/helper.h
+++ b/chrome/browser/chromeos/login/helper.h
@@ -153,15 +153,21 @@ class WideButton : public views::NativeButton {
} // namespace login
-// Font size correction in points for login/oobe controls.
+// Font size correction in pixels for login/oobe controls.
#if defined(CROS_FONTS_USING_BCI)
const int kFontSizeCorrectionDelta = 1;
-const int kUnselectedUsernameFontDelta = 0;
-const int kWelcomeTitleFontDelta = 5;
+const int kNetworkSelectionLabelFontDelta = 1;
+const int kSelectedUsernameFontDelta = 1;
+const int kUnselectedUsernameFontDelta = 1;
+const int kWelcomeTitleFontDelta = 8;
+const int kLoginTitleFontDelta = 3;
#else
const int kFontSizeCorrectionDelta = 2;
-const int kUnselectedUsernameFontDelta = 1;
-const int kWelcomeTitleFontDelta = 5;
+const int kNetworkSelectionLabelFontDelta = 1;
+const int kSelectedUsernameFontDelta = 1;
+const int kUnselectedUsernameFontDelta = 2;
+const int kWelcomeTitleFontDelta = 9;
+const int kLoginTitleFontDelta = 4;
#endif
// New pod sizes.
diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc
index 71a3a67..b1247b9 100644
--- a/chrome/browser/chromeos/login/network_selection_view.cc
+++ b/chrome/browser/chromeos/login/network_selection_view.cc
@@ -292,15 +292,18 @@ void NetworkSelectionView::Init() {
welcome_label_->SetFont(welcome_label_font);
welcome_label_->SetMultiLine(true);
+ gfx::Font select_label_font = rb.GetFont(ResourceBundle::MediumFont).
+ DeriveFont(kNetworkSelectionLabelFontDelta);
+
select_language_label_ = new views::Label();
- select_language_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ select_language_label_->SetFont(select_label_font);
languages_menubutton_ = new NotifyingMenuButton(
NULL, std::wstring(), delegate_->language_switch_menu(), true, delegate_);
InitMenuButtonProperties(languages_menubutton_);
select_keyboard_label_ = new views::Label();
- select_keyboard_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ select_keyboard_label_->SetFont(select_label_font);
keyboards_menubutton_ = new DropDownButton(
NULL /* listener */, L"", delegate_->keyboard_switch_menu(),
@@ -308,7 +311,7 @@ void NetworkSelectionView::Init() {
InitMenuButtonProperties(keyboards_menubutton_);
select_network_label_ = new views::Label();
- select_network_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
+ select_network_label_->SetFont(select_label_font);
network_dropdown_ = new NetworkControlReportOnActivate(false,
GetNativeWindow(),
diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc
index eb6927a..1ebeaf9 100644
--- a/chrome/browser/chromeos/login/new_user_view.cc
+++ b/chrome/browser/chromeos/login/new_user_view.cc
@@ -144,7 +144,7 @@ void NewUserView::Init() {
// Set up fonts.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
gfx::Font title_font = rb.GetFont(ResourceBundle::MediumBoldFont).DeriveFont(
- kFontSizeCorrectionDelta);
+ kLoginTitleFontDelta);
gfx::Font title_hint_font = rb.GetFont(ResourceBundle::BoldFont);
title_label_ = new views::Label();
diff --git a/chrome/browser/chromeos/login/screen_lock_view.cc b/chrome/browser/chromeos/login/screen_lock_view.cc
index d6052fc..75a715c2 100644
--- a/chrome/browser/chromeos/login/screen_lock_view.cc
+++ b/chrome/browser/chromeos/login/screen_lock_view.cc
@@ -117,7 +117,8 @@ void ScreenLockView::Init() {
std::wstring text = UTF8ToWide(user.GetDisplayName());
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- const gfx::Font& font = rb.GetFont(ResourceBundle::MediumBoldFont);
+ const gfx::Font& font = rb.GetFont(ResourceBundle::MediumBoldFont).DeriveFont(
+ kSelectedUsernameFontDelta);
// Layouts image, textfield and button components.
GridLayout* layout = new GridLayout(main_);
diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc
index 4339aac..6c1f2b3 100644
--- a/chrome/browser/chromeos/login/user_controller.cc
+++ b/chrome/browser/chromeos/login/user_controller.cc
@@ -410,7 +410,8 @@ WidgetGtk* UserController::CreateLabelWindow(int index,
WmIpcWindowType type) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& font = (type == WM_IPC_WINDOW_LOGIN_LABEL) ?
- rb.GetFont(ResourceBundle::MediumBoldFont) :
+ rb.GetFont(ResourceBundle::MediumBoldFont).DeriveFont(
+ kSelectedUsernameFontDelta) :
rb.GetFont(ResourceBundle::BaseFont).DeriveFont(
kUnselectedUsernameFontDelta, gfx::Font::BOLD);
std::wstring text;
diff --git a/chrome/browser/defaults.cc b/chrome/browser/defaults.cc
index a0764d9..50ed612 100644
--- a/chrome/browser/defaults.cc
+++ b/chrome/browser/defaults.cc
@@ -10,12 +10,9 @@ namespace browser_defaults {
// Make the regular omnibox text two points larger than the nine-point font
// used in the tab strip (11pt / 72pt/in * 96px/in = 14.667px).
-const double kAutocompleteEditFontPixelSize = 14.7;
-const double kAutocompleteEditFontPixelSizeInPopup = 10.0;
+const int kAutocompleteEditFontPixelSize = 15;
-// This is only used by AutocompletePopupViewGtk which is unused
-// unless TOOLKIT_VIEWS is undefined:
-const int kAutocompletePopupFontSize = 7;
+const int kAutocompleteEditFontPixelSizeInPopup = 10;
const SessionStartupPref::Type kDefaultSessionStartupType =
SessionStartupPref::LAST;
@@ -36,15 +33,13 @@ const bool kShowCancelButtonInTaskManager = true;
#elif defined(TOOLKIT_USES_GTK)
// 13.4px = 10pt @ 96dpi.
-const double kAutocompleteEditFontPixelSize = 13.4;
+const int kAutocompleteEditFontPixelSize = 13;
-// On Windows, popup windows' autocomplete box have a font 5/6 the size of a
-// regular window, which we duplicate here for GTK.
-const double kAutocompleteEditFontPixelSizeInPopup =
+// On Windows, popup windows' location text uses a font 5/6 the size of
+// that in a regular window, which we duplicate here for GTK.
+const int kAutocompleteEditFontPixelSizeInPopup =
kAutocompleteEditFontPixelSize * 5.0 / 6.0;
-const int kAutocompletePopupFontSize = 10;
-
#if defined(TOOLKIT_VIEWS)
const bool kCanToggleSystemTitleBar = false;
#else
diff --git a/chrome/browser/defaults.h b/chrome/browser/defaults.h
index eb64e5b..147c29e 100644
--- a/chrome/browser/defaults.h
+++ b/chrome/browser/defaults.h
@@ -15,14 +15,11 @@ namespace browser_defaults {
#if defined(USE_X11)
-// Size of the font in pixels used in the autocomplete box for normal windows.
-extern const double kAutocompleteEditFontPixelSize;
+// Size of the font used in the autocomplete box for normal windows, in pixels.
+extern const int kAutocompleteEditFontPixelSize;
-// Size of the font in pixels used in the autocomplete box for popup windows.
-extern const double kAutocompleteEditFontPixelSizeInPopup;
-
-// Size of the font used in the autocomplete popup.
-extern const int kAutocompletePopupFontSize;
+// Size of the font used in the autocomplete box for popup windows, in pixels.
+extern const int kAutocompleteEditFontPixelSizeInPopup;
// Can the user toggle the system title bar?
extern const bool kCanToggleSystemTitleBar;
diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
index 1336972..41ca2b6 100644
--- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc
@@ -31,6 +31,7 @@
namespace {
+const int kFontPixelSize = 13;
const int kLeftPadding = 16;
const int kTopPadding = 6;
const int kRightPadding = 15;
@@ -1074,10 +1075,7 @@ void TabRendererGtk::InitResources() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
- // Dividing by the pango scale factor maintains an absolute pixel size across
- // all DPIs.
- int size = static_cast<int>(13 / gfx::PlatformFontGtk::GetPangoScaleFactor());
- title_font_ = new gfx::Font(base_font.GetFontName(), size);
+ title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize);
title_font_height_ = title_font_->GetHeight();
crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON);
diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
index 8656360..66b7b45 100644
--- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -122,8 +122,8 @@ const int kIconVerticalPadding = 2;
const int kTextVerticalPadding = 3;
// The size delta between the font used for the edit and the result rows. Passed
// to gfx::Font::DeriveFont.
-#if defined(OS_CHROMEOS) && !defined(CROS_FONTS_USING_BCI)
-// Don't adjust font on chromeos as it becomes too small.
+#if defined(OS_CHROMEOS)
+// Don't adjust the size on Chrome OS (http://crbug.com/61433).
const int kEditFontAdjust = 0;
#else
const int kEditFontAdjust = -1;
diff --git a/gfx/font.cc b/gfx/font.cc
index 8b8241d..78b1a34 100644
--- a/gfx/font.cc
+++ b/gfx/font.cc
@@ -83,4 +83,3 @@ NativeFont Font::GetNativeFont() const {
}
} // namespace gfx
-
diff --git a/gfx/font.h b/gfx/font.h
index eb6e4d5..22f1ade 100644
--- a/gfx/font.h
+++ b/gfx/font.h
@@ -111,4 +111,3 @@ class Font {
} // namespace gfx
#endif // GFX_FONT_H_
-
diff --git a/gfx/gtk_util.cc b/gfx/gtk_util.cc
index 96195fe..fc240e0 100644
--- a/gfx/gtk_util.cc
+++ b/gfx/gtk_util.cc
@@ -171,10 +171,6 @@ double GetPangoResolution() {
determined_resolution = true;
PangoContext* default_context = gdk_pango_context_get();
resolution = pango_cairo_context_get_resolution(default_context);
-#if !defined(OS_CHROMEOS)
- // Until we switch to vector graphics, force the max DPI to 96.0.
- resolution = std::min(resolution, 96.);
-#endif
g_object_unref(default_context);
}
return resolution;
diff --git a/gfx/platform_font_gtk.cc b/gfx/platform_font_gtk.cc
index 61a0933..82b2e06 100644
--- a/gfx/platform_font_gtk.cc
+++ b/gfx/platform_font_gtk.cc
@@ -27,6 +27,27 @@ namespace {
// IsFallbackFontAllowed function in skia/ext/SkFontHost_fontconfig_direct.cpp.
const char* kFallbackFontFamilyName = "sans";
+// Returns the number of pixels in a point.
+// - multiply a point size by this to get pixels ("device units")
+// - divide a pixel size by this to get points
+float GetPixelsInPoint() {
+ static float pixels_in_point = 1.0;
+ static bool determined_value = false;
+
+ if (!determined_value) {
+ // http://goo.gl/UIh5m: "This is a scale factor between points specified in
+ // a PangoFontDescription and Cairo units. The default value is 96, meaning
+ // that a 10 point font will be 13 units high. (10 * 96. / 72. = 13.3)."
+ double pango_dpi = gfx::GetPangoResolution();
+ if (pango_dpi <= 0)
+ pango_dpi = 96.0;
+ pixels_in_point = pango_dpi / 72.0; // 72 points in an inch
+ determined_value = true;
+ }
+
+ return pixels_in_point;
+}
+
// 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.
@@ -127,14 +148,18 @@ PlatformFontGtk::PlatformFontGtk(const Font& other) {
}
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);
+ gint size_in_pixels = 0;
if (pango_font_description_get_size_is_absolute(native_font)) {
- // font_size_ is treated as scaled (see comment in GetPangoScaleFactor). If
- // we get here the font size is absolute though, and we need to invert the
- // scale so that when scaled in the rest of this class everything lines up.
- size /= GetPangoScaleFactor();
+ // If the size is absolute, then it's in Pango units rather than points.
+ // There are PANGO_SCALE Pango units in a device unit (pixel).
+ size_in_pixels = pango_font_description_get_size(native_font) / PANGO_SCALE;
+ } else {
+ // Otherwise, we need to convert from points.
+ size_in_pixels =
+ pango_font_description_get_size(native_font) * GetPixelsInPoint() /
+ PANGO_SCALE;
}
// Find best match font for |family_name| to make sure we can get
@@ -142,7 +167,7 @@ PlatformFontGtk::PlatformFontGtk(NativeFont native_font) {
// TODO(agl): remove this.
string16 font_family = FindBestMatchFontFamilyName(family_name);
- InitWithNameAndSize(font_family, size / PANGO_SCALE);
+ InitWithNameAndSize(font_family, size_in_pixels);
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
@@ -164,12 +189,12 @@ PlatformFontGtk::PlatformFontGtk(const string16& font_name,
double PlatformFontGtk::underline_position() const {
const_cast<PlatformFontGtk*>(this)->InitPangoMetrics();
- return underline_position_;
+ return underline_position_pixels_;
}
double PlatformFontGtk::underline_thickness() const {
const_cast<PlatformFontGtk*>(this)->InitPangoMetrics();
- return underline_thickness_;
+ return underline_thickness_pixels_;
}
////////////////////////////////////////////////////////////////////////////////
@@ -178,13 +203,13 @@ double PlatformFontGtk::underline_thickness() const {
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_);
+ DCHECK_LT(-size_delta, font_size_pixels_);
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,
+ font_size_pixels_ + size_delta,
style_));
}
@@ -202,20 +227,20 @@ Font PlatformFontGtk::DeriveFont(int size_delta, int style) const {
return Font(new PlatformFontGtk(typeface,
font_family_,
- font_size_ + size_delta,
+ font_size_pixels_ + size_delta,
style));
}
int PlatformFontGtk::GetHeight() const {
- return height_;
+ return height_pixels_;
}
int PlatformFontGtk::GetBaseline() const {
- return ascent_;
+ return ascent_pixels_;
}
int PlatformFontGtk::GetAverageCharacterWidth() const {
- return SkScalarRound(average_width_);
+ return SkScalarRound(average_width_pixels_);
}
int PlatformFontGtk::GetStringWidth(const string16& text) const {
@@ -239,15 +264,18 @@ string16 PlatformFontGtk::GetFontName() const {
}
int PlatformFontGtk::GetFontSize() const {
- return font_size_;
+ return font_size_pixels_;
}
NativeFont PlatformFontGtk::GetNativeFont() const {
PangoFontDescription* pfd = pango_font_description_new();
pango_font_description_set_family(pfd, UTF16ToUTF8(GetFontName()).c_str());
// Set the absolute size to avoid overflowing UI elements.
- pango_font_description_set_absolute_size(pfd,
- GetFontSize() * PANGO_SCALE * GetPangoScaleFactor());
+ // pango_font_description_set_absolute_size() takes a size in Pango units.
+ // There are PANGO_SCALE Pango units in one device unit. Screen output
+ // devices use pixels as their device units.
+ pango_font_description_set_absolute_size(
+ pfd, font_size_pixels_ * PANGO_SCALE);
switch (GetStyle()) {
case gfx::Font::NORMAL:
@@ -314,20 +342,20 @@ void PlatformFontGtk::InitWithTypefaceNameSizeAndStyle(
typeface_ = typeface;
typeface_->ref();
font_family_ = font_family;
- font_size_ = font_size;
+ font_size_pixels_ = font_size;
style_ = style;
pango_metrics_inited_ = false;
- average_width_ = 0.0f;
- underline_position_ = 0.0f;
- underline_thickness_ = 0.0f;
+ average_width_pixels_ = 0.0f;
+ underline_position_pixels_ = 0.0f;
+ underline_thickness_pixels_ = 0.0f;
SkPaint paint;
SkPaint::FontMetrics metrics;
PaintSetup(&paint);
paint.getFontMetrics(&metrics);
- ascent_ = SkScalarCeil(-metrics.fAscent);
- height_ = ascent_ + SkScalarCeil(metrics.fDescent);
+ ascent_pixels_ = SkScalarCeil(-metrics.fAscent);
+ height_pixels_ = ascent_pixels_ + SkScalarCeil(metrics.fDescent);
}
void PlatformFontGtk::InitFromPlatformFont(const PlatformFontGtk* other) {
@@ -335,21 +363,20 @@ void PlatformFontGtk::InitFromPlatformFont(const PlatformFontGtk* other) {
typeface_ = other->typeface_;
typeface_->ref();
font_family_ = other->font_family_;
- font_size_ = other->font_size_;
+ font_size_pixels_ = other->font_size_pixels_;
style_ = other->style_;
- height_ = other->height_;
- ascent_ = other->ascent_;
+ height_pixels_ = other->height_pixels_;
+ ascent_pixels_ = other->ascent_pixels_;
pango_metrics_inited_ = other->pango_metrics_inited_;
- average_width_ = other->average_width_;
- underline_position_ = other->underline_position_;
- underline_thickness_ = other->underline_thickness_;
+ average_width_pixels_ = other->average_width_pixels_;
+ underline_position_pixels_ = other->underline_position_pixels_;
+ underline_thickness_pixels_ = other->underline_thickness_pixels_;
}
void PlatformFontGtk::PaintSetup(SkPaint* paint) const {
paint->setAntiAlias(false);
paint->setSubpixelText(false);
- paint->setTextSize(
- SkFloatToScalar(font_size_ * GetPangoScaleFactor()));
+ paint->setTextSize(font_size_pixels_);
paint->setTypeface(typeface_);
paint->setFakeBoldText((gfx::Font::BOLD & style_) && !typeface_->isBold());
paint->setTextSkewX((gfx::Font::ITALIC & style_) && !typeface_->isItalic() ?
@@ -362,57 +389,38 @@ void PlatformFontGtk::InitPangoMetrics() {
PangoFontDescription* pango_desc = GetNativeFont();
PangoFontMetrics* pango_metrics = GetPangoFontMetrics(pango_desc);
- underline_position_ =
- pango_font_metrics_get_underline_position(pango_metrics);
- underline_position_ /= PANGO_SCALE;
+ underline_position_pixels_ =
+ pango_font_metrics_get_underline_position(pango_metrics) /
+ PANGO_SCALE;
- // todo(davemoore) Come up with a better solution.
+ // 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_position_pixels_ /= 2;
- underline_thickness_ =
- pango_font_metrics_get_underline_thickness(pango_metrics);
- underline_thickness_ /= PANGO_SCALE;
+ underline_thickness_pixels_ =
+ pango_font_metrics_get_underline_thickness(pango_metrics) /
+ PANGO_SCALE;
- // First get the pango based width
- double pango_width =
- pango_font_metrics_get_approximate_char_width(pango_metrics);
- pango_width /= PANGO_SCALE;
+ // First get the Pango-based width (converting from Pango units to pixels).
+ double pango_width_pixels =
+ pango_font_metrics_get_approximate_char_width(pango_metrics) /
+ PANGO_SCALE;
// Yes, this is how Microsoft recommends calculating the dialog unit
// conversions.
- int text_width = GetStringWidth(
+ int text_width_pixels = GetStringWidth(
ASCIIToUTF16("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
- double dialog_units = (text_width / 26 + 1) / 2;
- average_width_ = std::min(pango_width, dialog_units);
+ double dialog_units_pixels = (text_width_pixels / 26 + 1) / 2;
+ average_width_pixels_ = std::min(pango_width_pixels, dialog_units_pixels);
pango_font_description_free(pango_desc);
}
}
-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_;
+ return average_width_pixels_;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/gfx/platform_font_gtk.h b/gfx/platform_font_gtk.h
index fedbfc1..e69c24a 100644
--- a/gfx/platform_font_gtk.h
+++ b/gfx/platform_font_gtk.h
@@ -27,9 +27,6 @@ class PlatformFontGtk : public PlatformFont {
// pango_font_description_free().
static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
- // Return the scale factor for fonts that account for DPI.
- static float GetPangoScaleFactor();
-
// 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;
@@ -87,19 +84,19 @@ class PlatformFontGtk : public PlatformFont {
// Additional information about the face
// Skia actually expects a family name and not a font name.
string16 font_family_;
- int font_size_;
+ int font_size_pixels_;
int style_;
// Cached metrics, generated at construction
- int height_;
- int ascent_;
+ int height_pixels_;
+ int ascent_pixels_;
// 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_;
+ double average_width_pixels_;
+ double underline_position_pixels_;
+ double underline_thickness_pixels_;
// The default font, used for the default constructor.
static Font* default_font_;
@@ -108,4 +105,3 @@ class PlatformFontGtk : public PlatformFont {
} // namespace gfx
#endif // GFX_PLATFORM_FONT_GTK_
-