prawn-svg 0.34.2 → 0.35.1
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 +24 -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 +29 -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 +5 -5
- 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 +3 -7
- data/lib/prawn/svg/elements/viewport.rb +1 -3
- 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 +5 -7
- 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 -45
- 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 +36 -40
- 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 +21 -146
@@ -5,66 +5,74 @@ describe Prawn::SVG::Interface do
|
|
5
5
|
let(:prawn) { instance_double(Prawn::Document, font_families: {}, bounds: bounds, cursor: 600) }
|
6
6
|
let(:svg) { '<svg width="250" height="100"></svg>' }
|
7
7
|
|
8
|
-
describe
|
9
|
-
describe
|
10
|
-
it
|
8
|
+
describe '#initialize' do
|
9
|
+
describe 'invalid option detection' do
|
10
|
+
it 'rejects invalid options when debug is on' do
|
11
11
|
allow(Prawn).to receive(:debug).and_return(true)
|
12
12
|
|
13
|
-
expect
|
14
|
-
Prawn::SVG::Interface.new(svg, prawn, :
|
15
|
-
|
13
|
+
expect do
|
14
|
+
Prawn::SVG::Interface.new(svg, prawn, invalid: 'option')
|
15
|
+
end.to raise_error(Prawn::Errors::UnknownOption)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
Prawn::SVG::Interface.new(svg, prawn, :
|
18
|
+
it 'does nothing if an invalid option is given and debug is off' do
|
19
|
+
Prawn::SVG::Interface.new(svg, prawn, invalid: 'option')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
25
|
-
context
|
24
|
+
describe '#draw' do
|
25
|
+
context 'when the sizing object indicates the sizes are invalid' do
|
26
26
|
let(:interface) { Prawn::SVG::Interface.new('<svg width="0"></svg>', prawn, {}) }
|
27
27
|
|
28
28
|
it "doesn't draw anything and adds a warning" do
|
29
29
|
interface.draw
|
30
|
-
expect(interface.document.warnings).to eq [
|
30
|
+
expect(interface.document.warnings).to eq ['Zero or negative sizing data means this SVG cannot be rendered']
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
34
|
+
describe 'rewrites' do
|
35
35
|
before do
|
36
36
|
[:save_font, :bounding_box].each { |message| allow(prawn).to receive(message).and_yield }
|
37
|
-
allow(prawn).to receive_messages([:move_to, :line_to, :close_path, :fill_color, :stroke_color,
|
38
|
-
|
37
|
+
allow(prawn).to receive_messages([:move_to, :line_to, :close_path, :fill_color, :stroke_color,
|
38
|
+
:transformation_matrix, :restore_graphics_state])
|
39
|
+
allow(prawn).to receive(:save_graphics_state) { |&block| block&.call }
|
39
40
|
end
|
40
41
|
|
41
|
-
context
|
42
|
+
context 'when fill_and_stroke is issued' do
|
42
43
|
def expect_rectangle
|
43
|
-
if RUBY_VERSION.start_with?(
|
44
|
+
if RUBY_VERSION.start_with?('2.7.')
|
44
45
|
expect(prawn).to receive(:rectangle)
|
45
46
|
else
|
46
47
|
expect(prawn).to receive(:rectangle).with([0, 100], 10, 10)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
context
|
51
|
-
let(:interface)
|
51
|
+
context 'and fill rule is not set' do
|
52
|
+
let(:interface) do
|
53
|
+
Prawn::SVG::Interface.new('<svg width="250" height="100"><rect width="10" height="10" stroke="red"></rect></svg>',
|
54
|
+
prawn, {})
|
55
|
+
end
|
52
56
|
|
53
57
|
it "adds content 'B'" do
|
54
58
|
expect_rectangle
|
55
|
-
expect(prawn).to receive(:add_content).with(
|
56
|
-
expect(prawn).to receive(:add_content).with(
|
59
|
+
expect(prawn).to receive(:add_content).with('W n')
|
60
|
+
expect(prawn).to receive(:add_content).with('B')
|
57
61
|
interface.draw
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
61
|
-
context
|
62
|
-
let(:interface)
|
65
|
+
context 'and fill rule is evenodd' do
|
66
|
+
let(:interface) do
|
67
|
+
Prawn::SVG::Interface.new(
|
68
|
+
'<svg width="250" height="100"><rect width="10" height="10" stroke="red" fill-rule="evenodd"></rect></svg>', prawn, {}
|
69
|
+
)
|
70
|
+
end
|
63
71
|
|
64
72
|
it "adds content 'B*'" do
|
65
73
|
expect_rectangle
|
66
|
-
expect(prawn).to receive(:add_content).with(
|
67
|
-
expect(prawn).to receive(:add_content).with(
|
74
|
+
expect(prawn).to receive(:add_content).with('W n')
|
75
|
+
expect(prawn).to receive(:add_content).with('B*')
|
68
76
|
interface.draw
|
69
77
|
end
|
70
78
|
end
|
@@ -72,70 +80,70 @@ describe Prawn::SVG::Interface do
|
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
|
-
describe
|
83
|
+
describe '#position' do
|
76
84
|
subject { interface.position }
|
77
85
|
|
78
|
-
context
|
86
|
+
context 'when options[:at] supplied' do
|
79
87
|
let(:interface) { Prawn::SVG::Interface.new(svg, prawn, at: [1, 2], position: :left) }
|
80
88
|
|
81
|
-
it
|
89
|
+
it 'returns options[:at]' do
|
82
90
|
expect(subject).to eq [1, 2]
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
|
-
context
|
94
|
+
context 'when only a position is supplied' do
|
87
95
|
let(:interface) { Prawn::SVG::Interface.new(svg, prawn, position: position) }
|
88
96
|
|
89
|
-
context
|
97
|
+
context '(:left)' do
|
90
98
|
let(:position) { :left }
|
91
99
|
it { is_expected.to eq [0, 600] }
|
92
100
|
end
|
93
101
|
|
94
|
-
context
|
102
|
+
context '(:center)' do
|
95
103
|
let(:position) { :center }
|
96
104
|
it { is_expected.to eq [275, 600] }
|
97
105
|
end
|
98
106
|
|
99
|
-
context
|
107
|
+
context '(:right)' do
|
100
108
|
let(:position) { :right }
|
101
109
|
it { is_expected.to eq [550, 600] }
|
102
110
|
end
|
103
111
|
|
104
|
-
context
|
112
|
+
context 'a number' do
|
105
113
|
let(:position) { 25.5 }
|
106
114
|
it { is_expected.to eq [25.5, 600] }
|
107
115
|
end
|
108
116
|
end
|
109
117
|
|
110
|
-
context
|
118
|
+
context 'when a vposition is supplied' do
|
111
119
|
let(:interface) { Prawn::SVG::Interface.new(svg, prawn, vposition: vposition) }
|
112
120
|
|
113
|
-
context
|
121
|
+
context '(:top)' do
|
114
122
|
let(:vposition) { :top }
|
115
123
|
it { is_expected.to eq [0, 600] }
|
116
124
|
end
|
117
125
|
|
118
|
-
context
|
126
|
+
context '(:center)' do
|
119
127
|
let(:vposition) { :center }
|
120
128
|
it { is_expected.to eq [0, 350] }
|
121
129
|
end
|
122
130
|
|
123
|
-
context
|
131
|
+
context '(:bottom)' do
|
124
132
|
let(:vposition) { :bottom }
|
125
133
|
it { is_expected.to eq [0, 100] }
|
126
134
|
end
|
127
135
|
|
128
|
-
context
|
136
|
+
context 'a number' do
|
129
137
|
let(:vposition) { 25.5 }
|
130
138
|
it { is_expected.to eq [0, 600 - 25.5] }
|
131
139
|
end
|
132
140
|
end
|
133
141
|
end
|
134
142
|
|
135
|
-
describe
|
143
|
+
describe '#sizing and #resize' do
|
136
144
|
let(:interface) { Prawn::SVG::Interface.new(svg, prawn, {}) }
|
137
145
|
|
138
|
-
it
|
146
|
+
it 'allows the advanced user to resize the SVG after learning about its dimensions' do
|
139
147
|
expect(interface.sizing.output_width).to eq 250
|
140
148
|
expect(interface.sizing.output_height).to eq 100
|
141
149
|
|
@@ -5,58 +5,58 @@ RSpec.describe Prawn::SVG::Loaders::Data do
|
|
5
5
|
|
6
6
|
subject { Prawn::SVG::Loaders::Data.new.from_url(url) }
|
7
7
|
|
8
|
-
context
|
9
|
-
let(:url) {
|
8
|
+
context 'with a valid image/png data URL' do
|
9
|
+
let(:url) { 'data:image/png;base64,aGVsbG8=' }
|
10
10
|
|
11
|
-
it
|
12
|
-
expect(subject).to eq
|
11
|
+
it 'loads the data' do
|
12
|
+
expect(subject).to eq 'hello'
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
context
|
17
|
-
let(:url) {
|
16
|
+
context 'with a valid image/jpeg data URL' do
|
17
|
+
let(:url) { 'data:image/jpeg;base64,aGVsbG8=' }
|
18
18
|
|
19
|
-
it
|
20
|
-
expect(subject).to eq
|
19
|
+
it 'loads the data' do
|
20
|
+
expect(subject).to eq 'hello'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context
|
25
|
-
let(:url) {
|
24
|
+
context 'with a data URL that has extra metadata' do
|
25
|
+
let(:url) { 'data:image/png;base64;metadata;here,aGVsbG8=' }
|
26
26
|
|
27
|
-
it
|
28
|
-
expect(subject).to eq
|
27
|
+
it 'loads the data' do
|
28
|
+
expect(subject).to eq 'hello'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context "with a data URL that's uppercase" do
|
33
|
-
let(:url) {
|
33
|
+
let(:url) { 'DATA:IMAGE/PNG;BASE64;METADATA;HERE,aGVsbG8=' }
|
34
34
|
|
35
|
-
it
|
36
|
-
expect(subject).to eq
|
35
|
+
it 'loads the data' do
|
36
|
+
expect(subject).to eq 'hello'
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context "with a URL that's not a data scheme" do
|
41
|
-
let(:url) {
|
41
|
+
let(:url) { 'http://some.host' }
|
42
42
|
|
43
|
-
it
|
43
|
+
it 'returns nil' do
|
44
44
|
expect(subject).to be nil
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
context "with a data URL that's not an image" do
|
49
|
-
let(:url) {
|
49
|
+
let(:url) { 'data:application/pdf;base64,aGVsbG8=' }
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'raises' do
|
52
52
|
expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /image/
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
context "with a data URL that's not base64 encoded" do
|
57
|
-
let(:url) {
|
57
|
+
let(:url) { 'data:image/png;base32,agvsbg' }
|
58
58
|
|
59
|
-
it
|
59
|
+
it 'raises' do
|
60
60
|
expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /base64/
|
61
61
|
end
|
62
62
|
end
|
@@ -1,71 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Prawn::SVG::Loaders::File do
|
4
|
-
let(:root_path) {
|
5
|
-
let(:fake_root_path) {
|
4
|
+
let(:root_path) { '.' }
|
5
|
+
let(:fake_root_path) { '/some' }
|
6
6
|
|
7
7
|
let(:file_loader) { Prawn::SVG::Loaders::File.new(root_path) }
|
8
8
|
subject { file_loader.from_url(url) }
|
9
9
|
|
10
|
-
context
|
11
|
-
let(:root_path) {
|
10
|
+
context 'when an invalid path is supplied' do
|
11
|
+
let(:root_path) { '/does/not/exist' }
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'raises with an ArgumentError' do
|
14
14
|
expect { subject }.to raise_error ArgumentError, /is not a directory/
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
19
|
-
let(:url) {
|
18
|
+
context 'when a relative path is supplied' do
|
19
|
+
let(:url) { 'relative/./path' }
|
20
20
|
|
21
|
-
it
|
22
|
-
expect(File).to receive(:expand_path).with(
|
23
|
-
expect(File).to receive(:expand_path).with(
|
21
|
+
it 'loads the file' do
|
22
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
23
|
+
expect(File).to receive(:expand_path).with('relative/./path',
|
24
|
+
fake_root_path).and_return("#{fake_root_path}/relative/path")
|
24
25
|
|
25
26
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
26
27
|
expect(File).to receive(:exist?).with("#{fake_root_path}/relative/path").and_return(true)
|
27
|
-
expect(
|
28
|
+
expect(File).to receive(:binread).with("#{fake_root_path}/relative/path").and_return('data')
|
28
29
|
|
29
30
|
expect(subject).to eq 'data'
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
context
|
34
|
-
let(:url) {
|
34
|
+
context 'when an absolute path without file scheme is supplied' do
|
35
|
+
let(:url) { '/some/absolute/./path' }
|
35
36
|
|
36
|
-
it
|
37
|
-
expect(File).to receive(:expand_path).with(
|
38
|
-
expect(File).to receive(:expand_path).with(url, fake_root_path).and_return(
|
37
|
+
it 'loads the file' do
|
38
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
39
|
+
expect(File).to receive(:expand_path).with(url, fake_root_path).and_return('/some/absolute/path')
|
39
40
|
|
40
41
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
41
|
-
expect(File).to receive(:exist?).with(
|
42
|
-
expect(
|
42
|
+
expect(File).to receive(:exist?).with('/some/absolute/path').and_return(true)
|
43
|
+
expect(File).to receive(:binread).with('/some/absolute/path').and_return('data')
|
43
44
|
|
44
45
|
expect(subject).to eq 'data'
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
context
|
49
|
-
let(:url) {
|
49
|
+
context 'when an absolute path with file scheme is supplied' do
|
50
|
+
let(:url) { 'file:///some/absolute/./path%20name' }
|
50
51
|
|
51
|
-
it
|
52
|
-
expect(File).to receive(:expand_path).with(
|
53
|
-
expect(File).to receive(:expand_path).with(
|
52
|
+
it 'loads the file' do
|
53
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
54
|
+
expect(File).to receive(:expand_path).with('/some/absolute/./path name',
|
55
|
+
fake_root_path).and_return('/some/absolute/path name')
|
54
56
|
|
55
57
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
56
|
-
expect(File).to receive(:exist?).with(
|
57
|
-
expect(
|
58
|
+
expect(File).to receive(:exist?).with('/some/absolute/path name').and_return(true)
|
59
|
+
expect(File).to receive(:binread).with('/some/absolute/path name').and_return('data')
|
58
60
|
|
59
61
|
expect(subject).to eq 'data'
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
63
|
-
context
|
64
|
-
let(:url) {
|
65
|
+
context 'when a path outside of our root is specified' do
|
66
|
+
let(:url) { '/other/absolute/./path' }
|
65
67
|
|
66
|
-
it
|
67
|
-
expect(File).to receive(:expand_path).with(
|
68
|
-
expect(File).to receive(:expand_path).with(url, fake_root_path).and_return(
|
68
|
+
it 'raises' do
|
69
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
70
|
+
expect(File).to receive(:expand_path).with(url, fake_root_path).and_return('/other/absolute/path')
|
69
71
|
|
70
72
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
71
73
|
|
@@ -73,11 +75,11 @@ RSpec.describe Prawn::SVG::Loaders::File do
|
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
context
|
77
|
-
let(:url) {
|
78
|
+
context 'when a file: url with a host is specified' do
|
79
|
+
let(:url) { 'file://somewhere/somefile' }
|
78
80
|
|
79
|
-
it
|
80
|
-
expect(File).to receive(:expand_path).with(
|
81
|
+
it 'raises' do
|
82
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
81
83
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
82
84
|
|
83
85
|
expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, /with a host/
|
@@ -85,16 +87,17 @@ RSpec.describe Prawn::SVG::Loaders::File do
|
|
85
87
|
end
|
86
88
|
|
87
89
|
context "when we're running on Windows" do
|
88
|
-
let(:url) {
|
89
|
-
let(:fake_root_path) {
|
90
|
+
let(:url) { 'file:///c:/path/to/file.png' }
|
91
|
+
let(:fake_root_path) { 'c:/full' }
|
90
92
|
|
91
93
|
it "automatically fixes up URI's misparsing of Windows file paths and loads the file" do
|
92
|
-
expect(File).to receive(:expand_path).with(
|
93
|
-
expect(File).to receive(:expand_path).with(
|
94
|
+
expect(File).to receive(:expand_path).with('.').and_return(fake_root_path)
|
95
|
+
expect(File).to receive(:expand_path).with('c:/path/to/file.png',
|
96
|
+
fake_root_path).and_return('c:/full/path/to/file.png')
|
94
97
|
|
95
98
|
expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
|
96
|
-
expect(File).to receive(:exist?).with(
|
97
|
-
expect(
|
99
|
+
expect(File).to receive(:exist?).with('c:/full/path/to/file.png').and_return(true)
|
100
|
+
expect(File).to receive(:binread).with('c:/full/path/to/file.png').and_return('data')
|
98
101
|
|
99
102
|
allow(file_loader).to receive(:windows?).and_return true
|
100
103
|
expect(subject).to eq 'data'
|
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Prawn::SVG::Loaders::Web do
|
4
|
-
let(:url) {
|
4
|
+
let(:url) { 'http://hello.there/path' }
|
5
5
|
let(:uri) { URI(url) }
|
6
6
|
|
7
7
|
subject { Prawn::SVG::Loaders::Web.new.from_url(url) }
|
8
8
|
|
9
|
-
it
|
10
|
-
expect(Net::HTTP).to receive(:get).with(uri).and_return(
|
11
|
-
expect(subject).to eq
|
9
|
+
it 'loads an HTTP URL' do
|
10
|
+
expect(Net::HTTP).to receive(:get).with(uri).and_return('hello!')
|
11
|
+
expect(subject).to eq 'hello!'
|
12
12
|
end
|
13
13
|
|
14
|
-
context
|
15
|
-
let(:url) {
|
14
|
+
context 'with an https URL' do
|
15
|
+
let(:url) { 'https://hello.there/path' }
|
16
16
|
|
17
|
-
it
|
18
|
-
expect(Net::HTTP).to receive(:get).with(uri).and_return(
|
19
|
-
expect(subject).to eq
|
17
|
+
it 'loads the HTTPS URL' do
|
18
|
+
expect(Net::HTTP).to receive(:get).with(uri).and_return('hello!')
|
19
|
+
expect(subject).to eq 'hello!'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
24
|
-
it
|
25
|
-
expect(Net::HTTP).to receive(:get).with(uri).and_raise(SocketError,
|
23
|
+
context 'when the HTTP call raises' do
|
24
|
+
it 're-raises the error as UrlLoader errors' do
|
25
|
+
expect(Net::HTTP).to receive(:get).with(uri).and_raise(SocketError, 'argh')
|
26
26
|
expect { subject }.to raise_error Prawn::SVG::UrlLoader::Error, 'argh'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
context
|
31
|
-
let(:url) {
|
30
|
+
context 'with a non-http, non-https URL' do
|
31
|
+
let(:url) { 'mailto:someone@something' }
|
32
32
|
|
33
|
-
it
|
33
|
+
it 'returns nil' do
|
34
34
|
expect(subject).to be nil
|
35
35
|
end
|
36
36
|
end
|
@@ -22,68 +22,68 @@ RSpec.describe Prawn::SVG::Pathable do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
let(:document) { Prawn::SVG::Document.new(
|
25
|
+
let(:document) { Prawn::SVG::Document.new('<svg></svg>', [800, 600], { width: 800, height: 600 }) }
|
26
26
|
let(:state) { Prawn::SVG::State.new }
|
27
27
|
|
28
28
|
subject do
|
29
29
|
FakeElement.new(document, document.root, [], state)
|
30
30
|
end
|
31
31
|
|
32
|
-
describe
|
33
|
-
it
|
32
|
+
describe '#bounding_box' do
|
33
|
+
it 'determines the bounding box using the translated commands' do
|
34
34
|
expect(subject.bounding_box).to eq [10, 590, 30, 570]
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
39
|
-
it
|
38
|
+
describe '#apply_commands' do
|
39
|
+
it 'applies the commands to the call stack' do
|
40
40
|
subject.apply_commands
|
41
41
|
|
42
42
|
expect(subject.base_calls).to eq [
|
43
|
-
[
|
44
|
-
[
|
45
|
-
[
|
46
|
-
[
|
43
|
+
['move_to', [[10.0, 590.0]], {}, []],
|
44
|
+
['line_to', [[20.0, 580.0]], {}, []],
|
45
|
+
['curve_to', [[30.0, 570.0]], { bounds: [[25.0, 580.0], [25.0, 575.0]] }, []],
|
46
|
+
['close_path', [], {}, []]
|
47
47
|
]
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe
|
52
|
-
let(:marker) { instance_double(Prawn::SVG::Elements::Marker, name:
|
51
|
+
describe '#apply_markers' do
|
52
|
+
let(:marker) { instance_double(Prawn::SVG::Elements::Marker, name: 'marker') }
|
53
53
|
|
54
54
|
before do
|
55
|
-
document.elements_by_id[
|
55
|
+
document.elements_by_id['triangle'] = marker
|
56
56
|
end
|
57
57
|
|
58
|
-
context
|
58
|
+
context 'with marker-start attribute specified' do
|
59
59
|
before do
|
60
|
-
subject.properties.marker_start =
|
60
|
+
subject.properties.marker_start = 'url(#triangle)'
|
61
61
|
end
|
62
62
|
|
63
|
-
it
|
63
|
+
it 'calls apply_marker on the marker' do
|
64
64
|
expect(marker).to receive(:apply_marker).with(subject, point: [10, 10], angle: 45)
|
65
65
|
subject.apply_markers
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context
|
69
|
+
context 'with marker-mid attribute specified' do
|
70
70
|
before do
|
71
|
-
subject.properties.marker_mid =
|
71
|
+
subject.properties.marker_mid = 'url(#triangle)'
|
72
72
|
end
|
73
73
|
|
74
|
-
it
|
74
|
+
it 'calls apply_marker on the marker' do
|
75
75
|
expect(marker).to receive(:apply_marker).with(subject, point: [20, 20], angle: 45)
|
76
76
|
expect(marker).to receive(:apply_marker).with(subject, point: [30, 30], angle: -45)
|
77
77
|
subject.apply_markers
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
context
|
81
|
+
context 'with marker-end attribute specified' do
|
82
82
|
before do
|
83
|
-
subject.properties.marker_end =
|
83
|
+
subject.properties.marker_end = 'url(#triangle)'
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
86
|
+
it 'calls apply_marker on the marker' do
|
87
87
|
expect(marker).to receive(:apply_marker).with(subject, point: [10, 10], angle: -45)
|
88
88
|
subject.apply_markers
|
89
89
|
end
|