Posts Tagged ‘browsers’

Ugly font-variant bug

Thursday, April 22nd, 2010

Here’s an annoy­ing lit­tle bug that man­i­fests when you try to set a CSS font-variant prop­erty (say, small-caps) with a font that doesn’t pro­vide the requested vari­ant. For instance, here is some text in League Gothic, pulled in via @font-face:

Sample of league gothic text, rendered normally

League Gothic doesn’t have its own small caps vari­ant. So what hap­pens when you tell the browser to give you one any­way? Here it is with font-variant: small-caps applied as ren­dered in Firefox:

Sample of league gothic small caps, rendered correctly in Firefox

So far, so good. But here’s what you get when you add small caps to League Gothic in Webkit:

Sample of league gothic small caps, which falls back to the default font in Webkit

Whoops! Webkit-based browsers (I tested this in Safari, Webkit Nightly, and Chrome for OSX), when they don’t find the spec­i­fied vari­ant in the font itself, just go to the next font in the stack. In this case, it’s the browser’s default font.

So which behav­ior is cor­rect? The CSS2 spec essen­tially left it up to imple­men­tors to decide whether or not they would dynam­i­cally scale the font to imple­ment small caps. CSS3 removes the ambiguity:

If a gen­uine small-caps font is not avail­able, user agents should sim­u­late a small-caps font, for exam­ple by tak­ing a nor­mal font and replac­ing the low­er­case let­ters by scaled upper­case char­ac­ters. (CSS fonts mod­ule level 3)

Although a typo­graphic purist might take issue with this behav­ior (Bringhurst rails against the prac­tice of “rolling your own” vari­ants by dynam­i­cally scal­ing the exist­ing face), this is what the spec says browsers are sup­posed to do. And in fact, this is what Fire­fox does. Webkit, on the other hand, checks each font in the stack in order until it finds one that sup­plies the desired vari­ant. As in the exam­ple above, if there’s noth­ing else in the stack, it will fall back on the browser’s default font.

Unfor­tu­nately, there aren’t really any workarounds for this bug. But it should serve to remind you yet again that it’s super-important to put a good deal of thought into your font stack. Always try to build a stack where all of the fonts are as sim­i­lar as pos­si­ble, so when some­thing like this hap­pens, your design doesn’t break too badly.

For ref­er­ence, or if you’d like to see how your browser of choice han­dles these cases, here are some test cases together on a sep­a­rate page.

What I’m Reading: 3/28

Friday, March 28th, 2008
  1. It’s Not a League of Their Own: Boston Dirt Dogs has an excerpt from the 2008 Red Sox Annual in which the authors size up the Sox’ com­pe­ti­tion in the Amer­i­can League. On the whole, it’s pretty inter­est­ing I guess, but the best part is that the sec­tion on the Ori­oles is just one long ref­er­ence to The Wire. And if you read a lit­tle fur­ther down there’s another Wire ref­er­ence that’s mas­querad­ing as a pithy state­ment about the eco­nom­ics behind your brand new Tampa Bay Devil Rays:

    My eco­nom­ics are rusty, but when you have an infe­rior prod­uct in a sat­u­rated, inelas­tic mar­ket, one strat­egy is to re-brand the prod­uct. There­fore, exit the Devil, and their aqua uni­forms, to be replaced by the San Diego Padres kits with blue replac­ing sand brown.

    Stringer Bell is alive and well in the sports pages, folks.

  2. WebKit gets 100% on Acid3: “Yesterday’s news” you say? Nope. The news today is about Webkit/GTK. Awe­some news for us LXers. Also, def­i­nitely take a look at this account of the main Webkit team’s road to 100/100. It’s got some fun insights for spec­ta­tors of the race between Webkit and Opera for full Acid3 com­pli­ance. And for some (prob­a­bly much-needed) per­spec­tive, here’s one Mozilla-er’s take on the Acid3 arms race.
  3. JavaScript Talk at North­east­ern: It’s a video of John Resig’s recent talk at North­east­ern on Javascript and jQuery. What are you still doing here?

What I’m Reading: 3/24

Monday, March 24th, 2008
  1. Nine Tech­niques for CSS Image Replace­ment: If you spend any time at all play­ing with CSS, you know that there are a full bajil­lion tech­niques for replac­ing text with an image. It’s a lot to remem­ber, and I’ll fess up that I tend to use what­ever one I hap­pened to have read about most recently rather than tak­ing a con­sid­ered approach to which of them might be the best solu­tion for a given sit­u­a­tion. No more! The above-linked post does a great job of run­ning through the pros and cons of the 9 (9!) major tech­niques, and from now on you (mean­ing “I”) no longer have any excuse to not use the best, seman­tic, most acces­si­ble one at every opportunity.
  2. Drugs, Bugs, and IE8: A pre­dictably good read from Eric Meyer, but I link to it mainly to have an excuse to echo the fol­low­ing point: There are a lot of beta browsers out there right now (one less, now that Safari 3 has shipped). If you’re test­ing your sites in them and some­thing ren­ders in any way other than what you were expect­ing, sub­mit a bug report. Don’t change your code.
  3. Opti­miz­ing Page Load­ing in the Web Browser: For the browser builders, net­work latency is at least as big a prob­lem as con­nec­tion speed.
  4. A Japan­ese RPG Primer: The Essen­tial 20: Last week, Gama­su­tra pub­lished this list of the best of the best in Japan­ese RPGs through­out the ages. It’s a top-20, so it’s not exhaus­tive, but it’s sure as hell exhausting–i’ve been chip­ping away at this beastie since last week. Any­way, if you’re at all into JRPGs, it’s a really fun read. It’s also neat to see some old favorites put into con­text along­side some sem­i­nal games that you may never have been exposed to.