public virtual void StandardAndType3Fonts() { String fileName = "taggedDocumentWithType3Font"; String srcFileName = sourceFolder + "src_" + fileName + ".pdf"; String outFileName = destinationFolder + fileName + ".pdf"; String cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf"; FontProviderTest.PdfFontProvider sel = new FontProviderTest.PdfFontProvider(); sel.AddStandardPdfFonts(); PdfDocument pdfDoc = new PdfDocument(new PdfReader(new FileStream(srcFileName, FileMode.Open, FileAccess.Read )), new PdfWriter(new FileStream(outFileName, FileMode.Create))); PdfType3Font pdfType3Font = (PdfType3Font)PdfFontFactory.CreateFont((PdfDictionary)pdfDoc.GetPdfObject(5)); sel.AddPdfFont(pdfType3Font, "CustomFont"); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); Paragraph paragraph = new Paragraph("Next paragraph contains a triangle, actually Type 3 Font"); paragraph.SetProperty(Property.FONT, new String[] { StandardFontFamilies.TIMES }); doc.Add(paragraph); paragraph = new Paragraph("A"); paragraph.SetFontFamily("CustomFont"); doc.Add(paragraph); paragraph = new Paragraph("Next paragraph"); paragraph.SetProperty(Property.FONT, new String[] { StandardFonts.COURIER }); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + fileName)); }
public virtual void CustomFontProvider2() { String fileName = "customFontProvider2.pdf"; String outFileName = destinationFolder + fileName + ".pdf"; String cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf"; FontProvider fontProvider = new FontProvider(); // bold font. shouldn't be selected fontProvider.GetFontSet().AddFont(StandardFonts.TIMES_BOLD, null, "times"); // TODO DEVSIX-2119 Update if necessary // monospace font. shouldn't be selected fontProvider.GetFontSet().AddFont(StandardFonts.COURIER); fontProvider.GetFontSet().AddFont(sourceFolder + "../fonts/FreeSans.ttf", PdfEncodings.IDENTITY_H); fontProvider.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN, null, "times"); // TODO DEVSIX-2119 Update if necessary PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(fontProvider); Paragraph paragraph = new Paragraph("There is no default font (Helvetica) inside the used FontProvider's instance. So the first font, that has been added, should be selected. Here it's FreeSans." ).SetFontFamily("ABRACADABRA_THERE_IS_NO_SUCH_FONT"); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + fileName)); }
public virtual void CustomFontProvider() { String fileName = "customFontProvider.pdf"; String outFileName = destinationFolder + fileName + ".pdf"; String cmpFileName = sourceFolder + "cmp_" + fileName + ".pdf"; FontProvider fontProvider = new FontProvider(); fontProvider.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN, null, "times"); // TODO DEVSIX-2119 Update if necessary fontProvider.GetFontSet().AddFont(StandardFonts.HELVETICA); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(fontProvider); Paragraph paragraph1 = new Paragraph("Default Helvetica should be selected."); doc.Add(paragraph1); Paragraph paragraph2 = new Paragraph("Default Helvetica should be selected.").SetFontFamily(StandardFonts. COURIER); doc.Add(paragraph2); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff" + fileName)); }
public virtual void NonBreakingHyphenDifferentFonts() { //TODO: update after fix of DEVSIX-2034 String outFileName = destinationFolder + "nonBreakingHyphenDifferentFonts.pdf"; String cmpFileName = sourceFolder + "cmp_nonBreakingHyphenDifferentFonts.pdf"; String diffPrefix = "diff01_"; Document document = new Document(new PdfDocument(new PdfWriter(outFileName))); FontProvider sel = new FontProvider(); sel.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN); sel.GetFontSet().AddFont(StandardFonts.COURIER); sel.GetFontSet().AddFont(fontsFolder + "Puritan2.otf", PdfEncodings.IDENTITY_H, "Puritan2"); sel.GetFontSet().AddFont(fontsFolder + "NotoSans-Regular.ttf", PdfEncodings.IDENTITY_H, "NotoSans"); document.SetFontProvider(sel); document.Add(new Paragraph("StandardFonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment( TextAlignment.CENTER)); document.Add(new Paragraph("for Standard font TIMES_ROMAN: <‑> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here " ).SetFont(StandardFonts.TIMES_ROMAN)); document.Add(new Paragraph("for Standard font COURIER: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(StandardFonts.COURIER)); document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD))); document.Add(new Paragraph("for Standard font SYMBOL: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL))); document.Add(new Paragraph("Non-Standard fonts - non-breaking hyphen \\u2011").SetUnderline().SetTextAlignment (TextAlignment.CENTER)); document.Add(new Paragraph("for NotoSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans" )); document.Add(new Paragraph("for Puritan2: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2" )); sel.GetFontSet().AddFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, "FreeSans"); document.Add(new Paragraph("AFTER adding of FreeSans font with non-breaking hyphen \\u2011 support").SetUnderline ().SetTextAlignment(TextAlignment.CENTER)); document.Add(new Paragraph("for Standard font TIMES_ROMAN: <‑> non-breaking hyphen <\u2011> 2 hyphens<\u2011\u2011>here " ).SetFont(StandardFonts.TIMES_ROMAN)); document.Add(new Paragraph("for Standard font COURIER: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(StandardFonts.COURIER)); document.Add(new Paragraph("for Standard font HELVETICA_BOLD: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD))); document.Add(new Paragraph("for Standard font SYMBOL: <‑> non-breaking hyphen<\u2011> 2hyphens <\u2011\u2011>here " ).SetFont(PdfFontFactory.CreateFont(StandardFonts.SYMBOL))); document.Add(new Paragraph("for FreeSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("FreeSans" )); document.Add(new Paragraph("for NotoSans: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("NotoSans" )); document.Add(new Paragraph("for Puritan2: <‑> hyphen<\u2011> 2hyphens <\u2011\u2011>here").SetFont("Puritan2" )); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , diffPrefix)); }
public virtual void LatinAndNotdefGroup() { String outFileName = destinationFolder + "latinAndNotdefGroup.pdf"; String cmpFileName = sourceFolder + "cmp_latinAndNotdefGroup.pdf"; FontProvider sel = new FontProvider(); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "Puritan2.otf")); String s = "Hello мир!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); doc.SetFont("Puritan"); Text text = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY); Paragraph paragraph = new Paragraph(text); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void StandardPdfFonts() { String outFileName = destinationFolder + "standardPdfFonts.pdf"; String cmpFileName = sourceFolder + "cmp_standardPdfFonts.pdf"; FontProvider sel = new FontProvider(); sel.AddStandardPdfFonts(); String s = "Hello world!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); Paragraph paragraph = new Paragraph(s); paragraph.SetFont("Courier"); doc.Add(paragraph); paragraph = new Paragraph(s); paragraph.SetProperty(Property.FONT, "Times-Roman"); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void CyrillicAndLatinGroup2() { String outFileName = destinationFolder + "cyrillicAndLatinGroup2.pdf"; String cmpFileName = sourceFolder + "cmp_cyrillicAndLatinGroup2.pdf"; FontProvider sel = new FontProvider(); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "Puritan2.otf")); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "NotoSans-Regular.ttf")); NUnit.Framework.Assert.IsTrue(sel.AddFont(fontsFolder + "FreeSans.ttf")); String s = "Hello world! Здравствуй мир! Hello world! Здравствуй мир!"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); doc.SetFont("'Puritan', \"FreeSans\""); Text text = new Text(s).SetBackgroundColor(ColorConstants.LIGHT_GRAY); Paragraph paragraph = new Paragraph(text); doc.Add(paragraph); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void CustomFontWeight2() { String outFileName = destinationFolder + "customFontWeight2.pdf"; String cmpFileName = sourceFolder + "cmp_customFontWeight2.pdf"; FontProvider sel = new FontProvider(); sel.GetFontSet().AddFont(StandardFonts.HELVETICA); sel.GetFontSet().AddFont(StandardFonts.HELVETICA_BOLD); sel.GetFontSet().AddFont(StandardFonts.TIMES_ROMAN); //sel.getFontSet().addFont(FontConstants.TIMES_BOLD); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(new FileStream(outFileName, FileMode.Create))); Document doc = new Document(pdfDoc); doc.SetFontProvider(sel); Div div = new Div().SetFont(StandardFonts.TIMES_ROMAN); Paragraph paragraph = new Paragraph("Times Roman Bold text"); paragraph.SetProperty(Property.FONT_WEIGHT, "bold"); div.Add(paragraph); doc.Add(div); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }