Evangelism/Firefox3.5/35Days/Articles/@font-face: Difference between revisions

m
very light copy-editing, great article
No edit summary
m (very light copy-editing, great article)
 
Line 1: Line 1:
== Introducing <code>@font-face</code> ==
== Introducing <code>@font-face</code> ==


Firefox 3.0 improved typographic rendering by introducing support for kerning, ligatures, multiple weights, along with support for rendering complex scripts.  But authors are still limited to using commonly available fonts in their designs.  Firefox 3.5 removes this restriction by introducing support for the CSS @font-face rule, a way of linking to TrueType and OpenType fonts just as code and images are linked to today.  Safari since version 3.1 supports this type of font linking and Opera has announced planned support in Opera 10.
While Firefox 3.0 improved typographic rendering by introducing support for kerning, ligatures, and multiple weights along with support for rendering complex scripts, authors are still limited to using commonly available fonts in their designs.  Firefox 3.5 removes this restriction by introducing support for the CSS @font-face rule, a way of linking to TrueType and OpenType fonts just as code and images are linked to today.  Safari has supported this type of font linking since version 3.1, and Opera has announced that they plan to support it in Opera 10.


Using @font-face for font linking is relatively straightforward.  Within a stylesheet, each @font-face rule defines a family name to be used, the font resource to be loaded and the style characteristics of a given face such as whether it's bold or italic.  Firefox 3.5 only downloads the fonts as needed, so a stylesheet can list a whole set of fonts of which only a select few will actually be used.
Using @font-face for font linking is relatively straightforward.  Within a stylesheet, each @font-face rule defines a family name to be used, the font resource to be loaded, and the style characteristics of a given face such as whether it's bold or italic.  Firefox 3.5 only downloads the fonts as needed, so a stylesheet can list a whole set of fonts of which only a select few will actually be used.


<pre>
<pre>
Line 24: Line 24:
== Digging A Little Deeper ==
== Digging A Little Deeper ==


Most font families today consist of only four faces, regular, bold, italic and bold italic.  To define each of these faces the <code>font-weight</code> and <code>font-style</code> descriptors are used.  These define the style of the face; there's no concept of a cascade or inheritance that applies here.  Without an explicit definition each of these defaults to a value of 'normal':
Most font families today consist of only four faces: regular, bold, italic and bold italic.  To define each of these faces the <code>font-weight</code> and <code>font-style</code> descriptors are used.  These define the style of the face; there's no concept of a cascade or inheritance that applies here.  Without an explicit definition each of these defaults to a value of 'normal':


