Class: Squib::Card Private

Inherits:
Object
  • Object
show all
Defined in:
lib/squib/card.rb,
lib/squib/graphics/text.rb,
lib/squib/graphics/image.rb,
lib/squib/graphics/shapes.rb,
lib/squib/graphics/background.rb,
lib/squib/graphics/save_images.rb

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deck, width, height, index = -1)) ⇒ Card

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:


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

def initialize(deck, width, height, index=-1)
  @deck          = deck
  @width         = width
  @height        = height
  @backend       = deck.backend
  @index         = index
  @svgfile       = "#{deck.dir}/#{deck.prefix}#{deck.count_format % index}.svg"
  @cairo_surface = make_surface(@svgfile, @backend)
  @cairo_context = Squib::Graphics::CairoContextWrapper.new(Cairo::Context.new(@cairo_surface))
  @cairo_context.antialias = deck.antialias
end

Instance Attribute Details

#backendObject (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:


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

def backend
  @backend
end

#cairo_contextObject

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:


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

def cairo_context
  @cairo_context
end

#cairo_surfaceObject

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:


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

def cairo_surface
  @cairo_surface
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.

:nodoc:


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

def height
  @height
end

#indexObject (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:


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

def index
  @index
end

#svgfileObject (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:


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

def svgfile
  @svgfile
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.

:nodoc:


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

def width
  @width
end

Instance Method Details

#background(color) ⇒ 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
# File 'lib/squib/graphics/background.rb', line 6

def background(color)
  use_cairo do |cc|
    cc.set_source_squibcolor(color)
    cc.paint
  end
end

#circle(box, draw) ⇒ 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:


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

def circle(box, draw)
  x, y, r = box.x, box.y, box.radius
  use_cairo do |cc|
    if box.arc_direction == :clockwise
      cc.arc(x, y, r, box.arc_start, box.arc_end)
    else
      cc.arc_negative(x, y, r, box.arc_start, box.arc_end)
    end
    if box.arc_close
      cc.close_path();
    end
    cc.fill_n_stroke(draw)
  end
end

#compute_carve(rule, range) ⇒ Object

Compute the width of the carve that we need


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

def compute_carve(rule, range)
  w = rule[:box].width[@index]
  if w == :native
    file = rule[:file][@index].file
    case rule[:type]
    when :png
      Squib.cache_load_image(file).width.to_f / (range.size - 1)
    when :svg
      svg_data = rule[:svg_args].data[@index]
      unless file.to_s.empty? || svg_data.to_s.empty?
        Squib.logger.warn 'Both an SVG file and SVG data were specified'
      end
      return 0 if (file.nil? or file.eql? '') and svg_data.nil?
      svg_data = File.read(file) if svg_data.to_s.empty?
      RSVG::Handle.new_from_data(svg_data).width
    end
  else
    rule[:box].width[@index] * Pango::SCALE / (range.size - 1)
  end
end

#compute_dimensions(rotate, trim) ⇒ 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.


22
23
24
25
26
27
28
# File 'lib/squib/graphics/save_images.rb', line 22

def compute_dimensions(rotate, trim)
  if rotate
    [ @height - 2 * trim, @width - 2 * trim ]
  else
    [ @width - 2 * trim, @height - 2 * trim ]
  end
end

#compute_valign(layout, valign, embed_h) ⇒ 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:


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/squib/graphics/text.rb', line 26

def compute_valign(layout, valign, embed_h)
  return 0 unless layout.height > 0
  ink_extents = layout.extents[1]
  ink_extents.height = embed_h * Pango::SCALE if ink_extents.height == 0 # JUST embed, bug #134
  case valign.to_s.downcase
  when 'middle'
    Pango.pixels((layout.height - ink_extents.height) / 2)
  when 'bottom'
    Pango.pixels(layout.height - ink_extents.height)
  else
    0
  end
end

#curve(bez, draw) ⇒ 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.


96
97
98
99
100
101
102
103
104
# File 'lib/squib/graphics/shapes.rb', line 96

def curve(bez, draw)
  x1, y1, cx1, cy1 = bez.x1, bez.y1, bez.cx1, bez.cy1
  cx2, cy2, x2, y2 = bez.cx2, bez.cy2, bez.x2, bez.y2
  use_cairo do |cc|
    cc.move_to(x1, y1)
    cc.curve_to(cx1, cy1, cx2, cy2, x2, y2)
    cc.fill_n_stroke(draw)
  end
end

