Method: Squib::TextEmbed#svg

Defined in:
lib/squib/dsl/text_embed.rb

#svg(opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/squib/dsl/text_embed.rb', line 30

def svg(opts = {})
  warn_if_unexpected opts
  key   = Args::EmbedKey.new.validate_key(opts[:key])
  range = Args.extract_range opts, deck
  paint = Args.extract_paint opts, deck
  box   = Args.extract_box opts, deck, { width: :native, height: :native }
  adjust = Args::EmbedAdjust.new.load!(opts, expand_by: deck.size, layout: deck.layout, dpi: deck.dpi)
  trans = Args.extract_transform opts, deck
  ifile = Args.extract_input_file opts, deck
  svg_args = Args.extract_svg_special opts, deck
  rule = { type: :svg, file: ifile, box: box, paint: paint, trans: trans,
           adjust: adjust, svg_args: svg_args }
  rule[:draw] = Proc.new do |card, x, y, scale|
    i = card.index
    b = box[i]
    b.x, b.y = x, y
    b.width = b.width * scale if b.width.is_a? Numeric
    b.height = b.height * scale if b.height.is_a? Numeric
    Dir.chdir(deck.img_dir) do
      card.svg(ifile[i].file, svg_args[i], b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end