Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating icon fonts with vector software (i.e. inkscape) and fontforge?

Through getting some answers here and some research, I've come across a new approach to implementing icons. Rather than as images or css background, it seems you can approach icons as a font.

Will this method ultimately mean creating a one file font set that has each icon assigned to a character? Because this method is so new to me I really want to sure I approach it correctly first (I see great potential... so much better than creating different icons, exporting each as it's own .png file for every different color and size).

If that's the case, it'll take a bit of memorization (especially since I have over 26 icons). For those more experienced with fontforge, is there a way to say a specific word = character?

Also, in regards to implementing this on the website. I would then need to specify the font type within the css class/id (i.e. font=icons; ). And then I could change the size, color, etc. with css as well? Man, if this really is true. I wish I found out earlier... hours and hours could have been saved.

Anyway, any help with this is greatly appreciated. I'm about to get fontforge and start learning (if there's better free software for font creation, let me know). Hopefully this works out.

like image 770
jstacks Avatar asked Sep 09 '12 03:09

jstacks


People also ask

Which is better SVG or font icons?

Accessibility One major advantage of SVG icons over Icon fonts is their superior accessibility. SVGs are armed with built in semantic elements – like < title > and < desc > that makes it accessible to screen reader and text browsers. Unlike icon fonts, SVGs are treated as an image and not as a text.

How do I add glyphs to FontForge?

Select Encoding > Add Encoding Slots and enter the number of the glyphs you want — in this case, 3. FontForge will add the same number of slots at the very end of the font, and you will be moved there in the font chart.


2 Answers

I've successfully created a few icon fonts for my websites and the Inkscape FontForge approach as outlined in this how-to is pretty solid, and if you're used to using software such as Inkscape, it's also pretty easy too. Here's the steps I take:

Preparation (using Inkscape in this example)

  1. Open the Inkscape document that holds your designs.
  2. Make sure you've converted all shapes, type and lines to paths and check your drawing in outline mode to be sure. If there are problems, you can always refer back to this base file to make initial changes to the shapes.
  3. Create a new document by selecting New > fontforge_glyph.
  4. Paste an icon from your design into the new document.
  5. Resize the icon to fit the space provided (although it may be best you resize all icons in the original design document first - up to you).
  6. Centre the icon on the page using the Align tool (if appropriate).
  7. Save the drawing as a plain SVG (it's easier if you title according to the letter to be assigned eg. "j.svg").
  8. Repeat for other icons.

I'll often leave this plain SVG document open, pasting in new icons and centering and sizing according to the last. This way there is size and position consistency across the icon set (and you don't have to keep choosing the directory to save your plain SVGs).


Glyph creation (using FontForge)

  1. Once you've made an SVG file for each icon, open FontForge and create a new FontForge document.
  2. In the main glyph display list window, double-click one of the letters/numbers you have an icon for.
  3. In this new glyph window, choose File > Import and select one of your SVG files (you'll probably need to change the file filter in the file dialogue to show SVG files).
  4. If the import registers errors and the wireframe looks like its suffered a mild explosion, you'll need to go back to Inkscape to sort out the path. There's an easy way to find out the problem that should work in most cases:
  • In Inkscape, remove the fill of the icon. * Add a thin stroke (1px will do). * Convert the stroke to a path. * The resulting shape will probably be missing a part of your icon. * Undo all, then break icon apart and redraw/trace/correct the problem area.

Font creation (using FontForge)

  1. Back in FontForge, once you've added all of your icons, you need to give your typeface a name. In the main window, select Element > Font info.
  2. Change the following:
  • Fontname: MyFontMedium * Family name: My Font * Name for humans: My Font Medium * Weight: Book (Win XP thinks medium = bold, so best to use Book)
  1. In the main window, choose File > Generate Fonts and save to TrueType (ignoring any errors).

Font validation/conversion

  1. Go to www.fontsquirrel.com/fontface/generator or a similar service to upload your TTF file and get it converted (and corrected)
  2. The zip file you download will contain precise instructions on how to implement the fonts into your web project.

Hope that's of help.

like image 186
wayfarer_boy Avatar answered Nov 10 '22 14:11

wayfarer_boy


Here's an open source example of what you're looking to do:

http://fortawesome.github.com/Font-Awesome/

If you look at their code, you can see how to run the CSS:

https://github.com/FortAwesome/Font-Awesome/blob/master/css/font-awesome.css

And if you want to edit the fonts, download FontAwesome.ttf and edit in FontForge. If you want to do your own TTF, you could, but just take a look and copy how they did it I guess.

(Disclaimer: I haven't done this part of the process. On our team one of the guys uses a proprietary Mac App to come up with the font. If I need to do my own icon fonts in future I'll probably use Inkscape and FontForge though. I've checked enough to see that FontForge can import SVG, I haven't tried it though).

When you're done and you have your TTF font as you want it, you need to convert the font into the many different formats needed to use as a web font. I use this free online tool:

http://fontface.codeandmore.com/

... which will give you your EOT, SVG, TTF and WOFF font files, which should cover you for almost all browsers. You then need to include these files in your CSS, as demonstrated in the file linked above. Note: for the SVG file, there is an ID that you will have to update. I think it is automatically chosen by the conversion tool, so you'll have to edit the SVG, check what the ID is and include it.

For example, in this code:

@font-face {   font-family: 'MyIcons';   src: url('myiconfont-iconglyphs.eot');   src: url('myiconfont-iconglyphs.eot#iefix') format('embedded-opentype'),        url('myiconfont-iconglyphs.woff') format('woff'),        url('myiconfont-iconglyphs.ttf')  format('truetype'),        url('myiconfont-iconglyphs.svg#myiconfont-regular') format('svg');   font-weight: normal;   font-style: normal; } 

You may have to change the #myiconfont-regular bit after the svg definition.

like image 34
Jason O'Neil Avatar answered Nov 10 '22 15:11

Jason O'Neil