Sha256: ff487b1961c03f4fe823a20085faec10361a8252c2ce20d238310c369fd82570

Contents?: true

Size: 744 Bytes

Versions: 1

Compression:

Stored size: 744 Bytes

Contents

module Hershey
  class Character
    OFFSET = ' '.ord
    MATCHER = /\A(?<midpoint>[\d-]+) +(?<width>[\d-]+) ?(?<path>[\w -]*)\Z/.freeze

    def initialize(character, font: :futural)
      @char = I18n.transliterate(character.to_s[0] || ' ').to_sym
      @font = font
    end

    def to_path(offset)
      %Q{<path stroke="black" fill="none" d="#{info[:path]}" transform="translate(#{offset - info[:midpoint]},0)"></path>}
    end

    def spacing
      info[:spacing]
    end

    def char
      @char
    end

    alias_method :to_s, :char

    private

    def info
      Hershey::FONTS[@font][@char.to_s.ord - OFFSET]
    end

    def path_handler(path)
      path || (p `node /Users/wmd/tmp/smooth.js '#{path}'`.strip)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hershey-0.0.8 lib/hershey/character.rb