Class: Squib::Deck Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/squib/deck.rb,
lib/squib/dsl/csv.rb,
lib/squib/dsl/png.rb,
lib/squib/dsl/svg.rb,
lib/squib/dsl/grid.rb,
lib/squib/dsl/hand.rb,
lib/squib/dsl/line.rb,
lib/squib/dsl/rect.rb,
lib/squib/dsl/save.rb,
lib/squib/dsl/star.rb,
lib/squib/dsl/text.rb,
lib/squib/dsl/xlsx.rb,
lib/squib/dsl/yaml.rb,
lib/squib/dsl/curve.rb,
lib/squib/dsl/units.rb,
lib/squib/dsl/circle.rb,
lib/squib/dsl/groups.rb,
lib/squib/dsl/ellipse.rb,
lib/squib/dsl/polygon.rb,
lib/squib/api/settings.rb,
lib/squib/dsl/cut_zone.rb,
lib/squib/dsl/save_pdf.rb,
lib/squib/dsl/save_png.rb,
lib/squib/dsl/showcase.rb,
lib/squib/dsl/triangle.rb,
lib/squib/dsl/safe_zone.rb,
lib/squib/graphics/hand.rb,
lib/squib/dsl/background.rb,
lib/squib/dsl/save_sheet.rb,
lib/squib/sample_helpers.rb,
lib/squib/graphics/save_doc.rb,
lib/squib/graphics/showcase.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Some helper methods specifically for samples :nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block) ⇒ Deck

Squib’s constructor that sets the immutable properties.

This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck’s instance methods. The documented methods in Deck are the ones intended for use by most users. If your game requires multiple different sizes or orientations, I recommend using multiple ‘Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that’s not recommended.

Examples:

require 'squib'
Squib::Deck.new do
  text str: 'Hello, World!"
end

Parameters:

  • width (Integer) (defaults to: 825)

    the width of each card in pixels. Supports unit conversion (e.g. ‘2.5in’).

  • height (Integer) (defaults to: 1125)

    the height of each card in pixels. Supports unit conversion (e.g. ‘3.5in’).

  • cards (Integer) (defaults to: 1)

    the number of cards in the deck

  • dpi (Integer) (defaults to: 300)

    the pixels per inch when rendering out to PDF or calculating using inches.

  • config (String) (defaults to: 'config.yml')

    the file used for global settings of this deck

  • layout (String, Array) (defaults to: nil)

    load a YML file of custom layouts. Multiple files are merged sequentially, redefining collisons. See README and sample for details.

  • block (Block)

    the main body of the script.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/squib/deck.rb', line 61

def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
  @dpi           = dpi
  @font          = DEFAULT_FONT
  @cards         = []
  @conf          = Conf.load(config)
  @cell_px       = @conf.cell_px
  @progress_bar  = Progress.new(@conf.progress_bars) # FIXME this is evil. Using something different with @ and non-@
  show_info(config, layout)
  @width         = Args::UnitConversion.parse width, dpi, @cell_px
  @height        = Args::UnitConversion.parse height, dpi, @cell_px
  cards.times{ |i| @cards << Squib::Card.new(self, @width, @height, i) }
  @layout = LayoutParser.new(dpi, @cell_px).load_layout(layout)
  enable_groups_from_env!
  if block_given?
    instance_eval(&block) # here we go. wheeeee!
  end
  @cards.each { |c| c.finish! }
end

Instance Attribute Details

#cardsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck



29
30
31
# File 'lib/squib/deck.rb', line 29

def cards
  @cards
end

#cell_pxObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



36
37
38
# File 'lib/squib/deck.rb', line 36

def cell_px
  @cell_px
end

#confObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



36
37
38
# File 'lib/squib/deck.rb', line 36

def conf
  @conf
end

#dpiObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



36
37
38
# File 'lib/squib/deck.rb', line 36

def dpi
  @dpi
end

#fontObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



36
37
38
# File 'lib/squib/deck.rb', line 36

def font
  @font
end

#heightObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck



29
30
31
# File 'lib/squib/deck.rb', line 29

def height
  @height
