diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-20 17:11:21 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-20 17:11:21 +0100 |
| commit | 9e52a1d525c7a762d621a13a865a692488a71a76 (patch) | |
| tree | 5a6dcbdabca0a5958ad4c1f829b09a80c572b1c1 /unity-shared | |
| parent | ac948decee50405fea113fa3461f011326a9a7af (diff) | |
UnityShell: add FontSettings back
(bzr r3725.7.11)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/FontSettings.cpp | 92 | ||||
| -rw-r--r-- | unity-shared/FontSettings.h | 43 |
3 files changed, 136 insertions, 0 deletions
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index b29a584cd..b56c77990 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -29,6 +29,7 @@ set (UNITY_SHARED_SOURCES DesktopApplicationManager.cpp EMConverter.cpp GnomeFileManager.cpp + FontSettings.cpp GraphicsUtils.cpp IMTextEntry.cpp IconLoader.cpp diff --git a/unity-shared/FontSettings.cpp b/unity-shared/FontSettings.cpp new file mode 100644 index 000000000..4da0e9679 --- /dev/null +++ b/unity-shared/FontSettings.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> + */ + +#include "FontSettings.h" + +#include <cairo/cairo.h> + +#include <UnityCore/GLibWrapper.h> +#include <sigc++/sigc++.h> + +namespace unity +{ + +FontSettings::FontSettings() +{ + GtkSettings* settings = gtk_settings_get_default(); + + sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-hintstyle", sigc::mem_fun(this, &FontSettings::Refresh)); + sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-rgba", sigc::mem_fun(this, &FontSettings::Refresh)); + sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-antialias", sigc::mem_fun(this, &FontSettings::Refresh)); + + Refresh(); +} + +void FontSettings::Refresh(GtkSettings* unused0, GParamSpec* unused1) +{ + GtkSettings* settings = gtk_settings_get_default(); + cairo_font_options_t* font_options = cairo_font_options_create(); + + { + cairo_subpixel_order_t order = CAIRO_SUBPIXEL_ORDER_DEFAULT; + glib::String value; + g_object_get(settings, "gtk-xft-rgba", &value, NULL); + gint antialias; + g_object_get(settings, "gtk-xft-antialias", &antialias, NULL); + + if (value.Str() == "rgb") + order = CAIRO_SUBPIXEL_ORDER_RGB; + else if (value.Str() == "bgr") + order = CAIRO_SUBPIXEL_ORDER_BGR; + else if (value.Str() == "vrgb") + order = CAIRO_SUBPIXEL_ORDER_VRGB; + else if (value.Str() == "vbgr") + order = CAIRO_SUBPIXEL_ORDER_VBGR; + + cairo_font_options_set_subpixel_order(font_options, order); + cairo_font_options_set_antialias(font_options, + value.Str() == "none" ? (antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE) + : CAIRO_ANTIALIAS_SUBPIXEL); + + } + + { + cairo_hint_style_t style = CAIRO_HINT_STYLE_DEFAULT; + glib::String value; + g_object_get(settings, "gtk-xft-hintstyle", &value, NULL); + + if (value.Str() == "hintnone") + style = CAIRO_HINT_STYLE_NONE; + else if (value.Str() == "hintslight") + style = CAIRO_HINT_STYLE_SLIGHT; + else if (value.Str() == "hintmedium") + style = CAIRO_HINT_STYLE_MEDIUM; + else if (value.Str() == "hintfull") + style = CAIRO_HINT_STYLE_FULL; + + cairo_font_options_set_hint_style(font_options, style); + } + + // FIXME: Where do we read this value from? + cairo_font_options_set_hint_metrics(font_options, CAIRO_HINT_METRICS_ON); + + gdk_screen_set_font_options(gdk_screen_get_default(), font_options); + cairo_font_options_destroy(font_options); +} + +} diff --git a/unity-shared/FontSettings.h b/unity-shared/FontSettings.h new file mode 100644 index 000000000..362d3e7f8 --- /dev/null +++ b/unity-shared/FontSettings.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> + */ + +#ifndef UNITY_FONT_SETTINGS_H_ +#define UNITY_FONT_SETTINGS_H_ + +#include <gtk/gtk.h> + +#include <UnityCore/GLibSignal.h> + +namespace unity +{ + +class FontSettings +{ +public: + FontSettings(); + +private: + void Refresh(GtkSettings* unused0=nullptr, GParamSpec* unused1=nullptr); + +private: + glib::SignalManager sig_man_; +}; + +} + +#endif |
