LoginSignup
4

More than 5 years have passed since last update.

Prawn で絵文字が使えるようになる prawn-emoji の紹介

Last updated at Posted at 2016-12-23

Prawn で絵文字が使えるようになる prawn-emoji2.0.0 をリリースしたので紹介しておきます。

prawn-emoji とは

require 'prawn'
require 'prawn/emoji'

Prawn::Document.generate 'example.pdf' do
  font 'ipag.ttf'

  text '🐟 + 🔪 = 🍣'

  move_down 50
  text '🇯🇵'

  move_down 10
  text '🙏🙏🏻🙏🏼🙏🏽🙏🏾🙏🏿'

  move_down 50
  text_box '🍣' * 50, at: [0, cursor], width: 300

  move_down 50
  text_box '🍣を中央寄せ', align: :center, at: [0, cursor], width: 300

  move_down 50
  text_box '回転🍣', rotate: 45, at: [0, cursor], width: 150

  move_down 50
  text_box '大きい🍣', size: 20, at: [0, cursor], width: 300

  move_down 50
  draw_text '🍣食べたい', at: [0, cursor]
end

prawn-emoji を使うと、Prawn を使ったこんな感じのコードで PDF に絵文字を表示することができるようになります。

Screen Shot 2016-12-24 at 3.29.07.png

絵文字は EmojiOne を使ってるので、同じ寿司でも見た目が異なることはあります。

特徴

  • 絵文字を正しく描画するためには、TrueTypeフォントが必要
  • 絵文字画像は EmojiOne のものを使っている
  • v2.0.0 で、国旗など複合絵文字に対応した
  • テキストセンタリングやフォントサイズなど、一通りの機能は実装済み
  • Thinreports でも使える

既知の問題

Issue#7 Emoji cause text to extend beyond edge of bounding box

https://github.com/hidakatsuya/prawn-emoji/issues/7
これ難しいんですよね。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4