2006-08-30 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / hildon-widgets / hildon-font-selection-dialog.c
index 2297365..7c44660 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * This file is part of hildon-libs
  *
- * Copyright (C) 2005 Nokia Corporation.
+ * Copyright (C) 2005, 2006 Nokia Corporation.
  *
- * 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.
  *
  * This library is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
  *
  */
 
+/**
+ * SECTION:hildon-font-selection-dialog
+ * @short_description: A widget used to allow users to select a font 
+ * with certain properties
+ *
+ * Font selection can be made using this widget. Users can select font name, 
+ * size, style, etc. Users can also preview text in the selected font.
+ */
 #include <stdlib.h>
 #include <string.h>
 
 #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.
@@ -282,7 +290,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:
@@ -579,7 +587,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,
@@ -792,7 +800,7 @@ hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog
                     priv->font_color_button, FALSE, FALSE, 0);
   
   caption_control =
-    hildon_caption_new(group, _("ecdg_fi_font_color_selector"),
+    hildon_caption_new(group, _("ecdg_fi_font_colour_selector"),
                       font_color_box,
                       NULL, HILDON_CAPTION_OPTIONAL);
   
@@ -1074,7 +1082,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);
@@ -1094,7 +1103,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",
@@ -1104,7 +1113,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);
   
@@ -1112,7 +1121,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);
@@ -1126,6 +1135,37 @@ 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, "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)
@@ -1140,6 +1180,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);
 
@@ -1574,13 +1616,13 @@ toggle_clicked(GtkButton *button, gpointer unused)
 
 /**
  * hildon_font_selection_dialog_new:
- * @parent: the parent window.
- * @title: the title of font selection dialog.
+ * @parent: the parent window
+ * @title: the title of font selection dialog
  *
  * If NULL is passed for title, then default title
  * "Font" will be used.
  *
- * Return value: a new #HildonFontSelectionDialog.
+ * Returns: a new #HildonFontSelectionDialog
  */
 GtkWidget *
 hildon_font_selection_dialog_new(GtkWindow * parent,
@@ -1602,12 +1644,12 @@ hildon_font_selection_dialog_new(GtkWindow * parent,
 
 /**
  * hildon_font_selection_dialog_get_preview_text:
- * @fsd: the font selection dialog.
+ * @fsd: the font selection dialog
  *
  * Gets the text in preview dialog, which does not include the 
  * reference text. The returned string must be freed by the user.
  *
- * Returns: a string pointer.
+ * Returns: a string pointer
  */
 gchar *
 hildon_font_selection_dialog_get_preview_text(HildonFontSelectionDialog * fsd)
@@ -1621,8 +1663,8 @@ hildon_font_selection_dialog_get_preview_text(HildonFontSelectionDialog * fsd)
 
 /**
  * hildon_font_selection_dialog_set_preview_text:
- * @fsd: the font selection dialog.
- * @text: the text to be set to the preview dialog.
+ * @fsd: the font selection dialog
+ * @text: the text to be displayed in the preview dialog
  *
  * The default preview text is
  * "The quick brown fox jumped over the lazy dogs"
@@ -1645,17 +1687,17 @@ hildon_font_selection_dialog_set_preview_text(HildonFontSelectionDialog *
 
 /**
  * hildon_font_selection_dialog_get_text_tag:
- * @fsd: the font selection dialog.
+ * @fsd: the font selection dialog
  *
  * Get the #GtkTextTag for selections. This function
- * is deprecated function. The best way to use
+ * is deprecated. The best way to use
  * the text tags is to reuse them as much as possible.
- * The recommended way is to get the properties of font
- * selection dialog on GTK_RESPONSE_OK, according to
- * these property use the tags that you have pre-created.
+ * The recommended way is to get the properties of the font
+ * selection dialog on GTK_RESPONSE_OK, and according to
+ * these properties use the tags that you have pre-created.
  * 
  * Returns: a #GtkTextTag having corresponding properties
- * set. 
+ * set 
  */ 
 GtkTextTag * 
 hildon_font_selection_dialog_get_text_tag (HildonFontSelectionDialog *fsd)
@@ -1783,15 +1825,14 @@ hildon_font_selection_dialog_get_text_tag (HildonFontSelectionDialog *fsd)
 
 /** 
  * hildon_font_selection_dialog_set_buffer:
- * @fsd: the font selection dialog.
+ * @fsd: the font selection dialog
  * @buffer: a #GtkTextBuffer containing the text to which the selections will 
  * be applied. Applying is responsibility of application.
  *
- * This is deprecated function. GtkTextBuffer is not enough
+ * This is deprecated. GtkTextBuffer is not enough
  * to get the attributes of currently selected text. Please 
  * inspect the attributes yourself, and set the properties of
  * font selection dialog to reflect your inspection.
- * 
  */
 void 
 hildon_font_selection_dialog_set_buffer (HildonFontSelectionDialog *fsd,
@@ -1835,12 +1876,12 @@ hildon_font_selection_dialog_set_buffer (HildonFontSelectionDialog *fsd,
 
 /**
  * hildon_font_selection_dialog_get_font:
- * @fsd: the font selection dialog.
+ * @fsd: the font selection dialog
  *
- * This is a deprecated function, @PangoAttrList needs
+ * This is deprecated. @PangoAttrList needs
  * starting index, and end index on construction.
  *
- * Return value: pointer to @PangoAttrList.
+ * Returns: pointer to @PangoAttrList
  */
 PangoAttrList
 *hildon_font_selection_dialog_get_font(HildonFontSelectionDialog * fsd)
@@ -1859,10 +1900,10 @@ PangoAttrList
 
 /**
  * hildon_font_selection_dialog_set_font:
- * @fsd: the font selection dialog.
- * @list: the pango attribute list.
+ * @fsd: the font selection dialog
+ * @list: the pango attribute list
  *
- * This is a deprecated function.
+ * This is a deprecated.
  * 
  * Sets the font to the dialog.
  */