text-ltr-alignment-test.html 681 B

123456789101112131415161718192021222324252627282930
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Test to ensure left/right and start/end are offset by text width for ltr text</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.fillStyle = 'black';
  12. ctx.font = '20px sans-serif';
  13. ctx.textBaseline = 'top';
  14. var str = 'TEXT';
  15. var wid = ctx.measureText(str).width;
  16. ctx.textAlign = 'right';
  17. ctx.fillText(str, 64+wid, 0);
  18. ctx.textAlign = 'end';
  19. ctx.fillText(str, 64+wid, 20);
  20. ctx.textAlign = 'left';
  21. ctx.fillText(str, 64-wid/2, 40);
  22. </script>
  23. </body>
  24. </html>