[Goodies-commits] r7440 - in xfce4-dict/trunk: . lib

Enrico Troeger enrico at xfce.org
Fri May 29 18:41:10 CEST 2009


Author: enrico
Date: 2009-05-29 16:41:10 +0000 (Fri, 29 May 2009)
New Revision: 7440

Modified:
   xfce4-dict/trunk/ChangeLog
   xfce4-dict/trunk/lib/common.c
   xfce4-dict/trunk/lib/common.h
   xfce4-dict/trunk/lib/speedreader.c
Log:
Don't treat quotes as word separators.
Add an option to mark paragraphs when Speed Reading.

Modified: xfce4-dict/trunk/ChangeLog
===================================================================
--- xfce4-dict/trunk/ChangeLog	2009-05-29 16:02:19 UTC (rev 7439)
+++ xfce4-dict/trunk/ChangeLog	2009-05-29 16:41:10 UTC (rev 7440)
@@ -1,3 +1,10 @@
+2009-05-29  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * lib/common.c, lib/common.h, lib/speedreader.c:
+   Don't treat quotes as word separators.
+   Add an option to mark paragraphs when Speed Reading.
+
+
 2009-05-18  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * lib/common.c, lib/common.h, lib/dictd.c, lib/gui.c:

Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c	2009-05-29 16:02:19 UTC (rev 7439)
+++ xfce4-dict/trunk/lib/common.c	2009-05-29 16:41:10 UTC (rev 7440)
@@ -379,6 +379,7 @@
 	gint port = 2628;
 	gint panel_entry_size = 150;
 	gint wpm = 400;
+	gboolean mark_paragraphs = FALSE;
 	gboolean show_panel_entry = FALSE;
 	gchar *spell_bin_default = get_spell_program();
 	gchar *spell_dictionary_default = get_default_lang();
@@ -414,6 +415,7 @@
 
 		speedreader_font = xfce_rc_read_entry(rc, "speedreader_font", speedreader_font);
 		wpm = xfce_rc_read_int_entry(rc, "speedreader_wpm", wpm);
+		mark_paragraphs = xfce_rc_read_bool_entry(rc, "speedreader_mark_paragraphs", mark_paragraphs);
 
 		geo = xfce_rc_read_entry(rc, "geometry", geo);
 		parse_geometry(dd, geo);
@@ -455,6 +457,7 @@
 	dd->color_correct = g_new0(GdkColor, 1);
 	gdk_color_parse(success_color_str, dd->color_correct);
 
+	dd->speedreader_mark_paragraphs = mark_paragraphs;
 	dd->speedreader_wpm = wpm;
 	dd->speedreader_font = g_strdup(speedreader_font);
 
@@ -498,6 +501,7 @@
 
 		xfce_rc_write_entry(rc, "speedreader_font", dd->speedreader_font);
 		xfce_rc_write_int_entry(rc, "speedreader_wpm", dd->speedreader_wpm);
+		xfce_rc_write_bool_entry(rc, "speedreader_mark_paragraphs", dd->speedreader_mark_paragraphs);
 
 		g_free(link_color_str);
 		g_free(phon_color_str);

Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h	2009-05-29 16:02:19 UTC (rev 7439)
+++ xfce4-dict/trunk/lib/common.h	2009-05-29 16:41:10 UTC (rev 7440)
@@ -118,6 +118,7 @@
 	/* speed reader */
 	gint speedreader_wpm;
 	gchar *speedreader_font;
+	gboolean speedreader_mark_paragraphs;
 } DictData;
 
 

Modified: xfce4-dict/trunk/lib/speedreader.c
===================================================================
--- xfce4-dict/trunk/lib/speedreader.c	2009-05-29 16:02:19 UTC (rev 7439)
+++ xfce4-dict/trunk/lib/speedreader.c	2009-05-29 16:41:10 UTC (rev 7440)
@@ -44,6 +44,7 @@
 
 	GtkWidget *spin_wpm;
 	GtkWidget *button_font;
+	GtkWidget *check_mark_paragraphs;
 	GtkWidget *display_label;
 	GtkTextBuffer *buffer;
 
@@ -150,12 +151,15 @@
 }
 
 
