ruby-batik 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
+ .rvmrc
1
2
  *.gem
2
3
  .bundle
3
4
  Gemfile.lock
5
+ .rspec-tm
4
6
  pkg/*
@@ -1,3 +1,5 @@
1
+ java_import 'org.apache.batik.transcoder.ErrorHandler'
2
+
1
3
  module Batik
2
4
  class Transcoder
3
5
  def initialize(options={})
@@ -18,4 +20,20 @@ module Batik
18
20
  end
19
21
  alias_method :to_tif, :to_tiff
20
22
  end
23
+
24
+ class DefaultErrorHandler
25
+ include Java::OrgApacheBatikTranscoder::ErrorHandler
26
+
27
+ def error(exception)
28
+ raise exception
29
+ end
30
+
31
+ def fatalError(eexception)
32
+ raise exception
33
+ end
34
+
35
+ def warning(exception)
36
+ raise exception
37
+ end
38
+ end
21
39
  end
@@ -17,7 +17,7 @@ module Batik
17
17
 
18
18
  def self.default_options
19
19
  {
20
- :execute_onload => true, # true/false
20
+ :execute_onload => nil, # true/false
21
21
  :allowed_script_types => nil, # text/ecmascript, application/java-archive
22
22
  :constrain_script_origin => nil, # true/false
23
23
  :snapshot_time => nil,
@@ -40,22 +40,23 @@ module Batik
40
40
  out_io = StringIO.new('','w+b')
41
41
 
42
42
  transcoder = klass.new
43
+ transcoder.setErrorHandler(Batik::DefaultErrorHandler.new)
43
44
  options.each_pair do |key, val|
44
45
  next if val.nil?
45
46
 
46
- java_type = java_type_for(key)
47
- transcoder.java_send(:addTranscodingHint,
48
- [TranscodingHints::Key, java.lang.Object],
49
- transcoder.class.const_get("key_#{key}".upcase),
50
- val.to_java(java_type))
47
+ transcoder.addTranscodingHint(transcoder.class.const_get("key_#{key}".upcase), val.to_java(java_type_for(key)))
51
48
  end
52
- input = TranscoderInput.java_class.constructor(java.io.InputStream).new_instance(in_io.to_inputstream)
53
- output = TranscoderOutput.java_class.constructor(java.io.OutputStream).new_instance(out_io.to_outputstream)
54
49
 
55
- transcoder.transcode(input, output)
50
+ transcoder.transcode(TranscoderInput.new(in_io.to_inputstream), TranscoderOutput.new(out_io.to_outputstream))
56
51
  out_io.flush
57
- out_io.rewind
58
- out_io.read
52
+
53
+ # Sometimes this is closed for read. If so, we must use the #string method
54
+ if out_io.closed_read?
55
+ out_io.string
56
+ else
57
+ out_io.rewind
58
+ out_io.read
59
+ end
59
60
  end
60
61
 
61
62
  private
@@ -1,3 +1,3 @@
1
1
  module Batik
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/ruby-batik.gemspec CHANGED
@@ -13,10 +13,11 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "ruby-batik"
15
15
 
16
+ s.add_development_dependency "bundler", ">= 1.0.0"
17
+ s.add_development_dependency "rspec", ">= 2.6.0"
18
+
16
19
  s.files = `git ls-files`.split("\n")
17
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
22
  s.require_paths = ["lib"]
20
-
21
- s.add_development_dependency "rspec"
22
23
  end
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="12cm" height="3.6cm" viewBox="0 0 1000 300" version="1.1"
4
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
5
+ <defs>
6
+ <path id="MyPath" d="M 100 200 C 200 100 300 0 400 100
7
+ C 500 200 600 300 700 200
8
+ C 800 100 900 100 900 100" />
9
+ </defs>
10
+ <use xlink:href="#MyPath" fill="none" stroke="red" />
11
+ <text font-size="42.5" fill="blue" >
12
+ <textPath xlink:href="#MyPath">
13
+ We go up, then we go down, then up again
14
+ </textPath>
15
+ </text>
16
+
17
+ <rect x="1" y="1" width="998" height="298" fill="none" stroke="blue" stroke-width="2" />
18
+ <script type="text/ecmascript">
19
+ <![CDATA[
20
+ unknown_function(15);
21
+ ]]></script>
22
+ </svg>
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="12cm" height="3.6cm" viewBox="0 0 1000 300" version="1.1"
4
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
5
+ <defs>
6
+ <path id="MyPath" d="M 100 200 C 200 100 300 0 400 100
7
+ C 500 200 600 300 700 200
8
+ C 800 100 900 100 900 100" />
9
+ </defs>
10
+ <use xlink:href="#MyPath" fill="none" stroke="red" />
11
+ <text font-size="42.5" fill="blue" >
12
+ <textPath id="test" xlink:href="#MyPath">
13
+ We go up, then we go down, then up again
14
+ </textPath>
15
+ </text>
16
+
17
+ <rect x="1" y="1" width="998" height="298" fill="none" stroke="blue" stroke-width="2" />
18
+ <script type="text/ecmascript">
19
+ <![CDATA[
20
+ document.getElementById('test').firstChild.nodeValue = 'This should be here';
21
+ ]]>
22
+ </script>
23
+ </svg>
@@ -0,0 +1,27 @@
1
+ require File.expand_path('spec_helper.rb', File.dirname(__FILE__))
2
+
3
+ describe "script execution" do
4
+ it "should fail with invalid javascript" do
5
+ transcoder = Batik::Transcoder.new
6
+ svg = File.read(File.expand_path('svg_with_invalid_script.svg', File.dirname(__FILE__) + '/files'))
7
+ expect {
8
+ transcoder.to_png(svg, :execute_onload => true)
9
+ }.to raise_error(NativeException)
10
+ end
11
+
12
+ it "should not fail with valid_javascript" do
13
+ transcoder = Batik::Transcoder.new
14
+ svg = File.read(File.expand_path('svg_with_valid_script.svg', File.dirname(__FILE__) + '/files'))
15
+ expect {
16
+ File.open("/tmp/foo.png", 'wb+') { |fp| fp.write(transcoder.to_png(svg, :execute_onload => true)) }
17
+ }.to_not raise_error
18
+ end
19
+
20
+ it "should equal the prerendered test file" do
21
+ transcoder = Batik::Transcoder.new
22
+ svg = File.read(File.expand_path('svg_with_valid_script.svg', File.dirname(__FILE__) + '/files'))
23
+ expect {
24
+ transcoder.to_png(svg, :execute_onload => true).size.should eq(File.size(File.expand_path('svg_with_valid_script.png', File.dirname(__FILE__) + '/files')))
25
+ }.to_not raise_error
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ $LOAD_PATH << "#{File.expand_path(File.dirname(__FILE__))}/../lib"
4
+ require 'ruby-batik'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ruby-batik
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kelley Reynolds
@@ -10,19 +10,30 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-23 00:00:00 Z
13
+ date: 2012-01-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rspec
16
+ name: bundler
17
17
  prerelease: false
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 1.0.0
24
24
  type: :development
25
25
  version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.6.0
35
+ type: :development
36
+ version_requirements: *id002
26
37
  description: Wrapper for SVG Transcoding using Apache Batik
27
38
  email:
28
39
  - kelley.reynolds@rubyscale.com
@@ -34,7 +45,6 @@ extra_rdoc_files: []
34
45
 
35
46
  files:
36
47
  - .gitignore
37
- - .rvmrc
38
48
  - Gemfile
39
49
  - README.rdoc
40
50
  - Rakefile
@@ -46,6 +56,11 @@ files:
46
56
  - lib/ruby-batik/transcoders/tiff.rb
47
57
  - lib/ruby-batik/version.rb
48
58
  - ruby-batik.gemspec
59
+ - spec/files/svg_with_invalid_script.svg
60
+ - spec/files/svg_with_valid_script.png
61
+ - spec/files/svg_with_valid_script.svg
62
+ - spec/script_spec.rb
63
+ - spec/spec_helper.rb
49
64
  homepage: https://github.com/kreynolds/ruby-batik
50
65
  licenses: []
51
66
 
@@ -73,5 +88,9 @@ rubygems_version: 1.8.9
73
88
  signing_key:
74
89
  specification_version: 3
75
90
  summary: Wrapper for SVG Transcoding using Apache Batik
76
- test_files: []
77
-
91
+ test_files:
92
+ - spec/files/svg_with_invalid_script.svg
93
+ - spec/files/svg_with_valid_script.png
94
+ - spec/files/svg_with_valid_script.svg
95
+ - spec/script_spec.rb
96
+ - spec/spec_helper.rb
data/.rvmrc DELETED
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
- environment_id="jruby-1.6.5@ruby-batik"
8
-
9
- #
10
- # Uncomment following line if you want options to be set only for given project.
11
- #
12
- # PROJECT_JRUBY_OPTS=( --1.9 )
13
- #
14
- # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
15
- #
16
- # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
17
- #
18
-
19
- #
20
- # First we attempt to load the desired environment directly from the environment
21
- # file. This is very fast and efficient compared to running through the entire
22
- # CLI and selector. If you want feedback on which environment was used then
23
- # insert the word 'use' after --create as this triggers verbose mode.
24
- #
25
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
26
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
27
- then
28
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
29
-
30
- if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
31
- then
32
- . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
33
- fi
34
- else
35
- # If the environment file has not yet been created, use the RVM CLI to select.
36
- if ! rvm --create use "$environment_id"
37
- then
38
- echo "Failed to create RVM environment '${environment_id}'."
39
- return 1
40
- fi
41
- fi
42
-
43
- #
44
- # If you use an RVM gemset file to install a list of gems (*.gems), you can have
45
- # it be automatically loaded. Uncomment the following and adjust the filename if
46
- # necessary.
47
- #
48
- # filename=".gems"
49
- # if [[ -s "$filename" ]]
50
- # then
51
- # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
52
- # fi
53
-
54
- # If you use bundler, this might be useful to you:
55
- # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
56
- # then
57
- # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
58
- # gem install bundler
59
- # fi
60
- # if [[ -s Gemfile ]] && command -v bundle
61
- # then
62
- # bundle install
63
- # fi
64
-
65
- if [[ $- == *i* ]] # check for interactive shells
66
- then
67
- echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
68
- else
69
- echo "Using: $GEM_HOME" # don't use colors in interactive shells
70
- fi
71
-