Created
September 27, 2011 17:44
-
-
Save argami/1245721 to your computer and use it in GitHub Desktop.
Right measurement of text width on Javascript using canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
measure_text: (text, font_size, font_family) -> | |
canvas = document.createElement('canvas') | |
ctx = window.canvas.getContext '2d' | |
ctx.font = "#{font_size} #{font_family}" | |
ctx.measureText(text).width |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment