Class: Prawn::Emoji::Image

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/prawn/emoji/image.rb

Constant Summary collapse

STORE =
Emoji.root.join 'emoji', 'images'

Instance Method Summary collapse

Constructor Details

#initialize(emoji_char) ⇒ Image

Returns a new instance of Image.



14
15
16
# File 'lib/prawn/emoji/image.rb', line 14

def initialize(emoji_char)
  @emoji_char = emoji_char
end

Instance Method Details

#pathObject



34
35
36
# File 'lib/prawn/emoji/image.rb', line 34

def path
  STORE.join("#{emoji_char.codepoint}.png").to_s
end

#render(document, at:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prawn/emoji/image.rb', line 18

def render(document, at:)
  x, y = at

  position = [x, y + height]

  if Prawn::VERSION >= '2.3.0'
    document.image(path, at: position, width: width)
  else
    # Prawn 2.2 does not close the image file when Pathname is passed to Document#image method.
    # https://github.com/prawnpdf/prawn/pull/1090
    File.open(path, 'rb') do |image_file|
      document.image(image_file, at: position, width: width)
    end
  end
end