X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=applet%2Fcpmpsubtitles.c;h=63c9a0b7f9478bf8f60178836c4bb6f75b61dde8;hb=bfc1a094d396a089fff7c7a84183950c307fe99c;hp=73b23445e908cdec7643e15522da15d09bc99515;hpb=367849efa721dea7855be32ca07463a27ed35588;p=mafwsubrenderer diff --git a/applet/cpmpsubtitles.c b/applet/cpmpsubtitles.c index 73b2344..63c9a0b 100644 --- a/applet/cpmpsubtitles.c +++ b/applet/cpmpsubtitles.c @@ -2,8 +2,11 @@ * Subtitles control panel applet. * Copyright (C) 2010 Roman Moravcik * - * encodings structure imported from totem-subtitle-encoding.c - * Copyright (C) 2001-2006 Bastien Nocera + * encodings structure imported from totem-subtitle-encoding.c + * Copyright (C) 2001-2006 Bastien Nocera + * + * font family detection imported from hildon-font-selection-dialog.c + * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved. * * 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 @@ -24,6 +27,8 @@ #include #endif +#include + #include #include @@ -33,11 +38,37 @@ #include -#define GCONF_MAFW_GST_SUBTITLE_RENDERER "/system/mafw/mafw-gst-renderer" +#define GCONF_MAFW_GST_SUBTITLE_RENDERER "/system/mafw/mafw-gst-subtitles-renderer" #define _HL(str) dgettext("hildon-libs",str) typedef enum { + FONT_STYLE_REGULAR, + FONT_STYLE_ITALIC, + FONT_STYLE_BOLD, + FONT_STYLE_ITALIC_BOLD, + FONT_STYLE_LAST, +} FontStyleIndex; + +typedef struct { + int index; + const char *name; +} FontStyle; + +static FontStyle font_styles[] = { + {FONT_STYLE_REGULAR, N_("Regular")}, + {FONT_STYLE_ITALIC, N_("Italic")}, + {FONT_STYLE_BOLD, N_("Bold")}, + {FONT_STYLE_ITALIC_BOLD, N_("Italic Bold")} +}; + +static const gint font_sizes[] = +{ + 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, -1 +}; + +typedef enum +{ SUBTITLE_ENCODING_CURRENT_LOCALE, SUBTITLE_ENCODING_ISO_8859_6, @@ -146,14 +177,12 @@ typedef enum SUBTITLE_ENCODING_LAST } SubtitleEncodingIndex; - typedef struct { int index; const char *charset; const char *name; } SubtitleEncoding; - static SubtitleEncoding encodings[] = { {SUBTITLE_ENCODING_CURRENT_LOCALE, NULL, N_("Current Locale")}, @@ -328,28 +357,201 @@ gconf_set_string (GConfClient *client, g_free (tmp); } +static gboolean +is_internal_font (const gchar * name) +{ + /* FIXME Extremally BAD BAD BAD way of doing things */ + + 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 int +cmp_families (const void *a, + const void *b) +{ + const char *a_name = pango_font_family_get_name (* (PangoFontFamily **) a); + const char *b_name = pango_font_family_get_name (* (PangoFontFamily **) b); + + return g_utf8_collate (a_name, b_name); +} + static void font_selector_dialog (HildonButton *button, gpointer user_data) { - GtkWidget *dialog, *hbox; + GtkWidget *dialog, *hbox, *family_selector, *style_selector, *size_selector; + gint index = 0; + const gchar *font = NULL; + PangoFontDescription *font_desc = NULL; + PangoFontFamily **families; + gint n_families = 0; + PangoWeight pango_weight; + PangoStyle pango_style; + + font = hildon_button_get_value (HILDON_BUTTON (button)); + if (font == NULL) + return; + + font_desc = pango_font_description_from_string (font); dialog = gtk_dialog_new (); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_window_set_title (GTK_WINDOW (dialog), _("Font")); gtk_dialog_add_button(GTK_DIALOG (dialog), "OK", GTK_RESPONSE_ACCEPT); + gtk_window_set_default_size (GTK_WINDOW (dialog), -1, 400); hbox = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox); - // pango_font_description_from_string + /* font family selector */ + family_selector = hildon_touch_selector_new_text (); + gtk_box_pack_start (GTK_BOX (hbox), family_selector, TRUE, TRUE, 0); + + pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (dialog)), + &families, &n_families); + + filter_out_internal_fonts (families, &n_families); + + qsort (families, n_families, sizeof(PangoFontFamily *), cmp_families); + + for (index = 0; index < n_families; index++) { + const gchar *family = pango_font_family_get_name (families[index]); + hildon_touch_selector_insert_text (HILDON_TOUCH_SELECTOR (family_selector), + index, family); + + if (strcmp (family, pango_font_description_get_family (font_desc)) == 0) { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (family_selector), 0, + index); + hildon_touch_selector_center_on_selected (HILDON_TOUCH_SELECTOR (family_selector)); + } + } + g_free (families); + + /* font style selector */ + style_selector = hildon_touch_selector_new_text (); + gtk_box_pack_start (GTK_BOX (hbox), style_selector, TRUE, TRUE, 0); + + index = 0; + while (index < FONT_STYLE_LAST) { + const gchar *style = g_strdup_printf ("%s", _(font_styles[index].name)); + hildon_touch_selector_insert_text (HILDON_TOUCH_SELECTOR (style_selector), + font_styles[index].index, style); + index++; + } + pango_weight = pango_font_description_get_weight (font_desc); + pango_style = pango_font_description_get_style (font_desc); + + if (pango_weight == PANGO_WEIGHT_NORMAL) { + if (pango_style == PANGO_STYLE_NORMAL) { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (style_selector), 0, + FONT_STYLE_REGULAR); + } else { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (style_selector), 0, + FONT_STYLE_ITALIC); + } + } else { + if (pango_style == PANGO_STYLE_NORMAL) { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (style_selector), 0, + FONT_STYLE_BOLD); + } else { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (style_selector), 0, + FONT_STYLE_ITALIC_BOLD); + } + } + hildon_touch_selector_center_on_selected (HILDON_TOUCH_SELECTOR (style_selector)); + + /* font size selector */ + size_selector = hildon_touch_selector_new_text (); + gtk_box_pack_start (GTK_BOX (hbox), size_selector, TRUE, TRUE, 0); + + index = 0; + while (font_sizes[index] != -1) { + const gchar *size = g_strdup_printf ("%d", font_sizes[index]); + hildon_touch_selector_insert_text (HILDON_TOUCH_SELECTOR (size_selector), + index, size); + + if (font_sizes[index] == (pango_font_description_get_size (font_desc) / PANGO_SCALE)) { + hildon_touch_selector_set_active (HILDON_TOUCH_SELECTOR (size_selector), 0, + index); + hildon_touch_selector_center_on_selected (HILDON_TOUCH_SELECTOR (size_selector)); + } + + index++; + } /* Run the dialog */ gtk_widget_show_all (GTK_WIDGET (dialog)); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - // pango_font_description_to_string + if (font_desc) + pango_font_description_free (font_desc); + + font_desc = pango_font_description_new (); + + /* set font family */ + pango_font_description_set_family (font_desc, + hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (family_selector))); + + /* set font style */ + switch (hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (style_selector), 0)) { + case FONT_STYLE_REGULAR: + pango_font_description_set_style (font_desc, PANGO_STYLE_NORMAL); + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL); + break; + + case FONT_STYLE_ITALIC: + pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC); + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL); + break; + + case FONT_STYLE_BOLD: + pango_font_description_set_style (font_desc, PANGO_STYLE_NORMAL); + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + break; + + case FONT_STYLE_ITALIC_BOLD: + pango_font_description_set_style (font_desc, PANGO_STYLE_ITALIC); + pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); + break; + } + + /* set font size */ + pango_font_description_set_size (font_desc, + font_sizes[hildon_touch_selector_get_active (HILDON_TOUCH_SELECTOR (size_selector), 0)] * PANGO_SCALE); + + hildon_button_set_value (HILDON_BUTTON (button), pango_font_description_to_string (font_desc)); } + if (font_desc) + pango_font_description_free (font_desc); + gtk_widget_destroy(GTK_WIDGET(dialog)); } @@ -363,7 +565,7 @@ create_encoding_selector (void) selector = hildon_touch_selector_new_text (); while (index < SUBTITLE_ENCODING_LAST) { - gchar *encoding = NULL; + const gchar *encoding = NULL; if (encodings[index].charset) { encoding = g_strdup_printf ("%s (%s)", _(encodings[index].name), @@ -375,8 +577,6 @@ create_encoding_selector (void) hildon_touch_selector_insert_text (HILDON_TOUCH_SELECTOR (selector), encodings[index].index, encoding); - if (encoding) - g_free (encoding); index++; } @@ -423,8 +623,7 @@ create_subtitles_font_button (GConfClient *gconf_client) hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0); hildon_button_set_title_alignment (HILDON_BUTTON(button), 0.0, 0.5); hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5); - - g_signal_connect (button, "clicked", G_CALLBACK (font_selector_dialog), NULL); + hildon_button_set_style (HILDON_BUTTON (button), HILDON_BUTTON_STYLE_PICKER); font = gconf_get_string (gconf_client, "subtitle_font"); if (font) { @@ -432,6 +631,10 @@ create_subtitles_font_button (GConfClient *gconf_client) } else { hildon_button_set_value (HILDON_BUTTON (button), "Sans Bold 18"); } + + g_signal_connect (button, "clicked", G_CALLBACK (font_selector_dialog), + NULL); + return button; }