savage 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
1
+ 1.1.6
@@ -7,8 +7,8 @@ module Savage
7
7
  raise TypeError if (subpaths.empty?)
8
8
  path = Path.new
9
9
  path.subpaths = []
10
- subpaths.each do |subpath|
11
- path.subpaths << parse_subpath(subpath)
10
+ subpaths.each_with_index do |subpath, i|
11
+ path.subpaths << parse_subpath(subpath, i == 0)
12
12
  end
13
13
  path
14
14
  end
@@ -27,29 +27,31 @@ module Savage
27
27
  subpaths
28
28
  end
29
29
 
30
- def parse_subpath(parsable)
30
+ def parse_subpath(parsable, force_absolute=false)
31
31
  subpath = SubPath.new
32
- subpath.directions = extract_directions parsable
32
+ subpath.directions = extract_directions parsable, force_absolute
33
33
  subpath
34
34
  end
35
35
 
36
- def extract_directions(parsable)
36
+ def extract_directions(parsable, force_absolute=false)
37
37
  directions = []
38
+ i = 0
38
39
  parsable.scan /[MmLlHhVvQqCcTtSsAaZz](?:\d|[eE.,+-]|\W)*/m do |match_group|
39
- direction = build_direction $&
40
+ direction = build_direction $&, force_absolute && i == 0
40
41
  if direction.kind_of?(Array)
41
42
  directions.concat direction
42
43
  else
43
44
  directions << direction
44
45
  end
46
+ i += 1
45
47
  end
46
48
  directions
47
49
  end
48
50
 
49
- def build_direction(parsable)
51
+ def build_direction(parsable, force_absolute=false)
50
52
  directions = []
51
53
  coordinates = extract_coordinates parsable
52
- absolute = (parsable[0,1] == parsable[0,1].upcase) ? true : false
54
+ absolute = (force_absolute || parsable[0,1] == parsable[0,1].upcase) ? true : false
53
55
  recurse_code = parsable[0,1]
54
56
 
55
57
  # we need to handle this separately, since ClosePath doesn't take any coordinates
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "savage"
8
- s.version = "1.1.5"
8
+ s.version = "1.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Holland"]
12
- s.date = "2011-12-28"
12
+ s.date = "2012-08-02"
13
13
  s.description = "A little gem for extracting and manipulating SVG vector path data."
14
14
  s.email = "jeremy@jeremypholland.com"
15
15
  s.extra_rdoc_files = [
@@ -62,7 +62,7 @@ Gem::Specification.new do |s|
62
62
  ]
63
63
  s.homepage = "http://github.com/awebneck/savage"
64
64
  s.require_paths = ["lib"]
65
- s.rubygems_version = "1.8.10"
65
+ s.rubygems_version = "1.8.15"
66
66
  s.summary = "A little library to manipulate SVG path data"
67
67
 
68
68
  if s.respond_to? :specification_version then
@@ -12,6 +12,7 @@ describe Parser do
12
12
  lambda { Parser.parse("M100 200") }.should_not raise_error
13
13
  lambda { Parser.parse(2) }.should raise_error
14
14
  end
15
+
15
16
  it 'should return a path object with one subpath containing one move_to when the string is only a move_to command' do
16
17
  path = Parser.parse("M100 200")
17
18
  path.class.should == Path
@@ -20,6 +21,15 @@ describe Parser do
20
21
  path.subpaths.last.directions.last.class.should == Directions::MoveTo
21
22
  end
22
23
 
24
+ it 'should return a path object with one subpath containing an absolute move_to even when the string starts with a relative move_to command' do
25
+ path = Parser.parse("m100 200")
26
+ path.class.should == Path
27
+ path.subpaths.length.should == 1
28
+ path.subpaths.last.directions.length.should == 1
29
+ path.subpaths.last.directions.last.class.should == Directions::MoveTo
30
+ path.subpaths.last.directions.last.should be_absolute
31
+ end
32
+
23
33
  it 'should handle comma separated coordinates' do
24
34
  path = Parser.parse("M100,200")
25
35
  path.class.should == Path
@@ -37,6 +47,7 @@ describe Parser do
37
47
  path.subpaths.last.directions[1].should_not be_absolute
38
48
  path.subpaths.last.directions[1].class.should == Directions::LineTo
39
49
  end
50
+
40
51
  it 'should return a path object with one subpath containing a move_to and a horizontal_to when the string is a move_to command followed by a horizontal_to command' do
41
52
  path = Parser.parse("M100 200H-342.65")
42
53
  path.class.should == Path
@@ -45,6 +56,7 @@ describe Parser do
45
56
  path.subpaths.last.directions[0].class.should == Directions::MoveTo
46
57
  path.subpaths.last.directions[1].class.should == Directions::HorizontalTo
47
58
  end
59
+
48
60
  it 'should return a path object with one subpath containing a move_to and a vertical_to when the string is a move_to command followed by a vertical_to command' do
49
61
  path = Parser.parse("M100 200V-342.65")
50
62
  path.class.should == Path
@@ -53,6 +65,7 @@ describe Parser do
53
65
  path.subpaths.last.directions[0].class.should == Directions::MoveTo
54
66
  path.subpaths.last.directions[1].class.should == Directions::VerticalTo
55
67
  end
