prawn-svg 0.34.1 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +19 -0
- data/.github/workflows/test.yml +14 -27
- data/.gitignore +0 -1
- data/.rubocop.yml +86 -0
- data/.rubocop_todo.yml +51 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +81 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/prawn/svg/attributes/clip_path.rb +3 -3
- data/lib/prawn/svg/attributes/opacity.rb +3 -3
- data/lib/prawn/svg/attributes/stroke.rb +9 -9
- data/lib/prawn/svg/attributes/transform.rb +2 -2
- data/lib/prawn/svg/attributes.rb +1 -1
- data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +17 -15
- data/lib/prawn/svg/calculators/aspect_ratio.rb +16 -14
- data/lib/prawn/svg/calculators/document_sizing.rb +9 -10
- data/lib/prawn/svg/calculators/pixels.rb +8 -5
- data/lib/prawn/svg/color.rb +209 -212
- data/lib/prawn/svg/css/font_family_parser.rb +2 -2
- data/lib/prawn/svg/css/selector_parser.rb +39 -35
- data/lib/prawn/svg/css/stylesheets.rb +31 -24
- data/lib/prawn/svg/css/values_parser.rb +68 -0
- data/lib/prawn/svg/document.rb +6 -5
- data/lib/prawn/svg/elements/base.rb +39 -34
- data/lib/prawn/svg/elements/circle.rb +4 -4
- data/lib/prawn/svg/elements/clip_path.rb +0 -1
- data/lib/prawn/svg/elements/depth_first_base.rb +6 -6
- data/lib/prawn/svg/elements/ellipse.rb +3 -4
- data/lib/prawn/svg/elements/gradient.rb +49 -51
- data/lib/prawn/svg/elements/image.rb +5 -5
- data/lib/prawn/svg/elements/marker.rb +6 -7
- data/lib/prawn/svg/elements/path.rb +46 -47
- data/lib/prawn/svg/elements/polygon.rb +1 -1
- data/lib/prawn/svg/elements/polyline.rb +2 -2
- data/lib/prawn/svg/elements/rect.rb +3 -3
- data/lib/prawn/svg/elements/text.rb +1 -1
- data/lib/prawn/svg/elements/text_component.rb +22 -22
- data/lib/prawn/svg/elements/use.rb +4 -8
- data/lib/prawn/svg/elements/viewport.rb +5 -4
- data/lib/prawn/svg/elements.rb +30 -29
- data/lib/prawn/svg/extension.rb +2 -1
- data/lib/prawn/svg/font.rb +7 -7
- data/lib/prawn/svg/font_registry.rb +13 -13
- data/lib/prawn/svg/gradients.rb +3 -2
- data/lib/prawn/svg/interface.rb +4 -3
- data/lib/prawn/svg/loaders/data.rb +2 -2
- data/lib/prawn/svg/loaders/file.rb +12 -14
- data/lib/prawn/svg/loaders/web.rb +4 -8
- data/lib/prawn/svg/pathable.rb +41 -37
- data/lib/prawn/svg/properties.rb +34 -33
- data/lib/prawn/svg/renderer.rb +7 -7
- data/lib/prawn/svg/state.rb +1 -1
- data/lib/prawn/svg/transform_parser.rb +5 -5
- data/lib/prawn/svg/ttf.rb +21 -17
- data/lib/prawn/svg/url_loader.rb +1 -1
- data/lib/prawn/svg/version.rb +1 -1
- data/lib/prawn-svg.rb +1 -0
- data/prawn-svg.gemspec +4 -6
- data/spec/integration_spec.rb +77 -70
- data/spec/prawn/svg/attributes/opacity_spec.rb +11 -15
- data/spec/prawn/svg/attributes/transform_spec.rb +6 -6
- data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +50 -50
- data/spec/prawn/svg/calculators/document_sizing_spec.rb +35 -35
- data/spec/prawn/svg/calculators/pixels_spec.rb +31 -30
- data/spec/prawn/svg/color_spec.rb +31 -31
- data/spec/prawn/svg/css/font_family_parser_spec.rb +12 -12
- data/spec/prawn/svg/css/selector_parser_spec.rb +21 -21
- data/spec/prawn/svg/css/stylesheets_spec.rb +51 -43
- data/spec/prawn/svg/css/values_parser_spec.rb +16 -0
- data/spec/prawn/svg/document_spec.rb +15 -14
- data/spec/prawn/svg/elements/base_spec.rb +39 -34
- data/spec/prawn/svg/elements/gradient_spec.rb +39 -39
- data/spec/prawn/svg/elements/line_spec.rb +22 -22
- data/spec/prawn/svg/elements/marker_spec.rb +44 -47
- data/spec/prawn/svg/elements/path_spec.rb +134 -110
- data/spec/prawn/svg/elements/polygon_spec.rb +18 -18
- data/spec/prawn/svg/elements/polyline_spec.rb +16 -16
- data/spec/prawn/svg/elements/text_spec.rb +149 -127
- data/spec/prawn/svg/font_registry_spec.rb +34 -34
- data/spec/prawn/svg/font_spec.rb +4 -4
- data/spec/prawn/svg/interface_spec.rb +47 -39
- data/spec/prawn/svg/loaders/data_spec.rb +21 -21
- data/spec/prawn/svg/loaders/file_spec.rb +43 -40
- data/spec/prawn/svg/loaders/web_spec.rb +15 -15
- data/spec/prawn/svg/pathable_spec.rb +21 -21
- data/spec/prawn/svg/properties_spec.rb +51 -51
- data/spec/prawn/svg/transform_parser_spec.rb +12 -12
- data/spec/prawn/svg/ttf_spec.rb +5 -5
- data/spec/prawn/svg/url_loader_spec.rb +25 -23
- data/spec/spec_helper.rb +4 -4
- metadata +12 -143
@@ -17,30 +17,31 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
17
17
|
SVG
|
18
18
|
end
|
19
19
|
|
20
|
-
let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {width: 800, height: 600}) }
|
21
|
-
let(:state) { Prawn::SVG::State.new }
|
20
|
+
let(:document) { Prawn::SVG::Document.new(svg, [800, 600], { width: 800, height: 600 }) }
|
22
21
|
|
23
|
-
|
24
|
-
Prawn::SVG::
|
22
|
+
def new_state
|
23
|
+
state = Prawn::SVG::State.new
|
24
|
+
state.viewport_sizing = document.sizing
|
25
|
+
state
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
Prawn::SVG::Elements::
|
28
|
+
let(:line_element) do
|
29
|
+
Prawn::SVG::Elements::Line.new(document, document.root.elements[2], [], new_state)
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
subject do
|
33
|
+
Prawn::SVG::Elements::Marker.new(document, document.root.elements[1], [], new_state)
|
33
34
|
end
|
34
35
|
|
35
|
-
describe
|
36
|
-
it
|
36
|
+
describe '#parse' do
|
37
|
+
it 'forces display none' do
|
37
38
|
subject.parse
|
38
39
|
expect(subject.properties.display).to eq 'none'
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
describe
|
43
|
-
it
|
43
|
+
describe '#apply_marker' do
|
44
|
+
it 'adds the line and its marker to the call stack' do
|
44
45
|
subject.process
|
45
46
|
line_element.process
|
46
47
|
|
@@ -54,41 +55,37 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
54
55
|
# in section 11.6.3.
|
55
56
|
|
56
57
|
expect(line_element.base_calls).to eq [
|
57
|
-
[
|
58
|
-
[
|
59
|
-
[
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
],
|
64
|
-
[
|
65
|
-
[
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
[
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
]
|
89
|
-
]
|
90
|
-
],
|
91
|
-
["restore", [], {}, []]
|
58
|
+
['stroke_color', ['000000'], {}, []],
|
59
|
+
['line_width', [100.0], {}, []],
|
60
|
+
['stroke', [], {}, [
|
61
|
+
['move_to', [[0.0, 600.0]], {}, []],
|
62
|
+
['line_to', [[10.0, 590.0]], {}, []]
|
63
|
+
]],
|
64
|
+
['save', [], {}, []],
|
65
|
+
['transformation_matrix', [1, 0, 0, 1, 10, -10], {}, []],
|
66
|
+
['rotate', [-45], { origin: [0, 600.0] }, [
|
67
|
+
['transformation_matrix', [100.0, 0, 0, 100.0, 0, 0], {}, []],
|
68
|
+
['transformation_matrix', [1, 0, 0, 1, -0.0, 1.5], {}, []],
|
69
|
+
['rectangle', [[-0.5, 600.0], 4.0, 3.0], {}, []],
|
70
|
+
['clip', [], {}, []],
|
71
|
+
['transformation_matrix', [0.3, 0, 0, 0.3, 0, 0], {}, []],
|
72
|
+
['transparent', [1.0, 1.0], {}, [
|
73
|
+
['fill_color', ['000000'], {}, []],
|
74
|
+
['line_width', [1.0], {}, []],
|
75
|
+
['cap_style', [:butt], {}, []],
|
76
|
+
['join_style', [:miter], {}, []],
|
77
|
+
['undash', [], {}, []],
|
78
|
+
['save', [], {}, []],
|
79
|
+
['fill', [], {}, [
|
80
|
+
['move_to', [[0.0, 600.0]], {}, []],
|
81
|
+
['line_to', [[10.0, 595.0]], {}, []],
|
82
|
+
['line_to', [[0.0, 590.0]], {}, []],
|
83
|
+
['close_path', [], {}, []]
|
84
|
+
]],
|
85
|
+
['restore', [], {}, []]
|
86
|
+
]]
|
87
|
+
]],
|
88
|
+
['restore', [], {}, []]
|
92
89
|
]
|
93
90
|
end
|
94
91
|
end
|
@@ -1,45 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Prawn::SVG::Elements::Path do
|
4
|
-
let(:source) { double(name:
|
4
|
+
let(:source) { double(name: 'path', attributes: {}) }
|
5
5
|
let(:state) { Prawn::SVG::State.new }
|
6
6
|
let(:path) { Prawn::SVG::Elements::Path.new(nil, source, [], state) }
|
7
7
|
|
8
8
|
before do
|
9
|
-
allow(path).to receive(:attributes).and_return(
|
9
|
+
allow(path).to receive(:attributes).and_return('d' => d)
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
context
|
14
|
-
let(:d) {
|
12
|
+
describe 'command parsing' do
|
13
|
+
context 'with a valid path' do
|
14
|
+
let(:d) { 'm12.34 -56.78 1 2M4 5 12-34 -.5.7+3 2.3e3 4e4 4e+4 L31,-2e-5L 6,7 Z ZZa50 50 0 100 100' }
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'correctly parses' do
|
17
17
|
calls = []
|
18
|
-
allow(path).to receive(:parse_path_command) {|*args| calls << args}
|
18
|
+
allow(path).to receive(:parse_path_command) { |*args| calls << args }
|
19
19
|
path.parse
|
20
20
|
|
21
21
|
expect(calls).to eq [
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
[
|
22
|
+
['m', [[12.34, -56.78], [1, 2]]],
|
23
|
+
['M', [[4, 5], [12, -34], [-0.5, 0.7], [3, 2.3e3], [4e4, 4e4]]],
|
24
|
+
['L', [[31, -2e-5]]],
|
25
|
+
['L', [[6, 7]]],
|
26
|
+
['Z', []],
|
27
|
+
['Z', []],
|
28
|
+
['Z', []],
|
29
|
+
['a', [[50, 50, 0, 1, 0, 0, 100]]]
|
30
30
|
]
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
35
|
-
let(:d) {
|
34
|
+
context 'with m and M commands' do
|
35
|
+
let(:d) { 'M 1,2 3,4 m 5,6 7,8' }
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'treats subsequent points to m/M command as relative/absolute depending on command' do
|
38
38
|
[
|
39
|
-
[
|
40
|
-
[
|
41
|
-
[
|
42
|
-
[
|
39
|
+
['M', [[1, 2], [3, 4]]],
|
40
|
+
['L', [[3, 4]]],
|
41
|
+
['m', [[5, 6], [7, 8]]],
|
42
|
+
['l', [[7, 8]]]
|
43
43
|
].each do |args|
|
44
44
|
expect(path).to receive(:parse_path_command).with(*args).and_call_original
|
45
45
|
end
|
@@ -48,61 +48,64 @@ describe Prawn::SVG::Elements::Path do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
52
|
-
let(:d) {
|
51
|
+
context 'with an empty path' do
|
52
|
+
let(:d) { '' }
|
53
53
|
|
54
|
-
it
|
54
|
+
it 'correctly parses' do
|
55
55
|
expect(path).not_to receive(:run_path_command)
|
56
56
|
path.parse
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
context
|
61
|
-
let(:d) {
|
60
|
+
context 'with a path with invalid characters' do
|
61
|
+
let(:d) { 'M 10 % 20' }
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'raises' do
|
64
64
|
expect { path.parse }.to raise_error(Prawn::SVG::Elements::Base::SkipElementError)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context
|
69
|
-
let(:d) {
|
68
|
+
context 'with a path with numerical data before a command letter' do
|
69
|
+
let(:d) { 'M 10 % 20' }
|
70
70
|
|
71
|
-
it
|
71
|
+
it 'raises' do
|
72
72
|
expect { path.parse }.to raise_error(Prawn::SVG::Elements::Base::SkipElementError)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
context
|
78
|
-
subject
|
77
|
+
context 'when given an M path' do
|
78
|
+
subject do
|
79
|
+
path.parse
|
80
|
+
path.commands
|
81
|
+
end
|
79
82
|
|
80
|
-
context
|
81
|
-
let(:d) {
|
83
|
+
context 'with typical arguments' do
|
84
|
+
let(:d) { 'M 100 200 M 200 300 m 10 20' }
|
82
85
|
|
83
|
-
it
|
86
|
+
it 'issues a move command' do
|
84
87
|
expect(subject).to eq [
|
85
88
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
86
89
|
Prawn::SVG::Elements::Path::Move.new([200.0, 300.0]),
|
87
|
-
Prawn::SVG::Elements::Path::Move.new([210.0, 320.0])
|
90
|
+
Prawn::SVG::Elements::Path::Move.new([210.0, 320.0])
|
88
91
|
]
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
92
|
-
context
|
93
|
-
let(:d) {
|
95
|
+
context 'with only one argument' do
|
96
|
+
let(:d) { 'M 100 200 M 100' }
|
94
97
|
|
95
|
-
it
|
98
|
+
it 'bails out' do
|
96
99
|
expect(subject).to eq [
|
97
100
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
98
101
|
]
|
99
102
|
end
|
100
103
|
end
|
101
104
|
|
102
|
-
context
|
103
|
-
let(:d) {
|
105
|
+
context 'with no arguments' do
|
106
|
+
let(:d) { 'M 100 200 M' }
|
104
107
|
|
105
|
-
it
|
108
|
+
it 'bails out' do
|
106
109
|
expect(subject).to eq [
|
107
110
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
108
111
|
]
|
@@ -110,25 +113,28 @@ describe Prawn::SVG::Elements::Path do
|
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
113
|
-
context
|
114
|
-
subject
|
116
|
+
context 'when given an L path' do
|
117
|
+
subject do
|
118
|
+
path.parse
|
119
|
+
path.commands
|
120
|
+
end
|
115
121
|
|
116
|
-
context
|
117
|
-
let(:d) {
|
122
|
+
context 'with typical arguments' do
|
123
|
+
let(:d) { 'M 100 200 L 200 300 l 10 20' }
|
118
124
|
|
119
|
-
it
|
125
|
+
it 'issues a line command' do
|
120
126
|
expect(subject).to eq [
|
121
127
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
122
128
|
Prawn::SVG::Elements::Path::Line.new([200.0, 300.0]),
|
123
|
-
Prawn::SVG::Elements::Path::Line.new([210.0, 320.0])
|
129
|
+
Prawn::SVG::Elements::Path::Line.new([210.0, 320.0])
|
124
130
|
]
|
125
131
|
end
|
126
132
|
end
|
127
133
|
|
128
|
-
context
|
129
|
-
let(:d) {
|
134
|
+
context 'with only one argument' do
|
135
|
+
let(:d) { 'M 100 200 L 100' }
|
130
136
|
|
131
|
-
it
|
137
|
+
it 'bails out' do
|
132
138
|
expect(subject).to eq [
|
133
139
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
134
140
|
]
|
@@ -136,24 +142,27 @@ describe Prawn::SVG::Elements::Path do
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
139
|
-
context
|
140
|
-
subject
|
145
|
+
context 'when given a C path' do
|
146
|
+
subject do
|
147
|
+
path.parse
|
148
|
+
path.commands
|
149
|
+
end
|
141
150
|
|
142
|
-
context
|
143
|
-
let(:d) {
|
151
|
+
context 'with typical arguments' do
|
152
|
+
let(:d) { 'M 100 200 C 10 20 30 40 200 300' }
|
144
153
|
|
145
|
-
it
|
154
|
+
it 'issues a curve command' do
|
146
155
|
expect(subject).to eq [
|
147
156
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
148
|
-
Prawn::SVG::Elements::Path::Curve.new([200.0, 300.0], [10, 20], [30, 40])
|
157
|
+
Prawn::SVG::Elements::Path::Curve.new([200.0, 300.0], [10, 20], [30, 40])
|
149
158
|
]
|
150
159
|
end
|
151
160
|
end
|
152
161
|
|
153
|
-
context
|
154
|
-
let(:d) {
|
162
|
+
context 'with incomplete arguments' do
|
163
|
+
let(:d) { 'M 100 200 C 10 20 30 40 50' }
|
155
164
|
|
156
|
-
it
|
165
|
+
it 'bails out' do
|
157
166
|
expect(subject).to eq [
|
158
167
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
159
168
|
]
|
@@ -161,24 +170,27 @@ describe Prawn::SVG::Elements::Path do
|
|
161
170
|
end
|
162
171
|
end
|
163
172
|
|
164
|
-
context
|
165
|
-
subject
|
173
|
+
context 'when given an S path' do
|
174
|
+
subject do
|
175
|
+
path.parse
|
176
|
+
path.commands
|
177
|
+
end
|
166
178
|
|
167
|
-
context
|
168
|
-
let(:d) {
|
179
|
+
context 'with typical arguments' do
|
180
|
+
let(:d) { 'M 100 200 S 30 40 200 300' }
|
169
181
|
|
170
|
-
it
|
182
|
+
it 'issues a curve command' do
|
171
183
|
expect(subject).to eq [
|
172
184
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
173
|
-
Prawn::SVG::Elements::Path::Curve.new([200.0, 300.0], [100, 200], [30, 40])
|
185
|
+
Prawn::SVG::Elements::Path::Curve.new([200.0, 300.0], [100, 200], [30, 40])
|
174
186
|
]
|
175
187
|
end
|
176
188
|
end
|
177
189
|
|
178
|
-
context
|
179
|
-
let(:d) {
|
190
|
+
context 'with incomplete arguments' do
|
191
|
+
let(:d) { 'M 100 200 S 30 40 50' }
|
180
192
|
|
181
|
-
it
|
193
|
+
it 'bails out' do
|
182
194
|
expect(subject).to eq [
|
183
195
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
184
196
|
]
|
@@ -186,13 +198,16 @@ describe Prawn::SVG::Elements::Path do
|
|
186
198
|
end
|
187
199
|
end
|
188
200
|
|
189
|
-
context
|
190
|
-
subject
|
201
|
+
context 'when given a Q path' do
|
202
|
+
subject do
|
203
|
+
path.parse
|
204
|
+
path.commands
|
205
|
+
end
|
191
206
|
|
192
|
-
context
|
193
|
-
let(:d) {
|
207
|
+
context 'with typical arguments' do
|
208
|
+
let(:d) { 'M 0 0 Q 600 300 300 600' }
|
194
209
|
|
195
|
-
it
|
210
|
+
it 'issues a curve command' do
|
196
211
|
expect(subject).to eq [
|
197
212
|
Prawn::SVG::Elements::Path::Move.new([0, 0]),
|
198
213
|
Prawn::SVG::Elements::Path::Curve.new([300.0, 600.0], [400, 200], [500, 400])
|
@@ -200,10 +215,10 @@ describe Prawn::SVG::Elements::Path do
|
|
200
215
|
end
|
201
216
|
end
|
202
217
|
|
203
|
-
context
|
204
|
-
let(:d) {
|
218
|
+
context 'with incomplete arguments' do
|
219
|
+
let(:d) { 'M 100 200 Q 30 40 50' }
|
205
220
|
|
206
|
-
it
|
221
|
+
it 'bails out' do
|
207
222
|
expect(subject).to eq [
|
208
223
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
209
224
|
]
|
@@ -211,13 +226,16 @@ describe Prawn::SVG::Elements::Path do
|
|
211
226
|
end
|
212
227
|
end
|
213
228
|
|
214
|
-
context
|
215
|
-
subject
|
229
|
+
context 'when given a T path' do
|
230
|
+
subject do
|
231
|
+
path.parse
|
232
|
+
path.commands
|
233
|
+
end
|
216
234
|
|
217
|
-
context
|
218
|
-
let(:d) {
|
235
|
+
context 'with typical arguments' do
|
236
|
+
let(:d) { 'M 0 0 T 300 600' }
|
219
237
|
|
220
|
-
it
|
238
|
+
it 'issues a curve command' do
|
221
239
|
expect(subject).to eq [
|
222
240
|
Prawn::SVG::Elements::Path::Move.new([0, 0]),
|
223
241
|
Prawn::SVG::Elements::Path::Curve.new([300.0, 600.0], [0, 0], [100, 200])
|
@@ -225,10 +243,10 @@ describe Prawn::SVG::Elements::Path do
|
|
225
243
|
end
|
226
244
|
end
|
227
245
|
|
228
|
-
context
|
229
|
-
let(:d) {
|
246
|
+
context 'with incomplete arguments' do
|
247
|
+
let(:d) { 'M 100 200 T 30' }
|
230
248
|
|
231
|
-
it
|
249
|
+
it 'bails out' do
|
232
250
|
expect(subject).to eq [
|
233
251
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
234
252
|
]
|
@@ -236,35 +254,40 @@ describe Prawn::SVG::Elements::Path do
|
|
236
254
|
end
|
237
255
|
end
|
238
256
|
|
239
|
-
context
|
240
|
-
subject
|
257
|
+
context 'when given an A path' do
|
258
|
+
subject do
|
259
|
+
path.parse
|
260
|
+
path.commands
|
261
|
+
end
|
241
262
|
|
242
|
-
context
|
243
|
-
let(:d) {
|
263
|
+
context 'that is pretty normal' do
|
264
|
+
let(:d) { 'M 100 200 A 10 10 0 0 1 200 200' }
|
244
265
|
|
245
|
-
it
|
266
|
+
it 'uses bezier curves to approximate an arc path' do
|
246
267
|
expect(subject).to eq [
|
247
268
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
248
|
-
Prawn::SVG::Elements::Path::Curve.new([150.0, 150.0], [100.0, 172.57081148225683],
|
249
|
-
|
269
|
+
Prawn::SVG::Elements::Path::Curve.new([150.0, 150.0], [100.0, 172.57081148225683],
|
270
|
+
[122.57081148225683, 150.0]),
|
271
|
+
Prawn::SVG::Elements::Path::Curve.new([200.0, 200.0], [177.42918851774317, 150.0],
|
272
|
+
[200.0, 172.57081148225683])
|
250
273
|
]
|
251
274
|
end
|
252
275
|
end
|
253
276
|
|
254
|
-
context
|
255
|
-
let(:d) {
|
277
|
+
context 'with an identical start and end point' do
|
278
|
+
let(:d) { 'M 100 200 A 30 30 0 0 1 100 200' }
|
256
279
|
|
257
|
-
it
|
280
|
+
it 'ignores the path' do
|
258
281
|
expect(subject).to eq [
|
259
|
-
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
282
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
260
283
|
]
|
261
284
|
end
|
262
285
|
end
|
263
286
|
|
264
|
-
context
|
265
|
-
let(:d) {
|
287
|
+
context 'with an rx of 0' do
|
288
|
+
let(:d) { 'M 100 200 A 0 10 0 0 1 200 200' }
|
266
289
|
|
267
|
-
it
|
290
|
+
it 'substitutes a line_to' do
|
268
291
|
expect(subject).to eq [
|
269
292
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
270
293
|
Prawn::SVG::Elements::Path::Line.new([200.0, 200.0])
|
@@ -272,10 +295,10 @@ describe Prawn::SVG::Elements::Path do
|
|
272
295
|
end
|
273
296
|
end
|
274
297
|
|
275
|
-
context
|
276
|
-
let(:d) {
|
298
|
+
context 'with an ry of 0' do
|
299
|
+
let(:d) { 'M 100 200 A 10 0 0 0 1 200 200' }
|
277
300
|
|
278
|
-
it
|
301
|
+
it 'substitutes a line_to' do
|
279
302
|
expect(subject).to eq [
|
280
303
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
281
304
|
Prawn::SVG::Elements::Path::Line.new([200.0, 200.0])
|
@@ -283,24 +306,25 @@ describe Prawn::SVG::Elements::Path do
|
|
283
306
|
end
|
284
307
|
end
|
285
308
|
|
286
|
-
context
|
287
|
-
let(:d) {
|
309
|
+
context 'with incomplete arguments' do
|
310
|
+
let(:d) { 'M 100 200 A 10 20 30 L 10 20' }
|
288
311
|
|
289
|
-
it
|
312
|
+
it 'bails out' do
|
290
313
|
expect(subject).to eq [
|
291
314
|
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
292
315
|
]
|
293
316
|
end
|
294
317
|
end
|
295
318
|
|
296
|
-
context
|
297
|
-
let(:d) {
|
319
|
+
context 'with highly-compressed flags' do
|
320
|
+
let(:d) { 'M100,100a50 50 0 100 100' }
|
298
321
|
|
299
|
-
it
|
322
|
+
it 'correctly parses them' do
|
300
323
|
expect(subject).to eq [
|
301
324
|
Prawn::SVG::Elements::Path::Move.new([100.0, 100.0]),
|
302
325
|
Prawn::SVG::Elements::Path::Curve.new([50.0, 150.0], [72.57081148225681, 100.0], [50.0, 122.57081148225681]),
|
303
|
-
Prawn::SVG::Elements::Path::Curve.new([99.99999999999999, 200.0], [50.0, 177.42918851774317],
|
326
|
+
Prawn::SVG::Elements::Path::Curve.new([99.99999999999999, 200.0], [50.0, 177.42918851774317],
|
327
|
+
[72.5708114822568, 200.0])
|
304
328
|
]
|
305
329
|
end
|
306
330
|
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Prawn::SVG::Elements::Polygon do
|
4
|
-
let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {width: 800, height: 600}) }
|
4
|
+
let(:document) { Prawn::SVG::Document.new(svg, [800, 600], { width: 800, height: 600 }) }
|
5
5
|
|
6
6
|
subject do
|
7
7
|
Prawn::SVG::Elements::Polygon.new(document, document.root, [], Prawn::SVG::State.new)
|
8
8
|
end
|
9
9
|
|
10
|
-
context
|
10
|
+
context 'with a valid points attribute' do
|
11
11
|
let(:svg) { '<polygon points="10 10 20,20 30,30" />' }
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'renders the polygon' do
|
14
14
|
subject.process
|
15
15
|
expect(subject.base_calls).to eq [
|
16
|
-
[
|
17
|
-
[
|
18
|
-
[
|
19
|
-
[
|
20
|
-
[
|
21
|
-
]
|
16
|
+
['fill', [], {}, [
|
17
|
+
['move_to', [[10.0, 590.0]], {}, []],
|
18
|
+
['line_to', [[20.0, 580.0]], {}, []],
|
19
|
+
['line_to', [[30.0, 570.0]], {}, []],
|
20
|
+
['close_path', [], {}, []]
|
21
|
+
]]
|
22
22
|
]
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
context
|
26
|
+
context 'with a polygon that has an odd number of arguments' do
|
27
27
|
let(:svg) { '<polygon points="10 10 20,20 30" />' }
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'ignores the last one' do
|
30
30
|
subject.process
|
31
31
|
expect(subject.base_calls).to eq [
|
32
|
-
[
|
33
|
-
[
|
34
|
-
[
|
35
|
-
[
|
36
|
-
]
|
32
|
+
['fill', [], {}, [
|
33
|
+
['move_to', [[10.0, 590.0]], {}, []],
|
34
|
+
['line_to', [[20.0, 580.0]], {}, []],
|
35
|
+
['close_path', [], {}, []]
|
36
|
+
]]
|
37
37
|
]
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context
|
41
|
+
context 'with a polygon that has no arguments' do
|
42
42
|
let(:svg) { '<polygon points="" />' }
|
43
43
|
|
44
|
-
it
|
44
|
+
it 'renders nothing' do
|
45
45
|
subject.process
|
46
46
|
expect(subject.base_calls).to eq []
|
47
47
|
end
|