fontrobot 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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/fixtures/fontrobot/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ ## 0.1.4 (2/19/2013)
2
+
3
+ * Instructions for stopping watcher ([#46](https://github.com/FontCustom/fontcustom/issues/46))
4
+ * Dev/contribution instructions ([#45](https://github.com/FontCustom/fontcustom/issues/45))
5
+
6
+ ## 0.1.3 (2/2/2013)
7
+
8
+ * Add --debug CLI option, which shows fontforge output ([#37](https://github.com/FontCustom/fontcustom/issues/37))
9
+ * Patch for Illustrator CS6 SVG output ([#42](https://github.com/FontCustom/fontcustom/pull/42))
10
+ * Generate IE7 stylesheet ([#43](https://github.com/FontCustom/fontcustom/pull/43))
11
+ * Option to set custom font path for @font-face ([#43](https://github.com/FontCustom/fontcustom/pull/43))
12
+ * Option to generate test HTML file showing all glyphs ([#43](https://github.com/FontCustom/fontcustom/pull/43))
13
+ * Use eotlite.py instead of mkeot ([#43](https://github.com/FontCustom/fontcustom/pull/43))
14
+
15
+ ## 0.1.0 (12/2/2012)
16
+
17
+ * Changed API to use Thor `class_option`s
18
+ * Added option to change the name of the font and generated files ([#6](https://github.com/FontCustom/fontcustom/issues/6))
19
+ * Added option to disable the file name hash ([#13](https://github.com/FontCustom/fontcustom/issues/13))
20
+ * `fontcustom watch` compiles automatically on the first run
21
+ * Better help messages
22
+
23
+ ## 0.0.2 (11/26/2012)
24
+
25
+ * Fixed gemspec dependency bug ([#2](https://github.com/FontCustom/fontcustom/pull/2))
26
+ * Fixed Windows Chrome PUA bug ([#1](https://github.com/FontCustom/fontcustom/issues/1))
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ # Fontrobot Contributing Checklist
2
+
3
+ ## A short list to help you get started:
4
+
5
+ * Check out [issues]() for ideas. Is someone else working on something similar?
6
+ * Fork the repo and work out of a named topic branch, a la `git checkout -b my_sweet_contribution`. Please don't work directly off `master`.
7
+ * Run tests with `guard`.
8
+ * Add/improve tests for your contributions.
9
+ * Submit a pull request!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fontrobot.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'spork' do
5
+ watch('Gemfile.lock')
6
+ watch('spec/spec_helper.rb') { :rspec }
7
+ end
8
+
9
+ guard 'rspec', :cli => '--color --drb' do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/fontrobot/(.+)\.rb$}) { |m| "spec/fontrobot/#{m[1]}_spec.rb" }
12
+ watch('lib/fontrobot.rb') { 'spec/fontrobot/fontrobot_spec.rb' }
13
+ watch('lib/fontrobot/core.rb') { 'spec/fontrobot/fontrobot_spec.rb' }
14
+ watch('spec/spec_helper.rb') { 'spec' }
15
+ end
data/LICENSES.txt ADDED
@@ -0,0 +1,60 @@
1
+ fontrobot
2
+
3
+ Copyright (c) 2013 Tim Barkow
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+
27
+ sfnt2woff
28
+
29
+ Version: MPL 1.1/GPL 2.0/LGPL 2.1
30
+
31
+ The contents of this file are subject to the Mozilla Public License Version
32
+ 1.1 (the "License"); you may not use this file except in compliance with
33
+ the License. You may obtain a copy of the License at
34
+ http://www.mozilla.org/MPL/
35
+
36
+ Software distributed under the License is distributed on an "AS IS" basis,
37
+ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
38
+ for the specific language governing rights and limitations under the
39
+ License.
40
+
41
+ The Original Code is WOFF font packaging code.
42
+
43
+ The Initial Developer of the Original Code is Mozilla Corporation.
44
+ Portions created by the Initial Developer are Copyright (C) 2009
45
+ the Initial Developer. All Rights Reserved.
46
+
47
+ Contributor(s):
48
+ Jonathan Kew <jfkthame@gmail.com>
49
+
50
+ Alternatively, the contents of this file may be used under the terms of
51
+ either the GNU General Public License Version 2 or later (the "GPL"), or
52
+ the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
53
+ in which case the provisions of the GPL or the LGPL are applicable instead
54
+ of those above. If you wish to allow use of your version of this file only
55
+ under the terms of either the GPL or the LGPL, and not to allow others to
56
+ use your version of this file under the terms of the MPL, indicate your
57
+ decision by deleting the provisions above and replace them with the notice
58
+ and other provisions required by the GPL or the LGPL. If you do not delete
59
+ the provisions above, a recipient may use your version of this file under
60
+ the terms of any one of the MPL, the GPL or the LGPL.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ FontRobot v0.1
2
+ ==========
3
+
4
+ **Generate custom icon webfonts from the comfort of the command line.**
5
+
6
+ This is a fork of Fontcustom, required so I could make changes and update the gem in a timely fashion. FontRobot extends Fontcustom, adding more control over how the @fontface declaration is created. See command-line options below for more details.
7
+
8
+ [Fontcustom documentation](http://fontcustom.github.com/fontcustom/)
9
+
10
+
11
+ Installation
12
+ ------------
13
+
14
+ ```sh
15
+ # Requires FontForge
16
+ brew install fontforge ttfautohint
17
+ gem install fontrobot
18
+ ```
19
+
20
+
21
+ Usage
22
+ -----
23
+
24
+ ```sh
25
+ fontrobot compile path/to/vectors # Compile icons and css to path/to/fontrobot/*
26
+ fontrobot watch path/to/vectors # Watch for changes
27
+ ```
28
+
29
+ **Note:** the **ENTIRE** contents of the output directory (default '/fontrobot') are **DELETED** when regenerating the font. So, don't put anything else in there.
30
+
31
+
32
+ Command-line options
33
+ -----
34
+
35
+ ```sh
36
+ --output, -o => Specify an output directory. Default: $DIR/fontrobot
37
+ --name, -n => Specify a font name. This will be used in the generated fonts and CSS. Default: fontrobot
38
+ --font_path, -f => Specify a path for fonts in css @font-face declaration. Default: none
39
+
40
+ --order, -r => Specify font order in css @font-face. Default: "eot,ttf,woff,svg"
41
+ --inline, -i => Include specified font fomats as data-uri in @font-face. Default: none. Format: "eot,ttf,woff,svg"
42
+
43
+ --nohash => (boolean) Disable filename hashes. Default: false
44
+ --debug => (boolean) Display debug messages. Default: false
45
+ --html => (boolean) Generate html page with icons. Default: false
46
+ --scss => (boolean) Output .scss files. Default: false
47
+ ```
48
+
49
+ Need help?
50
+
51
+ ```sh
52
+ fontrobot --help
53
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # require 'rake'
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs = t.libs + ['lib/fontrobot', 'spec', 'spec/fixtures']
7
+ t.test_files = FileList['spec/fontrobot/*_spec.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
12
+
data/bin/fontrobot ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fontrobot/cli'
4
+
5
+ Fontrobot::CLI.start
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fontrobot/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "fontrobot"
8
+ gem.version = Fontrobot::VERSION
9
+ gem.authors = ["Tim Barkow"]
10
+ gem.email = ["tim@robotloveskitten.com"]
11
+ gem.summary = %q{Generate custom icon webfonts from the command line.}
12
+ gem.description = %q{Transforms EPS and SVG vectors into icon webfonts. Generates Bootstrap compatible CSS for easy inclusion in your projects.}
13
+ gem.homepage = "http://robotloveskitten.github.com/fontrobot/"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'json'
21
+ gem.add_dependency 'thor'
22
+ gem.add_dependency 'listen'
23
+
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'bundler'
26
+ gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'fakefs'
28
+ gem.add_development_dependency 'spork'
29
+ gem.add_development_dependency 'guard-spork'
30
+ gem.add_development_dependency 'guard-rspec'
31
+ gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
32
+ end
@@ -0,0 +1,32 @@
1
+ require 'thor'
2
+ require 'fontrobot'
3
+
4
+ module Fontrobot
5
+ class CLI < Thor
6
+ # duplicated from Fontrobot::Generator so as to also appear under `fontrobot help` command
7
+ class_option :output, :aliases => '-o', :desc => 'Specify an output directory. Default: $DIR/fontrobot'
8
+ class_option :name, :aliases => '-n', :desc => 'Specify a font name. This will be used in the generated fonts and CSS. Default: fontrobot'
9
+ class_option :font_path, :aliases => '-f', :desc => 'Specify a path for fonts in css @font-face declaration. Default: none'
10
+
11
+ class_option :order, :aliases => '-r', :desc => 'Specify font order in css @font-face. Default: "eot,ttf,woff,svg"'
12
+ class_option :inline, :aliases => '-i', :desc => 'Inline font as data-uri in @font-face. Default: none. Format: "eot,ttf,woff,svg"'
13
+
14
+ class_option :nohash, :type => :boolean, :default => false, :desc => 'Disable filename hashes. Default: false'
15
+ class_option :debug, :type => :boolean, :default => false, :desc => 'Display debug messages. Default: false'
16
+ class_option :html, :type => :boolean, :default => false, :desc => 'Generate html page with icons'
17
+ class_option :scss, :type => :boolean, :default => false, :desc => 'Output .scss files'
18
+
19
+ desc 'compile DIR [options]', 'Generates webfonts and CSS from *.svg and *.eps files in DIR.'
20
+ def compile(*args)
21
+ # workaround to pass arguments from one Thor class to another
22
+ ARGV.shift
23
+ Fontrobot.compile(*ARGV)
24
+ end
25
+
26
+ desc 'watch DIR [options]', 'Watches DIR for changes and regenerates webfonts and CSS automatically. Ctrl + C to stop.'
27
+ def watch(*args)
28
+ ARGV.shift
29
+ Fontrobot.watch(*ARGV)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,140 @@
1
+ require 'json'
2
+ require 'thor/group'
3
+ require 'base64'
4
+
5
+ module Fontrobot
6
+ class Generator < Thor::Group
7
+ include Thor::Actions
8
+
9
+ desc 'Generates webfonts from given directory of vectors.'
10
+
11
+ argument :input, :type => :string
12
+ class_option :output, :aliases => '-o'
13
+ class_option :name, :aliases => '-n'
14
+ class_option :font_path, :aliases => '-f'
15
+
16
+ class_option :order, :aliases => '-r' # 'Specify font order in css @font-face. Default: "eot,ttf,woff,svg"'
17
+ class_option :inline, :aliases => '-i' # 'Inline font as data-uri in @font-face. Default: none. Format: "eot,ttf,woff,svg"'
18
+
19
+ class_option :nohash, :type => :boolean, :default => false
20
+ class_option :debug, :type => :boolean, :default => false
21
+ class_option :html, :type => :boolean, :default => false
22
+ class_option :scss, :type => :boolean, :default => false
23
+
24
+
25
+ def self.source_root
26
+ File.dirname(__FILE__)
27
+ end
28
+
29
+ def verify_fontforge
30
+ if `which fontforge` == ''
31
+ raise Thor::Error, 'Please install fontforge first.'
32
+ end
33
+ end
34
+
35
+ def verify_input_dir
36
+ if ! File.directory?(input)
37
+ raise Thor::Error, "#{input} doesn't exist or isn't a directory."
38
+ elsif Dir[File.join(input, '*.{svg,eps}')].empty?
39
+ raise Thor::Error, "#{input} doesn't contain any vectors (*.svg or *.eps files)."
40
+ end
41
+ end
42
+
43
+ def verify_or_create_output_dir
44
+ @output = options.output.nil? ? File.join(File.dirname(input), 'fontrobot') : options.output
45
+ empty_directory(@output) unless File.directory?(@output)
46
+ end
47
+
48
+ def normalize_name
49
+ @name = if options.name
50
+ options.name.gsub(/\W/, '-').downcase
51
+ else
52
+ 'fontrobot'
53
+ end
54
+ end
55
+
56
+ def cleanup_output_dir
57
+ # simpler: how about we just delete everything in the dir?
58
+ old_files = Dir[File.join(@output, '*')]
59
+ old_files.each {|file| remove_file file }
60
+ end
61
+
62
+
63
+ def generate
64
+ gem_file_path = File.expand_path(File.join(File.dirname(__FILE__)))
65
+ name = options.name ? ' --name ' + @name : ''
66
+ nohash = options.nohash ? ' --nohash' : ''
67
+
68
+ # suppress fontforge message
69
+ # TODO get font name and classes from script (without showing fontforge message)
70
+ cmd = "fontforge -script #{gem_file_path}/scripts/generate.py #{input} #{@output + name + nohash}"
71
+ unless options.debug
72
+ cmd += " > /dev/null 2>&1"
73
+ end
74
+ `#{cmd}`
75
+ end
76
+
77
+
78
+ def show_paths
79
+ file = Dir[File.join(@output, @name + '*.ttf')].first
80
+ @path = file.chomp('.ttf')
81
+
82
+ ['woff','ttf','eot','svg'].each do |type|
83
+ say_status(:create, @path + '.' + type)
84
+ end
85
+ end
86
+
87
+
88
+ def fontface_sources
89
+ order = (options.order) ? options.order.split(",") : ['eot','ttf','woff','svg']
90
+ inline = (options.inline) ? options.inline.split(",") : []
91
+ reorder = {}
92
+ longtype = {
93
+ 'woff' => 'woff',
94
+ 'ttf' => 'truetype',
95
+ 'eot' => 'embedded-opentype',
96
+ 'svg' => 'svg'
97
+ }
98
+
99
+ if(!options.font_path.nil?)
100
+ font_path = (options.font_path) ? options.font_path : ''
101
+ @path = File.join(font_path, File.basename(@path))
102
+ else
103
+ @path = File.basename(@path)
104
+ end
105
+
106
+ @fontface = {
107
+ :eot => "url(\"#{@path}.eot?#iefix\") format(\"embedded-opentype\")",
108
+ :woff => "url(\"#{@path}.woff\") format(\"woff\")",
109
+ :ttf => "url(\"#{@path}.ttf\") format(\"truetype\")",
110
+ :svg => "url(\"#{@path}.svg##{@name}\") format(\"svg\")"
111
+ }
112
+
113
+ # reorder the fontface hash
114
+ order.each do |type|
115
+ if(inline.include?(type))
116
+ fontpath = File.expand_path(File.join(@output, File.basename(@path)+"."+type))
117
+ contents = File.read(fontpath)
118
+ encoded_contents = Base64.encode64(contents).gsub(/\n/, '') # encode and remove newlines, 1.8.7 compat
119
+ fontstring = "url(data:application/x-font-#{type};charset=utf-8;base64," + encoded_contents +") format('#{longtype[type]}')"
120
+ else
121
+ fontstring = @fontface[type.to_sym]
122
+ end
123
+ reorder[type.to_sym] = fontstring
124
+ end
125
+ @fonturls = reorder.map{|k,v| v }.join(",\n");
126
+ end
127
+
128
+
129
+ def create_stylesheet
130
+ say_status(:create, 'creating stylesheet')
131
+ extension = (options.scss) ? '.scss' : '.css'
132
+ files = Dir[File.join(input, '*.{svg,eps}')]
133
+ @classes = files.map {|file| File.basename(file)[0..-5].gsub(/\W/, '-').downcase }
134
+
135
+ template('templates/fontrobot.css', File.join(@output, "fontrobot#{extension}"))
136
+ template('templates/fontrobot-ie7.css', File.join(@output, "fontrobot-ie7#{extension}"))
137
+ template('templates/test.html', File.join(@output, 'test.html')) if options.html
138
+ end
139
+ end
140
+ end