Class: Squib::TextEmbed

Inherits:
Object
  • Object
show all
Includes:
WarnUnexpectedParams
Defined in:
lib/squib/dsl/text_embed.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WarnUnexpectedParams

#warn_if_unexpected

Constructor Details

#initialize(deck, dsl_method) ⇒ TextEmbed

Returns a new instance of TextEmbed.



15
16
17
18
# File 'lib/squib/dsl/text_embed.rb', line 15

def initialize(deck, dsl_method)
  @deck = deck
  @rules = {} # store an array of options for later usage
end

Instance Attribute Details

#deckObject (readonly)



13
14
15
# File 'lib/squib/dsl/text_embed.rb', line 13

def deck
  @deck
end

#dsl_methodObject (readonly)



13
14
15
# File 'lib/squib/dsl/text_embed.rb', line 13

def dsl_method
  @dsl_method
end

#rulesObject (readonly)



13
14
15
# File 'lib/squib/dsl/text_embed.rb', line 13

def rules
  @rules
end

Class Method Details

.accepted_paramsObject



20
21
22
23
24
25
26
27
28
# File 'lib/squib/dsl/text_embed.rb', line 20

def self.accepted_params
  %i(
    key file id force_id layout width height dx dy
    id force_id data
    flip_horizontal flip_vertical
    alpha angle blend mask
    placeholder
  )
end

Instance Method Details

#png(opts = {}) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/squib/dsl/text_embed.rb', line 55

def png(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
  rule  = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
  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.png(ifile[i].file, b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end

#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