text2path 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +14 -0
  4. data/README.md +40 -0
  5. data/lib/ext/savage/LICENSE +20 -0
  6. data/lib/ext/savage/README.rdoc +108 -0
  7. data/lib/ext/savage/Rakefile +39 -0
  8. data/lib/ext/savage/VERSION +1 -0
  9. data/lib/ext/savage/lib/savage/direction.rb +42 -0
  10. data/lib/ext/savage/lib/savage/direction_proxy.rb +19 -0
  11. data/lib/ext/savage/lib/savage/directions/arc_to.rb +29 -0
  12. data/lib/ext/savage/lib/savage/directions/close_path.rb +18 -0
  13. data/lib/ext/savage/lib/savage/directions/coordinate_target.rb +17 -0
  14. data/lib/ext/savage/lib/savage/directions/cubic_curve_to.rb +40 -0
  15. data/lib/ext/savage/lib/savage/directions/horizontal_to.rb +19 -0
  16. data/lib/ext/savage/lib/savage/directions/line_to.rb +15 -0
  17. data/lib/ext/savage/lib/savage/directions/move_to.rb +15 -0
  18. data/lib/ext/savage/lib/savage/directions/point_target.rb +17 -0
  19. data/lib/ext/savage/lib/savage/directions/quadratic_curve_to.rb +44 -0
  20. data/lib/ext/savage/lib/savage/directions/vertical_to.rb +19 -0
  21. data/lib/ext/savage/lib/savage/parser.rb +108 -0
  22. data/lib/ext/savage/lib/savage/path.rb +50 -0
  23. data/lib/ext/savage/lib/savage/sub_path.rb +54 -0
  24. data/lib/ext/savage/lib/savage/transformable.rb +48 -0
  25. data/lib/ext/savage/lib/savage/utils.rb +7 -0
  26. data/lib/ext/savage/lib/savage.rb +3 -0
  27. data/lib/ext/savage/savage.gemspec +80 -0
  28. data/lib/ext/savage/spec/savage/directions/arc_to_spec.rb +97 -0
  29. data/lib/ext/savage/spec/savage/directions/close_path_spec.rb +30 -0
  30. data/lib/ext/savage/spec/savage/directions/cubic_curve_to_spec.rb +146 -0
  31. data/lib/ext/savage/spec/savage/directions/horizontal_to_spec.rb +10 -0
  32. data/lib/ext/savage/spec/savage/directions/line_to_spec.rb +10 -0
  33. data/lib/ext/savage/spec/savage/directions/move_to_spec.rb +10 -0
  34. data/lib/ext/savage/spec/savage/directions/point_spec.rb +12 -0
  35. data/lib/ext/savage/spec/savage/directions/quadratic_curve_spec.rb +123 -0
  36. data/lib/ext/savage/spec/savage/directions/vertical_to_spec.rb +10 -0
  37. data/lib/ext/savage/spec/savage/parser_spec.rb +250 -0
  38. data/lib/ext/savage/spec/savage/path_spec.rb +105 -0
  39. data/lib/ext/savage/spec/savage/sub_path_spec.rb +195 -0
  40. data/lib/ext/savage/spec/savage/transformable_spec.rb +62 -0
  41. data/lib/ext/savage/spec/savage_spec.rb +5 -0
  42. data/lib/ext/savage/spec/shared/command.rb +13 -0
  43. data/lib/ext/savage/spec/shared/coordinate_target.rb +36 -0
  44. data/lib/ext/savage/spec/shared/direction.rb +29 -0
  45. data/lib/ext/savage/spec/shared/point_target.rb +45 -0
  46. data/lib/ext/savage/spec/spec_helper.rb +36 -0
  47. data/lib/text2path/converter.rb +65 -0
  48. data/lib/text2path/glyph.rb +13 -0
  49. data/lib/text2path/svg_font.rb +92 -0
  50. data/lib/text2path/svg_path.rb +38 -0
  51. data/lib/text2path/version.rb +3 -0
  52. data/lib/text2path.rb +10 -0
  53. data/libpeerconnection.log +0 -0
  54. data/out.svg +1 -0
  55. data/test.rb +6 -0
  56. metadata +127 -0
