prawn-svg 0.25.1 → 0.25.2

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: 920f166e2e978e119012447d12239650468aa192
4
- data.tar.gz: 4a55b681c5c4907dbf9e938da0ccd41217d1623f
3
+ metadata.gz: bc0f179818ef67c8d26893204ed003aade48b1e2
4
+ data.tar.gz: 061d2ab83b313f9973d2a480e51f2fd5d288fb0e
5
5
  SHA512:
6
- metadata.gz: 7934d9a7adaf305002aaea55e2d0acd58ff1d2a3307797f18f2bdb69281cebbcafb4acb16efce262643d28154e28cf160ad0a298e76c83e0913139ef37aebf6e
7
- data.tar.gz: a032d3e73d64fb48f3cffefb83a16b059fce5bbd491d73c90512c50056e590758ee0acfde004ae8892f1dc1b7dc50f00bc0ef3aa53393aa2842b3b1480b35e4e
6
+ metadata.gz: 1df75e7819f4b9c3d016e386ca48bf4041d490da015f808880ff5bc78f40659b37313eb31bbf4106e1d17212e4965bb43bb0b32899ea6fd3003a7e8e3bf3270f
7
+ data.tar.gz: a693b8ed00d9ee605dc924a0fce2160936662fa11f5555b98b02cf480e8057808f2b6ae2b5ad07d2b42939777ce3f60fb1123d481ea8f2f1e5b97ade42293b82
@@ -39,12 +39,16 @@ class Prawn::SVG::Document
39
39
  )
40
40
 
41
41
  @sizing = Prawn::SVG::Calculators::DocumentSizing.new(bounds, @root.attributes)
42
- sizing.requested_width = options[:width]
43
- sizing.requested_height = options[:height]
44
- sizing.calculate
42
+ calculate_sizing(requested_width: options[:width], requested_height: options[:height])
45
43
 
46
44
  @css_parser = CssParser::Parser.new
47
45
 
48
46
  yield self if block_given?
49
47
  end
48
+
49
+ def calculate_sizing(requested_width: nil, requested_height: nil)
50
+ sizing.requested_width = requested_width
51
+ sizing.requested_height = requested_height
52
+ sizing.calculate
53
+ end
50
54
  end
@@ -52,14 +52,12 @@ class Prawn::SVG::Font
52
52
  # Construct a subfamily name from the weight and style information.
53
53
  # Note that this name might not actually exist in the font.
54
54
  def subfamily_name
55
- sfn = if weight == :normal && style
55
+ if weight == :normal && style
56
56
  style
57
57
  elsif weight || style
58
- "#{weight} #{style}"
58
+ [weight, style].compact.join('_').to_sym
59
59
  else
60
- "normal"
60
+ :normal
61
61
  end
62
-
63
- sfn.strip.gsub(/\s+/, "_").downcase.to_sym
64
62
  end
65
63
  end
@@ -3,7 +3,8 @@ class Prawn::SVG::FontRegistry
3
3
  "/Library/Fonts",
4
4
  "/System/Library/Fonts",
5
5
  "#{ENV["HOME"]}/Library/Fonts",
6
- "/usr/share/fonts/truetype"
6
+ "/usr/share/fonts/truetype",
7
+ "/mnt/c/Windows/Fonts", # Bash on Ubuntu on Windows
7
8
  ]
8
9
 
9
10
  @font_path = DEFAULT_FONT_PATHS.select { |path| Dir.exist?(path) }
@@ -39,19 +39,29 @@ module Prawn
39
39
 
40
40
  @document.warnings.clear
41
41
 
42
- prawn.bounding_box(position, :width => @document.sizing.output_width, :height => @document.sizing.output_height) do
43
- prawn.save_graphics_state do
44
- clip_rectangle 0, 0, @document.sizing.output_width, @document.sizing.output_height
42
+ prawn.save_font do
43
+ prawn.bounding_box(position, :width => @document.sizing.output_width, :height => @document.sizing.output_height) do
44
+ prawn.save_graphics_state do
45
+ clip_rectangle 0, 0, @document.sizing.output_width, @document.sizing.output_height
45
46
 
46
- calls = []
47
- root_element = Prawn::SVG::Elements::Root.new(@document, @document.root, calls)
48
- root_element.process
47
+ calls = []
48
+ root_element = Prawn::SVG::Elements::Root.new(@document, @document.root, calls)
49
+ root_element.process
49
50
 
50
- proc_creator(prawn, calls).call
51
+ proc_creator(prawn, calls).call
52
+ end
51
53
  end
52
54
  end
53
55
  end
54
56
 
57
+ def sizing
58
+ document.sizing
59
+ end
60
+
61
+ def resize(width: nil, height: nil)
62
+ document.calculate_sizing(requested_width: width, requested_height: height)
63
+ end
64
+
55
65
  def position
56
66
  @options[:at] || [x_based_on_requested_alignment, y_based_on_requested_alignment]
