1- import { PDFEasyDefaults , regex } from '../utils/defines'
1+ import { PDFEasyDefaults } from '../utils/defines'
22import { getDataUri } from '../utils/request'
33import { Fonts , TextAlign } from '../utils/types'
4- import SVGtoPDF from 'svg-to-pdfkit'
54import { getCorrectFontFamily } from './transform'
6- import { getImageRaw } from '../content/image'
5+ import { getImageRaw , SvgToPNG } from '../content/image'
76
87export interface ContentText {
98 fontSize ?: number
@@ -136,11 +135,11 @@ export const resolveContent = async (
136135 }
137136
138137 const addImage = async ( ) => {
139- const style = content . image as ContentImage
138+ const style = content . svg ? content . svg : content . image as ContentImage
140139
141140 if ( ! content . raw ) return
142141
143- const { raw } = await getImageRaw ( content . raw )
142+ const { raw } = content . svg ? await SvgToPNG ( content . raw ) : await getImageRaw ( content . raw )
144143
145144 app . image (
146145 raw ,
@@ -159,51 +158,12 @@ export const resolveContent = async (
159158 )
160159 }
161160
162- const addSvg = async ( ) => {
163- const style = content . svg as ContentSVG
164-
165- if ( ! content . raw ) return
166-
167- const make = async ( value : string ) => {
168- await SVGtoPDF (
169- app ,
170- value ,
171- style . x || undefined ,
172- style . y || undefined ,
173- style . size
174- ? {
175- width : style . size ?. width || undefined ,
176- height : style . size ?. height || undefined ,
177- }
178- : { }
179- )
180- }
181-
182- // svg recording
183- if (
184- content . raw . match (
185- / < s v g \b [ ^ > ] * ?(?: v i e w B o x = \" ( \b [ ^ " ] * ) \" ) ? > ( [ \s \S ] * ?) < \/ s v g > / g
186- )
187- ) {
188- make ( content . raw )
189-
190- return
191- }
192-
193- if ( content . raw . match ( / h t t p s ? : \/ \/ / g) ) {
194- await getDataUri ( content . raw ) . then ( ( data : string ) => {
195- make ( data )
196- } )
197- }
198- }
199-
200161 if ( ! content . stack && ! content . text && ! content . image && ! content . svg ) {
201162 addSimpleText ( )
202163 return
203164 }
204165
205166 if ( content . stack ) await addStack ( )
206167 if ( content . text ) await addText ( )
207- if ( content . image ) await addImage ( )
208- if ( content . svg ) await addSvg ( )
168+ if ( content . image || content . svg ) await addImage ( )
209169}
0 commit comments