Class: Prawn::Emoji::Drawer
- Inherits:
-
Object
- Object
- Prawn::Emoji::Drawer
- Defined in:
- lib/prawn/emoji/drawer.rb
Instance Method Summary collapse
- #draw(text, text_options) ⇒ Object
-
#initialize(document) ⇒ Drawer
constructor
A new instance of Drawer.
Constructor Details
#initialize(document) ⇒ Drawer
Returns a new instance of Drawer.
11 12 13 14 |
# File 'lib/prawn/emoji/drawer.rb', line 11 def initialize(document) @document = document @emoji_index = Emoji::Index.new end |
Instance Method Details
#draw(text, text_options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prawn/emoji/drawer.rb', line 16 def draw(text, ) return text unless text.encoding == ::Encoding::UTF_8 return text unless Emoji::REGEX.match?(text) result = [] target = Emoji::Text.new(text) while target.contains_emoji? do if emoji_index.include?(target.emoji.codepoint) draw_emoji( target, text_options: , base_text: result.join ) result << target.left + Emoji::Substitution.new(@document).to_s else result << target.left_with_emoji end target = Emoji::Text.new(target.remaining) end result.join + target.to_s end |