Class: Hieroglyph::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/hieroglyph/font.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Font

Returns a new instance of Font.



7
8
9
10
11
12
13
14
15
16
# File 'lib/hieroglyph/font.rb', line 7

def initialize(options)
  @characters = []
  @unicode_values = []
  @contents = ""
  @options = options
  @output_path = File.join(@options[:output_folder], @options[:name] + ".svg")
  setup
  add_glyphs
  finish
end

Instance Attribute Details

#character_sheetObject

Returns the value of attribute character_sheet.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def character_sheet
  @character_sheet
end

#charactersObject

Returns the value of attribute characters.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def characters
  @characters
end

#contentsObject

Returns the value of attribute contents.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def contents
  @contents
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def options
  @options
end

#output_pathObject

Returns the value of attribute output_path.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def output_path
  @output_path
end

#unicode_valuesObject

Returns the value of attribute unicode_values.



5
6
7
# File 'lib/hieroglyph/font.rb', line 5

def unicode_values
  @unicode_values
end

Instance Method Details

#add(str) ⇒ Object



45
46
47
# File 'lib/hieroglyph/font.rb', line 45

def add(str)
  @contents << str
end

#add_glyphsObject



49
50
51
52
53
54
55
56
# File 'lib/hieroglyph/font.rb', line 49

def add_glyphs
  Hieroglyph.header 'Reading glyphs:'
  Dir.glob(File.join(@options[:glyph_folder], '*.svg')).each do |file|
    glyph = Glyph.new(file, @options[:glyph_folder], self)
    @character_sheet.add file
    add glyph.to_node
  end
end

#finishObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/hieroglyph/font.rb', line 34

def finish
  include "footer"
  set_name
  File.open(@output_path, "w") do |file|
    file.puts @contents
    file.close
  end
  Hieroglyph.header 'Done!'
  @character_sheet.save
end

#include(file) ⇒ Object



18
19
20
21
# File 'lib/hieroglyph/font.rb', line 18

def include(file)
  path = File.join(File.dirname(__FILE__), "assets/#{file}")
  add File.open(path).read
end

#set_nameObject



30
31
32
# File 'lib/hieroglyph/font.rb', line 30

def set_name
  @contents.gsub!("{{NAME}}", @options[:name])
end

#setupObject



23
24
25
26
27
28
# File 'lib/hieroglyph/font.rb', line 23

def setup
  Hieroglyph.header 'Setup:'
  Hieroglyph.delete @output_path
  @character_sheet = Hieroglyph.imagemagick_installed? ? CharacterSheet.new(@options) : NoopSheet.new
  include 'header'
end