prawn-svg 0.34.2 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f405c26de28dcc55e41e63ee5a6f8d433ab7dc4e9900bc3012e869689516698
4
- data.tar.gz: f6cfebbb831bbfd6a66608202285acd66a295de102ebd94a2a6be8e73454bec4
3
+ metadata.gz: 0567f606c8d50a83ca8521e9af1a39cda59c570086d624eb08f415e13e2e0623
4
+ data.tar.gz: 37e4d144020f202b293fb7106c7e9bcbe47b47bf3dd85ee6f811c757b89e1dc9
5
5
  SHA512:
6
- metadata.gz: e9092e304d63b84b8947e585448b627be95fcfbaad38b02e386bb9ed0b585871990a3ab1bc87a0480949141010aea67cb60c5c1ddc1be19b674056f8b7adceab
7
- data.tar.gz: 4dd717b2d65681f792951ef98a93df4dd1dd7a8f2f4f9caaa13ef7fce9a3428e8f2041e71537244167be257351f1a5720069e5b88c173145fc8f51ae31d1453f
6
+ metadata.gz: 89263ec912e718bb6405d0b4fd6b963665c1165bcedd8ec62226f7cfc4f8a80e9be771ceb55cfec45a65320e718724763f82dce20c274a6258da78f23394d91b
7
+ data.tar.gz: b87dfa3862f6679c530e2dfce0fcf9ef7a1e942cc2dff68f54bc6c053dd1b66915d2cae096a5d82e9905f35d3348a4e3a64bf02c0bb8491ef17826c890465e15
@@ -0,0 +1,19 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 3.3
16
+ bundler-cache: true
17
+
18
+ - name: Run RuboCop
19
+ run: bundle exec rubocop --parallel
@@ -1,35 +1,22 @@
1
1
  name: test
2
2
  on: [push, pull_request]
3
3
  jobs:
4
- rake_new:
4
+ test:
5
5
  runs-on: ubuntu-latest
6
6
  strategy:
7
7
  fail-fast: false
8
8
  matrix:
9
- ruby: [2.6, 2.7, '3.0', 3.1, 3.2, 3.3]
9
+ ruby: [2.7, '3.0', 3.1, 3.2, 3.3]
10
10
  steps:
11
- - uses: actions/checkout@v4
12
- - name: Set up Ruby
13
- uses: ruby/setup-ruby@v1
14
- with:
15
- bundler-cache: true
16
- ruby-version: ${{ matrix.ruby }}
17
- - name: Run tests
18
- run: bundle exec rake
19
- env:
20
- RUBYOPT: "--enable-frozen-string-literal"
21
- rake_old:
22
- runs-on: ubuntu-latest
23
- strategy:
24
- fail-fast: false
25
- matrix:
26
- ruby: [2.5]
27
- steps:
28
- - uses: actions/checkout@v4
29
- - name: Set up Ruby
30
- uses: ruby/setup-ruby@v1
31
- with:
32
- bundler-cache: true
33
- ruby-version: ${{ matrix.ruby }}
34
- - name: Run tests
35
- run: bundle exec rake
11
+ - uses: actions/checkout@v4
12
+ - name: Remove Gemfile.lock
13
+ run: rm -f Gemfile.lock
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ bundler-cache: true
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Run tests
20
+ run: bundle exec rake
21
+ env:
22
+ RUBYOPT: "--enable-frozen-string-literal"
data/.gitignore CHANGED
@@ -1,7 +1,6 @@
1
1
  .DS_Store
