<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>User Agent Man &#187; Fonts</title>
	<atom:link href="http://www.useragentman.com/blog/category/technologies/fonts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.useragentman.com/blog</link>
	<description>A Blog about Client Side Web Technology</description>
	<lastBuildDate>Wed, 08 Sep 2010 14:02:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Giving Challenged @font-face Fonts The Italics Makeover</title>
		<link>http://www.useragentman.com/blog/2010/09/07/giving-challenged-font-face-fonts-the-italics-makeover/</link>
		<comments>http://www.useragentman.com/blog/2010/09/07/giving-challenged-font-face-fonts-the-italics-makeover/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 03:59:34 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[@font-face]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Fonts]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1560</guid>
		<description><![CDATA[Have a font that doesn't have an italics variant? There is a simple solution to this problem using CSS3 Transforms.]]></description>
			<content:encoded><![CDATA[<p>See the nice italicized text in the heading of this article?  It is not so obvious to style as you may think.  There are many great free and commercial fonts out there that allow @font-face embedding.  Unfortunately, not all of them have an italics variant for one reason or another.  For example, the font I use for my blogs headlines, <a href="http://www.fonts.info/info/press/free-fonts-for-font-face-embedding.htm">Graublau Sans Web</a>, does not have a true italics variant included with it, while the font I use for the blog&#8217;s copy, <a href="http://www.fontsquirrel.com/fonts/Droid-Sans">Droid Sans</a>, does.  When a font doesn&#8217;t have an italics variant, and you try to italicize it in a web-page using <code>&lt;i&gt;</code> and <code>&lt;em&gt;</code> tags, the results depend on the browser you are using:</p>
<ul>
<li>Safari, Chrome and Opera will render the font normally <strong>without</strong> italicizing it.</li>
<li>Internet Explorer and Firefox will attempt to italicize the font, but Internet Explorer will slant the font at a 20&deg; angle while Firefox implements a 10&deg; slant.</li>
</ul>
<table class="dataTable">
<thead>
<tr>
<th style="width: 33%">Internet Explorer 6.0</th>
<th style="width: 33%">Firefox 3.6</th>
<th style="width: 33%">Safari 4/Chrome 5/Opera 10</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/09/badItalics-IE.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/badItalics-IE.png" alt="Default Italics for Graublau Web in IE." width="106" height="38" class="alignnone size-full wp-image-1567" /></a></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/badItalics-firefox.png" alt="Default Italics for Graublau Web in Firefox." width="106" height="38" class="alignnone size-full wp-image-1567" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/badItalics-safari.png" alt="Default Italics for Graublau Web in Safari." width="106" height="38" class="alignnone size-full wp-image-1567" /></td>
</tr>
</table>
<p>This inconsistency is quite annoying from a user-experience point of view.  However, there is a way of leveling the playing field by using the CSS3 <code>transform</code> property.  And even though Internet Explorer doesn&#8217;t recognize <code>transform</code>, there is a workaround <strong>without using JavaScript</strong> using the <code>Matrix</code> Visual Filter.</p>
<h2>The CSS</h2>
<p>When I was a calligraphy student, I learned that the Italics script was to be written on a 10&deg; angle.  Using the CSS3 <code>transform</code> property, this can be achieved by using the <code>skewX()</code> function:</p>
<blockquote class="code">
<pre>
#content h1 em {
    font-family: "Graublau Web Bold", Arial, sans-serif;
    font-style: normal;

<span class="hilite">    -moz-transform:    skewX(-10deg);
    -o-transform:      skewX(-10deg);
    -webkit-transform: skewX(-10deg);
    transform:         skewX(-10deg);

    display: inline-block;
</span>
}
	</pre>
</blockquote>
<p>The <code>display: inline-block</code> is there since Safari, Chrome and Opera will not allow transformations on an <code>inline</code> element.</p>
<p>But what about Internet Explorer?  I <strong>could</strong> use my cssSandpaper script, but it is <strong>really</strong> simple to do without it:</p>
<blockquote class="code">
<pre>
#content h1 em {
    font-family: "Graublau Web Bold", Arial, sans-serif;
    font-style: normal;

    -moz-transform:    skewX(-10deg);
    -o-transform:      skewX(-10deg);
    -webkit-transform: skewX(-10deg);
    transform:         skewX(-10deg);

    display: inline-block;

<span class="hilite">    /* IE8+: must be on one line. */
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=-0.1763269807084645, M21=0, M22=1, SizingMethod='auto expand')";

    /* IE6 and 7 */
    filter: progid:DXImageTransform.Microsoft.Matrix(
             M11=1,
             M12=-0.1763269807084645,
             M21=0,
             M22=1,
             SizingMethod='auto expand');</span>
}
	</pre>
</blockquote>
<p>This is the Microsoft <code>Matrix</code> Filter equivalent of <code>skewX(10deg)</code>. Let&#8217;s take a look at how this works in all the major browsers:</p>
<table class="dataTable">
<thead>
<tr>
<th style="width: 20%">Internet Explorer 6.0+</th>
<th style="width: 20%">Firefox 3.5+</th>
<th style="width: 20%">Safari 4+</th>
<th style="width: 20%">Chrome 5+</th>
<th style="width: 20%">Opera 10.5+</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodItalics-IE.png" alt="Italics Fix in IE" width="106" height="39" class="alignnone size-full wp-image-1574" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodItalics-firefox.png" alt="Italics Fix in Firefox" width="106" height="39" class="alignnone size-full wp-image-1574" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodItalics-safari.png" alt="Italics Fix in Safari" width="106" height="39" class="alignnone size-full wp-image-1574" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodItalics-chrome.png" alt="Italics Fix in Chrome" width="106" height="39" class="alignnone size-full wp-image-1574" /></td>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodItalics-opera.png" alt="Italics Fix in Opera" width="106" height="39" class="alignnone size-full wp-image-1574" /></td>
</tr>
</table>
<p>Isn&#8217;t that nice and consistent?  The screenshots are from the Windows versions of the browsers, but you can expect the same results for Mac and Linux versions as well.</p>
<h2>Is This <em>Really</em> Italics?</h2>
<p>Not really.  <strong>Technically, we are creating an oblique variant of this font.</strong> <a href="http://en.wikipedia.org/wiki/Oblique_type">The Wikipedia entry for Oblique fonts</a> states that many sans-serif fonts do not have italic variants, so this technique will be a useful one in a web developers toolkit.  </p>
<h2>Caveats</h2>
<ul>
<li>If you are going to make a few words in a row oblique, make sure you wrap the <code>&lt;i&gt;</code> and <code>&lt;em&gt;</code> tags around each word.  This is because the <code>display: inline-block</code> rule treats multiple words wrapped in one set of these tags as one word, which will cause problems when you want the words to wrap to the next line.<br />
<table>
<thead>
<tr>
<th>Wrapping multiple words with <strong>one</strong> <code>&lt;em&gt;</code> tag</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/badWordWrap.png" alt="Bad Word Wrap Example" title="badWordWrap" class="aligncenter size-full wp-image-1580" /></td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Wrapping multiple words with separate <code>&lt;em&gt;</code> tags</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/goodWordWrap.png" alt="Good Word Wrap Example" title="goodWordWrap"  class="aligncenter size-full wp-image-1582" /></td>
</tr>
</tbody>
</table>
</li>
<li>If the oblique text does not have a solid background color, it will appear &#8220;blocky&#8221; or &#8220;pixely&#8221; in IE.  To fix this, you must use IE&#8217;s Chroma Visual Filter, as described in my last blog post, <a href="/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/">How to Make ClearType, @font-face Fonts and CSS Visual Filters Play Nicely Together</a>.</li>
<li>In IE, multiple oblique words may appear to have more white space than the other browsers.  In this case you may need to create IE-only CSS rules that implement negative left margin on each word, using a solution like <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish’s Conditional CSS Pattern</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/09/07/giving-challenged-font-face-fonts-the-italics-makeover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Make ClearType, @font-face Fonts and CSS Visual Filters Play Nicely Together</title>
		<link>http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/</link>
		<comments>http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 20:49:51 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[ClearType]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[anti-aliased text]]></category>
		<category><![CDATA[blocky text]]></category>
		<category><![CDATA[cleartype]]></category>
		<category><![CDATA[CSS Filters]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[ie filters]]></category>
		<category><![CDATA[Internet Explorers]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[opacity]]></category>
		<category><![CDATA[Visual Filters]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=1526</guid>
		<description><![CDATA[Ever had a problem with using IE's Alpha Visual Filter and getting blocky text? A solution has been found, and it doesn't use JavaScript.  I expect to hear a sigh of relief from many developers.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Update (Sept. 3, 2010)</h3>
<ul>
<li>This article originally has the <code>filter</code> and <code>-ms-filter</code> rules reversed, which is against <a href="http://blogs.msdn.com/b/ie/archive/2008/09/08/microsoft-css-vendor-extensions.aspx">Microsoft&#8217;s best practices</a> for IE8.  This error has been corrected.</li>
<li>Thanks to <a href="http://www.zomigi.com">Zoe Mickley Gillenwater</a> for pointing out that IE8 needs to have all the filter functions (i.e. all the stuff in the double quotes) on one line.</li>
</ul>
</div>
<p>The modern web developer wants to be able to use a variety of CSS3 effects together, but sometimes doing this in IE can be challenging, especially if you don&#8217;t want to use JavaScript.  Let&#8217;s take a look a common problem with IE: blocky text in IE when using IE Visual filters on a block of text.  For example, if you&#8217;ve ever tried to do <a href="http://davidwalsh.name/css-opacity">the cross-browser CSS opacity trick</a> to implement opacity in IE6, this problem manifests itself when the <strong>text is styled with no background color</strong>.  A developer uses this well-known cross browser CSS-foo to make this work:</p>
<blockquote class="code">
<pre>
#badAntiAliasing {
	opacity: 0.5;

        /* IE 8 */
        -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";

        /* IE 6,7 */
	filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50);

}
</pre>
</blockquote>
<p>And it looks great in every browser, but <strong>it looks like crap in Internet Explorer 6 with ClearType turned on.</strong>  It is especially pronounced when using @font-face embedding with fonts that assume that some sort of anti-aliasing technology is being used.  The example below uses <a href="http://www.fonts.info/info/press/free-fonts-for-font-face-embedding.htm">Graublau Sans Web</a> with the Alpha filter to illustrate the issue:</p>
<table class="dataTable" style="margin-top: 1em">
<thead>
<tr>
<th>Opacity Solution in IE</th>
<th>Opacity Solution in every other browser</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/09/firefoxAntiAlias.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/firefoxAntiAlias.png" alt="" title="firefoxAntiAlias" width="360" height="50" class="alignnone size-full wp-image-1529" /></a></td>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieBadAntiAlias.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieBadAntiAlias.png" alt="" title="ieBadAntiAlias" width="361" height="58" class="alignnone size-full wp-image-1530" /></a></td>
</tr>
</tbody>
</table>
<p>This has been a known problem with IE ever since 2006 when ClearType&#8217;s product manager, Peter Gurevich, <a href="http://blogs.msdn.com/b/ie/archive/2006/08/31/730887.aspx">announced on the IEBlog their decision to disable ClearType on elements that use any Visual Filter</a>.  If you read the comments on this blog article, you will see many upset developers.  I was one of them, since this not only affects the <a href="http://msdn.microsoft.com/en-us/library/ms532967%28v=VS.85%29.aspx">Alpha Filter</a>, but all of <a href="http://msdn.microsoft.com/en-us/library/ms532849%28v=VS.85%29.aspx">IE&#8217;s Visual Filters</a>, some of which I use in cssSandpaper to get IE to support CSS3 properties like <code>transform</code>.</p>
<p>Today, however, we can rejoice.  There is a <strong>usable workaround that will make ClearType rendered fonts look nice when using Visual Filters</strong>.  In our example above, here is what needs to be done:</p>
<blockquote class="code">
<pre>
body.ie6 #goodAntiAliasing,
body.ie7 #goodAntiAliasing,
body.ie8 #goodAntiAliasing {
	background-color: <span class="hilite">white</span>;
}

