n20-common-lib 2.17.8 → 2.17.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -32,7 +32,14 @@ class Watermark {
|
|
|
32
32
|
ctx.fillStyle = options.textColor
|
|
33
33
|
ctx.textAlign = 'left'
|
|
34
34
|
ctx.textBaseline = 'Middle'
|
|
35
|
-
|
|
35
|
+
// 支持换行符分割文本
|
|
36
|
+
const lines = options.text.split('\n')
|
|
37
|
+
const lineHeight = parseInt(options.font) * 1.2 // 行高设为字体大小的1.2倍
|
|
38
|
+
const startY = can.height / 2 - ((lines.length - 1) * lineHeight) / 2
|
|
39
|
+
|
|
40
|
+
lines.forEach((line, index) => {
|
|
41
|
+
ctx.fillText(line, can.width / 10, startY + index * lineHeight)
|
|
42
|
+
})
|
|
36
43
|
|
|
37
44
|
return can.toDataURL('image/png')
|
|
38
45
|
}
|