Commit 36fbfd31 by 张立顺

调整文件名字

1 parent 89bd9f45
...@@ -8,10 +8,8 @@ class Draw { ...@@ -8,10 +8,8 @@ class Draw {
[_canvasObject_] = null; [_canvasObject_] = null;
[_canvas_] = null [_canvas_] = null
constructor(canvasObject) { constructor(canvasObject) {
wx.getSystemInfo().then(({ wx.getSystemInfo().then(({ pixelRatio }) => {
pixelRatio // console.log(pixelRatio)
}) => {
console.log(pixelRatio)
this[_canvasObject_] = canvasObject this[_canvasObject_] = canvasObject
this[_pixelRatio_] = canvasObject.pixelRatio || pixelRatio || 2 this[_pixelRatio_] = canvasObject.pixelRatio || pixelRatio || 2
const height = this.toRpx(canvasObject.height), const height = this.toRpx(canvasObject.height),
...@@ -38,14 +36,7 @@ class Draw { ...@@ -38,14 +36,7 @@ class Draw {
drawImages(imageParams, callback) { drawImages(imageParams, callback) {
this[_ctx_].beginPath() this[_ctx_].beginPath()
this[_ctx_].save() this[_ctx_].save()
let { let { borderRadius, height, width, url, x, y } = imageParams
borderRadius,
height,
width,
url,
x,
y
} = imageParams
height = this.toRpx(height) height = this.toRpx(height)
width = this.toRpx(width) width = this.toRpx(width)
x = this.toRpx(x) x = this.toRpx(x)
...@@ -78,13 +69,7 @@ class Draw { ...@@ -78,13 +69,7 @@ class Draw {
if (fontSize) this[_ctx_].font = `${fontSize}px${font}` if (fontSize) this[_ctx_].font = `${fontSize}px${font}`
return this[_ctx_].measureText(text).width return this[_ctx_].measureText(text).width
} }
drawFill({ drawFill({ x, y, width, height, color }) {
x,
y,
width,
height,
color
}) {
height = this.toRpx(height) height = this.toRpx(height)
width = this.toRpx(width) width = this.toRpx(width)
x = this.toRpx(x) x = this.toRpx(x)
...@@ -97,25 +82,8 @@ class Draw { ...@@ -97,25 +82,8 @@ class Draw {
this[_ctx_].save() this[_ctx_].save()
} }
drawText(textParams) { drawText(textParams) {
let { let { textDecoration, textBaseline, lineHeight, fontWeight, textAlign, textWidth, maxWidth, fontSize, lastFont, opacity, lineNum, width, color, text, x, y } = textParams,
textDecoration, font = this[_ctx_].font.split('px')[1]
textBaseline,
lineHeight,
fontWeight,
textAlign,
textWidth,
maxWidth,
fontSize,
lastFont,
opacity,
lineNum,
width,
color,
text,
x,
y
} = textParams,
font = this[_ctx_].font.split('px')[1]
textAlign = textAlign || 'left' textAlign = textAlign || 'left'
textBaseline = textBaseline || 'normal' textBaseline = textBaseline || 'normal'
opacity = typeof opacity === 'number' ? opacity : 1 opacity = typeof opacity === 'number' ? opacity : 1
...@@ -258,15 +226,7 @@ class Draw { ...@@ -258,15 +226,7 @@ class Draw {
} }
drawLine(lineParams, callback) { drawLine(lineParams, callback) {
this[_ctx_].beginPath() this[_ctx_].beginPath()
let { let { opacity, startX, startY, width, color, endX, endY } = lineParams
opacity,
startX,
startY,
width,
color,
endX,
endY
} = lineParams
startX = this.toRpx(startX) startX = this.toRpx(startX)
startY = this.toRpx(startY) startY = this.toRpx(startY)
width = this.toRpx(width) width = this.toRpx(width)
...@@ -283,12 +243,7 @@ class Draw { ...@@ -283,12 +243,7 @@ class Draw {
if (callback) callback() if (callback) callback()
} }
setLineY = params => { setLineY = params => {
let { let { textDecoration, textBaseline, fontSize, y } = params
textDecoration,
textBaseline,
fontSize,
y
} = params
let type = { let type = {
underline: { underline: {
top: y + fontSize, top: y + fontSize,
...@@ -312,11 +267,7 @@ class Draw { ...@@ -312,11 +267,7 @@ class Draw {
return type[textDecoration][textBaseline] return type[textDecoration][textBaseline]
} }
setLineX({ setLineX({ textAlign, text, x }) {
textAlign,
text,
x
}) {
let textWidth = this.getTextWidth(text) let textWidth = this.getTextWidth(text)
let type = { let type = {
left: x, left: x,
...@@ -326,13 +277,7 @@ class Draw { ...@@ -326,13 +277,7 @@ class Draw {
return type[textAlign] return type[textAlign]
} }
drawRadiusRect({ drawRadiusRect({ borderRadius, height, width, x, y }, callBack) {
borderRadius,
height,
width,
x,
y
}, callBack) {
let radius = typeof borderRadius === 'string' ? ((Number(borderRadius.split('%')[0]) / 100) * width) / 2 : borderRadius / 2 let radius = typeof borderRadius === 'string' ? ((Number(borderRadius.split('%')[0]) / 100) * width) / 2 : borderRadius / 2
radius = radius || 0 radius = radius || 0
this[_ctx_].beginPath() this[_ctx_].beginPath()
...@@ -343,12 +288,7 @@ class Draw { ...@@ -343,12 +288,7 @@ class Draw {
} }
if (callBack) callBack() if (callBack) callBack()
} }
getFontWidth({ getFontWidth({ textAlign, fontSize, text, x }) {
textAlign,
fontSize,
text,
x
}) {
let type = { let type = {
left: x, left: x,
center: x - (fontSize * text.length) / 2, center: x - (fontSize * text.length) / 2,
...@@ -358,12 +298,7 @@ class Draw { ...@@ -358,12 +298,7 @@ class Draw {
} }
drawDecoration(params) { drawDecoration(params) {
let { let { newText, opacity, y, x } = params
newText,
opacity,
y,
x
} = params
let lineX = x let lineX = x
let lineY = y let lineY = y
lineX = this.setLineX(params) lineX = this.setLineX(params)
...@@ -420,4 +355,4 @@ const createLocalImg = (url, callBack) => { ...@@ -420,4 +355,4 @@ const createLocalImg = (url, callBack) => {
} }
}) })
} }
export default Draw
\ No newline at end of file \ No newline at end of file
export default Draw
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!