Featc:删除重复的exportPadding配置,改为使用exportPaddingX和exportPaddingY配置;去除导出图片时的双重padding设置
This commit is contained in:
parent
64209a6392
commit
3f659af1e1
@ -8,7 +8,6 @@ class Export {
|
|||||||
// 构造函数
|
// 构造函数
|
||||||
constructor(opt) {
|
constructor(opt) {
|
||||||
this.mindMap = opt.mindMap
|
this.mindMap = opt.mindMap
|
||||||
this.exportPadding = this.mindMap.opt.exportPadding
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导出
|
// 导出
|
||||||
@ -51,14 +50,17 @@ class Export {
|
|||||||
// svg转png
|
// svg转png
|
||||||
svgToPng(svgSrc, transparent) {
|
svgToPng(svgSrc, transparent) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
// const { exportPaddingX, exportPaddingY } = this.mindMap.opt
|
||||||
|
let exportPaddingX = 0
|
||||||
|
let exportPaddingY = 0
|
||||||
const img = new Image()
|
const img = new Image()
|
||||||
// 跨域图片需要添加这个属性,否则画布被污染了无法导出图片
|
// 跨域图片需要添加这个属性,否则画布被污染了无法导出图片
|
||||||
img.setAttribute('crossOrigin', 'anonymous')
|
img.setAttribute('crossOrigin', 'anonymous')
|
||||||
img.onload = async () => {
|
img.onload = async () => {
|
||||||
try {
|
try {
|
||||||
let canvas = document.createElement('canvas')
|
let canvas = document.createElement('canvas')
|
||||||
canvas.width = img.width + this.exportPadding * 2
|
canvas.width = img.width + exportPaddingX * 2
|
||||||
canvas.height = img.height + this.exportPadding * 2
|
canvas.height = img.height + exportPaddingY * 2
|
||||||
let ctx = canvas.getContext('2d')
|
let ctx = canvas.getContext('2d')
|
||||||
// 绘制背景
|
// 绘制背景
|
||||||
if (!transparent) {
|
if (!transparent) {
|
||||||
@ -71,8 +73,8 @@ class Export {
|
|||||||
0,
|
0,
|
||||||
img.width,
|
img.width,
|
||||||
img.height,
|
img.height,
|
||||||
this.exportPadding,
|
exportPaddingX,
|
||||||
this.exportPadding,
|
exportPaddingY,
|
||||||
img.width,
|
img.width,
|
||||||
img.height
|
img.height
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user