#draw_text_hint(cc, x, y, layout, color) ⇒ 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:


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/squib/graphics/text.rb', line 10

def draw_text_hint(cc, x, y, layout, color)
  color = @deck.text_hint if color.to_s.eql? 'off' and not @deck.text_hint.to_s.eql? 'off'
  return if color.to_s.eql? 'off' or color.nil?
  # when w,h < 0, it was never set. extents[1] are ink extents
  w = layout.width / Pango::SCALE
  w = layout.extents[1].width / Pango::SCALE if w < 0
  h = layout.height / Pango::SCALE
  h = layout.extents[1].height / Pango::SCALE if h < 0
  cc.rounded_rectangle(0, 0, w, h, 0, 0)
  cc.set_source_color(color)
  cc.set_line_width(2.0)
  cc.stroke
end

#ellipse(box, draw, trans) ⇒ 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.

Ellipse drawing taken from looking at the control points in Inkscape Think of it like a rectangle. Curves go from mid-points of the sides of the rectangle. Control points are at 1/4 and 3/4 of the side. :nodoc:


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/squib/graphics/shapes.rb', line 38

def ellipse(box, draw, trans)
  x, y, w, h = box.x, box.y, box.width, box.height
  use_cairo do |cc|
    cc.rotate_about(box.x, box.y, trans.angle)
    cc.move_to(x, y + 0.5 * h)       # start west
    cc.curve_to(x, y + 0.25 * h,     # west to north
                x + 0.25 * w, y,
                x + 0.5 * w, y)
    cc.curve_to(x + 0.75 * w, y,     # north to east
                x + w, y + 0.25 * h,
                x + w, y + 0.5 * h)
    cc.curve_to(x + w, y + 0.75 * h, # east to south
                x + 0.75 * w, y + h,
                x + 0.5 * w, y + h)
    cc.curve_to(x + 0.25 * w, y + h, # south to west
                x, y + 0.75 * h,
                x, y + 0.5 * h)
    cc.fill_n_stroke(draw)
  end
end

#embed_images!(embed, str, layout, valign) ⇒ Object

# :nodoc: # @api private


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/squib/graphics/text.rb', line 79

def embed_images!(embed, str, layout, valign)
  return [] unless embed.rules.any?
  layout.markup = str
  clean_str     = layout.text
  attrs = layout.attributes || Pango::AttrList.new
  EmbeddingUtils.indices(clean_str, embed.rules.keys).each do |key, ranges|
    rule = embed.rules[key]
    ranges.each do |range|
      carve = Pango::Rectangle.new(0, 0, compute_carve(rule, range), 0)
      att = Pango::AttrShape.new(carve, carve, rule)
      att.start_index = range.first
      att.end_index = range.last
      attrs.insert(att)
    end
  end
  layout.attributes = attrs
  layout.context.set_shape_renderer do |cxt, att, do_path|
    unless do_path # when stroking the text
      rule = att.data
      x = Pango.pixels(layout.index_to_pos(att.start_index).x) +
          rule[:adjust].dx[@index]
      y = Pango.pixels(layout.index_to_pos(att.start_index).y) +
            rule[:adjust].dy[@index] +
            compute_valign(layout, valign, rule[:box].height[@index])
      rule[:draw].call(self, x, y)
      cxt.reset_clip
      [cxt, att, do_path]
    end
  end
end

#finish!Object


55
56
57
58
59
60
61
# File 'lib/squib/card.rb', line 55

def finish!
  begin
    @cairo_surface.finish
  rescue Cairo::SurfaceFinishedError
    # do nothin - if it's already finished that's fine
  end
end

#grid(box, draw) ⇒ 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:


61
62
63
64
65
66
67
# File 'lib/squib/graphics/shapes.rb', line 61

def grid(box, draw)
  x, y, w, h = box.x, box.y, box.width, box.height
  use_cairo do |cc|
    (x..@width + w).step(w)  { |ix| line_xy(ix, y - @height, ix, @height + y, draw) }
    (y..@height + h).step(h) { |iy| line_xy(x - @width, iy, @width + x, iy, draw) }
  end
end

#line(coord, draw) ⇒ 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:


80
81
82
# File 'lib/squib/graphics/shapes.rb', line 80

def line(coord, draw)
  line_xy(coord.x1, coord.y1, coord.x2, coord.y2, draw)
end

#line_xy(x1, y1, x2, y2, draw) ⇒ 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:


86
87
88
89
90
91
92
# File 'lib/squib/graphics/shapes.rb', line 86

