lib/esvg/symbol.rb in esvg-4.6.4 vs lib/esvg/symbol.rb in esvg-4.6.5
- old
+ new
@@ -57,12 +57,16 @@
@size[:height]
end
# Scale width based on propotion to height
def scale_width( h )
- s = split_unit( h )
- "#{( s[:size] / height * width ).round(2)}#{s[:unit]}"
+ begin
+ s = split_unit( h )
+ "#{( s[:size] / height * width ).round(2)}#{s[:unit]}"
+ rescue StandardError
+ binding.pry
+ end
end
# Scale height based on propotion to width
def scale_height( w )
s = split_unit( w )
@@ -280,10 +284,20 @@
viewBox: viewbox,
width: (coords[2].to_i - coords[0].to_i).abs,
height: (coords[3].to_i - coords[1].to_i).abs
}
else
- {}
+ # In case a viewbox hasn't been set, derive one.
+ if height = @content.scan(/<svg.+(height=["'](.+?)["'])/).flatten.last &&
+ width = @content.scan(/<svg.+(width=["'](.+?)["'])/).flatten.last
+ {
+ viewBox: "0 0 #{width} #{height}",
+ width: width.to_i,
+ height: height.to_i
+ }
+ else
+ {}
+ end
end
end
def pre_optimize(svg)