2
2
  spec/sample_output/*.pdf
3
3
  prawn-svg-*.gem
4
- Gemfile.lock
5
4
  .rvmrc
6
5
  .*.swp
7
6
  .ruby-version
data/.rubocop.yml ADDED
@@ -0,0 +1,86 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.7
5
+ NewCops: enable
6
+
7
+ Metrics/AbcSize:
8
+ Enabled: false
9
+
10
+ Metrics/BlockLength:
11
+ Enabled: false
12
+
13
+ Metrics/ClassLength:
14
+ Enabled: false
15
+
16
+ Metrics/CyclomaticComplexity:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ Metrics/ModuleLength:
23
+ Enabled: false
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Enabled: false
27
+
28
+ Style/Documentation:
29
+ Enabled: false
30
+
31
+ Style/FrozenStringLiteralComment:
32
+ Enabled: false
33
+
34
+ Style/ClassAndModuleChildren:
35
+ Enabled: false
36
+
37
+ Style/GuardClause:
38
+ Enabled: false
39
+
40
+ Style/SymbolArray:
41
+ Enabled: false
42
+
43
+ Style/WordArray:
44
+ Enabled: false
45
+
46
+ Layout/HashAlignment:
47
+ EnforcedHashRocketStyle: table
48
+ EnforcedColonStyle: table
49
+
50
+ Layout/FirstArgumentIndentation:
51
+ EnforcedStyle: consistent
52
+
53
+ Layout/ArgumentAlignment:
54
+ EnforcedStyle: with_fixed_indentation
55
+
56
+ Lint/SuppressedException:
57
+ Enabled: false
58
+
59
+ Style/AccessorGrouping:
60
+ Enabled: false
61
+
62
+ Style/PerlBackrefs:
63
+ Enabled: false
64
+
65
+ Naming/MethodParameterName:
66
+ Enabled: false
67
+
68
+ Metrics/ParameterLists:
69
+ Enabled: false
70
+
71
+ Metrics/BlockNesting:
72
+ Enabled: false
73
+
74
+ Naming/VariableNumber:
75
+ Enabled: false
76
+
77
+ Lint/ConstantDefinitionInBlock:
78
+ Exclude:
79
+ - spec/**/*.rb
80
+
81
+ Style/GlobalVars:
82
+ Exclude:
83
+ - spec/**/*.rb
84
+
85
+ Style/MultilineBlockChain:
86
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,51 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2024-06-16 03:19:10 UTC using RuboCop version 1.62.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowComments, AllowEmptyLambdas.
11
+ Lint/EmptyBlock:
12
+ Exclude:
13
+ - 'Rakefile'
14
+
15
+ # Offense count: 13
16
+ Lint/NonLocalExitFromIterator:
17
+ Exclude:
18
+ - 'lib/prawn/svg/css/selector_parser.rb'
19
+ - 'lib/prawn/svg/ttf.rb'
20
+
21
+ # Offense count: 1
22
+ Naming/AccessorMethodName:
23
+ Exclude:
24
+ - 'lib/prawn/svg/calculators/document_sizing.rb'
25
+
26
+ # Offense count: 1
27
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
28
+ # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
29
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
30
+ Naming/FileName:
31
+ Exclude:
32
+ - 'lib/prawn-svg.rb'
33
+
34
+ # Offense count: 9
35
+ # This cop supports safe autocorrection (--autocorrect).
36
+ Style/IfUnlessModifier:
37
+ Exclude:
38
+ - 'lib/prawn/svg/css/selector_parser.rb'
39
+ - 'lib/prawn/svg/elements/base.rb'
40
+ - 'lib/prawn/svg/elements/gradient.rb'
41
+ - 'lib/prawn/svg/elements/root.rb'
42
+ - 'lib/prawn/svg/elements/text_component.rb'
43
+ - 'lib/prawn/svg/elements/use.rb'
44
+ - 'lib/prawn/svg/loaders/file.rb'
45
+
46
+ # Offense count: 28
47
+ # This cop supports safe autocorrection (--autocorrect).
48
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
49
+ # URISchemes: http, https
50
+ Layout/LineLength:
51
+ Max: 180
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Declare your gem's dependencies in prawn-svg.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -10,5 +10,6 @@ gemspec
10
10
  # Git. Remember to move these dependencies to your gemspec before releasing
11
11
  # your gem to rubygems.org.
12
12
 
