prawn-svg 0.34.2 → 0.35.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +19 -0
  3. data/.github/workflows/test.yml +14 -27
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +86 -0
  6. data/.rubocop_todo.yml +51 -0
  7. data/Gemfile +4 -3
  8. data/Gemfile.lock +81 -0
  9. data/README.md +1 -1
  10. data/Rakefile +1 -1
  11. data/lib/prawn/svg/attributes/clip_path.rb +3 -3
  12. data/lib/prawn/svg/attributes/opacity.rb +3 -3
  13. data/lib/prawn/svg/attributes/stroke.rb +9 -9
  14. data/lib/prawn/svg/attributes/transform.rb +2 -2
  15. data/lib/prawn/svg/attributes.rb +1 -1
  16. data/lib/prawn/svg/calculators/arc_to_bezier_curve.rb +17 -15
  17. data/lib/prawn/svg/calculators/aspect_ratio.rb +16 -14
  18. data/lib/prawn/svg/calculators/document_sizing.rb +9 -10
  19. data/lib/prawn/svg/calculators/pixels.rb +8 -5
  20. data/lib/prawn/svg/color.rb +209 -212
  21. data/lib/prawn/svg/css/font_family_parser.rb +2 -2
  22. data/lib/prawn/svg/css/selector_parser.rb +39 -35
  23. data/lib/prawn/svg/css/stylesheets.rb +24 -24
  24. data/lib/prawn/svg/css/values_parser.rb +68 -0
  25. data/lib/prawn/svg/document.rb +6 -5
  26. data/lib/prawn/svg/elements/base.rb +29 -34
  27. data/lib/prawn/svg/elements/circle.rb +4 -4
  28. data/lib/prawn/svg/elements/clip_path.rb +0 -1
  29. data/lib/prawn/svg/elements/depth_first_base.rb +6 -6
  30. data/lib/prawn/svg/elements/ellipse.rb +3 -4
  31. data/lib/prawn/svg/elements/gradient.rb +49 -51
  32. data/lib/prawn/svg/elements/image.rb +5 -5
  33. data/lib/prawn/svg/elements/marker.rb +5 -5
  34. data/lib/prawn/svg/elements/path.rb +46 -47
  35. data/lib/prawn/svg/elements/polygon.rb +1 -1
  36. data/lib/prawn/svg/elements/polyline.rb +2 -2
  37. data/lib/prawn/svg/elements/rect.rb +3 -3
  38. data/lib/prawn/svg/elements/text.rb +1 -1
  39. data/lib/prawn/svg/elements/text_component.rb +22 -22
  40. data/lib/prawn/svg/elements/use.rb +3 -7
  41. data/lib/prawn/svg/elements/viewport.rb +1 -3
  42. data/lib/prawn/svg/elements.rb +30 -29
  43. data/lib/prawn/svg/extension.rb +2 -1
  44. data/lib/prawn/svg/font.rb +7 -7
  45. data/lib/prawn/svg/font_registry.rb +13 -13
  46. data/lib/prawn/svg/gradients.rb +3 -2
  47. data/lib/prawn/svg/interface.rb +4 -3
  48. data/lib/prawn/svg/loaders/data.rb +2 -2
  49. data/lib/prawn/svg/loaders/file.rb +12 -14
  50. data/lib/prawn/svg/loaders/web.rb +4 -8
  51. data/lib/prawn/svg/pathable.rb +41 -37
  52. data/lib/prawn/svg/properties.rb +34 -33
  53. data/lib/prawn/svg/renderer.rb +7 -7
  54. data/lib/prawn/svg/state.rb +1 -1
  55. data/lib/prawn/svg/transform_parser.rb +5 -5
  56. data/lib/prawn/svg/ttf.rb +21 -17
  57. data/lib/prawn/svg/url_loader.rb +1 -1
  58. data/lib/prawn/svg/version.rb +1 -1
  59. data/lib/prawn-svg.rb +1 -0
  60. data/prawn-svg.gemspec +4 -6
  61. data/spec/integration_spec.rb +77 -70
  62. data/spec/prawn/svg/attributes/opacity_spec.rb +11 -15
  63. data/spec/prawn/svg/attributes/transform_spec.rb +6 -6
  64. data/spec/prawn/svg/calculators/aspect_ratio_spec.rb +50 -50
  65. data/spec/prawn/svg/calculators/document_sizing_spec.rb +35 -35
  66. data/spec/prawn/svg/calculators/pixels_spec.rb +31 -30
  67. data/spec/prawn/svg/color_spec.rb +31 -31
  68. data/spec/prawn/svg/css/font_family_parser_spec.rb +12 -12
  69. data/spec/prawn/svg/css/selector_parser_spec.rb +21 -21
  70. data/spec/prawn/svg/css/stylesheets_spec.rb +51 -45
  71. data/spec/prawn/svg/css/values_parser_spec.rb +16 -0
  72. data/spec/prawn/svg/document_spec.rb +15 -14
  73. data/spec/prawn/svg/elements/base_spec.rb +39 -34
  74. data/spec/prawn/svg/elements/gradient_spec.rb +39 -39
  75. data/spec/prawn/svg/elements/line_spec.rb +22 -22
  76. data/spec/prawn/svg/elements/marker_spec.rb +36 -40
  77. data/spec/prawn/svg/elements/path_spec.rb +134 -110
  78. data/spec/prawn/svg/elements/polygon_spec.rb +18 -18
  79. data/spec/prawn/svg/elements/polyline_spec.rb +16 -16
  80. data/spec/prawn/svg/elements/text_spec.rb +149 -127
  81. data/spec/prawn/svg/font_registry_spec.rb +34 -34
  82. data/spec/prawn/svg/font_spec.rb +4 -4
  83. data/spec/prawn/svg/interface_spec.rb +47 -39
  84. data/spec/prawn/svg/loaders/data_spec.rb +21 -21
  85. data/spec/prawn/svg/loaders/file_spec.rb +43 -40
  86. data/spec/prawn/svg/loaders/web_spec.rb +15 -15
  87. data/spec/prawn/svg/pathable_spec.rb +21 -21
  88. data/spec/prawn/svg/properties_spec.rb +51 -51
  89. data/spec/prawn/svg/transform_parser_spec.rb +12 -12
  90. data/spec/prawn/svg/ttf_spec.rb +5 -5
  91. data/spec/prawn/svg/url_loader_spec.rb +25 -23
  92. data/spec/spec_helper.rb +4 -4
  93. metadata +12 -143
