Class: Painter::Text

Inherits:
Operation show all
Defined in:
lib/painter/text.rb

Defined Under Namespace

Classes: BlankFontError, MissingFontError

Instance Method Summary collapse

Methods inherited from Operation

#_angle, #_color, #angle, #color, #initialize, pretty_accessor

Constructor Details

This class inherits a constructor from Painter::Operation

Instance Method Details

#drawObject

Raises:



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

def draw
  raise BlankFontError if _font.nil?
  raise MissingFontError, _font unless File.exists?(_font)
  brect = FFI::MemoryPointer.new(:int, 8)
  error = CGD2::gdImageStringFT(@image.image_pointer, brect, _color.rgba, _font,
    _size.to_f, _angle.to_f, _at.x, _at.y, _text.gsub('&', '&'))
  raise "Drawing error: #{error}" unless error.null?
  brect = brect.read_array_of_int(8)
  { :lower_left   => [brect[0], brect[1]],
    :lower_right  => [brect[2], brect[3]],
    :upper_right  => [brect[4], brect[5]],
    :upper_left   => [brect[6], brect[7]]}
end