13
- # To use debugger
14
- # gem 'ruby-debug19', :require => 'ruby-debug'
13
+ gem 'rake', '~> 13.0'
14
+ gem 'rspec', '~> 3.0'
15
+ gem 'rubocop', '~> 1.64'
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prawn-svg (0.34.2)
5
+ css_parser (~> 1.6)
6
+ matrix (~> 0.4.2)
7
+ prawn (>= 0.11.1, < 3)
8
+ rexml (~> 3.2)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ addressable (2.8.6)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ ast (2.4.2)
16
+ bigdecimal (3.1.8)
17
+ css_parser (1.17.1)
18
+ addressable
19
+ diff-lcs (1.5.1)
20
+ json (2.7.2)
21
+ language_server-protocol (3.17.0.3)
22
+ matrix (0.4.2)
23
+ parallel (1.25.1)
24
+ parser (3.3.3.0)
25
+ ast (~> 2.4.1)
26
+ racc
27
+ pdf-core (0.10.0)
28
+ prawn (2.5.0)
29
+ matrix (~> 0.4)
30
+ pdf-core (~> 0.10.0)
31
+ ttfunk (~> 1.8)
32
+ public_suffix (5.1.0)
33
+ racc (1.8.0)
34
+ rainbow (3.1.1)
35
+ rake (13.2.1)
36
+ regexp_parser (2.9.2)
37
+ rexml (3.3.0)
38
+ strscan
39
+ rspec (3.13.0)
40
+ rspec-core (~> 3.13.0)
41
+ rspec-expectations (~> 3.13.0)
42
+ rspec-mocks (~> 3.13.0)
43
+ rspec-core (3.13.0)
44
+ rspec-support (~> 3.13.0)
45
+ rspec-expectations (3.13.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.13.0)
48
+ rspec-mocks (3.13.1)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.13.0)
51
+ rspec-support (3.13.1)
52
+ rubocop (1.64.1)
53
+ json (~> 2.3)
54
+ language_server-protocol (>= 3.17.0)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.3.0.2)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml (>= 3.2.5, < 4.0)
60
+ rubocop-ast (>= 1.31.1, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 2.4.0, < 3.0)
63
+ rubocop-ast (1.31.3)
64
+ parser (>= 3.3.1.0)
65
+ ruby-progressbar (1.13.0)
66
+ strscan (3.1.0)
67
+ ttfunk (1.8.0)
68
+ bigdecimal (~> 3.1)
69
+ unicode-display_width (2.5.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ prawn-svg!
76
+ rake (~> 13.0)
77
+ rspec (~> 3.0)
78
+ rubocop (~> 1.64)
79
+
80
+ BUNDLED WITH
81
+ 2.5.1
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.5.0.
13
+ The minimum Ruby version required is 2.7.
14
14
 
15
15
  ## Using prawn-svg
16
16
 
data/Rakefile CHANGED
@@ -23,4 +23,4 @@ require 'rspec/core/rake_task'
23
23
  RSpec::Core::RakeTask.new(:spec) do |spec|
24
24
  end
25
25
 
26
- task :default => :spec
26
+ task default: :spec
@@ -1,16 +1,16 @@
1
1
  module Prawn::SVG::Attributes::ClipPath
2
2
  def parse_clip_path_attribute_and_call
3
- return unless clip_path = properties.clip_path
3
+ return unless (clip_path = properties.clip_path)
4
4
  return if clip_path == 'none'
5
5
 
6
6
  clip_path_element = extract_element_from_url_id_reference(clip_path, 'clipPath')
7
7
 
8
8
  if clip_path_element.nil?
9
- document.warnings << "Could not resolve clip-path URI to a clipPath element"
9
+ document.warnings << 'Could not resolve clip-path URI to a clipPath element'
10
10
  else
11
11
  add_call_and_enter 'save_graphics_state'
12
12
  add_calls_from_element clip_path_element
13
- add_call "clip"
13
+ add_call 'clip'
14
14
  end
15
15
  end
16
16
  end
@@ -1,9 +1,9 @@
1
1
  module Prawn::SVG::Attributes::Opacity
2
2
  def parse_opacity_attributes_and_call
3
3
  # We can't do nested opacities quite like the SVG requires, but this is close enough.
4
- opacity = clamp(properties.opacity.to_f, 0, 1) if properties.opacity
5
- fill_opacity = clamp(properties.fill_opacity.to_f, 0, 1) if properties.fill_opacity
6
- stroke_opacity = clamp(properties.stroke_opacity.to_f, 0, 1) if properties.stroke_opacity
4
+ opacity = properties.opacity.to_f.clamp(0, 1) if properties.opacity
5
+ fill_opacity = properties.fill_opacity.to_f.clamp(0, 1) if properties.fill_opacity
6
+ stroke_opacity = properties.stroke_opacity.to_f.clamp(0, 1) if properties.stroke_opacity
7
7
 
8
8
  if opacity || fill_opacity || stroke_opacity
9
9
  state.fill_opacity *= [opacity || 1, fill_opacity || 1].min
@@ -1,9 +1,9 @@
1
1
  module Prawn::SVG::Attributes::Stroke
2
- CAP_STYLE_TRANSLATIONS = {"butt" => :butt, "round" => :round, "square" => :projecting_square}
3
- JOIN_STYLE_TRANSLATIONS = {"miter" => :miter, "round" => :round, "bevel" => :bevel}
2
+ CAP_STYLE_TRANSLATIONS = { 'butt' => :butt, 'round' => :round, 'square' => :projecting_square }.freeze
3
+ JOIN_STYLE_TRANSLATIONS = { 'miter' => :miter, 'round' => :round, 'bevel' => :bevel }.freeze
4
4
 
5
5
  def parse_stroke_attributes_and_call
6
- if width_string = properties.stroke_width
6
+ if (width_string = properties.stroke_width)
7
7
  width = pixels(width_string)
8
8
  state.stroke_width = width
9
9
  add_call('line_width', width)
@@ -12,12 +12,12 @@ module Prawn::SVG::Attributes::Stroke
12
12
  if (linecap = properties.stroke_linecap) && linecap != 'inherit'
13
13
  add_call('cap_style', CAP_STYLE_TRANSLATIONS.fetch(linecap, :butt))
14
14
  end
15
-
15
+
16
16
  if (linejoin = properties.stroke_linejoin) && linejoin != 'inherit'
17
17
  add_call('join_style', JOIN_STYLE_TRANSLATIONS.fetch(linejoin, :miter))
18
18
  end
19
19
 
20
- if dasharray = properties.stroke_dasharray
20
+ if (dasharray = properties.stroke_dasharray)
21
21
  case dasharray
22
22
  when 'inherit'
23
23
  # don't do anything
@@ -25,13 +25,13 @@ module Prawn::SVG::Attributes::Stroke
25
25
  add_call('undash')
26
26
  else
27
27
  array = dasharray.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
28
- array *= 2 if array.length % 2 == 1
29
- number_array = array.map {|value| pixels(value)}
28
+ array *= 2 if array.length.odd?
29
+ number_array = array.map { |value| pixels(value) }
30
30
 
31
- if number_array.any? {|number| number < 0}
31
+ if number_array.any?(&:negative?)
32
32
  @document.warnings << "stroke-dasharray cannot have negative numbers; treating as 'none'"
33
33
  add_call('undash')
34
- elsif number_array.inject(0) {|a, b| a + b} == 0
34
+ elsif number_array.inject(0) { |a, b| a + b }.zero?
35
35
  add_call('undash')
36
36
  else
37
37
  add_call('dash', number_array)
@@ -1,8 +1,8 @@
1
1
  module Prawn::SVG::Attributes::Transform
2
2
  def parse_transform_attribute_and_call
3
- return unless transform = attributes['transform']
3
+ return unless (transform = attributes['transform'])
4
4
 
5
5
  matrix = parse_transform_attribute(transform)
6
- add_call_and_enter "transformation_matrix", *matrix unless matrix == [1, 0, 0, 1, 0, 0]
6
+ add_call_and_enter 'transformation_matrix', *matrix unless matrix == [1, 0, 0, 1, 0, 0]
7
7
  end
8
8
  end
@@ -1,6 +1,6 @@
1
1
  module Prawn::SVG::Attributes
2
2
  end
3
3
 
4
- %w(transform opacity clip_path stroke space).each do |name|
4
+ %w[transform opacity clip_path stroke space].each do |name|
5
5
  require "prawn/svg/attributes/#{name}"
6
6
  end
@@ -7,15 +7,15 @@ module Prawn::SVG::Calculators
7
7
  def calculate_bezier_curve_points_for_arc(cx, cy, a, b, lambda_1, lambda_2, theta)
8
8
  e = lambda do |eta|
9
9
  [
10
- cx + a * Math.cos(theta) * Math.cos(eta) - b * Math.sin(theta) * Math.sin(eta),
11
- cy + a * Math.sin(theta) * Math.cos(eta) + b * Math.cos(theta) * Math.sin(eta)
10
+ cx + (a * Math.cos(theta) * Math.cos(eta)) - (b * Math.sin(theta) * Math.sin(eta)),
11
+ cy + (a * Math.sin(theta) * Math.cos(eta)) + (b * Math.cos(theta) * Math.sin(eta))
12
12
  ]
13
13
  end
14
14
 
15
15
  ep = lambda do |eta|
16
16
  [
17
- -a * Math.cos(theta) * Math.sin(eta) - b * Math.sin(theta) * Math.cos(eta),
18
- -a * Math.sin(theta) * Math.sin(eta) + b * Math.cos(theta) * Math.cos(eta)
17
+ (-a * Math.cos(theta) * Math.sin(eta)) - (b * Math.sin(theta) * Math.cos(eta)),
18
+ (-a * Math.sin(theta) * Math.sin(eta)) + (b * Math.cos(theta) * Math.cos(eta))
19
19
  ]
20
20
  end
21
21
 
@@ -28,28 +28,30 @@ module Prawn::SVG::Calculators
28
28
  # puts "error = #{calculate_curve_approximation_error(a, b, eta1, eta1 + d_eta)}"
29
29
  break
30
30
  end
31
+
31
32
  iterations *= 2
32
33
  d_lambda = (lambda_2 - lambda_1) / iterations
33
34
  end
34
35
 
35
36
  (0...iterations).collect do |iteration|
36
- eta_a, eta_b = calculate_eta_from_lambda(a, b, lambda_1+iteration*d_lambda, lambda_1+(iteration+1)*d_lambda)
37
+ eta_a, eta_b = calculate_eta_from_lambda(a, b, lambda_1 + (iteration * d_lambda),
38
+ lambda_1 + ((iteration + 1) * d_lambda))
37
39
  d_eta = eta_b - eta_a
38
40
 
39
- alpha = Math.sin(d_eta) * ((Math.sqrt(4 + 3 * Math.tan(d_eta / 2) ** 2) - 1) / 3)
41
+ alpha = Math.sin(d_eta) * ((Math.sqrt(4 + (3 * (Math.tan(d_eta / 2)**2))) - 1) / 3)
40
42
 
41
43
  x1, y1 = e[eta_a]
42
44
  x2, y2 = e[eta_b]
43
45
 
44
46
  ep_eta1_x, ep_eta1_y = ep[eta_a]
45
- q1_x = x1 + alpha * ep_eta1_x
46
- q1_y = y1 + alpha * ep_eta1_y
47
+ q1_x = x1 + (alpha * ep_eta1_x)
48
+ q1_y = y1 + (alpha * ep_eta1_y)
47
49
 
48
50
  ep_eta2_x, ep_eta2_y = ep[eta_b]
49
- q2_x = x2 - alpha * ep_eta2_x
50
- q2_y = y2 - alpha * ep_eta2_y
51
+ q2_x = x2 - (alpha * ep_eta2_x)
52
+ q2_y = y2 - (alpha * ep_eta2_y)
51
53
 
52
- {:p2 => [x2, y2], :q1 => [q1_x, q1_y], :q2 => [q2_x, q2_y]}
54
+ { p2: [x2, y2], q1: [q1_x, q1_y], q2: [q2_x, q2_y] }
53
55
  end
54
56
  end
55
57
 
@@ -68,7 +70,7 @@ module Prawn::SVG::Calculators
68
70
  [-0.0695069, -0.0437594, 0.0120636, 0.0163087],
69
71
  [-0.0328856, -0.00926032, -0.00173573, 0.00527385]
70
72
  ]