@@ -12,7 +12,7 @@ class Prawn::SVG::State
12
12
  @computed_properties = Prawn::SVG::Properties.new.load_default_stylesheet
13
13
  end
14
14
 
15
- def initialize_dup(other)
15
+ def initialize_dup(_other)
16
16
  @computed_properties = @computed_properties.dup
17
17
  end
18
18
 
@@ -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 { |a| a.to_f }
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 != 6
49
- warnings << "transform 'matrix' must have six arguments"
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", "true", "typ1"]
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, "rb") do |f|
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
- format, name_count, string_offset = data[0..5].unpack("nnn")
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, platform_specific_id, language_id, name_id, length, offset = data[start..start+11].unpack("nnnnnn")
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] = if UTF_16BE_PLATFORM_IDS.include?(platform_id)
50
- field.force_encoding(Encoding::UTF_16BE).encode(Encoding::UTF_8) rescue field
51
- else
52
- field
53
- end
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]
@@ -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, "No handler available for this URL scheme"
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)
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.34.2'
3
+ VERSION = '0.35.0'.freeze
4
4
  end
5
5
  end
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 = <<-EOT.strip
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
- EOT
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.5.0'
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
@@ -1,100 +1,100 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Integration test" do
3
+ describe 'Integration test' do
4
4
  root = "#{File.dirname(__FILE__)}/.."
5
5
 
6
- describe "a basic SVG file" do
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
- <<-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>
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 "is correctly converted to a call stack" do
27
+ it 'is correctly converted to a call stack' do
28
28
  element.process
29
29
 
