text-context-state-test.html 794 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>text to ensure text attributes are saved in the context state</title>
  5. </head>
  6. <body>
  7. <canvas id="c" width="128" height="64" style="direction:ltr"></canvas>
  8. <script type="text/javascript">
  9. var canvas = document.getElementById('c');
  10. var ctx = canvas.getContext('2d');
  11. ctx.textAlign = 'left';
  12. ctx.textBaseline = 'top';
  13. ctx.font = '16px sans-serif';
  14. ctx.save();
  15. ctx.textAlign = 'right';
  16. ctx.textBaseline = 'alphabetic';
  17. ctx.font = '24px serif';
  18. ctx.save();
  19. ctx.textAlign = 'center';
  20. ctx.textBaseline = 'bottom';
  21. ctx.font = '10px sans-serif';
  22. ctx.fillText('something', 80, 60);
  23. ctx.restore();
  24. ctx.fillText('other thing', 128, 40);
  25. ctx.restore();
  26. ctx.fillText('yet another thing', 0, 0);
  27. </script>
  28. </body>
  29. </html>