@@ -44,26 +44,23 @@ def draw_text!(text, at:, text_options:)
4444
4545 def draw_text ( text , at :, text_options :)
4646 draw_text! ( text , at : at , text_options : text_options )
47- document . width_of ( text , text_options )
47+
48+ width = document . width_of ( text , text_options )
49+
50+ if Prawn ::VERSION >= '2.3.0'
51+ # In prawn v2.3.0, the character spacing at the end of the text is not included in the calculated text width.
52+ # https://github.com/prawnpdf/prawn/pull/1117
53+ width > 0 ? width + document . character_spacing : width
54+ else
55+ width
56+ end
4857 end
4958
5059 def draw_emoji ( emoji_char , at :)
5160 emoji_image = Emoji ::Image . new ( emoji_char )
61+ emoji_image . render ( document , at : at )
5262
53- x , y = at
54-
55- # Prawn 2.2 does not close the image file when Pathname is passed to Document#image method.
56- #
57- # FIXME: This issue has been fixed by https://github.com/prawnpdf/prawn/pull/1090 but not released.
58- # Fix as follows after the PR released.
59- #
60- # @document.image(image_file.path, at: [x, y], width: image.width)
61- #
62- File . open ( emoji_image . path , 'rb' ) do |image_file |
63- @document . image ( image_file , at : [ x , y + emoji_char . height ] , width : emoji_char . width )
64- end
65-
66- emoji_char . width + document . character_spacing
63+ emoji_image . width + document . character_spacing
6764 end
6865 end
6966 end
0 commit comments