@@ -3,6 +3,7 @@ import { PDFEasy } from './runner'
33import path from 'path'
44import { regex } from './utils'
55import { resolveFontName } from './resolvers'
6+ import { FontKey } from './types'
67
78export const setExternalFonts = async ( instance : PDFEasy ) => {
89 const fontTarget = ( str : string ) =>
@@ -30,40 +31,17 @@ export const setExternalFonts = async (instance: PDFEasy) => {
3031 instance . runOptions ?. type === 'server' && ! regex ( ) . http ( font )
3132
3233 for ( const font of instance . fonts ) {
33- const normal = await getBase64ByURL (
34- isLocalServer ( font . normal ) ? fontTarget ( font . normal ) : font . normal ,
35- 'arraybuffer'
36- )
37- const italic = await getBase64ByURL (
38- isLocalServer ( font . italic ) ? fontTarget ( font . italic ) : font . italic ,
39- 'arraybuffer'
40- )
41- const bold = await getBase64ByURL (
42- isLocalServer ( font . bold ) ? fontTarget ( font . bold ) : font . bold ,
43- 'arraybuffer'
44- )
45- const bolditalic = await getBase64ByURL (
46- isLocalServer ( font . bolditalic )
47- ? fontTarget ( font . bolditalic )
48- : font . bolditalic ,
49- 'arraybuffer'
50- )
34+ const keys = [ 'normal' , 'italic' , 'bold' , 'bolditalic' ] as FontKey [ ]
5135
52- await instance . pdfkit ?. registerFont (
53- resolveFontName ( font . name , 'normal' ) ,
54- normal
55- )
56- await instance . pdfkit ?. registerFont (
57- resolveFontName ( font . name , 'italic' ) ,
58- italic
59- )
60- await instance . pdfkit ?. registerFont (
61- resolveFontName ( font . name , 'bold' ) ,
62- bold
63- )
64- await instance . pdfkit ?. registerFont (
65- resolveFontName ( font . name , 'bolditalic' ) ,
66- bolditalic
67- )
36+ for ( const key of keys ) {
37+ const item = font [ key ]
38+
39+ const url = await getBase64ByURL (
40+ isLocalServer ( item ) ? fontTarget ( item ) : item ,
41+ 'arraybuffer'
42+ )
43+
44+ await instance . pdfkit ?. registerFont ( resolveFontName ( font . name , key ) , url )
45+ }
6846 }
6947}
0 commit comments