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

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

Issue 400193004: Unify desktop Linux and Chrome OS font rendering params. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update some comments Created 6 years, 5 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
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 035c9aaeaa08c2efea0c6abc6fc6430dcb7161cd..1bcc04d6d80d4fee20605641e1ebdb7ca49116a6 100644
--- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
+++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc
@@ -6,6 +6,8 @@
#include <set>
+#include <pango/pango.h>
+
#include "base/command_line.h"
#include "base/debug/leak_annotations.h"
#include "base/environment.h"
@@ -40,6 +42,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
+#include "ui/gfx/pango_util.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
@@ -315,6 +318,60 @@ color_utils::HSL GetDefaultTint(int id) {
}
}
+// Returns a FontRenderParams corresponding to GTK's configuration.
+gfx::FontRenderParams GetGtkFontRenderParams() {
+ GtkSettings* gtk_settings = gtk_settings_get_default();
+ CHECK(gtk_settings);
+ gint antialias = 0;
+ gint hinting = 0;
+ gchar* hint_style = NULL;
+ gchar* rgba = NULL;
+ g_object_get(gtk_settings,
+ "gtk-xft-antialias", &antialias,
+ "gtk-xft-hinting", &hinting,
+ "gtk-xft-hintstyle", &hint_style,
+ "gtk-xft-rgba", &rgba,
+ NULL);
+
+ gfx::FontRenderParams params;
+ params.antialiasing = antialias != 0;
+
+ if (hinting == 0 || !hint_style || strcmp(hint_style, "hintnone") == 0) {
+ params.hinting = gfx::FontRenderParams::HINTING_NONE;
+ } else if (strcmp(hint_style, "hintslight") == 0) {
+ params.hinting = gfx::FontRenderParams::HINTING_SLIGHT;
+ } else if (strcmp(hint_style, "hintmedium") == 0) {
+ params.hinting = gfx::FontRenderParams::HINTING_MEDIUM;
+ } else if (strcmp(hint_style, "hintfull") == 0) {
+ params.hinting = gfx::FontRenderParams::HINTING_FULL;
+ } else {
+ LOG(WARNING) << "Unexpected gtk-xft-hintstyle \"" << hint_style << "\"";
+ params.hinting = gfx::FontRenderParams::HINTING_NONE;
+ }
+
+ if (!rgba || strcmp(rgba, "none") == 0) {
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
+ } else if (strcmp(rgba, "rgb") == 0) {
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB;
+ } else if (strcmp(rgba, "bgr") == 0) {
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR;
+ } else if (strcmp(rgba, "vrgb") == 0) {
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB;
+ } else if (strcmp(rgba, "vbgr") == 0) {
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR;
+ } else {
+ LOG(WARNING) << "Unexpected gtk-xft-rgba \"" << rgba << "\"";
+ params.subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
+ }
+
+ if (hint_style)
+ g_free(hint_style);
msw 2014/07/18 19:14:43 nit: Remove the NULL checks for these two g_free c
msw 2014/07/18 19:59:46 ping, but you can leave them if you prefer.
Daniel Erat 2014/07/18 20:26:51 whoops, sorry. saw this comment, did other things,
+ if (rgba)
+ g_free(rgba);
+
+ return params;
+}
+
} // namespace
Gtk2UI::Gtk2UI() : middle_click_action_(MIDDLE_CLICK_ACTION_LOWER) {
@@ -588,75 +645,16 @@ scoped_ptr<ui::LinuxInputMethodContext> Gtk2UI::CreateInputMethodContext(
new X11InputMethodContextImplGtk2(delegate));
}
-bool Gtk2UI::UseAntialiasing() const {
- GtkSettings* gtk_settings = gtk_settings_get_default();
- CHECK(gtk_settings);
- gint gtk_antialias = 0;
- g_object_get(gtk_settings,
- "gtk-xft-antialias", &gtk_antialias,
- NULL);
- return gtk_antialias != 0;
-}
-
-gfx::FontRenderParams::Hinting Gtk2UI::GetHintingStyle() const {
- GtkSettings* gtk_settings = gtk_settings_get_default();
- CHECK(gtk_settings);
- gfx::FontRenderParams::Hinting hinting =
- gfx::FontRenderParams::HINTING_SLIGHT;
- gint gtk_hinting = 0;
- gchar* gtk_hint_style = NULL;
- g_object_get(gtk_settings,
- "gtk-xft-hinting", &gtk_hinting,
- "gtk-xft-hintstyle", &gtk_hint_style,
- NULL);
-
- if (gtk_hint_style) {
- if (gtk_hinting == 0 || strcmp(gtk_hint_style, "hintnone") == 0)
- hinting = gfx::FontRenderParams::HINTING_NONE;
- else if (strcmp(gtk_hint_style, "hintslight") == 0)
- hinting = gfx::FontRenderParams::HINTING_SLIGHT;
- else if (strcmp(gtk_hint_style, "hintmedium") == 0)
- hinting = gfx::FontRenderParams::HINTING_MEDIUM;
- else if (strcmp(gtk_hint_style, "hintfull") == 0)
- hinting = gfx::FontRenderParams::HINTING_FULL;
-
- g_free(gtk_hint_style);
- }
-
- return hinting;
+gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const {
+ static gfx::FontRenderParams params = GetGtkFontRenderParams();
+ return params;
}
-gfx::FontRenderParams::SubpixelRendering
-Gtk2UI::GetSubpixelRenderingStyle() const {
- GtkSettings* gtk_settings = gtk_settings_get_default();
- CHECK(gtk_settings);
- gfx::FontRenderParams::SubpixelRendering subpixel_rendering =
- gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
- gchar* gtk_rgba = NULL;
- g_object_get(gtk_settings,
- "gtk-xft-rgba", &gtk_rgba,
- NULL);
-
- if (gtk_rgba) {
- if (strcmp(gtk_rgba, "none") == 0)
- subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_NONE;
- else if (strcmp(gtk_rgba, "rgb") == 0)
- subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_RGB;
- else if (strcmp(gtk_rgba, "bgr") == 0)
- subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_BGR;
- else if (strcmp(gtk_rgba, "vrgb") == 0)
- subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VRGB;
- else if (strcmp(gtk_rgba, "vbgr") == 0)
- subpixel_rendering = gfx::FontRenderParams::SUBPIXEL_RENDERING_VBGR;
-
- g_free(gtk_rgba);
- }
-
- return subpixel_rendering;
-}
-
-std::string Gtk2UI::GetDefaultFontDescription() const {
- return default_font_description_;
+scoped_ptr<gfx::ScopedPangoFontDescription>
+Gtk2UI::GetDefaultPangoFontDescription() const {
+ return scoped_ptr<gfx::ScopedPangoFontDescription>(
+ new gfx::ScopedPangoFontDescription(
+ pango_font_description_copy(default_font_description_->get())));
}
ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog(
@@ -823,27 +821,8 @@ void Gtk2UI::LoadGtkValues() {
SetThemeColorFromGtk(ThemeProperties::COLOR_BOOKMARK_TEXT, &label_color);
SetThemeColorFromGtk(ThemeProperties::COLOR_STATUS_BAR_TEXT, &label_color);
- gchar* font_string = pango_font_description_to_string(label_style->font_desc);
- default_font_description_ = std::string(font_string);
- g_free(font_string);
-
- {
- // TODO(derat): Remove this debugging code if/when http://crbug.com/375824
msw 2014/07/18 19:14:43 Did this yield any useful info? Is it worth keepin
Daniel Erat 2014/07/18 19:39:08 no, i don't think so. i originally theorized that
msw 2014/07/18 19:59:46 Acknowledged.
- // is resolved.
- GtkSettings* gtk_settings = gtk_settings_get_default();
- CHECK(gtk_settings);
- gchar* font_name = NULL;
- g_object_get(gtk_settings, "gtk-font-name", &font_name, NULL);
- if (font_name) {
- if (std::string(font_name) != default_font_description_) {
- LOG(ERROR) << "Font specified in gtk-font-name property ("
- << font_name << ") does not match font from GtkLabel ("
- << default_font_description_ << "); see "
- << "http://crbug.com/375824";
- }
- g_free(font_name);
- }
- }
+ default_font_description_.reset(new gfx::ScopedPangoFontDescription(
+ pango_font_description_copy(label_style->font_desc)));
// Build the various icon tints.
GetNormalButtonTintHSL(&button_tint_);

Powered by Google App Engine
This is Rietveld 408576698