-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfont_aspect_ratio.html
More file actions
32 lines (31 loc) · 950 Bytes
/
font_aspect_ratio.html
File metadata and controls
32 lines (31 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<html>
<head>
<title>Font Aspect Ratio</title>
<style>
#testletterholder{
float:left;
}
</style>
</head>
<body>
<div id="testletterholder"></div>
<div style="clear:both;"></div>
<div>Aspect ratio is:</div>
<div id="test_result"></div>
<script>
var FontSize = 12;
var div_holder = document.getElementById("testletterholder");
div_holder.innerHTML = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
div_holder.style.fontFamily = "courier";
div_holder.style.lineHeight = "1";
div_holder.style.fontSize = (FontSize*10)+"px";
setTimeout(function(){
HolderStyle = window.getComputedStyle(div_holder, null);
var Width = HolderStyle.width.replace(/[^0-9]/g, "")/div_holder.innerHTML.length;
var Height = HolderStyle.height.replace(/[^0-9]/g, "");
var AspectRatio = Width/Height;
document.getElementById("test_result").innerHTML = AspectRatio;
},10);
</script>
</body>
</html>