[goffice] Font Selector Dialog: implement more of the file chooser interface.



commit 2a18a7453bd048cf62528a43bda902f6486f9991
Author: Morten Welinder <terra gnome org>
Date:   Thu Mar 14 14:50:37 2013 -0400

    Font Selector Dialog: implement more of the file chooser interface.

 ChangeLog                        |    3 ++
 goffice/gtk/go-font-sel-dialog.c |   25 ++++++++++++++++++++--
 goffice/gtk/go-font-sel.c        |   41 +++++++++++++++++++++++++++----------
 goffice/gtk/go-font-sel.h        |    1 +
 4 files changed, 56 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1018a6f..1cac825 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-03-14  Morten Welinder  <terra gnome org>
 
+       * goffice/gtk/go-font-sel-dialog.c (gfsd_get_property)
+       (gfsd_set_property): Partially implement.
+
        * goffice/gtk/go-font-sel.c (gfs_class_init): Default show-style
        to FALSE.
        (go_font_sel_set_style): Make this public and use pango type args.
diff --git a/goffice/gtk/go-font-sel-dialog.c b/goffice/gtk/go-font-sel-dialog.c
index f218b09..05a5013 100644
--- a/goffice/gtk/go-font-sel-dialog.c
+++ b/goffice/gtk/go-font-sel-dialog.c
@@ -56,16 +56,26 @@ gfsd_set_property (GObject         *object,
        GOFontSelDialog *gfsd = GO_FONT_SEL_DIALOG (object);
 
        switch (prop_id) {
-       case GFSD_GTK_FONT_CHOOSER_PROP_FONT:
+       case GFSD_GTK_FONT_CHOOSER_PROP_FONT: {
+               PangoFontDescription *desc = pango_font_description_from_string
+                       (g_value_get_string (value));
+               go_font_sel_set_font_desc (gfsd->gfs, desc);
+               pango_font_description_free (desc);
                break;
+       }
+
        case GFSD_GTK_FONT_CHOOSER_PROP_FONT_DESC:
+               go_font_sel_set_font_desc (gfsd->gfs,
+                                          g_value_get_boxed (value));
                break;
 
        case GFSD_GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
                go_font_sel_set_sample_text (gfsd->gfs,
                                             g_value_get_string (value));
                break;
+
        case GFSD_GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
+               /* Not implemented */
                break;
 
        default:
@@ -83,17 +93,26 @@ gfsd_get_property (GObject         *object,
        GOFontSelDialog *gfsd = GO_FONT_SEL_DIALOG (object);
 
        switch (prop_id) {
-       case GFSD_GTK_FONT_CHOOSER_PROP_FONT:
+       case GFSD_GTK_FONT_CHOOSER_PROP_FONT: {
+               PangoFontDescription *desc =
+                       go_font_sel_get_font_desc (gfsd->gfs);
+               g_value_take_string (value, pango_font_description_to_string (desc));
+               pango_font_description_free (desc);
                break;
+       }
 
        case GFSD_GTK_FONT_CHOOSER_PROP_FONT_DESC:
+               g_value_take_boxed (value, go_font_sel_get_font_desc (gfsd->gfs));
                break;
 
        case GFSD_GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT:
-
+               /* Not implemented */
+               g_value_set_string (value, "");
                break;
 
        case GFSD_GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
+               /* Not implemented */
+               g_value_set_boolean (value, TRUE);
                break;
 
        default:
diff --git a/goffice/gtk/go-font-sel.c b/goffice/gtk/go-font-sel.c
index 85c4173..d2d617c 100644
--- a/goffice/gtk/go-font-sel.c
+++ b/goffice/gtk/go-font-sel.c
@@ -631,7 +631,8 @@ go_font_sel_set_style (GOFontSel *fs, PangoWeight weight, PangoStyle style)
                        n = 0;
        }
 
-       select_row (fs->font_style_list, n);
+       if (fs->font_style_list)
+               select_row (fs->font_style_list, n);
 
        go_font_sel_add_attr (fs, pango_attr_weight_new (weight));
        go_font_sel_add_attr (fs, pango_attr_style_new (style));
@@ -673,18 +674,36 @@ go_font_sel_set_color (GOFontSel *gfs, GOColor c)
 }
 
 void
-go_font_sel_set_font (GOFontSel *gfs, GOFont const *font)
+go_font_sel_set_font_desc (GOFontSel *fs, PangoFontDescription *desc)
 {
-       g_return_if_fail (GO_IS_FONT_SEL (gfs));
+       PangoFontMask fields;
+       g_return_if_fail (GO_IS_FONT_SEL (fs));
+
+       fields = pango_font_description_get_set_fields (desc);
+
+       if (fields & PANGO_FONT_MASK_FAMILY)
+               go_font_sel_set_family (fs,
+                                       pango_font_description_get_family (desc));
+       if (fields & (PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STYLE))
+               go_font_sel_set_style (fs,
+                                      pango_font_description_get_weight (desc),
+                                      pango_font_description_get_style (desc));
+
+       if (fields & PANGO_FONT_MASK_SIZE)
+               go_font_sel_set_size (fs,
+                                     pango_font_description_get_size (desc));
+}
+
+
+void
+go_font_sel_set_font (GOFontSel *fs, GOFont const *font)
+{
+       g_return_if_fail (GO_IS_FONT_SEL (fs));
 
-       go_font_sel_set_family (gfs, pango_font_description_get_family (font->desc));
-       go_font_sel_set_style (gfs,
-                              pango_font_description_get_weight (font->desc),
-                              pango_font_description_get_style (font->desc));
-       go_font_sel_set_size (gfs, pango_font_description_get_size (font->desc));
-       go_font_sel_set_strike (gfs, font->strikethrough);
-       go_font_sel_set_uline (gfs, font->underline);
-       go_font_sel_set_color (gfs, font->color);
+       go_font_sel_set_font_desc (fs, font->desc);
+       go_font_sel_set_strike (fs, font->strikethrough);
+       go_font_sel_set_uline (fs, font->underline);
+       go_font_sel_set_color (fs, font->color);
 }
 
 
diff --git a/goffice/gtk/go-font-sel.h b/goffice/gtk/go-font-sel.h
index 9c65423..d53446f 100644
--- a/goffice/gtk/go-font-sel.h
+++ b/goffice/gtk/go-font-sel.h
@@ -45,6 +45,7 @@ void go_font_sel_set_size          (GOFontSel *fs, int size);
 void go_font_sel_set_style         (GOFontSel *fs,
                                    PangoWeight weight, PangoStyle style);
 
+void go_font_sel_set_font_desc     (GOFontSel *fs, PangoFontDescription *desc);
 PangoFontDescription *go_font_sel_get_font_desc (GOFontSel *fs);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]