class SvgDrawer::Image

Public Class Methods

new(href, params = {}) click to toggle source
Calls superclass method SvgDrawer::Base::new
# File lib/svg_drawer/image.rb, line 13
def initialize(href, params = {})
  @href = href
  super(params)
end

Public Instance Methods

height() click to toggle source
# File lib/svg_drawer/image.rb, line 22
def height
  @height ||= height_unscaled * param(:scale).to_d
end
height_unscaled() click to toggle source
# File lib/svg_drawer/image.rb, line 30
def height_unscaled
  @height_unscaled ||= param(:img_height).to_d
end
incomplete() click to toggle source
# File lib/svg_drawer/image.rb, line 34
def incomplete
  false
end
width() click to toggle source
# File lib/svg_drawer/image.rb, line 18
def width
  @width ||= width_unscaled * param(:scale).to_d
end
width_unscaled() click to toggle source
# File lib/svg_drawer/image.rb, line 26
def width_unscaled
  @width_unscaled ||= param(:img_width).to_d
end

Private Instance Methods

_draw(parent) click to toggle source
# File lib/svg_drawer/image.rb, line 54
def _draw(parent)
  Utils::RasemWrapper.group(parent, class: 'image') do |image_group|
    x = param(:x_reposition) ? (viewport_width / 2 - width_unscaled * autoscale / 2) / param(:scale) : 0
    y = param(:y_reposition) ? (viewport_height / 2 - height_unscaled * autoscale / 2) / param(:scale) : 0
    image_group.image(x, y, width_unscaled, height_unscaled, @href, preserveAspectRatio: 'xMinYMin meet')
  end.scale(param(:scale), param(:scale))
end
autoscale() click to toggle source

This scale comes from preserveAspectRatio which can't be disabled (librsvg crashes with OOM when preserveAspectRatio=“none”)

# File lib/svg_drawer/image.rb, line 50
def autoscale
  [width / param(:img_width), height / param(:img_height)].min
end
viewport_height() click to toggle source
# File lib/svg_drawer/image.rb, line 44
def viewport_height
  param(:height) || height
end
viewport_width() click to toggle source
# File lib/svg_drawer/image.rb, line 40
def viewport_width
  param(:width) || width
end