71
- ]
73
+ ].freeze
72
74
 
73
75
  ERROR_COEFFICIENTS_B = [
74
76
  [
@@ -83,7 +85,7 @@ module Prawn::SVG::Calculators
83
85
  [0.0156192, -0.017535, 0.00326508, -0.228157],
84
86
  [-0.0236752, 0.0405821, -0.0173086, 0.176187]
85
87
  ]
86
- ]
88
+ ].freeze
87
89
 
88
90
  def calculate_curve_approximation_error(a, b, eta1, eta2)
89
91
  b_over_a = b / a
@@ -92,11 +94,11 @@ module Prawn::SVG::Calculators
92
94
  c = lambda do |i|
93
95
  (0..3).inject(0) do |accumulator, j|
94
96
  coef = coefficents[i][j]
95
- accumulator + ((coef[0] * b_over_a**2 + coef[1] * b_over_a + coef[2]) / (b_over_a * coef[3])) * Math.cos(j * (eta1 + eta2))
97
+ accumulator + ((((coef[0] * (b_over_a**2)) + (coef[1] * b_over_a) + coef[2]) / (b_over_a * coef[3])) * Math.cos(j * (eta1 + eta2)))
96
98
  end
97
99
  end
98
100
 
99
- ((0.001 * b_over_a**2 + 4.98 * b_over_a + 0.207) / (b_over_a * 0.0067)) * a * Math.exp(c[0] + c[1] * (eta2 - eta1))
101
+ (((0.001 * (b_over_a**2)) + (4.98 * b_over_a) + 0.207) / (b_over_a * 0.0067)) * a * Math.exp(c[0] + (c[1] * (eta2 - eta1)))
100
102
  end