57
67
  end
@@ -19,6 +19,13 @@
19
19
  # you're passing in a filename that hasn't been taken from an XML document's attribute,
20
20
  # you will want to URL encode it before you pass it in.
21
21
  #
22
+ # FILES READ AS BINARY
23
+ # ====================
24
+ # At the moment, prawn-svg uses this class only to load graphical files, which are binary.
25
+ # This class therefore uses IO.binread to read file data. If it is ever used in the future
26
+ # to load text files, it will have to be taught about what kind of file it's expecting to
27
+ # read, and adjust the file read function accordingly.
28
+ #
22
29
  module Prawn::SVG::Loaders
23
30
  class File
24
31
  attr_reader :root_path
@@ -53,7 +60,7 @@ module Prawn::SVG::Loaders
53
60
  path = build_absolute_and_expand_path(path)
54
61
  assert_valid_path!(path)
55
62
  assert_file_exists!(path)
56
- IO.read(path)
63
+ IO.binread(path)
57
64
  end
58
65
 
59
66
  def build_uri(url)
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.25.1'
3
+ VERSION = '0.25.2'
4
4
  end
5
5
  end
@@ -91,4 +91,18 @@ describe Prawn::SVG::Interface do
91
91
  end
92
92
  end
93
93
  end
94
+
95
+ describe "#sizing and #resize" do
96
+ let(:interface) { Prawn::SVG::Interface.new(svg, prawn, {}) }
97
+
98
+ it "allows the advanced user to resize the SVG after learning about its dimensions" do
99
+ expect(interface.sizing.output_width).to eq 250
100
+ expect(interface.sizing.output_height).to eq 100
101
+
102
+ interface.resize(width: 500)
103
+
104
+ expect(interface.sizing.output_width).to eq 500
105
+ expect(interface.sizing.output_height).to eq 200
106
+ end
107
+ end
94
108
  end
@@ -24,7 +24,7 @@ RSpec.describe Prawn::SVG::Loaders::File do
24
24
 
25
25
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
26
26
  expect(File).to receive(:exist?).with("#{fake_root_path}/relative/path").and_return(true)
27
- expect(IO).to receive(:read).with("#{fake_root_path}/relative/path").and_return("data")
27
+ expect(IO).to receive(:binread).with("#{fake_root_path}/relative/path").and_return("data")
28
28
 
29
29
  expect(subject).to eq 'data'
30
30
  end
@@ -39,7 +39,7 @@ RSpec.describe Prawn::SVG::Loaders::File do
39
39
 
40
40
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
41
41
  expect(File).to receive(:exist?).with("/some/absolute/path").and_return(true)
42
- expect(IO).to receive(:read).with("/some/absolute/path").and_return("data")
42
+ expect(IO).to receive(:binread).with("/some/absolute/path").and_return("data")
43
43
 
44
44
  expect(subject).to eq 'data'
45
45
  end
@@ -54,7 +54,7 @@ RSpec.describe Prawn::SVG::Loaders::File do
54
54
 
55
55
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
56
56
  expect(File).to receive(:exist?).with("/some/absolute/path name").and_return(true)
57
- expect(IO).to receive(:read).with("/some/absolute/path name").and_return("data")
57
+ expect(IO).to receive(:binread).with("/some/absolute/path name").and_return("data")
58
58
 
59
59
  expect(subject).to eq 'data'
60
60
  end
@@ -94,7 +94,7 @@ RSpec.describe Prawn::SVG::Loaders::File do
94
94
 
95
95
  expect(Dir).to receive(:exist?).with(fake_root_path).and_return(true)
96
96
  expect(File).to receive(:exist?).with("c:/full/path/to/file.png").and_return(true)
97
- expect(IO).to receive(:read).with("c:/full/path/to/file.png").and_return("data")
97
+ expect(IO).to receive(:binread).with("c:/full/path/to/file.png").and_return("data")
98
98
 
99
99
  allow(file_loader).to receive(:windows?).and_return true
100
100
  expect(subject).to eq 'data'
@@ -8,5 +8,6 @@
8
8
  <text y="100" fill="black" style="font-weight: 400;">prawn-svg</text>
9
9
  <text y="200" fill="black" style="font-weight: 600;">prawn-svg</text>
10
10
  <text y="300" fill="black" style="font-weight: 800;">prawn-svg</text>
11
+ <text y="400" fill="black" style="font-style: italic;">prawn-svg</text>
11
12
  </g>
