提交 ad81ca68 编写于 作者: D DCloud_LXH

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

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