Card - improve error message when reading invalid svg files
Add a test file in samples/images - it's a simple 1x1 pixel white png saved with a 'svg' extension. Fix for #228 (cherry picked from commit 32fad2460753a72cc2b0100d0a132512b6eeed81) # Conflicts: # lib/squib/graphics/image.rbdev
parent
4e92b1ae31
commit
52920ab8f0
|
|
@ -67,7 +67,12 @@ module Squib
|
||||||
Squib.logger.warn 'Both an SVG file and SVG data were specified' unless file.to_s.empty? || svg_args.data.to_s.empty?
|
Squib.logger.warn 'Both an SVG file and SVG data were specified' unless file.to_s.empty? || svg_args.data.to_s.empty?
|
||||||
return if (file.nil? or file.eql? '') and svg_args.data.nil? # nothing specified TODO Move this out to arg validator
|
return if (file.nil? or file.eql? '') and svg_args.data.nil? # nothing specified TODO Move this out to arg validator
|
||||||
svg_args.data = File.read(file) if svg_args.data.to_s.empty?
|
svg_args.data = File.read(file) if svg_args.data.to_s.empty?
|
||||||
svg = Rsvg::Handle.new_from_data(svg_args.data)
|
begin
|
||||||
|
svg = Rsvg::Handle.new_from_data(svg_args.data)
|
||||||
|
rescue Rsvg::Error::Failed
|
||||||
|
Squib.logger.error "Invalid SVG data. Is '#{file}' a valid svg file?"
|
||||||
|
return
|
||||||
|
end
|
||||||
box.width = svg.width if box.width == :native
|
box.width = svg.width if box.width == :native
|
||||||
box.height = svg.height if box.height == :native
|
box.height = svg.height if box.height == :native
|
||||||
box.width = svg.width.to_f * box.height.to_f / svg.height.to_f if box.width == :scale
|
box.width = svg.width.to_f * box.height.to_f / svg.height.to_f if box.width == :scale
|
||||||
|
|
|
||||||
|
|
@ -95,5 +95,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.
|
||||||
svg file: 'spanner.svg', width: :deck, height: :deck,
|
svg file: 'spanner.svg', width: :deck, height: :deck,
|
||||||
force_id: true, id: '' # <-- the important part
|
force_id: true, id: '' # <-- the important part
|
||||||
|
|
||||||
|
# Squib can handle incorrectly formatted svg files
|
||||||
|
svg file: 'bad-svg.svg'
|
||||||
|
|
||||||
save prefix: 'load_images_', format: :png
|
save prefix: 'load_images_', format: :png
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 163 B |
Loading…
Reference in New Issue