Differences between revisions 22 and 23
Revision 22 as of 2010-02-01 14:07:32
Size: 10402
Editor: KaiJaeger
Comment: Correction: IE8 DOES work!
Revision 23 as of 2010-02-01 17:37:49
Size: 10418
Editor: KaiJaeger
Comment:
Deletions are marked like this. Additions are marked like this.
Line 110: Line 110:
 * Firefox 3.4 and better (./) *1
 * Internet Explorer 8 *2
 * Firefox 3.4 and better (./) ^(1)^
 * Internet Explorer 6,7 & 8 ^(2)^
Line 117: Line 117:
*1 With Firefox, JavaScript needs to be enabled, otherwise font embedding does '''not '''work. ^1^ With Firefox, JavaScript needs to be enabled, otherwise font embedding does '''not '''work.
Line 119: Line 119:
--(*2 On some machines IE works, on others it doesn't. I can't resist to add: as usual.)-- Mea Culpa. A missing ";" for the IE made it fail. My mistake; IE8 works fine. -- KaiJaeger <<DateTime(2010-02-01T14:07:32Z)>> ^2^ --(On some machines IE works, on others it doesn't. I can't resist to add: as usual.))-- Mea Culpa. A missing ";" for the IE made it fail. My mistake; IE8 works fine. -- KaiJaeger <<DateTime(2010-02-01T14:07:32Z)>>

UnderstandingFontEmbedding

Note that this article is updated frequently, so it should always reflect "latest reality".

What it is

Font embedding simply means that when a web site is in need for a particular font to display a particular piece of text then this font is downloaded and installed temporarily by the browser automatically in the background.

From a designers point of view this is really nice, but there are important issues regarding licensing.

For APLers it's a chance to display APL code correctly on any machine even if that machine does not have an appropriate APL Unicode font installed.

What it is not

This article assumes that you have sufficient skills in CSS.

History

Font embedding was introduced by Microsoft with Internet Explorer 4 a long long time ago. This was never adapted by other browsers, and there was a reason for that: IE only accepts so-called EOT-fonts. It refers to "Embedded Open Type" fonts.

Now this format, although it has its merits, was owned by Microsoft, and Microsoft never even tried to make it a standard. For that reason other browser vendors stood away from this format.

In 2009, two things changed: Firstly, almost all other browsers (with the exception of Chrome) started to implement font embedding, although in a very different way. Secondly, Microsoft made the EOT-format public and at the same time started to make it a W3C-accepted standard.

That's good news, although for the time being it means that one has to provide different CSS rules for the IE and all the other browsers.

IE and EOT

EOT (Embedded Open Type) addresses two important issues:

  • It can be reduced to contain not all but only those characters of a particular font which got actually used on a particular web site.

  • It can be bound to a particular URL. In other words, only when the font is downloaded from a URL contained in the EOT file itself will IE make use of it. These allows to address licensing issues.

The way Microsoft has implemented it in terms of CSS rules is unfortunately different from all the other browsers: You cannot specify "Local" or "Format". If you are interested in details, this is the best source I managed to find: Embedding fonts: cross-browser problems

In short:

The lack of support for the "Local" directive means that IE always download the font in question, even if it is already installed locally anyway.

The "Format" directive is supposed to tell browsers which particular type of font the current font-face rule is all about, allowing them to skip this rule if the format tells them that they are not able to make use of it anyway. IE is not supporting "Local" and "Format" and adds them to the URL, making the whole thing fail.

TTF

TTFs (True Type Fonts) are used by the rest of the world for embedding fonts. Unfortunately there is no way to address licensing issues. This is bad news because it means that strictly speaking one can use only free TTFs for embedding purposes. Good news is that thanks to Adrian Smith, the owner and originator of "APL385 Unicode", everybody is allowed to distribute the "APL385 Unicode" TTF freely.

Converting a TTF font into EOT

In order to use the "APL385 Unicode" fonts for font embedding in IE we need to convert this font into an EOT file. Now if you are interested in how to do this, here are the details: Show

There is a tool available from Microsoft called WEFT that theoretically allows us to do this, but unfortunately IE won't use the resulting EOT file. The reasons are unknown.

However, there is a tool available that can create an EOT file that is used by IE8. Originally it was a UNIX/LINUX project:

http://code.google.com/p/ttf2eot/

This tool has a disadvantage: it does not allow us to bind the EOT-file to a particular URL. In our case, however, it doesn't matter as we will see.

The syntax to convert any font is easy; given you are in a directory where the exe as well as the font to be converted is located:

  ttf2eot.exe OLD-FONT.ttf NEW-FONT.eot

But you don't have to: Instead you can download a zipped version of the EOT file from this page, see the "Downloads" section at the very end of the page.

The CSS

Here is CSS code that defines a font "APLFont" from an embedded font.

Two important rules to follow:

  1. IE must come first.

  2. Make sure that all font-face rules are located at the very end of your CSS file.

