class Rabbit::Size

Attributes

base_height[R]
base_width[R]
logical_height[R]
logical_margin_bottom[R]
logical_margin_left[R]
logical_margin_right[R]
logical_margin_top[R]
logical_width[R]
ratio[R]
real_content_height[R]
real_content_width[R]
real_height[R]
real_width[R]

Public Class Methods

new(base_width, base_height, width, height, ratio) click to toggle source
# File lib/rabbit/size.rb, line 32
def initialize(base_width, base_height, width, height, ratio)
  @base_width = base_width
  @base_height = base_height
  @real_width = width
  @real_height = height
  @ratio = ratio
  compute_logical_size
end

Public Instance Methods

have_logical_margin?() click to toggle source
# File lib/rabbit/size.rb, line 51
def have_logical_margin?
  have_logical_margin_x? or have_logical_margin_y?
end
have_logical_margin_x?() click to toggle source
# File lib/rabbit/size.rb, line 41
def have_logical_margin_x?
  @logical_margin_left > 0 or
    @logical_margin_right > 0
end
have_logical_margin_y?() click to toggle source
# File lib/rabbit/size.rb, line 46
def have_logical_margin_y?
  @logical_margin_top > 0 or
    @logical_margin_bottom > 0
end
logical_scale() click to toggle source
# File lib/rabbit/size.rb, line 55
def logical_scale
  @logical_scale
end

Private Instance Methods

compute_logical_size() click to toggle source
# File lib/rabbit/size.rb, line 60
def compute_logical_size
  @logical_width = @base_width
  @logical_height = @base_height

  real_ratio = @real_width.to_f / @real_height.to_f
  if real_ratio == @ratio
    @real_content_width = @real_width
    @real_content_height = @real_height
  elsif real_ratio > @ratio
    @real_content_width = @real_width * (@ratio / real_ratio)
    @real_content_height = @real_height
  else
    @real_content_width = @real_width
    @real_content_height = @real_height * (real_ratio / @ratio)
  end

  logical_scale_x = @real_content_width.to_f / @logical_width.to_f
  logical_scale_y = @real_content_height.to_f / @logical_height.to_f

  real_margin_width = @real_width - @real_content_width
  logical_margin_width = real_margin_width / logical_scale_x
  @logical_margin_left = logical_margin_width / 2
  @logical_margin_right = logical_margin_width / 2

  real_margin_height = @real_height - @real_content_height
  logical_margin_height = real_margin_height / logical_scale_y
  @logical_margin_top = logical_margin_height / 2
  @logical_margin_bottom = logical_margin_height / 2

  @logical_scale = [logical_scale_x, logical_scale_y]
end