2006-09-12 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-font-selection-dialog.c
index 00eb605..daa09a0 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * This file is part of hildon-libs
  *
- * Copyright (C) 2005 Nokia Corporation.
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
  *
- * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License or any later version.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 #define _(String) dgettext(PACKAGE, String)
 
 #define SUPERSCRIPT_RISE 3333
-#define SUBSCRIPT_LOW -3333
-#define ON_BIT 0x01
+#define SUBSCRIPT_LOW   -3333
+#define ON_BIT  0x01
 #define OFF_BIT 0x02
-#define REFERENCE_LINE "Reference: " /*localized string?*/
 
 /*
  * These are what we use as the standard font sizes, for the size list.
@@ -97,7 +96,8 @@ enum
   PROP_STRIKETHROUGH_SET,
   PROP_POSITION,
   PROP_POSITION_SET,
-  PROP_PREVIEW_TEXT
+  PROP_PREVIEW_TEXT,
+  PROP_FONT_SCALING
 };
 
 typedef struct
@@ -132,6 +132,11 @@ struct _HildonFontSelectionDialogPrivate
    * when we change the color setting*/
   
   gboolean color_set;
+
+  /* font_scaling is the scaling factor applied to font
+   * scale in the preview dialog */
+
+  gdouble font_scaling;
   gulong color_modified_signal_handler;
 };
 
@@ -291,7 +296,7 @@ hildon_font_selection_dialog_get_property (GObject      *object,
        g_value_set_string(value, 
                           pango_font_family_get_name(priv->families[i]));
       else
-       g_value_set_string(value, "Nokia Sans");
+       g_value_set_string(value, "Sans");
       break;
       
     case PROP_FAMILY_SET:
@@ -386,7 +391,11 @@ hildon_font_selection_dialog_get_property (GObject      *object,
       else
        g_value_set_int(value, 0);
       break;
-      
+    
+    case PROP_FONT_SCALING:
+       g_value_set_double(value, priv->font_scaling);
+      break;
+  
     case PROP_POSITION_SET:
       i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_positioning));
       if(i >= 0 && i < 3)
@@ -553,6 +562,10 @@ hildon_font_selection_dialog_set_property (GObject         *object,
       else
        gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 0);
       break;
+
+    case PROP_FONT_SCALING:
+      priv->font_scaling = g_value_get_double(value);
+      break;
       
     case PROP_POSITION_SET:
       b = g_value_get_boolean(value);
