mireru 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtk3"
2
18
  require "stringio"
3
19
  require "hexdump"
@@ -0,0 +1,70 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
17
+ require "gtk3"
18
+ require "chupa-text"
19
+ gem "chupa-text-decomposer-html"
20
+ gem "chupa-text-decomposer-pdf"
21
+ gem "chupa-text-decomposer-libreoffice"
22
+
23
+ ChupaText::Decomposers.load
24
+
25
+ # TODO: workaround for a multibyte filename.
26
+ module URI
27
+ class Generic
28
+ alias :path_raw :path
29
+ def path
30
+ URI.decode_www_form_component(path_raw, Encoding.find("locale"))
31
+ end
32
+ end
33
+
34
+ def self.parse(uri)
35
+ uri = URI.encode_www_form_component(uri)
36
+ DEFAULT_PARSER.parse(uri)
37
+ end
38
+ end
39
+
40
+ module Mireru
41
+ module Widget
42
+ class ExtractedText < Gtk::TextView
43
+ def initialize(file)
44
+ buffer = buffer_from_file(file)
45
+ super(buffer)
46
+ self.editable = false
47
+ end
48
+
49
+ private
50
+ def buffer_from_file(file)
51
+ extractor = ChupaText::Extractor.new
52
+ extractor.apply_configuration(ChupaText::Configuration.default)
53
+
54
+ text = ""
55
+ extractor.extract(file) do |extracted_data|
56
+ text << extracted_data.body
57
+ end
58
+
59
+ buffer_from_text(text)
60
+ end
61
+
62
+ def buffer_from_text(text)
63
+ text.encode!("utf-8") unless text.encoding == "utf-8"
64
+ buffer = Gtk::TextBuffer.new
65
+ buffer.text = text
66
+ buffer
67
+ end
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtk3"
2
18
 
3
19
  module Mireru
@@ -5,16 +21,27 @@ module Mireru
5
21
  class Image < Gtk::Image
6
22
  def initialize(file, width, height)
7
23
  super()
8
- pixbuf_animation = Gdk::PixbufAnimation.new(file)
9
- if pixbuf_animation.static_image?
10
- pixbuf = pixbuf_animation.static_image
11
- if pixbuf.width > width || pixbuf.height > height
12
- pixbuf = Gdk::Pixbuf.new(file, width, height)
24
+ @pixbuf = Gdk::PixbufAnimation.new(file)
25
+ if @pixbuf.static_image?
26
+ @pixbuf = @pixbuf.static_image
27
+ if @pixbuf.width > width || @pixbuf.height > height
28
+ scale_preserving_aspect_ratio(width, height)
13
29
  end
14
- self.pixbuf = pixbuf
30
+ self.pixbuf = @pixbuf
15
31
  else
16
- self.pixbuf_animation = pixbuf_animation
32
+ self.pixbuf_animation = @pixbuf
33
+ end
34
+ end
35
+
36
+ def scale_preserving_aspect_ratio(width, height)
37
+ if @pixbuf.is_a?(Gdk::PixbufAnimation)
38
+ @pixbuf = @pixbuf.static_image
17
39
  end
40
+ x_ratio = width.to_f / @pixbuf.width
41
+ y_ratio = height.to_f / @pixbuf.height
42
+ ratio = [x_ratio, y_ratio].min
43
+ self.pixbuf = @pixbuf.scale(@pixbuf.width * ratio,
44
+ @pixbuf.height * ratio)
18
45
  end
19
46
  end
20
47
  end
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtk3"
2
18
  require "poppler"
3
19
 
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtk3"
2
18
  require "rsvg2"
3
19
 
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtksourceview3"
2
18
 
3
19
  module Mireru
@@ -22,11 +38,30 @@ module Mireru
22
38
  end
23
39
 
24
40
  def buffer_from_text(text)
25
- text.encode!("utf-8") unless text.encoding == "utf-8"
41
+ to = Encoding::UTF_8
42
+ from = guess_encoding(text)
43
+ if to != from
44
+ text.encode!(to,
45
+ from,
46
+ {
47
+ :invalid => :replace,
48
+ :undef => :replace,
49
+ })
50
+ end
26
51
  buffer = GtkSource::Buffer.new
27
52
  buffer.text = text
28
53
  buffer
29
54
  end
55
+
56
+ def guess_encoding(text)
57
+ return Encoding::UTF_8 if utf8?(text)
58
+ require "nkf"
59
+ NKF.guess(text)
60
+ end
61
+
62
+ def utf8?(text)
63
+ text.dup.force_encoding(Encoding::UTF_8).valid_encoding?
64
+ end
30
65
  end
31
66
  end
32
67
  end
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "clutter-gtk"
2
18
  require "clutter-gst"
3
19
 