30
30
  expect(element.calls).to eq [
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], {}, []]
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
- ["restore", [], {}, []],
41
- ["save", [], {}, []],
42
- ["fill_color", ["008000"], {}, []],
43
- ["fill", [], {}, [
44
- ["rectangle", [[10.0, 200.0], 10.0, 10.0], {}, []]
40
+ ['restore', [], {}, []],
41
+ ['save', [], {}, []],
42
+ ['fill_color', ['008000'], {}, []],
43
+ ['fill', [], {}, [
44
+ ['rectangle', [[10.0, 200.0], 10.0, 10.0], {}, []]
45
45
  ]],
46
- ["restore", [], {}, []],
47
- ["save", [], {}, []],
48
- ["fill_color", ["ff0000"], {}, []],
49
- ["fill", [], {}, [
50
- ["rectangle", [[20.0, 200.0], 10.0, 10.0], {}, []]
46
+ ['restore', [], {}, []],
47
+ ['save', [], {}, []],
48
+ ['fill_color', ['ff0000'], {}, []],
49
+ ['fill', [], {}, [
50
+ ['rectangle', [[20.0, 200.0], 10.0, 10.0], {}, []]
51
51
  ]],
52
- ["restore", [], {}, []],
53
- ["save", [], {}, []],
54
- ["fill_color", ["ffff00"], {}, []],
55
- ["fill", [], {}, [
56
- ["rectangle", [[30.0, 200.0], 10.0, 10.0], {}, []]
52
+ ['restore', [], {}, []],
53
+ ['save', [], {}, []],
54
+ ['fill_color', ['ffff00'], {}, []],
55
+ ['fill', [], {}, [
56
+ ['rectangle', [[30.0, 200.0], 10.0, 10.0], {}, []]
57
57
  ]],
58
- ["restore", [], {}, []]
58
+ ['restore', [], {}, []]
59
59
  ]
60
60
  end
61
61
  end
62
62
 
63
- context "with option :position" do
64
- let(:svg) { IO.read("#{root}/spec/sample_svg/cubic01a.svg") }
63
+ context 'with option :position' do
64
+ let(:svg) { File.read("#{root}/spec/sample_svg/cubic01a.svg") }
65
65
 
66
- it "aligns the image as requested" do
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, :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
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 "with option :vposition" do
80
- let(:svg) { IO.read("#{root}/spec/sample_svg/cubic01a.svg") }
79
+ context 'with option :vposition' do
80
+ let(:svg) { File.read("#{root}/spec/sample_svg/cubic01a.svg") }
81
81
 
82
- it "aligns the image as requested" do
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, :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
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 "sample file rendering" do
94
+ describe 'sample file rendering' do
95
95
  files = Dir["#{root}/spec/sample_svg/*.svg"]
96
96
 
97
- it "has at least 10 SVG sample files to test" do
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 IO.read(file), :at => [0, prawn.bounds.top], :width => prawn.bounds.width, :enable_file_requests_with_root => File.dirname(__FILE__) do |doc|
108
- doc.url_loader.add_to_cache("https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-wide.jpg", IO.read("#{root}/spec/sample_images/mushroom-wide.jpg"))
109
- doc.url_loader.add_to_cache("https://raw.githubusercontent.com/mogest/prawn-svg/master/spec/sample_images/mushroom-long.jpg", IO.read("#{root}/spec/sample_images/mushroom-long.jpg"))
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 {|w| w =~ /Verdana/ && w =~ /is not a known font/ || w =~ /(render gradients$|waiting on the Prawn project)/}
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 "multiple file rendering" do
120
- it "renders multiple files on to the same PDF" do
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 "This is multiple SVGs being output to the same PDF", :at => [0, y]
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 IO.read("#{root}/spec/sample_svg/arcs01.svg"), :at => [0, y], :width => width / 2
129
- prawn.svg IO.read("#{root}/spec/sample_svg/circle01.svg"), :at => [width / 2, y], :width => width / 2
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 "Here are some more PDFs below", :at => [0, y]
139
+ prawn.draw_text 'Here are some more PDFs below', at: [0, y]
133
140
 
134
141
  y -= 12
135
- prawn.svg IO.read("#{root}/spec/sample_svg/quad01.svg"), :at => [0, y], :width => width / 3
136
- prawn.svg IO.read("#{root}/spec/sample_svg/rect01.svg"), :at => [width / 3, y], :width => width / 3
137
- prawn.svg IO.read("#{root}/spec/sample_svg/rect02.svg"), :at => [width / 3 * 2, y], :width => width / 3
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 "#parse_opacity_attributes_and_call" do
17
+ describe '#parse_opacity_attributes_and_call' do
22
18
  subject { element.parse_opacity_attributes_and_call }
23
19
 
24
- context "with no opacity specified" do
25
- it "does nothing" do
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 "with opacity" do
32
- it "sets fill and stroke opacity" do
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 "with just fill opacity" do
44
- it "sets fill opacity and sets stroke opacity to 1" do
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 "with an existing fill/stroke opacity" do
56
- it "multiplies the new opacity by the old" do
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 "with stroke, fill, and opacity all specified" do
72
- it "choses the lower of them" do
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 "when a non-identity matrix is requested" do
19
+ context 'when a non-identity matrix is requested' do
20
20
  let(:transform) { 'translate(-5.5)' }
21
21
 
22
- it "passes the transform and executes the returned matrix" do
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 "when an identity matrix is requested" do
31
+ context 'when an identity matrix is requested' do
32
32
  let(:transform) { 'translate(0)' }
33
33
 
34
- it "does not execute any commands" do
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 "when transform is blank" do
44
- it "does nothing" do
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
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
1
+ require "#{File.dirname(__FILE__)}/../../../spec_helper"
2
2
 
3
3
  describe Prawn::SVG::Calculators::AspectRatio do
4
4
  def test(*args)
@@ -6,90 +6,90 @@ describe Prawn::SVG::Calculators::AspectRatio do
6
6
  [[aspect.width, aspect.height], [aspect.x, aspect.y]]
7
7
  end
8
8
 
9
- it "handles none" do
10
- expect(test "none", [50,80], [100,100]).to eq [[50, 80], [0, 0]]
11
- expect(test "none", [100,100], [50,80]).to eq [[100, 100], [0, 0]]
9
+ it 'handles none' do
10
+ expect(test('none', [50, 80], [100, 100])).to eq [[50, 80], [0, 0]]
11
+ expect(test('none', [100, 100], [50, 80])).to eq [[100, 100], [0, 0]]
12
12
  end
13
13
 
14
- context "using meet" do
15
- context "with smaller containers than objects" do
16
- let(:coords) { [[50,80], [100,100]] }
14
+ context 'using meet' do
15
+ context 'with smaller containers than objects' do
16
+ let(:coords) { [[50, 80], [100, 100]] }
17
17
 
18
- it "correctly calculates the result" do
19
- expect(test "xMidYMid meet", *coords).to eq [[50, 50], [0, 15]]
20
- expect(test "xMinYMin meet", *coords).to eq [[50, 50], [0, 0]]
21
- expect(test "xMaxYMax meet", *coords).to eq [[50, 50], [0, 30]]
18
+ it 'correctly calculates the result' do
19
+ expect(test('xMidYMid meet', *coords)).to eq [[50, 50], [0, 15]]
20
+ expect(test('xMinYMin meet', *coords)).to eq [[50, 50], [0, 0]]
21
+ expect(test('xMaxYMax meet', *coords)).to eq [[50, 50], [0, 30]]
22
22
  end
23
23
  end
24
24
 
25
- context "with bigger containers than objects" do
26
- let(:coords) { [[100,80], [50,50]] }
25
+ context 'with bigger containers than objects' do
26
+ let(:coords) { [[100, 80], [50, 50]] }
27
27
 
28
- it "correctly calculates the result" do
29
- expect(test "xMidYMid meet", *coords).to eq [[80, 80], [10, 0]]
30
- expect(test "xMinYMin meet", *coords).to eq [[80, 80], [0, 0]]
31
- expect(test "xMaxYMax meet", *coords).to eq [[80, 80], [20, 0]]
28
+ it 'correctly calculates the result' do
29
+ expect(test('xMidYMid meet', *coords)).to eq [[80, 80], [10, 0]]
30
+ expect(test('xMinYMin meet', *coords)).to eq [[80, 80], [0, 0]]
31
+ expect(test('xMaxYMax meet', *coords)).to eq [[80, 80], [20, 0]]
32
32
  end
33
33
  end
34
34
 
35
- context "with bigger square containers" do
36
- let(:coords) { [[100,100], [50,80]] }
35
+ context 'with bigger square containers' do
36
+ let(:coords) { [[100, 100], [50, 80]] }
37
37
 
38
- it "correctly calculates the result" do
39
- expect(test "xMidYMid meet", *coords).to eq [[62.5, 100], [18.75, 0]]
40
- expect(test "xMinYMin meet", *coords).to eq [[62.5, 100], [0, 0]]
41
- expect(test "xMaxYMax meet", *coords).to eq [[62.5, 100], [37.5, 0]]
38
+ it 'correctly calculates the result' do
39
+ expect(test('xMidYMid meet', *coords)).to eq [[62.5, 100], [18.75, 0]]
40
+ expect(test('xMinYMin meet', *coords)).to eq [[62.5, 100], [0, 0]]
41
+ expect(test('xMaxYMax meet', *coords)).to eq [[62.5, 100], [37.5, 0]]
42
42
  end
43
43
  end
44
44
 
45
- context "with oddly shaped containers" do
46
- let(:coords) { [[100,20], [50,50]] }
45
+ context 'with oddly shaped containers' do
46
+ let(:coords) { [[100, 20], [50, 50]] }
47
47
 
48
- it "correctly calculates the result" do
49
- expect(test "xMidYMid meet", *coords).to eq [[20, 20], [40, 0]]
50
- expect(test "xMinYMin meet", *coords).to eq [[20, 20], [0, 0]]
51
- expect(test "xMaxYMax meet", *coords).to eq [[20, 20], [80, 0]]
48
+ it 'correctly calculates the result' do
49
+ expect(test('xMidYMid meet', *coords)).to eq [[20, 20], [40, 0]]
50
+ expect(test('xMinYMin meet', *coords)).to eq [[20, 20], [0, 0]]
51
+ expect(test('xMaxYMax meet', *coords)).to eq [[20, 20], [80, 0]]
52
52
  end
53
53
  end
54
54
  end
55
55
 
56
- context "using slice" do
57
- context "with smaller containers than objects" do
58
- let(:coords) { [[50,80], [100,100]] }
56
+ context 'using slice' do
57
+ context 'with smaller containers than objects' do
58
+ let(:coords) { [[50, 80], [100, 100]] }
59
59
 
60
- it "correctly calculates the result" do
61
- expect(test "xMidYMid slice", *coords).to eq [[80, 80], [-15, 0]]
62
- expect(test "xMinYMin slice", *coords).to eq [[80, 80], [0, 0]]
63
- expect(test "xMaxYMax slice", *coords).to eq [[80, 80], [-30, 0]]
60
+ it 'correctly calculates the result' do
61
+ expect(test('xMidYMid slice', *coords)).to eq [[80, 80], [-15, 0]]
62
+ expect(test('xMinYMin slice', *coords)).to eq [[80, 80], [0, 0]]
63
+ expect(test('xMaxYMax slice', *coords)).to eq [[80, 80], [-30, 0]]
64
64
  end
65
65
  end
66
66
 
67
- context "with bigger containers than objects" do
68
- let(:coords) { [[100,80], [50,50]] }
67
+ context 'with bigger containers than objects' do
68
+ let(:coords) { [[100, 80], [50, 50]] }
69
69
 
70
- it "correctly calculates the result" do
71
- expect(test "xMidYMid slice", *coords).to eq [[100, 100], [0, -10]]
72
- expect(test "xMinYMin slice", *coords).to eq [[100, 100], [0, 0]]
73
- expect(test "xMaxYMax slice", *coords).to eq [[100, 100], [0, -20]]
70
+ it 'correctly calculates the result' do
71
+ expect(test('xMidYMid slice', *coords)).to eq [[100, 100], [0, -10]]
72
+ expect(test('xMinYMin slice', *coords)).to eq [[100, 100], [0, 0]]
73
+ expect(test('xMaxYMax slice', *coords)).to eq [[100, 100], [0, -20]]
74
74
  end
75
75
  end
76
76
 
77
- context "with oddly shaped containers" do
78
- let(:coords) { [[100,20], [50,50]] }
77
+ context 'with oddly shaped containers' do
78
+ let(:coords) { [[100, 20], [50, 50]] }
79
79
 
80
- it "correctly calculates the result" do
81
- expect(test "xMidYMid slice", *coords).to eq [[100, 100], [0, -40]]
82
- expect(test "xMinYMin slice", *coords).to eq [[100, 100], [0, 0]]
83
- expect(test "xMaxYMax slice", *coords).to eq [[100, 100], [0, -80]]
80
+ it 'correctly calculates the result' do
81
+ expect(test('xMidYMid slice', *coords)).to eq [[100, 100], [0, -40]]
82
+ expect(test('xMinYMin slice', *coords)).to eq [[100, 100], [0, 0]]
83
+ expect(test('xMaxYMax slice', *coords)).to eq [[100, 100], [0, -80]]
84
84
  end
85
85
  end
86
86
  end
87
87
 
88
88
  it "defaults to 'xMidYMid meet' if nothing is supplied" do
89
- expect(test "", [50,80], [100,100]).to eq test "xMidYMid meet", [50,80], [100,100]
89
+ expect(test('', [50, 80], [100, 100])).to eq test 'xMidYMid meet', [50, 80], [100, 100]
90
90
  end
91
91
 
92
92
  it "defaults to 'xMidYMid meet' if something invalid is supplied" do
93
- expect(test "completely invalid", [50,80], [100,100]).to eq test "xMidYMid meet", [50,80], [100,100]
93
+ expect(test('completely invalid', [50, 80], [100, 100])).to eq test 'xMidYMid meet', [50, 80], [100, 100]
94
94
  end
95
95
  end