#goodAntiAliasing {
	opacity: 0.5;

        /* IE 8: yes, it is ugly but it has to be on one line. :-( */
        -ms-filter: "progid:DXImageTransform.Microsoft.Chroma(<span class="hilite">color='white'</span>) progid:DXImageTransform.Microsoft.Alpha(opacity=50)";

        /* IE 6,7 is more flexible: it can be on multiple lines. */
	filter: progid:DXImageTransform.Microsoft.Chroma(<span class="hilite">color='white'</span>)
                progid:DXImageTransform.Microsoft.Alpha(opacity=50);

}
</pre>
</blockquote>
<p>What is going on here?</p>
<ol>
<li>The first rule sets the background color of the container to a color that is represents the color of the majority of the background image on the page.  <strong>Note that this rule uses <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish&#8217;s Conditional CSS Pattern</a> to serve it only to IE.</strong></li>
<li>The second rule executes two of IE&#8217;s Visual Filters:
<ul>
<li>the Chroma Visual Filter, which tells IE &#8220;Please make this color transparent&#8221;.  The color we choose to make transparent is the one we selected in the first rule.</li>
<li>the Alpha Visual Filter, which does the opacity trick</li>
</ul>
</ol>
<table class="dataTable">
<thead>
<tr>
<th>New Opacity Solution in IE</th>
<th>New Opacity Solution in every other browser</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieBadAntiAlias.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieBadAntiAlias.png" alt="" title="ieBadAntiAlias" width="361" height="58" class="alignnone size-full wp-image-1530" /></a></td>
<td><a href="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieBadAntiAlias.png"><img src="http://www.useragentman.com/blog/wp-content/uploads/2010/09/ieGoodAntiAlias.png" alt="" title="ieBadAntiAlias" width="361" height="58" class="alignnone size-full wp-image-1530" /></a></td>
</tr>
</tbody>
</table>
<p><strong>These filters must be in the order given</strong>, and not the other way around.  Note also that care must be given that <strong>the color chosen to be transparent should be the average color of what is behind the text being styled</strong>, otherwise you will get less than optimal results.  If this background is a complex image, just use the colour that&#8217;s used most often.</p>
<p>This fixes not only the IE opacity problem, but also issues with other Visual Filters, such as <code>Matrix</code>.  I will be updating cssSandpaper to use this trick so that transformed objects in IE won&#8217;t look so blocky.</p>
<p><a class="exampleLink" href="/tests/fontFacePlusFilter/">Take a look at the solution in action (make sure you look at it in IE in order to get the full effect)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2010/09/02/how-to-make-cleartype-font-face-fonts-and-css-visual-filters-play-nicely-together/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Introducing: The Type Rendering Project</title>
		<link>http://www.useragentman.com/blog/2009/11/30/introducing-the-type-rendering-project/</link>
		<comments>http://www.useragentman.com/blog/2009/11/30/introducing-the-type-rendering-project/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 17:05:58 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[@font-face]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Fonts]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=412</guid>
		<description><![CDATA[Join a project that will allow developers to <strong>find ways to make web type look better <em>right now</em></strong>.]]></description>
			<content:encoded><![CDATA[<div id="attachment_416" class="wp-caption alignleft" style="width: 260px"><img class="size-medium wp-image-416 " title="Type Rendering Project Logo" src="http://www.useragentman.com/blog/wp-content/uploads/2009/11/r-300x300.png" alt="Type Rendering Project Logo" width="250" height="250" /><p class="wp-caption-text"><span></span></p></div>
<p>Although this blog wasn&#8217;t meant to be a forum on <em>just</em> CSS font-embedding, it is a topic of great interest to me and has been the inspiration of a few articles here (my article on <a href="/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/">JavaScript font-smoothing detection</a> being the latest).  As a result, I have been very fortunate in meeting a lot of interesting and like-minded individuals who want to make the web a better place for typography.</p>
<p>One of the more vocal ones, <a href="http://paulirish.com/">Paul Irish</a>, asked me to join a project that will allow developers to <strong>find ways to make web type look better <em>right now</em></strong>.  Other members include web font blogger Tim Brown of <a href="http://www.nicewebtype.com/">Nice Web Type</a> and Ethan Dunham of the excellent font resource <a href="http://fontsquirrel.com/">Font Squirrel</a>.  The result is <a href="http://typerendering.com/">The Type Rendering Project</a> &#8211; we’ve set some goals and would like to open up dialogue with you to fulfill them. We&#8217;re asking for your participation, and lots of expert advice, to fulfill these intentions. If you are interested and are a Twitter user, <a href="http://twitter.com/typerendering">follow us</a> &#8211;  and more importantly, <a href="http://twitter.com/home?status=I+care+about+how+type+looks+on+the+web,+so+I+follow+%40typerendering.">tell folks you care about how type looks on websites</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/11/30/introducing-the-type-rendering-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Detect Font-Smoothing Using JavaScript</title>
		<link>http://www.useragentman.com/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/</link>
		<comments>http://www.useragentman.com/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 19:41:50 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[@font-face]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[ClearType]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=338</guid>
		<description><![CDATA[Not all @font-face fonts look good when font-smoothing is turned off.  Now you can detect whether a font smoothing technology is being used and serve alternative fonts for those users.]]></description>
			<content:encoded><![CDATA[<div class="importantNotes">
<h3>Interested in making web typography look better?</h3>
<p><a href="/blog/2009/11/30/introducing-the-type-rendering-project/">Read about The Type Rendering Project!</a></p>
</div>
<div id="attachment_404" class="wp-caption alignleft" style="width: 260px"><img class="size-full wp-image-404 " title="fontSmoothingLeader" src="http://www.useragentman.com/blog/wp-content/uploads/2009/11/fontSmoothingLeader.png" alt="Image a remix of Wikimedia Images http://bit.ly/5LufSS and http://bit.ly/6Jjlbd" width="250" height="250" /><p class="wp-caption-text">
<div>Examples of font-smoothing and subpixel-rendering as performed by technologies like ClearType.  Image Credit: Wikimedia Commons users <a href='http://commons.wikimedia.org/wiki/File:Antialias-vrs-Cromapixel.png'>Pandries</a> and <a href='http://commons.wikimedia.org/wiki/File:ClearType02.png'>Kalan</a></div>
<p></p></div>
<p>In <a title="&quot;More @font-face in Depth&quot; article" href="http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/">an earlier article</a>, I mentioned that <a title=" Boing Boing’s Redesign Uncovers the Dark Side of Web Fonts" href="http://www.webmonkey.com/blog/Boing_Boing_s_Redesign_Uncovers_the_Dark_Side_of_Web_Fonts">Boing-Boing had a few issues when they wanted to use @font-face embedding inside their website</a>.  In short, the problem was that some fonts look bad on computer monitors without font-smoothing enabled in the operating system.  This brought on a lot of discussion as to whether there was a way to detect whether or not font-smoothing was being used using JavaScript.  I initially thought there wasn&#8217;t a way, but after seeing a promising but incomplete method of detecting font-smoothing, I spent a few days devising a way to do it.</p>
<h2>Internet Explorer Does Something Easily (For a Change)</h2>
<p><a href="http://paulirish.com/">Paul Irish</a> mentioned to me and a few other colleagues that he came across <a href="http://silkworth.net/browser_os/cleartype.html">a page using an Active X control that detects font-smoothing in IE</a>.  I was so hopeful &#8230; until I realized that this only works on browsers that have come into contact with <a href="http://www.microsoft.com/typography/cleartype/tuner/tune.aspx">Microsoft&#8217;s online Cleartype Tuner</a>, which I visited with my copy of IE months before.  If a users had never visited this page, the script would fail.</p>
<p>I was more disappointed because Googling &#8220;javascript cleartype&#8221; did not point to anything useful.  However, searching for &#8220;javascript font-smoothing&#8221; pointed me to an article that told me about Internet Explorer&#8217;s <a href="http://www.java2s.com/Code/JavaScript/Window-Browser/ScreenfontSmoothingEnabled.htm">screen.fontSmoothingEnabled</a> property.  This gives us what we need &#8230; but only in Internet Explorer.  How on Earth can we detect font-smoothing in other browsers, and in non-Windows operating systems?</p>
<h2>Canvas to the Rescue</h2>
<div id="attachment_390" class="wp-caption aligncenter" style="width: 420px"><img class="size-full wp-image-390" title="aliasAndAntiAliasComparison" src="http://www.useragentman.com/blog/wp-content/uploads/2009/11/aliasAndAntiAliasComparison.png" alt="aliasAndAntiAliasComparison" width="410" height="244" /><p class="wp-caption-text">Letter &#39;O&#39; , Arial font, 32 px, rendered both without (left) and with (right) font-smoothing</p></div>
<p style="text-align: center;">
<p>I then thought about about the screenshots I made for <a href="/blog/2009/09/20/font-face-in-depth/">the @font-face in Depth article</a>.  Can a browser render a black glyph and detect if there is some sort of non-black pixel colouring around the its edges of the glyphs? <strong> A human can tell the difference</strong>:  if there are some non-black pixels around the edge of the glyph, it must be using font-smoothing.</p>
<p>But <strong>web browsers can do this too!</strong> Just have the browser draw a letter in black inside a <code>canvas</code> tag, and then have it sift through the canvas&#8217; pixels to see if there are any that are <strong>not</strong> pure black or pure white (more accurately, have the browser check the alpha channel to see if there are any semi-transparent pixels, which have a value that is not 0 or 255).    If there are no semi-transparent pixels, then the algorithm assumes that no font-smoothing is being used. I wrote an JavaScript routine that does this &#8211; it starts from co-ordinate (8,1) and scans left to right, to the bottom of the canvas (any point on near the top on the left-hand side of the canvas would have done as well).</p>
<p>The result is a JavaScript object, <code>TypeHelpers</code>, which implements this routine in one method, <code>hasSmoothing()</code>:</p>
<blockquote class="code">
<pre>var TypeHelpers = new function(){

   // I use me instead of this.  For reasons why, please read:
   // http://w3future.com/html/stories/callbacks.xml
   var me = this;

   me.hasSmoothing = function(){

      // IE has screen.fontSmoothingEnabled - sweet!
      if (typeof(screen.fontSmoothingEnabled) != "undefined") {
         return screen.fontSmoothingEnabled;
      } else {

         try {

            // Create a 35x35 Canvas block.
            var canvasNode = document.createElement('canvas');
            canvasNode.width = "35";
            canvasNode.height = "35"

            // We must put this node into the body, otherwise
            // Safari Windows does not report correctly.
            canvasNode.style.display = 'none';
            document.body.appendChild(canvasNode);
            var ctx = canvasNode.getContext('2d');

            // draw a black letter 'O', 32px Arial.
            ctx.textBaseline = "top";
            ctx.font = "32px Arial";
            ctx.fillStyle = "black";
            ctx.strokeStyle = "black";

            ctx.fillText("O", 0, 0);

            // start at (8,1) and search the canvas from left to right,
            // top to bottom to see if we can find a non-black pixel.  If
            // so we return true.
            for (var j = 8; j &lt;= 32; j++) {
               for (var i = 1; i &lt;= 32; i++) {

                  var imageData = ctx.getImageData(i, j, 1, 1).data;
                  var alpha = imageData[3];

                  if (alpha != 255 &amp;&amp; alpha != 0) {
                     return true; // font-smoothing must be on.
                  }
               }

            }

            // didn't find any non-black pixels - return false.
            return false;
         }
         catch (ex) {
            // Something went wrong (for example, Opera cannot use the
            // canvas fillText() method.  Return null (unknown).
            return null;
         }
      }
   }

   me.insertClasses = function(){
      var result = me.hasSmoothing();
      var htmlNode = document.getElementsByTagName('html')[0];
      if (result == true) {
         htmlNode.className += " hasFontSmoothing-true";
      } else if (result == false) {
            htmlNode.className += " hasFontSmoothing-false";
      } else { // result == null
            htmlNode.className += " hasFontSmoothing-unknown";
      }
   }

}

// if EventHelpers.js is included, insert the hasFontSmoothing CSS classes
if (window.EventHelpers) {
   EventHelpers.addPageLoadEvent('TypeHelpers.insertClasses')
}</pre>
</blockquote>
<p>Note the object also has an <code>insertClasses()</code> method.  This method, when run, adds a class to the <code>html</code> tag:</p>
<ul>
<li><code>hasFontSmoothing-true</code> if font-smoothing is being used</li>
<li><code>hasFontSmoothing-false</code> if it is not</li>
<li><code>hasFontSmoothing-unknown</code> if the user agent is unable to tell</li>
</ul>
<p>This makes it easy for developers who don&#8217;t want to mess with JavaScript code and just want  to use CSS.</p>
<p>Also note the <code>EventHelpers.addPageLoadEvent()</code> call at the end of the code.  This method (which is part of <code>EventHelpers.js</code>, included with the archive below) <a href="http://dean.edwards.name/weblog/2005/09/busted/">implements Dean Edwards&#8217; window.onload alternative which doesn&#8217;t wait for all the objects in the page to be loaded</a>.   I use this implementation to execute <code>TypeHelpers.insertClasses()</code> when the page loads so any font-detection CSS rules will work right away.  Please feel free to change this code to use the equivalent function call in Dojo, Prototype, jQuery, or whatever JavaScript code framework you prefer.</p>
<h2>Example #1: JavaScript Font Smoothing Detection</h2>
<p>Enough of theory &#8230; let&#8217;s look at it in practice!  To show how to detect font-smoothing with JavaScript, I created a page that, when the page is loaded, checks to see if it can tell if font-smoothing has been implemented and tells the user.  Here is the code that does this check:</p>
<blockquote class="code">
<pre>function displayInfo() {

   var message;
   var isFontSmoothingOn = TypeHelpers.hasSmoothing();
   if (isFontSmoothingOn == true) {
      message = "This browser is using a font-smoothing technology";
   } else if (isFontSmoothingOn == false) {
      message = "This browser isn't using a font-smoothing technology"
   } else {
      message = "We could not detect if font-smoothing is being used."
   }
   document.getElementById('detectInfo').innerHTML = message;

}

window.onload = displayInfo;</pre>
</blockquote>
<p><a class="exampleLink" href="/tests/fontSmoothing/">See the above code in action</a></p>
<h2>Example #2: CSS Font Smoothing Detection</h2>
<p>As implied earlier, this library can help CSS use different fonts if the browser is using a font-smoothing technology.   For example, using the following CSS will allow a browser to use the Droid Sans embedded font only if it using font-smoothing — otherwise, it will use Arial:</p>
<blockquote class="code">
<pre>@font-face {
	font-family: "Droid Sans";
	src: url("/shared/fonts/DroidSans/DroidSans.eot");
	src: local("Droid Sans"),
	     local("Droid Sans"),
	     url("/shared/fonts/DroidSans/DroidSans.ttf") format("truetype");
}

body {
	font-family: "Arial", "Helvetica", sans-serif;
}

html.hasFontSmoothing-true body {
	font-family: "Droid Sans", "Arial", "Helvetica", sans-serif;
}</pre>
</blockquote>
<p>We can also serve special content to users depending on the way fonts are rendered on their browser.  We first create content for all three scenerios (browser uses font-smoothing, browser doesn&#8217;t use font-smoothing, and the &#8220;we cannot detect&#8221; case) and wrap the content inside &lt;code&gt;div&lt;/code&gt; tags using appropriate CSS classes:</p>
<blockquote class="code">
<pre>&lt;div class="fontSmoothingMessage initiallyHidden"&gt;
    &lt;p&gt;You browser &lt;strong&gt;is&lt;/strong&gt; rendering this page
    with font-smoothing. Because of that, we will attempt
    to serve up the Droid Sans font to render this page,
    because we think it looks cool. If you are using a
    browser (such as Google Chrome) that cannot render
    downloaded True Type fonts by default, then the page
    will be rendered using Arial instead.&lt;/p&gt;
&lt;/div&gt;

&lt;div class="noFontSmoothingMessage initiallyHidden"&gt;
    Your browser &lt;strong&gt;is not&lt;/strong&gt; rendering this
    page with font-smoothing. It is for that reason we have
    decided to use the plain old Arial font to render this
    page, because it is hinted for use for displays that
    don't employ a font-smoothing technology.
&lt;/div&gt;

&lt;div class="unknownFontSmoothingMessage initiallyHidden"&gt;
    &lt;strong&gt;We are not sure&lt;/strong&gt; if your browser is
    rendering this page with a font-smoothing technology.
    It is for that reason we have decided to use the plain
    old Arial font to render this page, because it is
    hinted for use for displays that don't employ a
    font-smoothing technology.
&lt;/div&gt;</pre>
</blockquote>
<p>Note all the <code>div</code> tags are members of the class <code>initiallyHidden</code>.  This class will be used to hide all font-smoothing related content until the script kicks in.</p>
<p>However, all this will not work unless we use the following CSS code:</p>
<blockquote class="code">
<pre>.initiallyHidden {
	display: none;
}

html.hasFontSmoothing-true .fontSmoothingMessage,
html.hasFontSmoothing-false .noFontSmoothingMessage,
html.hasFontSmoothing-unknown .unknownFontSmoothingMessage {
	display: block;
}</pre>
</blockquote>
<p>Of course, this whole soltution relies on whether JavaScript being turned on in the user&#8217;s browser.  This should be kept in mind when implementing this solution.</p>
<p><a class="exampleLink" href="/tests/fontSmoothing/cssExample.html">See the above code in action</a></p>
<h2>Download</h2>
<p>All code used in this article can be downloaded below (<strong>Note:</strong> version 1.0 was missing the Droid Sans Fonts which have now been put into the archive.  Thanks to John Faulds for pointing this out).</p>
<p><a class="exampleLink" href="/downloads/TypeHelpers.zip">TypeHelpers.js v.1.0a and sample code.</a></p>
<p>With the help of <a href="http://www.nicewebtype.com">Tim Brown</a>, it was determined that the code detected font-smoothing correctly in the following browsers:</p>
<ul>
<li>Internet Explorer 6 and up on Windows XP and higher.</li>
<li>Firefox 3.5 and higher on Windows XP and higher, Mac OS X 10.4 and higher, and Ubuntu Linux 9.10 (and probably lower)</li>
<li>Chrome 3.0 on Windows XP and higher</li>
<li>Safari 4.0.3 on Windows XP and higher and Mac OS X 10.4 and higher</li>
</ul>
<p>This script <strong>cannot detect font-smoothing in any version of Opera</strong> (at the time of this writing, this includes all versions up to 10.10), since it cannot write text inside the canvas element in a way we can poll the pixels afterwards.  If anyone can find a way of making it work with Opera, please write a comment below — I&#8217;d love to be able to support this browser.</p>
<h2>Testing Caveats</h2>
<p>Testing font-smoothing in most Windows web browsers is easy since it can be turned off inside the Display control panel. However, when using Safari for Windows, it is necessary to navigate inside Safari&#8217;s <strong>Appearance</strong> preferences and set the <strong>Font-smoothing</strong> option to <strong>Windows Standard</strong>.  This is because  by default, Safari uses it&#8217;s own built-in font-rendering engine which doesn&#8217;t seem to render aliased fonts.  In Mac OS X, it seems anti-aliasing only works for fonts below a certain size, so aliased fonts don&#8217;t seem to be an issue with that operating system.  In Ubuntu Linux I have yet to find a way of shutting of font-smoothing.  If anyone knows a way, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/11/29/how-to-detect-font-smoothing-using-javascript/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>More @font-face fun</title>
		<link>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/</link>
		<comments>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 00:53:36 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[@font-face. opera. chrome]]></category>
		<category><![CDATA[anti-aliasing]]></category>
		<category><![CDATA[cleartype]]></category>
		<category><![CDATA[svg fonts]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=237</guid>
		<description><![CDATA[My first post @font-face in Depth got a huge amount of unexpected attention.  Thank you all for your comments and criticism.  Since the post, there have been quite a bit of information I have read about and thought I should share. SVG fonts for Opera and Chrome Jonathan Snook wrote a great article regarding Opera [...]]]></description>
			<content:encoded><![CDATA[<p>My first post <a href="/blog/2009/09/20/font-face-in-depth/">@font-face in Depth</a> got a <strong>huge</strong> amount of unexpected attention.  Thank you all for your comments and criticism.  Since the post, there have been quite a bit of information I have read about and thought I should share.</p>
<h2>SVG fonts for Opera and Chrome</h2>
<p><a href="http://www.snook.ca/">Jonathan Snook</a> wrote a great article <a href="http://www.snook.ca/archives/html_and_css/becoming-a-font-embedding-master">regarding Opera 10 and Google Chrome supporting SVG fonts</a> (Chrome can load them without any pesky command line switch!).   He mentions how to convert TrueType fonts to this format using <a href="http://xml.apache.org/batik/">Batik</a>, and that by removing all the <code>&lt;hkren&gt;</code> elements inside the file&#8217;s XML can make the font smaller than the original TrueType file.  Too bad the browsers don&#8217;t support this format.</p>
<h2>Opera&#8217;s buggy implementation</h2>
<p>I noticed after I launched my first @font-face article that Opera was not loading the fonts on my blog when users visited more than one page.  It turns out that Opera 10&#8242;s implementation of @font-face is a little buggy.  When you feed it a page with an embedded font, you may not see the embedded fonts properly, like in the screenshot below:</p>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2009/10/screenshotOpera.png"><img class="size-medium wp-image-238 " title="screenshotOpera" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/screenshotOpera-300x215.png" alt="screenshotOpera" width="300" height="215" /></a><p class="wp-caption-text">Opera sometimes doesn&#39;t load the font at all, and removes other styling (click to enlarge).</p></div>
<p><a href="http://readableweb.com/opera-admits-font-face-bugs-in-opera-10/">According to Opera</a>, this happens when &#8220;specifying different weights and styles for a single font-family name&#8221;.  Håkon Wium Lie, the company&#8217;s Chief Technology Officer , <a href="http://devfiles.myopera.com/articles/751/webfonts-workaround.html">has described a work-around</a> until the company can fix the problem properly.</p>
<p>I am debating whether to implement the work around on my site, or to wait for Opera to fix the problem and patch all Opera 10 installations via auto-update (I&#8217;m leaning towards the latter).</p>
<h2>Performance Issues With Font Embedding</h2>
<p>One of the comments on the last article came from <a href="http://stevesouders.com/">Steve Souders</a> who had <a href="/blog/2009/09/20/font-face-in-depth/#comment-37">performance concerns with font-embedding</a>.  Paul Irish came back with information showing the <a href="http://paulirish.com/2009/fighting-the-font-face-fout/">when browsers load the fonts, and what they do before the font is loaded</a>.  He also shows how to use JavaScript to make the loading behaviour consistent between browsers.</p>
<p>The performance issues with font-embedding is something I am going to be keeping an eye on, especially when it comes to font-services, which the OpenType site believes will be <a href="http://opentype.info/blog/2009/07/29/why-webfont-services-are-the-future-of-fonts-on-the-web/">the future of web font distribution for commercial fonts</a>.  Although it doesn&#8217;t seem like much of an issue currently (my blog <em>seems</em> to load quickly), I don&#8217;t want to do anything that would slow down my web applications &#8211; especially if I am using them just to make the text look a little prettier.</p>
<h2>Windows XP Rendering Issues</h2>
<p>Boing-Boing had a bad experience with font-embedding.  Turns out <a href="http://www.webmonkey.com/blog/Boing_Boing_s_Redesign_Uncovers_the_Dark_Side_of_Web_Fonts">they got a lot of complaints when they decided to incorporate it into their website</a>.  The reason: some users didn&#8217;t have ClearType turned on, and the font Boing-Boing chose looked &#8220;like ass&#8221; without ClearType.</p>
<p>Below are screenshots of this site without ClearType on:</p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 449px"><img class="size-full wp-image-250" title="ieNoAA" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/ieNoAA.png" alt="ieNoAA" width="439" height="336" /><p class="wp-caption-text">Internet Explorer without ClearType</p></div>
<p style="text-align: center;">
<div id="attachment_251" class="wp-caption aligncenter" style="width: 465px"><img class="size-full wp-image-251" title="firefoxNoAA" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/firefoxNoAA.png" alt="Firefox without ClearType" width="455" height="327" /><p class="wp-caption-text">Firefox without ClearType</p></div>
<p>The article stated that there are quite a few XP computers which apparently don&#8217;t have ClearType on by default. I wonder if there are any stats to back that up. If so, then developers embed fonts into pages should test that scenario as well.  It does look different.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
