Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: canvas fill style 支持的颜色定义错误 #10

Merged
merged 3 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Fixed 错误定义
* [x] fix component 定义
* [x] fix page 定义错误
* [x] fix wx.OnStopCallbackResult (RecorderManager)
* [x] fix wx.Color 定义错误
* [x] fix 支持 canvasContext.setFillStyle() 传入 wx.CanvasGradient 类型
* [x] fix canvasContext.drawImage() 可选 3/5/9 个参数

> [English version](./README-en.md)

Expand Down
33 changes: 33 additions & 0 deletions test/canvas.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Page({
data: {},
getImage() {
const canvasWidth = 420
const ctx = wx.createCanvasContext('share-canvas')
ctx.setFontSize(20)
ctx.setFillStyle('rgb(179,179,179)')
ctx.fillText('test', 0, 20, canvasWidth)
ctx.drawImage('img', 0, 50, canvasWidth, 210)
const gradient = ctx.createLinearGradient(0, 50, 0, 210)
gradient.addColorStop(0.5, 'rgba(0,0,0,0)')
gradient.addColorStop(1, 'rgba(0,0,0,0.4)')
ctx.setFillStyle(gradient)
ctx.fillRect(0, 50, canvasWidth, 210)

ctx.setStrokeStyle('#fff')
ctx.setLineJoin('round')
ctx.setLineWidth(6)
ctx.strokeRect(20, 198, 76, 76)
ctx.drawImage('abc', 20, 198, 76, 76)

ctx.draw(false, () => {
wx.canvasToTempFilePath({
canvasId: 'share-canvas',
quality: 1,
success: ({ tempFilePath }) => {
this.setData({ shareImage: tempFilePath })
},
})
})
},
})
17 changes: 15 additions & 2 deletions types/wx/lib.wx.api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,8 @@ backgroundAudioManager.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb
* | Yellow | #FFFF00 |
* | YellowGreen | #9ACD32 | */
type Color =
|'AliceBlue'
| string
mutoe marked this conversation as resolved.
Show resolved Hide resolved
| 'AliceBlue'
| 'AntiqueWhite'
| 'Aqua'
| 'Aquamarine'
Expand Down Expand Up @@ -5308,6 +5309,18 @@ wx.chooseImage({

```
* ![] */
drawImage(
imageResource: string,
sx: number,
sy: number
): void;
drawImage(
imageResource: string,
sx: number,
sy: number,
sWidth: number,
sHeight: number,
): void;
drawImage(
/** 所要绘制的图片资源 */
imageResource: string,
Expand Down Expand Up @@ -5674,7 +5687,7 @@ ctx.draw()
/** [Color]
*
* 填充的颜色,默认颜色为 black。 */
color: Color,
color: Color | wx.CanvasGradient,
): void;
/** [CanvasContext.setFontSize(number fontSize)](CanvasContext.setFontSize.md)
*
Expand Down