Typography On Web: Cufón And @font-face Resources And Guides

I have always been envious of graphic designer for their ability of using every font they want in their projects, playing with typography and creating beautiful design while I had to limit myself to a few web-safe font families. Although with the appearance of Cufón and @font-face the difference between print typography and web typography didn’t change much, this is still a big step towards the future when, I hope, we can replace all the fonts on a site without overloading the server that’s hosting it or the computer you are using.

There were previous tools with which you could use various fonts on web, tools like sIFR or FLIR but they were pretty difficult to implement, comparing to Cufón or @font-face, and they were loading pretty slow. It’s hard to tell at the moment if another tool like these presented in the article will be invented in the near future and overcome them, but for the moment we can use Cufón and @font-face to make better web typography and I find that a blessing.

Cufón

Cufón aims to become a worthy alternative to sIFR, which despite its merits still remains painfully tricky to set up and use. Cufón consists of two individual parts – a font generator, which converts fonts to a proprietary format and a rendering engine written in JavaScript.

In reality the generator is little more than a web-based interface to FontForge. First, the generator builds a custom FontForge script based on user input and then runs it, saving the result as an SVG font. The SVG font is then parsed and SVG paths are converted to VML paths. This is a crucial step in achieving stellar performance in Internet Explorer, as it supports VML natively. The resulting document is then converted into JSON with a mix of functional JavaScript.

There are several advantages of using Cufón:

  • To include a font, you only need to load it with the standard < script > tag as any other JavaScript file and it will be registered automatically
  • There is no need to manually parse the file on client-side again
  • External JavaScript files block execution until they have loaded, which helps us to achieve a flicker-free, clean replacement
  • It compresses extremely well. While often somewhat large in terms of file size without any compression, a compressed font usually weighs in 60-80% less than the original.


Browser support:

  • Internet Explorer 6, 7 and 8
  • Internet Explorer 9 beta (as of 1.09i)
  • Mozilla Firefox 1.5+
  • Safari 3+
  • Opera 9.5+
  • Google Chrome 1.0+
  • iOS 2.0+
  • Opera Mini (to a certain degree)

How to use Cufón

First, you have to use the Cufón Generator to customize the way the font will render. There are many options from which you can choose so you will find this at least interesting. After you finish the setup you will have a Javascript file which you will include in the HTML along with cufon.js in the head section of the page.

<script src="cufon.js" type="text/javascript"></script>
<script src="Titillium_300.font.js" type="text/javascript"></script>
<script type="text/javascript">
	Cufon.replace('#divname h2');
</script>

There have been reported some problems with Internet Explorer which delays the appearance of the new font, but this can be solved with the following code inserted before the ending of the < body > tag.

<script type="text/javascript"> Cufon.now(); </script>

Styling the font with CSS

The rules that apply to CSS text customizing also apply on Cufón but there are a few things that you must take care of so that the font can be viewed properly.

Because of Internet Explorer’s “awesomeness” the font-style < em > and < i > are reported as normal instead of italic so you have to make sure you set it in the CSS file to be displayed properly.

em, i {
	font-style: italic;
}

For the :hover attribute to work you have to use the following line. It is disabled by default due to performance issues.

Cufon.replace('#divname h2', {
	hover: true
});

By default cufón will only apply :hover effects to links (< a >). You can change this with:

Cufon.replace('#divname h2', {
	hover: true,
	hoverables: { strong: true, em: true }
});

Known bugs

  • Internet Explorer: should you not call Cufon.now() just before the closing tag, there might be a short, visible delay before the text is replaced.
  • Internet Explorer: rgba() is only supported in textShadow.
  • Firefox 1.5: rgba() colors are not supported at all.
  • Opera: Cufon will refuse to load when any of your CSS files is completely empty (0 characters)
  • All browsers: text-align: justify is equal to text-align: left
  • All browsers: line-height may not behave as expected under non-strict doctypes.
  • Google Chrome 1.0: text with opacity of less than 100% may have white edges. This is a known bug in Chromium.
  • text-decoration is not supported.

WordPress plugin

Cufon replacement WordPress plugin

This Plugin makes it easy to implement Cufón into your WordPress Blog. The only thing you have to do is converting your font files and upload them into the plugins font directory. You can enable the objects you want to get replaced in the Admin Menu of your WordPress Blog.

Installation:

  • Upload wp-cufon folder to the /wp-content/plugins/ directory
  • Activate the plugin through the ‘Plugins’ menu in WordPress
  • Convert or get some compatible .font.js fontfiles
  • Create a directory with the name fonts in /wp-content/plugins/
  • Upload your font-files to /wp-content/plugins/fonts/
  • Go to the Settings Page and enter your replacement codes with the “font-family” names of your fonts –> Example: Cufon.replace(‘h1′, { fontFamily: ‘Vegur’ }); –> you can test the free Vegur fontfile from /wp-cufon/example/ – load the file into your external font directory.

