blacksmith 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rvmrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blacksmith.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Konstantin Tennhard
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Blacksmith
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blacksmith'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blacksmith
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/blacksmith/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Konstantin Tennhard"]
6
+ gem.email = ["me@t6d.de"]
7
+ gem.summary = %q{Blacksmith uses FontForge to build fonts from SVG graphics}
8
+ gem.homepage = "http://github.com/t6d/blacksmith"
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "blacksmith"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Blacksmith::VERSION
16
+
17
+ gem.add_dependency "smart_properties", "~> 1.0"
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'blacksmith'
3
+
4
+ Blacksmith.forge do
5
+
6
+ name "Blacksmith Medium"
7
+ family "Blacksmith"
8
+
9
+ source File.expand_path('../src', __FILE__)
10
+ target File.expand_path('../blacksmith-medium.ttf', __FILE__)
11
+
12
+ glyph 'star', code: 0x0061
13
+
14
+ end
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" version="1.1">
3
+ <title></title>
4
+ <description>Created with Sketch (http://www.bohemiancoding.com/sketch)</description>
5
+ <defs>
6
+ <linearGradient id="gradient-1" x1="50%" y1="0%" x2="50%" y2="100%">
7
+ <stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:100"></stop>
8
+ <stop offset="100%" style="stop-color:rgb(0,0,0); stop-opacity:100"></stop>
9
+ </linearGradient>
10
+ <linearGradient id="gradient-2" x1="50%" y1="0%" x2="50%" y2="100%">
11
+ <stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:100"></stop>
12
+ <stop offset="100%" style="stop-color:rgb(0,0,0); stop-opacity:100"></stop>
13
+ </linearGradient>
14
+ <linearGradient id="gradient-3" x1="50%" y1="0%" x2="50%" y2="100%">
15
+ <stop offset="0%" style="stop-color:rgb(255,255,255); stop-opacity:100"></stop>
16
+ <stop offset="100%" style="stop-color:rgb(0,0,0); stop-opacity:100"></stop>
17
+ </linearGradient>
18
+ </defs>
19
+ <g fill="rgb(215,215,215)" id="Page 1">
20
+ <g fill="rgb(0,0,0)" id="Star 55"></g>
21
+ <path id="Star 55" d="M65,90 L35,106 L41,72 L16,48 L50,43 L65,13 L80,43 L114,48 L89,72 L95,106 L65,90 Z M65,90" fill="rgb(0,0,0)"></path>
22
+ <path id="Star 55 decoration" d="" fill="rgb(0,0,0)"></path>
23
+ </g>
24
+ </svg>
data/lib/blacksmith.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'smart_properties'
2
+ require 'erb'
3
+ require 'tempfile'
4
+
5
+ require 'blacksmith/font'
6
+ require 'blacksmith/font_builder'
7
+ require 'blacksmith/glyph'
8
+ require 'blacksmith/version'
9
+
10
+ module Blacksmith
11
+
12
+ class << self
13
+
14
+ def forge(filename = nil, &block)
15
+ font = prepare_font(&block)
16
+ forge_font(font)
17
+ end
18
+
19
+ private
20
+
21
+ def prepare_font(&block)
22
+ FontBuilder.new(&block).build
23
+ end
24
+
25
+ def forge_font(font)
26
+ path = create_forging_instructions(font)
27
+ create_font_from_instructions(path)
28
+ File.unlink(path)
29
+ end
30
+
31
+ def create_forging_instructions(font)
32
+ script = Tempfile.new('fontforge-instructions')
33
+
34
+ script << font.instance_exec(forging_template) do |template|
35
+ template.result(binding)
36
+ end
37
+
38
+ script.close
39
+ script.path
40
+ end
41
+
42
+ def forging_template
43
+ template = File.read(File.join(root_directory, 'support', 'build.py.erb'))
44
+ ERB.new(template, nil, '<>')
45
+ end
46
+
47
+ def root_directory
48
+ File.expand_path('../..', __FILE__)
49
+ end
50
+
51
+ def create_font_from_instructions(path)
52
+ `fontforge -lang=py -script #{path}`
53
+ end
54
+
55
+ end
56
+
57
+
58
+ end
@@ -0,0 +1,52 @@
1
+ module Blacksmith
2
+ class Font
3
+ include SmartProperties
4
+
5
+ property :name, :required => true,
6
+ :converts => :to_s
7
+
8
+ property :family, :required => true,
9
+ :converts => :to_s
10
+
11
+ property :copyright, :converts => :to_s
12
+
13
+ property :ascent, :required => true,
14
+ :converts => :to_i,
15
+ :accepts => lambda { |number| number > 0 },
16
+ :default => 800
17
+
18
+ property :descent, :required => true,
19
+ :converts => :to_i,
20
+ :accepts => lambda { |number| number > 0 },
21
+ :default => 200
22
+
23
+ property :weight, :required => true,
24
+ :default => 'Medium'
25
+
26
+ property :version, :required => true,
27
+ :converts => :to_s,
28
+ :accepts => lambda { |v| /\d+\.\d+(\.\d+)?/.match(v) },
29
+ :default => '1.0'
30
+
31
+ property :filename, :required => true,
32
+ :converts => :to_s,
33
+ :accepts => lambda { |target|
34
+ File.extname(target) == '.ttf' and
35
+ File.directory?(File.dirname(target))
36
+ }
37
+
38
+ def identifier
39
+ name.gsub(/\W+/, '_')
40
+ end
41
+
42
+ def glyphs
43
+ (@glyphs || []).dup
44
+ end
45
+
46
+ def <<(glyph)
47
+ @glyphs ||= []
48
+ @glyphs << glyph
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ module Blacksmith
2
+ class FontBuilder
3
+
4
+ def initialize(&block)
5
+ @_instructions = block
6
+ @_attributes = {}
7
+ @_glyphs = {}
8
+ @_source = '.'
9
+ end
10
+
11
+ def build
12
+ instance_eval(&@_instructions)
13
+
14
+ font = Font.new(@_attributes)
15
+
16
+ @_glyphs.each do |name, attrs|
17
+ attrs[:outline] ||= File.join(@_source, "#{name}.svg")
18
+ font << Glyph.new(attrs)
19
+ end
20
+
21
+ font
22
+ end
23
+
24
+ def source(path = nil)
25
+ if path
26
+ raise ArgumentError, "Directory does not exist: #{path}" unless File.directory?(path)
27
+ @_source = path
28
+ else
29
+ @_source
30
+ end
31
+ end
32
+
33
+ def target(path = nil)
34
+ if path
35
+ raise ArgumentError, "Directory does not exist: #{path}" unless File.directory?(File.dirname(path))
36
+ @_attributes[:filename] = path
37
+ else
38
+ @_attributes[:filename]
39
+ end
40
+ end
41
+
42
+ def glyph(name, attrs)
43
+ @_glyphs[name] = attrs
44
+ end
45
+
46
+ def method_missing(name, *args)
47
+ if args.length == 1
48
+ @_attributes[name] = args[0]
49
+ else
50
+ super
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ module Blacksmith
2
+ class Glyph
3
+ include SmartProperties
4
+
5
+ property :outline, :required => true,
6
+ :converts => :to_s,
7
+ :accepts => lambda { |filename| File.exist?(filename) }
8
+
9
+ property :code, :required => true
10
+
11
+ property :left_side_bearing, :required => true,
12
+ :converts => :to_i,
13
+ :default => 15
14
+
15
+ property :right_side_bearing, :required => true,
16
+ :converts => :to_i,
17
+ :default => 15
18
+
19
+ def name
20
+ File.basename(outline)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Blacksmith
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ import fontforge
2
+
3
+ font = fontforge.font()
4
+
5
+ font.version = "<%= version %>"
6
+ font.fontname = "<%= identifier %>"
7
+ font.fullname = "<%= name %>"
8
+ font.familyname = "<%= family %>"
9
+ font.copyright = "<%= copyright %>"
10
+ font.ascent = <%= ascent %>
11
+ font.descent = <%= descent %>
12
+ font.weight = "<%= weight %>"
13
+
14
+ <% for glyph in glyphs do %>
15
+ # <%= glyph.name %>
16
+ c = font.createChar(<%= glyph.code %>)
17
+ c.importOutlines("<%= glyph.outline %>")
18
+ c.left_side_bearing = <%= glyph.left_side_bearing %>
19
+ c.right_side_bearing = <%= glyph.right_side_bearing %>
20
+ c.simplify()
21
+ c.round()
22
+
23
+ <% end %>
24
+
25
+ font.generate("<%= filename %>")
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacksmith
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Konstantin Tennhard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: smart_properties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description:
31
+ email:
32
+ - me@t6d.de
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - blacksmith.gemspec
43
+ - examples/forging_fonts.rb
44
+ - examples/src/star.svg
45
+ - lib/blacksmith.rb
46
+ - lib/blacksmith/font.rb
47
+ - lib/blacksmith/font_builder.rb
48
+ - lib/blacksmith/glyph.rb
49
+ - lib/blacksmith/version.rb
50
+ - support/build.py.erb
51
+ homepage: http://github.com/t6d/blacksmith
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Blacksmith uses FontForge to build fonts from SVG graphics
75
+ test_files: []