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
data/lib/prawn/svg/renderer.rb
CHANGED
@@ -74,7 +74,7 @@ module Prawn
|
|
74
74
|
when :top
|
75
75
|
sizing.bounds[1]
|
76
76
|
when :center, :centre
|
77
|
-
sizing.bounds[1] - (sizing.bounds[1] - sizing.output_height) / 2.0
|
77
|
+
sizing.bounds[1] - ((sizing.bounds[1] - sizing.output_height) / 2.0)
|
78
78
|
when :bottom
|
79
79
|
sizing.output_height
|
80
80
|
when Numeric
|
@@ -135,20 +135,20 @@ module Prawn
|
|
135
135
|
@cursor = [at[0], at[1]]
|
136
136
|
end
|
137
137
|
|
138
|
-
if offset = options.delete(:offset)
|
138
|
+
if (offset = options.delete(:offset))
|
139
139
|
at[0] += offset[0]
|
140
140
|
at[1] -= offset[1]
|
141
141
|
end
|
142
142
|
|
143
143
|
width = prawn.width_of(text, options.merge(kerning: true))
|
144
144
|
|
145
|
-
if stretch_to_width = options.delete(:stretch_to_width)
|
145
|
+
if (stretch_to_width = options.delete(:stretch_to_width))
|
146
146
|
factor = stretch_to_width.to_f * 100 / width.to_f
|
147
147
|
prawn.add_content "#{factor} Tz"
|
148
148
|
width = stretch_to_width.to_f
|
149
149
|
end
|
150
150
|
|
151
|
-
if pad_to_width = options.delete(:pad_to_width)
|
151
|
+
if (pad_to_width = options.delete(:pad_to_width))
|
152
152
|
padding_required = pad_to_width.to_f - width.to_f
|
153
153
|
padding_per_character = padding_required / text.length.to_f
|
154
154
|
prawn.add_content "#{padding_per_character} Tc"
|
@@ -158,7 +158,7 @@ module Prawn
|
|
158
158
|
case options.delete(:text_anchor)
|
159
159
|
when 'middle'
|
160
160
|
at[0] -= width / 2
|
161
|
-
@cursor = [at[0] + width / 2, at[1]]
|
161
|
+
@cursor = [at[0] + (width / 2), at[1]]
|
162
162
|
when 'end'
|
163
163
|
at[0] -= width
|
164
164
|
@cursor = at.dup
|
@@ -178,8 +178,8 @@ module Prawn
|
|
178
178
|
when 'transformation_matrix'
|
179
179
|
left = prawn.bounds.absolute_left
|
180
180
|
top = prawn.bounds.absolute_top
|
181
|
-
arguments[4] += left - (left * arguments[0] + top * arguments[2])
|
182
|
-
arguments[5] += top - (left * arguments[1] + top * arguments[3])
|
181
|
+
arguments[4] += left - ((left * arguments[0]) + (top * arguments[2]))
|
182
|
+
arguments[5] += top - ((left * arguments[1]) + (top * arguments[3]))
|
183
183
|
|
184
184
|
when 'clip'
|
185
185
|
prawn.add_content 'W n' # clip to path
|
data/lib/prawn/svg/state.rb
CHANGED
@@ -17,7 +17,7 @@ module Prawn::SVG::TransformParser
|
|
17
17
|
matrix *= Matrix[[1, 0, 0], [0, 1, -y_pixels(y.to_f)], [0, 0, 1]]
|
18
18
|
|
19
19
|
when 'rotate'
|
20
|
-
angle, x, y = arguments.collect
|
20
|
+
angle, x, y = arguments.collect(&:to_f)
|
21
21
|
angle = angle * Math::PI / 180.0
|
22
22
|
|
23
23
|
case arguments.length
|
@@ -45,11 +45,11 @@ module Prawn::SVG::TransformParser
|
|
45
45
|
matrix *= Matrix[[1, 0, 0], [-Math.tan(angle), 1, 0], [0, 0, 1]]
|
46
46
|
|
47
47
|
when 'matrix'
|
48
|
-
if arguments.length
|
49
|
-
|
50
|
-
else
|
51
|
-
a, b, c, d, e, f = arguments.collect { |argument| argument.to_f }
|
48
|
+
if arguments.length == 6
|
49
|
+
a, b, c, d, e, f = arguments.collect(&:to_f)
|
52
50
|
matrix *= Matrix[[a, -c, e], [-b, d, -f], [0, 0, 1]]
|
51
|
+
else
|
52
|
+
warnings << "transform 'matrix' must have six arguments"
|
53
53
|
end
|
54
54
|
|
55
55
|
else
|
data/lib/prawn/svg/ttf.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Prawn::SVG::TTF
|
2
|
-
SFNT_VERSION_STRINGS = ["\x00\x01\x00\x00",
|
3
|
-
LANGUAGE_IDS = [0, 0x409] # English, US English
|
4
|
-
UTF_16BE_PLATFORM_IDS = [0, 3] # Unicode, Microsoft
|
2
|
+
SFNT_VERSION_STRINGS = ["\x00\x01\x00\x00", 'true', 'typ1'].freeze
|
3
|
+
LANGUAGE_IDS = [0, 0x409].freeze # English, US English
|
4
|
+
UTF_16BE_PLATFORM_IDS = [0, 3].freeze # Unicode, Microsoft
|
5
5
|
|
6
6
|
attr_reader :family, :subfamily
|
7
7
|
|
@@ -12,45 +12,49 @@ class Prawn::SVG::TTF
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def load_data_from_file(filename)
|
15
|
-
File.open(filename,
|
15
|
+
File.open(filename, 'rb') do |f|
|
16
16
|
offset_table = f.read(12)
|
17
17
|
return unless offset_table && offset_table.length == 12 && SFNT_VERSION_STRINGS.include?(offset_table[0..3])
|
18
18
|
|
19
|
-
table_count = offset_table[4].ord * 256 + offset_table[5].ord
|
19
|
+
table_count = (offset_table[4].ord * 256) + offset_table[5].ord
|
20
20
|
tables = f.read(table_count * 16)
|
21
21
|
return unless tables && tables.length == table_count * 16
|
22
22
|
|
23
23
|
offset, length = table_count.times do |index|
|
24
24
|
start = index * 16
|
25
|
-
if tables[start..start+3] == 'name'
|
26
|
-
break tables[start+8..start+15].unpack("NNN")
|
27
|
-
end
|
25
|
+
break tables[start + 8..start + 15].unpack('NNN') if tables[start..start + 3] == 'name'
|
28
26
|
end
|
29
27
|
|
30
28
|
return unless length
|
29
|
+
|
31
30
|
f.seek(offset)
|
32
31
|
data = f.read(length)
|
33
32
|
return unless data && data.length == length
|
34
33
|
|
35
|
-
|
34
|
+
_, name_count, string_offset = data[0..5].unpack('nnn')
|
36
35
|
|
37
36
|
names = {}
|
38
37
|
name_count.times do |index|
|
39
|
-
start = 6 + index * 12
|
40
|
-
platform_id,
|
38
|
+
start = 6 + (index * 12)
|
39
|
+
platform_id, _, language_id, name_id, length, offset = data[start..start + 11].unpack('nnnnnn')
|
41
40
|
next unless offset
|
42
41
|
next unless LANGUAGE_IDS.include?(language_id)
|
43
42
|
next unless [1, 2, 16, 17].include?(name_id)
|
44
43
|
|
45
44
|
offset += string_offset
|
46
|
-
field = data[offset..offset+length-1]
|
45
|
+
field = data[offset..offset + length - 1]
|
47
46
|
next unless field && field.length == length
|
48
47
|
|
49
|
-
names[name_id] =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
names[name_id] =
|
49
|
+
if UTF_16BE_PLATFORM_IDS.include?(platform_id)
|
50
|
+
begin
|
51
|
+
field.force_encoding(Encoding::UTF_16BE).encode(Encoding::UTF_8)
|
52
|
+
rescue StandardError
|
53
|
+
field
|
54
|
+
end
|
55
|
+
else
|
56
|
+
field
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
60
|
@family = names[16] || names[1]
|
data/lib/prawn/svg/url_loader.rb
CHANGED
@@ -34,7 +34,7 @@ class Prawn::SVG::UrlLoader
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def perform(url)
|
37
|
-
try_each_loader(url) or raise Error,
|
37
|
+
try_each_loader(url) or raise Error, 'No handler available for this URL scheme'
|
38
38
|
end
|
39
39
|
|
40
40
|
def try_each_loader(url)
|
data/lib/prawn/svg/version.rb
CHANGED
data/lib/prawn-svg.rb
CHANGED
@@ -26,6 +26,7 @@ require 'prawn/svg/interface'
|
|
26
26
|
require 'prawn/svg/css/font_family_parser'
|
27
27
|
require 'prawn/svg/css/selector_parser'
|
28
28
|
require 'prawn/svg/css/stylesheets'
|
29
|
+
require 'prawn/svg/css/values_parser'
|
29
30
|
require 'prawn/svg/ttf'
|
30
31
|
require 'prawn/svg/font'
|
31
32
|
require 'prawn/svg/gradients'
|
data/prawn-svg.gemspec
CHANGED
@@ -4,9 +4,9 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.name = 'prawn-svg'
|
5
5
|
gem.version = Prawn::SVG::VERSION
|
6
6
|
gem.summary = 'SVG renderer for Prawn PDF library'
|
7
|
-
gem.description = <<-
|
7
|
+
gem.description = <<-DESC.strip
|
8
8
|
This gem allows you to render SVG directly into a PDF using the 'prawn' gem. Since PDF is vector-based, you'll get nice scaled graphics if you use SVG instead of an image.
|
9
|
-
|
9
|
+
DESC
|
10
10
|
gem.author = 'Mog Nesbitt'
|
11
11
|
gem.email = 'mog@seriousorange.com'
|
12
12
|
gem.homepage = 'http://github.com/mogest/prawn-svg'
|
@@ -14,15 +14,13 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
16
16
|
gem.files = `git ls-files`.split("\n")
|
17
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
17
|
gem.require_paths = ['lib']
|
18
|
+
gem.metadata = { 'rubygems_mfa_required' => 'true' }
|
19
19
|
|
20
|
-
gem.required_ruby_version = '>= 2.
|
20
|
+
gem.required_ruby_version = '>= 2.7.0'
|
21
21
|
|
22
22
|
gem.add_runtime_dependency 'css_parser', '~> 1.6'
|
23
23
|
gem.add_runtime_dependency 'matrix', '~> 0.4.2'
|
24
24
|
gem.add_runtime_dependency 'prawn', '>= 0.11.1', '< 3'
|
25
25
|
gem.add_runtime_dependency 'rexml', '~> 3.2'
|
26
|
-
gem.add_development_dependency 'rake', '~> 13.0'
|
27
|
-
gem.add_development_dependency 'rspec', '~> 3.0'
|
28
26
|
end
|
data/spec/integration_spec.rb
CHANGED
@@ -1,100 +1,100 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'Integration test' do
|
4
4
|
root = "#{File.dirname(__FILE__)}/.."
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe 'a basic SVG file' do
|
7
7
|
let(:document) { Prawn::SVG::Document.new(svg, [800, 600], {}) }
|
8
8
|
let(:element) { Prawn::SVG::Elements::Root.new(document) }
|
9
9
|
|
10
10
|
let(:svg) do
|
11
|
-
|
12
|
-
<svg width="100" height="200">
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
</svg>
|
11
|
+
<<~SVG
|
12
|
+
<svg width="100" height="200">
|
13
|
+
<style><![CDATA[
|
14
|
+
#puppy { fill: red; }
|
15
|
+
.animal { fill: green; }
|
16
|
+
rect { fill: blue; }
|
17
|
+
]]></style>
|
18
|
+
|
19
|
+
<rect x="0" y="0" width="10" height="10"/>
|
20
|
+
<rect x="10" y="0" width="10" height="10" class="animal"/>
|
21
|
+
<rect x="20" y="0" width="10" height="10" class="animal" id="puppy"/>
|
22
|
+
<rect x="30" y="0" width="10" height="10" class="animal" id="puppy" style="fill: yellow;"/>
|
23
|
+
</svg>
|
24
24
|
SVG
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'is correctly converted to a call stack' do
|
28
28
|
element.process
|
29
29
|
|
30
30
|
expect(element.calls).to eq [
|
31
|
-
[
|
32
|
-
[
|
33
|
-
[
|
34
|
-
[
|
35
|
-
[
|
36
|
-
[
|
37
|
-
[
|
38
|
-
[
|
31
|
+
['fill_color', ['000000'], {}, []],
|
32
|
+
['transformation_matrix', [1, 0, 0, 1, 0, 0], {}, []],
|
33
|
+
['transformation_matrix', [1, 0, 0, 1, 0, 0], {}, []],
|
34
|
+
['save', [], {}, []], ['restore', [], {}, []],
|
35
|
+
['save', [], {}, []],
|
36
|
+
['fill_color', ['0000ff'], {}, []],
|
37
|
+
['fill', [], {}, [
|
38
|
+
['rectangle', [[0.0, 200.0], 10.0, 10.0], {}, []]
|
39
39
|
]],
|
40
|
-
[
|
41
|
-
[
|
42
|
-
[
|
43
|
-
[
|
44
|
-
[
|
40
|
+
['restore', [], {}, []],
|
41
|
+
['save', [], {}, []],
|
42
|
+
['fill_color', ['008000'], {}, []],
|
43
|
+
['fill', [], {}, [
|
44
|
+
['rectangle', [[10.0, 200.0], 10.0, 10.0], {}, []]
|
45
45
|
]],
|
46
|
-
[
|
47
|
-
[
|
48
|
-
[
|
49
|
-
[
|
50
|
-
[
|
46
|
+
['restore', [], {}, []],
|
47
|
+
['save', [], {}, []],
|
48
|
+
['fill_color', ['ff0000'], {}, []],
|
49
|
+
['fill', [], {}, [
|
50
|
+
['rectangle', [[20.0, 200.0], 10.0, 10.0], {}, []]
|
51
51
|
]],
|
52
|
-
[
|
53
|
-
[
|
54
|
-
[
|
55
|
-
[
|
56
|
-
[
|
52
|
+
['restore', [], {}, []],
|
53
|
+
['save', [], {}, []],
|
54
|
+
['fill_color', ['ffff00'], {}, []],
|
55
|
+
['fill', [], {}, [
|
56
|
+
['rectangle', [[30.0, 200.0], 10.0, 10.0], {}, []]
|
57
57
|
]],
|
58
|
-
[
|
58
|
+
['restore', [], {}, []]
|
59
59
|
]
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
context
|
64
|
-
let(:svg) {
|
63
|
+
context 'with option :position' do
|
64
|
+
let(:svg) { File.read("#{root}/spec/sample_svg/cubic01a.svg") }
|
65
65
|
|
66
|
-
it
|
66
|
+
it 'aligns the image as requested' do
|
67
67
|
Prawn::Document.generate("#{root}/spec/sample_output/_with_position.pdf") do |prawn|
|
68
68
|
width = prawn.bounds.width / 3
|
69
69
|
|
70
|
-
prawn.svg svg, :
|
71
|
-
prawn.svg svg, :
|
72
|
-
prawn.svg svg, :
|
73
|
-
prawn.svg svg, :
|
74
|
-
prawn.svg svg, :
|
70
|
+
prawn.svg svg, width: width, position: :left
|
71
|
+
prawn.svg svg, width: width, position: :center
|
72
|
+
prawn.svg svg, width: width, position: :right
|
73
|
+
prawn.svg svg, width: width, position: 50
|
74
|
+
prawn.svg svg, width: width
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
context
|
80
|
-
let(:svg) {
|
79
|
+
context 'with option :vposition' do
|
80
|
+
let(:svg) { File.read("#{root}/spec/sample_svg/cubic01a.svg") }
|
81
81
|
|
82
|
-
it
|
82
|
+
it 'aligns the image as requested' do
|
83
83
|
Prawn::Document.generate("#{root}/spec/sample_output/_with_vposition.pdf") do |prawn|
|
84
84
|
width = prawn.bounds.width / 3
|
85
85
|
|
86
|
-
prawn.svg svg, :
|
87
|
-
prawn.svg svg, :
|
88
|
-
prawn.svg svg, :
|
89
|
-
prawn.svg svg, :
|
86
|
+
prawn.svg svg, width: width, position: :left, vposition: :bottom
|
87
|
+
prawn.svg svg, width: width, position: :center, vposition: :center
|
88
|
+
prawn.svg svg, width: width, position: :right, vposition: :top
|
89
|
+
prawn.svg svg, width: width, position: 50, vposition: 50
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
94
|
+
describe 'sample file rendering' do
|
95
95
|
files = Dir["#{root}/spec/sample_svg/*.svg"]
|
96
96
|
|
97
|
-
it
|
97
|
+
it 'has at least 10 SVG sample files to test' do
|
98
98
|
files.length.should >= 10
|
99
99
|
end
|
100
100
|
|
@@ -104,37 +104,44 @@ describe "Integration test" do
|
|
104
104
|
|
105
105
|
warnings = nil
|
106
106
|
Prawn::Document.generate("#{root}/spec/sample_output/#{File.basename file}.pdf") do |prawn|
|
107
|
-
r = prawn.svg
|
108
|
-
|
109
|
-
doc.url_loader.add_to_cache(
|
107
|
+
r = prawn.svg File.read(file), at: [0, prawn.bounds.top], width: prawn.bounds.width,
|
108
|
+
enable_file_requests_with_root: File.dirname(__FILE__) do |doc|
|
109
|
+
doc.url_loader.add_to_cache(
|
110
|
+
'https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg', File.read("#{root}/spec/sample_images/mushroom-wide.jpg")
|
111
|
+
)
|
112
|
+
doc.url_loader.add_to_cache(
|
113
|
+
'https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg', File.read("#{root}/spec/sample_images/mushroom-long.jpg")
|
114
|
+
)
|
110
115
|
end
|
111
116
|
|
112
|
-
warnings = r[:warnings].reject
|
117
|
+
warnings = r[:warnings].reject do |w|
|
118
|
+
(w =~ /Verdana/ && w =~ /is not a known font/) || w =~ /(render gradients$|waiting on the Prawn project)/
|
119
|
+
end
|
113
120
|
end
|
114
121
|
warnings.should == []
|
115
122
|
end
|
116
123
|
end
|
117
124
|
end
|
118
125
|
|
119
|
-
describe
|
120
|
-
it
|
126
|
+
describe 'multiple file rendering' do
|
127
|
+
it 'renders multiple files on to the same PDF' do
|
121
128
|
Prawn::Document.generate("#{root}/spec/sample_output/_multiple.pdf") do |prawn|
|
122
129
|
width = prawn.bounds.width
|
123
130
|
|
124
131
|
y = prawn.bounds.top - 12
|
125
|
-
prawn.draw_text
|
132
|
+
prawn.draw_text 'This is multiple SVGs being output to the same PDF', at: [0, y]
|
126
133
|
|
127
134
|
y -= 12
|
128
|
-
prawn.svg
|
129
|
-
prawn.svg
|
135
|
+
prawn.svg File.read("#{root}/spec/sample_svg/arcs01.svg"), at: [0, y], width: width / 2
|
136
|
+
prawn.svg File.read("#{root}/spec/sample_svg/circle01.svg"), at: [width / 2, y], width: width / 2
|
130
137
|
|
131
138
|
y -= 120
|
132
|
-
prawn.draw_text
|
139
|
+
prawn.draw_text 'Here are some more PDFs below', at: [0, y]
|
133
140
|
|
134
141
|
y -= 12
|
135
|
-
prawn.svg
|
136
|
-
prawn.svg
|
137
|
-
prawn.svg
|
142
|
+
prawn.svg File.read("#{root}/spec/sample_svg/quad01.svg"), at: [0, y], width: width / 3
|
143
|
+
prawn.svg File.read("#{root}/spec/sample_svg/rect01.svg"), at: [width / 3, y], width: width / 3
|
144
|
+
prawn.svg File.read("#{root}/spec/sample_svg/rect02.svg"), at: [width / 3 * 2, y], width: width / 3
|
138
145
|
end
|
139
146
|
end
|
140
147
|
end
|
@@ -10,26 +10,22 @@ describe Prawn::SVG::Attributes::Opacity do
|
|
10
10
|
@properties = ::Prawn::SVG::Properties.new
|
11
11
|
@state = ::Prawn::SVG::State.new
|
12
12
|
end
|
13
|
-
|
14
|
-
def clamp(value, min_value, max_value)
|
15
|
-
[[value, min_value].max, max_value].min
|
16
|
-
end
|
17
13
|
end
|
18
14
|
|
19
15
|
let(:element) { OpacityTestElement.new }
|
20
16
|
|
21
|
-
describe
|
17
|
+
describe '#parse_opacity_attributes_and_call' do
|
22
18
|
subject { element.parse_opacity_attributes_and_call }
|
23
19
|
|
24
|
-
context
|
25
|
-
it
|
20
|
+
context 'with no opacity specified' do
|
21
|
+
it 'does nothing' do
|
26
22
|
expect(element).not_to receive(:add_call_and_enter)
|
27
23
|
subject
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
|
-
context
|
32
|
-
it
|
27
|
+
context 'with opacity' do
|
28
|
+
it 'sets fill and stroke opacity' do
|
33
29
|
element.properties.opacity = '0.4'
|
34
30
|
|
35
31
|
expect(element).to receive(:add_call_and_enter).with('transparent', 0.4, 0.4)
|
@@ -40,8 +36,8 @@ describe Prawn::SVG::Attributes::Opacity do
|
|
40
36
|
end
|
41
37
|
end
|
42
38
|
|
43
|
-
context
|
44
|
-
it
|
39
|
+
context 'with just fill opacity' do
|
40
|
+
it 'sets fill opacity and sets stroke opacity to 1' do
|
45
41
|
element.properties.fill_opacity = '0.4'
|
46
42
|
|
47
43
|
expect(element).to receive(:add_call_and_enter).with('transparent', 0.4, 1)
|
@@ -52,8 +48,8 @@ describe Prawn::SVG::Attributes::Opacity do
|
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
55
|
-
context
|
56
|
-
it
|
51
|
+
context 'with an existing fill/stroke opacity' do
|
52
|
+
it 'multiplies the new opacity by the old' do
|
57
53
|
element.state.fill_opacity = 0.5
|
58
54
|
element.state.stroke_opacity = 0.8
|
59
55
|
|
@@ -68,8 +64,8 @@ describe Prawn::SVG::Attributes::Opacity do
|
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
71
|
-
context
|
72
|
-
it
|
67
|
+
context 'with stroke, fill, and opacity all specified' do
|
68
|
+
it 'choses the lower of them' do
|
73
69
|
element.properties.fill_opacity = '0.4'
|
74
70
|
element.properties.stroke_opacity = '0.6'
|
75
71
|
element.properties.opacity = '0.5'
|
@@ -16,10 +16,10 @@ describe Prawn::SVG::Attributes::Transform do
|
|
16
16
|
|
17
17
|
subject { element.send :parse_transform_attribute_and_call }
|
18
18
|
|
19
|
-
context
|
19
|
+
context 'when a non-identity matrix is requested' do
|
20
20
|
let(:transform) { 'translate(-5.5)' }
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'passes the transform and executes the returned matrix' do
|
23
23
|
expect(element).to receive(:parse_transform_attribute).with(transform).and_return([1, 2, 3, 4, 5, 6])
|
24
24
|
expect(element).to receive(:add_call_and_enter).with('transformation_matrix', 1, 2, 3, 4, 5, 6)
|
25
25
|
|
@@ -28,10 +28,10 @@ describe Prawn::SVG::Attributes::Transform do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
context
|
31
|
+
context 'when an identity matrix is requested' do
|
32
32
|
let(:transform) { 'translate(0)' }
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'does not execute any commands' do
|
35
35
|
expect(element).to receive(:parse_transform_attribute).with(transform).and_return([1, 0, 0, 1, 0, 0])
|
36
36
|
expect(element).not_to receive(:add_call_and_enter)
|
37
37
|
|
@@ -40,8 +40,8 @@ describe Prawn::SVG::Attributes::Transform do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
context
|
44
|
-
it
|
43
|
+
context 'when transform is blank' do
|
44
|
+
it 'does nothing' do
|
45
45
|
expect(element).not_to receive(:parse_transform_attribute)
|
46
46
|
expect(element).not_to receive(:add_call_and_enter)
|
47
47
|
|