lib/prawn/svg/calculators/document_sizing.rb in prawn-svg-0.34.2 vs lib/prawn/svg/calculators/document_sizing.rb in prawn-svg-0.35.0
- old
+ new
@@ -1,8 +1,8 @@
module Prawn::SVG::Calculators
class DocumentSizing
- DEFAULT_ASPECT_RATIO = "xMidYMid meet"
+ DEFAULT_ASPECT_RATIO = 'xMidYMid meet'.freeze
attr_writer :document_width, :document_height
attr_writer :view_box, :preserve_aspect_ratio
attr_reader :bounds
@@ -31,25 +31,24 @@
@output_width = Pixels::Measurement.to_pixels(@document_width || @requested_width, container_width)
@output_height = Pixels::Measurement.to_pixels(@document_height || @requested_height, container_height)
if @view_box
values = @view_box.strip.split(Prawn::SVG::Elements::COMMA_WSP_REGEXP)
- @x_offset, @y_offset, @viewport_width, @viewport_height = values.map {|value| value.to_f}
+ @x_offset, @y_offset, @viewport_width, @viewport_height = values.map(&:to_f)
- if @viewport_width > 0 && @viewport_height > 0
+ if @viewport_width.positive? && @viewport_height.positive?
# If neither the width nor height was specified, use the entire width and the viewbox ratio
# to determine the height.
- if @output_width.nil? && @output_height.nil?
- @output_width = container_width
- end
+ @output_width = container_width if @output_width.nil? && @output_height.nil?
# If one of the output dimensions is missing, calculate it from the other one
# using the ratio of the viewport width to height.
@output_width ||= @output_height * @viewport_width / @viewport_height
@output_height ||= @output_width * @viewport_height / @viewport_width
- aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height], [@viewport_width, @viewport_height])
+ aspect = AspectRatio.new(@preserve_aspect_ratio, [@output_width, @output_height],
+ [@viewport_width, @viewport_height])
@x_scale = aspect.width / @viewport_width
@y_scale = aspect.height / @viewport_height
@x_offset -= aspect.x / @x_scale
@y_offset -= aspect.y / @y_scale
end
@@ -62,11 +61,11 @@
end
return if invalid?
# SVG 1.1 section 7.10
- @viewport_diagonal = Math.sqrt(@viewport_width**2 + @viewport_height**2) / Math.sqrt(2)
+ @viewport_diagonal = Math.sqrt((@viewport_width**2) + (@viewport_height**2)) / Math.sqrt(2)
if @requested_width
scale = @requested_width / @output_width
@output_width = @requested_width
@output_height *= scale
@@ -92,13 +91,13 @@
(@requested_width && @requested_width <= 0) ||
(@requested_height && @requested_height <= 0)
end
def requested_width=(value)
- @requested_width = (value.to_f if value)
+ @requested_width = value&.to_f
end
def requested_height=(value)
- @requested_height = (value.to_f if value)
+ @requested_height = value&.to_f
end
end
end