[gnome-control-center/extensible-shell] [appearance] Port the font configuration to new system
- From: William Jon McCann <mccann src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-control-center/extensible-shell] [appearance] Port the font configuration to new system
- Date: Wed, 27 Jan 2010 04:55:24 +0000 (UTC)
commit 71dda58296ee10a2250a2f4bd3d67d6bd3a1cd02
Author: William Jon McCann <jmccann redhat com>
Date: Tue Jan 26 23:35:00 2010 -0500
[appearance] Port the font configuration to new system
capplets/appearance/Makefile.am | 7 +
capplets/appearance/cc-appearance-panel.c | 11 +
capplets/appearance/cc-font-common.c | 244 +++++++++
capplets/appearance/cc-font-common.h | 78 +++
capplets/appearance/cc-font-details-dialog.c | 603 ++++++++++++++++++++++
capplets/appearance/cc-font-details-dialog.h | 58 +++
capplets/appearance/cc-font-page.c | 691 ++++++++++++++++++++++++++
capplets/appearance/cc-font-page.h | 55 ++
capplets/appearance/data/appearance.ui | 4 +-
9 files changed, 1749 insertions(+), 2 deletions(-)
---
diff --git a/capplets/appearance/Makefile.am b/capplets/appearance/Makefile.am
index f7acc72..d924535 100644
--- a/capplets/appearance/Makefile.am
+++ b/capplets/appearance/Makefile.am
@@ -47,6 +47,12 @@ libappearance_la_SOURCES = \
cc-theme-customize-dialog.c \
cc-theme-page.h \
cc-theme-page.c \
+ cc-font-common.h \
+ cc-font-common.c \
+ cc-font-page.h \
+ cc-font-page.c \
+ cc-font-details-dialog.h \
+ cc-font-details-dialog.c \
cc-appearance-panel.h \
cc-appearance-panel.c \
$(NULL)
@@ -58,6 +64,7 @@ libappearance_la_LDFLAGS = \
libappearance_la_LIBADD = \
libappearance-common.la \
$(EXTENSION_LIBS) \
+ $(FONT_CAPPLET_LIBS) \
$(EXTENSION_COMMON_LIBS) \
$(NULL)
diff --git a/capplets/appearance/cc-appearance-panel.c b/capplets/appearance/cc-appearance-panel.c
index 2e8c716..3112c14 100644
--- a/capplets/appearance/cc-appearance-panel.c
+++ b/capplets/appearance/cc-appearance-panel.c
@@ -32,6 +32,7 @@
#include "cc-theme-page.h"
#include "cc-background-page.h"
+#include "cc-font-page.h"
#include "cc-appearance-panel.h"
#define CC_APPEARANCE_PANEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_APPEARANCE_PANEL, CcAppearancePanelPrivate))
@@ -43,6 +44,7 @@ struct CcAppearancePanelPrivate
GtkWidget *notebook;
CcPage *theme_page;
CcPage *background_page;
+ CcPage *font_page;
};
enum {
@@ -156,6 +158,15 @@ setup_panel (CcAppearancePanel *panel)
gtk_notebook_append_page (GTK_NOTEBOOK (panel->priv->notebook), GTK_WIDGET (panel->priv->background_page), label);
gtk_widget_show (GTK_WIDGET (panel->priv->background_page));
+ panel->priv->font_page = cc_font_page_new ();
+ g_object_get (panel->priv->font_page,
+ "display-name", &display_name,
+ NULL);
+ label = gtk_label_new (display_name);
+ g_free (display_name);
+ gtk_notebook_append_page (GTK_NOTEBOOK (panel->priv->notebook), GTK_WIDGET (panel->priv->font_page), label);
+ gtk_widget_show (GTK_WIDGET (panel->priv->font_page));
+
g_object_set (panel,
"current-page", panel->priv->theme_page,
NULL);
diff --git a/capplets/appearance/cc-font-common.c b/capplets/appearance/cc-font-common.c
new file mode 100644
index 0000000..ddf18f9
--- /dev/null
+++ b/capplets/appearance/cc-font-common.c
@@ -0,0 +1,244 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2002 Jonathan Blandford <jrb gnome org>
+ * Copyright (C) 2007 Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+#include <glib/gi18n-lib.h>
+#include <gconf/gconf-client.h>
+
+#ifdef HAVE_XFT2
+#include <gdk/gdkx.h>
+#include <X11/Xft/Xft.h>
+#endif /* HAVE_XFT2 */
+
+#include "cc-font-common.h"
+
+#ifdef HAVE_XFT2
+
+/*
+ * Code for displaying previews of font rendering with various Xft options
+ */
+
+static void
+sample_size_request (GtkWidget *darea,
+ GtkRequisition *requisition)
+{
+ GdkPixbuf *pixbuf = g_object_get_data (G_OBJECT (darea), "sample-pixbuf");
+
+ requisition->width = gdk_pixbuf_get_width (pixbuf) + 2;
+ requisition->height = gdk_pixbuf_get_height (pixbuf) + 2;
+}
+
+static void
+sample_expose (GtkWidget *darea,
+ GdkEventExpose *expose)
+{
+ GdkPixbuf *pixbuf = g_object_get_data (G_OBJECT (darea), "sample-pixbuf");
+ int width = gdk_pixbuf_get_width (pixbuf);
+ int height = gdk_pixbuf_get_height (pixbuf);
+
+ int x = (darea->allocation.width - width) / 2;
+ int y = (darea->allocation.height - height) / 2;
+
+ gdk_draw_rectangle (darea->window, darea->style->white_gc, TRUE,
+ 0, 0,
+ darea->allocation.width, darea->allocation.height);
+ gdk_draw_rectangle (darea->window, darea->style->black_gc, FALSE,
+ 0, 0,
+ darea->allocation.width - 1, darea->allocation.height - 1);
+
+ gdk_draw_pixbuf (darea->window, NULL, pixbuf, 0, 0, x, y, width, height,
+ GDK_RGB_DITHER_NORMAL, 0, 0);
+}
+
+static XftFont *
+open_pattern (FcPattern *pattern,
+ Antialiasing antialiasing,
+ Hinting hinting)
+{
+#ifdef FC_HINT_STYLE
+ static const int hintstyles[] = {
+ FC_HINT_NONE, FC_HINT_SLIGHT, FC_HINT_MEDIUM, FC_HINT_FULL
+ };
+#endif /* FC_HINT_STYLE */
+
+ FcPattern *res_pattern;
+ FcResult result;
+ XftFont *font;
+
+ Display *xdisplay = gdk_x11_get_default_xdisplay ();
+ int screen = gdk_x11_get_default_screen ();
+
+ res_pattern = XftFontMatch (xdisplay, screen, pattern, &result);
+ if (res_pattern == NULL)
+ return NULL;
+
+ FcPatternDel (res_pattern, FC_HINTING);
+ FcPatternAddBool (res_pattern, FC_HINTING, hinting != HINT_NONE);
+
+#ifdef FC_HINT_STYLE
+ FcPatternDel (res_pattern, FC_HINT_STYLE);
+ FcPatternAddInteger (res_pattern, FC_HINT_STYLE, hintstyles[hinting]);
+#endif /* FC_HINT_STYLE */
+
+ FcPatternDel (res_pattern, FC_ANTIALIAS);
+ FcPatternAddBool (res_pattern, FC_ANTIALIAS, antialiasing != ANTIALIAS_NONE);
+
+ FcPatternDel (res_pattern, FC_RGBA);
+ FcPatternAddInteger (res_pattern, FC_RGBA,
+ antialiasing == ANTIALIAS_RGBA ? FC_RGBA_RGB : FC_RGBA_NONE);
+
+ FcPatternDel (res_pattern, FC_DPI);
+ FcPatternAddInteger (res_pattern, FC_DPI, 96);
+
+ font = XftFontOpenPattern (xdisplay, res_pattern);
+ if (!font)
+ FcPatternDestroy (res_pattern);
+
+ return font;
+}
+
+void
+setup_font_sample (GtkWidget *darea,
+ Antialiasing antialiasing,
+ Hinting hinting)
+{
+ const char *string1 = "abcfgop AO ";
+ const char *string2 = "abcfgop";
+
+ XftColor black, white;
+ XRenderColor rendcolor;
+
+ Display *xdisplay = gdk_x11_get_default_xdisplay ();
+
+ GdkColormap *colormap = gdk_rgb_get_colormap ();
+ Colormap xcolormap = GDK_COLORMAP_XCOLORMAP (colormap);
+
+ GdkVisual *visual = gdk_colormap_get_visual (colormap);
+ Visual *xvisual = GDK_VISUAL_XVISUAL (visual);
+
+ FcPattern *pattern;
+ XftFont *font1, *font2;
+ XGlyphInfo extents1 = { 0 };
+ XGlyphInfo extents2 = { 0 };
+ GdkPixmap *pixmap;
+ XftDraw *draw;
+ GdkPixbuf *tmp_pixbuf, *pixbuf;
+
+ int width, height;
+ int ascent, descent;
+
+ pattern = FcPatternBuild (NULL,
+ FC_FAMILY, FcTypeString, "Serif",
+ FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN,
+ FC_SIZE, FcTypeDouble, 18.,
+ NULL);
+ font1 = open_pattern (pattern, antialiasing, hinting);
+ FcPatternDestroy (pattern);
+
+ pattern = FcPatternBuild (NULL,
+ FC_FAMILY, FcTypeString, "Serif",
+ FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC,
+ FC_SIZE, FcTypeDouble, 20.,
+ NULL);
+ font2 = open_pattern (pattern, antialiasing, hinting);
+ FcPatternDestroy (pattern);
+
+ ascent = 0;
+ descent = 0;
+ if (font1) {
+ XftTextExtentsUtf8 (xdisplay, font1, (unsigned char *) string1,
+ strlen (string1), &extents1);
+ ascent = MAX (ascent, font1->ascent);
+ descent = MAX (descent, font1->descent);
+ }
+
+ if (font2) {
+ XftTextExtentsUtf8 (xdisplay, font2, (unsigned char *) string2,
+ strlen (string2), &extents2);
+ ascent = MAX (ascent, font2->ascent);
+ descent = MAX (descent, font2->descent);
+ }
+
+ width = extents1.xOff + extents2.xOff + 4;
+ height = ascent + descent + 2;
+
+ pixmap = gdk_pixmap_new (NULL, width, height, visual->depth);
+
+ draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap);
+
+ rendcolor.red = 0;
+ rendcolor.green = 0;
+ rendcolor.blue = 0;
+ rendcolor.alpha = 0xffff;
+ XftColorAllocValue (xdisplay, xvisual, xcolormap, &rendcolor, &black);
+
+ rendcolor.red = 0xffff;
+ rendcolor.green = 0xffff;
+ rendcolor.blue = 0xffff;
+ rendcolor.alpha = 0xffff;
+ XftColorAllocValue (xdisplay, xvisual, xcolormap, &rendcolor, &white);
+ XftDrawRect (draw, &white, 0, 0, width, height);
+ if (font1)
+ XftDrawStringUtf8 (draw,
+ &black,
+ font1,
+ 2, 2 + ascent,
+ (unsigned char *) string1,
+ strlen (string1));
+ if (font2)
+ XftDrawStringUtf8 (draw,
+ &black,
+ font2,
+ 2 + extents1.xOff,
+ 2 + ascent,
+ (unsigned char *) string2,
+ strlen (string2));
+
+ XftDrawDestroy (draw);
+
+ if (font1)
+ XftFontClose (xdisplay, font1);
+ if (font2)
+ XftFontClose (xdisplay, font2);
+
+ tmp_pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap, 0, 0, 0, 0, width, height);
+ pixbuf = gdk_pixbuf_scale_simple (tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES);
+
+ g_object_unref (pixmap);
+ g_object_unref (tmp_pixbuf);
+
+ g_object_set_data_full (G_OBJECT (darea),
+ "sample-pixbuf",
+ pixbuf,
+ (GDestroyNotify) g_object_unref);
+
+ g_signal_connect (darea, "size_request", G_CALLBACK (sample_size_request), NULL);
+ g_signal_connect (darea, "expose_event", G_CALLBACK (sample_expose), NULL);
+}
+
+#endif
diff --git a/capplets/appearance/cc-font-common.h b/capplets/appearance/cc-font-common.h
new file mode 100644
index 0000000..4d12e64
--- /dev/null
+++ b/capplets/appearance/cc-font-common.h
@@ -0,0 +1,78 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2002 Jonathan Blandford <jrb gnome org>
+ * Copyright (C) 2007 Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#define GTK_FONT_KEY "/desktop/gnome/interface/font_name"
+#define DESKTOP_FONT_KEY "/apps/nautilus/preferences/desktop_font"
+
+#define METACITY_DIR "/apps/metacity/general"
+#define WINDOW_TITLE_FONT_KEY METACITY_DIR "/titlebar_font"
+#define WINDOW_TITLE_USES_SYSTEM_KEY METACITY_DIR "/titlebar_uses_system_font"
+#define MONOSPACE_FONT_KEY "/desktop/gnome/interface/monospace_font_name"
+#define DOCUMENT_FONT_KEY "/desktop/gnome/interface/document_font_name"
+
+#define FONT_RENDER_DIR "/desktop/gnome/font_rendering"
+#define FONT_ANTIALIASING_KEY FONT_RENDER_DIR "/antialiasing"
+#define FONT_HINTING_KEY FONT_RENDER_DIR "/hinting"
+#define FONT_RGBA_ORDER_KEY FONT_RENDER_DIR "/rgba_order"
+#define FONT_DPI_KEY FONT_RENDER_DIR "/dpi"
+
+
+/* X servers sometimes lie about the screen's physical dimensions, so we cannot
+ * compute an accurate DPI value. When this happens, the user gets fonts that
+ * are too huge or too tiny. So, we see what the server returns: if it reports
+ * something outside of the range [DPI_LOW_REASONABLE_VALUE,
+ * DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use
+ * DPI_FALLBACK instead.
+ *
+ * See get_dpi_from_gconf_or_server() below, and also
+ * https://bugzilla.novell.com/show_bug.cgi?id=217790
+ */
+#define DPI_FALLBACK 96
+#define DPI_LOW_REASONABLE_VALUE 50
+#define DPI_HIGH_REASONABLE_VALUE 500
+
+#define MAX_FONT_POINT_WITHOUT_WARNING 32
+#define MAX_FONT_SIZE_WITHOUT_WARNING MAX_FONT_POINT_WITHOUT_WARNING*1024
+
+typedef enum {
+ ANTIALIAS_NONE,
+ ANTIALIAS_GRAYSCALE,
+ ANTIALIAS_RGBA
+} Antialiasing;
+
+typedef enum {
+ HINT_NONE,
+ HINT_SLIGHT,
+ HINT_MEDIUM,
+ HINT_FULL
+} Hinting;
+
+typedef enum {
+ RGBA_RGB,
+ RGBA_BGR,
+ RGBA_VRGB,
+ RGBA_VBGR
+} RgbaOrder;
+
+void setup_font_sample (GtkWidget *drawing_area,
+ Antialiasing antialiasing,
+ Hinting hinting);
diff --git a/capplets/appearance/cc-font-details-dialog.c b/capplets/appearance/cc-font-details-dialog.c
new file mode 100644
index 0000000..74220f4
--- /dev/null
+++ b/capplets/appearance/cc-font-details-dialog.c
@@ -0,0 +1,603 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2002 Jonathan Blandford <jrb gnome org>
+ * Copyright (C) 2007 Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2010 William Jon McCann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <glib/gstdio.h>
+#include <gconf/gconf-client.h>
+
+#include "cc-font-details-dialog.h"
+#include "cc-font-common.h"
+
+#define CC_FONT_DETAILS_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_FONT_DETAILS_DIALOG, CcFontDetailsDialogPrivate))
+
+#define WID(s) GTK_WIDGET (gtk_builder_get_object (builder, s))
+
+struct CcFontDetailsDialogPrivate
+{
+ GSList *font_groups;
+ GtkWidget *dpi_spin_button;
+
+ GtkWidget *antialias_none_sample;
+ GtkWidget *antialias_grayscale_sample;
+ GtkWidget *antialias_subpixel_sample;
+
+ GtkWidget *antialias_none_radiobutton;
+ GtkWidget *antialias_grayscale_radiobutton;
+ GtkWidget *antialias_subpixel_radiobutton;
+
+ GtkWidget *hint_none_sample;
+ GtkWidget *hint_slight_sample;
+ GtkWidget *hint_medium_sample;
+ GtkWidget *hint_full_sample;
+
+ GtkWidget *hint_none_radiobutton;
+ GtkWidget *hint_slight_radiobutton;
+ GtkWidget *hint_medium_radiobutton;
+ GtkWidget *hint_full_radiobutton;
+
+ GtkWidget *subpixel_rgb_image;
+ GtkWidget *subpixel_bgr_image;
+ GtkWidget *subpixel_vrgb_image;
+ GtkWidget *subpixel_vbgr_image;
+
+ GtkWidget *subpixel_rgb_radiobutton;
+ GtkWidget *subpixel_bgr_radiobutton;
+ GtkWidget *subpixel_vrgb_radiobutton;
+ GtkWidget *subpixel_vbgr_radiobutton;
+
+ gboolean in_change;
+
+ guint dpi_notify_id;
+};
+
+enum {
+ PROP_0,
+};
+
+static void cc_font_details_dialog_class_init (CcFontDetailsDialogClass *klass);
+static void cc_font_details_dialog_init (CcFontDetailsDialog *font_details_dialog);
+static void cc_font_details_dialog_finalize (GObject *object);
+
+G_DEFINE_TYPE (CcFontDetailsDialog, cc_font_details_dialog, GTK_TYPE_DIALOG)
+
+static GConfEnumStringPair rgba_order_enums[] = {
+ { RGBA_RGB, "rgb" },
+ { RGBA_BGR, "bgr" },
+ { RGBA_VRGB, "vrgb" },
+ { RGBA_VBGR, "vbgr" },
+ { -1, NULL }
+};
+
+static GConfEnumStringPair antialias_enums[] = {
+ { ANTIALIAS_NONE, "none" },
+ { ANTIALIAS_GRAYSCALE, "grayscale" },
+ { ANTIALIAS_RGBA, "rgba" },
+ { -1, NULL }
+};
+
+static GConfEnumStringPair hint_enums[] = {
+ { HINT_NONE, "none" },
+ { HINT_SLIGHT, "slight" },
+ { HINT_MEDIUM, "medium" },
+ { HINT_FULL, "full" },
+ { -1, NULL }
+};
+
+static void
+cc_font_details_dialog_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ CcFontDetailsDialog *self;
+
+ self = CC_FONT_DETAILS_DIALOG (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_font_details_dialog_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static double
+dpi_from_pixels_and_mm (int pixels, int mm)
+{
+ double dpi;
+
+ if (mm >= 1)
+ dpi = pixels / (mm / 25.4);
+ else
+ dpi = 0;
+
+ return dpi;
+}
+
+static double
+get_dpi_from_x_server (void)
+{
+ GdkScreen *screen;
+ double dpi;
+
+ screen = gdk_screen_get_default ();
+ if (screen) {
+ double width_dpi, height_dpi;
+
+ width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen),
+ gdk_screen_get_width_mm (screen));
+ height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen),
+ gdk_screen_get_height_mm (screen));
+
+ if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE ||
+ height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE)
+ dpi = DPI_FALLBACK;
+ else
+ dpi = (width_dpi + height_dpi) / 2.0;
+ } else {
+ /* Huh!? No screen? */
+ dpi = DPI_FALLBACK;
+ }
+
+ return dpi;
+}
+
+static void
+dpi_load (CcFontDetailsDialog *dialog)
+{
+ GConfClient *client;
+ GConfValue *value;
+ gdouble dpi;
+
+ client = gconf_client_get_default ();
+ value = gconf_client_get_without_default (client, FONT_DPI_KEY, NULL);
+ g_object_unref (client);
+
+ if (value) {
+ dpi = gconf_value_get_float (value);
+ gconf_value_free (value);
+ } else
+ dpi = get_dpi_from_x_server ();
+
+ if (dpi < DPI_LOW_REASONABLE_VALUE)
+ dpi = DPI_LOW_REASONABLE_VALUE;
+
+ dialog->priv->in_change = TRUE;
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->dpi_spin_button), dpi);
+ dialog->priv->in_change = FALSE;
+}
+
+static void
+on_dpi_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ CcFontDetailsDialog *dialog)
+{
+ dpi_load (dialog);
+}
+
+static void
+on_dpi_value_changed (GtkSpinButton *spinner,
+ CcFontDetailsDialog *dialog)
+{
+ /* Like any time when using a spin button with GConf, there is
+ * a race condition here. When we change, we send the new
+ * value to GConf, then restore to the old value until
+ * we get a response to emulate the proper model/view behavior.
+ *
+ * If the user changes the value faster than responses are
+ * received from GConf, this may cause mildly strange effects.
+ */
+ if (!dialog->priv->in_change) {
+ gdouble new_dpi;
+ GConfClient *client;
+
+ client = gconf_client_get_default ();
+ new_dpi = gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->dpi_spin_button));
+ gconf_client_set_float (client, FONT_DPI_KEY, new_dpi, NULL);
+ g_object_unref (client);
+
+ dpi_load (dialog);
+ }
+}
+
+/*
+ * EnumGroup - a group of radio buttons tied to a string enumeration
+ * value. We add this here because the gconf peditor
+ * equivalent of this is both painful to use (you have
+ * to supply functions to convert from enums to indices)
+ * and conceptually broken (the order of radio buttons
+ * in a group when using Glade is not predictable.
+ */
+typedef struct
+{
+ GConfClient *client;
+ CcFontDetailsDialog *dialog;
+ GSList *items;
+ char *gconf_key;
+ GConfEnumStringPair *enums;
+ int default_value;
+ guint notify_id;
+} EnumGroup;
+
+typedef struct
+{
+ EnumGroup *group;
+ GtkToggleButton *widget;
+ int value;
+} EnumItem;
+
+static void
+enum_group_load (EnumGroup *group)
+{
+ char *str = gconf_client_get_string (group->client, group->gconf_key, NULL);
+ int val = group->default_value;
+ GSList *tmp_list;
+
+ if (str)
+ gconf_string_to_enum (group->enums, str, &val);
+
+ g_free (str);
+
+ group->dialog->priv->in_change = TRUE;
+
+ for (tmp_list = group->items; tmp_list; tmp_list = tmp_list->next) {
+ EnumItem *item = tmp_list->data;
+
+ if (val == item->value)
+ gtk_toggle_button_set_active (item->widget, TRUE);
+ }
+
+ group->dialog->priv->in_change = FALSE;
+}
+
+static void
+on_enum_group_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ EnumGroup *group)
+{
+ enum_group_load (group);
+}
+
+static void
+enum_item_toggled (GtkToggleButton *toggle_button,
+ EnumItem *item)
+{
+ EnumGroup *group = item->group;
+
+ if (!group->dialog->priv->in_change) {
+ gconf_client_set_string (group->client,
+ group->gconf_key,
+ gconf_enum_to_string (group->enums, item->value),
+ NULL);
+ }
+
+ /* Restore back to the previous state until we get notification */
+ enum_group_load (group);
+}
+
+static EnumGroup *
+enum_group_create (CcFontDetailsDialog *dialog,
+ const char *gconf_key,
+ GConfEnumStringPair *enums,
+ int default_value,
+ GtkWidget *first_widget,
+ ...)
+{
+ EnumGroup *group;
+ GtkWidget *widget;
+ va_list args;
+
+ group = g_new (EnumGroup, 1);
+
+ group->dialog = dialog;
+ group->client = gconf_client_get_default ();
+ group->gconf_key = g_strdup (gconf_key);
+ group->enums = enums;
+ group->default_value = default_value;
+ group->items = NULL;
+
+ va_start (args, first_widget);
+
+ widget = first_widget;
+ while (widget) {
+ EnumItem *item;
+
+ item = g_new (EnumItem, 1);
+ item->group = group;
+ item->widget = GTK_TOGGLE_BUTTON (widget);
+ item->value = va_arg (args, int);
+
+ g_signal_connect (item->widget,
+ "toggled",
+ G_CALLBACK (enum_item_toggled),
+ item);
+
+ group->items = g_slist_prepend (group->items, item);
+
+ widget = va_arg (args, GtkWidget *);
+ }
+
+ va_end (args);
+
+ enum_group_load (group);
+
+ group->notify_id = gconf_client_notify_add (group->client,
+ gconf_key,
+ (GConfClientNotifyFunc) on_enum_group_changed,
+ group,
+ NULL,
+ NULL);
+
+ return group;
+}
+
+static void
+enum_group_destroy (EnumGroup *group)
+{
+ g_free (group->gconf_key);
+
+ g_slist_foreach (group->items, (GFunc) g_free, NULL);
+ g_slist_free (group->items);
+
+ gconf_client_notify_remove (group->client, group->notify_id);
+ g_object_unref (group->client);
+
+ g_free (group);
+}
+
+static void
+setup_dialog (CcFontDetailsDialog *dialog)
+{
+ GtkBuilder *builder;
+ GtkWidget *widget;
+ GtkWidget *box;
+ GtkAdjustment *adjustment;
+ EnumGroup *group;
+ GConfClient *client;
+ GError *error;
+
+ builder = gtk_builder_new ();
+
+ error = NULL;
+ gtk_builder_add_from_file (builder,
+ GNOMECC_UI_DIR
+ "/appearance.ui",
+ &error);
+ if (error != NULL) {
+ g_error (_("Could not load user interface file: %s"),
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ dialog->priv->dpi_spin_button = WID ("dpi_spinner");
+
+ /* pick a sensible maximum dpi */
+ adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (dialog->priv->dpi_spin_button));
+ adjustment->upper = DPI_HIGH_REASONABLE_VALUE;
+ adjustment->lower = DPI_LOW_REASONABLE_VALUE;
+ adjustment->step_increment = 1;
+
+ dpi_load (dialog);
+ g_signal_connect (dialog->priv->dpi_spin_button,
+ "value_changed",
+ G_CALLBACK (on_dpi_value_changed),
+ dialog);
+
+ client = gconf_client_get_default ();
+ dialog->priv->dpi_notify_id = gconf_client_notify_add (client,
+ FONT_DPI_KEY,
+ (GConfClientNotifyFunc) on_dpi_changed,
+ dialog,
+ NULL,
+ NULL);
+
+ dialog->priv->antialias_none_sample = WID ("antialias_none_sample");
+ dialog->priv->antialias_grayscale_sample = WID ("antialias_grayscale_sample");
+ dialog->priv->antialias_subpixel_sample = WID ("antialias_subpixel_sample");
+
+ dialog->priv->antialias_none_radiobutton = WID ("antialias_none_radio");
+ dialog->priv->antialias_grayscale_radiobutton = WID ("antialias_grayscale_radio");
+ dialog->priv->antialias_subpixel_radiobutton = WID ("antialias_subpixel_radio");
+
+ dialog->priv->hint_none_sample = WID ("hint_none_sample");
+ dialog->priv->hint_slight_sample = WID ("hint_slight_sample");
+ dialog->priv->hint_medium_sample = WID ("hint_medium_sample");
+ dialog->priv->hint_full_sample = WID ("hint_full_sample");
+
+ dialog->priv->hint_none_radiobutton = WID ("hint_none_radio");
+ dialog->priv->hint_slight_radiobutton = WID ("hint_slight_radio");
+ dialog->priv->hint_medium_radiobutton = WID ("hint_medium_radio");
+ dialog->priv->hint_full_radiobutton = WID ("hint_full_radio");
+
+ dialog->priv->subpixel_rgb_image = WID ("subpixel_rgb_image");
+ dialog->priv->subpixel_bgr_image = WID ("subpixel_bgr_image");
+ dialog->priv->subpixel_vrgb_image = WID ("subpixel_vrgb_image");
+ dialog->priv->subpixel_vbgr_image = WID ("subpixel_vbgr_image");
+
+ dialog->priv->subpixel_rgb_radiobutton = WID ("subpixel_rgb_radio");
+ dialog->priv->subpixel_bgr_radiobutton = WID ("subpixel_bgr_radio");
+ dialog->priv->subpixel_vrgb_radiobutton = WID ("subpixel_vrgb_radio");
+ dialog->priv->subpixel_vbgr_radiobutton = WID ("subpixel_vbgr_radio");
+
+ setup_font_sample (dialog->priv->antialias_none_sample,
+ ANTIALIAS_NONE,
+ HINT_FULL);
+ setup_font_sample (dialog->priv->antialias_grayscale_sample,
+ ANTIALIAS_GRAYSCALE,
+ HINT_FULL);
+ setup_font_sample (dialog->priv->antialias_subpixel_sample,
+ ANTIALIAS_RGBA,
+ HINT_FULL);
+
+ group = enum_group_create (dialog,
+ FONT_ANTIALIASING_KEY,
+ antialias_enums,
+ ANTIALIAS_GRAYSCALE,
+ dialog->priv->antialias_none_radiobutton,
+ ANTIALIAS_NONE,
+ dialog->priv->antialias_grayscale_radiobutton,
+ ANTIALIAS_GRAYSCALE,
+ dialog->priv->antialias_subpixel_radiobutton,
+ ANTIALIAS_RGBA,
+ NULL);
+ dialog->priv->font_groups = g_slist_prepend (dialog->priv->font_groups, group);
+
+ setup_font_sample (dialog->priv->hint_none_sample, ANTIALIAS_GRAYSCALE, HINT_NONE);
+ setup_font_sample (dialog->priv->hint_slight_sample, ANTIALIAS_GRAYSCALE, HINT_SLIGHT);
+ setup_font_sample (dialog->priv->hint_medium_sample, ANTIALIAS_GRAYSCALE, HINT_MEDIUM);
+ setup_font_sample (dialog->priv->hint_full_sample, ANTIALIAS_GRAYSCALE, HINT_FULL);
+
+ group = enum_group_create (dialog,
+ FONT_HINTING_KEY,
+ hint_enums,
+ HINT_FULL,
+ dialog->priv->hint_none_radiobutton, HINT_NONE,
+ dialog->priv->hint_slight_radiobutton, HINT_SLIGHT,
+ dialog->priv->hint_medium_radiobutton, HINT_MEDIUM,
+ dialog->priv->hint_full_radiobutton, HINT_FULL,
+ NULL);
+ dialog->priv->font_groups = g_slist_prepend (dialog->priv->font_groups, group);
+
+ gtk_image_set_from_file (GTK_IMAGE (dialog->priv->subpixel_rgb_image),
+ GNOMECC_PIXMAP_DIR "/subpixel-rgb.png");
+ gtk_image_set_from_file (GTK_IMAGE (dialog->priv->subpixel_bgr_image),
+ GNOMECC_PIXMAP_DIR "/subpixel-bgr.png");
+ gtk_image_set_from_file (GTK_IMAGE (dialog->priv->subpixel_vrgb_image),
+ GNOMECC_PIXMAP_DIR "/subpixel-vrgb.png");
+ gtk_image_set_from_file (GTK_IMAGE (dialog->priv->subpixel_vbgr_image),
+ GNOMECC_PIXMAP_DIR "/subpixel-vbgr.png");
+
+ group = enum_group_create (dialog,
+ FONT_RGBA_ORDER_KEY, rgba_order_enums, RGBA_RGB,
+ dialog->priv->subpixel_rgb_radiobutton, RGBA_RGB,
+ dialog->priv->subpixel_bgr_radiobutton, RGBA_BGR,
+ dialog->priv->subpixel_vrgb_radiobutton, RGBA_VRGB,
+ dialog->priv->subpixel_vbgr_radiobutton, RGBA_VBGR,
+ NULL);
+ dialog->priv->font_groups = g_slist_prepend (dialog->priv->font_groups, group);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
+
+ widget = WID ("render_details_vbox");
+ box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ gtk_widget_reparent (widget, box);
+ gtk_widget_show (widget);
+
+ g_object_unref (builder);
+ g_object_unref (client);
+}
+
+static GObject *
+cc_font_details_dialog_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ CcFontDetailsDialog *dialog;
+
+ dialog = CC_FONT_DETAILS_DIALOG (G_OBJECT_CLASS (cc_font_details_dialog_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_properties));
+
+ setup_dialog (dialog);
+
+ return G_OBJECT (dialog);
+}
+
+static void
+cc_font_details_dialog_class_init (CcFontDetailsDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = cc_font_details_dialog_get_property;
+ object_class->set_property = cc_font_details_dialog_set_property;
+ object_class->constructor = cc_font_details_dialog_constructor;
+ object_class->finalize = cc_font_details_dialog_finalize;
+
+ g_type_class_add_private (klass, sizeof (CcFontDetailsDialogPrivate));
+}
+
+static void
+cc_font_details_dialog_init (CcFontDetailsDialog *dialog)
+{
+ dialog->priv = CC_FONT_DETAILS_DIALOG_GET_PRIVATE (dialog);
+}
+
+static void
+cc_font_details_dialog_finalize (GObject *object)
+{
+ CcFontDetailsDialog *dialog;
+ GConfClient *client;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (CC_IS_FONT_DETAILS_DIALOG (object));
+
+ dialog = CC_FONT_DETAILS_DIALOG (object);
+
+ g_return_if_fail (dialog->priv != NULL);
+
+ client = gconf_client_get_default ();
+ gconf_client_notify_remove (client, dialog->priv->dpi_notify_id);
+ g_object_unref (client);
+
+ g_slist_foreach (dialog->priv->font_groups,
+ (GFunc) enum_group_destroy,
+ NULL);
+ g_slist_free (dialog->priv->font_groups);
+
+ G_OBJECT_CLASS (cc_font_details_dialog_parent_class)->finalize (object);
+}
+
+GtkWidget *
+cc_font_details_dialog_new (void)
+{
+ GObject *object;
+
+ object = g_object_new (CC_TYPE_FONT_DETAILS_DIALOG,
+ "title", _("Font Rendering Details"),
+ "has-separator", FALSE,
+ NULL);
+
+ return GTK_WIDGET (object);
+}
diff --git a/capplets/appearance/cc-font-details-dialog.h b/capplets/appearance/cc-font-details-dialog.h
new file mode 100644
index 0000000..43c1f9b
--- /dev/null
+++ b/capplets/appearance/cc-font-details-dialog.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 William Jon McCann
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __CC_FONT_DETAILS_DIALOG_H
+#define __CC_FONT_DETAILS_DIALOG_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_FONT_DETAILS_DIALOG (cc_font_details_dialog_get_type ())
+#define CC_FONT_DETAILS_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_FONT_DETAILS_DIALOG, CcFontDetailsDialog))
+#define CC_FONT_DETAILS_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_FONT_DETAILS_DIALOG, CcFontDetailsDialogClass))
+#define CC_IS_FONT_DETAILS_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_FONT_DETAILS_DIALOG))
+#define CC_IS_FONT_DETAILS_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_FONT_DETAILS_DIALOG))
+#define CC_FONT_DETAILS_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_FONT_DETAILS_DIALOG, CcFontDetailsDialogClass))
+
+typedef struct CcFontDetailsDialogPrivate CcFontDetailsDialogPrivate;
+
+typedef struct
+{
+ GtkDialog parent;
+ CcFontDetailsDialogPrivate *priv;
+} CcFontDetailsDialog;
+
+typedef struct
+{
+ GtkDialogClass parent_class;
+} CcFontDetailsDialogClass;
+
+#define CC_FONT_DETAILS_DIALOG_ERROR (cc_font_details_dialog_error_quark ())
+
+GType cc_font_details_dialog_get_type (void);
+GQuark cc_font_details_dialog_error_quark (void);
+
+GtkWidget * cc_font_details_dialog_new (void);
+
+G_END_DECLS
+
+#endif /* __CC_FONT_DETAILS_DIALOG_H */
diff --git a/capplets/appearance/cc-font-page.c b/capplets/appearance/cc-font-page.c
new file mode 100644
index 0000000..c15a06b
--- /dev/null
+++ b/capplets/appearance/cc-font-page.c
@@ -0,0 +1,691 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2002 Jonathan Blandford <jrb gnome org>
+ * Copyright (C) 2007 Jens Granseuer <jensgr gmx net>
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+#include <glib/gi18n-lib.h>
+#include <gconf/gconf-client.h>
+
+#include "gconf-property-editor.h"
+
+#include "cc-font-page.h"
+#include "cc-font-details-dialog.h"
+#include "cc-font-common.h"
+
+#define CC_FONT_PAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_FONT_PAGE, CcFontPagePrivate))
+
+#define WID(s) GTK_WIDGET (gtk_builder_get_object (builder, s))
+
+struct CcFontPagePrivate
+{
+ GtkWidget *window_title_font;
+ GtkWidget *desktop_font;
+ GtkWidget *document_font;
+ GtkWidget *monospace_font;
+ GtkWidget *application_font;
+
+ GtkWidget *font_details_dialog;
+ GSList *font_pairs;
+
+ gboolean in_change;
+ char *old_font;
+ guint metacity_font_notify_id;
+ guint font_render_notify_id;
+};
+
+enum {
+ PROP_0,
+};
+
+static void cc_font_page_class_init (CcFontPageClass *klass);
+static void cc_font_page_init (CcFontPage *font_page);
+static void cc_font_page_finalize (GObject *object);
+
+G_DEFINE_TYPE (CcFontPage, cc_font_page, CC_TYPE_PAGE)
+
+static GConfEnumStringPair antialias_enums[] = {
+ { ANTIALIAS_NONE, "none" },
+ { ANTIALIAS_GRAYSCALE, "grayscale" },
+ { ANTIALIAS_RGBA, "rgba" },
+ { -1, NULL }
+};
+
+static GConfEnumStringPair hint_enums[] = {
+ { HINT_NONE, "none" },
+ { HINT_SLIGHT, "slight" },
+ { HINT_MEDIUM, "medium" },
+ { HINT_FULL, "full" },
+ { -1, NULL }
+};
+
+static void
+cc_font_page_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cc_font_page_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/*
+ * Code implementing a group of radio buttons with different Xft option combinations.
+ * If one of the buttons is matched by the GConf key, we pick it. Otherwise we
+ * show the group as inconsistent.
+ */
+static void
+font_render_get_gconf (GConfClient *client,
+ Antialiasing *antialiasing,
+ Hinting *hinting)
+{
+ char *antialias_str = gconf_client_get_string (client, FONT_ANTIALIASING_KEY, NULL);
+ char *hint_str = gconf_client_get_string (client, FONT_HINTING_KEY, NULL);
+ int val;
+
+ val = ANTIALIAS_GRAYSCALE;
+ if (antialias_str) {
+ gconf_string_to_enum (antialias_enums, antialias_str, &val);
+ g_free (antialias_str);
+ }
+ *antialiasing = val;
+
+ val = HINT_FULL;
+ if (hint_str) {
+ gconf_string_to_enum (hint_enums, hint_str, &val);
+ g_free (hint_str);
+ }
+ *hinting = val;
+}
+
+typedef struct {
+ Antialiasing antialiasing;
+ Hinting hinting;
+ GtkToggleButton *radio;
+} FontPair;
+
+static void
+font_render_load (CcFontPage *page)
+{
+ Antialiasing antialiasing;
+ Hinting hinting;
+ gboolean inconsistent = TRUE;
+ GSList *tmp_list;
+ GConfClient *client;
+
+ client = gconf_client_get_default ();
+ font_render_get_gconf (client, &antialiasing, &hinting);
+ g_object_unref (client);
+
+ page->priv->in_change = TRUE;
+
+ for (tmp_list = page->priv->font_pairs; tmp_list; tmp_list = tmp_list->next) {
+ FontPair *pair = tmp_list->data;
+
+ if (antialiasing == pair->antialiasing && hinting == pair->hinting) {
+ gtk_toggle_button_set_active (pair->radio, TRUE);
+ inconsistent = FALSE;
+ break;
+ }
+ }
+
+ for (tmp_list = page->priv->font_pairs; tmp_list; tmp_list = tmp_list->next) {
+ FontPair *pair = tmp_list->data;
+
+ gtk_toggle_button_set_inconsistent (pair->radio, inconsistent);
+ }
+
+ page->priv->in_change = FALSE;
+}
+
+static void
+on_font_render_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ CcFontPage *page)
+{
+ font_render_load (page);
+}
+
+static void
+on_font_radio_toggled (GtkToggleButton *toggle_button,
+ CcFontPage *page)
+{
+ GSList *l;
+
+ if (!page->priv->in_change) {
+ GConfClient *client = gconf_client_get_default ();
+ FontPair *pair;
+
+ pair = NULL;
+ for (l = page->priv->font_pairs; l != NULL; l = l->next) {
+ FontPair *p;
+ p = l->data;
+ if (p->radio == toggle_button) {
+ pair = p;
+ break;
+ }
+ }
+
+ g_assert (pair != NULL);
+
+ gconf_client_set_string (client,
+ FONT_ANTIALIASING_KEY,
+ gconf_enum_to_string (antialias_enums, pair->antialiasing),
+ NULL);
+ gconf_client_set_string (client,
+ FONT_HINTING_KEY,
+ gconf_enum_to_string (hint_enums, pair->hinting),
+ NULL);
+
+ /* Restore back to the previous state until we get notification */
+ font_render_load (page);
+ g_object_unref (client);
+ }
+}
+
+static void
+setup_font_pair (CcFontPage *page,
+ GtkWidget *radio,
+ GtkWidget *darea,
+ Antialiasing antialiasing,
+ Hinting hinting)
+{
+ FontPair *pair = g_new (FontPair, 1);
+
+ pair->antialiasing = antialiasing;
+ pair->hinting = hinting;
+ pair->radio = GTK_TOGGLE_BUTTON (radio);
+
+ setup_font_sample (darea, antialiasing, hinting);
+ page->priv->font_pairs = g_slist_prepend (page->priv->font_pairs, pair);
+
+ g_signal_connect (radio,
+ "toggled",
+ G_CALLBACK (on_font_radio_toggled),
+ page);
+}
+
+static void
+metacity_titlebar_load_sensitivity (CcFontPage *page)
+{
+ GConfClient *client;
+
+ client = gconf_client_get_default ();
+ gtk_widget_set_sensitive (page->priv->window_title_font,
+ !gconf_client_get_bool (client,
+ WINDOW_TITLE_USES_SYSTEM_KEY,
+ NULL));
+ g_object_unref (client);
+}
+
+static void
+on_metacity_font_changed (GConfClient *client,
+ guint cnxn_id,
+ GConfEntry *entry,
+ CcFontPage *page)
+{
+ metacity_titlebar_load_sensitivity (page);
+}
+
+/* returns 0 if the font is safe, otherwise returns the size in points. */
+static gint
+font_dangerous (const char *font)
+{
+ PangoFontDescription *pfd;
+ gboolean retval = 0;
+
+ pfd = pango_font_description_from_string (font);
+ if (pfd == NULL)
+ /* an invalid font was passed in. This isn't our problem. */
+ return 0;
+
+ if ((pango_font_description_get_set_fields (pfd) & PANGO_FONT_MASK_SIZE) &&
+ (pango_font_description_get_size (pfd) >= MAX_FONT_SIZE_WITHOUT_WARNING)) {
+ retval = pango_font_description_get_size (pfd)/1024;
+ }
+ pango_font_description_free (pfd);
+
+ return retval;
+}
+
+static GConfValue *
+application_font_to_gconf (GConfPropertyEditor *peditor,
+ GConfValue *value)
+{
+ GConfValue *new_value;
+ const char *new_font;
+ GtkWidget *font_button;
+ gint danger_level;
+ CcFontPage *page;
+
+ page = g_object_get_data (G_OBJECT (peditor), "page");
+
+ font_button = GTK_WIDGET (gconf_property_editor_get_ui_control (peditor));
+ g_return_val_if_fail (font_button != NULL, NULL);
+
+ new_value = gconf_value_new (GCONF_VALUE_STRING);
+ new_font = gconf_value_get_string (value);
+ if (font_dangerous (page->priv->old_font)) {
+ /* If we're already too large, we don't warn again. */
+ gconf_value_set_string (new_value, new_font);
+ return new_value;
+ }
+
+ danger_level = font_dangerous (new_font);
+ if (danger_level) {
+ GtkWidget *warning_dialog, *apply_button;
+ const char *warning_label;
+ char *warning_label2;
+
+ warning_label = _("Font may be too large");
+
+ if (danger_level > MAX_FONT_POINT_WITHOUT_WARNING) {
+ warning_label2 = g_strdup_printf (ngettext (
+ "The font selected is %d point large, "
+ "and may make it difficult to effectively "
+ "use the computer. It is recommended that "
+ "you select a size smaller than %d.",
+ "The font selected is %d points large, "
+ "and may make it difficult to effectively "
+ "use the computer. It is recommended that "
+ "you select a size smaller than %d.",
+ danger_level),
+ danger_level,
+ MAX_FONT_POINT_WITHOUT_WARNING);
+ } else {
+ warning_label2 = g_strdup_printf (ngettext (
+ "The font selected is %d point large, "
+ "and may make it difficult to effectively "
+ "use the computer. It is recommended that "
+ "you select a smaller sized font.",
+ "The font selected is %d points large, "
+ "and may make it difficult to effectively "
+ "use the computer. It is recommended that "
+ "you select a smaller sized font.",
+ danger_level),
+ danger_level);
+ }
+
+ warning_dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ "%s",
+ warning_label);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (warning_dialog),
+ "%s", warning_label2);
+
+ gtk_dialog_add_button (GTK_DIALOG (warning_dialog),
+ _("Use previous font"), GTK_RESPONSE_CLOSE);
+
+ apply_button = gtk_button_new_with_label (_("Use selected font"));
+
+ gtk_button_set_image (GTK_BUTTON (apply_button), gtk_image_new_from_stock (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON));
+ gtk_dialog_add_action_widget (GTK_DIALOG (warning_dialog), apply_button, GTK_RESPONSE_APPLY);
+ GTK_WIDGET_SET_FLAGS (apply_button, GTK_CAN_DEFAULT);
+ gtk_widget_show (apply_button);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (warning_dialog), GTK_RESPONSE_CLOSE);
+
+ g_free (warning_label2);
+
+ if (gtk_dialog_run (GTK_DIALOG (warning_dialog)) == GTK_RESPONSE_APPLY) {
+ gconf_value_set_string (new_value, new_font);
+ } else {
+ gconf_value_set_string (new_value, page->priv->old_font);
+ gtk_font_button_set_font_name (GTK_FONT_BUTTON (font_button), page->priv->old_font);
+ }
+
+ gtk_widget_destroy (warning_dialog);
+ } else {
+ gconf_value_set_string (new_value, new_font);
+ }
+
+ return new_value;
+}
+
+static void
+on_application_font_changed (CcFontPage *page)
+{
+ const char *font;
+
+ font = gtk_font_button_get_font_name (GTK_FONT_BUTTON (page->priv->application_font));
+ g_free (page->priv->old_font);
+ page->priv->old_font = g_strdup (font);
+}
+
+#ifdef HAVE_XFT2
+
+static void
+on_font_details_response (GtkDialog *dialog,
+ gint response_id,
+ CcFontPage *page)
+{
+ if (page->priv->font_details_dialog != NULL) {
+ gtk_widget_destroy (page->priv->font_details_dialog);
+ page->priv->font_details_dialog = NULL;
+ }
+}
+
+static void
+on_details_button_clicked (GtkWidget *button,
+ CcFontPage *page)
+{
+ if (page->priv->font_details_dialog == NULL) {
+ GtkWidget *toplevel;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (page));
+ if (!GTK_WIDGET_TOPLEVEL (toplevel)) {
+ toplevel = NULL;
+ }
+
+ page->priv->font_details_dialog = cc_font_details_dialog_new ();
+
+ g_signal_connect (page->priv->font_details_dialog,
+ "response",
+ G_CALLBACK (on_font_details_response),
+ page);
+
+ gtk_window_set_transient_for (GTK_WINDOW (page->priv->font_details_dialog),
+ GTK_WINDOW (toplevel));
+
+ }
+
+ gtk_window_present (GTK_WINDOW (page->priv->font_details_dialog));
+}
+#endif /* HAVE_XFT2 */
+
+static void
+setup_page (CcFontPage *page)
+{
+ GtkBuilder *builder;
+ GtkWidget *widget;
+ GError *error;
+ GConfClient *client;
+ GObject *peditor;
+
+ client = gconf_client_get_default ();
+
+ builder = gtk_builder_new ();
+
+ error = NULL;
+ gtk_builder_add_from_file (builder,
+ GNOMECC_UI_DIR
+ "/appearance.ui",
+ &error);
+ if (error != NULL) {
+ g_error (_("Could not load user interface file: %s"),
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ page->priv->font_details_dialog = NULL;
+
+ gconf_client_add_dir (client,
+ "/desktop/gnome/interface",
+ GCONF_CLIENT_PRELOAD_ONELEVEL,
+ NULL);
+ gconf_client_add_dir (client,
+ "/apps/nautilus/preferences",
+ GCONF_CLIENT_PRELOAD_ONELEVEL,
+ NULL);
+ gconf_client_add_dir (client,
+ METACITY_DIR,
+ GCONF_CLIENT_PRELOAD_ONELEVEL,
+ NULL);
+#ifdef HAVE_XFT2
+ gconf_client_add_dir (client,
+ FONT_RENDER_DIR,
+ GCONF_CLIENT_PRELOAD_ONELEVEL,
+ NULL);
+#endif /* HAVE_XFT2 */
+
+ page->priv->window_title_font = WID ("window_title_font");
+ page->priv->application_font = WID ("application_font");
+ page->priv->desktop_font = WID ("desktop_font");
+ page->priv->document_font = WID ("document_font");
+ page->priv->monospace_font = WID ("monospace_font");
+
+ peditor = gconf_peditor_new_font (NULL,
+ GTK_FONT_KEY,
+ page->priv->application_font,
+ "conv-from-widget-cb",
+ application_font_to_gconf,
+ NULL);
+ g_object_set_data (peditor, "page", page);
+
+ g_signal_connect_swapped (peditor,
+ "value-changed",
+ G_CALLBACK (on_application_font_changed),
+ page);
+ on_application_font_changed (page);
+
+ peditor = gconf_peditor_new_font (NULL,
+ DOCUMENT_FONT_KEY,
+ page->priv->document_font,
+ NULL);
+
+ peditor = gconf_peditor_new_font (NULL,
+ DESKTOP_FONT_KEY,
+ page->priv->desktop_font,
+ NULL);
+
+ peditor = gconf_peditor_new_font (NULL,
+ WINDOW_TITLE_FONT_KEY,
+ page->priv->window_title_font,
+ NULL);
+
+ peditor = gconf_peditor_new_font (NULL,
+ MONOSPACE_FONT_KEY,
+ page->priv->monospace_font,
+ NULL);
+
+ page->priv->metacity_font_notify_id =
+ gconf_client_notify_add (client,
+ WINDOW_TITLE_USES_SYSTEM_KEY,
+ (GConfClientNotifyFunc) on_metacity_font_changed,
+ page,
+ NULL,
+ NULL);
+
+ metacity_titlebar_load_sensitivity (page);
+
+#ifdef HAVE_XFT2
+ setup_font_pair (page,
+ WID ("monochrome_radio"),
+ WID ("monochrome_sample"),
+ ANTIALIAS_NONE, HINT_FULL);
+ setup_font_pair (page,
+ WID ("best_shapes_radio"),
+ WID ("best_shapes_sample"),
+ ANTIALIAS_GRAYSCALE, HINT_MEDIUM);
+ setup_font_pair (page,
+ WID ("best_contrast_radio"),
+ WID ("best_contrast_sample"),
+ ANTIALIAS_GRAYSCALE, HINT_FULL);
+ setup_font_pair (page,
+ WID ("subpixel_radio"),
+ WID ("subpixel_sample"),
+ ANTIALIAS_RGBA, HINT_FULL);
+
+ font_render_load (page);
+
+ page->priv->font_render_notify_id =
+ gconf_client_notify_add (client,
+ FONT_RENDER_DIR,
+ (GConfClientNotifyFunc) on_font_render_changed,
+ page,
+ NULL,
+ NULL);
+
+ g_signal_connect (WID ("details_button"),
+ "clicked",
+ G_CALLBACK (on_details_button_clicked),
+ page);
+#else /* !HAVE_XFT2 */
+ gtk_widget_hide (WID ("font_render_frame"));
+#endif /* HAVE_XFT2 */
+
+
+ widget = WID ("font_vbox");
+ gtk_widget_reparent (widget, GTK_WIDGET (page));
+ gtk_widget_show (widget);
+
+ g_object_unref (client);
+ g_object_unref (builder);
+}
+
+static GObject *
+cc_font_page_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ CcFontPage *font_page;
+
+ font_page = CC_FONT_PAGE (G_OBJECT_CLASS (cc_font_page_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_properties));
+
+ g_object_set (font_page,
+ "display-name", _("Font"),
+ "id", "font",
+ NULL);
+
+ setup_page (font_page);
+
+ return G_OBJECT (font_page);
+}
+
+static void
+start_working (CcFontPage *page)
+{
+ static gboolean once = FALSE;
+
+ if (!once) {
+
+ once = TRUE;
+ }
+}
+
+static void
+stop_working (CcFontPage *page)
+{
+
+}
+
+static void
+cc_font_page_active_changed (CcPage *base_page,
+ gboolean is_active)
+{
+ CcFontPage *page = CC_FONT_PAGE (base_page);
+
+ if (is_active)
+ start_working (page);
+ else
+ stop_working (page);
+
+ CC_PAGE_CLASS (cc_font_page_parent_class)->active_changed (base_page, is_active);
+
+}
+
+static void
+cc_font_page_class_init (CcFontPageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ CcPageClass *page_class = CC_PAGE_CLASS (klass);
+
+ object_class->get_property = cc_font_page_get_property;
+ object_class->set_property = cc_font_page_set_property;
+ object_class->constructor = cc_font_page_constructor;
+ object_class->finalize = cc_font_page_finalize;
+
+ page_class->active_changed = cc_font_page_active_changed;
+
+ g_type_class_add_private (klass, sizeof (CcFontPagePrivate));
+}
+
+static void
+cc_font_page_init (CcFontPage *page)
+{
+ page->priv = CC_FONT_PAGE_GET_PRIVATE (page);
+}
+
+static void
+cc_font_page_finalize (GObject *object)
+{
+ CcFontPage *page;
+ GConfClient *client;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (CC_IS_FONT_PAGE (object));
+
+ page = CC_FONT_PAGE (object);
+
+ g_return_if_fail (page->priv != NULL);
+
+ client = gconf_client_get_default ();
+ gconf_client_notify_remove (client, page->priv->metacity_font_notify_id);
+ gconf_client_notify_remove (client, page->priv->font_render_notify_id);
+ g_object_unref (client);
+
+
+ g_slist_foreach (page->priv->font_pairs,
+ (GFunc) g_free,
+ NULL);
+ g_slist_free (page->priv->font_pairs);
+ g_free (page->priv->old_font);
+
+ G_OBJECT_CLASS (cc_font_page_parent_class)->finalize (object);
+}
+
+CcPage *
+cc_font_page_new (void)
+{
+ GObject *object;
+
+ object = g_object_new (CC_TYPE_FONT_PAGE, NULL);
+
+ return CC_PAGE (object);
+}
diff --git a/capplets/appearance/cc-font-page.h b/capplets/appearance/cc-font-page.h
new file mode 100644
index 0000000..9632dfb
--- /dev/null
+++ b/capplets/appearance/cc-font-page.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __CC_FONT_PAGE_H
+#define __CC_FONT_PAGE_H
+
+#include <gtk/gtk.h>
+#include "cc-page.h"
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_FONT_PAGE (cc_font_page_get_type ())
+#define CC_FONT_PAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CC_TYPE_FONT_PAGE, CcFontPage))
+#define CC_FONT_PAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CC_TYPE_FONT_PAGE, CcFontPageClass))
+#define CC_IS_FONT_PAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CC_TYPE_FONT_PAGE))
+#define CC_IS_FONT_PAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CC_TYPE_FONT_PAGE))
+#define CC_FONT_PAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CC_TYPE_FONT_PAGE, CcFontPageClass))
+
+typedef struct CcFontPagePrivate CcFontPagePrivate;
+
+typedef struct
+{
+ CcPage parent;
+ CcFontPagePrivate *priv;
+} CcFontPage;
+
+typedef struct
+{
+ CcPageClass parent_class;
+} CcFontPageClass;
+
+GType cc_font_page_get_type (void);
+
+CcPage * cc_font_page_new (void);
+
+G_END_DECLS
+
+#endif /* __CC_FONT_PAGE_H */
diff --git a/capplets/appearance/data/appearance.ui b/capplets/appearance/data/appearance.ui
index c9cefcf..87a670e 100644
--- a/capplets/appearance/data/appearance.ui
+++ b/capplets/appearance/data/appearance.ui
@@ -14,7 +14,7 @@
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
- <object class="GtkVBox" id="vbox7">
+ <object class="GtkVBox" id="render_details_vbox">
<property name="visible">True</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
@@ -1129,7 +1129,7 @@
</packing>
</child>
<child>
- <object class="GtkVBox" id="fonts_vbox">
+ <object class="GtkVBox" id="font_vbox">
<property name="visible">True</property>
<property name="border_width">12</property>
<property name="orientation">vertical</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]