-static gchar *sr_replace_unicode_charatcers(const gchar *text)
+static gchar *sr_replace_unicode_characters(const gchar *text, gboolean mark_paragraphs)
 {
 	GString *str;
 	gchar *result;
-	gunichar c;
+	gunichar c = 0, last_c, x;
+	gboolean last_line_was_empty = FALSE;
 
+	g_return_val_if_fail(text != NULL, NULL);
+
 	if (! g_utf8_validate(text, -1, NULL))
 		return g_strdup(text);
 
@@ -163,6 +167,7 @@
 
 	while (*text)
 	{
+		last_c = c;
 		c = g_utf8_get_char(text);
 
 		switch (g_unichar_type(c))
@@ -174,9 +179,45 @@
 				g_string_append_c(str, ' ');
 				break;
 			case G_UNICODE_PARAGRAPH_SEPARATOR:
+				if (mark_paragraphs)
+					g_string_append_unichar(str, 182); /* 182 = ¶ */
+				/* intended fall-through */
 			case G_UNICODE_LINE_SEPARATOR:
 				g_string_append_c(str, '\n');
 				break;
+			case G_UNICODE_CONTROL:
+			{
+				/* if not \n or \r, add it literally */
+				if (! mark_paragraphs || strchr("\n\r", c) == NULL)
+				{
+					g_string_append_unichar(str, c);
+				}
+				else /* add pilcrows for paragraphs */
+				{
+					if ((last_c == '\r' && c == '\n') || /* CRLF */
+						(last_c == '\r' && c != '\n') || /* CR */
+						(last_c != '\r' && c == '\n'))   /* LF */
+					{
+						if (c == '\n')
+							/* skip to the next character */
+							x = g_utf8_get_char(g_utf8_next_char(text));
+						else
+							x = c;
+
+						if (strchr("\r\n", x))
+						{
+							last_line_was_empty = TRUE;
+						}
+						else if (last_line_was_empty)
+						{
+							last_line_was_empty = FALSE;
+							g_string_append(str, "¶\n");
+						}
+					}
+					g_string_append_unichar(str, c);
+				}
+				break;
+			}
 			default:
 				g_string_append_unichar(str, c);
 		}
@@ -239,6 +280,10 @@
 		return;
 	}
 
+	/* mark paragraphs? */
+	priv->dd->speedreader_mark_paragraphs = gtk_toggle_button_get_active(
+		GTK_TOGGLE_BUTTON(priv->check_mark_paragraphs));
+
 	/* set the font */
 	fontname = gtk_font_button_get_font_name(GTK_FONT_BUTTON(priv->button_font));
 	pfd = pango_font_description_from_string(fontname);
@@ -256,8 +301,9 @@
 
 	/* prepare word list and start the timer */
 	priv->word_idx = 0;
-	cleaned_text = sr_replace_unicode_charatcers(text); /* replace Unicode dashes and spaces */
-	priv->words = sr_strsplit_set(cleaned_text, " -_=\"\t\n\r");
+	/* replace Unicode dashes and spaces and mark paragraphs */
+	cleaned_text = sr_replace_unicode_characters(text, priv->dd->speedreader_mark_paragraphs);
+	priv->words = sr_strsplit_set(cleaned_text, " -_=\t\n\r");
 	priv->words_len = g_strv_length(priv->words);
 
 	priv->timer_id = g_timeout_add(interval, sr_timer, dialog);
@@ -386,9 +432,12 @@
 	priv->spin_wpm = gtk_spin_button_new_with_range(5.0, 10000.0, 5);
 	gtk_label_set_mnemonic_widget(GTK_LABEL(label_words), priv->spin_wpm);
 
+	priv->check_mark_paragraphs = gtk_check_button_new_with_mnemonic(_("_Mark Paragraphs"));
+
 	hbox_words = gtk_hbox_new(FALSE, 0);
 	gtk_box_pack_start(GTK_BOX(hbox_words), label_words, FALSE, FALSE, 6);
 	gtk_box_pack_start(GTK_BOX(hbox_words), priv->spin_wpm, FALSE, FALSE, 6);
+	gtk_box_pack_start(GTK_BOX(hbox_words), priv->check_mark_paragraphs, FALSE, FALSE, 12);
 
 	label_font = gtk_label_new_with_mnemonic(_("_Font Size:"));
 	gtk_misc_set_alignment(GTK_MISC(label_font), 1, 0.5);
@@ -488,6 +537,8 @@
 
 	gtk_spin_button_set_value(GTK_SPIN_BUTTON(priv->spin_wpm), dd->speedreader_wpm);
 	gtk_font_button_set_font_name(GTK_FONT_BUTTON(priv->button_font), dd->speedreader_font);
+	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->check_mark_paragraphs),
+		dd->speedreader_mark_paragraphs);
 
 	priv->dd = dd;
 




More information about the Goodies-commits mailing list