Skip to content

Commit 55c5d3c

Browse files
Kate IvanovaiText-CI
authored andcommitted
Introduce integration tests for 'font-weight' font-selection
DEVSIX-5145 Autoported commit. Original commit hash: [12f905689]
1 parent 0e440e9 commit 55c5d3c

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

itext.tests/itext.layout.tests/itext/layout/FontSelectorTest.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,102 @@ public virtual void OpenSansFontSetExtraBoldTest01() {
532532
);
533533
}
534534

535+
[NUnit.Framework.Test]
536+
public virtual void OpenSansFontWeightBoldRenderingTest() {
537+
//TODO: DEVSIX-4147 (update cmp-file after the issue will be resolved)
538+
String outFileName = destinationFolder + "openSansFontWeightBoldRendering.pdf";
539+
String cmpFileName = sourceFolder + "cmp_openSansFontWeightBoldRendering.pdf";
540+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
541+
Document doc = new Document(pdfDoc);
542+
FontProvider sel = new FontProvider();
543+
sel.GetFontSet().AddFont(fontsFolder + "Open_Sans/" + "OpenSans-Bold.ttf");
544+
sel.GetFontSet().AddFont(fontsFolder + "Open_Sans/" + "OpenSans-ExtraBold.ttf");
545+
sel.GetFontSet().AddFont(fontsFolder + "Open_Sans/" + "OpenSans-SemiBold.ttf");
546+
doc.SetFontProvider(sel);
547+
Div div = new Div().SetFontFamily("OpenSans");
548+
Paragraph paragraph1 = new Paragraph("Hello, OpenSansExtraBold! ");
549+
paragraph1.SetProperty(Property.FONT_WEIGHT, "800");
550+
Paragraph paragraph2 = new Paragraph(new Text("Hello, OpenSansBold! "));
551+
paragraph2.SetProperty(Property.FONT_WEIGHT, "700");
552+
Paragraph paragraph3 = new Paragraph(new Text("Hello, OpenSansSemiBold!"));
553+
paragraph3.SetProperty(Property.FONT_WEIGHT, "600");
554+
div.Add(paragraph1).Add(paragraph2).Add(paragraph3);
555+
doc.Add(div);
556+
doc.Close();
557+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
558+
));
559+
}
560+
561+
[NUnit.Framework.Test]
562+
public virtual void OpenSansFontWeightNotBoldRenderingTest() {
563+
//TODO: DEVSIX-4147 (update cmp-file after the issue will be resolved)
564+
String outFileName = destinationFolder + "openSansFontWeightNotBoldRendering.pdf";
565+
String cmpFileName = sourceFolder + "cmp_openSansFontWeightNotBoldRendering.pdf";
566+
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
567+
Document doc = new Document(pdfDoc);
568+
FontProvider sel = new FontProvider();
569+
sel.GetFontSet().AddFont(fontsFolder + "Open_Sans/" + "OpenSans-Regular.ttf");
570+
sel.GetFontSet().AddFont(fontsFolder + "Open_Sans/" + "OpenSans-Light.ttf");
571+
doc.SetFontProvider(sel);
572+
Div div = new Div().SetFontFamily("OpenSans");
573+
Paragraph paragraph1 = new Paragraph("Hello, OpenSansRegular! ");
574+
paragraph1.SetProperty(Property.FONT_WEIGHT, "400");
575+
Paragraph paragraph2 = new Paragraph(new Text("Hello, OpenSansLight! "));
576+
paragraph2.SetProperty(Property.FONT_WEIGHT, "300");
577+
div.Add(paragraph1).Add(paragraph2);
578+
doc.Add(div);
579+
doc.Close();
580+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
581+
));
582+
}
583+
584+
[NUnit.Framework.Test]
585+
public virtual void OpenSansOutOfBoldFontWeightTest() {
586+
String openSansFolder = "Open_Sans/";
587+
FontSet set = new FontSet();
588+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-Bold.ttf");
589+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-ExtraBold.ttf");
590+
IList<String> fontFamilies = new List<String>();
591+
fontFamilies.Add("OpenSans");
592+
FontCharacteristics fc = new FontCharacteristics();
593+
fc.SetFontWeight((short)400);
594+
NUnit.Framework.Assert.AreEqual("OpenSans-Bold", new FontSelector(set.GetFonts(), fontFamilies, fc).BestMatch
595+
().GetDescriptor().GetFontName());
596+
}
597+
598+
[NUnit.Framework.Test]
599+
public virtual void OpenSansOutOfMixedFontWeightTest() {
600+
String openSansFolder = "Open_Sans/";
601+
FontSet set = new FontSet();
602+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-Light.ttf");
603+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-SemiBold.ttf");
604+
IList<String> fontFamilies = new List<String>();
605+
fontFamilies.Add("OpenSans");
606+
FontCharacteristics fc = new FontCharacteristics();
607+
fc.SetFontWeight((short)100);
608+
NUnit.Framework.Assert.AreEqual("OpenSans-Light", new FontSelector(set.GetFonts(), fontFamilies, fc).BestMatch
609+
().GetDescriptor().GetFontName());
610+
fc = new FontCharacteristics();
611+
fc.SetFontWeight((short)600);
612+
NUnit.Framework.Assert.AreEqual("OpenSans-SemiBold", new FontSelector(set.GetFonts(), fontFamilies, fc).BestMatch
613+
().GetDescriptor().GetFontName());
614+
}
615+
616+
[NUnit.Framework.Test]
617+
public virtual void OpenSansOutOfNotBoldFontWeightTest() {
618+
// TODO: DEVSIX-2120 Currently light and regular fonts have the same score. When fixed update assertion to "OpenSans-Regular"
619+
String openSansFolder = "Open_Sans/";
620+
FontSet set = new FontSet();
621+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-Light.ttf");
622+
set.AddFont(fontsFolder + openSansFolder + "OpenSans-Regular.ttf");
623+
IList<String> fontFamilies = new List<String>();
624+
fontFamilies.Add("OpenSans");
625+
FontCharacteristics fc = new FontCharacteristics();
626+
fc.SetFontWeight((short)700);
627+
NUnit.Framework.Assert.AreEqual("OpenSans-Light", new FontSelector(set.GetFonts(), fontFamilies, fc).BestMatch
628+
().GetDescriptor().GetFontName());
629+
}
630+
535631
private void CheckSelector(ICollection<FontInfo> fontInfoCollection, String fontFamily, String expectedNormal
536632
, String expectedBold, String expectedItalic, String expectedBoldItalic) {
537633
IList<String> fontFamilies = new List<String>();

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
83b3c3a3f27949ab04ab2ffaa0927672b3199b5d
1+
12f905689dc1452d06a2e13b1780fc7c0a1677d9

0 commit comments

Comments
 (0)