def line_xy(x1, y1, x2, y2, draw)
  use_cairo do |cc|
    cc.move_to(x1, y1)
    cc.line_to(x2, y2)
    cc.fancy_stroke(draw)
  end
end

#make_surface(svgfile, backend) ⇒ 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:


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/squib/card.rb', line 32

def make_surface(svgfile, backend)
  case backend.downcase.to_sym
  when :memory
    Cairo::ImageSurface.new(@width, @height)
  when :svg
    FileUtils.mkdir_p @deck.dir unless Dir.exists?(@deck.dir)
    Cairo::SVGSurface.new(svgfile, @width, @height)
  else
    Squib.logger.fatal "Back end not recognized: '#{backend}'"
    abort
  end
end

#png(file, box, paint, trans) ⇒ 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:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/squib/graphics/image.rb', line 32

def png(file, box, paint, trans)
  Squib.logger.debug {"RENDERING PNG: \n  file: #{file}\n  box: #{box}\n  paint: #{paint}\n  trans: #{trans}"}
  return if file.nil? or file.eql? ''
  png = Squib.cache_load_image(file)
  use_cairo do |cc|
    cc.translate(box.x, box.y)
    box.width    = png.width.to_f  if box.width  == :native
    box.height   = png.height.to_f if box.height == :native
    box.width    = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale
    box.height   = png.height.to_f * box.width.to_f / png.width.to_f  if box.height == :scale

    scale_width  = box.width.to_f / png.width.to_f
    scale_height = box.height.to_f / png.height.to_f
    warn_png_scale(file, scale_width, scale_height)
    cc.scale(scale_width, scale_height)

    cc.rotate(trans.angle)
    cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
    cc.translate(-box.x, -box.y)

    trans.crop_width  = png.width.to_f  if trans.crop_width  == :native
    trans.crop_height = png.height.to_f if trans.crop_height == :native
    cc.rounded_rectangle(box.x, box.y, trans.crop_width, trans.crop_height, trans.crop_corner_x_radius, trans.crop_corner_y_radius)
    cc.clip
    cc.translate(-trans.crop_x, -trans.crop_y)


    cc.set_source(png, box.x, box.y)
    cc.operator = paint.blend unless paint.blend == :none
    if paint.mask.empty?
      cc.paint(paint.alpha)
    else
      cc.set_source_squibcolor(paint.mask)
      cc.mask(png, box.x, box.y)
    end
  end
end

#polygon(poly, trans, draw) ⇒ 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:


127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/squib/graphics/shapes.rb', line 127

def polygon(poly, trans, draw)
  x, y, n, radius = poly.x, poly.y, poly.n, poly.radius
  use_cairo do |cc|
    cc.rotate_about(x, y, trans.angle)
    cc.move_to(x + radius, y) # i = 0, so cos(0)=1 and sin(0)=0
    theta = (2 * Math::PI) / n.to_f
    0.upto(n) do |i|
        cc.line_to(x + radius * Math::cos(i * theta),
                   y + radius * Math::sin(i * theta))
    end
    cc.close_path
    cc.fill_n_stroke(draw)
  end
end

#preprocess_save?(batch) ⇒ Boolean

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:

Returns:

  • (Boolean)

18
19
20
# File 'lib/squib/graphics/save_images.rb', line 18

def preprocess_save?(batch)
  batch.rotate != false || batch.trim > 0
end

#preprocessed_save(width, height, batch) ⇒ 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.


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/squib/graphics/save_images.rb', line 30

def preprocessed_save(width, height, batch)
  new_cc = Cairo::Context.new(Cairo::ImageSurface.new(width, height))
  trim_radius = batch.trim_radius
  if batch.rotate != false
    new_cc.translate(width * 0.5, height * 0.5)
    new_cc.rotate(batch.angle)
    new_cc.translate(height * -0.5, width * -0.5)
    new_cc.rounded_rectangle(0, 0, height, width, trim_radius, trim_radius)
  else
    new_cc.rounded_rectangle(0, 0, width, height, trim_radius, trim_radius)
  end
  new_cc.clip
  new_cc.set_source(@cairo_surface, -batch.trim, -batch.trim)
  new_cc.paint
  return new_cc.target
end

#rect(box, draw, trans) ⇒ 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:


7
8
9
10
11
12
13
14
# File 'lib/squib/graphics/shapes.rb', line 7

