提交 fd92e929 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'v3' of https://github.com/dcloudio/uni-app into v3

......@@ -258,6 +258,18 @@ var methods3 = ['setFillStyle', 'setTextAlign', 'setStrokeStyle', 'setGlobalAlph
'setTextBaseline', 'setLineDash'
]
var tempCanvas
function getTempCanvas () {
if (!tempCanvas) {
tempCanvas = document.createElement('canvas')
}
return tempCanvas
}
function TextMetrics (width) {
this.width = width
}
export class CanvasContext {
constructor (id, pageId) {
this.id = id
......@@ -313,8 +325,15 @@ export class CanvasContext {
}
}
// TODO
// measureText (text) {
// }
measureText (text) {
if (typeof document === 'object') {
var c2d = getTempCanvas().getContext('2d')
c2d.font = this.state.font
return new TextMetrics(c2d.measureText(text).width || 0)
} else {
return new TextMetrics(0)
}
}
save () {
this.actions.push({
method: 'save',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册