Syntax
ctx.measureText(text);
Parameters
- text
- The text to measure.
Return value
A TextMetrics
object.
Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function draw() { var ctx = document.getElementById( 'canvas' ).getContext( '2d' ); ctx.font = "48px serif" ; ctx.fillText( "Hello world" , 10, 50); ctx.font = "48px serif" ; ctx.strokeText( "Hello world" , 10, 100); ctx.font = "48px serif" ; ctx.fillText(ctx.measureText( "Hello world" ).width, 10, 150); ctx.font = "48px serif" ; ctx.fillText( "Hello world" , 10, 200, 100); } |
Demo
'Develop > canvas' 카테고리의 다른 글
33 .clip() - 잘라내기 (0) | 2015.08.10 |
---|---|
32. globalCompositeOperation - 색상 블렌딩모드 (합성) (0) | 2015.08.10 |
30. strokeText() - 라인으로 글쓰기 (0) | 2015.08.10 |
29. fillText() - 글자그리기 (0) | 2015.08.10 |
28. transform() - 회전 (0) | 2015.08.10 |