68
+
56
69
  it 'should return a path object with one subpath containing a move_to and a full cubic_curve_to when the string is a move_to command followed by a full cubic_curve_to command' do
57
70
  path = Parser.parse("M100 200C-342.65-32 1.233-34 255 12")
58
71
  path.class.should == Path
@@ -62,6 +75,7 @@ describe Parser do
62
75
  path.subpaths.last.directions[1].class.should == Directions::CubicCurveTo
63
76
  path.subpaths.last.directions[1].command_code.should == 'C'
64
77
  end
78
+
65
79
  it 'should return a path object with one subpath containing a move_to and a short cubic_curve_to when the string is a move_to command followed by a short cubic_curve_to command' do
66
80
  path = Parser.parse("M100 200S1.233-34 255 12")
67
81
  path.class.should == Path
@@ -71,6 +85,7 @@ describe Parser do
71
85
  path.subpaths.last.directions[1].class.should == Directions::CubicCurveTo
72
86
  path.subpaths.last.directions[1].command_code.should == 'S'
73
87
  end
88
+
74
89
  it 'should return a path object with one subpath containing a move_to and a full quadratic_curve_to when the string is a move_to command followed by a full quadratic_curve_to command' do
75
90
  path = Parser.parse("M100 200Q1.233-34 255 12")
76
91
  path.class.should == Path
@@ -80,6 +95,7 @@ describe Parser do
80
95
  path.subpaths.last.directions[1].class.should == Directions::QuadraticCurveTo
81
96
  path.subpaths.last.directions[1].command_code.should == 'Q'
82
97
  end
98
+
83
99
  it 'should return a path object with one subpath containing a move_to and a short quadratic_curve_to when the string is a move_to command followed by a short quadratic_curve_to command' do
84
100
  path = Parser.parse("M100 200T255 12")
85
101
  path.class.should == Path
@@ -98,6 +114,7 @@ describe Parser do
98
114
  path.subpaths.last.directions[1].class.should == Directions::ArcTo
99
115
  path.subpaths.last.directions[1].command_code.should == 'A'
100
116
  end
117
+
101
118
  it 'should return a path object with one subpath containing a move_to, a line_to, and a close_path command when the string is a move_to command followed by a line_to followed by a close_path command' do
102
119
  path = Parser.parse("M100 200l-342.65 21Z")
103
120
  path.class.should == Path
@@ -121,6 +138,7 @@ describe Parser do
121
138
  path.subpaths.last.directions[1].target.x.should == 300
122
139
  path.subpaths.last.directions[1].target.y.should == 400
123
140
  end
141
+
124
142
  it 'should return a path object with one subpath containing two line_to directions when the string is a line_to command followed by implicit coordinates' do
125
143
  path = Parser.parse("L100 200 300 400")
126
144
  path.class.should == Path
@@ -133,6 +151,7 @@ describe Parser do
133
151
  path.subpaths.last.directions[1].target.x.should == 300
134
152
  path.subpaths.last.directions[1].target.y.should == 400
135
153
  end
154
+
136
155
  it 'should return a path object with one subpath containing a move_to and a line_to direction when the string is a move_to command followed by implicit coordinates' do
137
156
  path = Parser.parse("M100 200 300 400")
138
157
  path.class.should == Path
@@ -145,6 +164,7 @@ describe Parser do
145
164
  path.subpaths.last.directions[1].target.x.should == 300
146
165
  path.subpaths.last.directions[1].target.y.should == 400
147
166
  end
167
+
148
168
  it 'should return a path object with one subpath containing a move_to and two line_to directions when the string is a move_to command followed by more than one set of implicit coordinates' do
149
169
  path = Parser.parse("M100 200 300 400 500 600 ")
150
170
  path.class.should == Path
@@ -160,6 +180,7 @@ describe Parser do
160
180
  path.subpaths.last.directions[2].target.x.should == 500
161
181
  path.subpaths.last.directions[2].target.y.should == 600
162
182
  end
183
+
163
184
  it 'should return a path object with two subpaths containing one line_to directions each when the string is two move_to commands each followed by a line_to command' do
164
185
  path = Parser.parse("M100 200 332 -12.3M594 230-423 11.1")
165
186
  path.class.should == Path
@@ -178,6 +199,7 @@ describe Parser do
178
199
  path.subpaths[1].directions[1].target.x.should == -423
179
200
  path.subpaths[1].directions[1].target.y.should == 11.1
180
201
  end
202
+
181
203
  it 'should generate the same string given to it (assuming float values are used), if not changed in the interim' do
182
204
  path_string = "M100.0 200.0A255.0 12.0-123.0 1 0 23.0-93.4L100.0 200.0 300.0 400.0Q1.233-34.0 255.0 12.0T255.0 12.0H-342.65Z"
183
205
  path = Parser.parse(path_string)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-28 00:00:00.000000000 Z
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70355808993480 !ruby/object:Gem::Requirement
16
+ requirement: &8559400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70355808993480
24
+ version_requirements: *8559400
25
25
  description: A little gem for extracting and manipulating SVG vector path data.
26
26
  email: jeremy@jeremypholland.com
27
27
  executables: []
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 1.8.10
95
+ rubygems_version: 1.8.15
96
96
  signing_key:
97
97
  specification_version: 3
98
98
  summary: A little library to manipulate SVG path data