Letter spacing and Font size for limited amount of characters

OK, I have a few dynamic controls on my page which have limited amount of letters I can enter. So I need to make a formula which calculates the letter spacing using the height and width of the control and a number of max letters. I need to also calculate the Font size using the same variables. The result is that the textbox is filled with the text completly and all the possible letters are printed and it fits.

So let me try to represent this in code so people can relate.

H = getHeight();
W = getWidth();
TheItemT.Style.Add("letter-spacing", ((18 * (W / 18) / TheItemT.MaxLength) * 0.46) + "px");
//This was my prototype. It works in some cases where the control isnt too big. 18 and 0.46 are random variables that make it look good.
TheItemT.Style.Add(HtmlTextWriterStyle.FontSize, (18 * (W / 18) / TheItemT.MaxLength).ToString() + "px");

Problem with my code is that it doesn't use the height and I can't wrap around my head around the math to make it work. To be honest I pulled this out of my ass and it sort of worked.

Ideas anyone?

链接地址: http://www.djcxy.com/p/87506.html

上一篇: 使用一致的软包装以HTML格式进行响应式字体调整

下一篇: 字母间距和字体大小以限制字符数量