Showcase of sites that use Cufón font replacement

adlucent.com

adlucent.com

meinlpercussion.com

meinlpercussion.com

calayuca.com

calayuca.com

lasttweet.com

lasttweet.com

luckyny.com

luckyny.com

squiid.com

squiid.com

zendesk.com

zendesk.com

34one.com

34one.com

rutmfl.se

rutmfl.se

dailydesigninspiration.com

dailydesigninspiration.com

thevisualclick.com

thevisualclick.com

donttalktorobots.com

donttalktorobots.com

@font-face

@font-face is a CSS rule which allows you to download a particular font from your server to render a webpage if the user hasn’t got that font installed. This means that web designers will no longer have to adhere to a particular set of “web safe” fonts that the user has pre-installed on their computer.

How to use

To use @font-face is even easier than Cufón or the old sIFR or FLIR. First, you have to define the rule in CSS, “font-family” is what you want to call the font, “src” is where it can be found, include a “font-weight” (not needed for normal, but required by everything else, bold, thin etc).

@font-face {
    font-family: DeliciousRoman;
    src: url(http://www.font-face.com/fonts/delicious/Delicious-Roman.otf);
    font-weight:400;
}

And after this you simply use it like any other font-family that you used before.

p {
    font-family: DeliciousRoman, Helvetica, Arial, sans-serif;
}

However, every browser has its own font format that is accepted, IE supports only EOT, Firefox supports OTF and TTF, Chrome supports TTF and SVG, Safari and Opera support OTF, TTF and SVG so in order to be sure that your font will be displayed correctly you will have to use a bulletproof @font-face syntax like the people from Fontspring have named it:

@font-face {
	font-family: 'MyFontFamily';
	src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'), 
	     url('myfont-webfont.woff') format('woff'), 
	     url('myfont-webfont.ttf')  format('truetype'),
	     url('myfont-webfont.svg#svgFontName') format('svg');
	}

In case you want to lower the server memory usage, you can use Google Font API with which you can choose a font from the Google font directory and insert it basically the same way as you would if you would have hosted the font on your domain.

<link href='http://fonts.googleapis.com/css?family=Bowlby+One+SC&v1' rel='stylesheet' type='text/css'>
<!-- 

-->

And then add it to the div you wanted to use this font with

#sidebar h2 {
    font-family: Bowlby One SC, Helvetica, Arial, sans-serif;
}

In case you want to use more than one font from the Google font directory on the same page, load them in the same line, instead of multiple ones.

<link href='http://fonts.googleapis.com/css?family=Forum&v1:b,bi|Varela&v1:i|Redressed&v1' rel='stylesheet' type='text/css'>
<!-- Where "b" stands for bold, "bi" for bold-italic and "i", of course, 
for italic. These shortcodes can be used if you want to have the bold 
or italic versions of the font on your site. -->

Showcase of sites using @font-face

reallysimpleworks.com

reallysimpleworks.com

kunalchhajer.com

kunalchhajer.com

pumpkin-king.com

pumpkin-king.com

auxiliumlab.it

auxiliumlab.it

seosara.com

seosara.com

html5boilerplate.com

html5boilerplate.com

coucoushop.ch

coucoushop.ch

lostworldsfairs.com/atlantis

lostworldsfairs.com/atlantis

vayknights.co.uk

vayknights.co.uk

wearefixel.com

wearefixel.com

themeskingdom.com

themeskingdom.com

html5lab.pl

html5lab.pl

mobilezr.com

mobilezr.com

singleframedesign.co.uk

singleframedesign.co.uk

fireballdesign.co.uk

fireballdesign.co.uk

studioadam.be

studioadam.be

yebocreative.com

yebocreative.com

proov.fr

proov.fr

thrivesolo.com

thrivesolo.com

davidhellmann.com

davidhellmann.com

circle.co.ke

circle.co.ke

Copyright issues with Cufón and @font-face

Although you may have thought that you have been blessed by God with these tools, there are certain copyright issues that you have to be aware of. A lot of the fonts you would want to use have licenses, even the ones that are labeled free, and those licenses don’t allow you to embed the fonts on your websites.

However, there are a few Fonts you can embed freely:

Delicious

Delicious

Dekar

Dekar

League Gothic

League Gothic

Sertig

Sertig

Cicle

Cicle

Anivers

Anivers

Prociono

Prociono

Fertigo Pro

Fertigo Pro

Hattori Hanzo

Hattori Hanzo

Raleway

Raleway

Tallys

Tallys

Jura

Jura

Telegrafico

telegrafico

Museo Sans

Museo Sans

CA BND Bold WEB

CA BND Bold WEB

Ripe

Ripe

Bebas

Bebas

Junction

Junction

Code

Code

Chunk

Chunk

Quicksand

Quicksand

Kilogram

Kilogram

Nevis

Nevis

St Marie

St Marie

FRANCHISE

FRANCHISE

Further resources