@@ -11,6 +11,8 @@ import { fabric } from 'fabric';
1111import Editor from './Editor' ;
1212type IEditor = Editor ;
1313import { SelectEvent , SelectMode } from './eventType' ;
14+ import { off } from 'process' ;
15+ import { forIn } from 'lodash-es' ;
1416
1517function transformText ( objects : any ) {
1618 if ( ! objects ) return ;
@@ -227,8 +229,11 @@ class ServersPlugin {
227229
228230 saveSvg ( ) {
229231 this . editor . hooksEntity . hookSaveBefore . callAsync ( '' , ( ) => {
230- const option = this . _getSaveSvgOption ( ) ;
231- const dataUrl = this . canvas . toSVG ( option ) ;
232+ const { fontOption, svgOption } = this . _getSaveSvgOption ( ) ;
233+ fabric . fontPaths = {
234+ ...fontOption ,
235+ } ;
236+ const dataUrl = this . canvas . toSVG ( svgOption ) ;
232237 const fileStr = `data:image/svg+xml;charset=utf-8,${ encodeURIComponent ( dataUrl ) } ` ;
233238 this . editor . hooksEntity . hookSaveAfter . callAsync ( fileStr , ( ) => {
234239 downFile ( fileStr , 'svg' ) ;
@@ -263,15 +268,33 @@ class ServersPlugin {
263268
264269 _getSaveSvgOption ( ) {
265270 const workspace = this . canvas . getObjects ( ) . find ( ( item ) => item . id === 'workspace' ) ;
271+ let fontFamilyArry = this . canvas
272+ . getObjects ( )
273+ . filter ( ( item ) => item . type == 'textbox' )
274+ . map ( ( item ) => item . fontFamily ) ;
275+ fontFamilyArry = Array . from ( new Set ( fontFamilyArry ) ) ;
276+
277+ const fontList = this . editor . getPlugin ( 'FontPlugin' ) . cacheList ;
278+
279+ const fontEntry = { } ;
280+ for ( const font of fontFamilyArry ) {
281+ const item = fontList . find ( ( item ) => item . name === font ) ;
282+ fontEntry [ font ] = item . file ;
283+ }
284+
285+ console . log ( '_getSaveSvgOption' , fontEntry ) ;
266286 const { left, top, width, height } = workspace as fabric . Object ;
267287 return {
268- width,
269- height,
270- viewBox : {
271- x : left ,
272- y : top ,
288+ fontOption : fontEntry ,
289+ svgOption : {
273290 width,
274291 height,
292+ viewBox : {
293+ x : left ,
294+ y : top ,
295+ width,
296+ height,
297+ } ,
275298 } ,
276299 } ;
277300 }
@@ -280,6 +303,7 @@ class ServersPlugin {
280303 const workspace = this . canvas
281304 . getObjects ( )
282305 . find ( ( item : fabric . Object ) => item . id === 'workspace' ) ;
306+ console . log ( 'getObjects' , this . canvas . getObjects ( ) ) ;
283307 const { left, top, width, height } = workspace as fabric . Object ;
284308 const option = {
285309 name : 'New Image' ,
0 commit comments