views:

160

answers:

2

I'm using a custom font and the @font-face tag. In Windows, everything looks great, regardless of whether it's Firefox, Chrome, or IE.

On Mac, it's a different story. For some reason, the Mac font renderer thinks the font is a lot shorter than it is.

For example, consider this test code (live example here):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        
        <title>Webble</title>
        <style type="text/css">
        @font-face
        {
            font-family: "Bubbleboy 2";
            src: url("bubbleboy-2.ttf") format('truetype');         
        }

        body
        {
            font-family: "Bubbleboy 2";
            font-size: 30px;
        }

        div
        {
            background-color: maroon;
            color: yellow;
            height: 100px;
            line-height: 100px;
        }
        </style>
    </head>
    <body>
        <div>The quick brown fox jumped over the lazy dog.</div>
    </body>
</html>

Open it on Windows Firefox and on Mac Firefox. Use your mouse to select it.

On Windows, you'll notice it fully selects the font.

On Mac, it only selects about half the font. If you look at what it is selecting, you'll see that that part has been centered, instead of the full height of the font.

Is there anyway to fix this rather large discrepancy?

A: 

Actually Windows is the culprit. Windows ClearType font renderer actually hammers the font's shape into pixel boundaries to make it "clearer" whereas Mac OS doesn't touch the shape of the font (which I very much prefer). This often leads to "taller" or "thinner" glyphs on screen, whereas on Mac OS you get a true representation of the font as the designer intended.

Here's an article by Jeff Atwood explaining the differences. In any case, you're not going to be able to get around it.

http://www.codinghorror.com/blog/2007/06/font-rendering-respecting-the-pixel-grid.html

Nick Bedford
Ugh... serious? What a pain. I guess I'll have to come up with some CSS hacks :(
cdmckay
Unfortunately the way the font is rendered is out of the web designer's control, at least until you bite the bullet and use images or maybe give server rendered title images.
Nick Bedford
This isn't correct at all; the pixel grid changes are tiny compared to nearly half the height of the characters as described here. The problem is just a buggy font. Please see my answer.
Nicholas Riley
+3  A: 

The font's ascent is too small. The Windows browsers (and Mac Safari, too, in my testing) just throw out the ascent value as incorrect, whereas Firefox and Opera on the Mac accept it.

The easiest way to fix this is with ttx, part of FontTools.

Use it like this:

% ttx bubbleboy-2.ttf
[...]
% edit bubbleboy-2.ttx

Change the ascent value to 1100 (or whatever works for you):

  <hhea>
    <tableVersion value="1.0"/>
    <ascent value="1100"/>

Then reconstitute the font:

% ttx bubbleboy-2.ttx 
Compiling "bubbleboy-2.ttx" to "bubbleboy-2#1.ttf"...
[...]

This new font should be fixed; you can check by opening it in Font Book.

If you want a more visual picture of the problem, try FontForge, though be warned its interface is rather baroque. Once you've opened the font, double-click a capital letter; you'll see a horizontal line bisecting the glyph. This is the (wrong) ascent. You can fix the ascent in Element > Font Info, then click General. Uncheck "Scale Outlines" or the ascent will be bigger but still wrong. :-)

However, to modify the font, I would recommend ttx over FontForge for small changes like this because it's less likely to destroy what it doesn't understand.

Nicholas Riley
Thanks Nicholas, I'll give it a go.
cdmckay
Worked perfectly, thank you!
cdmckay
Hmmm, now some new weirdness: the font resulting from editing the TTX files works everywhere except Chrome for Windows, where it seems not to accept it.
cdmckay
Hmm interesting. If I convert a font to TTX and back to TTF without editing anything, it still doesn't work on Chrome for Windows. Must be an issue with TTX, I'll give FontForge a go.
cdmckay
Gah, that's annoying, I've never had any problems with ttx. You might report it to the Letteror folks.
Nicholas Riley
Found a solution: edit the font with TTX, convert back to TTF, then open it in FontForge and re-save it. Then it works everywhere :)
cdmckay