Skip to content

Commit

Permalink
Works with Windows. (#289)
Browse files Browse the repository at this point in the history
* works on windows
* updated readme
  • Loading branch information
jdell64 authored and JakeBeresford committed Jun 12, 2017
1 parent a5ed696 commit dfbb108
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ wget http://people.mozilla.com/~jkew/woff/woff-code-latest.zip
unzip woff-code-latest.zip -d sfnt2woff && cd sfnt2woff && make && sudo mv sfnt2woff /usr/local/bin/
gem install fontcustom
```
####Note for windows:

1. Install fontforge: http://fontforge.github.io/en-US/downloads/windows/
- Install to a path without spaces, eg c:\FontForgeBuilds
- At the end of the installer check the 'run fontforge' box. It finishes some set up.
2. Add the installation path to your System PATH variable (c:\FontForgeBuilds\bin)
3. Open up a new command prompt and test it. `fontforge -help`
4. gem install fontcustom


### Quick Start

Expand Down Expand Up @@ -66,6 +75,77 @@ compatible font-url() helper. You'll most likely also need to set
`preprocessor_path` as the relative path from your compiled CSS to your output
directory.

**Example Use in Rails**

Add `gem 'fontcustom'` to your gem file.
```
bundle
```
Create a `fontcustom.yml` file with something like this:
```yml
# config/fontcustom.yml

font_name: icons
css_selector: .icon-{{glyph}}
preprocessor_path: ""
autowidth: false
no_hash: true
force: false
debug: false
quiet: false

input:
vectors: app/assets/icons

output:
fonts: app/assets/fonts
css: app/assets/stylesheets

templates:
- scss
```
This tells the gem to take the vectors from `app/assets/icons` and create fonts and stylesheets for them.

Create a file in lib/tasks called `icons.rake` :

```ruby
namespace :icons do
task :compile do
puts "Compiling icons..."
puts %x(fontcustom compile)
end
end
```

Load up the icons directory and test it out.

Run this command with
```sh
rake icons:compile
```

This should run the installed and configured gem to create your icons:

```sh
Compiling icons...
create .fontcustom-manifest.json
create app/assets/fonts
create app/assets/fonts/icons.ttf
app/assets/fonts/icons.svg
app/assets/fonts/icons.woff
app/assets/fonts/icons.eot
create app/assets/stylesheets/_icons.scss
```
Access these new icons by creating a tag with the class `icon-{{glyph}}` where the {{glyph}} is the name of the svg you put in the icon folder.
For example, if you added a file called 'cars54' icon would look something like this:

```html
<i class="icon-cars54"</i>
```

Now the font is adjustable to css 'font-size' and 'color'.

**Save CSS and fonts to different locations**

You can save generated fonts, CSS, and other files to different locations by
Expand Down
6 changes: 5 additions & 1 deletion lib/fontcustom/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def compile
private

def check_fontforge
fontforge = `which fontforge`
if !Gem.win_platform?
fontforge = `which fontforge`
else
fontforge = `where fontforge`
end
if fontforge == "" || fontforge == "fontforge not found"
raise Fontcustom::Error, "Please install fontforge first. Visit <http://fontcustom.com> for instructions."
end
Expand Down
12 changes: 10 additions & 2 deletions lib/fontcustom/scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def createGlyph( name, source, code ):
# Convert WOFF
scriptPath = os.path.dirname(os.path.realpath(__file__))
try:
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
# check if on windows
if os.name == 'nt':
subprocess.Popen([scriptPath + '/sfnt2woff.exe', fontfile + '.ttf'], stdout=subprocess.PIPE)
else:
subprocess.Popen([scriptPath + '/sfnt2woff', fontfile + '.ttf'], stdout=subprocess.PIPE)
except OSError:
# If the local version of sfnt2woff fails (i.e., on Linux), try to use the
# global version. This allows us to avoid forcing OS X users to compile
Expand All @@ -123,7 +127,11 @@ def createGlyph( name, source, code ):

# Convert EOT for IE7
subprocess.call('python ' + scriptPath + '/eotlitetool.py ' + fontfile + '.ttf -o ' + fontfile + '.eot', shell=True)
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
# check if windows
if os.name == 'nt':
subprocess.call('move ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
else:
subprocess.call('mv ' + fontfile + '.eotlite ' + fontfile + '.eot', shell=True)
manifest['fonts'].append(fontfile + '.eot')

finally:
Expand Down
Binary file added lib/fontcustom/scripts/sfnt2woff.exe
Binary file not shown.

0 comments on commit dfbb108

Please sign in to comment.