Sha256: afd98cf768ef8d8e3db3cf13872b3fa1daff1f19ee43d49d91da1b04ed6cfd3e

Contents?: true

Size: 794 Bytes

Versions: 8

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

module Prawn
  module Emoji
    class Char
      VARIATION_SELECTORS = %w(fe0e fe0f).freeze

      class << self
        def format_codepoint(codepoints)
          (codepoints - VARIATION_SELECTORS).map { |c| c.rjust(4, '0') }.join('-').downcase
        end
      end

      attr_reader :font_size, :char
      alias_method :to_s, :char

      def initialize(char, font_size)
        @char = char
        @font_size = font_size
      end

      def ==(other)
        char == other.to_s
      end

      def codepoint
        @codepoint ||= self.class.format_codepoint(char.codepoints.map { |c| c.to_s(16) })
      end

      def width
        @width ||= font_size * 0.85
      end

      def height
        @height ||= font_size * 0.8
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
prawn-emoji-5.3.0 lib/prawn/emoji/char.rb
prawn-emoji-5.2.0 lib/prawn/emoji/char.rb
prawn-emoji-5.1.0 lib/prawn/emoji/char.rb
prawn-emoji-5.0.0 lib/prawn/emoji/char.rb
prawn-emoji-4.2.0 lib/prawn/emoji/char.rb
prawn-emoji-4.1.0 lib/prawn/emoji/char.rb
prawn-emoji-4.0.0 lib/prawn/emoji/char.rb
prawn-emoji-4.0.0.beta.1 lib/prawn/emoji/char.rb