diff --git a/Makefile b/Makefile
index aa7f871..3d80368 100644
--- a/Makefile
+++ b/Makefile
@@ -4,4 +4,6 @@ test :
testrb `find tests -name '*.rb'`
test-coverage :
- rcov -x '\/jruby\/lib\/' -x '\/tests\/data\/' `find tests -name '*.rb'`
\ No newline at end of file
+ rcov -x '\/jruby\/lib\/' -x '\/tests\/data\/' `find tests -name '*.rb'`
+ sed 's#
| # | #' coverage/index.html > coverage/index.html.new
+ mv coverage/index.html.new coverage/index.html
diff --git a/classes/InputFilter.rb b/classes/InputFilter.rb
index 97de32f..de852e5 100644
--- a/classes/InputFilter.rb
+++ b/classes/InputFilter.rb
@@ -1,4 +1,4 @@
-require 'filter'
+require File.dirname(__FILE__) + '/Filter.rb'
class InputFilter < Filter
OutputFilename = "tmp.png"
diff --git a/classes/SVGToTempBitmap.rb b/classes/SVGToTempBitmap.rb
new file mode 100644
index 0000000..8c498d6
--- /dev/null
+++ b/classes/SVGToTempBitmap.rb
@@ -0,0 +1,102 @@
+require File.dirname(__FILE__) + '/InputFilter.rb'
+
+class SVGToTempBitmap < InputFilter
+ include PrintHandling
+
+ #
+ # select which build method to use based on the number of provided images.
+ #
+ def build(input)
+ (input.instance_of? Array) ? multiple(input) : single(input)
+ end
+
+ #
+ # process a single input file, possibly splitting it into two output files if it's a spread
+ #
+ def single(input)
+ filename = Dir.pwd + '/' + OutputFilename
+ inkscape(input, filename)
+ @cleanup << filename
+
+ if @config['spread']
+ targets = build_spread(filename)
+ @cleanup.concat targets
+ return targets
+ end
+
+ return filename
+ end
+
+ def build_spread(filename)
+ width, height = get_dimensions(filename)
+ targets = []
+
+ [ [ "left", 0 ], [ "right", width / 2 ] ].each do |side, offset|
+ target = filename + "-#{side}.png"
+ command = [
+ "\"#{filename}\"",
+ "-gravity Northwest",
+ "-crop #{width/2}x#{height}+#{offset}+0",
+ "+repage",
+ "\"#{target}\""
+ ]
+
+ convert(command)
+
+ targets << target
+ end
+
+ return targets
+ end
+
+ #
+ # combine multiple input files onto a single page-sized canvas.
+ # images are added left-to-right and top-to-bottom starting from the top-left of the page.
+ # leave a grid square blank by passing the filename "/blank".
+ #
+ def multiple(files)
+ if @config['spread']; raise "Spreads and grids combined do not make sense"; end
+
+ width, height = @config['grid'].split("x").collect { |f| f.to_f }
+ joined_files = []
+
+ page_width, page_height = calculate_page_size
+
+ grid_width = page_width / width
+ grid_height = page_height / height
+
+ 0.upto(files.length - 1) do |i|
+ x = i % width
+ y = (i / width).floor
+
+ if files[i].split('/').last != "blank"
+ tmp_svg_output = OutputFilename + "-#{i}.png"
+ inkscape(Dir.pwd + '/' + files[i], tmp_svg_output)
+
+ joined_files << [ tmp_svg_output, x, y ]
+ @cleanup << tmp_svg_output
+ end
+ end
+
+ command = [
+ "-size #{page_width}x#{page_height}",
+ "xc:white"
+ ]
+
+ joined_files.each do |file, x, y|
+ image_width, image_height = get_dimensions(file)
+
+ x_offset = (grid_width - image_width) / 2
+ y_offset = (grid_height - image_height) / 2
+
+ command << "\"#{file}\" -geometry +#{x * grid_width + x_offset}+#{y * grid_height + y_offset} -composite"
+ end
+
+ command << OutputFilename
+
+ convert(command)
+
+ @cleanup << OutputFilename
+ OutputFilename
+ end
+end
diff --git a/minicomic-backend.rb b/minicomic-backend.rb
index dab0d51..adbecc6 100755
--- a/minicomic-backend.rb
+++ b/minicomic-backend.rb
@@ -7,102 +7,6 @@ Dir[File.dirname(__FILE__) + "/classes/*.rb"].each do |file|
require file
end
-class SVGToTempBitmap < InputFilter
- include PrintHandling
-
- #
- # select which build method to use based on the number of provided images.
- #
- def build(input)
- (input.instance_of? Array) ? multiple(input) : single(input)
- end
-
- #
- # process a single input file, possibly splitting it into two output files if it's a spread
- #
- def single(input)
- filename = Dir.pwd + '/' + OutputFilename
- inkscape(input, filename)
- @cleanup << filename
-
- if @config['spread']
- width, height = get_dimensions(filename)
- targets = []
-
- [ [ "left", 0 ], [ "right", width / 2 ] ].each do |side, offset|
- target = filename + "-#{side}.png"
- command = [
- "\"#{filename}\"",
- "-gravity Northwest",
- "-crop #{width/2}x#{height}+#{offset}+0",
- "+repage",
- "\"#{target}\""
- ]
-
- convert(command)
-
- targets << target
- @cleanup << target
- end
-
- return targets
- end
-
- return filename
- end
-
- #
- # combine multiple input files onto a single page-sized canvas.
- # images are added left-to-right and top-to-bottom starting from the top-left of the page.
- # leave a grid square blank by passing the filename "/blank".
- #
- def multiple(files)
- if @config['spread']; raise "Spreads and grids combined do not make sense"; end
-
- width, height = @config['grid'].split("x").collect { |f| f.to_f }
- joined_files = []
-
- page_width, page_height = calculate_page_size
-
- grid_width = page_width / width
- grid_height = page_height / height
-
- 0.upto(files.length - 1) do |i|
- x = i % width
- y = (i / width).floor
-
- if files[i].split('/').last != "blank"
- tmp_svg_output = OutputFilename + "-#{i}.png"
- inkscape(Dir.pwd + '/' + files[i], tmp_svg_output)
-
- joined_files << [ tmp_svg_output, x, y ]
- @cleanup << tmp_svg_output
- end
- end
-
- command = [
- "-size #{page_width}x#{page_height}",
- "xc:white"
- ]
-
- joined_files.each do |file, x, y|
- image_width, image_height = get_dimensions(file)
-
- x_offset = (grid_width - image_width) / 2
- y_offset = (grid_height - image_height) / 2
-
- command << "\"#{file}\" -geometry +#{x * grid_width + x_offset}+#{y * grid_height + y_offset} -composite"
- end
-
- command << OutputFilename
-
- convert(command)
-
- @cleanup << OutputFilename
- OutputFilename
- end
-end
-
#
# Process an input file for the Web
#
diff --git a/tests/TestSVGToTempBitmap.rb b/tests/TestSVGToTempBitmap.rb
new file mode 100644
index 0000000..f2b203d
--- /dev/null
+++ b/tests/TestSVGToTempBitmap.rb
@@ -0,0 +1,28 @@
+require 'rubygems'
+require 'test/unit'
+require 'fakefs/safe'
+require File.dirname(__FILE__) + '/../classes/SVGToTempBitmap.rb'
+
+class TestSVGToTempBitmap < Test::Unit::TestCase
+ def setup
+ @filter = SVGToTempBitmap.new
+ end
+
+ def test_build
+ [
+ [ "", :single ],
+ [ [], :multiple ]
+ ].each do |input, expected_method|
+ @filter.expects(expected_method).with(input)
+ @filter.build(input)
+ end
+ end
+
+ def test_build_spread
+ @filter.stubs(:get_dimensions).with('filename').returns([50, 75])
+ @filter.expects(:convert).with(['"filename"', '-gravity Northwest', '-crop 25x75+0+0', '+repage', '"filename-left.png"'])
+ @filter.expects(:convert).with(['"filename"', '-gravity Northwest', '-crop 25x75+25+0', '+repage', '"filename-right.png"'])
+
+ assert_equal [ 'filename-left.png', 'filename-right.png' ], @filter.build_spread('filename')
+ end
+end