@@ -411,11 +411,7 @@ public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, Strin
411
411
* @return a new {@link PdfTextFormField}
412
412
*/
413
413
public static PdfTextFormField createText (PdfDocument doc , Rectangle rect , String name , String value ) {
414
- try {
415
- return createText (doc , rect , name , value , PdfFontFactory .createFont (), (float ) DEFAULT_FONT_SIZE );
416
- } catch (IOException e ) {
417
- throw new PdfException (e );
418
- }
414
+ return createText (doc , rect , name , value , null , -1 );
419
415
}
420
416
421
417
/**
@@ -511,11 +507,7 @@ public static PdfTextFormField createMultilineText(PdfDocument doc, Rectangle re
511
507
* @return a new {@link PdfTextFormField}
512
508
*/
513
509
public static PdfTextFormField createMultilineText (PdfDocument doc , Rectangle rect , String name , String value ) {
514
- try {
515
- return createText (doc , rect , name , value , PdfFontFactory .createFont (), (float ) DEFAULT_FONT_SIZE , true );
516
- } catch (IOException e ) {
517
- throw new PdfException (e );
518
- }
510
+ return createText (doc , rect , name , value , null , -1 , true );
519
511
}
520
512
521
513
/**
@@ -2657,58 +2649,50 @@ protected Object[] getFontAndSize(PdfDictionary asNormal) throws IOException {
2657
2649
if (asNormal != null ) {
2658
2650
normalResources = asNormal .getAsDictionary (PdfName .Resources );
2659
2651
}
2652
+
2653
+ PdfDictionary daFontDict = null ;
2654
+ PdfName daFontName = null ;
2655
+ Object [] dab = new Object [3 ];
2660
2656
if (defaultResources != null || normalResources != null ) {
2661
2657
PdfDictionary normalFontDic = normalResources != null ? normalResources .getAsDictionary (PdfName .Font ) : null ;
2662
2658
PdfDictionary defaultFontDic = defaultResources != null ? defaultResources .getAsDictionary (PdfName .Font ) : null ;
2663
2659
PdfString defaultAppearance = getDefaultAppearance ();
2664
-
2665
2660
if ((normalFontDic != null || defaultFontDic != null ) && defaultAppearance != null ) {
2666
- Object [] dab = splitDAelements (defaultAppearance .toUnicodeString ());
2667
- PdfName fontName = new PdfName (dab [DA_FONT ].toString ());
2668
- fontAndSize [2 ] = fontName ;
2669
- PdfDictionary requiredFontDictionary = null ;
2670
- if (normalFontDic != null && null != normalFontDic .getAsDictionary (fontName )) {
2671
- requiredFontDictionary = normalFontDic .getAsDictionary (fontName );
2672
- } else if (defaultFontDic != null ) {
2673
- requiredFontDictionary = defaultFontDic .getAsDictionary (fontName );
2674
- }
2675
- if (font != null ) {
2676
- fontAndSize [0 ] = font ;
2677
- } else {
2678
- PdfFont dicFont = document != null ? document .getFont (requiredFontDictionary ) : PdfFontFactory .createFont (requiredFontDictionary );
2679
- fontAndSize [0 ] = dicFont ;
2680
- }
2681
- if (fontSize >= 0 ) {
2682
- fontAndSize [1 ] = fontSize ;
2683
- } else {
2684
- fontAndSize [1 ] = dab [DA_SIZE ];
2685
- }
2686
- if (color == null ) {
2687
- color = (Color ) dab [DA_COLOR ];
2688
- }
2689
- } else {
2690
- if (font != null ) {
2691
- fontAndSize [0 ] = font ;
2692
- } else {
2693
- fontAndSize [0 ] = PdfFontFactory .createFont ();
2694
- }
2695
- if (fontSize >= 0 ) {
2696
- fontAndSize [1 ] = fontSize ;
2697
- } else {
2698
- fontAndSize [1 ] = (float ) DEFAULT_FONT_SIZE ;
2661
+ dab = splitDAelements (defaultAppearance .toUnicodeString ());
2662
+ Object fontNameObj = dab [DA_FONT ];
2663
+ if (fontNameObj != null ) {
2664
+ daFontName = new PdfName (fontNameObj .toString ());
2665
+ // according to spec, DA font shall be taken from the DR
2666
+ if (defaultFontDic != null && null != defaultFontDic .getAsDictionary (daFontName )) {
2667
+ daFontDict = defaultFontDic .getAsDictionary (daFontName );
2668
+ } else if (normalFontDic != null ) {
2669
+ // search normal appearance as a fall back in case it was not found in DR
2670
+ daFontDict = normalFontDic .getAsDictionary (daFontName );
2671
+ }
2699
2672
}
2700
2673
}
2674
+ }
2675
+
2676
+ if (font != null ) {
2677
+ fontAndSize [0 ] = font ;
2678
+ } else if (daFontDict != null ) {
2679
+ PdfFont daFont = document != null ? document .getFont (daFontDict ) : PdfFontFactory .createFont (daFontDict );
2680
+ fontAndSize [0 ] = daFont ;
2681
+ fontAndSize [2 ] = daFontName ;
2701
2682
} else {
2702
- if (font != null ) {
2703
- fontAndSize [0 ] = font ;
2704
- } else {
2705
- fontAndSize [0 ] = PdfFontFactory .createFont ();
2706
- }
2707
- if (fontSize >= 0 ) {
2708
- fontAndSize [1 ] = fontSize ;
2709
- } else {
2710
- fontAndSize [1 ] = (float ) DEFAULT_FONT_SIZE ;
2711
- }
2683
+ fontAndSize [0 ] = PdfFontFactory .createFont ();
2684
+ }
2685
+
2686
+ if (fontSize >= 0 ) {
2687
+ fontAndSize [1 ] = fontSize ;
2688
+ } else if (dab [DA_SIZE ] != null ) {
2689
+ fontAndSize [1 ] = dab [DA_SIZE ];
2690
+ } else {
2691
+ fontAndSize [1 ] = (float ) DEFAULT_FONT_SIZE ;
2692
+ }
2693
+
2694
+ if (color == null ) {
2695
+ color = (Color ) dab [DA_COLOR ];
2712
2696
}
2713
2697
2714
2698
return fontAndSize ;
@@ -2757,7 +2741,7 @@ protected static Object[] splitDAelements(String da) {
2757
2741
stack .add (tk .getStringValue ());
2758
2742
}
2759
2743
}
2760
- } catch (IOException e ) {
2744
+ } catch (Exception ignored ) {
2761
2745
2762
2746
}
2763
2747
return ret ;
0 commit comments