@@ -187,21 +187,20 @@ func FormFontResDict(xRefTable *model.XRefTable) (types.Dict, error) {
187187 return xRefTable .DereferenceDict (o )
188188}
189189
190- func formFontIndRef (xRefTable * model.XRefTable , fontID string ) (* types.IndirectRef , error ) {
191- d , err := FormFontResDict (xRefTable )
192- if err != nil {
193- return nil , err
190+ func formFontIndRef (xRefTable * model.XRefTable , fontID string ) * types.IndirectRef {
191+
192+ indRef , ok := xRefTable .FillFonts [fontID ]
193+ if ok {
194+ return & indRef
194195 }
195196
196- for k , v := range d {
197- //fmt.Printf("%s %s\n", k, v)
197+ for k , v := range xRefTable .FillFonts {
198198 if strings .HasPrefix (k , fontID ) || strings .HasPrefix (fontID , k ) {
199- indRef , _ := v .(types.IndirectRef )
200- return & indRef , nil
199+ return & v
201200 }
202201 }
203202
204- return nil , nil
203+ return nil
205204}
206205
207206func FontIndRef (fName string , ctx * model.Context , fonts map [string ]types.IndirectRef ) (* types.IndirectRef , error ) {
@@ -234,87 +233,6 @@ func FontIndRef(fName string, ctx *model.Context, fonts map[string]types.Indirec
234233 return nil , nil
235234}
236235
237- func ensureCorrectFontIndRef (
238- ctx * model.Context ,
239- fontIndRef * * types.IndirectRef ,
240- fName string ,
241- fonts map [string ]types.IndirectRef ) error {
242-
243- d , err := ctx .DereferenceDict (* * fontIndRef )
244- if err != nil {
245- return err
246- }
247-
248- if enc := d .NameEntry ("Encoding" ); enc != nil && * enc == "Identity-H" {
249- indRef , ok := fonts [fName ]
250- if ! ok {
251- fonts [fName ] = * * fontIndRef
252- return nil
253- }
254- if indRef != * * fontIndRef {
255- return errors .Errorf ("pdfcpu: %s: duplicate fontDicts" , fName )
256- }
257- return nil
258- }
259-
260- indRef , err := FontIndRef (fName , ctx , fonts )
261- if err != nil {
262- return err
263- }
264- if indRef != nil {
265- * fontIndRef = indRef
266- }
267-
268- return nil
269- }
270-
271- func fontFromAcroDict (xRefTable * model.XRefTable , fontIndRef * types.IndirectRef , fName , fLang * string , fontID string ) error {
272-
273- // Use DA fontId from Acrodict
274-
275- s := xRefTable .Form .StringEntry ("DA" )
276- if s == nil {
277- if fName != nil {
278- return errors .Errorf ("pdfcpu: unsupported font: %s" , * fName )
279- }
280- return errors .Errorf ("pdfcpu: unsupported fontID: %s" , fontID )
281- }
282-
283- da := strings .Fields (* s )
284- rootFontID := ""
285-
286- for i := 0 ; i < len (da ); i ++ {
287- if da [i ] == "Tf" {
288- if i >= 2 {
289- rootFontID = da [i - 2 ][1 :]
290- }
291- break
292- }
293- }
294-
295- if rootFontID == "" {
296- if fName != nil {
297- return errors .Errorf ("pdfcpu: unsupported font: %s" , * fName )
298- }
299- return errors .Errorf ("pdfcpu: unsupported fontID: %s" , fontID )
300- }
301-
302- fontID = rootFontID
303- indRef , err := formFontIndRef (xRefTable , fontID )
304- if err != nil {
305- return err
306- }
307-
308- * fontIndRef = * indRef
309-
310- * fName , * fLang , err = FormFontNameAndLangForID (xRefTable , * indRef )
311- if err != nil {
312- return err
313- }
314-
315- return nil
316- }
317-
318236func ensureUTF8FormFont (ctx * model.Context , fonts map [string ]types.IndirectRef ) (string , string , string , * types.IndirectRef , error ) {
319237
320238 // TODO Make name of UTF-8 userfont part of pdfcpu configs.
@@ -357,11 +275,7 @@ func extractFormFontDetails(
357275
358276 if len (fontID ) > 0 {
359277
360- fontIndRef , err = formFontIndRef (xRefTable , fontID )
361- if err != nil {
362- return "" , "" , "" , nil , err
363- }
364-
278+ fontIndRef = formFontIndRef (xRefTable , fontID )
365279 if fontIndRef != nil {
366280 fName , fLang , err = FormFontNameAndLangForID (xRefTable , * fontIndRef )
367281 if err != nil {
0 commit comments