Ejemplo n.º 1
0
        [Test] //ExSkip
        public void RegisterDictionary()
        {
            // Set up a callback that tracks warnings that occur during hyphenation dictionary registration
            WarningInfoCollection warningInfoCollection = new WarningInfoCollection();

            Hyphenation.WarningCallback = warningInfoCollection;

            // Register an English (US) hyphenation dictionary by stream
            Stream dictionaryStream = new FileStream(MyDir + "hyph_en_US.dic", FileMode.Open, FileAccess.Read);

            Hyphenation.RegisterDictionary("en-US", dictionaryStream);

            // No warnings detected
            Assert.AreEqual(0, warningInfoCollection.Count);

            // Open a document with a German locale that might not get automatically hyphenated by Microsoft Word an english machine
            Document doc = new Document(MyDir + "German text.docx");

            // To hyphenate that document upon saving, we need a hyphenation dictionary for the "de-CH" language code
            // This callback will handle the automatic request for that dictionary
            Hyphenation.Callback = new CustomHyphenationDictionaryRegister();

            // When we save the document, it will be hyphenated according to rules defined by the dictionary known by our callback
            doc.Save(ArtifactsDir + "Hyphenation.RegisterDictionary.pdf");

            // This dictionary contains two identical patterns, which will trigger a warning
            Assert.AreEqual(1, warningInfoCollection.Count);
            Assert.AreEqual(WarningType.MinorFormattingLoss, warningInfoCollection[0].WarningType);
            Assert.AreEqual(WarningSource.Layout, warningInfoCollection[0].Source);
            Assert.AreEqual("Hyphenation dictionary contains duplicate patterns. The only first found pattern will be used. " +
                            "Content can be wrapped differently.", warningInfoCollection[0].Description);
        }
        public void GetEnumeratorEx()
        {
            //ExStart
            //ExFor:WarningInfoCollection.GetEnumerator
            //ExFor:WarningInfoCollection.Clear
            //ExSummary:Shows how to read and clear a collection of warnings.
            WarningInfoCollection wic = new WarningInfoCollection();

            var enumerator = wic.GetEnumerator();
            while (enumerator.MoveNext())
            {
                WarningInfo wi = (WarningInfo)enumerator.Current;
                Console.WriteLine(wi.Description);
            }

            wic.Clear();
            //ExEnd
        }
Ejemplo n.º 3
0
        private static void UseWarningSourceMarkdown(string dataDir)
        {
            // ExStart: UseWarningSourceMarkdown
            Document doc = new Document(dataDir + "input.docx");

            WarningInfoCollection warnings = new WarningInfoCollection();

            doc.WarningCallback = warnings;
            doc.Save(dataDir + "output.md");

            foreach (WarningInfo warningInfo in warnings)
            {
                if (warningInfo.Source == WarningSource.Markdown)
                {
                    Console.WriteLine(warningInfo.Description);
                }
            }
            // ExEnd: UseWarningSourceMarkdown
        }
        public void GetEnumeratorEx()
        {
            //ExStart
            //ExFor:WarningInfoCollection.GetEnumerator
            //ExFor:WarningInfoCollection.Clear
            //ExSummary:Shows how to read and clear a collection of warnings.
            WarningInfoCollection wic = new WarningInfoCollection();

            var enumerator = wic.GetEnumerator();

            while (enumerator.MoveNext())
            {
                WarningInfo wi = (WarningInfo)enumerator.Current;
                Console.WriteLine(wi.Description);
            }

            wic.Clear();
            //ExEnd
        }
Ejemplo n.º 5
0
        public void UseWarningSource()
        {
            //ExStart:UseWarningSourceMarkdown
            Document doc = new Document(MyDir + "Emphases markdown warning.docx");

            WarningInfoCollection warnings = new WarningInfoCollection();

            doc.WarningCallback = warnings;

            doc.Save(ArtifactsDir + "WorkingWithMarkdown.UseWarningSource.md");

            foreach (WarningInfo warningInfo in warnings)
            {
                if (warningInfo.Source == WarningSource.Markdown)
                {
                    Console.WriteLine(warningInfo.Description);
                }
            }
            //ExEnd:UseWarningSourceMarkdown
        }
Ejemplo n.º 6
0
        public void GetEnumeratorEx()
        {
            //ExStart
            //ExFor:WarningInfoCollection.GetEnumerator
            //ExFor:WarningInfoCollection.Clear
            //ExSummary:Shows how to read and clear a collection of warnings.
            WarningInfoCollection wic = new WarningInfoCollection();

            using (IEnumerator <WarningInfo> enumerator = wic.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    WarningInfo wi = enumerator.Current;
                    if (wi != null)
                    {
                        Console.WriteLine(wi.Description);
                    }
                }

                wic.Clear();
            }
            //ExEnd
        }