prawn-svg 0.26.0 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +5 -3
- data/lib/prawn/svg/calculators/document_sizing.rb +2 -10
- data/lib/prawn/svg/elements/gradient.rb +3 -6
- data/lib/prawn/svg/elements/line.rb +3 -0
- data/lib/prawn/svg/elements/path.rb +24 -14
- data/lib/prawn/svg/font.rb +4 -2
- data/lib/prawn/svg/version.rb +1 -1
- data/prawn-svg.gemspec +1 -1
- data/spec/prawn/svg/calculators/document_sizing_spec.rb +5 -5
- data/spec/prawn/svg/elements/base_spec.rb +1 -1
- data/spec/prawn/svg/elements/line_spec.rb +23 -5
- data/spec/prawn/svg/elements/marker_spec.rb +4 -3
- data/spec/prawn/svg/elements/path_spec.rb +173 -1
- data/spec/prawn/svg/elements/text_spec.rb +1 -1
- data/spec/prawn/svg/font_spec.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bd5082f2d3bfb40a2776b9b8239ec0d345e826
|
4
|
+
data.tar.gz: 77c9df1c4f8bab6198ea45a0531314deac6e7a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d429c038aade4dad263441309d48f43e8ea185f67f85de9e556cbb1b2f50dd19af4bc6345e0a62388eaca504caea8d00506404630be11efea206a28a3b680f3
|
7
|
+
data.tar.gz: 83bc2528c2ba901523e3d54e32098852d354d35c07fc7bacbbc2583526422e8d2f613195e94145efeb56eeeb0d2db427b59bd0f1da19f888cc21f0b2cb7fbb7f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This will take an SVG document as input and render it into your PDF. Find out m
|
|
10
10
|
http://github.com/prawnpdf/prawn
|
11
11
|
|
12
12
|
prawn-svg is compatible with all versions of Prawn from 0.11.1 onwards, including the 1.x and 2.x series.
|
13
|
-
The minimum Ruby version required is 2.
|
13
|
+
The minimum Ruby version required is 2.1.0.
|
14
14
|
|
15
15
|
## Using prawn-svg
|
16
16
|
|
@@ -76,8 +76,7 @@ prawn-svg supports most but not all of the full SVG 1.1 specification. It curre
|
|
76
76
|
|
77
77
|
- `<marker>`
|
78
78
|
|
79
|
-
-
|
80
|
-
into Prawn. (gradientTransform, spreadMethod and stop-opacity are unimplemented.)
|
79
|
+
- `<linearGradient>` is implemented with Prawn 2.2.0+ (gradientTransform, spreadMethod and stop-opacity are unimplemented.)
|
81
80
|
|
82
81
|
- `<switch>` and `<foreignObject>`, although prawn-svg cannot handle any data that is not SVG so `<foreignObject>`
|
83
82
|
tags are always ignored.
|
@@ -119,6 +118,9 @@ Mac OS X and Debian Linux users. You can add to the font path:
|
|
119
118
|
Prawn::SVG::FontRegistry.font_path << "/my/font/directory"
|
120
119
|
```
|
121
120
|
|
121
|
+
### Using with prawn-rails
|
122
|
+
|
123
|
+
In your Gemfile, put `gem 'prawn-svg'` before `gem 'prawn-rails'` so that prawn-rails can see the prawn-svg extension.
|
122
124
|
|
123
125
|
--
|
124
126
|
Copyright Roger Nesbitt <roger@seriousorange.com>. MIT licence.
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Prawn::SVG::Calculators
|
2
2
|
class DocumentSizing
|
3
|
-
DEFAULT_WIDTH = 300
|
4
|
-
DEFAULT_HEIGHT = 150
|
5
3
|
DEFAULT_ASPECT_RATIO = "xMidYMid meet"
|
6
4
|
|
7
5
|
attr_writer :document_width, :document_height
|
@@ -30,17 +28,14 @@ module Prawn::SVG::Calculators
|
|
30
28
|
container_width = @requested_width || @bounds[0]
|
31
29
|
container_height = @requested_height || @bounds[1]
|
32
30
|
|
33
|
-
@output_width = Pixels::Measurement.to_pixels(@document_width ||
|
34
|
-
@output_height = Pixels::Measurement.to_pixels(@document_height ||
|
31
|
+
@output_width = Pixels::Measurement.to_pixels(@document_width || container_width, container_width)
|
32
|
+
@output_height = Pixels::Measurement.to_pixels(@document_height || container_height, container_height)
|
35
33
|
|
36
34
|
if @view_box
|
37
35
|
values = @view_box.strip.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
|
38
36
|
@x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f}
|
39
37
|
|
40
38
|
if @viewport_width > 0 && @viewport_height > 0
|
41
|
-
@output_width ||= container_width
|
42
|
-
@output_height ||= @output_width * @viewport_height / @viewport_width
|
43
|
-
|
44
39
|
aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height], [@viewport_width, @viewport_height])
|
45
40
|
@x_scale = aspect.width / @viewport_width
|
46
41
|
@y_scale = aspect.height / @viewport_height
|
@@ -48,9 +43,6 @@ module Prawn::SVG::Calculators
|
|
48
43
|
@y_offset -= aspect.y / @y_scale
|
49
44
|
end
|
50
45
|
else
|
51
|
-
@output_width ||= Pixels::Measurement.to_pixels(DEFAULT_WIDTH, container_width)
|
52
|
-
@output_height ||= Pixels::Measurement.to_pixels(DEFAULT_HEIGHT, container_height)
|
53
|
-
|
54
46
|
@viewport_width = @output_width
|
55
47
|
@viewport_height = @output_height
|
56
48
|
end
|
@@ -42,12 +42,9 @@ class Prawn::SVG::Elements::Gradient < Prawn::SVG::Elements::Base
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def assert_compatible_prawn_version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# if (Prawn::VERSION.split(".").map(&:to_i) <=> [2, 0, 4]) == -1
|
49
|
-
# raise SkipElementError, "Prawn 2.0.4+ must be used if you'd like prawn-svg to render gradients"
|
50
|
-
# end
|
45
|
+
if (Prawn::VERSION.split(".").map(&:to_i) <=> [2, 2, 0]) == -1
|
46
|
+
raise SkipElementError, "Prawn 2.2.0+ must be used if you'd like prawn-svg to render gradients"
|
47
|
+
end
|
51
48
|
end
|
52
49
|
|
53
50
|
def load_gradient_configuration
|
@@ -2,6 +2,9 @@ class Prawn::SVG::Elements::Line < Prawn::SVG::Elements::Base
|
|
2
2
|
include Prawn::SVG::Pathable
|
3
3
|
|
4
4
|
def parse
|
5
|
+
# Lines are one dimensional, so cannot be filled.
|
6
|
+
computed_properties.fill = 'none'
|
7
|
+
|
5
8
|
@x1 = x_pixels(attributes['x1'] || 0)
|
6
9
|
@y1 = y_pixels(attributes['y1'] || 0)
|
7
10
|
@x2 = x_pixels(attributes['x2'] || 0)
|
@@ -22,12 +22,14 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
22
22
|
matched_commands = match_all(data, COMMAND_REGEXP)
|
23
23
|
raise SkipElementError, "Invalid/unsupported syntax for SVG path data" if matched_commands.nil?
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
catch :invalid_command do
|
26
|
+
matched_commands.each do |matched_command|
|
27
|
+
command = matched_command[1]
|
28
|
+
matched_values = match_all(matched_command[2], VALUES_REGEXP)
|
29
|
+
raise "should be impossible to have invalid inside data, but we ended up here" if matched_values.nil?
|
30
|
+
values = matched_values.collect {|value| value[1].to_f}
|
31
|
+
parse_path_command(command, values)
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -46,8 +48,8 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
46
48
|
|
47
49
|
case upcase_command
|
48
50
|
when 'M' # moveto
|
49
|
-
x = values.shift
|
50
|
-
y = values.shift
|
51
|
+
x = values.shift or throw :invalid_command
|
52
|
+
y = values.shift or throw :invalid_command
|
51
53
|
|
52
54
|
if relative && @last_point
|
53
55
|
x += @last_point.first
|
@@ -67,7 +69,7 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
67
69
|
when 'L' # lineto
|
68
70
|
while values.any?
|
69
71
|
x = values.shift
|
70
|
-
y = values.shift
|
72
|
+
y = values.shift or throw :invalid_command
|
71
73
|
if relative && @last_point
|
72
74
|
x += @last_point.first
|
73
75
|
y += @last_point.last
|
@@ -92,7 +94,9 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
92
94
|
|
93
95
|
when 'C' # curveto
|
94
96
|
while values.any?
|
95
|
-
x1, y1, x2, y2, x, y = (
|
97
|
+
x1, y1, x2, y2, x, y = values.shift(6)
|
98
|
+
throw :invalid_command unless y
|
99
|
+
|
96
100
|
if relative && @last_point
|
97
101
|
x += @last_point.first
|
98
102
|
x1 += @last_point.first
|
@@ -108,7 +112,9 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
108
112
|
|
109
113
|
when 'S' # shorthand/smooth curveto
|
110
114
|
while values.any?
|
111
|
-
x2, y2, x, y = (
|
115
|
+
x2, y2, x, y = values.shift(4)
|
116
|
+
throw :invalid_command unless y
|
117
|
+
|
112
118
|
if relative && @last_point
|
113
119
|
x += @last_point.first
|
114
120
|
x2 += @last_point.first
|
@@ -130,11 +136,13 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
130
136
|
when 'Q', 'T' # quadratic curveto
|
131
137
|
while values.any?
|
132
138
|
if shorthand = upcase_command == 'T'
|
133
|
-
x, y = (
|
139
|
+
x, y = values.shift(2)
|
134
140
|
else
|
135
|
-
x1, y1, x, y = (
|
141
|
+
x1, y1, x, y = values.shift(4)
|
136
142
|
end
|
137
143
|
|
144
|
+
throw :invalid_command unless y
|
145
|
+
|
138
146
|
if relative && @last_point
|
139
147
|
x += @last_point.first
|
140
148
|
x1 += @last_point.first if x1
|
@@ -166,7 +174,9 @@ class Prawn::SVG::Elements::Path < Prawn::SVG::Elements::Base
|
|
166
174
|
return unless @last_point
|
167
175
|
|
168
176
|
while values.any?
|
169
|
-
rx, ry, phi, fa, fs, x2, y2 = (
|
177
|
+
rx, ry, phi, fa, fs, x2, y2 = values.shift(7)
|
178
|
+
throw :invalid_command unless y2
|
179
|
+
|
170
180
|
x1, y1 = @last_point
|
171
181
|
|
172
182
|
return if rx.zero? && ry.zero?
|
data/lib/prawn/svg/font.rb
CHANGED
@@ -21,9 +21,11 @@ class Prawn::SVG::Font
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def initialize(name, weight, style, font_registry: nil)
|
24
|
-
name = GENERIC_CSS_FONT_MAPPING.fetch(name, name) # If it's a standard CSS font name, map it to one of the standard PDF fonts.
|
25
|
-
|
26
24
|
@font_registry = font_registry
|
25
|
+
unless font_registry.installed_fonts.key?(name)
|
26
|
+
# map generic font name to one of the built-in PDF fonts if not already mapped
|
27
|
+
name = GENERIC_CSS_FONT_MAPPING[name] || name
|
28
|
+
end
|
27
29
|
@name = font_registry.correctly_cased_font_name(name) || name
|
28
30
|
@weight = weight
|
29
31
|
@style = style
|
data/lib/prawn/svg/version.rb
CHANGED
data/prawn-svg.gemspec
CHANGED
@@ -18,7 +18,7 @@ spec = Gem::Specification.new do |gem|
|
|
18
18
|
gem.name = "prawn-svg"
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.required_ruby_version = '>= 2.
|
21
|
+
gem.required_ruby_version = '>= 2.1.0'
|
22
22
|
|
23
23
|
gem.add_runtime_dependency "prawn", ">= 0.11.1", "< 3"
|
24
24
|
gem.add_runtime_dependency "css_parser", "~> 1.3"
|
@@ -74,12 +74,12 @@ describe Prawn::SVG::Calculators::DocumentSizing do
|
|
74
74
|
context "when a viewBox is specified" do
|
75
75
|
let(:attributes) { {"viewBox" => "0 0 100 200"} }
|
76
76
|
|
77
|
-
it "defaults to 100% width and
|
77
|
+
it "defaults to 100% width and height" do
|
78
78
|
sizing.calculate
|
79
79
|
expect(sizing.viewport_width).to eq 100
|
80
80
|
expect(sizing.viewport_height).to eq 200
|
81
81
|
expect(sizing.output_width).to eq 1200
|
82
|
-
expect(sizing.output_height).to eq
|
82
|
+
expect(sizing.output_height).to eq 800
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -116,11 +116,11 @@ describe Prawn::SVG::Calculators::DocumentSizing do
|
|
116
116
|
context "when neither viewBox nor requested width/height specified" do
|
117
117
|
let(:attributes) { {} }
|
118
118
|
|
119
|
-
it "defaults to
|
119
|
+
it "defaults to 100%" do
|
120
120
|
sizing.calculate
|
121
121
|
|
122
|
-
expect(sizing.output_width).to eq
|
123
|
-
expect(sizing.output_height).to eq
|
122
|
+
expect(sizing.output_width).to eq 1200
|
123
|
+
expect(sizing.output_height).to eq 800
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
@@ -32,7 +32,7 @@ describe Prawn::SVG::Elements::Base do
|
|
32
32
|
it "appends the relevant calls" do
|
33
33
|
element.process
|
34
34
|
expect(element.base_calls).to eq [
|
35
|
-
["rotate", [-90.0, {origin: [0,
|
35
|
+
["rotate", [-90.0, {origin: [0, 600.0]}], [
|
36
36
|
["transparent", [0.5, 1], [
|
37
37
|
["fill_color", ["ff0000"], []],
|
38
38
|
["stroke_color", ["0000ff"], []],
|
@@ -8,12 +8,13 @@ RSpec.describe Prawn::SVG::Elements::Line do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
context "with attributes specified" do
|
11
|
-
let(:svg) { '<line x1="5" y1="10" x2="15" y2="20" />' }
|
11
|
+
let(:svg) { '<line x1="5" y1="10" x2="15" y2="20" stroke="black" />' }
|
12
12
|
|
13
13
|
it "renders the line" do
|
14
14
|
subject.process
|
15
15
|
expect(subject.base_calls).to eq [
|
16
|
-
["
|
16
|
+
["stroke_color", ["000000"], []],
|
17
|
+
["stroke", [], [
|
17
18
|
["move_to", [[5.0, 590.0]], []],
|
18
19
|
["line_to", [[15.0, 580.0]], []]]
|
19
20
|
]
|
@@ -21,17 +22,34 @@ RSpec.describe Prawn::SVG::Elements::Line do
|
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
context "with no attributes specified" do
|
25
|
+
context "with no attributes nor stroke specified" do
|
25
26
|
let(:svg) { '<line />' }
|
26
27
|
|
27
|
-
it "
|
28
|
+
it "outlines a path from 0,0 to 0,0" do
|
28
29
|
subject.process
|
29
30
|
expect(subject.base_calls).to eq [
|
30
|
-
["
|
31
|
+
["end_path", [], [
|
31
32
|
["move_to", [[0, 600]], []],
|
32
33
|
["line_to", [[0, 600]], []]]
|
33
34
|
]
|
34
35
|
]
|
35
36
|
end
|
36
37
|
end
|
38
|
+
|
39
|
+
context "with a fill specified" do
|
40
|
+
let(:svg) { '<line x1="0" y1="0" x2="15" y2="20" style="stroke: red; fill: blue;" />' }
|
41
|
+
|
42
|
+
it "ignores the fill" do
|
43
|
+
subject.process
|
44
|
+
|
45
|
+
expect(subject.base_calls).to eq [
|
46
|
+
["fill_color", ["0000ff"], []],
|
47
|
+
["stroke_color", ["ff0000"], []],
|
48
|
+
["stroke", [], [
|
49
|
+
["move_to", [[0, 600]], []],
|
50
|
+
["line_to", [[15.0, 580.0]], []]]
|
51
|
+
]
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
37
55
|
end
|
@@ -12,7 +12,7 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
12
12
|
<path d="M 0 0 L 10 5 L 0 10 z" />
|
13
13
|
</marker>
|
14
14
|
|
15
|
-
<line x2="10" y2="10" stroke-width="100" />
|
15
|
+
<line x2="10" y2="10" stroke="black" stroke-width="100" />
|
16
16
|
</svg>
|
17
17
|
SVG
|
18
18
|
end
|
@@ -54,8 +54,9 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
54
54
|
# in section 11.6.3.
|
55
55
|
|
56
56
|
expect(line_element.base_calls).to eq [
|
57
|
+
["stroke_color", ["000000"], []],
|
57
58
|
["line_width", [100.0], []],
|
58
|
-
["
|
59
|
+
["stroke", [], [
|
59
60
|
["move_to", [[0.0, 600.0]], []],
|
60
61
|
["line_to", [[10.0, 590.0]], []]
|
61
62
|
]
|
@@ -69,7 +70,7 @@ RSpec.describe Prawn::SVG::Elements::Marker do
|
|
69
70
|
["clip", [], []],
|
70
71
|
["transformation_matrix", [0.3, 0, 0, 0.3, 0, 0], []],
|
71
72
|
["transparent", [1.0, 1.0], [
|
72
|
-
["
|
73
|
+
["stroke_color", ["000000"], []],
|
73
74
|
["line_width", [100.0], []],
|
74
75
|
["cap_style", [:butt], []],
|
75
76
|
["undash", [], []],
|
@@ -74,6 +74,168 @@ describe Prawn::SVG::Elements::Path do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
context "when given an M path" do
|
78
|
+
subject { path.parse; path.commands }
|
79
|
+
|
80
|
+
context "with typical arguments" do
|
81
|
+
let(:d) { "M 100 200 M 200 300 m 10 20" }
|
82
|
+
|
83
|
+
it "issues a move command" do
|
84
|
+
expect(subject).to eq [
|
85
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
86
|
+
Prawn::SVG::Elements::Path::Move.new([200.0, 300.0]),
|
87
|
+
Prawn::SVG::Elements::Path::Move.new([210.0, 320.0]),
|
88
|
+
]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "with only one argument" do
|
93
|
+
let(:d) { "M 100 200 M 100" }
|
94
|
+
|
95
|
+
it "bails out" do
|
96
|
+
expect(subject).to eq [
|
97
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
98
|
+
]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with no arguments" do
|
103
|
+
let(:d) { "M 100 200 M" }
|
104
|
+
|
105
|
+
it "bails out" do
|
106
|
+
expect(subject).to eq [
|
107
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
108
|
+
]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when given an L path" do
|
114
|
+
subject { path.parse; path.commands }
|
115
|
+
|
116
|
+
context "with typical arguments" do
|
117
|
+
let(:d) { "M 100 200 L 200 300 l 10 20" }
|
118
|
+
|
119
|
+
it "issues a line command" do
|
120
|
+
expect(subject).to eq [
|
121
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0]),
|
122
|
+
Prawn::SVG::Elements::Path::Line.new([200.0, 300.0]),
|
123
|
+
Prawn::SVG::Elements::Path::Line.new([210.0, 320.0]),
|
124
|
+
]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with only one argument" do
|
129
|
+
let(:d) { "M 100 200 L 100" }
|
130
|
+
|
131
|
+
it "bails out" do
|
132
|
+
expect(subject).to eq [
|
133
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
134
|
+
]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when given a C path" do
|
140
|
+
subject { path.parse; path.commands }
|
141
|
+
|
142
|
+
context "with typical arguments" do
|
143
|
+
let(:d) { "M 100 200 C 10 20 30 40 200 300" }
|
144
|
+
|
145
|
+
it "issues a curve command" do
|
146
|
+
expect(subject).to eq [
|
147
|
+
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]),
|
149
|
+
]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with incomplete arguments" do
|
154
|
+
let(:d) { "M 100 200 C 10 20 30 40 50" }
|
155
|
+
|
156
|
+
it "bails out" do
|
157
|
+
expect(subject).to eq [
|
158
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
159
|
+
]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when given an S path" do
|
165
|
+
subject { path.parse; path.commands }
|
166
|
+
|
167
|
+
context "with typical arguments" do
|
168
|
+
let(:d) { "M 100 200 S 30 40 200 300" }
|
169
|
+
|
170
|
+
it "issues a curve command" do
|
171
|
+
expect(subject).to eq [
|
172
|
+
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]),
|
174
|
+
]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "with incomplete arguments" do
|
179
|
+
let(:d) { "M 100 200 S 30 40 50" }
|
180
|
+
|
181
|
+
it "bails out" do
|
182
|
+
expect(subject).to eq [
|
183
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
184
|
+
]
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "when given a Q path" do
|
190
|
+
subject { path.parse; path.commands }
|
191
|
+
|
192
|
+
context "with typical arguments" do
|
193
|
+
let(:d) { "M 0 0 Q 600 300 300 600" }
|
194
|
+
|
195
|
+
it "issues a curve command" do
|
196
|
+
expect(subject).to eq [
|
197
|
+
Prawn::SVG::Elements::Path::Move.new([0, 0]),
|
198
|
+
Prawn::SVG::Elements::Path::Curve.new([300.0, 600.0], [400, 200], [500, 400])
|
199
|
+
]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "with incomplete arguments" do
|
204
|
+
let(:d) { "M 100 200 Q 30 40 50" }
|
205
|
+
|
206
|
+
it "bails out" do
|
207
|
+
expect(subject).to eq [
|
208
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
209
|
+
]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "when given a T path" do
|
215
|
+
subject { path.parse; path.commands }
|
216
|
+
|
217
|
+
context "with typical arguments" do
|
218
|
+
let(:d) { "M 0 0 T 300 600" }
|
219
|
+
|
220
|
+
it "issues a curve command" do
|
221
|
+
expect(subject).to eq [
|
222
|
+
Prawn::SVG::Elements::Path::Move.new([0, 0]),
|
223
|
+
Prawn::SVG::Elements::Path::Curve.new([300.0, 600.0], [0, 0], [100, 200])
|
224
|
+
]
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "with incomplete arguments" do
|
229
|
+
let(:d) { "M 100 200 T 30" }
|
230
|
+
|
231
|
+
it "bails out" do
|
232
|
+
expect(subject).to eq [
|
233
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
234
|
+
]
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
77
239
|
context "when given an A path" do
|
78
240
|
subject { path.parse; path.commands }
|
79
241
|
|
@@ -98,7 +260,7 @@ describe Prawn::SVG::Elements::Path do
|
|
98
260
|
]
|
99
261
|
end
|
100
262
|
end
|
101
|
-
|
263
|
+
|
102
264
|
context "with an rx of 0" do
|
103
265
|
let(:d) { "M 100 200 A 0 10 0 0 1 200 200" }
|
104
266
|
|
@@ -120,5 +282,15 @@ describe Prawn::SVG::Elements::Path do
|
|
120
282
|
]
|
121
283
|
end
|
122
284
|
end
|
285
|
+
|
286
|
+
context "with incomplete arguments" do
|
287
|
+
let(:d) { "M 100 200 A 10 20 30 L 10 20" }
|
288
|
+
|
289
|
+
it "bails out" do
|
290
|
+
expect(subject).to eq [
|
291
|
+
Prawn::SVG::Elements::Path::Move.new([100.0, 200.0])
|
292
|
+
]
|
293
|
+
end
|
294
|
+
end
|
123
295
|
end
|
124
296
|
end
|
@@ -65,7 +65,7 @@ Even more
|
|
65
65
|
|
66
66
|
it "should inherit text-anchor from parent element" do
|
67
67
|
element.process
|
68
|
-
expect(element.calls.flatten).to include(:size => 12.0, :style => :normal, :text_anchor => "middle", :at => [50.0,
|
68
|
+
expect(element.calls.flatten).to include(:size => 12.0, :style => :normal, :text_anchor => "middle", :at => [50.0, 586.0], :offset => [0,0])
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
data/spec/prawn/svg/font_spec.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
3
|
describe Prawn::SVG::Font do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "maps generic font name to built-in font" do
|
6
|
+
font_registry = Prawn::SVG::FontRegistry.new({})
|
7
|
+
font = Prawn::SVG::Font.new('sans-serif', :normal, :normal, font_registry: font_registry)
|
8
|
+
font.name.should == 'Helvetica'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "preserves generic font name if mapped" do
|
12
|
+
font_registry = Prawn::SVG::FontRegistry.new('sans-serif' => { normal: 'Times-Roman' })
|
13
|
+
font = Prawn::SVG::Font.new('sans-serif', :normal, :normal, font_registry: font_registry)
|
14
|
+
font.name.should == 'sans-serif'
|
15
|
+
end
|
16
|
+
end
|
4
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -236,7 +236,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
236
236
|
requirements:
|
237
237
|
- - ">="
|
238
238
|
- !ruby/object:Gem::Version
|
239
|
-
version: 2.
|
239
|
+
version: 2.1.0
|
240
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
241
|
requirements:
|
242
242
|
- - ">="
|