書式
コンテキスト.font = 書体設定
説明
fillText()および
strokeText()で描画する書体や文字形状、サイズなどを指定します。設定できる内容はスタイルシートでのfontプロパティの指定と同じです。例えば正体で24ptにする場合はfont="24pt normal"のように指定します。font="italic 24pt 'Time-Bold'"であれば斜体で24ptサイズ、書体をTime-Boldにします。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample</title>
<script>
window.onload = function(){
var canvasObj = document.getElementById("imgCanvas");
var context = canvasObj.getContext("2d");
context.fillStyle = "rgba(255,0,0,1)";
context.font = "italic 36pt 'Palatino-Bold'";
context.fillText("Sample Text", 30, 100);
}
</script>
</head>
<body>
<h1>Sample</h1>
<canvas id="imgCanvas" width="320" height="240" style="border:1px black solid"></canvas>
</body>
</html>