end

#layoutObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



36
37
38
# File 'lib/squib/deck.rb', line 36

def layout
  @layout
end

#progress_barObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck



29
30
31
# File 'lib/squib/deck.rb', line 29

def progress_bar
  @progress_bar
end

#widthObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Attributes for the width, height (in pixels) and number of cards These are expected to be immuatble for the life of Deck



29
30
31
# File 'lib/squib/deck.rb', line 29

def width
  @width
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Directly accesses the array of cards in the deck



83
84
85
# File 'lib/squib/deck.rb', line 83

def [](key)
  @cards[key]
end

#background(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/background.rb', line 5

def background(opts = {})
  DSL::Background.new(self, __callee__).run(opts)
end

#build(grp = :all, &block) ⇒ Object

DSL method. See squib.readthedocs.io



23
24
25
26
# File 'lib/squib/dsl/groups.rb', line 23

def build grp = :all, &block
  raise 'Please provide a block' unless block_given?
  block.yield if build_groups.include? grp
end

#build_groupsObject

DSL method. See squib.readthedocs.io



41
42
43
# File 'lib/squib/dsl/groups.rb', line 41

def build_groups
  @build_groups ||= Set.new.add(:all)
end

#cells(n) ⇒ Object

DSL method. See squib.readthedocs.io



32
33
34
# File 'lib/squib/dsl/units.rb', line 32

def cells(n)
  n.to_f * @cell_px
end

#circle(opts = {}) ⇒ Object



8
9
10
# File 'lib/squib/dsl/circle.rb', line 8

def circle(opts = {})
  DSL::Circle.new(self, __callee__).run(opts)
end

#cm(n) ⇒ Object

DSL method. See squib.readthedocs.io



17
18
19
# File 'lib/squib/dsl/units.rb', line 17

def cm(n)
  @dpi * Squib::INCHES_IN_CM * n.to_f
end

#compute_dimensions(sheet, rotate) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
48
49
50
# File 'lib/squib/graphics/save_doc.rb', line 43

def compute_dimensions(sheet, rotate)
  w,h = rotate ? [@height,@width] : [@width,@height]
  w -= 2 * sheet.trim
  h -= 2 * sheet.trim
  sheet_width = (sheet.columns * (w + 2 * sheet.gap)) + (2 * sheet.margin)
  sheet_height = (sheet.rows * (h + 2 * sheet.gap)) + (2 * sheet.margin)
  return [w, h, sheet_width, sheet_height]
end

#csv(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



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

def csv(opts = {}, &block)
  DSL::Csv.new(__callee__).run(opts, &block)
end

#curve(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/curve.rb', line 5

def curve(opts = {})
  DSL::Curve.new(self, __callee__).run(opts)
end

#cut_zone(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/cut_zone.rb', line 5

def cut_zone(opts = {})
  DSL::CutZone.new(self, __callee__).run(opts)
end

#deg(n) ⇒ Object

DSL method. See squib.readthedocs.io



27
28
29
# File 'lib/squib/dsl/units.rb', line 27

def deg(n)
  n.to_f * (Math::PI / 180.0)
end

#disable_build(grp) ⇒ Object

DSL method. See squib.readthedocs.io



35
36
37
38
# File 'lib/squib/dsl/groups.rb', line 35

def disable_build grp
  build_groups # make sure it's initialized
  @build_groups.delete grp
end

#draw_graph_paper(width, height) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Draw graph paper for samples



9
10
11
12
13
14
15
16
# File 'lib/squib/sample_helpers.rb', line 9

def draw_graph_paper(width, height)
  background color: 'white'
  grid width: 50,  height: 50,  stroke_color: '#659ae9', stroke_width: 1.5
  grid width: 200, height: 200, stroke_color: '#659ae9', stroke_width: 3, x: 50, y: 50
  (50..height).step(200) do |y|
    text str: "y=#{y}", x: 3, y: y - 18, font: 'Open Sans, Sans 10'
  end
end

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterates over each card in the deck



90
91
92
# File 'lib/squib/deck.rb', line 90

def each(&block)
  @cards.each { |card| block.call(card) }
