[微信小程序]canvas字体没法加错,canvas设置字体大小有问题 [对于问题,给我一个另类的答案吧!]+ 查看更多
[微信小程序]canvas字体没法加错,canvas设置字体大小有问题 [对于问题,给我一个另类的答案吧!]
+ 查看更多
在真机上有下面几个问题
canvas设置自提大小有问题
let ctx = wx.createCanvasContext( 'canvas' );
let sysres = wx.getSystemInfoSync();
let rate = sysres.windowWidth / 750;
ctx.font = `normal bold ${34 * rate}px sans-serif`;
ctx.setFillStyle( '#333333' );
ctx.fillText( this .data.title, 40 *rate, 100 * rate);
ctx.font = `normal normal ${30 * rate}px sans-serif`;
ctx.fillText( this .data.content, 40 * rate, 200 * rate);
ctx.draw();
|
这样设置的,在真机上字体很小,必须单独在ctx.font后面再设置字体大小才没有问题
ctx.setFontSize(34 * rate); ctx.setFontSize(30 * rate); |
还有加粗也不行
代码是这样的,想要标题加粗,内容不加粗,开发工具正常,但是真机上都没加粗
let ctx = wx.createCanvasContext( 'canvas' );
let sysres = wx.getSystemInfoSync(); let rate = sysres.windowWidth / 750; ctx.font = `normal bold ${34 * rate}px sans-serif`; ctx.setFontSize(34 * rate); ctx.setFillStyle( '#333333' );
ctx.fillText( this .data.title, 40 *rate, 100 * rate);
ctx.font = `normal normal ${30 * rate}px sans-serif`; ctx.setFontSize(30 * rate); ctx.fillText( this .data.content, 40 * rate, 200 * rate);
ctx.draw(); |
开发工具里面是这样的