Note that the IE part must not contain "local" and "format" - IE doesn't understand them and as a result fails to process not only that CSS rule but sometimes the rest of the CSS file as well. Other browsers will try to understand the rule but finally ignore it because it's not referring to a TTF font. Then they will carry on to process the remaining parts of the CSS file.

Note that the link http://misc.aplteam.com/apl385.eot is a real one but of course you should not use it in your own CSS file.

/* IE first */
@font-face {
        font-family: 'APLFont';
        src:    url("http://misc.aplteam.com/apl385U.eot");
}

@font-face {
        font-family: 'APLFont';
        src:    url("http://misc.aplteam.com/apl385.ttf");
}

Now "APLFont" can be used in the same way as any other font-family in CSS. An example:

pre {
   font-family:"APL385 Unicode","APLX Upright",APLFont,monospace;
}

Note that this lets the browser try to use a locally installed "APL385 Unicode" font first. If there is no such font installed on the local machine, it tries to find a locally installed "APLX Upright". Only when this fails, too, it makes use of "APLFont" which in turn is responsible for downloading the font in question.

In theory that's it. In practice it is a bit more complicated because Opera 10.0 is ought to process the "local" directive but it doesn't; Instead it failes completely. However, in the download section there is a file fontface.css available which deals with all these problems.

Performance considerations

Because the IE does not recognize the "Local" directive, there is no way to tell IE "download this font only if that font (this and that may or may not be the same font) is not installed locally. Which mans that IE will always download the font.

This shouldn't be as bad as it sounds because the EOT version of a font is compressed and therefore supposed to be smaller than the corresponding TTF file. However, that is not true for the "APL385 Unicode" font. The EOT version is actually marginally larger then the TTF font.

Anyway, one can savely assume that somebody interested in APL has a fast Internet connection, so downloading about 186KB should not pose a problem. In fact it's 372KB because the APL wiki uses a special version of the "APL385 Unicode" font for headlines which is not publicly available.

Who's going to take advantage?

These browsers should be fine. A (./) means that it worked at least for me.

  • Chrome 4.0 and better (./)

  • Firefox 3.4 and better (./) (1)

  • Internet Explorer 6,7 & 8 (2)

  • Opera 10.0 and better (./)

  • Safari 4.0 and better (./)

I can report only for Windows.

1 With Firefox, JavaScript needs to be enabled, otherwise font embedding does not work.

2 On some machines IE works, on others it doesn't. I can't resist to add: as usual.) Mea Culpa. A missing ";" for the IE made it fail. My mistake; IE8 works fine. -- KaiJaeger 2010-02-01 14:07:32

Strange effects

Browsers use different strategies how to display a page which comes with embedded fonts. Safari for example does not show anything until it is absolutely clear about how the page is going to look like. As a result some people complain that the browser is slow. That's not exactly true because it's a strategic decision made by Apple.

Firefox on the other hand tries to display something as soon as possible, even if the final layout might be different. Therefore Firefox comes up with something quite fast. However, for an embedded font Firefox uses one that is locally available. As a result the page changes more or less dramatically when the embedded font finally becomes available. Some people criticise this as distracting. Again this is a strategic decision.

Since APL glyphs might be completely unreadable with any font chosen by chance I prefer Safari's approach although Firefox is my preferred browser.

Web server issues

There is still a problem: We learned that an EOT file is supposed to come with a particular URL inside the file, and that IE won't accept a font which got downloaded from elsewhere. Fortunately, IE does accept an EOT file that does not have any URL specified. This is important for the APL wiki since we cannot download the font from
http://aplwiki.com/apl385 Unicode.eot
because this URL would be processed by the wiki software (MoinMoin) and therefore result in a "Page not found".

But Apache, the web server used for the APL wiki, won't deliver the font by default from another domain. To change that you must include this into your Apache configuration file (httpd.conf):

Header set Access-Control-Allow-Origin "*"

This decreases the safety of the web site marginally.

I have no experiences with IIS.

The future

We can assume that

  • Internet Explorer 9 will process both, "local" and "format".
  • EOT will become a W3C-recognized standard. Which means that sooner or later all other browsers will accept EOT fonts as well.

Mozilla has proposed WOFF (Web Open Font Format) which will be supported by Firefox 3.6. This new format addresses licensing issues and compresses fonts heavily. For details see http://hacks.mozilla.org/2009/10/woff/

The future is bright.

Downloads

  • apl385.eot.zip (The "APL385 Unicode" font as EOT file; needed for IE)

  • apl385.ttf.zip (The "APL385 Unicode" font as TTF file; needed for IE)

  • fontface.zip (Sample CSS which should work with all modern browsers)

Author: KaiJaeger


CategoryUnicode

UnderstandingFontEmbedding (last edited 2017-11-21 10:08:49 by KaiJaeger)