end

#ellipse(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/ellipse.rb', line 5

def ellipse(opts = {})
  DSL::Ellipse.new(self, __callee__).run(opts)
end

#enable_build(grp) ⇒ Object

DSL method. See squib.readthedocs.io



29
30
31
32
# File 'lib/squib/dsl/groups.rb', line 29

def enable_build grp
  build_groups # make sure it's initialized
  @build_groups << grp
end

#enable_groups_from_env!Object

Not a DSL method, but initialized from Deck.new



46
47
48
49
50
51
# File 'lib/squib/dsl/groups.rb', line 46

def enable_groups_from_env!
  return if ENV['SQUIB_BUILD'].nil?
  ENV['SQUIB_BUILD'].split(',').each do |grp|
    enable_build grp.strip.to_sym
  end
end

#grid(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/grid.rb', line 5

def grid(opts = {})
  DSL::Grid.new(self, __callee__).run(opts)
end

#hand(opts = {}) ⇒ Object



9
10
11
# File 'lib/squib/dsl/hand.rb', line 9

def hand(opts = {})
  DSL::Hand.new(self, __callee__).run(opts)
end

#hint(text: :off) ⇒ Object

DSL method. See squib.readthedocs.io



5
6
7
# File 'lib/squib/api/settings.rb', line 5

def hint(text: :off)
  conf.text_hint = text
end

#inches(n) ⇒ Object

DSL method. See squib.readthedocs.io



7
8
9
# File 'lib/squib/dsl/units.rb', line 7

def inches(n)
  @dpi * n.to_f
end

#line(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/line.rb', line 5

def line(opts = {})
  DSL::Line.new(self, __callee__).run(opts)
end

#mm(n) ⇒ Object

DSL method. See squib.readthedocs.io



22
23
24
# File 'lib/squib/dsl/units.rb', line 22

def mm(n)
  @dpi * Squib::INCHES_IN_CM * n.to_f / 10.0
end

#perspective(src, scale, face_right) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/squib/graphics/showcase.rb', line 65

def perspective(src, scale, face_right)
  dest_cxt = Cairo::Context.new(Cairo::ImageSurface.new(src.width * scale, src.height))
  in_thickness = 1 # Take strip 1 pixel-width at a time
  out_thickness = 3 # Scale it to 3 pixels wider to cover any gaps
  (0..src.width).step(in_thickness) do |i|
    percentage = i / src.width.to_f
    i = src.width - i if face_right
    factor = scale + (percentage * (1.0 - scale)) # linear interpolation
    dest_cxt.save
    dest_cxt.translate 0, src.height / 2.0 * (1.0 - factor)
    dest_cxt.scale factor * scale, factor
    dest_cxt.set_source src, 0, 0
    dest_cxt.rounded_rectangle i, 0, out_thickness, src.height, 0, 0
    dest_cxt.fill
    dest_cxt.restore
  end
  return dest_cxt.target
end

#png(opts = {}) ⇒ Object



10
11
12
# File 'lib/squib/dsl/png.rb', line 10

def png(opts = {})
  DSL::PNG.new(self, __callee__).run(opts)
end

#points(n) ⇒ Object

DSL method. See squib.readthedocs.io



12
13
14
# File 'lib/squib/dsl/units.rb', line 12

def points(n)
  @dpi / Squib::POINTS_PER_IN * n.to_f
end

#polygon(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/polygon.rb', line 5

def polygon(opts = {})
  DSL::Polygon.new(self, __callee__).run(opts)
end

#preprocess(surface, trim, w, h, rotate, angle) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a new Cairo::ImageSurface that is trimmed and rotated from the original :nodoc:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/squib/graphics/save_doc.rb', line 60

def preprocess(surface, trim, w, h, rotate, angle)
  if trim > 0 || rotate
    tmp = Cairo::ImageSurface.new(w, h)
    cc = Cairo::Context.new(tmp)
    if rotate
      cc.translate w * 0.5, h * 0.5
      cc.rotate angle
      cc.translate h * -0.5, w * -0.5
    end
    cc.set_source(surface, -1 * trim, -1 * trim)
    cc.paint
    surface = tmp
  end
  surface
