gucharmap r1758 - trunk/gucharmap
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gucharmap r1758 - trunk/gucharmap
- Date: Mon, 31 Mar 2008 12:44:01 +0100 (BST)
Author: chpe
Date: Mon Mar 31 12:44:01 2008
New Revision: 1758
URL: http://svn.gnome.org/viewvc/gucharmap?rev=1758&view=rev
Log:
Make GucharmapMiniFontself use only PangoFontDescription instead of separate size and family.
Move the initial font setting code to GucharmapWindow.
Modified:
trunk/gucharmap/gucharmap-charmap.c
trunk/gucharmap/gucharmap-charmap.h
trunk/gucharmap/gucharmap-chartable.c
trunk/gucharmap/gucharmap-mini-fontsel.c
trunk/gucharmap/gucharmap-mini-fontsel.h
trunk/gucharmap/gucharmap-window.c
trunk/gucharmap/gucharmap-window.h
trunk/gucharmap/main.c
Modified: trunk/gucharmap/gucharmap-charmap.c
==============================================================================
--- trunk/gucharmap/gucharmap-charmap.c (original)
+++ trunk/gucharmap/gucharmap-charmap.c Mon Mar 31 12:44:01 2008
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2004 Noah Levitt
- * Copyright (c) 2007 Christian Persch
+ * Copyright (c) 2007, 2008 Christian Persch
*
* 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
@@ -241,6 +241,13 @@
gboolean in_notification)
{
GucharmapCharmapPrivate *priv = charmap->priv;
+ GObject *object = G_OBJECT (charmap);
+ gboolean equal;
+
+ g_object_freeze_notify (object);
+
+ equal = priv->font_desc != NULL &&
+ pango_font_description_equal (priv->font_desc, font_desc);
if (priv->font_desc)
pango_font_description_free (priv->font_desc);
@@ -253,7 +260,10 @@
if (gtk_widget_get_style (GTK_WIDGET (priv->details_view)))
gucharmap_charmap_update_text_tags (charmap);
- g_object_notify (G_OBJECT (charmap), "font-desc");
+ if (!equal)
+ g_object_notify (G_OBJECT (charmap), "font-desc");
+
+ g_object_thaw_notify (object);
}
static void
@@ -729,14 +739,14 @@
GParamSpec *pspec,
GucharmapCharmap *charmap)
{
+ GucharmapCharmapPrivate *priv = charmap->priv;
PangoFontDescription *font_desc;
- g_print ("sync_font_desc\n");
-
font_desc = gucharmap_chartable_get_font_desc (chartable);
gucharmap_charmap_set_font_desc_internal (charmap,
pango_font_description_copy (font_desc),
- TRUE);
+ //FIXME FALSE,
+ priv->font_desc != NULL /* Do notify if we didn't have a font desc yet */);
}
static void
Modified: trunk/gucharmap/gucharmap-charmap.h
==============================================================================
--- trunk/gucharmap/gucharmap-charmap.h (original)
+++ trunk/gucharmap/gucharmap-charmap.h Mon Mar 31 12:44:01 2008
@@ -33,7 +33,7 @@
#define GUCHARMAP_TYPE_CHARMAP (gucharmap_charmap_get_type ())
#define GUCHARMAP_CHARMAP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GUCHARMAP_TYPE_CHARMAP, GucharmapCharmap))
-#define GUCHARMAP_CHARMAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_CHARMAP, GucharmapCharmapClass))
+#define GUCHARMAP_CHARMAP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_CHARMAP, GucharmapCharmapClass))
#define GUCHARMAP_IS_CHARMAP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GUCHARMAP_TYPE_CHARMAP))
#define GUCHARMAP_IS_CHARMAP_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GUCHARMAP_TYPE_CHARMAP))
#define GUCHARMAP_CHARMAP_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GUCHARMAP_TYPE_CHARMAP, GucharmapCharmapClass))
Modified: trunk/gucharmap/gucharmap-chartable.c
==============================================================================
--- trunk/gucharmap/gucharmap-chartable.c (original)
+++ trunk/gucharmap/gucharmap-chartable.c Mon Mar 31 12:44:01 2008
@@ -1,6 +1,6 @@
/*
* Copyright  2004 Noah Levitt
- * Copyright  2007 Christian Persch
+ * Copyright  2007, 2008 Christian Persch
*
* Some code copied from gtk+/gtk/gtkiconview:
* Copyright  2002, 2004 Anders Carlsson <andersca gnu org>
@@ -1652,6 +1652,8 @@
PangoFontDescription *font_desc;
font_desc = pango_font_description_copy (widget->style->font_desc);
+ pango_font_description_set_size (font_desc,
+ 2.0 * pango_font_description_get_size (font_desc));
gucharmap_chartable_set_font_desc_internal (chartable, font_desc);
}
Modified: trunk/gucharmap/gucharmap-mini-fontsel.c
==============================================================================
--- trunk/gucharmap/gucharmap-mini-fontsel.c (original)
+++ trunk/gucharmap/gucharmap-mini-fontsel.c Mon Mar 31 12:44:01 2008
@@ -1,5 +1,6 @@
/*
* Copyright  2004 Noah Levitt
+ * Copyright  2008 Christian Persch
*
* 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
@@ -18,6 +19,8 @@
#include <config.h>
+#include <string.h>
+
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
@@ -34,8 +37,8 @@
enum
{
- CHANGED,
- NUM_SIGNALS
+ PROP_0,
+ PROP_FONT_DESC
};
enum
@@ -43,15 +46,21 @@
COL_FAMILIY
};
-static guint gucharmap_mini_font_selection_signals[NUM_SIGNALS];
+static void gucharmap_mini_font_selection_class_init (GucharmapMiniFontSelectionClass *klass);
+static void gucharmap_mini_font_selection_init (GucharmapMiniFontSelection *fontsel);
+static void gucharmap_mini_font_selection_finalize (GObject *object);
+G_DEFINE_TYPE (GucharmapMiniFontSelection, gucharmap_mini_font_selection, GTK_TYPE_HBOX)
static void
fill_font_families_combo (GucharmapMiniFontSelection *fontsel)
{
+ GtkComboBox *combo = GTK_COMBO_BOX (fontsel->family);
PangoFontFamily **families;
int n_families, i;
+ fontsel->family_store = gtk_list_store_new (1, G_TYPE_STRING);
+
pango_context_list_families (
gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
&families, &n_families);
@@ -74,11 +83,13 @@
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (fontsel->family_store),
COL_FAMILIY,
GTK_SORT_ASCENDING);
-}
+ gtk_combo_box_set_model (combo, GTK_TREE_MODEL (fontsel->family_store));
+ g_object_unref (fontsel->family_store);
+}
static void
-update_font_familiy_combo (GucharmapMiniFontSelection *fontsel)
+update_font_family_combo (GucharmapMiniFontSelection *fontsel)
{
GtkTreeModel *model = GTK_TREE_MODEL (fontsel->family_store);
GtkTreeIter iter;
@@ -86,8 +97,10 @@
gboolean found = FALSE;
font_family = pango_font_description_get_family (fontsel->font_desc);
- if (!font_family || !font_family[0])
+ if (!font_family || !font_family[0]) {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1);
return;
+ }
if (!gtk_tree_model_get_iter_first (model, &iter))
return;
@@ -102,22 +115,14 @@
if (found) {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (fontsel->family), &iter);
+ } else {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1);
}
}
-
static void
-set_family (GucharmapMiniFontSelection *fontsel,
- const gchar *new_family)
-{
- pango_font_description_set_family (fontsel->font_desc, new_family);
- g_signal_emit (fontsel, gucharmap_mini_font_selection_signals[CHANGED], 0);
-}
-
-
-static void
-family_changed (GtkComboBox *combo,
- GucharmapMiniFontSelection *fontsel)
+family_combo_changed (GtkComboBox *combo,
+ GucharmapMiniFontSelection *fontsel)
{
GtkTreeIter iter;
char *family;
@@ -132,55 +137,108 @@
if (!family)
return;
- set_family (fontsel, family);
+ pango_font_description_set_family (fontsel->font_desc, family);
g_free (family);
+
+ g_object_notify (G_OBJECT (fontsel), "font-desc");
}
+/* returns font size in points */
+static int
+get_font_size (GucharmapMiniFontSelection *fontsel)
+{
+ return pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE;
+}
/* size is in points */
static void
-set_size (GucharmapMiniFontSelection *fontsel,
- gint size)
+set_font_size (GucharmapMiniFontSelection *fontsel,
+ int size)
{
- pango_font_description_set_size (
- fontsel->font_desc,
- PANGO_SCALE * CLAMP (size, MIN_FONT_SIZE, MAX_FONT_SIZE));
- g_signal_emit (fontsel, gucharmap_mini_font_selection_signals[CHANGED], 0);
-}
+ size = CLAMP (size, MIN_FONT_SIZE, MAX_FONT_SIZE);
+ pango_font_description_set_size (fontsel->font_desc, PANGO_SCALE * size);
+ gtk_adjustment_set_value (GTK_ADJUSTMENT (fontsel->size_adj), size);
+
+ g_object_notify (G_OBJECT (fontsel), "font-desc");
+}
static void
-size_changed (GtkAdjustment *adjustment,
- GucharmapMiniFontSelection *fontsel)
+font_size_changed (GtkAdjustment *adjustment,
+ GucharmapMiniFontSelection *fontsel)
{
- if ((gint) gtk_adjustment_get_value (adjustment)
- != pango_font_description_get_size (fontsel->font_desc))
- set_size (fontsel, (gint) gtk_adjustment_get_value (adjustment));
-}
+ int new_size;
+ new_size = gtk_adjustment_get_value (adjustment);
+ if (new_size != get_font_size (fontsel))
+ set_font_size (fontsel, new_size);
+}
static void
-mini_font_selection_finalize (GObject *object)
+gucharmap_mini_font_selection_finalize (GObject *object)
{
GucharmapMiniFontSelection *fontsel = GUCHARMAP_MINI_FONT_SELECTION (object);
pango_font_description_free (fontsel->font_desc);
+
+ G_OBJECT_CLASS (gucharmap_mini_font_selection_parent_class)->finalize (object);
}
+static void
+gucharmap_mini_font_selection_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GucharmapMiniFontSelection *mini_fontsel = GUCHARMAP_MINI_FONT_SELECTION (object);
+
+ switch (prop_id) {
+ case PROP_FONT_DESC:
+ gucharmap_mini_font_selection_set_font_desc (mini_fontsel, g_value_get_boxed (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
static void
-gucharmap_mini_font_selection_class_init (GucharmapMiniFontSelectionClass *clazz)
+gucharmap_mini_font_selection_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GucharmapMiniFontSelection*mini_fontsel = GUCHARMAP_MINI_FONT_SELECTION (object);
+
+ switch (prop_id) {
+ case PROP_FONT_DESC:
+ g_value_set_boxed (value, gucharmap_mini_font_selection_get_font_desc (mini_fontsel));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gucharmap_mini_font_selection_class_init (GucharmapMiniFontSelectionClass *klass)
{
- gucharmap_mini_font_selection_signals[CHANGED] =
- g_signal_new (I_("changed"), gucharmap_mini_font_selection_get_type (),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GucharmapMiniFontSelectionClass, changed),
- NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- G_OBJECT_CLASS (clazz)->finalize = mini_font_selection_finalize;
+ gobject_class->finalize = gucharmap_mini_font_selection_finalize;
+ gobject_class->get_property = gucharmap_mini_font_selection_get_property;
+ gobject_class->set_property = gucharmap_mini_font_selection_set_property;
+
+ g_object_class_install_property
+ (gobject_class,
+ PROP_FONT_DESC,
+ g_param_spec_boxed ("font-desc", NULL, NULL,
+ PANGO_TYPE_FONT_DESCRIPTION,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
}
-
static void
bold_toggled (GtkToggleButton *toggle,
GucharmapMiniFontSelection *fontsel)
@@ -190,10 +248,9 @@
else
pango_font_description_set_weight (fontsel->font_desc, PANGO_WEIGHT_NORMAL);
- g_signal_emit (fontsel, gucharmap_mini_font_selection_signals[CHANGED], 0);
+ g_object_notify (G_OBJECT (fontsel), "font-desc");
}
-
static void
italic_toggled (GtkToggleButton *toggle,
GucharmapMiniFontSelection *fontsel)
@@ -203,10 +260,9 @@
else
pango_font_description_set_style (fontsel->font_desc, PANGO_STYLE_NORMAL);
- g_signal_emit (fontsel, gucharmap_mini_font_selection_signals[CHANGED], 0);
+ g_object_notify (G_OBJECT (fontsel), "font-desc");
}
-
static void
gucharmap_mini_font_selection_init (GucharmapMiniFontSelection *fontsel)
{
@@ -215,19 +271,18 @@
gtk_widget_ensure_style (GTK_WIDGET (fontsel));
fontsel->font_desc = pango_font_description_copy (GTK_WIDGET (fontsel)->style->font_desc);
- fontsel->default_size = pango_font_description_get_size (fontsel->font_desc);
+ fontsel->default_size = -1;
- fontsel->size_adj = gtk_adjustment_new (pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE,
- MIN_FONT_SIZE, MAX_FONT_SIZE, 1, 9, 0);
+ fontsel->size_adj = gtk_adjustment_new (MIN_FONT_SIZE,
+ MIN_FONT_SIZE, MAX_FONT_SIZE, 1, 8, 0);
accessib = gtk_widget_get_accessible (GTK_WIDGET (fontsel));
atk_object_set_name (accessib, _("Font"));
gtk_box_set_spacing (GTK_BOX (fontsel), 6);
- fontsel->family_store = gtk_list_store_new (1, G_TYPE_STRING);
- fontsel->family = gtk_combo_box_new_with_model (GTK_TREE_MODEL (fontsel->family_store));
- g_object_unref (fontsel->family_store);
+ fontsel->family = gtk_combo_box_new ();
+
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (fontsel->family), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (fontsel->family), renderer,
@@ -255,13 +310,13 @@
accessib = gtk_widget_get_accessible (fontsel->size);
atk_object_set_name (accessib, _("Font Size"));
g_signal_connect (fontsel->size_adj, "value-changed",
- G_CALLBACK (size_changed), fontsel);
+ G_CALLBACK (font_size_changed), fontsel);
fill_font_families_combo (fontsel);
- update_font_familiy_combo (fontsel);
-
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (fontsel->family), -1);
g_signal_connect (fontsel->family, "changed",
- G_CALLBACK (family_changed), fontsel);
+ G_CALLBACK (family_combo_changed), fontsel);
gtk_box_pack_start (GTK_BOX (fontsel), fontsel->family, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (fontsel), fontsel->bold, FALSE, FALSE, 0);
@@ -273,7 +328,6 @@
gtk_widget_show_all (GTK_WIDGET (fontsel));
}
-
GtkWidget *
gucharmap_mini_font_selection_new (void)
{
@@ -281,26 +335,37 @@
NULL));
}
-G_DEFINE_TYPE (GucharmapMiniFontSelection, gucharmap_mini_font_selection, GTK_TYPE_HBOX)
-
-/* XXX: should do error checking */
-gboolean
-gucharmap_mini_font_selection_set_font_name (GucharmapMiniFontSelection *fontsel,
- const gchar *fontname)
+void
+gucharmap_mini_font_selection_set_font_desc (GucharmapMiniFontSelection *fontsel,
+ PangoFontDescription *font_desc)
{
+ GObject *object = G_OBJECT (fontsel);
+ PangoFontDescription *new_font_desc;
+ const char *new_font_family;
+
+ g_return_if_fail (GUCHARMAP_IS_MINI_FONT_SELECTION (fontsel));
+ g_return_if_fail (font_desc != NULL);
+
+ g_object_freeze_notify (object);
+
+ new_font_desc = pango_font_description_copy (font_desc);
+ new_font_family = pango_font_description_get_family (new_font_desc);
+ if (!new_font_family) {
+ pango_font_description_set_family (new_font_desc, "Sans");
+ new_font_family = pango_font_description_get_family (new_font_desc);
+ }
- PangoFontDescription *fd = pango_font_description_from_string (fontname);
- if (pango_font_description_get_family (fd) == NULL)
- {
- const gchar *fam = pango_font_description_get_family (fontsel->font_desc);
- pango_font_description_set_family (fd, fam);
- }
+ if ((!fontsel->font_desc ||
+ strcmp (pango_font_description_get_family (fontsel->font_desc), new_font_family) != 0) &&
+ pango_font_description_get_size (new_font_desc) > 0)
+ fontsel->default_size = pango_font_description_get_size (new_font_desc) / PANGO_SCALE;
- pango_font_description_free (fontsel->font_desc);
+ if (fontsel->font_desc)
+ pango_font_description_free (fontsel->font_desc);
- fontsel->font_desc = fd;
+ fontsel->font_desc = new_font_desc;
- update_font_familiy_combo (fontsel);
+ update_font_family_combo (fontsel);
/* treat oblique and italic both as italic */
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fontsel->italic), pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_ITALIC || pango_font_description_get_style (fontsel->font_desc) == PANGO_STYLE_OBLIQUE);
@@ -311,48 +376,41 @@
GTK_ADJUSTMENT (fontsel->size_adj),
pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE);
- g_signal_emit (fontsel, gucharmap_mini_font_selection_signals[CHANGED], 0);
+ g_object_notify (G_OBJECT (fontsel), "font-desc");
- return TRUE;
+ g_object_thaw_notify (object);
}
-
-
-gchar *
-gucharmap_mini_font_selection_get_font_name (GucharmapMiniFontSelection *fontsel)
+PangoFontDescription *
+gucharmap_mini_font_selection_get_font_desc (GucharmapMiniFontSelection *fontsel)
{
- return pango_font_description_to_string (fontsel->font_desc);
-}
+ g_return_val_if_fail (GUCHARMAP_IS_MINI_FONT_SELECTION (fontsel), NULL);
-
-/* returns font size in points */
-gint
-gucharmap_mini_font_selection_get_font_size (GucharmapMiniFontSelection *fontsel)
-{
- return pango_font_description_get_size (fontsel->font_desc) / PANGO_SCALE;
+ return fontsel->font_desc;
}
-
-/* size in points */
void
-gucharmap_mini_font_selection_set_font_size (GucharmapMiniFontSelection *fontsel,
- gint size)
+gucharmap_mini_font_selection_change_font_size (GucharmapMiniFontSelection *fontsel,
+ float factor)
{
- gtk_adjustment_set_value (GTK_ADJUSTMENT (fontsel->size_adj), size);
- set_size (fontsel, size);
-}
+ int size, new_size;
-/* size in points */
-void
-gucharmap_mini_font_selection_set_default_font_size (GucharmapMiniFontSelection *fontsel,
- gint size)
-{
- fontsel->default_size = size;
+ size = pango_font_description_get_size (fontsel->font_desc);
+
+ new_size = (float) size * factor / (float) PANGO_SCALE;
+ if (factor > 1.0f)
+ new_size = MAX (new_size, size + 1);
+ else if (factor < 1.0f)
+ new_size = MIN (new_size, size - 1);
+
+ set_font_size (fontsel, new_size);
}
-/* size in points */
void
gucharmap_mini_font_selection_reset_font_size (GucharmapMiniFontSelection *fontsel)
{
- gucharmap_mini_font_selection_set_font_size (fontsel, fontsel->default_size);
+ if (fontsel->default_size > 0)
+ set_font_size (fontsel, fontsel->default_size);
+ else
+ set_font_size (fontsel, pango_font_description_get_size (GTK_WIDGET (fontsel)->style->font_desc) * 2.0f / PANGO_SCALE);
}
Modified: trunk/gucharmap/gucharmap-mini-fontsel.h
==============================================================================
--- trunk/gucharmap/gucharmap-mini-fontsel.h (original)
+++ trunk/gucharmap/gucharmap-mini-fontsel.h Mon Mar 31 12:44:01 2008
@@ -1,5 +1,6 @@
/*
* Copyright  2004 Noah Levitt
+ * Copyright  2008 Christian Persch
*
* 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
@@ -25,7 +26,7 @@
#define GUCHARMAP_TYPE_MINI_FONT_SELECTION (gucharmap_mini_font_selection_get_type ())
#define GUCHARMAP_MINI_FONT_SELECTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GUCHARMAP_TYPE_MINI_FONT_SELECTION, GucharmapMiniFontSelection))
-#define GUCHARMAP_MINI_FONT_SELECTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_MINI_FONT_SELECTION, GucharmapMiniFontSelectionClass))
+#define GUCHARMAP_MINI_FONT_SELECTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_MINI_FONT_SELECTION, GucharmapMiniFontSelectionClass))
#define GUCHARMAP_IS_MINI_FONT_SELECTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GUCHARMAP_TYPE_MINI_FONT_SELECTION))
#define GUCHARMAP_IS_MINI_FONT_SELECTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GUCHARMAP_TYPE_MINI_FONT_SELECTION))
#define GUCHARMAP_MINI_FONT_SELECTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GUCHARMAP_TYPE_MINI_FONT_SELECTION, GucharmapMiniFontSelectionClass))
@@ -53,25 +54,23 @@
struct _GucharmapMiniFontSelectionClass
{
GtkHBoxClass parent_class;
-
- void (* changed) (GucharmapMiniFontSelection *fontsel);
};
-GType gucharmap_mini_font_selection_get_type (void);
-GtkWidget * gucharmap_mini_font_selection_new (void);
-gboolean gucharmap_mini_font_selection_set_font_name (GucharmapMiniFontSelection *fontsel,
- const gchar *fontname);
-gchar * gucharmap_mini_font_selection_get_font_name (GucharmapMiniFontSelection *fontsel);
-gint gucharmap_mini_font_selection_get_font_size (GucharmapMiniFontSelection *fontsel);
-void gucharmap_mini_font_selection_set_font_size (GucharmapMiniFontSelection *fontsel,
- gint size);
-void gucharmap_mini_font_selection_set_default_font_size (GucharmapMiniFontSelection *fontsel,
- gint size);
-void gucharmap_mini_font_selection_reset_font_size (GucharmapMiniFontSelection *fontsel);
+GType gucharmap_mini_font_selection_get_type (void);
-G_END_DECLS
+GtkWidget * gucharmap_mini_font_selection_new (void);
+void gucharmap_mini_font_selection_set_font_desc (GucharmapMiniFontSelection *fontsel,
+ PangoFontDescription *font_desc);
-#endif /* #ifndef GUCHARMAP_MINI_FONTSEL_H */
+PangoFontDescription * gucharmap_mini_font_selection_get_font_desc (GucharmapMiniFontSelection *fontsel);
+
+void gucharmap_mini_font_selection_change_font_size (GucharmapMiniFontSelection *fontsel,
+ float factor);
+void gucharmap_mini_font_selection_reset_font_size (GucharmapMiniFontSelection *fontsel);
+
+G_END_DECLS
+
+#endif /* #ifndef GUCHARMAP_MINI_FONTSEL_H */
Modified: trunk/gucharmap/gucharmap-window.c
==============================================================================
--- trunk/gucharmap/gucharmap-window.c (original)
+++ trunk/gucharmap/gucharmap-window.c Mon Mar 31 12:44:01 2008
@@ -31,6 +31,8 @@
#include "gucharmap-settings.h"
#include "gucharmap-window.h"
+#define FONT_CHANGE_FACTOR (1.189207115f) /* 2^(0.25) */
+
/* #define ENABLE_PRINTING */
static void gucharmap_window_class_init (GucharmapWindowClass *klass);
@@ -360,22 +362,16 @@
font_bigger (GtkAction *action,
GucharmapWindow *guw)
{
- gint size, increment;
-
- size = gucharmap_mini_font_selection_get_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel));
- increment = MAX (size / 5, 1);
- gucharmap_mini_font_selection_set_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel), size + increment);
+ gucharmap_mini_font_selection_change_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel),
+ FONT_CHANGE_FACTOR);
}
static void
font_smaller (GtkAction *action,
GucharmapWindow *guw)
{
- gint size, increment;
-
- size = gucharmap_mini_font_selection_get_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel));
- increment = MAX (size / 5, 1);
- gucharmap_mini_font_selection_set_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel), size - increment);
+ gucharmap_mini_font_selection_change_font_size (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel),
+ 1.0f / FONT_CHANGE_FACTOR);
}
static void
@@ -703,18 +699,6 @@
"</menubar>";
static void
-fontsel_changed (GucharmapMiniFontSelection *fontsel,
- GucharmapWindow *guw)
-{
- gchar *font_name = gucharmap_mini_font_selection_get_font_name (fontsel);
-
- gucharmap_charmap_set_font (guw->charmap, font_name);
- gucharmap_settings_set_font (font_name);
-
- g_free (font_name);
-}
-
-static void
insert_character_in_text_to_copy (GucharmapChartable *chartable,
GucharmapWindow *guw)
{
@@ -775,6 +759,46 @@
}
static void
+fontsel_sync_font_desc (GucharmapMiniFontSelection *fontsel,
+ GParamSpec *pspec,
+ GucharmapWindow *guw)
+{
+ PangoFontDescription *font_desc;
+ char *font;
+
+ if (guw->in_notification)
+ return;
+
+ font_desc = gucharmap_mini_font_selection_get_font_desc (fontsel);
+
+ guw->in_notification = TRUE;
+ gucharmap_charmap_set_font_desc (guw->charmap, font_desc);
+ guw->in_notification = FALSE;
+
+ font = pango_font_description_to_string (font_desc);
+ gucharmap_settings_set_font (font);
+ g_free (font);
+}
+
+static void
+charmap_sync_font_desc (GucharmapCharmap *charmap,
+ GParamSpec *pspec,
+ GucharmapWindow *guw)
+{
+ PangoFontDescription *font_desc;
+
+ if (guw->in_notification)
+ return;
+
+ font_desc = gucharmap_charmap_get_font_desc (charmap);
+
+ guw->in_notification = TRUE;
+ gucharmap_mini_font_selection_set_font_desc (GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel),
+ font_desc);
+ guw->in_notification = FALSE;
+}
+
+static void
charmap_sync_active_character (GtkWidget *widget,
GParamSpec *pspec,
GucharmapWindow *guw)
@@ -910,7 +934,8 @@
/* The font selector */
guw->fontsel = gucharmap_mini_font_selection_new ();
- g_signal_connect (guw->fontsel, "changed", G_CALLBACK (fontsel_changed), guw);
+ g_signal_connect (guw->fontsel, "notify::font-desc",
+ G_CALLBACK (fontsel_sync_font_desc), guw);
gtk_box_pack_start (GTK_BOX (big_vbox), guw->fontsel, FALSE, FALSE, 0);
gtk_widget_show (GTK_WIDGET (guw->fontsel));
@@ -918,6 +943,8 @@
guw->charmap = GUCHARMAP_CHARMAP (gucharmap_charmap_new ());
g_signal_connect (guw->charmap, "notify::active-character",
G_CALLBACK (charmap_sync_active_character), guw);
+ g_signal_connect (guw->charmap, "notify::font-desc",
+ G_CALLBACK (charmap_sync_font_desc), guw);
gtk_box_pack_start (GTK_BOX (big_vbox), GTK_WIDGET (guw->charmap),
TRUE, TRUE, 0);
@@ -1020,11 +1047,19 @@
}
void
-gucharmap_window_set_font (GucharmapWindow *window)
-{
-}
-GucharmapMiniFontSelection *
-gucharmap_window_get_mini_font_selection (GucharmapWindow *guw)
+gucharmap_window_set_font (GucharmapWindow *guw,
+ const char *font)
{
- return GUCHARMAP_MINI_FONT_SELECTION (guw->fontsel);
+ PangoFontDescription *font_desc;
+
+ g_return_if_fail (GUCHARMAP_IS_WINDOW (guw));
+
+ g_assert (!GTK_WIDGET_REALIZED (guw));
+
+ if (!font)
+ return;
+
+ font_desc = pango_font_description_from_string (font);
+ gucharmap_charmap_set_font_desc (guw->charmap, font_desc);
+ pango_font_description_free (font_desc);
}
Modified: trunk/gucharmap/gucharmap-window.h
==============================================================================
--- trunk/gucharmap/gucharmap-window.h (original)
+++ trunk/gucharmap/gucharmap-window.h Mon Mar 31 12:44:01 2008
@@ -28,7 +28,7 @@
#define GUCHARMAP_TYPE_WINDOW (gucharmap_window_get_type ())
#define GUCHARMAP_WINDOW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GUCHARMAP_TYPE_WINDOW, GucharmapWindow))
-#define GUCHARMAP_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_WINDOW, GucharmapWindowClass))
+#define GUCHARMAP_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GUCHARMAP_TYPE_WINDOW, GucharmapWindowClass))
#define GUCHARMAP_IS_WINDOW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GUCHARMAP_TYPE_WINDOW))
#define GUCHARMAP_IS_WINDOW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GUCHARMAP_TYPE_WINDOW))
#define GUCHARMAP_WINDOW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GUCHARMAP_TYPE_WINDOW, GucharmapWindowClass))
@@ -58,6 +58,8 @@
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
+
+ guint in_notification : 1;
};
struct _GucharmapWindowClass
@@ -71,9 +73,8 @@
GtkWidget * gucharmap_window_new (void);
-void gucharmap_window_set_font (GucharmapWindow *window);
-
-GucharmapMiniFontSelection * gucharmap_window_get_mini_font_selection (GucharmapWindow *guw);
+void gucharmap_window_set_font (GucharmapWindow *guw,
+ const char *font);
GdkCursor *_gucharmap_window_progress_cursor (void);
Modified: trunk/gucharmap/main.c
==============================================================================
--- trunk/gucharmap/main.c (original)
+++ trunk/gucharmap/main.c Mon Mar 31 12:44:01 2008
@@ -1,5 +1,6 @@
/*
* Copyright  2004 Noah Levitt
+ * Copyright  2007, 2008 Christian Persch
*
* 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
@@ -34,15 +35,11 @@
GdkScreen *screen;
gint monitor;
GdkRectangle rect;
- GucharmapMiniFontSelection *fontsel;
- char *font_setting;
- char *font = NULL;
- PangoFontDescription *font_desc = NULL;
GError *error = NULL;
- char *font_arg = NULL;
+ char *font = NULL;
GOptionEntry goptions[] =
{
- { "font", 0, 0, G_OPTION_ARG_STRING, &font_arg,
+ { "font", 0, 0, G_OPTION_ARG_STRING, &font,
N_("Font to start with; ex: 'Serif 27'"), N_("FONT") },
{ NULL }
};
@@ -61,7 +58,7 @@
gucharmap_settings_initialize ();
- g_set_application_name (_("Gucharmap"));
+ g_set_application_name (_("Character Map"));
gtk_window_set_default_icon_name (GUCHARMAP_ICON_NAME);
window = gucharmap_window_new ();
@@ -73,44 +70,19 @@
gdk_screen_get_monitor_geometry (screen, monitor, &rect);
gtk_window_set_default_size (GTK_WINDOW (window), rect.width * 9/16, rect.height * 9/16);
- /* FIXMEchpe: move all this into gucharmap-window */
- fontsel = gucharmap_window_get_mini_font_selection (GUCHARMAP_WINDOW (window));
-
- font_desc = pango_font_description_copy (window->style->font_desc);
- pango_font_description_set_size (font_desc,
- 2.0 * pango_font_description_get_size (font_desc));
-
- font_setting = gucharmap_settings_get_font ();
- if (font_setting) {
- PangoFontDescription *font_setting_desc;
-
- font_setting_desc = pango_font_description_from_string (font_setting);
- pango_font_description_merge (font_desc, font_setting_desc, TRUE);
- pango_font_description_free (font_setting_desc);
- g_free (font_setting);
- }
-
- if (font_arg) {
- PangoFontDescription *font_argDesc = pango_font_description_from_string (font_arg);
- pango_font_description_merge (font_desc, font_argDesc, TRUE);
- pango_font_description_free (font_argDesc);
- g_free (font_arg);
- }
-
- /* FIXME: convert here from PangoFontDescription to char *, then in
- * gucharmap_mini_font_selection_set_font_name convert back to PangoFontDescription */
- font = pango_font_description_to_string (font_desc);
- gucharmap_mini_font_selection_set_font_name (fontsel, font);
- g_free (font);
-
- gucharmap_mini_font_selection_set_default_font_size (fontsel,
- PANGO_PIXELS (pango_font_description_get_size (font_desc)));
- pango_font_description_free (font_desc);
+ /* No --font argument, use the stored font (if any) */
+ if (!font)
+ font = gucharmap_settings_get_font ();
- gucharmap_mini_font_selection_reset_font_size (fontsel);
+ if (font)
+ {
+ gucharmap_window_set_font (GUCHARMAP_WINDOW (window), font);
+ g_free (font);
+ }
gucharmap_settings_add_window (GTK_WINDOW (window));
- gtk_widget_show (window);
+
+ gtk_window_present (GTK_WINDOW (window));
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]