Пример #1
0
        public void SetFontSubstitutes()
        {
            //ExStart
            //ExFor:Document.FontSettings
            //ExFor:FontSettings.SetFontSubstitutes(String, String[])
            //ExSummary:Shows how to define alternative fonts if original does not exist
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontSubstitutes("Times New Roman", new String[] { "Slab", "Arvo" });
            //ExEnd
            Document doc = new Document(MyDir + "Rendering.doc");

            doc.FontSettings = fontSettings;

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            //Check that font source are default
            FontSourceBase[] fontSource = doc.FontSettings.GetFontsSources();
            Assert.AreEqual("SystemFonts", fontSource[0].Type.ToString());

            Assert.AreEqual("Times New Roman", doc.FontSettings.DefaultFontName);

            String[] alternativeFonts = doc.FontSettings.GetFontSubstitutes("Times New Roman");
            Assert.AreEqual(new String[] { "Slab", "Arvo" }, alternativeFonts);
        }
Пример #2
0
        public void FontSubstitutionWarnings()
        {
            Document doc = new Document(MyDir + "Rendering.doc");

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            HandleDocumentWarnings callback = new HandleDocumentWarnings();

            doc.WarningCallback = callback;

            FontSettings fontSettings = new FontSettings();

            fontSettings.DefaultFontName = "Arial";
            fontSettings.SetFontSubstitutes("Arial", new string[] { "Arvo", "Slab" });
            fontSettings.SetFontsFolder(MyDir + @"MyFonts\", false);

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Rendering.MissingFontNotification.pdf");

            Assert.True(callback.mFontWarnings[0].Description
                        .Equals("Font substitutes: 'Arial' replaced with 'Arvo'."));
            Assert.True(callback.mFontWarnings[1].Description
                        .Equals(
                            "Font 'Times New Roman' has not been found. Using 'Noticia Text' font instead. Reason: closest match according to font info from the document."));
        }
        public void AddFontSubstitutes()
        {
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontSubstitutes("Slab", new string[] { "Times New Roman", "Arial" });
            fontSettings.AddFontSubstitutes("Arvo", new string[] { "Open Sans", "Arial" });

            Document doc = new Document(MyDir + "Rendering.doc");

            doc.FontSettings = fontSettings;

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            string[] alternativeFonts = doc.FontSettings.GetFontSubstitutes("Slab");
            Assert.AreEqual(new string[] { "Times New Roman", "Arial" }, alternativeFonts);

            alternativeFonts = doc.FontSettings.GetFontSubstitutes("Arvo");
            Assert.AreEqual(new string[] { "Open Sans", "Arial" }, alternativeFonts);
        }
        public void SetFontSubstitutes()
        {
            FontSettings fontSettings = new FontSettings();

            fontSettings.SetFontSubstitutes("Times New Roman", new string[] { "Slab", "Arvo" });

            Document doc = new Document(MyDir + "Rendering.doc");

            doc.FontSettings = fontSettings;

            MemoryStream dstStream = new MemoryStream();

            doc.Save(dstStream, SaveFormat.Docx);

            //Check that font source are default
            FontSourceBase[] fontSource = doc.FontSettings.GetFontsSources();
            Assert.AreEqual("SystemFonts", fontSource[0].Type.ToString());

            Assert.AreEqual("Times New Roman", doc.FontSettings.DefaultFontName);

            string[] alternativeFonts = doc.FontSettings.GetFontSubstitutes("Times New Roman");
            Assert.AreEqual(new string[] { "Slab", "Arvo" }, alternativeFonts);
        }
Пример #5
0
        public void FontSubstitutionWarnings()
        {
            Document doc = new Document(MyDir + "Rendering.doc");

            // Create a new class implementing IWarningCallback and assign it to the PdfSaveOptions class.
            ExRendering.HandleDocumentWarnings callback = new ExRendering.HandleDocumentWarnings();
            doc.WarningCallback = callback;

            FontSettings fontSettings = new FontSettings();
            fontSettings.DefaultFontName = "Arial";
            fontSettings.SetFontSubstitutes("Arial", new string[] { "Arvo", "Slab" });
            fontSettings.SetFontsFolder(MyDir + @"MyFonts\", false);

            doc.FontSettings = fontSettings;

            doc.Save(MyDir + @"\Artifacts\Rendering.MissingFontNotification.pdf");
            
            Assert.True(callback.mFontWarnings[0].Description.Equals("Font substitutes: 'Arial' replaced with 'Arvo'."));
            Assert.True(callback.mFontWarnings[1].Description.Equals("Font 'Times New Roman' has not been found. Using 'Arvo' font instead. Reason: default font setting."));
        }
        public void AddFontSubstitutes()
        {
            FontSettings fontSettings = new FontSettings();
            fontSettings.SetFontSubstitutes("Slab", new string[] { "Times New Roman", "Arial" });
            fontSettings.AddFontSubstitutes("Arvo", new string[] { "Open Sans", "Arial" });
            
            Document doc = new Document(MyDir + "Rendering.doc");
            doc.FontSettings = fontSettings;
            
            MemoryStream dstStream = new MemoryStream();
            doc.Save(dstStream, SaveFormat.Docx);

            string[] alternativeFonts = doc.FontSettings.GetFontSubstitutes("Slab");
            Assert.AreEqual(new string[] { "Times New Roman", "Arial" }, alternativeFonts);

            alternativeFonts = doc.FontSettings.GetFontSubstitutes("Arvo");
            Assert.AreEqual(new string[] { "Open Sans", "Arial" }, alternativeFonts);
        }
        public void SetFontSubstitutes()
        {
            FontSettings fontSettings = new FontSettings();
            fontSettings.SetFontSubstitutes("Times New Roman", new string[] { "Slab", "Arvo" });
            
            Document doc = new Document(MyDir + "Rendering.doc");
            doc.FontSettings = fontSettings;

            MemoryStream dstStream = new MemoryStream();
            doc.Save(dstStream, SaveFormat.Docx);

            //Check that font source are default
            FontSourceBase[] fontSource = doc.FontSettings.GetFontsSources();
            Assert.AreEqual("SystemFonts", fontSource[0].Type.ToString());

            Assert.AreEqual("Times New Roman", doc.FontSettings.DefaultFontName);

            string[] alternativeFonts = doc.FontSettings.GetFontSubstitutes("Times New Roman");
            Assert.AreEqual(new string[] { "Slab", "Arvo" }, alternativeFonts);
        }