def rect(box, draw, trans)
  use_cairo do |cc|
    cc.rotate_about(box.x, box.y, trans.angle)
    cc.rounded_rectangle(box.x, box.y, box.width, box.height,
                         box.x_radius, box.y_radius)
    cc.fill_n_stroke(draw)
  end
end

#save_png(batch) ⇒ 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
# File 'lib/squib/graphics/save_images.rb', line 6

def save_png(batch)
  surface = if preprocess_save?(batch)
              w, h = compute_dimensions(batch.rotate, batch.trim)
              preprocessed_save(w, h, batch)
            else
              @cairo_surface
            end
  write_png(surface, index, batch.dir, batch.prefix, batch.count_format)
end

#set_font_rendering_opts!(layout) ⇒ Object


40
41
42
43
44
45
46
# File 'lib/squib/graphics/text.rb', line 40

def set_font_rendering_opts!(layout)
  font_options                = Cairo::FontOptions.new
  font_options.antialias      = Conf::ANTIALIAS_OPTS[(@deck.antialias || 'gray').downcase]
  font_options.hint_metrics   = 'on' # TODO make this configurable
  font_options.hint_style     = 'full' # TODO make this configurable
  layout.context.font_options = font_options
end

#set_wh!(layout, 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.

:nodoc:


50
51
52
53
# File 'lib/squib/graphics/text.rb', line 50

def set_wh!(layout, width, height)
  layout.width  = width * Pango::SCALE unless width.nil? || width == :auto
  layout.height = height * Pango::SCALE unless height.nil? || height == :auto
end

#star(poly, trans, draw) ⇒ 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:


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/squib/graphics/shapes.rb', line 108

def star(poly, trans, draw)
  x, y, n = poly.x, poly.y, poly.n
  inner_radius, outer_radius = poly.inner_radius, poly.outer_radius
  use_cairo do |cc|
    cc.rotate_about(x, y, trans.angle)
    cc.move_to(x + outer_radius, y) # i = 0, so cos(0)=1 and sin(0)=0
    theta = Math::PI / n.to_f # i.e. (2*pi) / (2*n)
    0.upto(2 * n) do |i|
        radius = i.even? ? outer_radius : inner_radius
        cc.line_to(x + radius * Math::cos(i * theta),
                   y + radius * Math::sin(i * theta))
    end
    cc.close_path
    cc.fill_n_stroke(draw)
  end
end

#stroke_outline!(cc, layout, draw) ⇒ Object


110
111
112
113
114
115
116
# File 'lib/squib/graphics/text.rb', line 110

def stroke_outline!(cc, layout, draw)
  if draw.stroke_width > 0
    cc.pango_layout_path(layout)
    cc.fancy_stroke draw
    cc.set_source_squibcolor(draw.color)
  end
end

#svg(file, svg_args, box, paint, trans) ⇒ 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:


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/squib/graphics/image.rb', line 80

def svg(file, svg_args, box, paint, trans)
  Squib.logger.debug {"Rendering: #{file}, id: #{id} @#{x},#{y} #{width}x#{height}, alpha: #{alpha}, blend: #{blend}, angle: #{angle}, mask: #{mask}"}
  Squib.logger.warn 'Both an SVG file and SVG data were specified' unless file.to_s.empty? || svg_args.data.to_s.empty?
  return if (file.nil? or file.eql? '') and svg_args.data.nil? # nothing specified TODO Move this out to arg validator
  svg_args.data = File.read(file) if svg_args.data.to_s.empty?
  begin
    svg = Rsvg::Handle.new_from_data(svg_args.data)
  rescue Rsvg::Error::Failed
    Squib.logger.error "Invalid SVG data. Is '#{file}' a valid svg file?"
    return
  end
  box.width    = svg.width  if box.width == :native
  box.height   = svg.height if box.height == :native
  box.width  = svg.width.to_f * box.height.to_f / svg.height.to_f if box.width == :scale
  box.height = svg.height.to_f * box.width.to_f / svg.width.to_f  if box.height == :scale
  scale_width  = box.width.to_f / svg.width.to_f
  scale_height = box.height.to_f / svg.height.to_f
  use_cairo do |cc|
    cc.translate(box.x, box.y)
    cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
    cc.rotate(trans.angle)
    cc.scale(scale_width, scale_height)

    trans.crop_width  = box.width  if trans.crop_width  == :native
    trans.crop_height = box.height if trans.crop_height == :native
    cc.rounded_rectangle(0, 0, trans.crop_width / scale_width, trans.crop_height / scale_height, trans.crop_corner_x_radius, trans.crop_corner_y_radius)
    cc.clip
    cc.translate(-trans.crop_x, -trans.crop_y)

    cc.operator = paint.blend unless paint.blend == :none
    if paint.mask.to_s.empty?
      cc.render_rsvg_handle(svg, id: svg_args.id)
    else
      tmp = Cairo::ImageSurface.new(box.width / scale_width, box.height / scale_height)
      tmp_cc = Cairo::Context.new(tmp)
      tmp_cc.render_rsvg_handle(svg, id: svg_args.id)
      cc.set_source_squibcolor(paint.mask)
      cc.mask(tmp, 0, 0)
    end
  end
