提交 ad81ca68 编写于 作者: D DCloud_LXH

feat: canvas 支持 hidpi 属性控制是否启用高清处理

上级 b1132900
......@@ -105,6 +105,7 @@ if (pixelRatio !== 1) {
args[1] *= pixelRatio
args[2] *= pixelRatio
args[3] *= pixelRatio
// Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值
var font = this.__font__ || this.font
......@@ -130,6 +131,7 @@ if (pixelRatio !== 1) {
args[1] *= pixelRatio // x
args[2] *= pixelRatio // y
args[3] *= pixelRatio // y
// Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值
var font = this.__font__ || this.font
......@@ -157,11 +159,11 @@ if (pixelRatio !== 1) {
})(proto.drawImage)
}
export function wrapper (canvas) {
canvas.width = canvas.offsetWidth * pixelRatio
canvas.height = canvas.offsetHeight * pixelRatio
canvas.__hidpi__ = true
export function wrapper (canvas, hidpi = true) {
canvas.width = canvas.offsetWidth * (hidpi ? pixelRatio : 1)
canvas.height = canvas.offsetHeight * (hidpi ? pixelRatio : 1)
canvas.__hidpi__ = hidpi
// 避免低版本安卓上 context 实例被回收
canvas.__context2d__ = canvas.getContext('2d')
canvas.__context2d__.__hidpi__ = true
canvas.__context2d__.__hidpi__ = hidpi
}
......@@ -78,6 +78,10 @@ export default {
disableScroll: {
type: [Boolean, String],
default: false
},
hidpi: {
type: Boolean,
default: true
}
},
data () {
......@@ -110,6 +114,9 @@ export default {
$listeners[event] = eventHandler
})
return $listeners
},
pixelRatio () {
return this.hidpi ? pixelRatio : 1
}
},
created () {
......@@ -135,15 +142,15 @@ export default {
},
_resize (size) {
var canvas = this.$refs.canvas
var hasChanged = !size || (canvas.width !== Math.floor(size.width * pixelRatio) || canvas.height !== Math.floor(size.height * pixelRatio))
var hasChanged = !size || (canvas.width !== Math.floor(size.width * this.pixelRatio) || canvas.height !== Math.floor(size.height * this.pixelRatio))
if (!hasChanged) return
if (canvas.width > 0 && canvas.height > 0) {
var context = canvas.getContext('2d')
var imageData = context.getImageData(0, 0, canvas.width, canvas.height)
wrapper(canvas)
wrapper(canvas, this.hidpi)
context.putImageData(imageData, 0, 0)
} else {
wrapper(canvas)
wrapper(canvas, this.hidpi)
}
},
_touchmove (event) {
......@@ -377,8 +384,8 @@ export default {
height = height ? Math.min(height, maxHeight) : maxHeight
if (!hidpi) {
if (!destWidth && !destHeight) {
destWidth = Math.round(width * pixelRatio)
destHeight = Math.round(height * pixelRatio)
destWidth = Math.round(width * this.pixelRatio)
destHeight = Math.round(height * this.pixelRatio)
} else if (!destWidth) {
destWidth = Math.round(width / height * destHeight)
} else if (!destHeight) {
......
......@@ -6,7 +6,7 @@ const schema = {
name: {
givenName: 'firstName',
middleName: 'middleName',
familyName: 'lastName',
familyName: 'lastName'
},
nickname: 'nickName',
photos: {
......@@ -84,7 +84,7 @@ const schema = {
const keepFields = ['type', 'preferred']
function buildContact(contact, data, schema) {
function buildContact (contact, data, schema) {
let hasValue = 0
Object.keys(schema).forEach(contactKey => {
const dataKey = schema[contactKey]
......@@ -127,7 +127,7 @@ function buildContact(contact, data, schema) {
return hasValue
}
export function addPhoneContact(data, callbackId) {
export function addPhoneContact (data, callbackId) {
plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, (addressbook) => {
!data.photoFilePath && (data.photoFilePath = '')
const contact = addressbook.create()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册