Advertisement
476179

I-RenderingText

Dec 11th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <title>rendering text</title>
  7. </head>
  8. <canvas id="canvas" width="640" height="480" style="border: 1px solid black;"></canvas>
  9. <body>
  10.  
  11. <script>
  12.  
  13. var canvas1 = document.getElementById("canvas");
  14. var dt = canvas1.getContext("2d");
  15.  
  16. var theText = "Drawing Text on a canvas";
  17.  
  18. //draw the text uisng default settings
  19. dt.fillText(theText,20,20);
  20.  
  21. //draw text changing font info
  22. dt.font = "25pt Georgia";
  23. dt.fillText(theText,20,60)
  24.  
  25. //draw text with fill colour
  26. dt.fillStyle = "blue";
  27. dt.fillText(theText,20,100);
  28.  
  29. //draw text with both a stroke and fill with opacity set
  30. dt.font = "32pt Verdana";
  31. dt.fillStyle ="#663399";
  32. dt.strokeStyle = "rgba(0,0,255,0.8)";
  33. dt.fillText(theText,20,160);
  34. dt.strokeText(theText,20,160);
  35.  
  36.  
  37. //draw line under text
  38. var textW = dt.measureText(theText);
  39. dt.beginPath();
  40. dt.strokeStyle = "Black";
  41. dt.moveTo(20,170);
  42. dt.lineTo(textW.width+20,170);
  43. dt.stroke();
  44. </script>
  45.  
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement