Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1018)

Unified Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 929733002: Fix Pango font rendering with HiDPi displays on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Pango font rendering with HiDPi displays on Linux. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | ui/gfx/font_render_params_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/libgtk2ui/gtk2_ui.cc
diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
index 5405a718ef1f540515ff20cf0e15580cd44a3d20..fc226578da52d24b509fd11622c3ca36dd10885c 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -381,7 +381,7 @@ gfx::FontRenderParams GetGtkFontRenderParams() {
// Queries GTK for its font DPI setting and returns the number of pixels in a
// point.
-double GetPixelsInPoint() {
+double GetPixelsInPoint(float device_scale_factor) {
GtkSettings* gtk_settings = gtk_settings_get_default();
CHECK(gtk_settings);
gint gtk_dpi = -1;
@@ -390,6 +390,10 @@ double GetPixelsInPoint() {
// GTK multiplies the DPI by 1024 before storing it.
double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0;
+ // Take device_scale_factor into account — if Chrome already scales the
+ // entire UI up by 2x, we should not also scale up.
+ dpi /= device_scale_factor;
+
// There are 72 points in an inch.
return dpi / 72.0;
}
@@ -413,7 +417,8 @@ views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() {
Gtk2UI::Gtk2UI()
: default_font_size_pixels_(0),
default_font_style_(gfx::Font::NORMAL),
- middle_click_action_(GetDefaultMiddleClickAction()) {
+ middle_click_action_(GetDefaultMiddleClickAction()),
+ device_scale_factor_(1.0) {
GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess());
}
@@ -1384,7 +1389,7 @@ void Gtk2UI::UpdateDefaultFont(const PangoFontDescription* desc) {
const double size_points = pango_font_description_get_size(desc) /
static_cast<double>(PANGO_SCALE);
default_font_size_pixels_ = static_cast<int>(
- GetPixelsInPoint() * size_points + 0.5);
+ GetPixelsInPoint(device_scale_factor_) * size_points + 0.5);
query.point_size = static_cast<int>(size_points);
}
@@ -1407,6 +1412,12 @@ void Gtk2UI::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) {
NativeThemeGtk2::instance()->NotifyObservers();
}
+void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) {
+ device_scale_factor_ = device_scale_factor;
+ GtkStyle* label_style = gtk_rc_get_style(fake_label_.get());
+ UpdateDefaultFont(label_style->font_desc);
+}
+
} // namespace libgtk2ui
views::LinuxUI* BuildGtk2UI() {
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_ui.h ('k') | ui/gfx/font_render_params_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698