const ctx = canvas.getContext("2d");
const text = ctx.measureText("foo");
text.actualBoundingBoxAscent;
对应的test.js文件是:
wx.createSelectorQuery()
.select('#secondCut')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
const cdx = canvas.getContext('2d')
let width = res[0].width
let height = res[0].height
const dpr = wx.getWindowInfo().pixelRatio
canvas.width = width * dpr
canvas.height = height * dpr
cdx.scale(dpr, dpr)
cdx.clearRect(0, 0, width, height)
cdx.rect(0, 0, width, height);
cdx.fillStyle="white";
cdx.fill();
cdx.font="200px bolder";
cdx.fillStyle = "black";
cdx.textAlign="center";
let measureText=cdx.measureText("测试文字")
console.log(measureText)
})
},
对应的test.wxml内容是:
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
开发者工具中调用后获取的内容参考第一个图
在真机调试中获取的内容参考第二图
也就是说measureText两次调用返回的内容不一样
无法在真机上获取actualBoundingBoxAscent的值