我正在尝试做一些基于句子中字符数量的动态规划。英语字母表中哪个字母在屏幕上占像素最多?
当前回答
大写的“M”通常是最宽的。
其他回答
我认为字母W是最宽的。
这取决于字体。例如,交叉0所占的空间要比普通0大得多。
但如果要猜的话,我会选X或B。
大写的“M”通常是最宽的。
那么程序化的解决方案呢?
var capsIndex = 65; var smallIndex = 97 var div = document.createElement('div'); div.style.float = 'left'; document.body.appendChild(div); var highestWidth = 0; var elem; for(var i = capsIndex; i < capsIndex + 26; i++) { div.innerText = String.fromCharCode(i); var computedWidth = window.getComputedStyle(div, null).getPropertyValue("width"); if(highestWidth < parseFloat(computedWidth)) { highestWidth = parseFloat(computedWidth); elem = String.fromCharCode(i); } } for(var i = smallIndex; i < smallIndex + 26; i++) { div.innerText = String.fromCharCode(i); var computedWidth = window.getComputedStyle(div, null).getPropertyValue("width"); if(highestWidth < parseFloat(computedWidth)) { highestWidth = parseFloat(computedWidth); elem = String.fromCharCode(i); } } div.innerHTML = '<b>' + elem + '</b>' + ' won';
想知道真正最长的字形,而不仅仅是猜测? 我说的不仅仅是字母、数字和常用符号(!, @等等)。我指的是UTF-16的32,834个字符中最长的字形。 所以我从@NK的回答开始,他有一个程序化的解决方案,并进行了修改:
var capsIndex = 65; var smallIndex = 97; var div = document.createElement('div'); div.style.float = 'left'; document.body.appendChild(div); var highestWidth = 0; var elem; for(var i = capsIndex; i < 32834; i++) { div.innerText = String.fromCharCode(i); var computedWidth = window.getComputedStyle(div, null).getPropertyValue("width"); if(highestWidth < parseFloat(computedWidth)) { highestWidth = parseFloat(computedWidth); elem = String.fromCharCode(i); } } div.innerHTML = '<b>' + elem + '</b>' + ' won';
在运行并等待(等待)之后,它给出输出won。 这就是UTF-32中最长的字符! 请注意,在大多数字体上,最长的字形是﷽,但有些字体(特别是单行字体)与运行程序时使用的字体重叠。