@@ -0,0 +1,50 @@
1
+ module Savage
2
+ class Path
3
+ require File.dirname(__FILE__) + "/direction_proxy"
4
+ require File.dirname(__FILE__) + "/sub_path"
5
+
6
+ include Utils
7
+ include DirectionProxy
8
+ include Transformable
9
+
10
+ attr_accessor :subpaths
11
+
12
+ define_proxies do |sym,const|
13
+ define_method(sym) do |*args|
14
+ @subpaths.last.send(sym,*args)
15
+ end
16
+ end
17
+
18
+ def initialize(*args)
19
+ @subpaths = [SubPath.new]
20
+ @subpaths.last.move_to(*args) if (2..3).include?(*args.length)
21
+ yield self if block_given?
22
+ end
23
+
24
+ def directions
25
+ directions = []
26
+ @subpaths.each { |subpath| directions.concat(subpath.directions) }
27
+ directions
28
+ end
29
+
30
+ def move_to(*args)
31
+ unless (@subpaths.last.directions.empty?)
32
+ (@subpaths << SubPath.new(*args)).last
33
+ else
34
+ @subpaths.last.move_to(*args)
35
+ end
36
+ end
37
+
38
+ def closed?
39
+ @subpaths.last.closed?
40
+ end
41
+
42
+ def to_command
43
+ @subpaths.collect { |subpath| subpath.to_command }.join
44
+ end
45
+
46
+ def transform(*args)
47
+ @subpaths.each {|subpath| subpath.transform *args }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,54 @@
1
+ module Savage
2
+ class SubPath
3
+ include Utils
4
+ include DirectionProxy
5
+ include Transformable
6
+
7
+ define_proxies do |sym,const|
8
+ define_method(sym) do |*args|
9
+ raise TypeError if const == "QuadraticCurveTo" && @directions.last.class != Directions::QuadraticCurveTo && [2,3].include?(args.length)
10
+ raise TypeError if const == "CubicCurveTo" && @directions.last.class != Directions::CubicCurveTo && [4,5].include?(args.length)
11
+ (@directions << Savage::Directions.const_get(const).new(*args)).last
12
+ end
13
+ end
14
+
15
+ attr_accessor :directions
16
+
17
+ def move_to(*args)
18
+ return nil unless @directions.empty?
19
+ (@directions << Directions::MoveTo.new(*args)).last
20
+ end
21
+
22
+ def initialize(*args)
23
+ @directions = []
24
+ move_to(*args) if (2..3).include?(args.length)
25
+ yield self if block_given?
26
+ end
27
+
28
+ def to_command
29
+ @directions.to_enum(:each_with_index).collect { |dir, i|
30
+ command_string = dir.to_command
31
+ if i > 0
32
+ prev_command_code = @directions[i-1].command_code
33
+ if dir.command_code == prev_command_code || (prev_command_code.match(/^[Mm]$/) && dir.command_code == 'L')
34
+ command_string.gsub!(/^[A-Za-z]/,'')
35
+ command_string.insert(0,' ') unless command_string.match(/^-/)
36
+ end
37
+ end
38
+ command_string
39
+ }.join
40
+ end
41
+
42
+ def commands
43
+ @directions
44
+ end
45
+
46
+ def closed?
47
+ @directions.last.kind_of? Directions::ClosePath
48
+ end
49
+
50
+ def transform(*args)
51
+ directions.each { |dir| dir.transform *args }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ require 'bigdecimal'
2
+ require 'bigdecimal/util'
3
+
4
+ module Savage
5
+
6
+ module Transformable
7
+
8
+ # Matrix:
9
+ def transform(scale_x, skew_x, skew_y, scale_y, tx, ty)
10
+ end
11
+
12
+ def translate(tx, ty=0)
13
+ transform( 1, 0, 0, 1, tx, ty )
14
+ end
15
+
16
+ def scale(sx, sy=sx)
17
+ transform( sx, 0, 0, sy, 0, 0 )
18
+ end
19
+
20
+ # TODO:
21
+ # make cx, cy be origin center
22
+ def rotate( angle, cx=0, cy=0 )
23
+ a = (angle.to_f/180).to_d * Math::PI
24
+ translate( cx, cy )
25
+ transform( Math.cos(a), Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0)
26
+ translate( -cx, -cy )
27
+ end
28
+
29
+ def skew_x( angle )
30
+ a = angle.to_f/180 * Math::PI
31
+ transform( 1, 0, Math.tan(a), 1, 0, 0 )
32
+ end
33
+
34
+ def skew_y( angle )
35
+ a = angle.to_f/180 * Math::PI
36
+ transform( 1, Math.tan(a), 0, 1, 0, 0 )
37
+ end
38
+
39
+ protected
40
+
41
+ def transform_dot( dot, scale_x, skew_x, skew_y, scale_y, tx, ty )
42
+ x, y = dot.x, dot.y
43
+ dot.x = x*scale_x + y*skew_x + tx
44
+ dot.y = x*skew_y + y*scale_y + ty
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module Savage
2
+ module Utils
3
+ def bool_to_int(value)
4
+ (value) ? 1 : 0
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ %w[ utils transformable direction path parser ].each do |library|
2
+ require_relative "savage/#{library}"
3
+ end
@@ -0,0 +1,80 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "savage"
8
+ s.version = "1.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeremy Holland"]
12
+ s.date = "2013-01-10"
13
+ s.description = "A little gem for extracting and manipulating SVG vector path data."
14
+ s.email = "jeremy@jeremypholland.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/savage.rb",
27
+ "lib/savage/direction.rb",
28
+ "lib/savage/direction_proxy.rb",
29
+ "lib/savage/directions/arc_to.rb",
30
+ "lib/savage/directions/close_path.rb",
31
+ "lib/savage/directions/coordinate_target.rb",
32
+ "lib/savage/directions/cubic_curve_to.rb",
33
+ "lib/savage/directions/horizontal_to.rb",
34
+ "lib/savage/directions/line_to.rb",
35
+ "lib/savage/directions/move_to.rb",
36
+ "lib/savage/directions/point_target.rb",
37
+ "lib/savage/directions/quadratic_curve_to.rb",
38
+ "lib/savage/directions/vertical_to.rb",
39
+ "lib/savage/parser.rb",
40
+ "lib/savage/path.rb",
41
+ "lib/savage/sub_path.rb",
42
+ "lib/savage/utils.rb",
43
+ "savage.gemspec",
44
+ "spec/savage/directions/arc_to_spec.rb",
45
+ "spec/savage/directions/close_path_spec.rb",
46
+ "spec/savage/directions/cubic_curve_to_spec.rb",
47
+ "spec/savage/directions/horizontal_to_spec.rb",
48
+ "spec/savage/directions/line_to_spec.rb",
49
+ "spec/savage/directions/move_to_spec.rb",
50
+ "spec/savage/directions/point_spec.rb",
51
+ "spec/savage/directions/quadratic_curve_spec.rb",
52
+ "spec/savage/directions/vertical_to_spec.rb",
53
+ "spec/savage/parser_spec.rb",
54
+ "spec/savage/path_spec.rb",
55
+ "spec/savage/sub_path_spec.rb",
56
+ "spec/savage_spec.rb",
57
+ "spec/shared/command.rb",
58
+ "spec/shared/coordinate_target.rb",
59
+ "spec/shared/direction.rb",
60
+ "spec/shared/point_target.rb",
61
+ "spec/spec_helper.rb"
62
+ ]
63
+ s.homepage = "http://github.com/awebneck/savage"
64
+ s.require_paths = ["lib"]
65
+ s.rubygems_version = "1.8.24"
66
+ s.summary = "A little library to manipulate SVG path data"
67
+
68
+ if s.respond_to? :specification_version then
69
+ s.specification_version = 3
70
+
71
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
+ s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
73
+ else
74
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<rspec>, [">= 2.3.0"])
78
+ end
79
+ end
80
+
@@ -0,0 +1,97 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe ArcTo do
6
+ def dir_class; ArcTo; end
7
+ def create_relative; ArcTo.new(100,200,300,true,false,400,500,false); end
8
+ def command_code; 'a'; end
9
+
10
+ before :each do
11
+ @dir = dir_class.new(100,200,300,true,false,400,500)
12
+ end
13
+
14
+ include Command
15
+ it_behaves_like 'Direction'
16
+
17
+ it 'should have a target' do
18
+ @dir.respond_to?(:target).should == true
19
+ @dir.target.class.should == Point
20
+ end
21
+ it 'should have a radius' do
22
+ @dir.respond_to?(:radius).should == true
23
+ @dir.radius.class.should == Point
24
+ end
25
+ it 'should have a large arc based on the constructor argument' do
26
+ @dir.respond_to?(:large_arc).should == true
27
+ @dir.large_arc.should == true
28
+ end
29
+ it 'should have a sweep based on the constructor argument' do
30
+ @dir.respond_to?(:sweep).should == true
31
+ @dir.sweep.should == false
32
+ end
33
+ it 'should have a rotation based on the constructor arugment' do
34
+ @dir.respond_to?(:rotation).should == true
35
+ @dir.rotation.should == 300
36
+ end
37
+ it 'should have an accessible target x, based on the constructor argument' do
38
+ @dir.target.x.should == 400
39
+ end
40
+ it 'should have an accessible target y, based on the constructor argument' do
41
+ @dir.target.y.should == 500
42
+ end
43
+ it 'should have an accessible x radius, based on the constructor argument' do
44
+ @dir.radius.x.should == 100
45
+ end
46
+ it 'should have an accessible y radius, based on the constructor argument' do
47
+ @dir.radius.y.should == 200
48
+ end
49
+ it 'should be constructed with at least x and y radii, rotation, large arc, sweep, and target x and y parameters' do
50
+ lambda { dir_class.new }.should raise_error
51
+ lambda { dir_class.new 45 }.should raise_error
52
+ lambda { dir_class.new 45, 50 }.should raise_error
53
+ lambda { dir_class.new 45, 50, 60 }.should raise_error
54
+ lambda { dir_class.new 45, 50, 60, true }.should raise_error
55
+ lambda { dir_class.new 45, 50, 60, true, true }.should raise_error
56
+ lambda { dir_class.new 45, 50, 60, true, true, 100 }.should raise_error
57
+ lambda { dir_class.new 45, 50, 60, true, true, 100, 200 }.should_not raise_error
58
+ end
59
+ it 'should be relative if constructed with a false eighth parameter' do
60
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200, false
61
+ direction.absolute?.should == false
62
+ end
63
+ it 'should be absolute if constructed with a true eighth parameter' do
64
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200, true
65
+ direction.absolute?.should == true
66
+ end
67
+ it 'should be absolute if constructed with only seven parameters' do
68
+ direction = dir_class.new 45, 50, 60, true, true, 100, 200
69
+ direction.absolute?.should == true
70
+ end
71
+ describe '#to_command' do
72
+ it 'should have exactly 7 numerical parameters' do
73
+ extract_coordinates(@dir.to_command).length.should == 7
74
+ end
75
+ it 'should show the provided x radius value as the first parameter' do
76
+ extract_coordinates(@dir.to_command)[0].should == 100
77
+ end
78
+ it 'should show the provided y radius value as the second parameter' do
79
+ extract_coordinates(@dir.to_command)[1].should == 200
80
+ end
81
+ it 'should show the provided rotation value as the third parameter' do
82
+ extract_coordinates(@dir.to_command)[2].should == 300
83
+ end
84
+ it 'should show the integer interpretation of the provided large arc value as the fourth parameter' do
85
+ extract_coordinates(@dir.to_command)[3].should == 1
86
+ end
87
+ it 'should show the integer interpretation of the provided sweep value as the fifth parameter' do
88
+ extract_coordinates(@dir.to_command)[4].should == 0
89
+ end
90
+ it 'should show the provided target x value as the sixth parameter' do
91
+ extract_coordinates(@dir.to_command)[5].should == 400
92
+ end
93
+ it 'should show the provided target y value as the seventh parameter' do
94
+ extract_coordinates(@dir.to_command)[6].should == 500
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe ClosePath do
6
+ before :each do
7
+ @dir = ClosePath.new()
8
+ end
9
+ def create_relative; ClosePath.new(false); end
10
+ def command_code; 'z'; end
11
+ include Command
12
+ it_behaves_like 'Direction'
13
+ it 'should be constructed with with either no parameters or a single boolean parameter' do
14
+ lambda { ClosePath.new }.should_not raise_error
15
+ lambda { ClosePath.new true }.should_not raise_error
16
+ lambda { ClosePath.new 45, 50 }.should raise_error
17
+ end
18
+ it 'should be relative if constructed with a false parameter' do
19
+ direction = ClosePath.new(false)
20
+ direction.absolute?.should == false
21
+ end
22
+ it 'should be absolute if constructed with a false parameter' do
23
+ direction = ClosePath.new(true)
24
+ direction.absolute?.should == true
25
+ end
26
+ it 'should be absolute if constructed with no parameters' do
27
+ direction = ClosePath.new()
28
+ direction.absolute?.should == true
29
+ end
30
+ end
@@ -0,0 +1,146 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe CubicCurveTo do
6
+ def dir_class; CubicCurveTo; end
7
+ def create_relative; CubicCurveTo.new(100,200,300,400,500,600,false); end
8
+ def command_code; 'c'; end
9
+
10
+ before :each do
11
+ @dir = dir_class.new(100,200,300,400,500,600)
12
+ end
13
+
14
+ include Command
15
+ it_behaves_like 'Direction'
16
+
17
+ it 'should have a target' do
18
+ @dir.respond_to?(:target).should == true
19
+ @dir.target.class.should == Point
20
+ end
21
+ it 'should have a control point' do
22
+ @dir.respond_to?(:control).should == true
23
+ @dir.control.class.should == Point
24
+ end
25
+ it 'should have an accessible target x, based on the constructor argument' do
26
+ @dir.target.x.should == 500
27
+ end
28
+ it 'should have an accessible target y, based on the constructor argument' do
29
+ @dir.target.y.should == 600
30
+ end
31
+ it 'should have an accessible second control x, based on the constructor argument' do
32
+ @dir.control_2.x.should == 300
33
+ end
34
+ it 'should have an accessible second control y, based on the constructor argument' do
35
+ @dir.control_2.y.should == 400
36
+ end
37
+ context 'when in verbose format' do
38
+ it 'should be constructed with at least target x and y, control 1 x and y, and control 2 x and y parameters' do
39
+ lambda { dir_class.new }.should raise_error
40
+ lambda { dir_class.new 45 }.should raise_error
41
+ lambda { dir_class.new 45, 50 }.should raise_error
42
+ lambda { dir_class.new 45, 50, 60 }.should raise_error
43
+ lambda { dir_class.new 45, 50, 60, 70, 80 }.should raise_error
44
+ lambda { dir_class.new 45, 50, 60, 70, 80, 90 }.should_not raise_error
45
+ lambda { dir_class.new 45, 50, 60, 70, 80, 90, true }.should_not raise_error
46
+ end
47
+ it 'should be relative if constructed with a false seventh parameter' do
48
+ direction = dir_class.new 45, 50, 60, 70, 80, 90, false
49
+ direction.absolute?.should == false
50
+ end
51
+ it 'should be absolute if constructed with a true seventh parameter' do
52
+ direction = dir_class.new 45, 50, 60, 70, 80, 90, true
53
+ direction.absolute?.should == true
54
+ end
55
+ it 'should be absolute if constructed with only six parameters' do
56
+ direction = dir_class.new 45, 50, 60, 70, 80, 90
57
+ direction.absolute?.should == true
58
+ end
59
+ it 'should have an accessible first control x, based on the constructor argument' do
60
+ @dir.control_1.x.should == 100
61
+ end
62
+ it 'should have an accessible first control y, based on the constructor argument' do
63
+ @dir.control_1.y.should == 200
64
+ end
65
+ describe '#to_command' do
66
+ it 'should start with a lower-case c when not absolute' do
67
+ extract_command(CubicCurveTo.new(100,200,300,400,500,600,false).to_command).should == 'c'
68
+ end
69
+ it 'should start with a capital C when absolute' do
70
+ extract_command(@dir.to_command).should == 'C'
71
+ end
72
+ it 'should have exactly 6 numerical parameters' do
73
+ extract_coordinates(@dir.to_command).length.should == 6
74
+ end
75
+ it 'should show the provided first control X value as the first parameter' do
76
+ extract_coordinates(@dir.to_command)[0].should == 100
77
+ end
78
+ it 'should show the provided first control Y value as the second parameter' do
79
+ extract_coordinates(@dir.to_command)[1].should == 200
80
+ end
81
+ it 'should show the provided second control X value as the third parameter' do
82
+ extract_coordinates(@dir.to_command)[2].should == 300
83
+ end
84
+ it 'should show the provided second control Y value as the fourth parameter' do
85
+ extract_coordinates(@dir.to_command)[3].should == 400
86
+ end
87
+ it 'should show the provided target X value as the fifth parameter' do
88
+ extract_coordinates(@dir.to_command)[4].should == 500
89
+ end
90
+ it 'should show the provided target Y value as the sixth parameter' do
91
+ extract_coordinates(@dir.to_command)[5].should == 600
92
+ end
93
+ end
94
+ end
95
+ context 'when in shorthand format' do
96
+ before :each do
97
+ @dir = CubicCurveTo.new(100,200,300,400)
98
+ end
99
+ it 'should be constructed with at least target x and y parameters' do
100
+ lambda { dir_class.new }.should raise_error
101
+ lambda { dir_class.new 45 }.should raise_error
102
+ lambda { dir_class.new 45, 50 }.should raise_error
103
+ lambda { dir_class.new 45, 50, 60 }.should raise_error
104
+ lambda { dir_class.new 45, 50, 60, 70 }.should_not raise_error
105
+ lambda { dir_class.new 45, 50, 60, 70, true }.should_not raise_error
106
+ end
107
+ it 'should be relative if constructed with a false third parameter' do
108
+ direction = dir_class.new 45, 50, 60, 70, false
109
+ direction.absolute?.should == false
110
+ end
111
+ it 'should be absolute if constructed with a true third parameter' do
112
+ direction = dir_class.new 45, 50, 60, 70, true
113
+ direction.absolute?.should == true
114
+ end
115
+ it 'should be absolute if constructed with only two parameters' do
116
+ direction = dir_class.new 45, 50, 60, 70
117
+ direction.absolute?.should == true
118
+ end
119
+ it 'should have an nil first control, based on the constructor argument' do
120
+ @dir.control_1.should == nil
121
+ end
122
+ describe '#to_command' do
123
+ it 'should start with a lower-case s when not absolute' do
124
+ extract_command(CubicCurveTo.new(100,200,300,400,false).to_command).should == 's'
125
+ end
126
+ it 'should start with a capital S when absolute' do
127
+ extract_command(@dir.to_command).should == 'S'
128
+ end
129
+ it 'should have exactly 2 numerical parameters' do
130
+ extract_coordinates(@dir.to_command).length.should == 4
131
+ end
132
+ it 'should show the provided second control X value as the first parameter' do
133
+ extract_coordinates(@dir.to_command)[0].should == 100
134
+ end
135
+ it 'should show the provided second control Y value as the second parameter' do
136
+ extract_coordinates(@dir.to_command)[1].should == 200
137
+ end
138
+ it 'should show the provided target X value as the third parameter' do
139
+ extract_coordinates(@dir.to_command)[2].should == 300
140
+ end
141
+ it 'should show the provided target Y value as the fourth parameter' do
142
+ extract_coordinates(@dir.to_command)[3].should == 400
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe HorizontalTo do
6
+ def dir_class; HorizontalTo; end
7
+ def create_relative; HorizontalTo.new(100,false); end
8
+ def command_code; 'h'; end
9
+ it_behaves_like 'CoordinateTarget'
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe LineTo do
6
+ def dir_class; LineTo; end
7
+ def create_relative; LineTo.new(100,200,false); end
8
+ def command_code; 'l'; end
9
+ it_behaves_like 'PointTarget'
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe MoveTo do
6
+ def dir_class; MoveTo; end
7
+ def create_relative; MoveTo.new(100,200,false); end
8
+ def command_code; 'm'; end
9
+ it_behaves_like 'PointTarget'
10
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ include Savage::Directions
4
+
5
+ describe Point do
6
+ it 'should have an x' do
7
+ Point.new.respond_to?(:x).should == true;
8
+ end
9
+ it 'should have an y' do
10
+ Point.new.respond_to?(:y).should == true;
11
+ end
12
+ end