class Hershey::Character

Constants

MATCHER
OFFSET

Public Class Methods

new(character, font: :futural) click to toggle source
# File lib/hershey/character.rb, line 8
def initialize(character, font: :futural)
  @char = I18n.transliterate(character.to_s[0] || ' ').to_sym
  @font = font
end

Public Instance Methods

char() click to toggle source
# File lib/hershey/character.rb, line 21
def char
  @char
end
Also aliased as: to_s
spacing() click to toggle source
# File lib/hershey/character.rb, line 17
def spacing
  info[:spacing]
end
to_path(offset) click to toggle source
# File lib/hershey/character.rb, line 13
def to_path(offset)
  %Q{<path stroke="black" fill="none" d="#{info[:path]}" transform="translate(#{offset - info[:midpoint]},0)"></path>}
end
to_s()
Alias for: char

Private Instance Methods

info() click to toggle source
# File lib/hershey/character.rb, line 29
def info
  @@chars = {}
  @@char_list ||= YAML.load_file(File.join(File.dirname(__FILE__), 'fonts_full.yaml'))[@font]
  @@chars[@char] ||= @@char_list[@char.to_s.ord - OFFSET]
  unless @@chars[@char]
    match = Hershey::FONTS[@font][@char.to_s.ord - OFFSET].match(MATCHER)
    @@chars[@char] = {
      path: path_handler(match['path']),
      midpoint: match['midpoint'].to_i,
      spacing: match['width'].to_i - match['midpoint'].to_i,
    }
  end
  @@chars[@char]
end
path_handler(path) click to toggle source
# File lib/hershey/character.rb, line 44
def path_handler(path)
  n = `node /Users/wmd/tmp/smooth.js '#{path}'`.strip
  puts n
  n
end