Method: MagicCloud::Canvas#draw_text

Defined in:
lib/magic_cloud/canvas.rb

#draw_text(text, options = {}) ⇒ Object

rubocop:todo Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/magic_cloud/canvas.rb', line 20

def draw_text(text, options = {}) # rubocop:todo Metrics/AbcSize
  return nil if text.empty?

  draw = Magick::Draw.new # FIXME: is it necessary every time?

  x = options.fetch(:x, 0)
  y = options.fetch(:y, 0)
  rotate = options.fetch(:rotate, 0)

  set_text_options(draw, options)

  rect = _measure_text(draw, text, rotate)

  draw.
    translate(x + rect.width/2, y + rect.height/2).
    rotate(rotate).
    translate(0, rect.height/8). # RMagick text_align seems really weird
    text(0, 0, text).
    draw(@internal)

  rect
end