lib/squib/graphics/image.rb in squib-0.13.4 vs lib/squib/graphics/image.rb in squib-0.14.beta1
- old
+ new
@@ -65,10 +65,15 @@
def svg(file, svg_args, box, paint, trans)
Squib.logger.debug {"Rendering: #{file}, id: #{id} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
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
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.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.height = svg.height.to_f * box.width.to_f / svg.width.to_f if box.height == :scale
scale_width = box.width.to_f / svg.width.to_f