12
13
  </svg>
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.25.1
4
+ version: 0.25.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-21 00:00:00.000000000 Z
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -250,93 +250,4 @@ rubygems_version: 2.5.1
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: SVG renderer for Prawn PDF library
253
- test_files:
254
- - spec/integration_spec.rb
255
- - spec/prawn/svg/attributes/transform_spec.rb
256
- - spec/prawn/svg/calculators/aspect_ratio_spec.rb
257
- - spec/prawn/svg/calculators/document_sizing_spec.rb
258
- - spec/prawn/svg/calculators/pixels_spec.rb
259
- - spec/prawn/svg/color_spec.rb
260
- - spec/prawn/svg/css_spec.rb
261
- - spec/prawn/svg/document_spec.rb
262
- - spec/prawn/svg/elements/base_spec.rb
263
- - spec/prawn/svg/elements/gradient_spec.rb
264
- - spec/prawn/svg/elements/line_spec.rb
265
- - spec/prawn/svg/elements/marker_spec.rb
266
- - spec/prawn/svg/elements/path_spec.rb
267
- - spec/prawn/svg/elements/polygon_spec.rb
268
- - spec/prawn/svg/elements/polyline_spec.rb
269
- - spec/prawn/svg/elements/style_spec.rb
270
- - spec/prawn/svg/elements/text_spec.rb
271
- - spec/prawn/svg/font_registry_spec.rb
272
- - spec/prawn/svg/font_spec.rb
273
- - spec/prawn/svg/interface_spec.rb
274
- - spec/prawn/svg/loaders/data_spec.rb
275
- - spec/prawn/svg/loaders/file_spec.rb
276
- - spec/prawn/svg/loaders/web_spec.rb
277
- - spec/prawn/svg/pathable_spec.rb
278
- - spec/prawn/svg/properties_spec.rb
279
- - spec/prawn/svg/ttf_spec.rb
280
- - spec/prawn/svg/url_loader_spec.rb
281
- - spec/sample_images/mushroom-long.jpg
282
- - spec/sample_images/mushroom-wide.jpg
283
- - spec/sample_output/directory
284
- - spec/sample_svg/arcs01.svg
285
- - spec/sample_svg/arrows.svg
286
- - spec/sample_svg/cap_styles.svg
287
- - spec/sample_svg/circle01.svg
288
- - spec/sample_svg/clip_path.svg
289
- - spec/sample_svg/close_path.svg
290
- - spec/sample_svg/cubic01.svg
291
- - spec/sample_svg/cubic01a.svg
292
- - spec/sample_svg/cubic02.svg
293
- - spec/sample_svg/display_none.svg
294
- - spec/sample_svg/ellipse01.svg
295
- - spec/sample_svg/gistfile1.svg
296
- - spec/sample_svg/google_charts.svg
297
- - spec/sample_svg/gradients.svg
298
- - spec/sample_svg/hidden_paths.svg
299
- - spec/sample_svg/highcharts.svg
300
- - spec/sample_svg/image01.svg
301
- - spec/sample_svg/image02_base64.svg
302
- - spec/sample_svg/image03.svg
303
- - spec/sample_svg/line01.svg
304
- - spec/sample_svg/marker.svg
305
- - spec/sample_svg/markers_degenerate_cp.svg
306
- - spec/sample_svg/maths.svg
307
- - spec/sample_svg/matrix_transform.svg
308
- - spec/sample_svg/matrix_transform_3.svg
309
- - spec/sample_svg/negminy.svg
310
- - spec/sample_svg/no_width_or_height.svg
311
- - spec/sample_svg/offset_viewport.svg
312
- - spec/sample_svg/omnigraffle.svg
313
- - spec/sample_svg/opacity01.svg
314
- - spec/sample_svg/path.svg
315
- - spec/sample_svg/pie_piece.svg
316
- - spec/sample_svg/polygon01.svg
317
- - spec/sample_svg/polyline01.svg
318
- - spec/sample_svg/preserve-space.svg
319
- - spec/sample_svg/quad01.svg
320
- - spec/sample_svg/rect01.svg
321
- - spec/sample_svg/rect02.svg
322
- - spec/sample_svg/rotate_scale.svg
323
- - spec/sample_svg/scale.svg
324
- - spec/sample_svg/scruffy_graph.svg
325
- - spec/sample_svg/subfamilies.svg
326
- - spec/sample_svg/subviewports.svg
327
- - spec/sample_svg/subviewports2.svg
328
- - spec/sample_svg/text_entities.svg
329
- - spec/sample_svg/tref01.svg
330
- - spec/sample_svg/triangle01.svg
331
- - spec/sample_svg/tspan01.svg
332
- - spec/sample_svg/tspan02.svg
333
- - spec/sample_svg/tspan03-cc.svg
334
- - spec/sample_svg/tspan03.svg
335
- - spec/sample_svg/tspan04.svg
336
- - spec/sample_svg/tspan05.svg
337
- - spec/sample_svg/tspan91.svg
338
- - spec/sample_svg/use.svg
339
- - spec/sample_svg/viewbox.svg
340
- - spec/sample_svg/viewport.svg
341
- - spec/sample_ttf/OpenSans-SemiboldItalic.ttf
342
- - spec/spec_helper.rb
253
+ test_files: []