[Illumination-commit] SF.net SVN: illumination:[4121] trunk/Illumination/src/Lum/OS/Gtk/GtkTheme. c
Status: Beta
Brought to you by:
tteuling
|
From: <tte...@us...> - 2011-04-23 13:45:05
|
Revision: 4121
http://illumination.svn.sourceforge.net/illumination/?rev=4121&view=rev
Author: tteuling
Date: 2011-04-23 13:44:58 +0000 (Sat, 23 Apr 2011)
Log Message:
-----------
Make use of GSettings for reading Gtk/Gnome default font names and sizes.
Modified Paths:
--------------
trunk/Illumination/src/Lum/OS/Gtk/GtkTheme.cpp
Modified: trunk/Illumination/src/Lum/OS/Gtk/GtkTheme.cpp
===================================================================
--- trunk/Illumination/src/Lum/OS/Gtk/GtkTheme.cpp 2011-03-01 14:31:14 UTC (rev 4120)
+++ trunk/Illumination/src/Lum/OS/Gtk/GtkTheme.cpp 2011-04-23 13:44:58 UTC (rev 4121)
@@ -44,6 +44,10 @@
#include <Lum/OS/Display.h>
+#if GLIB_CHECK_VERSION(2,26,0)
+ #include <gio/gio.h>
+#endif
+
#if defined(HAVE_LIB_GCONF)
#include <gconf/gconf-client.h>
#endif
@@ -3433,7 +3437,85 @@
return false;
}
-#if defined(HAVE_LIB_GCONF)
+#if GLIB_CHECK_VERSION(2,26,0)
+ static std::wstring ExtractFontNameFromGSettings(const char* key)
+ {
+ GSettings *settings;
+ gchar *tmp;
+
+ settings=g_settings_new("org.gnome.desktop.interface");
+ tmp=g_settings_get_string(settings,key);
+
+ if (tmp==NULL) {
+ g_object_unref(settings);
+ return L"";
+ }
+
+ std::wstring name(Lum::Base::StringToWString(tmp));
+
+ if (name.empty()) {
+ g_free(tmp);
+ g_object_unref(settings);
+ return L"";
+ }
+
+ g_free(tmp);
+ g_object_unref(settings);
+
+ size_t x=name.length()-1;
+
+ while (x>0 && name[x]>=L'0' && name[x]<=L'9') {
+ x--;
+ }
+ while (x>0 && name[x]==L' ') {
+ x--;
+ }
+
+ return name.substr(0,x+1);
+ }
+
+ static double ExtractFontSizeFromGSettings(const char* key)
+ {
+ GSettings *settings;
+ gchar *tmp;
+
+ settings=g_settings_new("org.gnome.desktop.interface");
+ tmp=g_settings_get_string(settings,key);
+
+ if (tmp==NULL) {
+ g_object_unref(settings);
+ return 0;
+ }
+
+ std::wstring size(Lum::Base::StringToWString(tmp));
+
+ if (size.empty()) {
+ g_free(tmp);
+ g_object_unref(settings);
+ return 0;
+ }
+
+ g_free(tmp);
+ g_object_unref(settings);
+
+ size_t x=size.length()-1;
+ size_t value;
+
+ while (x>0 && size[x]>=L'0' && size[x]<=L'9') {
+ x--;
+ }
+
+ assert(x<size.length());
+
+ size=size.substr(x+1);
+
+ if (Lum::Base::WStringToNumber(size,value)) {
+ return value;
+ }
+
+ assert(false);
+ }
+#elif defined(HAVE_LIB_GCONF)
static std::wstring ExtractFontNameFromGConf(const char* path)
{
GConfClient *client;
@@ -3470,7 +3552,7 @@
return name.substr(0,x+1);
}
- static size_t ExtractFontSizeFromGConf(const char* path)
+ static double ExtractFontSizeFromGConf(const char* path)
{
GConfClient *client;
gchar *tmp;
@@ -3488,7 +3570,7 @@
if (size.empty()) {
g_free(tmp);
g_object_unref(client);
- return 0;
+ return 0.0;
}
g_free(tmp);
@@ -3518,32 +3600,68 @@
std::wstring result;
#if defined(LUM_HAVE_LIB_HILDON)
- return Lum::Base::StringToWString(pango_font_description_get_family(gtkWidgets->GetStyle(GtkWidgets::styleWindow)->font_desc));
+ result=Lum::Base::StringToWString(pango_font_description_get_family(gtkWidgets->GetStyle(GtkWidgets::styleWindow)->font_desc));
+
+ if (!result.empty()) {
+ return result;
+ }
+#elif GLIB_CHECK_VERSION(2,26,0)
+ result=ExtractFontNameFromGSettings("font-name");
+
+ if (!result.empty()) {
+ return result;
+ }
#elif defined(HAVE_LIB_GCONF)
result=ExtractFontNameFromGConf("/desktop/gnome/interface/font_name");
-#endif
- if (result.empty()) {
- result=L"Helvetica";
+ if (!result.empty()) {
+ return result;
}
+#endif
+ result=L"Helvetica";
+
return result;
}
double GtkTheme::GetProportionalFontSize() const
{
- size_t result=0;
+ double result=0;
#if defined(LUM_HAVE_LIB_HILDON)
result=pango_font_description_get_size(gtkWidgets->GetStyle(GtkWidgets::styleWindow)->font_desc)/PANGO_SCALE;
+
+ if (result>=0) {
+ double resolution=gdk_screen_get_resolution(gdk_screen_get_default());
+
+ if (resolution<=0) {
+ resolution=96;
+ }
+
+ return result*(resolution/72);
+ }
+#elif GLIB_CHECK_VERSION(2,26,0)
+ result=ExtractFontSizeFromGSettings("font-name");
+
+ if (result>=0) {
+ return result;
+ }
#elif defined(HAVE_LIB_GCONF)
result=ExtractFontSizeFromGConf("/desktop/gnome/interface/font_name");
-#endif
- if (result==0) {
- result=9;
+ if (result>=0) {
+ double resolution=gdk_screen_get_resolution(gdk_screen_get_default());
+
+ if (resolution<=0) {
+ resolution=96;
+ }
+
+ return result*(resolution/72);
}
+#endif
+ result=9;
+
double resolution=gdk_screen_get_resolution(gdk_screen_get_default());
if (resolution<=0) {
@@ -3557,29 +3675,51 @@
{
std::wstring result;
-#if defined(HAVE_LIB_GCONF)
+#if GLIB_CHECK_VERSION(2,26,0)
+ result=ExtractFontNameFromGSettings("monospace-font-name");
+
+ if (!result.empty()) {
+ return result;
+ }
+
+#elif defined(HAVE_LIB_GCONF)
result=ExtractFontNameFromGConf("/desktop/gnome/interface/monospace_font_name");
-#endif
- if (result.empty()) {
- result=L"Fixed";
+ if (!result.empty()) {
+ return result;
}
+#endif
+ result=L"Fixed";
+
return result;
}
double GtkTheme::GetFixedFontSize() const
{
- size_t result=0;
+ double result=0;
-#if defined(HAVE_LIB_GCONF)
+#if GLIB_CHECK_VERSION(2,26,0)
+ result=ExtractFontSizeFromGSettings("monospace-font-name");
+
+ if (result>=0) {
+ return result;
+ }
+#elif defined(HAVE_LIB_GCONF)
result=ExtractFontSizeFromGConf("/desktop/gnome/interface/monospace_font_name");
-#endif
+ if (result>=0) {
+ double resolution=gdk_screen_get_resolution(gdk_screen_get_default());
- if (result==0) {
- result=9;
+ if (resolution<=0) {
+ resolution=96;
+ }
+
+ return result*(resolution/72);
}
+#endif
+ result=9;
+
double resolution=gdk_screen_get_resolution(gdk_screen_get_default());
if (resolution<=0) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|