【问题标题】:Html5 canvas font weight is rendering much heavier than it shouldHtml5 画布字体重量渲染比它应该重得多
【发布时间】:2016-12-21 22:20:57
【问题描述】:
【问题讨论】:
标签:
javascript
css
html
canvas
fonts
【解决方案1】:
字体字符串中的第一个属性是样式,可以是正常、斜体或斜体之一。第二个属性是weight,可以是normal(但不是Regular)。
ctxt.font = "normal 34px Gotham, Helvetica Neue, sans-serif";
应该可以。
【解决方案2】:
HTML 画布字体属性同时包含许多属性。 Regular 不是其中任何一个的有效值。使用例如normal 或 lighter 设置字体粗细。请参阅MDN 或此示例:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.font = "normal 30px Arial";
ctx.fillText("Hello World", 20, 50);
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>