Esempio n. 1
0
        public void Dictionary()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(String)
            //ExFor:Hyphenation.RegisterDictionary(String, String)
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to perform and verify hyphenation dictionary registration.
            // Register a dictionary file from the local file system to the "de-CH" locale
            Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic");

            // This method can be used to verify that a language has a matching registered hyphenation dictionary
            Assert.True(Hyphenation.IsDictionaryRegistered("de-CH"));

            // The dictionary file contains a long list of words in a specified language, and in this case it is German
            // These words define a set of rules for hyphenating text (splitting words across lines)
            // If we open a document with text of a language matching that of a registered dictionary,
            // that dictionary's hyphenation rules will be applied and visible upon saving
            Document doc = new Document(MyDir + "German text.docx");

            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");

            // We can also un-register a dictionary to disable these effects on any documents opened after the operation
            Hyphenation.UnregisterDictionary("de-CH");

            Assert.False(Hyphenation.IsDictionaryRegistered("de-CH"));

            doc = new Document(MyDir + "German text.docx");
            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            //ExEnd
        }
Esempio n. 2
0
        public void Dictionary()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(String)
            //ExFor:Hyphenation.RegisterDictionary(String, String)
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to register a hyphenation dictionary.
            // A hyphenation dictionary contains a list of strings that define hyphenation rules for the dictionary's language.
            // When a document contains lines of text in which a word could be split up and continued on the next line,
            // hyphenation will look through the dictionary's list of strings for that word's substrings.
            // If the dictionary contains a substring, then hyphenation will split the word across two lines
            // by the substring, and add a hyphen to the first half.
            // Register a dictionary file from the local file system to the "de-CH" locale.
            Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic");

            Assert.True(Hyphenation.IsDictionaryRegistered("de-CH"));

            // Open a document containing text with a locale matching that of our dictionary,
            // and save it to a fixed-page save format. The text in that document will be hyphenated.
            Document doc = new Document(MyDir + "German text.docx");

            Assert.True(doc.FirstSection.Body.FirstParagraph.Runs.OfType <Run>().All(
                            r => r.Font.LocaleId == new CultureInfo("de-CH").LCID));

            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");

            // Re-load the document after un-registering the dictionary,
            // and save it to another PDF, which will not have hyphenated text.
            Hyphenation.UnregisterDictionary("de-CH");

            Assert.False(Hyphenation.IsDictionaryRegistered("de-CH"));

            doc = new Document(MyDir + "German text.docx");
            doc.Save(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            //ExEnd

#if NET462 || NETCOREAPP2_1 || JAVA
            Aspose.Pdf.Document pdfDoc       = new Aspose.Pdf.Document(ArtifactsDir + "Hyphenation.Dictionary.Registered.pdf");
            TextAbsorber        textAbsorber = new TextAbsorber();
            textAbsorber.Visit(pdfDoc);

            Assert.True(textAbsorber.Text.Contains("La ob storen an deinen am sachen. Dop-\r\n" +
                                                   "pelte  um  da  am  spateren  verlogen  ge-\r\n" +
                                                   "kommen  achtzehn  blaulich."));

            pdfDoc       = new Aspose.Pdf.Document(ArtifactsDir + "Hyphenation.Dictionary.Unregistered.pdf");
            textAbsorber = new TextAbsorber();
            textAbsorber.Visit(pdfDoc);

            Assert.True(textAbsorber.Text.Contains("La  ob  storen  an  deinen  am  sachen. \r\n" +
                                                   "Doppelte  um  da  am  spateren  verlogen \r\n" +
                                                   "gekommen  achtzehn  blaulich."));
#endif
        }
        public void IsDictionaryRegisteredEx()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(String)
            //ExSummary:Shows how to open check if some dictionary is registered.
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Assert.AreEqual(true, Hyphenation.IsDictionaryRegistered("en-US"));
            //ExEnd
        }
        public void IsDictionaryRegisteredEx()
        {
            //ExStart
            //ExFor:Hyphenation.IsDictionaryRegistered(string)
            //ExSummary:Shows how to open check if some dictionary is registered.
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Console.WriteLine(Hyphenation.IsDictionaryRegistered("en-US")); // True
            //ExEnd
        }
        public void UnregisteredDictionaryEx()
        {
            //ExStart
            //ExFor:Hyphenation.UnregisterDictionary(String)
            //ExSummary:Shows how to un-register a dictionary.
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Hyphenation.UnregisterDictionary("en-US");

            Assert.AreEqual(false, Hyphenation.IsDictionaryRegistered("en-US"));
            //ExEnd
        }
        public void UnregisterDictionaryEx()
        {
            //ExStart
            //ExFor:Hyphenation.UnregisterDictionary(string)
            //ExSummary:Shows how to un-register a dictionary
            Document doc = new Document(MyDir + "Document.doc");

            Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic");

            Hyphenation.UnregisterDictionary("en-US");

            Console.WriteLine(Hyphenation.IsDictionaryRegistered("en-US")); // False
            //ExEnd
        }
Esempio n. 7
0
            public void RequestDictionary(string language)
            {
                Console.Write("Hyphenation dictionary requested: " + language);

                if (Hyphenation.IsDictionaryRegistered(language))
                {
                    Console.WriteLine(", is already registered.");
                    return;
                }

                if (mHyphenationDictionaryFiles.ContainsKey(language))
                {
                    Hyphenation.RegisterDictionary(language, mHyphenationDictionaryFiles[language]);
                    Console.WriteLine(", successfully registered.");
                    return;
                }

                Console.WriteLine(", no respective dictionary file known by this Callback.");
            }
Esempio n. 8
0
        public void SuppressHyphens(bool suppressAutoHyphens)
        {
            //ExStart
            //ExFor:ParagraphFormat.SuppressAutoHyphens
            //ExSummary:Shows how to suppress hyphenation for a paragraph.
            Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic");

            Assert.True(Hyphenation.IsDictionaryRegistered("de-CH"));

            // Open a document containing text with a locale matching that of our dictionary.
            // When we save this document to a fixed page save format, its text will have hyphenation.
            Document doc = new Document(MyDir + "German text.docx");

            // We can set the "SuppressAutoHyphens" property to "true" to disable hyphenation
            // for a specific paragraph while keeping it enabled for the rest of the document.
            // The default value for this property is "false",
            // which means every paragraph by default uses hyphenation if any is available.
            doc.FirstSection.Body.FirstParagraph.ParagraphFormat.SuppressAutoHyphens = suppressAutoHyphens;

            doc.Save(ArtifactsDir + "ParagraphFormat.SuppressHyphens.pdf");
            //ExEnd

#if NET462 || NETCOREAPP2_1 || JAVA
            Aspose.Pdf.Document pdfDoc       = new Aspose.Pdf.Document(ArtifactsDir + "ParagraphFormat.SuppressHyphens.pdf");
            TextAbsorber        textAbsorber = new TextAbsorber();
            textAbsorber.Visit(pdfDoc);

            if (suppressAutoHyphens)
            {
                Assert.True(textAbsorber.Text.Contains("La  ob  storen  an  deinen  am  sachen. \r\n" +
                                                       "Doppelte  um  da  am  spateren  verlogen \r\n" +
                                                       "gekommen  achtzehn  blaulich."));
            }
            else
            {
                Assert.True(textAbsorber.Text.Contains("La ob storen an deinen am sachen. Dop-\r\n" +
                                                       "pelte  um  da  am  spateren  verlogen  ge-\r\n" +
                                                       "kommen  achtzehn  blaulich."));
            }
#endif
        }