Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
67ffea48
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
67ffea48
编写于
2月 07, 2022
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: canvas 支持 hidpi 属性控制是否启用高清处理
上级
c7693164
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
24 addition
and
11 deletion
+24
-11
packages/uni-components/src/helpers/hidpi.js
packages/uni-components/src/helpers/hidpi.js
+6
-4
packages/uni-components/src/vue/canvas/index.tsx
packages/uni-components/src/vue/canvas/index.tsx
+18
-7
未找到文件。
packages/uni-components/src/helpers/hidpi.js
浏览文件 @
67ffea48
...
@@ -17,10 +17,10 @@ export const pixelRatio = __NODE_JS__
...
@@ -17,10 +17,10 @@ export const pixelRatio = __NODE_JS__
return
(
window
.
devicePixelRatio
||
1
)
/
backingStore
return
(
window
.
devicePixelRatio
||
1
)
/
backingStore
})()
})()
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
.
getContext
(
'
2d
'
).
__hidpi__
=
true
canvas
.
getContext
(
'
2d
'
).
__hidpi__
=
hidpi
}
}
let
isHidpi
=
false
let
isHidpi
=
false
...
@@ -129,6 +129,7 @@ export function initHidpi() {
...
@@ -129,6 +129,7 @@ export function initHidpi() {
args
[
1
]
*=
pixelRatio
args
[
1
]
*=
pixelRatio
args
[
2
]
*=
pixelRatio
args
[
2
]
*=
pixelRatio
args
[
3
]
*=
pixelRatio
var
font
=
this
.
font
var
font
=
this
.
font
this
.
font
=
font
.
replace
(
this
.
font
=
font
.
replace
(
...
@@ -153,6 +154,7 @@ export function initHidpi() {
...
@@ -153,6 +154,7 @@ export function initHidpi() {
args
[
1
]
*=
pixelRatio
// x
args
[
1
]
*=
pixelRatio
// x
args
[
2
]
*=
pixelRatio
// y
args
[
2
]
*=
pixelRatio
// y
args
[
3
]
*=
pixelRatio
var
font
=
this
.
font
var
font
=
this
.
font
this
.
font
=
font
.
replace
(
this
.
font
=
font
.
replace
(
...
...
packages/uni-components/src/vue/canvas/index.tsx
浏览文件 @
67ffea48
...
@@ -66,6 +66,10 @@ const props = {
...
@@ -66,6 +66,10 @@ const props = {
type
:
[
Boolean
,
String
],
type
:
[
Boolean
,
String
],
default
:
false
,
default
:
false
,
},
},
hidpi
:
{
type
:
Boolean
,
default
:
true
,
},
}
}
type
Props
=
ExtractPropTypes
<
typeof
props
>
type
Props
=
ExtractPropTypes
<
typeof
props
>
...
@@ -98,7 +102,11 @@ export default /*#__PURE__*/ defineBuiltInComponent({
...
@@ -98,7 +102,11 @@ export default /*#__PURE__*/ defineBuiltInComponent({
})
})
const
{
_listeners
}
=
useListeners
(
props
,
$listeners
,
trigger
)
const
{
_listeners
}
=
useListeners
(
props
,
$listeners
,
trigger
)
const
{
_handleSubscribe
,
_resize
}
=
useMethods
(
canvas
,
actionsWaiting
)
const
{
_handleSubscribe
,
_resize
}
=
useMethods
(
props
,
canvas
,
actionsWaiting
)
useSubscribe
(
useSubscribe
(
_handleSubscribe
as
(
_handleSubscribe
as
(
...
@@ -205,6 +213,7 @@ function useListeners(
...
@@ -205,6 +213,7 @@ function useListeners(
}
}
function
useMethods
(
function
useMethods
(
props
:
Props
,
canvasRef
:
Ref
<
HTMLCanvasElement
|
null
>
,
canvasRef
:
Ref
<
HTMLCanvasElement
|
null
>
,
actionsWaiting
:
Ref
<
boolean
>
actionsWaiting
:
Ref
<
boolean
>
)
{
)
{
...
@@ -213,20 +222,22 @@ function useMethods(
...
@@ -213,20 +222,22 @@ function useMethods(
[
key
:
string
]:
HTMLImageElement
&
{
ready
:
boolean
}
[
key
:
string
]:
HTMLImageElement
&
{
ready
:
boolean
}
}
=
{}
}
=
{}
const
_pixelRatio
=
computed
(()
=>
(
props
.
hidpi
?
pixelRatio
:
1
))
function
_resize
(
size
?:
{
width
:
number
;
height
:
number
})
{
function
_resize
(
size
?:
{
width
:
number
;
height
:
number
})
{
let
canvas
=
canvasRef
.
value
!
let
canvas
=
canvasRef
.
value
!
var
hasChanged
=
var
hasChanged
=
!
size
||
!
size
||
canvas
.
width
!==
Math
.
floor
(
size
.
width
*
pixelRatio
)
||
canvas
.
width
!==
Math
.
floor
(
size
.
width
*
_pixelRatio
.
value
)
||
canvas
.
height
!==
Math
.
floor
(
size
.
height
*
pixelRatio
)
canvas
.
height
!==
Math
.
floor
(
size
.
height
*
_pixelRatio
.
value
)
if
(
!
hasChanged
)
return
if
(
!
hasChanged
)
return
if
(
canvas
.
width
>
0
&&
canvas
.
height
>
0
)
{
if
(
canvas
.
width
>
0
&&
canvas
.
height
>
0
)
{
let
context
=
canvas
.
getContext
(
'
2d
'
)
!
let
context
=
canvas
.
getContext
(
'
2d
'
)
!
let
imageData
=
context
.
getImageData
(
0
,
0
,
canvas
.
width
,
canvas
.
height
)
let
imageData
=
context
.
getImageData
(
0
,
0
,
canvas
.
width
,
canvas
.
height
)
wrapper
(
canvas
)
wrapper
(
canvas
,
props
.
hidpi
)
context
.
putImageData
(
imageData
,
0
,
0
)
context
.
putImageData
(
imageData
,
0
,
0
)
}
else
{
}
else
{
wrapper
(
canvas
)
wrapper
(
canvas
,
props
.
hidpi
)
}
}
}
}
function
actionsChanged
(
function
actionsChanged
(
...
@@ -522,8 +533,8 @@ function useMethods(
...
@@ -522,8 +533,8 @@ function useMethods(
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
*
_pixelRatio
.
value
)
destHeight
=
Math
.
round
(
height
*
pixelRatio
)
destHeight
=
Math
.
round
(
height
*
_pixelRatio
.
value
)
}
else
if
(
!
destWidth
)
{
}
else
if
(
!
destWidth
)
{
destWidth
=
Math
.
round
((
width
/
height
)
*
destHeight
)
destWidth
=
Math
.
round
((
width
/
height
)
*
destHeight
)
}
else
if
(
!
destHeight
)
{
}
else
if
(
!
destHeight
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录