Back to index

unity  6.0.0
FontSettings.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00017  */
00018 
00019 #include "FontSettings.h"
00020 
00021 #include <cairo/cairo.h>
00022 
00023 #include <UnityCore/GLibWrapper.h>
00024 
00025 namespace unity
00026 {
00027 
00028 FontSettings::FontSettings()
00029 {
00030   GtkSettings* settings = gtk_settings_get_default();
00031 
00032   sig_man_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-hintstyle", sigc::mem_fun(this, &FontSettings::Refresh)));
00033   sig_man_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-rgba", sigc::mem_fun(this, &FontSettings::Refresh)));
00034   sig_man_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-antialias", sigc::mem_fun(this, &FontSettings::Refresh)));
00035 
00036   Refresh();
00037 }
00038 
00039 void FontSettings::Refresh(GtkSettings* unused0, GParamSpec* unused1)
00040 {
00041   GtkSettings* settings = gtk_settings_get_default();
00042   cairo_font_options_t* font_options = cairo_font_options_create();
00043 
00044   {
00045     cairo_subpixel_order_t order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
00046     glib::String value;
00047     g_object_get(settings, "gtk-xft-rgba", &value, NULL);
00048     gint antialias;
00049     g_object_get(settings, "gtk-xft-antialias", &antialias, NULL);
00050     
00051     if (value.Str() == "rgb")
00052       order = CAIRO_SUBPIXEL_ORDER_RGB;
00053     else if (value.Str() == "bgr")
00054       order = CAIRO_SUBPIXEL_ORDER_BGR;
00055     else if (value.Str() == "vrgb")
00056       order = CAIRO_SUBPIXEL_ORDER_VRGB;
00057     else if (value.Str() == "vbgr")
00058       order = CAIRO_SUBPIXEL_ORDER_VBGR;
00059 
00060     cairo_font_options_set_subpixel_order(font_options, order);
00061     cairo_font_options_set_antialias(font_options,
00062                                      value.Str() == "none" ? (antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE) 
00063                                                            : CAIRO_ANTIALIAS_SUBPIXEL);
00064 
00065   }
00066 
00067   {
00068     cairo_hint_style_t style = CAIRO_HINT_STYLE_DEFAULT;
00069     glib::String value;
00070     g_object_get(settings, "gtk-xft-hintstyle", &value, NULL);
00071     
00072     if (value.Str() == "hintnone")
00073       style = CAIRO_HINT_STYLE_NONE;
00074     else if (value.Str() == "hintslight")
00075       style = CAIRO_HINT_STYLE_SLIGHT;
00076     else if (value.Str() == "hintmedium")
00077       style = CAIRO_HINT_STYLE_MEDIUM;
00078     else if (value.Str() == "hintfull")
00079       style = CAIRO_HINT_STYLE_FULL;
00080 
00081     cairo_font_options_set_hint_style(font_options, style);
00082   }
00083   
00084   // FIXME: Where do we read this value from?
00085   cairo_font_options_set_hint_metrics(font_options, CAIRO_HINT_METRICS_ON);
00086 
00087   gdk_screen_set_font_options(gdk_screen_get_default(), font_options);
00088   cairo_font_options_destroy(font_options);
00089 }
00090 
00091 }