101
103
 
102
104
  def calculate_eta_from_lambda(a, b, lambda_1, lambda_2)
@@ -4,10 +4,10 @@ module Prawn::SVG::Calculators
4
4
  attr_reader :width, :height, :x, :y
5
5
 
6
6
  def initialize(value, container_dimensions, object_dimensions)
7
- values = (value || "xMidYMid meet").split(' ')
7
+ values = (value || 'xMidYMid meet').split
8
8
  @x = @y = 0
9
9
 
10
- if values.first == "defer"
10
+ if values.first == 'defer'
11
11
  @defer = true
12
12
  values.shift
13
13
  end
@@ -20,35 +20,37 @@ module Prawn::SVG::Calculators
20
20
  container_ratio = w_container / h_container.to_f
21
21
  object_ratio = w_object / h_object.to_f
22
22
 
23
- if @align == "none"
23
+ if @align == 'none'
24
24
  @width, @height = container_dimensions
25
25
  else
26
- matches = @align.to_s.strip.match(/\Ax(Min|Mid|Max)Y(Min|Mid|Max)\z/i) || [nil, "Mid", "Mid"]
26
+ matches = @align.to_s.strip.match(/\Ax(Min|Mid|Max)Y(Min|Mid|Max)\z/i) || [nil, 'Mid', 'Mid']
27
27
 
