AceLewis/fontcrusher

Impossible to make it work

Closed this issue · 5 comments

This is really not easy to use for people who don't do python all day

It seems like it's made for windows at first sight so I tried to make it work but:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python3.4/site-packages/fontcrusher/find_used_glyphs.py", line 43, in find_used_glyphs
    for file in glob.iglob(include_arg[0], **include_arg[1]):
TypeError: iglob() got an unexpected keyword argument 'recursive'

Now i'm trying to make the example.py work but the path is wrong ofc

I try to edit this but no idea what it means: include_argument = [[r'./website_folder/**\*', {'recursive': True}]]

Then:

Traceback (most recent call last):
  File "example.py", line 17, in <module>
    used_glyphs = find_used_glyphs.find_used_glyphs(include_argument, regex_for_find, exclude_args=exclude_arg)
  File "/home/user/.local/lib/python3.4/site-packages/fontcrusher/find_used_glyphs.py", line 43, in find_used_glyphs
    for file in glob.iglob(include_arg[0], **include_arg[1]):
TypeError: iglob() got an unexpected keyword argument 'recursive'

So I removed , {'recursive': True} and got:

FFTM NOT subset; don't know how to subset; dropped

If you update, plz notify me :)

This is because recursive globs is a Python 3.5+ feature. You can not use the recursive by omitting it however it will not recursively search the directories.

Ok, so I just need to try with python 3.5, I just fear i'm gonna break everything by updating python on linux :(

Don't update the system version of Python, use pyenv. Also the recursive feature is for scanning directories and sub directories for the font icons that are used in the project. If you have a few directories then you can just list all of them in include_argument.

Ok, I installed python 3.5.6 with pyenv locally (in the example.py directory)

python -V                                                                                                                          43ms|17:50:24
Python 2.7.6

Then I modified the example.py with:

"""
I think this example code very quickly explains how this modlue can be used and
can serve as a cookie cutter code that you can copy and paste.
"""

import fontcrusher
from fontcrusher import find_used_glyphs, get_glyph_name, css_crush

# Load in font and CSS file for font
font_object = fontcrusher.load_the_font(r'./website_folder/fontawesome-webfont.ttf')
css_file = css_crush.read_file(r'./website_folder/font-awesome.min.css')

# Find all glyphs used in website
regex_for_find = find_used_glyphs.get_regex_for_glyph('font_awesome')
include_argument = [[r'./website_folder/**/*', {'recursive': True}]]
exclude_arg = [[r'./website_folder/subdirectory/exclude_file.txt']]
used_glyphs = find_used_glyphs.find_used_glyphs(include_argument, regex_for_find, exclude_args=exclude_arg)

# Find the unicode values of those glyphs and use unicode value to get glyph name
unicode_values = get_glyph_name.get_unicode_value_list('fa', used_glyphs, css_file).values()
glyph_names = get_glyph_name.get_glyph_name_list(font_object, unicode_values).values()

# create a new font object with only the glyphs used in the website
crushed_font = fontcrusher.crush_font(font_object, glyph_names)
# Remove all CSS atributed for unneeded glyphs
crushed_css = css_crush.remove_glyphs_from_css(css_file, 'font_awesome', used_glyphs)

# Save the crushed font and save the crushed CSS
crushed_font.save(r'./website_folder/fontawesome-webfont.crushed.ttf')
css_crush.write_file(r'./website_folder/font-awesome.crushed.css', crushed_css)

# To save a woff font
crushed_font.flavor = 'woff'
crushed_font.save(r'./website_folder/fontawesome-webfont.crushed.woff')

Then I installed with pip install fontcrusher

Then I got this error:

python example.py                                                                                                                 578ms|17:51:31
FFTM NOT subset; don't know how to subset; dropped

However I got this in the repo:

	modified:   website_folder/font-awesome.crushed.css
	modified:   website_folder/fontawesome-webfont.crushed.ttf
	modified:   website_folder/fontawesome-webfont.crushed.woff

It reduced files size to 900 bytes instead of 3.5kb, and I realized you had already provided the crushed files. Then I retried from 0 and it made them bigger, well that was weird. Basically the result is different from your results in the readme @AceLewis

So, what do?