<pre>
<pre>
Line 49: Line 49:
[[File:Multiplefaces.png|center|link=http://people.mozilla.org/~jdaggett/demos/multiplefaces.html|Font family with multiple styles]]
[[File:Multiplefaces.png|center|link=http://people.mozilla.org/~jdaggett/demos/multiplefaces.html|Font family with multiple styles]]


A feature that's easy to overlook is that @font-face allows the creation of families with more than just regular and bold faces, up to nine weights can be defined for a single family.  This is true even on Windows, where underlying platform limitations usually restrict font families to just regular and bold weights.  Fonts such as those of the Japanese open source [http://mplus-fonts.sourceforge.jp M+ Fonts project] have as many as seven weights.  A selection of these are used in the [http://people.mozilla.org/~jdaggett/demos/multipleweights.html sample] below:
A feature that's easy to overlook is that @font-face allows the creation of families with more than just regular and bold faces -- up to nine weights can be defined for a single family.  This is true even on Windows, where underlying platform limitations usually restrict font families to just regular and bold weights.  Fonts such as those of the Japanese open source [http://mplus-fonts.sourceforge.jp M+ Fonts project] have as many as seven weights.  A selection of these are used in the [http://people.mozilla.org/~jdaggett/demos/multipleweights.html sample] below:


[[File:Multipleweights.png|center|link=http://people.mozilla.org/~jdaggett/demos/multipleweights.html|Font family with multiple weights]]
[[File:Multipleweights.png|center|link=http://people.mozilla.org/~jdaggett/demos/multipleweights.html|Font family with multiple weights]]
Line 81: Line 81:
[[File:Macwinlinrendering.png|center|link=http://people.mozilla.org/~jdaggett/demos/localfallback.html| Use of local() for linking to local fonts]]
[[File:Macwinlinrendering.png|center|link=http://people.mozilla.org/~jdaggett/demos/localfallback.html| Use of local() for linking to local fonts]]


The Helvetica Neue font family is available on most Mac OS X systems but generally not on either Windows or Linux machines.  When the example here is rendered on Mac OS X, the local Helvetica Neue faces are used and no font is downloaded.  Under Windows and Linux the attempt to load a local face fails and a substitute font, MgOpen Moderna is downloaded and used instead.  MgOpen Moderna is intended to be a substitute for Helvetica, hence it renders similar to Helvetica Neue.  So an author can guarantee text appearance but avoid a font download when it's not necessary.
The Helvetica Neue font family is available on most Mac OS X systems but generally on neither Windows nor Linux machines.  When the example here is rendered on Mac OS X, the local Helvetica Neue faces are used and no font is downloaded.  Under Windows and Linux the attempt to load a local font fails and a substitute font -- MgOpen Moderna -- is downloaded and used instead.  MgOpen Moderna is designed to be a substitute for Helvetica, so it renders similarly to Helvetica Neue.  This way, an author can guarantee text appearance but avoid a font download when it's unnecessary.


The name used to refer to a specific font face is the full name for an individual font.  Generally it's the family name plus the style name (e.g. "Helvetica Bold").  Under Mac OS X, the name is listed in the information panel for a given face.  Select a single face and choose 'Show Font Info' from the Preview menu in FontBook:
The name used to refer to a specific font face is the full name for an individual font.  Generally it's the family name plus the style name (e.g. "Helvetica Bold").  Under Mac OS X, the name is listed in the information panel for a given face.  Select a single face and choose 'Show Font Info' from the Preview menu in FontBook:
Line 131: Line 131:
== Font Licensing Issues ==
== Font Licensing Issues ==


When using a font for a website, it's important to always confirm that the font license permits use on a website.  If the license agreement is filled with opaque legalese, err on the side of caution, check with the font vendor before using a font on a site.  If the license permits its use, it's a good idea to add a comment near the @font-face rules that points to the license, for future reference.
When using a font for a website, it's important to always confirm that the font license permits use on a website.  If the license agreement is filled with opaque legalese, err on the side of caution and check with the font vendor before using a font on a site.  If the license permits its use, it's a good idea to add a comment near the @font-face rules that points to the license, for future reference.


''&ldquo;I found a free font, can I use it on my site?&rdquo;''
''&ldquo;I found a free font, can I use it on my site?&rdquo;''
Line 139: Line 139:
''&ldquo;I just want to use [insert favorite font name here] on my site.  Is that possible?&rdquo;''
''&ldquo;I just want to use [insert favorite font name here] on my site.  Is that possible?&rdquo;''


Right now, probably no.  The use of font linking on the web is still in its infancy.  Most fonts that ship with proprietary OS's today have licenses that limit their use to standard desktop applications, so uploading these fonts to a web server is almost certainly not permitted currently.  Piracy has plagued the font industry in the past so most font vendors are wary of allowing their fonts to be used except in relatively limited contexts.  Many font vendors are focused on the needs of publishing and printing industries, the relative complexity of their license agreements often reflects this.  In the future, some font designers may conclude that the sales of fonts as web fonts will outweigh any potential loss in sales due to piracy, others may not.  Their license agreements will reflect this choice and should be respected.
Right now, probably not.  The use of font linking on the web is still in its infancy.  Most fonts that ship with proprietary OS's today have licenses that limit their use to standard desktop applications, so uploading these fonts to a web server is almost certainly not permitted.  Piracy has plagued the font industry in the past, so most font vendors are wary of allowing their fonts to be used except in relatively limited contexts.  Many font vendors are focused on the needs of publishing and printing industries, and the relative complexity of their license agreements often reflects this.  In the future, some font designers may conclude that the sales of fonts as web fonts will outweigh any potential loss in sales due to piracy, others may not.  Their license agreements will reflect this choice and should be respected.


The stock photography market is often described as a $2 billion market but the web font market is still close to a $0 market, it can only go up!
The stock photography market is often described as a $2 billion market but the web font market is still close to a $0 market, it can only go up!
Line 166: Line 166:
== Future Work ==
== Future Work ==


For Firefox 3.5, the [https://bugzilla.mozilla.org/show_bug.cgi?id=3512 <code>font-stretch</code>] and [https://bugzilla.mozilla.org/show_bug.cgi?id=475891 <code>unicode-range</code>] descriptors are not supported.  [https://bugzilla.mozilla.org/show_bug.cgi?id=119490 Fonts defined in SVG documents] are also not supported yet.  These are under consideration for inclusion in future releases.  As always, patches welcome!
For Firefox 3.5, the [https://bugzilla.mozilla.org/show_bug.cgi?id=3512 <code>font-stretch</code>] and [https://bugzilla.mozilla.org/show_bug.cgi?id=475891 <code>unicode-range</code>] descriptors are not supported.  [https://bugzilla.mozilla.org/show_bug.cgi?id=119490 Fonts defined in SVG documents] are also not supported yet.  These are under consideration for inclusion in future releases.  As always, patches are welcome!


== Further Resources ==
== Further Resources ==
canmove, Confirmed users, Bureaucrats and Sysops emeriti
6,906

edits