end

#rect(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/rect.rb', line 5

def rect(opts = {})
  DSL::Rect.new(self, __callee__).run(opts)
end

#reflect(src, roffset, rpercent, rstrength) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/squib/graphics/showcase.rb', line 46

def reflect(src, roffset, rpercent, rstrength)
  tmp_cc = Cairo::Context.new(Cairo::ImageSurface.new(src.width, src.height * (1.0 + rpercent) + roffset))
  tmp_cc.set_source(src, 0, 0)
  tmp_cc.paint
  # Flip affine magic from: http://cairographics.org/matrix_transform/
  matrix = Cairo::Matrix.new(1, 0, 0, -1, 0, 2 * src.height + roffset)
  tmp_cc.transform(matrix) # flips the coordinate system
  top_y    = src.height    # top of the reflection
  bottom_y = src.height * (1.0 - rpercent) + roffset # bottom of the reflection
  gradient = Cairo::LinearPattern.new(0, top_y, 0, bottom_y)
  gradient.add_color_stop_rgba(0.0, 0, 0, 0, rstrength) # start a little reflected
  gradient.add_color_stop_rgba(1.0, 0, 0, 0, 0.0)       # fade to nothing
  tmp_cc.set_source(src, 0, 0)
  tmp_cc.mask(gradient)
  return tmp_cc.target
end

#render_hand(range, sheet, hand) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Draw cards in a fan.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/squib/graphics/hand.rb', line 8

def render_hand(range, sheet, hand)
  cards       = range.collect { |i| @cards[i] }
  center_x    = width / 2.0
  center_y    = hand.radius + height
  out_size    = 3.0 * center_y
  angle_delta = (hand.angle_range.last - hand.angle_range.first) / cards.size
  cxt = Cairo::Context.new(Cairo::RecordingSurface.new(0, 0, out_size, out_size))
  cxt.translate(out_size / 2.0, out_size / 2.0)
  cxt.rotate(hand.angle_range.first)
  cxt.translate(-width, -width)
  cards.each_with_index do |card, i|
    cxt.translate(center_x, center_y)
    cxt.rotate(angle_delta)
    cxt.translate(-center_x, -center_y)
    card.use_cairo do |card_cxt|
      cxt.rounded_rectangle(sheet.trim, sheet.trim,
                            width - (2 * sheet.trim), height - (2 * sheet.trim),
                            sheet.trim_radius, sheet.trim_radius)
      cxt.clip
      cxt.set_source(card_cxt.target)
      cxt.paint
      cxt.reset_clip
    end
  end
  x, y, w, h = cxt.target.ink_extents # I love Ruby assignment ;)
  png_cxt = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(Cairo::ImageSurface.new(w + 2 * sheet.margin, h + 2 * sheet.margin)))
  png_cxt.set_source_squibcolor(sheet.fill_color)
  png_cxt.paint
  png_cxt.translate(-x + sheet.margin, -y + sheet.margin)
  png_cxt.set_source(cxt.target)
  png_cxt.paint
  png_cxt.target.write_to_png sheet.full_filename
end

#render_sheet(range, batch, sheet) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/squib/graphics/save_doc.rb', line 6

def render_sheet(range, batch, sheet)
  rotate = batch.rotate.any? true # either rotate all or none
  w,h,sheet_width,sheet_height = compute_dimensions(sheet, rotate)
  cc = Cairo::Context.new(Cairo::ImageSurface.new(sheet_width, sheet_height))
  num_this_sheet = 0
  sheet_num = 0
  y = sheet.margin
  x = sheet.rtl ? rtl_start_x(sheet_width, sheet, w) : sheet.margin
  @progress_bar.start("Saving PNG sheet to #{batch.summary}", @cards.size + 1) do |bar|
    range.each do |i|
      if num_this_sheet >= (sheet.columns * sheet.rows) # new sheet
        filename = batch.full_filename(sheet_num)
        cc.target.write_to_png(filename)
        new_sheet = false
        num_this_sheet = 0
        sheet_num += 1
        y = sheet.margin
        x = sheet.rtl ? rtl_start_x(sheet_width, sheet, w) : sheet.margin
        cc = Cairo::Context.new(Cairo::ImageSurface.new(sheet_width, sheet_height))
      end
      surface = preprocess(@cards[i].cairo_surface,
                            sheet.trim, w, h,
                            rotate, batch.angle[i])
      cc.set_source(surface, x, y)
      cc.paint
      num_this_sheet += 1
      x += (w + sheet.gap) * (sheet.rtl ? -1 : 1)
      if num_this_sheet % sheet.columns == 0 # new row
        x = sheet.rtl ? rtl_start_x(sheet_width, sheet, w) : sheet.margin
        y += h + sheet.gap
      end
      bar.increment
    end
    cc.target.write_to_png(batch.full_filename(sheet_num))
  end