28
28
  if (container_ratio > object_ratio) == slice?
29
- @width, @height = [w_container, w_container / object_ratio]
29
+ @width = w_container
30
+ @height = w_container / object_ratio
30
31
  @y = case matches[2].downcase
31
- when "min" then 0
32
- when "mid" then (h_container - w_container/object_ratio)/2
33
- when "max" then h_container - w_container/object_ratio
32
+ when 'min' then 0
33
+ when 'mid' then (h_container - (w_container / object_ratio)) / 2
34
+ when 'max' then h_container - (w_container / object_ratio)
34
35
  end
35
36
  else
36
- @width, @height = [h_container * object_ratio, h_container]
37
+ @width = h_container * object_ratio
38
+ @height = h_container
37
39
  @x = case matches[1].downcase
38
- when "min" then 0
39
- when "mid" then (w_container - h_container*object_ratio)/2
40
- when "max" then w_container - h_container*object_ratio
40
+ when 'min' then 0
41
+ when 'mid' then (w_container - (h_container * object_ratio)) / 2
42
+ when 'max' then w_container - (h_container * object_ratio)
41
43
  end
42
44
  end
43
45
  end
44
46
  end
45
47
 
46
48
  def slice?
47
- @meet_or_slice == "slice"
49
+ @meet_or_slice == 'slice'
48
50
  end
