提交 dadad203 编写于 作者: Q qiang

fix: App、H5 端移除 CanvasContext.measureText 异步方法

上级 b59e1bce
......@@ -328,38 +328,16 @@ export class CanvasContext {
}
}
measureText (text, callback) {
measureText (text) {
const font = this.state.font
let width
if (__PLATFORM__ === 'h5') {
const width = measureText(text, font)
const textMetrics = new TextMetrics(width)
if (typeof callback === 'function') {
setTimeout(() => callback(textMetrics), 0)
}
return textMetrics
width = measureText(text, font)
} else {
let textMetrics = new TextMetrics(0)
if (typeof callback === 'function') {
const callbackId = canvasEventCallbacks.push(function ({ width }) {
callback(new TextMetrics(width))
})
operateCanvas(this.id, this.pageId, 'measureText', {
text,
font,
callbackId
})
} else {
const webview = plus.webview.getWebviewById(String(this.pageId))
if (webview && webview.evalJSSync) {
const js = `(${measureText.toString()})(${JSON.stringify(text)},${JSON.stringify(font)})`
const width = webview.evalJSSync(js) || 0
textMetrics = new TextMetrics(width)
} else {
console.error('warning: measureText missing required arguments: callback')
}
}
return textMetrics
const webview = plus.webview.getWebviewById(String(this.pageId))
width = webview.evalJSSync(`(${measureText.toString()})(${JSON.stringify(text)},${JSON.stringify(font)})`)
}
return new TextMetrics(width)
}
save () {
......
......@@ -277,22 +277,6 @@ export default {
}, this.$page.id)
}
},
measureText ({
text,
font,
callbackId
}) {
const canvas = getTempCanvas()
const c2d = canvas.getContext('2d')
c2d.font = font
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'measureText:ok',
width: c2d.measureText(text).width || 0
}
}, this.$page.id)
},
preloadImage: function (actions) {
var self = this
actions.forEach(function (action) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册