data/lib/mireru/window.rb CHANGED
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "gtk3"
2
18
  require "mireru/widget"
3
19
  require "mireru/navigator"
@@ -28,7 +44,7 @@ module Mireru
28
44
  define_keybind
29
45
  end
30
46
 
31
- def add_from_file(file)
47
+ def add_from_file(file, chupa=false)
32
48
  @scroll.hadjustment.value = 0
33
49
  @scroll.vadjustment.value = 0
34
50
  @scroll.each do |child|
@@ -37,7 +53,7 @@ module Mireru
37
53
  end
38
54
  width = @scroll.allocated_width - 10
39
55
  height = @scroll.allocated_height - 10
40
- @widget = Mireru::Widget.create(file, width, height)
56
+ @widget = Mireru::Widget.create(file, width, height, chupa)
41
57
  @widget.override_font(Pango::FontDescription.new(@font)) if @font
42
58
  if @widget.is_a?(Gtk::Scrollable)
43
59
  @scroll.add(@widget)
@@ -87,8 +103,7 @@ module Mireru
87
103
  if Mireru::Widget.image?(@file)
88
104
  width = @scroll.allocated_width - 10
89
105
  height = @scroll.allocated_height - 10
90
- pixbuf = Gdk::Pixbuf.new(@file, width, height)
91
- @widget.pixbuf = pixbuf
106
+ @widget.scale_preserving_aspect_ratio(width, height)
92
107
  elsif @widget.is_a?(Gtk::TextView)
93
108
  font = @widget.pango_context.families.sample.name
94
109
  @widget.override_font(Pango::FontDescription.new(font))
@@ -122,6 +137,8 @@ module Mireru
122
137
  font = font.sub(/\d+\z/, (font_size - 1).to_s)
123
138
  @widget.override_font(Pango::FontDescription.new(font))
124
139
  end
140
+ when Gdk::Keyval::GDK_KEY_E
141
+ add_from_file(@file, true)
125
142
  when Gdk::Keyval::GDK_KEY_h
126
143
  @scroll.hadjustment.value -= 17
127
144
  when Gdk::Keyval::GDK_KEY_j
@@ -168,10 +185,33 @@ module Mireru
168
185
  @paned.position -= 2
169
186
  when Gdk::Keyval::GDK_KEY_l
170
187
  @paned.position += 2
188
+ when Gdk::Keyval::GDK_KEY_Return
189
+ execute_selected_file
171
190
  else
172
191
  return false
173
192
  end
174
193
  true
175
194
  end
195
+
196
+ def execute_selected_file
197
+ command = nil
198
+
199
+ case RUBY_PLATFORM
200
+ when /mswin|mingw|bccwin/
201
+ command = "start"
202
+ when /darwin/
203
+ command = "open"
204
+ else
205
+ $stderr.puts(<<-END_OF_MESSAGE)
206
+ Ctrl+Enter is not supported in this platform (#{RUBY_PLATFORM}).
207
+ Only supports Windows (use `start` command) and OS X (use `open` command).
208
+ END_OF_MESSAGE
209
+ return
210
+ end
211
+
212
+ Thread.new do
213
+ system(command, @file.encode("locale"))
214
+ end
215
+ end
176
216
  end
177
217
  end
data/mireru.gemspec CHANGED
@@ -26,6 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency("poppler", "= 2.2.0")
27
27
  spec.add_runtime_dependency("rsvg2", "= 2.2.0")
28
28
  spec.add_runtime_dependency("hexdump")
29
+ spec.add_runtime_dependency("chupa-text")
30
+ spec.add_runtime_dependency("chupa-text-decomposer-html")
31
+ spec.add_runtime_dependency("chupa-text-decomposer-pdf")
32
+ spec.add_runtime_dependency("chupa-text-decomposer-libreoffice")
29
33
 
30
34
  spec.add_development_dependency("test-unit")
31
35
  spec.add_development_dependency("test-unit-notify")
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "test-unit"
2
18
  require "test/unit/notify"
3
19
  require "test/unit/rr"
data/test/run-test.rb CHANGED
@@ -1,4 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program; if not, write to the Free Software Foundation, Inc.,
17
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2
18
 
3
19
  base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
20
  lib_dir = File.join(base_dir, "lib")
data/test/test-logger.rb CHANGED
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "mireru/logger"
2
18
  require "mireru/command/mireru"
3
19
  require "stringio"
data/test/test-mireru.rb CHANGED
@@ -1,3 +1,19 @@
1
+ # Copyright (C) 2013-2014 Masafumi Yokoyama <myokoym@gmail.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License along
14
+ # with this program; if not, write to the Free Software Foundation, Inc.,
15
+ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+
1
17
  require "mireru/command/mireru"
2
18
 
3
19
  class MireruTest < Test::Unit::TestCase