@@ -588,7 +601,7 @@ hildon_font_selection_dialog_class_init(HildonFontSelectionDialogClass *
   g_object_class_install_property(gobject_class, PROP_FAMILY,
                                  g_param_spec_string("family",
                                  "Font family", "String defines"
-                                 " the font family", "Nokia Sans",
+                                 " the font family", "Sans",
                                  G_PARAM_READWRITE));
   
   g_object_class_install_property(gobject_class, PROP_FAMILY_SET,
@@ -688,6 +701,16 @@ hildon_font_selection_dialog_class_init(HildonFontSelectionDialogClass *
                                   "Font position super or subscript",
                                   -1, 1, 0,
                                   G_PARAM_READWRITE));
+
+  /* FIXME This was introduced in 0.14.1. We don't have documentation for 
+   * properties anyways, but once it's there it needs to be marked as 
+   * Since: 0.14.1 */
+  g_object_class_install_property(gobject_class, PROP_FONT_SCALING,
+                                  g_param_spec_double ("font-scaling",
+                                  "Font scaling",
+                                  "Font scaling for the preview dialog",
+                                  0, 10, 1,
+                                  G_PARAM_READWRITE));
   
   g_object_class_install_property(gobject_class, PROP_POSITION_SET,
                                  g_param_spec_boolean ("position-set",
@@ -794,6 +817,7 @@ hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog
   font_color_box = gtk_hbox_new(FALSE, 0);
   priv->font_color_button = hildon_color_button_new();
   priv->color_set = FALSE;
+  priv->font_scaling = 1.0;
   priv->color_modified_signal_handler = 
     g_signal_connect(G_OBJECT(priv->font_color_button), "notify::color",
                     G_CALLBACK(color_modified_cb), (gpointer) priv);
@@ -954,6 +978,7 @@ hildon_font_selection_dialog_create_attrlist(HildonFontSelectionDialog *
           strikethrough, strikethrough_set, position_set;
   GdkColor *color = NULL;
   gchar *family = NULL;
+  gdouble font_scaling = 1.0;
 
   list = pango_attr_list_new();
  
@@ -966,7 +991,9 @@ hildon_font_selection_dialog_create_attrlist(HildonFontSelectionDialog *
               "underline", &underline, "underline-set", &underline_set,
               "strikethrough", &strikethrough, "strikethrough-set", 
               &strikethrough_set, "position", &position, 
-              "position-set", &position_set, NULL);
+              "position-set", &position_set, 
+               "font-scaling", &font_scaling,
+               NULL);
 
   /*family*/
   if(family_set)
@@ -1055,7 +1082,14 @@ hildon_font_selection_dialog_create_attrlist(HildonFontSelectionDialog *
 
       add_preview_text_attr(list, attr, start_index, len);
     }
-  
+
+  /*font scaling for preview*/
+  if(font_scaling)
+    {
+      attr = pango_attr_scale_new(font_scaling);
+      add_preview_text_attr(list, attr, 0, len + start_index);
+    }
+   
   return list;
 }
 
@@ -1083,7 +1117,8 @@ hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
                                GTK_RESPONSE_ACCEPT,
                                NULL);
 
-  str = g_strconcat(REFERENCE_LINE, priv->preview_text, 0);
+  str = g_strconcat(_("ecdg_fi_preview_font_preview_reference"),
+                    priv->preview_text, 0);
 
   preview_label = gtk_label_new(str);
   gtk_label_set_line_wrap(GTK_LABEL(preview_label), TRUE);
@@ -1103,7 +1138,7 @@ hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
   
   /*Set the font*/
   list = hildon_font_selection_dialog_create_attrlist(fontsel, 
-                               strlen(REFERENCE_LINE),
+                               strlen(_("ecdg_fi_preview_font_preview_reference")),
                                strlen(priv->preview_text));
 
   g_object_get(G_OBJECT(fontsel), "family", &str, "family-set",
@@ -1113,7 +1148,7 @@ hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
   if(family_set)
     {
       attr = pango_attr_family_new(str);
-      add_preview_text_attr(list, attr, 0, strlen(REFERENCE_LINE));
+      add_preview_text_attr(list, attr, 0, strlen(_("ecdg_fi_preview_font_preview_reference")));
     }
   g_free(str);
   
@@ -1121,7 +1156,7 @@ hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
   if(size_set)
     {
       attr = pango_attr_size_new(size * PANGO_SCALE);
-      add_preview_text_attr(list, attr, 0, strlen(REFERENCE_LINE));
+      add_preview_text_attr(list, attr, 0, strlen(_("ecdg_fi_preview_font_preview_reference")));
     }
   
   gtk_label_set_attributes(GTK_LABEL(preview_label), list);
@@ -1135,6 +1170,40 @@ hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
   gtk_widget_destroy(preview_dialog);
 }
 
+
+static gboolean is_internal_font(const gchar * name){
+  return strcmp(name, "DeviceSymbols") == 0
+      || strcmp(name, "Nokia Smiley" ) == 0
+      || strcmp(name, "NewCourier" ) == 0
+      || strcmp(name, "NewTimes" ) == 0
+      || strcmp(name, "SwissA" ) == 0
+      || strcmp(name, "Nokia Sans"   ) == 0
+      || strcmp(name, "Nokia Sans Cn") == 0;
+}
+
+static void filter_out_internal_fonts(PangoFontFamily **families, int *n_families){
+  int i;
+  int n; /* counts valid fonts */
+  const gchar * name = NULL;
+
+  for(i = 0, n = 0; i < *n_families; i++){
+
+    name = pango_font_family_get_name(families[i]);
+        
+    if(!is_internal_font(name)){
+
+      if(i!=n){ /* there are filtered out families */
+       families[n] = families[i]; /* shift the current family */
+      }
+
+      n++; /* count one more valid */
+    }
+  }/* foreach font family */
+
+  *n_families = n;  
+}
+
+
 static void
 hildon_font_selection_dialog_show_available_fonts(HildonFontSelectionDialog 
                                                  *fontsel)
@@ -1149,6 +1218,8 @@ hildon_font_selection_dialog_show_available_fonts(HildonFontSelectionDialog
                              (GTK_WIDGET(fontsel)), &priv->families,
                              &priv->n_families);
 
+  filter_out_internal_fonts(priv->families, &priv->n_families);
+
   qsort(priv->families, priv->n_families, sizeof(PangoFontFamily *),
        cmp_families);