微信ウィジェットcanvasで描いた文字の右揃え方法

2652 ワード

ctx.fillText('   -Ⅱ ', this.data.windowWidth - ctx.measureText('   -Ⅱ ').width - 20, 110)
ctx.fillText('1 ', this.data.windowWidth - ctx.measureText('1 ').width - 20, 140)
ctx.fillText('20 ', this.data.windowWidth - ctx.measureText('20 ').width - 20, 170)

ctx.measureText()メソッドは,文字段落幅を計算し,自分で計算するよりも信頼できる.自分で計算した文字の大きさを計算した後、右の起点が必ずしも適切ではない.