Skip to content

Commit 0cd45c6

Browse files
committed
added hyphen functionality
1 parent 28d18b1 commit 0cd45c6

File tree

3 files changed

+630
-2
lines changed

3 files changed

+630
-2
lines changed

gritz.pl

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use Gtk2 '-init';
2323
use Getopt::Long;
2424
use Pod::Usage;
25+
use lib 'lib/';
26+
use Hyphen;
2527

2628
# defines
2729
my $font = "courier new 24";
@@ -44,6 +46,8 @@
4446
my $back_ptr = -1;
4547
my $prev_back_ptr = -1;
4648
my $fast_forward = 0;
49+
my $hyphen = Text::Hyphen->new('min_word' => 17,
50+
'min_prefix' => 8, 'min_suffix' => 8, 'min_part' => 7);
4751

4852

4953
####################
@@ -66,6 +70,22 @@ sub get_line
6670
}
6771

6872
my @words_buffer;
73+
sub limit_word_length
74+
{
75+
my $i = 0;
76+
for ($i = 0; $i <= $#words_buffer; ++$i) {
77+
my @tmp_buffer = ();
78+
printf("word: $i = ".$words_buffer[$i]."\n");
79+
@tmp_buffer = $hyphen->hyphenate($words_buffer[$i]);
80+
# if hyphenate happened, replace original word by hyphen array
81+
if ($#tmp_buffer > 0) {
82+
$tmp_buffer[$_] .= "-" foreach (0 .. $#tmp_buffer - 1);
83+
splice(@words_buffer, $i, 1, @tmp_buffer);
84+
}
85+
}
86+
#printf ($foo->hyphenate('Schiffahrt')."\n");;
87+
}
88+
6989
my @back_buffer;
7090
my $sentence_cnt = 0;
7191
sub get_next_word
@@ -100,6 +120,8 @@ sub get_next_word
100120
@words_buffer = split(' ', $line);
101121
}
102122
$sentence_cnt++;
123+
limit_word_length();
124+
printf($line."\n");
103125
unshift(@back_buffer, $line);
104126
pop(@back_buffer) if ($#back_buffer > 10);
105127
}
@@ -108,6 +130,7 @@ sub get_next_word
108130
# line into @words_buffer
109131
if ($#words_buffer < 0) {
110132
@words_buffer = split(' ', $back_buffer[$back_ptr]);
133+
limit_word_length();
111134
}
112135
# if @words_buffer empty, proceed with next line
113136
$back_ptr-- if ($#words_buffer <= 0);
@@ -187,8 +210,8 @@ sub set_text
187210
$next_shot += $timeout / 2 if ($word_length > 10);
188211
$next_shot += $timeout / 2 if ($word_length > 14);
189212
$next_shot += $timeout / 2 if ($word_length > 18);
190-
$next_shot += $timeout * 1.5 if ($word =~ /.*[\.!?;]$/);
191213
$next_shot += $timeout / 2 if ($word =~ /.*,$/);
214+
$next_shot += $timeout * 1.5 if ($word =~ /.*[\.!\?;]«?$/);
192215

193216
# search for vowel from start to the mid of the word,
194217
# this will be the focuspoint of the word
@@ -354,7 +377,6 @@ sub main
354377
return TRUE;
355378
}
356379

357-
358380
main();
359381

360382

0 commit comments

Comments
 (0)