end

#render_showcase(range, sheet, showcase) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

So the Cairo people have said over and over again that they won’t support the 3x3 matrices that would handle perspective transforms. Since our perspective transform needs are a bit simpler, we can use a “striping method” that does the job for us. It’s a little bit involved, but it works well enough for limited ranges of our parameters. These were also helpful:

http://kapo-cpp.blogspot.com/2008/01/perspective-effect-using-cairo.html
http://zetcode.com/gui/pygtk/drawingII/

:nodoc:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/squib/graphics/showcase.rb', line 14

def render_showcase(range, sheet, showcase)
  out_width = range.size * ((@width - 2 * sheet.trim) * showcase.scale * showcase.offset) + 2 * sheet.margin
  out_height = showcase.reflect_offset + (1.0 + showcase.reflect_percent) * (@height - 2 * sheet.trim) + 2 * sheet.margin
  out_cc = Cairo::Context.new(Cairo::ImageSurface.new(out_width, out_height))
  wrapper = Squib::Graphics::CairoContextWrapper.new(out_cc)
  wrapper.set_source_squibcolor(sheet.fill_color)
  wrapper.paint

  cards = range.collect { |i| @cards[i] }
  cards.each_with_index do |card, i|
    trimmed = trim_rounded(card.cairo_surface, showcase.trim, showcase.trim_radius)
    reflected = reflect(trimmed, showcase.reflect_offset, showcase.reflect_percent, showcase.reflect_strength)
    perspectived = perspective(reflected, showcase.scale, showcase.face_right?)
    out_cc.set_source(perspectived, sheet.margin + i * perspectived.width * showcase.offset, sheet.margin)
    out_cc.paint
  end
  out_cc.target.write_to_png("#{sheet.dir}/#{sheet.file}")
end

#rtl_start_x(sheet_width, sheet, w) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/squib/graphics/save_doc.rb', line 52

def rtl_start_x(sheet_width, sheet, w)
  return sheet_width - sheet.margin - sheet.gap - w
end

#safe_zone(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/safe_zone.rb', line 5

def safe_zone(opts = {})
  DSL::SafeZone.new(self, __callee__).run(opts)
end

#sample(str) {|@sample_x, @sample_y| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Define a set of samples on some graph paper

Yields:

  • (@sample_x, @sample_y)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/squib/sample_helpers.rb', line 19

def sample(str)
  @sample_x ||= 100
  @sample_y ||= 100
  rect x: 460, y: @sample_y - 40, width: 600,
       height: 180, fill_color: '#FFD655', stroke_color: 'black', radius: 15
  text str: str, x: 460, y: @sample_y - 40,
       width: 540, height: 180,
       valign: 'middle', align: 'center',
       font: 'Times New Roman,Serif 8'
  yield @sample_x, @sample_y
  @sample_y += 200
end

#save(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/squib/dsl/save.rb', line 8

def save(opts = {})
  fmts = Array(opts[:format])
  warn 'Must specify format :png and/or :pdf' if fmts.empty?
  opts.delete :format # not needed anymore
  save_png(opts) if fmts.include? :png
  save_pdf(opts) if fmts.include? :pdf
  uns = fmts - [:pdf, :png ]
  unless uns.empty?
    warn "Unsupported format(s) #{uns} to #{'save'.cyan}()", uplevel: 1
  end
  self