end

#text(embed, para, box, trans, draw, dpi) ⇒ 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:


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/squib/graphics/text.rb', line 126

def text(embed, para, box, trans, draw, dpi)
  Squib.logger.debug {"Rendering text with: \n#{para} \nat:\n #{box} \ndraw:\n #{draw} \ntransform: #{trans}"}
  extents = nil
  use_cairo do |cc|
    cc.set_source_squibcolor(draw.color)
    cc.translate(box.x, box.y)
    cc.rotate(trans.angle)
    cc.move_to(0, 0)

    font_desc      = Pango::FontDescription.new(para.font)
    font_desc.size = para.font_size * Pango::SCALE unless para.font_size.nil?
    layout         = cc.create_pango_layout
    layout.font_description = font_desc
    layout.text = para.str.to_s
    layout.context.resolution = dpi
    if para.markup
      para.str = @deck.typographer.process(layout.text)
      layout.markup = para.str.to_s
    end

    set_font_rendering_opts!(layout)
    set_wh!(layout, box.width, box.height)
    layout.wrap      = para.wrap
    layout.ellipsize = para.ellipsize
    layout.alignment = para.align

    layout.justify = para.justify unless para.justify.nil?
    layout.spacing = para.spacing unless para.spacing.nil?

    embed_images!(embed, para.str, layout, para.valign)

    vertical_start = compute_valign(layout, para.valign, 0)
    cc.move_to(0, vertical_start)

    stroke_outline!(cc, layout, draw) if draw.stroke_strategy == :stroke_first
    cc.move_to(0, vertical_start)

    cc.show_pango_layout(layout)
    stroke_outline!(cc, layout, draw) if draw.stroke_strategy == :fill_first
    draw_text_hint(cc, box.x, box.y, layout, para.hint)
    extents = { width: layout.extents[1].width / Pango::SCALE,
                height: layout.extents[1].height / Pango::SCALE }
    warn_if_ellipsized layout
  end
  return extents
end

#triangle(tri, draw) ⇒ 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:


71
72
73
74
75
76
# File 'lib/squib/graphics/shapes.rb', line 71

def triangle(tri, draw)
  use_cairo do |cc|
    cc.triangle(tri.x1, tri.y1, tri.x2, tri.y2, tri.x3, tri.y3)
    cc.fill_n_stroke(draw)
  end
end

#use_cairo(&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.

A save/restore wrapper for using Cairo :nodoc:


48
49
50
51
52
53
# File 'lib/squib/card.rb', line 48

def use_cairo(&block)
  @cairo_context.save
  @cairo_context.new_path # see bug 248
  block.yield(@cairo_context)
  @cairo_context.restore
end

#warn_if_ellipsized(layout) ⇒ Object


118
119
120
121
122
# File 'lib/squib/graphics/text.rb', line 118

def warn_if_ellipsized(layout)
   if @deck.conf.warn_ellipsize? && layout.ellipsized?
     Squib.logger.warn { "Ellipsized (too much text). Card \##{@index}. Text:  \"#{layout.text}\". \n (To disable this warning, set warn_ellipsize: false in config.yml)" }
   end
end

#warn_png_scale(file, scale_width, scale_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.

:nodoc:


72
73
74
75
76
# File 'lib/squib/graphics/image.rb', line 72

def warn_png_scale(file, scale_width, scale_height)
  if @deck.conf.warn_png_scale? && (scale_width > 1.0 || scale_height > 1.0)
    Squib.logger.warn "PNG is being upscaled - antialiasing could result: #{file}"
  end
end

#write_png(surface, i, dir, prefix, count_format) ⇒ 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.


47
48
49
# File 'lib/squib/graphics/save_images.rb', line 47

def write_png(surface, i, dir, prefix, count_format)
  surface.write_to_png("#{dir}/#{prefix}#{count_format % i}.png")
end