49
51
 
50
52
  def meet?
51
- @meet_or_slice != "slice"
53
+ @meet_or_slice != 'slice'
52
54
  end
53
55
 
54
56
  def inspect
@@ -1,6 +1,6 @@
1
1
  module Prawn::SVG::Calculators
2
2
  class DocumentSizing
3
- DEFAULT_ASPECT_RATIO = "xMidYMid meet"
3
+ DEFAULT_ASPECT_RATIO = 'xMidYMid meet'.freeze
4
4
 
5
5
  attr_writer :document_width, :document_height
6
6
  attr_writer :view_box, :preserve_aspect_ratio
@@ -33,21 +33,20 @@ module Prawn::SVG::Calculators
33
33
 
34
34
  if @view_box
35
35
  values = @view_box.strip.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
36
- @x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f}
36
+ @x_offset, @y_offset, @viewport_width, @viewport_height = values.map(&:to_f)
37
37
 
38
- if @viewport_width > 0 && @viewport_height > 0
38
+ if @viewport_width.positive? && @viewport_height.positive?
39
39
  # If neither the width nor height was specified, use the entire width and the viewbox ratio
40
40
  # to determine the height.
41
- if @output_width.nil? && @output_height.nil?
42
- @output_width = container_width
43
- end
41
+ @output_width = container_width if @output_width.nil? && @output_height.nil?
44
42
 
45
43
  # If one of the output dimensions is missing, calculate it from the other one
46
44
  # using the ratio of the viewport width to height.
47
45
  @output_width ||= @output_height * @viewport_width / @viewport_height
48
46
  @output_height ||= @output_width * @viewport_height / @viewport_width
49
47
 
50
- aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height], [@viewport_width, @viewport_height])
48
+ aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height],
49
+ [@viewport_width, @viewport_height])
51
50
  @x_scale = aspect.width / @viewport_width
52
51
  @y_scale = aspect.height / @viewport_height
53
52
  @x_offset -= aspect.x / @x_scale
@@ -64,7 +63,7 @@ module Prawn::SVG::Calculators
64
63
  return if invalid?
65
64
 
66
65
  # SVG 1.1 section 7.10
67
- @viewport_diagonal = Math.sqrt(@viewport_width**2 + @viewport_height**2) / Math.sqrt(2)
66
+ @viewport_diagonal = Math.sqrt((@viewport_width**2) + (@viewport_height**2)) / Math.sqrt(2)
68
67
 
69
68
  if @requested_width
70
69
  scale = @requested_width / @output_width
@@ -94,11 +93,11 @@ module Prawn::SVG::Calculators
94
93
  end
95
94
 
96
95
  def requested_width=(value)
97
- @requested_width = (value.to_f if value)
96
+ @requested_width = value&.to_f
98
97
  end
99
98
 
100
99
  def requested_height=(value)
101
- @requested_height = (value.to_f if value)
100
+ @requested_height = value&.to_f
102
101
  end
103
102
  end
104
103
  end