@@ -496,12 +496,7 @@ public static PdfTextFormField CreateText(PdfDocument doc, Rectangle rect, Strin
496
496
/// <see cref="PdfTextFormField"/>
497
497
/// </returns>
498
498
public static PdfTextFormField CreateText ( PdfDocument doc , Rectangle rect , String name , String value ) {
499
- try {
500
- return CreateText ( doc , rect , name , value , PdfFontFactory . CreateFont ( ) , ( float ) DEFAULT_FONT_SIZE ) ;
501
- }
502
- catch ( System . IO . IOException e ) {
503
- throw new PdfException ( e ) ;
504
- }
499
+ return CreateText ( doc , rect , name , value , null , - 1 ) ;
505
500
}
506
501
507
502
/// <summary>
@@ -658,12 +653,7 @@ public static PdfTextFormField CreateMultilineText(PdfDocument doc, Rectangle re
658
653
/// </returns>
659
654
public static PdfTextFormField CreateMultilineText ( PdfDocument doc , Rectangle rect , String name , String value
660
655
) {
661
- try {
662
- return CreateText ( doc , rect , name , value , PdfFontFactory . CreateFont ( ) , ( float ) DEFAULT_FONT_SIZE , true ) ;
663
- }
664
- catch ( System . IO . IOException e ) {
665
- throw new PdfException ( e ) ;
666
- }
656
+ return CreateText ( doc , rect , name , value , null , - 1 , true ) ;
667
657
}
668
658
669
659
/// <summary>
@@ -3274,71 +3264,59 @@ protected internal virtual Object[] GetFontAndSize(PdfDictionary asNormal) {
3274
3264
if ( asNormal != null ) {
3275
3265
normalResources = asNormal . GetAsDictionary ( PdfName . Resources ) ;
3276
3266
}
3267
+ PdfDictionary daFontDict = null ;
3268
+ PdfName daFontName = null ;
3269
+ Object [ ] dab = new Object [ 3 ] ;
3277
3270
if ( defaultResources != null || normalResources != null ) {
3278
3271
PdfDictionary normalFontDic = normalResources != null ? normalResources . GetAsDictionary ( PdfName . Font ) : null ;
3279
3272
PdfDictionary defaultFontDic = defaultResources != null ? defaultResources . GetAsDictionary ( PdfName . Font ) :
3280
3273
null ;
3281
3274
PdfString defaultAppearance = GetDefaultAppearance ( ) ;
3282
3275
if ( ( normalFontDic != null || defaultFontDic != null ) && defaultAppearance != null ) {
3283
- Object [ ] dab = SplitDAelements ( defaultAppearance . ToUnicodeString ( ) ) ;
3284
- PdfName fontName = new PdfName ( dab [ DA_FONT ] . ToString ( ) ) ;
3285
- fontAndSize [ 2 ] = fontName ;
3286
- PdfDictionary requiredFontDictionary = null ;
3287
- if ( normalFontDic != null && null != normalFontDic . GetAsDictionary ( fontName ) ) {
3288
- requiredFontDictionary = normalFontDic . GetAsDictionary ( fontName ) ;
3289
- }
3290
- else {
3291
- if ( defaultFontDic != null ) {
3292
- requiredFontDictionary = defaultFontDic . GetAsDictionary ( fontName ) ;
3276
+ dab = SplitDAelements ( defaultAppearance . ToUnicodeString ( ) ) ;
3277
+ Object fontNameObj = dab [ DA_FONT ] ;
3278
+ if ( fontNameObj != null ) {
3279
+ daFontName = new PdfName ( fontNameObj . ToString ( ) ) ;
3280
+ // according to spec, DA font shall be taken from the DR
3281
+ if ( defaultFontDic != null && null != defaultFontDic . GetAsDictionary ( daFontName ) ) {
3282
+ daFontDict = defaultFontDic . GetAsDictionary ( daFontName ) ;
3283
+ }
3284
+ else {
3285
+ if ( normalFontDic != null ) {
3286
+ // search normal appearance as a fall back in case it was not found in DR
3287
+ daFontDict = normalFontDic . GetAsDictionary ( daFontName ) ;
3288
+ }
3293
3289
}
3294
- }
3295
- if ( font != null ) {
3296
- fontAndSize [ 0 ] = font ;
3297
- }
3298
- else {
3299
- PdfFont dicFont = document != null ? document . GetFont ( requiredFontDictionary ) : PdfFontFactory . CreateFont (
3300
- requiredFontDictionary ) ;
3301
- fontAndSize [ 0 ] = dicFont ;
3302
- }
3303
- if ( fontSize >= 0 ) {
3304
- fontAndSize [ 1 ] = fontSize ;
3305
- }
3306
- else {
3307
- fontAndSize [ 1 ] = dab [ DA_SIZE ] ;
3308
- }
3309
- if ( color == null ) {
3310
- color = ( Color ) dab [ DA_COLOR ] ;
3311
- }
3312
- }
3313
- else {
3314
- if ( font != null ) {
3315
- fontAndSize [ 0 ] = font ;
3316
- }
3317
- else {
3318
- fontAndSize [ 0 ] = PdfFontFactory . CreateFont ( ) ;
3319
- }
3320
- if ( fontSize >= 0 ) {
3321
- fontAndSize [ 1 ] = fontSize ;
3322
- }
3323
- else {
3324
- fontAndSize [ 1 ] = ( float ) DEFAULT_FONT_SIZE ;
3325
3290
}
3326
3291
}
3327
3292
}
3293
+ if ( font != null ) {
3294
+ fontAndSize [ 0 ] = font ;
3295
+ }
3328
3296
else {
3329
- if ( font != null ) {
3330
- fontAndSize [ 0 ] = font ;
3297
+ if ( daFontDict != null ) {
3298
+ PdfFont daFont = document != null ? document . GetFont ( daFontDict ) : PdfFontFactory . CreateFont ( daFontDict ) ;
3299
+ fontAndSize [ 0 ] = daFont ;
3300
+ fontAndSize [ 2 ] = daFontName ;
3331
3301
}
3332
3302
else {
3333
3303
fontAndSize [ 0 ] = PdfFontFactory . CreateFont ( ) ;
3334
3304
}
3335
- if ( fontSize >= 0 ) {
3336
- fontAndSize [ 1 ] = fontSize ;
3305
+ }
3306
+ if ( fontSize >= 0 ) {
3307
+ fontAndSize [ 1 ] = fontSize ;
3308
+ }
3309
+ else {
3310
+ if ( dab [ DA_SIZE ] != null ) {
3311
+ fontAndSize [ 1 ] = dab [ DA_SIZE ] ;
3337
3312
}
3338
3313
else {
3339
3314
fontAndSize [ 1 ] = ( float ) DEFAULT_FONT_SIZE ;
3340
3315
}
3341
3316
}
3317
+ if ( color == null ) {
3318
+ color = ( Color ) dab [ DA_COLOR ] ;
3319
+ }
3342
3320
return fontAndSize ;
3343
3321
}
3344
3322
@@ -3407,7 +3385,7 @@ protected internal static Object[] SplitDAelements(String da) {
3407
3385
}
3408
3386
}
3409
3387
}
3410
- catch ( System . IO . IOException ) {
3388
+ catch ( Exception ) {
3411
3389
}
3412
3390
return ret ;
3413
3391
}
0 commit comments