Advertisement
antiquekid3

Character Width Generator

Oct 26th, 2014
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <canvas id="myCanvas" width="0" height="0" style="border:1px solid #d3d3d3;">
  6. Your browser does not support the HTML5 canvas tag.</canvas>
  7. <pre>
  8. <script>
  9.  
  10. var c = document.getElementById("myCanvas");
  11. var ctx = c.getContext("2d");
  12. ctx.font = "12pt Arial";
  13. for (character = 32; character < 127; character++)
  14. {
  15.   var txt = ""
  16.   for (i = 0; i < 128; i++)
  17.   {
  18.      txt = txt + String.fromCharCode(character);
  19.   }
  20.   document.writeln(String.fromCharCode(character), ": ", ctx.measureText(txt).width / 128);
  21. }
  22.  
  23. </script>
  24. </pre>
  25. </body>
  26. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement