Evangelism/Firefox3.6/WOFF: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{draft}}
== Introducing support for the WOFF font format ==
 
Support for the CSS @font-face rule was introduced in Firefox 3.5, a way of linking directly to TrueType and OpenType fonts.  For Firefox 3.6, support for the WOFF font format has been added.  The WOFF (Web Open Font Format) format is a simple way of packaging fonts for the web, the fonts are compressed so they are typically smaller than directly linked OpenType or TrueType fonts.


== Introducing support for the WOFF font format ==
The WOFF format originated from a collabaration between the font designers Erik van Blokland and Tal Leming and Mozilla's Jonathan Kew.  Each had proposed their own format and WOFF represents a melding of these different proposals.  The  [http://people.mozilla.com/~jkew/woff/woff-spec-latest.html format itself] is intended to be a simple repackaging of OpenType or TrueType font data, it doesn't introduce any new behavior, alter the @font-face linking mechanism or affect the way fonts are rendered.  Many font vendors have [http://typegirl.tumblr.com/post/142912558/most-of-the-important-foundries-are-supporting-webfont expressed support for this new format] so the hope is this will open up a wider range of font options for web designers.


Support for the CSS @font-face rule was introduced in Firefox 3.5, a way of linking directly to TrueType and OpenType fonts.  For Firefox 3.6, support for the WOFF font format has been addedThe WOFF format is a simple way of packaging fonts for the web, the fonts are compressed so they are typically smaller than directly linked OpenType or TrueType fonts.
Compression is part of the WOFF format so web authors can optimize the size
of fonts used on their pages. The compression format is lossless, the uncompressed font data will match that of the original OpenType or TrueType font, so the way the font renders will be the same as the originalSimilar compression can be achieved using general HTTP compression but because compression is part of the WOFF format, it's simpler for authors to use, especially in situations where access to server configuration is not possible.


The WOFF format originated from a collabaration between the font designers Erik van Blokland and Tal Leming and Mozilla's Jonathan Kew.  Each had proposed their own format and WOFF represents a melding of these different proposalsThe  [http://people.mozilla.com/~jkew/woff/woff-spec-latest.html format itself] is intended to be a simple repackaging of OpenType or TrueType font data, it doesn't introduce any new behavior, alter the @font-face linking mechanism or affect the way fonts are rendered.
The format includes optional metadata so that a font vendor can tag their fonts with information related to font usageThis metadata doesn't affect how fonts are loaded but tools can use this information to identify the source of a given font, so that those interested in the design of a given page can track down the fonts used on that page.  Fonts in WOFF format are compressed but are not encrypted, the format should not be viewed as a “secure” format by those looking for a mechanism to strictly regulate and control font use.


The format includes optional metadata so that a font vendor can tag their fonts with information related to their use. This metadata doesn't affect how fonts are loaded but tools can use this information to identify the source of a given font, so that those interested in the design of a given page can track down the fonts used on that page.  Fonts in WOFF format are compressed but are not encrypted, the format should not be viewed as a "secure" format by those looking for a mechanism to strictly regulate and control the use of their fonts.
Note: until Firefox 3.6 ships, users can test the use of WOFF fonts with Firefox [http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/ nightly builds].


== Examples ==
== Examples ==


Below is a simple example that shows how to construct an @font-face rule that links to a WOFF font.  To support browsers that only support direct linking to OpenType and TrueType fonts, the <code>'src'</code> descriptor lists the WOFF font first along with a format hint (<code>"woff"</code>), followed by the TrueType version.  Structured this way, browsers that support the WOFF format will download the WOFF file and browsers that don't will download the TrueType version.
Below is a simple example that shows how to construct an @font-face rule that links to a WOFF font.  To support browsers that only support direct linking to OpenType and TrueType fonts, the <code>'src'</code> descriptor lists the WOFF font first along with a format hint (<code>"woff"</code>), followed by the TrueType version:


<pre>
<pre>
Line 26: Line 29:
</pre>
</pre>


As rendered:
Structured this way, browsers that support the WOFF format will download the WOFF file.  Other browsers that support @font-face but don't yet support the WOFF format will use the TrueType version.  (Note: IE support is a bit trickier, as discussed below). As WOFF is adopted more widely the need to include links to multiple font formats will diminish.


[[File:Gentiumtest.png|center|link=http://people.mozilla.org/~jdaggett/webfonts/gentium-test.html|Simple cross-browser test]]
[[File:Gentiumtest.png|center|link=http://people.mozilla.org/~jdaggett/webfonts/gentium-test.html|Simple cross-browser test]]
Other examples below demostrate the use of WOFF formatted fonts but each example has been constructed so that it will work in any browser that supports @font-face, including Internet Explorer.


=== A font family with multiple faces ===
=== A font family with multiple faces ===
Line 38: Line 44:


[[File:Chunkfivetest.png|center|link=http://people.mozilla.org/~jdaggett/webfonts/chunkfive-test.html|Using a Postscript CFF (.otf) font]]
[[File:Chunkfivetest.png|center|link=http://people.mozilla.org/~jdaggett/webfonts/chunkfive-test.html|Using a Postscript CFF (.otf) font]]
=== African Language Display ===
Below is an example of how downloadable fonts can be used to render languages for which font support is usually lacking.  The example shows the UN Declaration of Human Rights, translated into two African languages, and how these render with default browser fonts vs. with a downloadable font suited for rendering these languages:
[[File:Charissiltest.png|center|link=http://people.mozilla.com/~jkew/woff/udhr-sample/|African Language Display]]




Line 54: Line 67:
Firefox 3.6 will be the first shipping browser to support the WOFF format so it's important to construct @font-face rules that work with browsers lacking WOFF support.  One thing that helps greatly with this is the use of format hints to indicate the format of font data before it's downloaded; browsers that don't recognize a given format simply skip data in a format they don't support.
Firefox 3.6 will be the first shipping browser to support the WOFF format so it's important to construct @font-face rules that work with browsers lacking WOFF support.  One thing that helps greatly with this is the use of format hints to indicate the format of font data before it's downloaded; browsers that don't recognize a given format simply skip data in a format they don't support.


Internet Explorer, including IE8, only support the EOT font format and only implements a subset of the @font-face rule descriptors.  This makes creating cross-platform @font-face rules that work with IE especially tricky.  See Paul Irish's blog post for [http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/ one interesting technique].
Internet Explorer, including IE8, only supports the EOT font format and only implements a subset of the @font-face rule descriptors.  This makes creating cross-platform @font-face rules that work with IE especially tricky.  One solution is to make different rules for IE:
 
<pre>
@font-face {
  font-family: GentiumTest;
  src: url(fonts/GenR102.eot);  /* for IE */
}
 
@font-face {
  font-family: GentiumTest;
  src: url(fonts/GenR102.woff) format("woff"); /* WOFF-enabled browsers */
}
</pre>


Note: until Firefox 3.6 ships, users can test the use of WOFF fonts with Firefox [http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/ nightly builds].
One minor downside of this is that IE doesn't understand format hints and doesn't parse @font-face URL's correctly, it treats format hints as part of the URL, so web authors using the @font-face rules above will see the following in their access logs:
 
<pre>
GET /fonts/GenR102.eot HTTP/1.1" 200 303536
GET /fonts/GenR102.woff)%20format(%22woff%22) HTTP/1.1" 404 335
</pre>


== Future Work ==
IE successfully pulls down and uses the EOT version of the font but also tries to pull down the WOFF font with the format hint included in the URL.  This fails and doesn't affecting page rendering but it wastes valuable server resources.  For more discussion, see Paul Irish's blog post for [http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/ one interesting workaround].


OpenType features, support for unicode-range and improved ClearType rendering.
Another problem is that IE currently tries to download <strong>all</strong> fonts on the page, whether they are used or not.  That makes site-wide stylesheets containing all fonts used on site pages difficult, since IE will always try to download all fonts defined in @font-face rules, wasting lots of server bandwidth.


== Further Resources ==
== Further Resources ==
Line 67: Line 97:
* [http://people.mozilla.com/~jkew/woff/woff-spec-latest.html Latest draft WOFF specification]
* [http://people.mozilla.com/~jkew/woff/woff-spec-latest.html Latest draft WOFF specification]
* [http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/ Original blog post on using @font-face]
* [http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/ Original blog post on using @font-face]
* [http://dev.w3.org/csswg/css3-fonts/ CSS3 Fonts draft]
* [http://dev.w3.org/csswg/css3-fonts/ CSS3 Fonts working draft]
* [https://developer.mozilla.org/en/CSS/@font-face MDC @font-face documentation]
* [https://developer.mozilla.org/en/CSS/@font-face MDC @font-face documentation]


=== Tools ===
=== Tools ===
*
* [http://people.mozilla.com/~jkew/woff/woff-code-latest.zip Jonathan Kew's sample encoding/decoding code]
* [http://sourceforge.net/projects/fonttools/ FontTools/TTX - Python scripts for displaying font data]
* [http://code.typesupply.com/wiki/woffTools woffTools - tools for examining and validating WOFF files]
* [http://sourceforge.net/projects/fonttools/ FontTools/TTX - Python library and tool for manipulating font data]
* [http://fonts.philip.html5.org/ Web-based font subsetting tool]


=== Examples ===
=== General @font-face Examples ===
* [http://www.alistapart.com/articles/cssatten CSS @ Ten: The Next Big Thing]
* [http://www.alistapart.com/articles/cssatten CSS @ Ten: The Next Big Thing]
* [http://nicewebtype.com/fonts/graublau-sans-web/ Example layout using Graublau Sans]
* [http://nicewebtype.com/fonts/graublau-sans-web/ Example layout using Graublau Sans]
Line 83: Line 115:
* [http://www.fontsquirrel.com/ Font Squirrel]
* [http://www.fontsquirrel.com/ Font Squirrel]
* [http://opentype.info/demo/webfontdemo.html 10 Great Free Fonts for @font-face]
* [http://opentype.info/demo/webfontdemo.html 10 Great Free Fonts for @font-face]
* [http://fonts.philip.html5.org/ Web-based font subsetting tool]
* [http://www.smashingmagazine.com/2007/11/08/40-excellent-freefonts-for-professional-design/ 40 Excellent Free Fonts by Smashing Magazine]
* [http://www.smashingmagazine.com/2007/11/08/40-excellent-freefonts-for-professional-design/ 40 Excellent Free Fonts by Smashing Magazine]

Latest revision as of 01:45, 19 October 2009

Introducing support for the WOFF font format

Support for the CSS @font-face rule was introduced in Firefox 3.5, a way of linking directly to TrueType and OpenType fonts. For Firefox 3.6, support for the WOFF font format has been added. The WOFF (Web Open Font Format) format is a simple way of packaging fonts for the web, the fonts are compressed so they are typically smaller than directly linked OpenType or TrueType fonts.

The WOFF format originated from a collabaration between the font designers Erik van Blokland and Tal Leming and Mozilla's Jonathan Kew. Each had proposed their own format and WOFF represents a melding of these different proposals. The format itself is intended to be a simple repackaging of OpenType or TrueType font data, it doesn't introduce any new behavior, alter the @font-face linking mechanism or affect the way fonts are rendered. Many font vendors have expressed support for this new format so the hope is this will open up a wider range of font options for web designers.

Compression is part of the WOFF format so web authors can optimize the size of fonts used on their pages. The compression format is lossless, the uncompressed font data will match that of the original OpenType or TrueType font, so the way the font renders will be the same as the original. Similar compression can be achieved using general HTTP compression but because compression is part of the WOFF format, it's simpler for authors to use, especially in situations where access to server configuration is not possible.

The format includes optional metadata so that a font vendor can tag their fonts with information related to font usage. This metadata doesn't affect how fonts are loaded but tools can use this information to identify the source of a given font, so that those interested in the design of a given page can track down the fonts used on that page. Fonts in WOFF format are compressed but are not encrypted, the format should not be viewed as a &#147;secure&#148; format by those looking for a mechanism to strictly regulate and control font use.

Note: until Firefox 3.6 ships, users can test the use of WOFF fonts with Firefox nightly builds.

Examples

Below is a simple example that shows how to construct an @font-face rule that links to a WOFF font. To support browsers that only support direct linking to OpenType and TrueType fonts, the 'src' descriptor lists the WOFF font first along with a format hint ("woff"), followed by the TrueType version:

/* Gentium (SIL International) */

@font-face {
  font-family: GentiumTest;
  src: url(fonts/GenR102.woff) format("woff"), url(fonts/GenR102.ttf) format("truetype");
}

body {
  font-family: GentiumTest, Times, Times New Roman, serif;
}

Structured this way, browsers that support the WOFF format will download the WOFF file. Other browsers that support @font-face but don't yet support the WOFF format will use the TrueType version. (Note: IE support is a bit trickier, as discussed below). As WOFF is adopted more widely the need to include links to multiple font formats will diminish.

Simple cross-browser test

Other examples below demostrate the use of WOFF formatted fonts but each example has been constructed so that it will work in any browser that supports @font-face, including Internet Explorer.


A font family with multiple faces

Family with multiple faces


Using a Postscript CFF font

Using a Postscript CFF (.otf) font


African Language Display

Below is an example of how downloadable fonts can be used to render languages for which font support is usually lacking. The example shows the UN Declaration of Human Rights, translated into two African languages, and how these render with default browser fonts vs. with a downloadable font suited for rendering these languages:

African Language Display


Another Postscript CFF font

Another Postscript CFF (.otf) font


An example in Japanese

With a Japanese font


Working With Other Browsers

Firefox 3.6 will be the first shipping browser to support the WOFF format so it's important to construct @font-face rules that work with browsers lacking WOFF support. One thing that helps greatly with this is the use of format hints to indicate the format of font data before it's downloaded; browsers that don't recognize a given format simply skip data in a format they don't support.

Internet Explorer, including IE8, only supports the EOT font format and only implements a subset of the @font-face rule descriptors. This makes creating cross-platform @font-face rules that work with IE especially tricky. One solution is to make different rules for IE:

@font-face {
  font-family: GentiumTest;
  src: url(fonts/GenR102.eot);  /* for IE */
}

@font-face {
  font-family: GentiumTest;
  src: url(fonts/GenR102.woff) format("woff"); /* WOFF-enabled browsers */
}

One minor downside of this is that IE doesn't understand format hints and doesn't parse @font-face URL's correctly, it treats format hints as part of the URL, so web authors using the @font-face rules above will see the following in their access logs:

GET /fonts/GenR102.eot HTTP/1.1" 200 303536
GET /fonts/GenR102.woff)%20format(%22woff%22) HTTP/1.1" 404 335

IE successfully pulls down and uses the EOT version of the font but also tries to pull down the WOFF font with the format hint included in the URL. This fails and doesn't affecting page rendering but it wastes valuable server resources. For more discussion, see Paul Irish's blog post for one interesting workaround.

Another problem is that IE currently tries to download all fonts on the page, whether they are used or not. That makes site-wide stylesheets containing all fonts used on site pages difficult, since IE will always try to download all fonts defined in @font-face rules, wasting lots of server bandwidth.

Further Resources

Documentation

Tools

General @font-face Examples

Font Resources