savage 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/savage/parser.rb +73 -75
- data/savage.gemspec +8 -8
- data/spec/savage/parser_spec.rb +7 -0
- metadata +34 -43
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.4
|
data/lib/savage/parser.rb
CHANGED
@@ -18,7 +18,7 @@ module Savage
|
|
18
18
|
subpaths = []
|
19
19
|
if move_index = parsable.index(/[Mm]/)
|
20
20
|
subpaths << parsable[0...move_index] if move_index > 0
|
21
|
-
parsable.scan /[Mm](?:\d|[.,-]|[LlHhVvQqCcTtSsAaZz]|\W)+/m do |match_group|
|
21
|
+
parsable.scan /[Mm](?:\d|[eE.,-]|[LlHhVvQqCcTtSsAaZz]|\W)+/m do |match_group|
|
22
22
|
subpaths << $&
|
23
23
|
end
|
24
24
|
else
|
@@ -35,7 +35,7 @@ module Savage
|
|
35
35
|
|
36
36
|
def extract_directions(parsable)
|
37
37
|
directions = []
|
38
|
-
parsable.scan /[MmLlHhVvQqCcTtSsAaZz](?:\d|[.,-]|\W)*/m do |match_group|
|
38
|
+
parsable.scan /[MmLlHhVvQqCcTtSsAaZz](?:\d|[eE.,-]|\W)*/m do |match_group|
|
39
39
|
direction = build_direction $&
|
40
40
|
if direction.kind_of?(Array)
|
41
41
|
directions.concat direction
|
@@ -47,89 +47,87 @@ module Savage
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def build_direction(parsable)
|
50
|
-
|
51
|
-
implicit_directions = false
|
50
|
+
directions = []
|
52
51
|
coordinates = extract_coordinates parsable
|
53
52
|
absolute = (parsable[0,1] == parsable[0,1].upcase) ? true : false
|
54
53
|
recurse_code = parsable[0,1]
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
raise TypeError if x.nil? || y.nil?
|
60
|
-
direction = Directions::MoveTo.new(x,y,absolute)
|
61
|
-
recurse_code = 'L'
|
62
|
-
when /[Ll]/
|
63
|
-
x = coordinates.shift
|
64
|
-
y = coordinates.shift
|
65
|
-
raise TypeError if x.nil? || y.nil?
|
66
|
-
direction = Directions::LineTo.new(x,y,absolute)
|
67
|
-
when /[Hh]/
|
68
|
-
target = coordinates.shift
|
69
|
-
raise TypeError if target.nil?
|
70
|
-
direction = Directions::HorizontalTo.new(target,absolute)
|
71
|
-
when /[Vv]/
|
72
|
-
target = coordinates.shift
|
73
|
-
raise TypeError if target.nil?
|
74
|
-
direction = Directions::VerticalTo.new(target,absolute)
|
75
|
-
when /[Cc]/
|
76
|
-
control_1_x = coordinates.shift
|
77
|
-
control_1_y = coordinates.shift
|
78
|
-
control_2_x = coordinates.shift
|
79
|
-
control_2_y = coordinates.shift
|
80
|
-
x = coordinates.shift
|
81
|
-
y = coordinates.shift
|
82
|
-
raise TypeError if x.nil? || y.nil? || control_1_x.nil? || control_1_y.nil? || control_2_x.nil? || control_2_y.nil?
|
83
|
-
direction = Directions::CubicCurveTo.new(control_1_x,control_1_y,control_2_x,control_2_y,x,y,absolute)
|
84
|
-
when /[Ss]/
|
85
|
-
control_2_x = coordinates.shift
|
86
|
-
control_2_y = coordinates.shift
|
87
|
-
x = coordinates.shift
|
88
|
-
y = coordinates.shift
|
89
|
-
raise TypeError if x.nil? || y.nil? || control_2_x.nil? || control_2_y.nil?
|
90
|
-
direction = Directions::CubicCurveTo.new(control_2_x,control_2_y,x,y,absolute)
|
91
|
-
when /[Qq]/
|
92
|
-
control_x = coordinates.shift
|
93
|
-
control_y = coordinates.shift
|
94
|
-
x = coordinates.shift
|
95
|
-
y = coordinates.shift
|
96
|
-
raise TypeError if x.nil? || y.nil? || control_x.nil? || control_y.nil?
|
97
|
-
direction = Directions::QuadraticCurveTo.new(control_x,control_y,x,y,absolute)
|
98
|
-
when /[Tt]/
|
99
|
-
x = coordinates.shift
|
100
|
-
y = coordinates.shift
|
101
|
-
raise TypeError if x.nil? || y.nil?
|
102
|
-
direction = Directions::QuadraticCurveTo.new(x,y,absolute)
|
103
|
-
when /[Aa]/
|
104
|
-
rx = coordinates.shift
|
105
|
-
ry = coordinates.shift
|
106
|
-
rotation = coordinates.shift
|
107
|
-
large_arc = (coordinates.shift > 0) ? true : false
|
108
|
-
sweep = (coordinates.shift > 0) ? true : false
|
109
|
-
x = coordinates.shift
|
110
|
-
y = coordinates.shift
|
111
|
-
raise TypeError if x.nil? || y.nil? || rx.nil? || ry.nil? || rotation.nil?
|
112
|
-
direction = Directions::ArcTo.new(rx,ry,rotation,large_arc,sweep,x,y,absolute)
|
113
|
-
when /[Zz]/
|
114
|
-
direction = Directions::ClosePath.new(absolute)
|
115
|
-
when /[^MmLlHhVvCcSsQqTtAaZz]/
|
116
|
-
coordinates = []
|
117
|
-
raise TypeError
|
54
|
+
|
55
|
+
# we need to handle this separately, since ClosePath doesn't take any coordinates
|
56
|
+
if coordinates.empty? && recurse_code =~ /[Zz]/
|
57
|
+
directions << Directions::ClosePath.new(absolute)
|
118
58
|
end
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
59
|
+
|
60
|
+
until coordinates.empty?
|
61
|
+
case recurse_code
|
62
|
+
when /[Mm]/
|
63
|
+
x = coordinates.shift
|
64
|
+
y = coordinates.shift
|
65
|
+
raise TypeError if x.nil? || y.nil?
|
66
|
+
directions << Directions::MoveTo.new(x,y,absolute)
|
67
|
+
recurse_code = 'L'
|
68
|
+
when /[Ll]/
|
69
|
+
x = coordinates.shift
|
70
|
+
y = coordinates.shift
|
71
|
+
raise TypeError if x.nil? || y.nil?
|
72
|
+
directions << Directions::LineTo.new(x,y,absolute)
|
73
|
+
when /[Hh]/
|
74
|
+
target = coordinates.shift
|
75
|
+
raise TypeError if target.nil?
|
76
|
+
directions << Directions::HorizontalTo.new(target,absolute)
|
77
|
+
when /[Vv]/
|
78
|
+
target = coordinates.shift
|
79
|
+
raise TypeError if target.nil?
|
80
|
+
directions << Directions::VerticalTo.new(target,absolute)
|
81
|
+
when /[Cc]/
|
82
|
+
control_1_x = coordinates.shift
|
83
|
+
control_1_y = coordinates.shift
|
84
|
+
control_2_x = coordinates.shift
|
85
|
+
control_2_y = coordinates.shift
|
86
|
+
x = coordinates.shift
|
87
|
+
y = coordinates.shift
|
88
|
+
raise TypeError if x.nil? || y.nil? || control_1_x.nil? || control_1_y.nil? || control_2_x.nil? || control_2_y.nil?
|
89
|
+
directions << Directions::CubicCurveTo.new(control_1_x,control_1_y,control_2_x,control_2_y,x,y,absolute)
|
90
|
+
when /[Ss]/
|
91
|
+
control_2_x = coordinates.shift
|
92
|
+
control_2_y = coordinates.shift
|
93
|
+
x = coordinates.shift
|
94
|
+
y = coordinates.shift
|
95
|
+
raise TypeError if x.nil? || y.nil? || control_2_x.nil? || control_2_y.nil?
|
96
|
+
directions << Directions::CubicCurveTo.new(control_2_x,control_2_y,x,y,absolute)
|
97
|
+
when /[Qq]/
|
98
|
+
control_x = coordinates.shift
|
99
|
+
control_y = coordinates.shift
|
100
|
+
x = coordinates.shift
|
101
|
+
y = coordinates.shift
|
102
|
+
raise TypeError if x.nil? || y.nil? || control_x.nil? || control_y.nil?
|
103
|
+
directions << Directions::QuadraticCurveTo.new(control_x,control_y,x,y,absolute)
|
104
|
+
when /[Tt]/
|
105
|
+
x = coordinates.shift
|
106
|
+
y = coordinates.shift
|
107
|
+
raise TypeError if x.nil? || y.nil?
|
108
|
+
directions << Directions::QuadraticCurveTo.new(x,y,absolute)
|
109
|
+
when /[Aa]/
|
110
|
+
rx = coordinates.shift
|
111
|
+
ry = coordinates.shift
|
112
|
+
rotation = coordinates.shift
|
113
|
+
large_arc = (coordinates.shift > 0) ? true : false
|
114
|
+
sweep = (coordinates.shift > 0) ? true : false
|
115
|
+
x = coordinates.shift
|
116
|
+
y = coordinates.shift
|
117
|
+
raise TypeError if x.nil? || y.nil? || rx.nil? || ry.nil? || rotation.nil?
|
118
|
+
directions << Directions::ArcTo.new(rx,ry,rotation,large_arc,sweep,x,y,absolute)
|
119
|
+
when /[^MmLlHhVvCcSsQqTtAaZz]/
|
120
|
+
coordinates = []
|
121
|
+
raise TypeError
|
125
122
|
end
|
126
123
|
end
|
127
|
-
|
124
|
+
|
125
|
+
directions
|
128
126
|
end
|
129
127
|
|
130
128
|
def extract_coordinates(command_string)
|
131
129
|
coordinates = []
|
132
|
-
command_string.scan(/-?\d+(\.\d+)?/) do |match_group|
|
130
|
+
command_string.scan(/-?\d+(\.\d+)?([eE]-?\d+)?/) do |match_group|
|
133
131
|
coordinates << $&.to_f
|
134
132
|
end
|
135
133
|
coordinates
|
data/savage.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.1.
|
7
|
+
s.name = "savage"
|
8
|
+
s.version = "1.1.4"
|
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 =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-12-02"
|
13
|
+
s.description = "A little gem for extracting and manipulating SVG vector path data."
|
14
|
+
s.email = "jeremy@jeremypholland.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -60,10 +60,10 @@ Gem::Specification.new do |s|
|
|
60
60
|
"spec/shared/point_target.rb",
|
61
61
|
"spec/spec_helper.rb"
|
62
62
|
]
|
63
|
-
s.homepage =
|
63
|
+
s.homepage = "http://github.com/awebneck/savage"
|
64
64
|
s.require_paths = ["lib"]
|
65
|
-
s.rubygems_version =
|
66
|
-
s.summary =
|
65
|
+
s.rubygems_version = "1.8.10"
|
66
|
+
s.summary = "A little library to manipulate SVG path data"
|
67
67
|
|
68
68
|
if s.respond_to? :specification_version then
|
69
69
|
s.specification_version = 3
|
data/spec/savage/parser_spec.rb
CHANGED
@@ -191,5 +191,12 @@ describe Parser do
|
|
191
191
|
path.subpaths[0].directions.length.should == 2
|
192
192
|
path.subpaths[1].directions.length.should == 6
|
193
193
|
end
|
194
|
+
|
195
|
+
it "should support scienfitic notation in paths (eg. 2e-5)" do
|
196
|
+
# this is a 100x100 square
|
197
|
+
path = Parser.parse "M 0,0 L 1e2,0 100,1000e-1 L 0,100"
|
198
|
+
points = path.directions.map{|d| [d.target.x, d.target.y] }
|
199
|
+
points.should == [[0.0, 0.0], [100.0, 0.0], [100.0, 100.0], [0.0, 100.0]]
|
200
|
+
end
|
194
201
|
end
|
195
202
|
end
|
metadata
CHANGED
@@ -1,50 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: savage
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.4
|
4
5
|
prerelease:
|
5
|
-
version: 1.1.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Jeremy Holland
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: rspec
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70224833773340 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
24
21
|
version: 2.3.0
|
25
22
|
type: :development
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70224833773340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
requirement: &70224833766920 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
35
32
|
version: 2.3.5
|
36
33
|
type: :runtime
|
37
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70224833766920
|
38
36
|
description: A little gem for extracting and manipulating SVG vector path data.
|
39
37
|
email: jeremy@jeremypholland.com
|
40
38
|
executables: []
|
41
|
-
|
42
39
|
extensions: []
|
43
|
-
|
44
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
45
41
|
- LICENSE
|
46
42
|
- README.rdoc
|
47
|
-
files:
|
43
|
+
files:
|
48
44
|
- .document
|
49
45
|
- .rspec
|
50
46
|
- LICENSE
|
@@ -87,33 +83,28 @@ files:
|
|
87
83
|
- spec/shared/direction.rb
|
88
84
|
- spec/shared/point_target.rb
|
89
85
|
- spec/spec_helper.rb
|
90
|
-
has_rdoc: true
|
91
86
|
homepage: http://github.com/awebneck/savage
|
92
87
|
licenses: []
|
93
|
-
|
94
88
|
post_install_message:
|
95
89
|
rdoc_options: []
|
96
|
-
|
97
|
-
require_paths:
|
90
|
+
require_paths:
|
98
91
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
93
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version:
|
105
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
99
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version:
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
111
104
|
requirements: []
|
112
|
-
|
113
105
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.8.10
|
115
107
|
signing_key:
|
116
108
|
specification_version: 3
|
117
109
|
summary: A little library to manipulate SVG path data
|
118
110
|
test_files: []
|
119
|
-
|