end

#save_pdf(opts = {}) ⇒ Object



8
9
10
# File 'lib/squib/dsl/save_pdf.rb', line 8

def save_pdf(opts = {})
  DSL::SavePDF.new(self, __callee__).run(opts)
end

#save_png(opts = {}) ⇒ Object



8
9
10
# File 'lib/squib/dsl/save_png.rb', line 8

def save_png(opts = {})
  DSL::SavePNG.new(self, __callee__).run(opts)
end

#save_sheet(opts = {}) ⇒ Object



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

def save_sheet(opts = {})
  DSL::SaveSheet.new(self, __callee__).run(opts)
end

#set(opts = {}) ⇒ Object

DSL method. See squib.readthedocs.io



10
11
12
13
# File 'lib/squib/api/settings.rb', line 10

def set(opts = {})
  raise 'DEPRECATED: As of v0.7 img_dir is no longer supported in "set". Use config.yml instead.' if opts.key? :img_dir
  @font = (opts[:font] == :default) ? Squib::DEFAULT_FONT : opts[:font]
end

#show_info(config, layout) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Use Logger to show more detail on the run :nodoc:



97
98
99
100
101
# File 'lib/squib/deck.rb', line 97

def show_info(config, layout)
  Squib::logger.info "Squib v#{Squib::VERSION}"
  Squib::logger.info "  building #{@cards.size} #{@width}x#{@height} cards"
  Squib::logger.info "  using #{@backend}"
end

#showcase(opts = {}) ⇒ Object



8
9
10
# File 'lib/squib/dsl/showcase.rb', line 8

def showcase(opts = {})
  DSL::Showcase.new(self, __callee__).run(opts)
end

#star(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/star.rb', line 5

def star(opts = {})
  DSL::Star.new(self, __callee__).run(opts)
end

#svg(opts = {}) ⇒ Object



11
12
13
# File 'lib/squib/dsl/svg.rb', line 11

def svg(opts = {})
  DSL::SVG.new(self, __callee__).run(opts)
end

#text(opts = {}) {|embed| ... } ⇒ Object

Yields:

  • (embed)


11
12
13
14
15
# File 'lib/squib/dsl/text.rb', line 11

def text(opts = {})
  embed = TextEmbed.new self, __callee__
  yield(embed) if block_given? # store the opts for later use
  DSL::Text.new(self, __callee__, embed).run(opts)
end

#triangle(opts = {}) ⇒ Object



5
6
7
# File 'lib/squib/dsl/triangle.rb', line 5

def triangle(opts = {})
  DSL::Triangle.new(self, __callee__).run(opts)
end

#trim_rounded(src, trim, radius) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

:nodoc:



35
36
37
38
39
40
41
42
# File 'lib/squib/graphics/showcase.rb', line 35

def trim_rounded(src, trim, radius)
  trim_cc = Cairo::Context.new(Cairo::ImageSurface.new(@width - 2.0 * trim, @height - 2.0 * trim))
  trim_cc.rounded_rectangle(0, 0, trim_cc.target.width, trim_cc.target.height, radius, radius)
  trim_cc.set_source(src, -1 * trim, -1 * trim)
  trim_cc.clip
  trim_cc.paint
  return trim_cc.target
end

#use_layout(file: 'layout.yml') ⇒ Object

DSL method. See squib.readthedocs.io



16
17
18
# File 'lib/squib/api/settings.rb', line 16

def use_layout(file: 'layout.yml')
  @layout = LayoutParser.new(@dpi).load_layout(file, @layout)
end

#xlsx(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



14
15
16
# File 'lib/squib/dsl/xlsx.rb', line 14

def xlsx(opts = {}, &block)
  DSL::Xlsx.new(__callee__).run(opts, &block)
end

#yaml(opts = {}, &block) ⇒ Object

DSL method. See squib.readthedocs.io



14
15
16
# File 'lib/squib/dsl/yaml.rb', line 14

def yaml(opts = {}, &block)
  DSL::Yaml.new(__callee__).run(opts, &block)
end