@@ -48,6 +48,7 @@ This file is part of the iText (R) project.
48
48
import com .itextpdf .io .font .constants .StandardFonts ;
49
49
import com .itextpdf .kernel .colors .ColorConstants ;
50
50
import com .itextpdf .kernel .font .PdfFont ;
51
+ import com .itextpdf .kernel .font .PdfFontFactory ;
51
52
import com .itextpdf .kernel .pdf .PdfDocument ;
52
53
import com .itextpdf .kernel .pdf .PdfWriter ;
53
54
import com .itextpdf .kernel .utils .CompareTool ;
@@ -594,6 +595,135 @@ public void openSansFontSetExtraBoldTest01() {
594
595
checkSelector (set .getFonts (), "Open Sans ExtraBold" , "Times-Bold" , "Times-Bold" , "Times-BoldItalic" , "Times-BoldItalic" );
595
596
}
596
597
598
+ @ Test
599
+ //TODO: DEVSIX-4147 (update cmp-file after the issue will be resolved)
600
+ public void openSansFontWeightBoldRenderingTest () throws Exception {
601
+ String outFileName = destinationFolder + "openSansFontWeightBoldRendering.pdf" ;
602
+ String cmpFileName = sourceFolder + "cmp_openSansFontWeightBoldRendering.pdf" ;
603
+
604
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
605
+ Document doc = new Document (pdfDoc );
606
+
607
+ FontProvider sel = new FontProvider ();
608
+ sel .getFontSet ().addFont (fontsFolder + "Open_Sans/" + "OpenSans-Bold.ttf" );
609
+ sel .getFontSet ().addFont (fontsFolder + "Open_Sans/" + "OpenSans-ExtraBold.ttf" );
610
+ sel .getFontSet ().addFont (fontsFolder + "Open_Sans/" + "OpenSans-SemiBold.ttf" );
611
+ doc .setFontProvider (sel );
612
+
613
+ Div div = new Div ().setFontFamily ("OpenSans" );
614
+
615
+ Paragraph paragraph1 = new Paragraph ("Hello, OpenSansExtraBold! " );
616
+ paragraph1 .setProperty (Property .FONT_WEIGHT , "800" );
617
+
618
+ Paragraph paragraph2 = new Paragraph (new Text ("Hello, OpenSansBold! " ));
619
+ paragraph2 .setProperty (Property .FONT_WEIGHT , "700" );
620
+
621
+ Paragraph paragraph3 = new Paragraph (new Text ("Hello, OpenSansSemiBold!" ));
622
+ paragraph3 .setProperty (Property .FONT_WEIGHT , "600" );
623
+
624
+ div
625
+ .add (paragraph1 )
626
+ .add (paragraph2 )
627
+ .add (paragraph3 );
628
+ doc .add (div );
629
+
630
+ doc .close ();
631
+
632
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
633
+ }
634
+
635
+ @ Test
636
+ //TODO: DEVSIX-4147 (update cmp-file after the issue will be resolved)
637
+ public void openSansFontWeightNotBoldRenderingTest () throws Exception {
638
+ String outFileName = destinationFolder + "openSansFontWeightNotBoldRendering.pdf" ;
639
+ String cmpFileName = sourceFolder + "cmp_openSansFontWeightNotBoldRendering.pdf" ;
640
+
641
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
642
+ Document doc = new Document (pdfDoc );
643
+
644
+ FontProvider sel = new FontProvider ();
645
+ sel .getFontSet ().addFont (fontsFolder + "Open_Sans/" + "OpenSans-Regular.ttf" );
646
+ sel .getFontSet ().addFont (fontsFolder + "Open_Sans/" + "OpenSans-Light.ttf" );
647
+ doc .setFontProvider (sel );
648
+
649
+ Div div = new Div ().setFontFamily ("OpenSans" );
650
+
651
+ Paragraph paragraph1 = new Paragraph ("Hello, OpenSansRegular! " );
652
+ paragraph1 .setProperty (Property .FONT_WEIGHT , "400" );
653
+
654
+ Paragraph paragraph2 = new Paragraph (new Text ("Hello, OpenSansLight! " ));
655
+ paragraph2 .setProperty (Property .FONT_WEIGHT , "300" );
656
+
657
+ div
658
+ .add (paragraph1 )
659
+ .add (paragraph2 );
660
+ doc .add (div );
661
+
662
+ doc .close ();
663
+
664
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder ));
665
+ }
666
+
667
+ @ Test
668
+ public void openSansOutOfBoldFontWeightTest () {
669
+ String openSansFolder = "Open_Sans/" ;
670
+
671
+ FontSet set = new FontSet ();
672
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Bold.ttf" );
673
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-ExtraBold.ttf" );
674
+
675
+ List <String > fontFamilies = new ArrayList <>();
676
+ fontFamilies .add ("OpenSans" );
677
+
678
+ FontCharacteristics fc = new FontCharacteristics ();
679
+ fc .setFontWeight ((short ) 400 );
680
+
681
+ Assert .assertEquals ("OpenSans-Bold" , new FontSelector (set .getFonts (), fontFamilies , fc ).bestMatch ().getDescriptor ().getFontName ());
682
+ }
683
+
684
+ @ Test
685
+ public void openSansOutOfMixedFontWeightTest () {
686
+ String openSansFolder = "Open_Sans/" ;
687
+
688
+ FontSet set = new FontSet ();
689
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Light.ttf" );
690
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-SemiBold.ttf" );
691
+
692
+ List <String > fontFamilies = new ArrayList <>();
693
+ fontFamilies .add ("OpenSans" );
694
+
695
+ FontCharacteristics fc = new FontCharacteristics ();
696
+ fc .setFontWeight ((short ) 100 );
697
+
698
+ Assert .assertEquals ("OpenSans-Light" ,
699
+ new FontSelector (set .getFonts (), fontFamilies , fc ).bestMatch ().getDescriptor ().getFontName ());
700
+
701
+ fc = new FontCharacteristics ();
702
+ fc .setFontWeight ((short ) 600 );
703
+
704
+ Assert .assertEquals ("OpenSans-SemiBold" ,
705
+ new FontSelector (set .getFonts (), fontFamilies , fc ).bestMatch ().getDescriptor ().getFontName ());
706
+ }
707
+
708
+ @ Test
709
+ // TODO: DEVSIX-2120 Currently light and regular fonts have the same score. When fixed update assertion to "OpenSans-Regular"
710
+ public void openSansOutOfNotBoldFontWeightTest () {
711
+ String openSansFolder = "Open_Sans/" ;
712
+
713
+ FontSet set = new FontSet ();
714
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Light.ttf" );
715
+ set .addFont (fontsFolder + openSansFolder + "OpenSans-Regular.ttf" );
716
+
717
+ List <String > fontFamilies = new ArrayList <>();
718
+ fontFamilies .add ("OpenSans" );
719
+
720
+ FontCharacteristics fc = new FontCharacteristics ();
721
+ fc .setFontWeight ((short ) 700 );
722
+
723
+ Assert .assertEquals ("OpenSans-Light" ,
724
+ new FontSelector (set .getFonts (), fontFamilies , fc ).bestMatch ().getDescriptor ().getFontName ());
725
+ }
726
+
597
727
private void checkSelector (Collection <FontInfo > fontInfoCollection , String fontFamily ,
598
728
String expectedNormal , String expectedBold , String expectedItalic , String expectedBoldItalic ) {
599
729
List <String > fontFamilies = new ArrayList <>();
0 commit comments