tags:

views:

50

answers:

3

I'm using JavaScript to inflate a span of left-aligned text until it fills its container, or until it reaches variable thresholds in either height or width. This process results in a widely varying font-size.

My problem is that, with certain characters, there is a small amount of padding on the left... and while normally it's not noticeable, with very large font sizes it can reach 10 pixels or more.

I whipped up a page to demonstrate the effect on various characters: http://jsfiddle.net/kBu7S/

The text span exists in a design where every other element going down the page is aligned pixel for pixel to the left edge, so it's very visually distracting with the larger text sizes.

Can anyone think of a way to calculate the amount of padding, so that I can bump the relative position of the span? Or maybe there's even a CSS solution? (letter-spacing and word-spacing have no effect.)

I'll admit that even a dirty solution seems pretty unlikely... thanks for your consideration though.

A: 

Well, you could build a script to generate an image using the same typeface with the same size (black on white background) and read the bitmap to count the distance from the left edge to the first black pixel.

It's kind of overkill, but it's the only thing I can think of.

Júlio Santos
this whole question is kind of overkill :) thanks for the idea.
JKS
A: 

This worked on the fiddle:

#text:first-letter { margin-left:-3px}

You could expand that to a class...

.fontCorrection:first-letter { margin-left:-3px }

...and apply it as appropriate.

Steve
Didn't work for me. Just shifted the letters to the left, but if you grow their size, there is still a varying amount of gap.
davr
Then use Javascript to alter the CSS rule in the increase function. Where's your solution?
Steve
Actually `#text:first-letter { margin-left: -0.05em; }` is not a bad approximation — but still not quite close enough. thanks for the thought...
JKS
OK mate thanks to you also. :)
Steve
+2  A: 

The padding is often called the "shoulder" of the type, and it's intrinsic to the design of the typeface. There's no simple way to counter-act it, because it's there for optical reasons, to give the type the right spacing. After all, if you type IIIIIII, you need to have some spacing between the capital I's, and that only comes from this padding. Other characters, like WWWWWW, need none.

Your best bet is to do an experiment with your typeface, and measure the actual padding on each character, then build a table mapping characters to their paddings. Then you can adjust the character's position. This is a lot of work, but I don't know what else you can do.

Ned Batchelder
Shoulder! That's what it's called. I can't even tell you how many different ways I tried to google the name of that padding. I just got home from work, but your idea about mapping the different shoulders (maybe as percentages?) is a good starting point for the morning...
JKS
Wouldn't that only work locally?
Steve
"locally"? I'm not sure what you mean.
Ned Batchelder
Based on two samples per letter! So far the largest deviation I've seen is 1px — close enough! `var helveticaLeftShoulders={a:12/667,b:89/848,c:30/529,d:95/892,e:112/911,f:51/380,g:15/259,h:76/723,i:283/834,j:0.026,k:95/868,l:73/556,m:10/119,n:52/515,o:1/21,p:112/911,q:1/21,r:87/740,s:28/415,t:1/47,u:80/723,v:24/667,w:1/59,y:13/510,x:13/510,z:20/611};`
JKS
(those measurements are only for capitals, btw!)
JKS