From 4b22bc5cc2394170c22e389fb1b159f96375d43d Mon Sep 17 00:00:00 2001 From: Alice Peng <1399789151@qq.com> Date: Sat, 15 Jun 2024 19:01:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=E5=AF=BC=E5=87=BA?= =?UTF-8?q?svg=E5=AD=97=E4=BD=93=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/ServersPlugin.ts | 38 +++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/packages/core/ServersPlugin.ts b/packages/core/ServersPlugin.ts index 575097f1..51d274c0 100644 --- a/packages/core/ServersPlugin.ts +++ b/packages/core/ServersPlugin.ts @@ -230,8 +230,12 @@ class ServersPlugin { saveSvg() { this.editor.hooksEntity.hookSaveBefore.callAsync('', () => { - const option = this._getSaveSvgOption(); - const dataUrl = this.canvas.toSVG(option); + const { fontOption, svgOption } = this._getSaveSvgOption(); + console.log('saveSvg', fontOption); + fabric.fontPaths = { + ...fontOption, + }; + const dataUrl = this.canvas.toSVG(svgOption); const fileStr = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(dataUrl)}`; this.editor.hooksEntity.hookSaveAfter.callAsync(fileStr, () => { downFile(fileStr, 'svg'); @@ -266,15 +270,34 @@ class ServersPlugin { _getSaveSvgOption() { const workspace = this.canvas.getObjects().find((item) => item.id === 'workspace'); + let fontFamilyArry = this.canvas + .getObjects() + .filter((item) => item.type == 'textbox') + .map((item) => item.fontFamily); + fontFamilyArry = Array.from(new Set(fontFamilyArry)); + + const fontList = this.editor.getPlugin('FontPlugin').cacheList; + + const fontEntry = {}; + for (const font of fontFamilyArry) { + const item = fontList.find((item) => item.name === font); + fontEntry[font] = item.file; + } + const { left, top, width, height } = workspace as fabric.Object; return { - width, - height, - viewBox: { - x: left, - y: top, + fontOption: { + ...fontEntry, + }, + svgOption: { width, height, + viewBox: { + x: left, + y: top, + width, + height, + }, }, }; } @@ -283,6 +306,7 @@ class ServersPlugin { const workspace = this.canvas .getObjects() .find((item: fabric.Object) => item.id === 'workspace'); + const { left, top, width, height } = workspace as fabric.Object; const option = { name: 'New Image', From f2e6384e4ff7b005c109c6b5235883db3de47d87 Mon Sep 17 00:00:00 2001 From: Alice Peng <1399789151@qq.com> Date: Sat, 15 Jun 2024 19:03:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/ServersPlugin.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/ServersPlugin.ts b/packages/core/ServersPlugin.ts index 51d274c0..a83f32a1 100644 --- a/packages/core/ServersPlugin.ts +++ b/packages/core/ServersPlugin.ts @@ -286,9 +286,7 @@ class ServersPlugin { const { left, top, width, height } = workspace as fabric.Object; return { - fontOption: { - ...fontEntry, - }, + fontOption: fontEntry, svgOption: { width, height, From d2fcc4df39213ebbc1dd39cbc328e3b287292c34 Mon Sep 17 00:00:00 2001 From: Alice Peng <1399789151@qq.com> Date: Sun, 16 Jun 2024 21:34:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/ServersPlugin.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/ServersPlugin.ts b/packages/core/ServersPlugin.ts index a83f32a1..10b08532 100644 --- a/packages/core/ServersPlugin.ts +++ b/packages/core/ServersPlugin.ts @@ -273,15 +273,18 @@ class ServersPlugin { let fontFamilyArry = this.canvas .getObjects() .filter((item) => item.type == 'textbox') - .map((item) => item.fontFamily); + .map((item) => (item as fabric.Text).fontFamily || ''); fontFamilyArry = Array.from(new Set(fontFamilyArry)); - const fontList = this.editor.getPlugin('FontPlugin').cacheList; + const fontList = this.editor.getPlugin('FontPlugin')?.cacheList ?? []; + + const fontEntry: Record = {}; - const fontEntry = {}; for (const font of fontFamilyArry) { - const item = fontList.find((item) => item.name === font); - fontEntry[font] = item.file; + if (font) { + const item = fontList.find((item: { name: string }) => item.name === font); + fontEntry[font] = item.file; + } } const { left, top, width, height } = workspace as fabric.Object; From 0554f6b025b6a8479c4f378073ceac8c5366135b Mon Sep 17 00:00:00 2001 From: Alice Peng <1399789151@qq.com> Date: Tue, 18 Jun 2024 10:52:55 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4console=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/ServersPlugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/ServersPlugin.ts b/packages/core/ServersPlugin.ts index 10b08532..65f0b45b 100644 --- a/packages/core/ServersPlugin.ts +++ b/packages/core/ServersPlugin.ts @@ -231,7 +231,6 @@ class ServersPlugin { saveSvg() { this.editor.hooksEntity.hookSaveBefore.callAsync('', () => { const { fontOption, svgOption } = this._getSaveSvgOption(); - console.log('saveSvg', fontOption); fabric.fontPaths = { ...fontOption, };