Class: Squib::TextEmbed

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/api/text_embed.rb

Instance Method Summary collapse

Instance Method Details

#png(opts = {}) ⇒ Object

Context object for embedding a png within text

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • key (String) — default: '*'

    the string to replace with the graphic. Can be multiple letters, e.g. ':tool:'

  • file (String) — default: '') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}

    '') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See Specifying Files. Supports Arrays, see Arrays and Singleon Expansion

  • layout (String, Symbol) — default: nil

    entry in the layout to use as defaults for this command. See Custom Layouts. Supports Arrays, see Arrays and Singleon Expansion

  • width (Fixnum) — default: :native

    the width of the image rendered

  • height (Fixnum) — default: :native

    the height of the image rendered

  • dx (Integer) — default: 0

    "delta x", or adjust the icon horizontally by x pixels

  • dy (Integer) — default: 0

    "delta y", or adjust the icon vertically by y pixels

  • alpha (Decimal) — default: 1.0

    the alpha-transparency percentage used to blend this image. Supports Arrays, see Arrays and Singleon Expansion

  • blend (:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity) — default: :none

    the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see Arrays and Singleon Expansion

  • angle (FixNum) — default: 0

    Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see Arrays and Singleon Expansion



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/squib/api/text_embed.rb', line 75

def png(opts = {})
  key   = Args::EmbedKey.new.validate_key(opts[:key])
  range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
  paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
  box   = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  rule  = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
  rule[:draw] = Proc.new do |card, x, y|
    i = card.index
    b = box[i]
    b.x, b.y = x, y
    Dir.chdir(@img_dir) do
      card.png(ifile[i].file, b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end

#svg(opts = {}) ⇒ Object

Context object for embedding an svg icon within text

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • key (String) — default: '*'

    the string to replace with the graphic. Can be multiple letters, e.g. ':tool:'

  • file (String) — default: '') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}

    '') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See Specifying Files. Supports Arrays, see Arrays and Singleon Expansion

  • id (String) — default: nil

    if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see Arrays and Singleon Expansion

  • force_id (Boolean) — default: false

    if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see Arrays and Singleon Expansion

  • layout (String, Symbol) — default: nil

    entry in the layout to use as defaults for this command. See Custom Layouts. Supports Arrays, see Arrays and Singleon Expansion

  • width (Integer) — default: :native

    the width of the image rendered.

  • height (Integer) — default: :native

    the height the height of the image rendered.

  • dx (Integer) — default: 0

    "delta x", or adjust the icon horizontally by x pixels

  • dy (Integer) — default: 0

    "delta y", or adjust the icon vertically by y pixels

  • alpha (Decimal) — default: 1.0

    the alpha-transparency percentage used to blend this image. Supports Arrays, see Arrays and Singleon Expansion

  • blend (:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity) — default: :none

    the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see Arrays and Singleon Expansion

  • angle (FixNum) — default: 0

    Rotation of the in radians. Note that this rotates around the upper-left corner, making the placement of x-y coordinates slightly tricky. Supports Arrays, see Arrays and Singleon Expansion



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/squib/api/text_embed.rb', line 41

def svg(opts = {})
  key   = Args::EmbedKey.new.validate_key(opts[:key])
  range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
  paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
  box   = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  svg_args = Args::SvgSpecial.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
  rule  = { type: :png, file: ifile, box: box, paint: paint, trans: trans, adjust: adjust }
  rule[:draw] = Proc.new do |card, x, y|
    i = card.index
    b = box[i]
    b.x, b.y = x, y
    Dir.chdir(@img_dir) do
      card.svg(ifile[i].file, svg_args[i], b, paint[i], trans[i])
    end
  end
  @rules[key] = rule
end