@@ -63,6 +63,7 @@ This file is part of the iText (R) project.
63
63
import com .itextpdf .test .annotations .type .IntegrationTest ;
64
64
import org .junit .Assert ;
65
65
import org .junit .BeforeClass ;
66
+ import org .junit .Ignore ;
66
67
import org .junit .Test ;
67
68
import org .junit .experimental .categories .Category ;
68
69
@@ -78,8 +79,6 @@ public class FontSelectorTest extends ExtendedITextTest {
78
79
public static final String destinationFolder = "./target/test/com/itextpdf/layout/FontSelectorTest/" ;
79
80
public static final String fontsFolder = "./src/test/resources/com/itextpdf/layout/fonts/" ;
80
81
81
- private static final String PANGRAM = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
82
-
83
82
@ BeforeClass
84
83
public static void beforeClass () {
85
84
createDestinationFolder (destinationFolder );
@@ -112,6 +111,7 @@ public void cyrillicAndLatinGroup() throws Exception {
112
111
}
113
112
114
113
@ Test
114
+ // TODO DEVSIX-2120 The font-family name of Puritan2.otf is 'Puritan 2.0' but this name doesn't match font-family name pattern
115
115
public void cyrillicAndLatinGroup2 () throws Exception {
116
116
String fileName = "cyrillicAndLatinGroup2" ;
117
117
String outFileName = destinationFolder + fileName + ".pdf" ;
@@ -413,124 +413,157 @@ public void singleFontWithUnicodeRange() throws Exception {
413
413
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" + fileName ));
414
414
}
415
415
416
-
417
416
@ Test
418
417
public void standardFontSetTimesTest01 () {
419
- standardFontSetTest ( "Times" , "Times-Roman" , "Times-Bold" , "Times-Italic" , "Times-BoldItalic" );
418
+ checkSelector ( getStandardFontSet (). getFonts (), "Times" , "Times-Roman" , "Times-Bold" , "Times-Italic" , "Times-BoldItalic" );
420
419
}
421
420
422
421
@ Test
423
422
public void standardFontSetHelveticaTest01 () {
424
- standardFontSetTest ( "Helvetica" , "Helvetica" , "Helvetica-Bold" , "Helvetica-Oblique" , "Helvetica-BoldOblique" );
423
+ checkSelector ( getStandardFontSet (). getFonts (), "Helvetica" , "Helvetica" , "Helvetica-Bold" , "Helvetica-Oblique" , "Helvetica-BoldOblique" );
425
424
}
426
425
427
426
@ Test
428
- public void standardFontSetCourierTest () {
429
- standardFontSetTest ( "Courier" , "Courier" , "Courier-Bold" , "Courier-Oblique" , "Courier-BoldOblique" );
427
+ public void standardFontSetCourierTest01 () {
428
+ checkSelector ( getStandardFontSet (). getFonts (), "Courier" , "Courier" , "Courier-Bold" , "Courier-Oblique" , "Courier-BoldOblique" );
430
429
}
431
430
432
- private void standardFontSetTest (String fontFamily , String expectedNormal , String expectedBold , String expectedItalic , String expectedBoldItalic ) {
433
- Collection <FontInfo > fontInfoCollection = getStandardFontSet ().getFonts ();
431
+ @ Test
432
+ // TODO DEVSIX-2120 Currently both light and regular fonts have the same score so that light is picked up lexicographically. After the changes are implemented the correct one (regular) font shall be selected and the expected constants should be updated
433
+ // TODO Default font shall be specified.
434
+ public void openSansFontSetIncorrectNameTest01 () {
435
+ FontSet set = getOpenSansFontSet ();
436
+ addTimesFonts (set );
437
+ checkSelector (set .getFonts (), "OpenSans" , "OpenSans-Light" , "OpenSans-Bold" , "OpenSans-LightItalic" , "OpenSans-BoldItalic" );
438
+ }
439
+
440
+ @ Test
441
+ // TODO DEVSIX-2120 Currently both light and regular fonts have the same score so that light is picked up lexicographically. After the changes are implemented the correct one (regular) font shall be selected and the expected constants should be updated
442
+ // TODO Default font shall be specified.
443
+ public void openSansFontSetRegularTest01 () {
444
+ FontSet set = getOpenSansFontSet ();
445
+ addTimesFonts (set );
446
+ checkSelector (set .getFonts (), "Open Sans" , "OpenSans-Light" , "OpenSans-Bold" , "OpenSans-LightItalic" , "OpenSans-BoldItalic" );
447
+ }
448
+
449
+ @ Test
450
+ // TODO DEVSIX-2127 After DEVSIX-2120 the font should be selected correctly, but the text will still need to be bolded via emulation
451
+ // TODO DEVSIX-2120 Light subfamily is not processed
452
+ // TODO Default font shall be specified.
453
+ public void openSansFontSetLightTest01 () {
454
+ FontSet set = getOpenSansFontSet ();
455
+ addTimesFonts (set );
456
+ checkSelector (set .getFonts (), "Open Sans Light" , "OpenSans-Light" , "OpenSans-Bold" , "OpenSans-LightItalic" , "OpenSans-BoldItalic" );
457
+ }
458
+
459
+ @ Test
460
+ // TODO DEVSIX-2120 ExtraBold subfamily is not processed
461
+ // TODO DEVSIX-2135 if FontCharacteristics instance is not modified, font-family is parsed and 'bold' substring is considered as a reason to set bold flag in FontCharacteristics instance. That should be reviewed.
462
+ @ Ignore ("DEVSIX-2120: we cannot set a wrong expected string for normal font characteristics because in different contexts iText selects different fonts" )
463
+ public void openSansFontSetExtraBoldTest01 () {
464
+ FontSet set = getOpenSansFontSet ();
465
+ addTimesFonts (set );
466
+ checkSelector (set .getFonts (), "Open Sans ExtraBold" , "Times-Bold" , "Times-Bold" , "Times-BoldItalic" , "Times-BoldItalic" );
467
+ }
434
468
469
+ private void checkSelector (Collection <FontInfo > fontInfoCollection , String fontFamily ,
470
+ String expectedNormal , String expectedBold , String expectedItalic , String expectedBoldItalic ) {
435
471
List <String > fontFamilies = new ArrayList <>();
436
472
fontFamilies .add (fontFamily );
437
473
438
- FontCharacteristics fc ;
439
-
440
474
// Normal
441
475
442
- fc = new FontCharacteristics ();
443
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedNormal ) );
476
+ FontCharacteristics fc = new FontCharacteristics ();
477
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedNormal );
444
478
445
479
fc = new FontCharacteristics ();
446
480
fc .setFontWeight ((short ) 300 );
447
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedNormal ) );
481
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedNormal );
448
482
449
483
fc = new FontCharacteristics ();
450
484
fc .setFontWeight ((short ) 100 );
451
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedNormal ) );
485
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedNormal );
452
486
453
487
fc = new FontCharacteristics ();
454
488
fc .setFontWeight ("normal" );
455
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedNormal ) );
489
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedNormal );
456
490
457
491
fc = new FontCharacteristics ();
458
492
fc .setFontStyle ("normal" );
459
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedNormal ) );
493
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedNormal );
460
494
461
495
462
496
// Bold
463
497
464
498
fc = new FontCharacteristics ();
465
499
fc .setBoldFlag (true );
466
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBold ) );
500
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBold );
467
501
468
502
fc = new FontCharacteristics ();
469
503
fc .setFontWeight ("bold" );
470
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBold ) );
504
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBold );
471
505
472
506
fc = new FontCharacteristics ();
473
507
fc .setFontWeight ((short ) 700 );
474
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBold ) );
508
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBold );
475
509
476
510
fc = new FontCharacteristics ();
477
511
fc .setFontWeight ((short ) 800 );
478
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBold ) );
512
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBold );
479
513
480
514
481
515
// Italic
482
516
483
517
fc = new FontCharacteristics ();
484
518
fc .setFontStyle ("italic" );
485
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedItalic ) );
519
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedItalic );
486
520
487
521
fc = new FontCharacteristics ();
488
522
fc .setFontStyle ("italic" );
489
523
fc .setFontWeight ("normal" );
490
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedItalic ) );
524
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedItalic );
491
525
492
526
fc = new FontCharacteristics ();
493
527
fc .setFontStyle ("italic" );
494
528
fc .setFontWeight ((short ) 300 );
495
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedItalic ) );
529
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedItalic );
496
530
497
531
fc = new FontCharacteristics ();
498
532
fc .setFontStyle ("italic" );
499
533
fc .setFontWeight ((short ) 500 );
500
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedItalic ) );
534
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedItalic );
501
535
502
536
fc = new FontCharacteristics ();
503
537
fc .setFontStyle ("oblique" );
504
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedItalic ) );
538
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedItalic );
505
539
506
540
507
541
// BoldItalic
508
542
509
543
fc = new FontCharacteristics ();
510
544
fc .setFontStyle ("italic" );
511
545
fc .setFontWeight ("bold" );
512
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic ) );
546
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic );
513
547
514
548
fc = new FontCharacteristics ();
515
549
fc .setFontStyle ("oblique" );
516
550
fc .setFontWeight ("bold" );
517
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic ) );
551
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic );
518
552
519
553
fc = new FontCharacteristics ();
520
554
fc .setFontStyle ("italic" );
521
555
fc .setFontWeight ((short ) 700 );
522
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic ) );
556
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic );
523
557
524
558
fc = new FontCharacteristics ();
525
559
fc .setFontStyle ("italic" );
526
560
fc .setFontWeight ((short ) 800 );
527
- Assert . assertTrue ( checkFontSelector ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic ) );
561
+ assertSelectedFont ( fontInfoCollection , fontFamilies , fc , expectedBoldItalic );
528
562
}
529
563
530
564
531
- private boolean checkFontSelector (Collection <FontInfo > fontInfoCollection , List <String > fontFamilies , FontCharacteristics fc , String expectedFontName ) {
532
- return expectedFontName .equals (new FontSelector (fontInfoCollection , fontFamilies , fc ).bestMatch ().getFontName ());
533
-
565
+ private void assertSelectedFont (Collection <FontInfo > fontInfoCollection , List <String > fontFamilies , FontCharacteristics fc , String expectedFontName ) {
566
+ Assert .assertEquals (expectedFontName , new FontSelector (fontInfoCollection , fontFamilies , fc ).bestMatch ().getDescriptor ().getFontName ());
534
567
}
535
568
536
569
private static FontSet getStandardFontSet () {
@@ -544,11 +577,32 @@ private static FontSet getStandardFontSet() {
544
577
set .addFont (StandardFonts .HELVETICA_BOLDOBLIQUE );
545
578
set .addFont (StandardFonts .HELVETICA_OBLIQUE );
546
579
set .addFont (StandardFonts .SYMBOL );
580
+ set .addFont (StandardFonts .ZAPFDINGBATS );
581
+ addTimesFonts (set );
582
+ return set ;
583
+ }
584
+
585
+ private static FontSet getOpenSansFontSet () {
586
+ String openSansFolder = "Open_Sans/" ;
587
+ FontSet set = new FontSet ();
588
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Bold.ttf" );
589
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-BoldItalic.ttf" );
590
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-ExtraBold.ttf" );
591
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-ExtraBoldItalic.ttf" );
592
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Light.ttf" );
593
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-LightItalic.ttf" );
594
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Regular.ttf" );
595
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Italic.ttf" );
596
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-SemiBold.ttf" );
597
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-SemiBoldItalic.ttf" );
598
+ return set ;
599
+ }
600
+
601
+ private static FontSet addTimesFonts (FontSet set ) {
547
602
set .addFont (StandardFonts .TIMES_ROMAN );
548
603
set .addFont (StandardFonts .TIMES_BOLD );
549
604
set .addFont (StandardFonts .TIMES_BOLDITALIC );
550
605
set .addFont (StandardFonts .TIMES_ITALIC );
551
- set .addFont (StandardFonts .ZAPFDINGBATS );
552
606
return set ;
553
607
}
554
608
0 commit comments