prawn-svg 0.27.0 → 0.27.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05bd5082f2d3bfb40a2776b9b8239ec0d345e826
4
- data.tar.gz: 77c9df1c4f8bab6198ea45a0531314deac6e7a59
3
+ metadata.gz: 78e98b74bfb10e36c2de7a051662546c98ddcfa5
4
+ data.tar.gz: 9fe692aebb49298a976f9436141c9bf9f4e3b750
5
5
  SHA512:
6
- metadata.gz: 8d429c038aade4dad263441309d48f43e8ea185f67f85de9e556cbb1b2f50dd19af4bc6345e0a62388eaca504caea8d00506404630be11efea206a28a3b680f3
7
- data.tar.gz: 83bc2528c2ba901523e3d54e32098852d354d35c07fc7bacbbc2583526422e8d2f613195e94145efeb56eeeb0d2db427b59bd0f1da19f888cc21f0b2cb7fbb7f
6
+ metadata.gz: bca8bd9a84bb372434d0a6aac7911c13e097fbdc30e788c9dad883a922237b384cc6f9786a3992193bd46ee47e562274bbe5e7f39a7ad6eba0a9311422e40c24
7
+ data.tar.gz: 67af84522eb27d03b18afa2d9f6309b4a2588f411ddf123681dd69bf34992a85c2aab62946d87ab025bb12c66df3e2189b3543c5eba4e79c4de691003206696b
@@ -28,14 +28,25 @@ module Prawn::SVG::Calculators
28
28
  container_width = @requested_width || @bounds[0]
29
29
  container_height = @requested_height || @bounds[1]
30
30
 
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)
31
+ @output_width = Pixels::Measurement.to_pixels(@document_width || @requested_width, container_width)
32
+ @output_height = Pixels::Measurement.to_pixels(@document_height || @requested_height, container_height)
33
33
 
34
34
  if @view_box
35
35
  values = @view_box.strip.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
36
36
  @x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f}
37
37
 
38
38
  if @viewport_width > 0 && @viewport_height > 0
39
+ # If neither the width nor height was specified, use the entire space available
40
+ if @output_width.nil? && @output_height.nil?
41
+ @output_width = container_width
42
+ @output_height = container_height
43
+ end
44
+
45
+ # If one of the output dimensions is missing, calculate it from the other one
46
+ # using the ratio of the viewport width to height.
47
+ @output_width ||= @output_height * @viewport_width / @viewport_height
48
+ @output_height ||= @output_width * @viewport_height / @viewport_width
49
+
39
50
  aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height], [@viewport_width, @viewport_height])
40
51
  @x_scale = aspect.width / @viewport_width
41
52
  @y_scale = aspect.height / @viewport_height
@@ -43,6 +54,9 @@ module Prawn::SVG::Calculators
43
54
  @y_offset -= aspect.y / @y_scale
44
55
  end
45
56
  else
57
+ @output_width ||= container_width
58
+ @output_height ||= container_height
59
+
46
60
  @viewport_width = @output_width
47
61
  @viewport_height = @output_height
48
62
  end
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.27.0'
3
+ VERSION = '0.27.1'
4
4
  end
5
5
  end
@@ -113,6 +113,34 @@ describe Prawn::SVG::Calculators::DocumentSizing do
113
113
  end
114
114
  end
115
115
 
116
+ context "when a viewBox and a requested width is supplied" do
117
+ let(:attributes) { {"viewBox" => "0 0 100 200"} }
118
+
119
+ it "uses the requested width and calculates the height based on the viewBox" do
120
+ sizing.requested_width = 550
121
+ sizing.calculate
122
+
123
+ expect(sizing.viewport_width).to eq 100
124
+ expect(sizing.viewport_height).to eq 200
125
+ expect(sizing.output_width).to eq 550
126
+ expect(sizing.output_height).to eq 1100
127
+ end
128
+ end
129
+
130
+ context "when a viewBox and a requested height is supplied" do
131
+ let(:attributes) { {"viewBox" => "0 0 100 200"} }
132
+
133
+ it "uses the requested height and calculates the width based on the viewBox" do
134
+ sizing.requested_height = 400
135
+ sizing.calculate
136
+
137
+ expect(sizing.viewport_width).to eq 100
138
+ expect(sizing.viewport_height).to eq 200
139
+ expect(sizing.output_width).to eq 200
140
+ expect(sizing.output_height).to eq 400
141
+ end
142
+ end
143
+
116
144
  context "when neither viewBox nor requested width/height specified" do
117
145
  let(:attributes) { {} }
118
146
 
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.27.0
4
+ version: 0.27.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-31 00:00:00.000000000 Z
11
+ date: 2017-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn