public void MinLetterCountDontRaiseExceptionIfNegativeValue()
 {
     var text = @"disciplines";
     var expected = @"dis-ci-plines";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minLetterCount: -1).HyphenateText(text);
     Assert.AreEqual(expected, hyphenateText);
 }
Beispiel #2
0
        public virtual void UriTest01()
        {
            String            outFileName       = destinationFolder + "uriTest01.pdf";
            String            cmpFileName       = sourceFolder + "cmp_uriTest01.pdf";
            PdfDocument       pdfDoc            = new PdfDocument(new PdfWriter(outFileName));
            Document          document          = new Document(pdfDoc, new PageSize(140, 500));
            Hyphenator        hyphenator        = new Hyphenator("en", "en", 3, 3);
            HyphenationConfig hyphenationConfig = new HyphenationConfig(hyphenator);

            document.SetHyphenation(hyphenationConfig);
            Paragraph p = new Paragraph("https://stackoverflow.com/");

            document.Add(p);
            p = new Paragraph("http://stackoverflow.com/");
            document.Add(p);
            p = new Paragraph("m://iiiiiiii.com/");
            document.Add(p);
            document.Add(new AreaBreak());
            p = new Paragraph("https://stackoverflow.com/");
            p.SetHyphenation(null);
            document.Add(p);
            p = new Paragraph("http://stackoverflow.com/");
            p.SetHyphenation(null);
            document.Add(p);
            p = new Paragraph("m://iiiiiiii.com/");
            p.SetHyphenation(null);
            document.Add(p);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
 public void HyphenateText()
 {
     var text = @"The arts are a vast subdivision of culture, composed of many creative endeavors and disciplines. It is a broader term than ""art"", which as a description of a field usually means only the visual arts. The arts encompass the visual arts, the literary arts and the performing arts – music, theatre, dance and film, among others. This list is by no means comprehensive, but only meant to introduce the concept of the arts. For all intents and purposes, the history of the arts begins with the history of art. The arts might have origins in early human evolutionary prehistory. According to a recent suggestion, several forms of audio and visual arts (rhythmic singing and drumming on external objects, dancing, body and face painting) were developed very early in hominid evolution by the forces of natural selection in order to reach an altered state of consciousness. In this state, which Jordania calls battle trance, hominids and early human were losing their individuality, and were acquiring a new collective identity, where they were not feeling fear or pain, and were religiously dedicated to the group interests, in total disregards of their individual safety and life. This state was needed to defend early hominids from predators, and also to help to obtain food by aggressive scavenging. Ritualistic actions involving heavy rhythmic music, rhythmic drill, coupled sometimes with dance and body painting had been universally used in traditional cultures before the hunting or military sessions in order to put them in a specific altered state of consciousness and raise the morale of participants.";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-",hyphenateLastWord:true).HyphenateText(text);
     var expected = @"The arts are a vast sub-di-vi-sion of cul-ture, com-posed of many cre-ative endeavors and dis-ci-plines. It is a broader term than ""art"", which as a descrip-tion of a field usu-ally means only the visual arts. The arts encom-pass the visual arts, the lit-erary arts and the per-forming arts – music, the-atre, dance and film, among others. This list is by no means com-pre-hen-sive, but only meant to intro-duce the con-cept of the arts. For all intents and pur-poses, the his-tory of the arts begins with the his-tory of art. The arts might have ori-gins in early human evo-lu-tionary pre-his-tory. According to a recent sugges-tion, sev-eral forms of audio and visual arts (rhythmic singing and drum-ming on external objects, dancing, body and face painting) were devel-oped very early in hominid evo-lu-tion by the forces of nat-ural selec-tion in order to reach an altered state of con-scious-ness. In this state, which Jor-dania calls battle trance, hominids and early human were losing their indi-vid-u-ality, and were acquiring a new col-lec-tive iden-tity, where they were not feeling fear or pain, and were reli-giously ded-i-cated to the group inter-ests, in total dis-re-gards of their indi-vidual safety and life. This state was needed to defend early hominids from preda-tors, and also to help to obtain food by aggres-sive scavenging. Rit-u-al-istic actions involving heavy rhythmic music, rhythmic drill, cou-pled some-times with dance and body painting had been uni-ver-sally used in tra-di-tional cul-tures before the hunting or mil-i-tary ses-sions in order to put them in a spe-cific altered state of con-scious-ness and raise the morale of par-tic-i-pants.";
     Assert.AreEqual(expected, hyphenateText);
 }
 public void CrashOnExceptionWord()
 {
     var text = @"сегодня";
     var expected = @"се-го-дня";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.Russian, "-", -50).HyphenateText(text);
     Assert.AreEqual(expected, hyphenateText);
 }
 public void HyphenateLastWordOptionTrueTest()
 {
     var text = @".. consciousness and raise the morale of participants.";
     var expected = @".. con-scious-ness and raise the morale of par-tic-i-pants.";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", hyphenateLastWord: true).HyphenateText(text);
     Assert.AreEqual(expected, hyphenateText);
 }
        public void PatternsTest()
        {
            var hyphenator = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "•");

            Assert.AreEqual("sub•di•vi•sion", hyphenator.HyphenateText("subdivision"));
            Assert.AreEqual("cre•ative", hyphenator.HyphenateText("creative"));
            Assert.AreEqual("dis•ci•plines", hyphenator.HyphenateText("disciplines"));
        }
        public void HyphenateLastWordOptionTrueTest()
        {
            var text          = @".. consciousness and raise the morale of participants.";
            var expected      = @".. con-scious-ness and raise the morale of par-tic-i-pants.";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", hyphenateLastWord: true).HyphenateText(text);

            Assert.AreEqual(expected, hyphenateText);
        }
        public void MinLetterCountTest()
        {
            var text          = @"disciplines";
            var expected      = @"disci-plines";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minLetterCount: 4).HyphenateText(text);

            Assert.AreEqual(expected, hyphenateText);
        }
        public void MinLetterCountDontRaiseException()
        {
            var text          = @"disciplines";
            var expected      = @"disciplines";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minLetterCount: 50).HyphenateText(text);

            Assert.Equal(expected, hyphenateText);
        }
        public void CorrectPatternsWithSorting()
        {
            var        text          = "Universitätsstadt";
            Hyphenator hypenator     = new Hyphenator(new FilePatternsLoader("Resources/hyph-de-1996.pat.txt"), "-", sortPatterns: true);
            var        hyphenateText = hypenator.HyphenateText(text);

            Assert.Equal("Uni-ver-si-täts-stadt", hyphenateText);
        }
        public void MinWordLengthDontRaiseExceptionTest()
        {
            var text          = @"disciplines";
            var expected      = @"dis-ci-plines";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minWordLength: -50).HyphenateText(text);

            Assert.Equal(expected, hyphenateText);
        }
        public void MinLetterCountDontRaiseExceptionIfNegativeValue()
        {
            var text          = @"disciplines";
            var expected      = @"dis-ci-plines";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minLetterCount: -1).HyphenateText(text);

            Assert.AreEqual(expected, hyphenateText);
        }
        public void MinWordLengthTest()
        {
            var text          = @"disciplines";
            var expected      = @"disciplines";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minWordLength: 50).HyphenateText(text);

            Assert.AreEqual(expected, hyphenateText);
        }
        public void HyphenateText()
        {
            var text          = @"The arts are a vast subdivision of culture, composed of many creative endeavors and disciplines. It is a broader term than ""art"", which as a description of a field usually means only the visual arts. The arts encompass the visual arts, the literary arts and the performing arts – music, theatre, dance and film, among others. This list is by no means comprehensive, but only meant to introduce the concept of the arts. For all intents and purposes, the history of the arts begins with the history of art. The arts might have origins in early human evolutionary prehistory. According to a recent suggestion, several forms of audio and visual arts (rhythmic singing and drumming on external objects, dancing, body and face painting) were developed very early in hominid evolution by the forces of natural selection in order to reach an altered state of consciousness. In this state, which Jordania calls battle trance, hominids and early human were losing their individuality, and were acquiring a new collective identity, where they were not feeling fear or pain, and were religiously dedicated to the group interests, in total disregards of their individual safety and life. This state was needed to defend early hominids from predators, and also to help to obtain food by aggressive scavenging. Ritualistic actions involving heavy rhythmic music, rhythmic drill, coupled sometimes with dance and body painting had been universally used in traditional cultures before the hunting or military sessions in order to put them in a specific altered state of consciousness and raise the morale of participants.";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", hyphenateLastWord: true, minLetterCount: 3).HyphenateText(text);
            var expected      = @"The arts are a vast sub-di-vi-sion of cul-ture, com-posed of many cre-ative endeav-ors and dis-ci-plines. It is a broader term than ""art"", which as a descrip-tion of a field usu-ally means only the visual arts. The arts encom-pass the visual arts, the lit-er-ary arts and the per-form-ing arts – music, the-atre, dance and film, among others. This list is by no means com-pre-hen-sive, but only meant to intro-duce the con-cept of the arts. For all intents and pur-poses, the his-tory of the arts begins with the his-tory of art. The arts might have ori-gins in early human evo-lu-tion-ary pre-his-tory. Accord-ing to a recent sugges-tion, sev-eral forms of audio and visual arts (rhyth-mic sing-ing and drum-ming on exter-nal objects, danc-ing, body and face paint-ing) were devel-oped very early in hominid evo-lu-tion by the forces of nat-u-ral selec-tion in order to reach an altered state of con-scious-ness. In this state, which Jor-da-nia calls bat-tle trance, hominids and early human were los-ing their indi-vid-u-al-ity, and were acquir-ing a new col-lec-tive iden-tity, where they were not feel-ing fear or pain, and were reli-giously ded-i-cated to the group inter-ests, in total dis-re-gards of their indi-vid-ual safety and life. This state was needed to defend early hominids from preda-tors, and also to help to obtain food by aggres-sive scaveng-ing. Rit-u-al-is-tic actions involv-ing heavy rhyth-mic music, rhyth-mic drill, cou-pled some-times with dance and body paint-ing had been uni-ver-sally used in tra-di-tional cul-tures before the hunt-ing or mil-i-tary ses-sions in order to put them in a spe-cific altered state of con-scious-ness and raise the morale of par-tic-i-pants.";

            Assert.AreEqual(expected, hyphenateText);
        }
        public void DoNotCrashOnRussianWords()
        {
            var text          = @"сегодня";
            var expected      = @"се-го-дня";
            var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.Russian, "-", -50).HyphenateText(text);

            Assert.AreEqual(expected, hyphenateText);
        }
        public void CorrectMinimalLetterCountHandling()
        {
            var        text          = "обработано";
            Hyphenator hypenator     = new Hyphenator(HyphenatePatternsLanguage.Russian, "-", 2, 2);
            var        hyphenateText = hypenator.HyphenateText(text);

            Assert.AreEqual("об-ра-бо-та-но", hyphenateText);
        }
Beispiel #17
0
        public void LoadPatternsTest()
        {
            var loader        = new FilePatternsLoader("./Resources/test_pat.txt");
            var hyphenator    = new Hyphenator(loader, "-");
            var hyphenateText = hyphenator.HyphenateText("перенос");

            Assert.AreEqual("пере-нос", hyphenateText);
        }
        public void LoadingDataByLoader()
        {
            var        text          = "обработано";
            Hyphenator hypenator     = new Hyphenator(new ResourceHyphenatePatternsLoader(HyphenatePatternsLanguage.Russian), "-", 2, 2);
            var        hyphenateText = hypenator.HyphenateText(text);

            Assert.AreEqual("об-ра-бо-та-но", hyphenateText);
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            var wordnet = new WordnetDictionary(
                "/media/milleniumbug/stuff/asdf/english_resources/english-wordnet-2020.xml",
                "/media/milleniumbug/stuff/asdf/english_resources/wordnet.cache");

            var latin1          = Encoding.GetEncoding("iso-8859-1");
            var hyphenationList = HyphenationFileReader.ReadFromFile("/home/milleniumbug/dokumenty/asdf/english_resources/delphiforfun/Syllables.txt", ((char)183).ToString(), latin1)
                                  .Concat(HyphenationFileReader.ReadFromFile("/home/milleniumbug/dokumenty/asdf/english_resources/delphiforfun/SyllablesUpdate.txt", " ", latin1))
                                  .OrderBy(hyphentationInfo => hyphentationInfo.Word, StringComparer.InvariantCulture)
                                  .ToList();
            string?line;

            var        loader    = new ResourceHyphenatePatternsLoader(HyphenatePatternsLanguage.EnglishUs);
            Hyphenator hypenator = new Hyphenator(loader, "-");

            while (true)
            {
                Console.Write("> ");
                line = Console.ReadLine();
                if (line == null)
                {
                    break;
                }

                var resultOpt = BinarySearch(
                    hyphenationList,
                    (list, index) => list[index],
                    hyphenationList.Count,
                    line,
                    info => info.Word,
                    StringComparer.InvariantCulture);
                resultOpt.Match(result =>
                {
                    Console.WriteLine(string.Join("-", result.element.Syllables));
                },
                                () =>
                {
                    Console.WriteLine("fall back to generic hyphenator");
                    Console.WriteLine(hypenator.HyphenateText(line));
                });
                var lookupResult = wordnet.Lookup(line);
                foreach (var entry in lookupResult)
                {
                    Console.WriteLine($"{line} ({entry.PartOfSpeech})");
                    foreach (var definition in entry.Definition)
                    {
                        Console.WriteLine(definition);
                    }

                    foreach (var example in entry.Examples)
                    {
                        Console.WriteLine($"- {example}");
                    }
                }
            }
        }
        public void ThrowExceptionWhenEmptyPatterns()
        {
            var loader = new Mock <IHyphenatePatternsLoader>();

            loader.Setup(x => x.LoadPatterns()).Returns((string)null);
            Assert.Throws <ArgumentException>(() =>
            {
                var hyphenator = new Hyphenator(loader.Object, "-");
            });
        }
Beispiel #21
0
        public Hyphenator GetHyphenator()
        {
            if (hyphenator != null)
            {
                return(hyphenator);
            }

            lock (this)
            {
                return(hyphenator = Hyphenator.FromCulture(ToString()));
            }
        }
        public void LoadingDataByLoaderWithoutExceptions()
        {
            var text   = "автобиография";
            var loader = new Mock <IHyphenatePatternsLoader>();

            loader.Setup(x => x.LoadPatterns())
            .Returns(@"
3био
                ");
            loader.Setup(x => x.LoadExceptions()).Returns((string)null);
            Hyphenator hypenator     = new Hyphenator(loader.Object, "-", 0, 0);
            var        hyphenateText = hypenator.HyphenateText(text);

            Assert.AreEqual("авто-биография", hyphenateText);
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            //a simple test since I cannot run tests due to this http://stackoverflow.com/questions/43494462/why-test-explorer-doesnt-see-my-nunit-tests-for-asp-net-core-mvc
            var hyphenatorEn = new Hyphenator(HyphenatePatternsLanguage.EnglishBritish, hyphenateSymbol: "-", hyphenateLastWord: true);
            var hyphenatorDe = new Hyphenator(HyphenatePatternsLanguage.German, hyphenateSymbol: "-", hyphenateLastWord: true);
            var hyphenatorEs = new Hyphenator(HyphenatePatternsLanguage.Spanish, hyphenateSymbol: "-", hyphenateLastWord: true);

            var en = hyphenatorEn.HyphenateText("Discuss social networking");
            var de = hyphenatorDe.HyphenateText("Jemanden begrüßen und sich vorstellen");
            var es = hyphenatorEs.HyphenateText("Llamar a una persona por teléfono");

            Console.WriteLine(en);
            Console.WriteLine(de);
            Console.WriteLine(es);
            Console.ReadKey();
        }
        protected void _TestHyphenate <T>
        (
            string word,
            string expected
        )
            where T : Hyphenator, new()
        {
            Hyphenator hyphenator = new T();

            int[]  positions = hyphenator.Hyphenate(word);
            string actual    = Hyphenator.ShowHyphenated
                               (
                word,
                positions
                               );

            Assert.AreEqual(expected, actual);
        }
Beispiel #25
0
        public virtual void ParenthesisTest01()
        {
            String            outFileName       = destinationFolder + "parenthesisTest01.pdf";
            String            cmpFileName       = sourceFolder + "cmp_parenthesisTest01.pdf";
            PdfDocument       pdfDoc            = new PdfDocument(new PdfWriter(outFileName));
            Document          document          = new Document(pdfDoc, new PageSize(300, 500));
            Hyphenator        hyphenator        = new Hyphenator("de", "de", 3, 3);
            HyphenationConfig hyphenationConfig = new HyphenationConfig(hyphenator);

            document.SetHyphenation(hyphenationConfig);
            document.Add(new Paragraph("1                             (((\"|Annuitätendarlehen|\")))"));
            document.Add(new Paragraph("2                              ((\"|Annuitätendarlehen|\"))"));
            document.Add(new Paragraph("3                               (\"|Annuitätendarlehen|\")"));
            document.Add(new Paragraph("4                                \"|Annuitätendarlehen|\""));
            document.Add(new Paragraph("5                                 \"Annuitätendarlehen\""));
            document.Add(new Paragraph("6                                      Annuitätendarlehen"));
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Beispiel #26
0
        public void Test()
        {
            var text        = @"The arts are a vast subdivision of culture, composed of many creative endeavors and disciplines. It is a broader term than ""art"", which as a description of a field usually means only the visual arts. The arts encompass the visual arts, the literary arts and the performing arts – music, theatre, dance and film, among others. This list is by no means comprehensive, but only meant to introduce the concept of the arts. For all intents and purposes, the history of the arts begins with the history of art. The arts might have origins in early human evolutionary prehistory. According to a recent suggestion, several forms of audio and visual arts (rhythmic singing and drumming on external objects, dancing, body and face painting) were developed very early in hominid evolution by the forces of natural selection in order to reach an altered state of consciousness. In this state, which Jordania calls battle trance, hominids and early human were losing their individuality, and were acquiring a new collective identity, where they were not feeling fear or pain, and were religiously dedicated to the group interests, in total disregards of their individual safety and life. This state was needed to defend early hominids from predators, and also to help to obtain food by aggressive scavenging. Ritualistic actions involving heavy rhythmic music, rhythmic drill, coupled sometimes with dance and body painting had been universally used in traditional cultures before the hunting or military sessions in order to put them in a specific altered state of consciousness and raise the morale of participants.";
            var hyphenator  = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-");
            var stopWatches = new List <long>();

            for (int i = 0; i < 200; i++)
            {
                var startNew = Stopwatch.StartNew();
                hyphenator.HyphenateText(text);
                startNew.Stop();

                if (i > 10)
                {
                    stopWatches.Add(startNew.ElapsedMilliseconds);
                }
            }

            var avg  = stopWatches.Average();
            var disp = stopWatches.Select(x => Math.Abs(avg - x)).Max();

            Console.WriteLine("{0} ± {1}", avg, disp);
        }
        private void ManipulatePdf(string dest)
        {
            // See hyphenation example of specified word in console
            // For the correct run of sample, please, add an itext.hyph dependency,
            // which could be found on the following web-page: https://mvnrepository.com/artifact/com.itextpdf/hyph
            Hyphenation s = Hyphenator.Hyphenate("de", "DE", "Leistungsscheinziffer", 2, 2);

            Console.Out.WriteLine(s);

            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            doc.SetMargins(0, 0, 0, 0);

            Table table = new Table(UnitValue.CreatePercentArray(1)).SetFixedLayout();

            table.SetWidth(UnitValue.CreatePercentValue(10));

            Text text = new Text("Leistungsscheinziffer");

            text.SetHyphenation(new HyphenationConfig("de", "DE", 2, 2));
            table.AddCell(new Cell().Add(new Paragraph(text)));

            Paragraph paragraph = new Paragraph();

            paragraph.SetHyphenation(new HyphenationConfig("de", "DE", 2, 2));
            paragraph.Add("Leistungsscheinziffer");
            table.AddCell(new Cell().Add(paragraph));

            // soft hyphens
            table.AddCell(new Cell().Add(new Paragraph("Le\u00adistun\u00ADgssch\u00ADeinziffe\u00ADr").SetHyphenation
                                             (new HyphenationConfig(3, 2))));

            doc.Add(table);

            doc.Close();
        }
Beispiel #28
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage:\n\thyphenator \"path\\to\\file.txt\"");
                return;
            }

            var opts        = new ResourceHyphenatePatternsLoader(HyphenatePatternsLanguage.EnglishUs);
            var nhyphenator = new Hyphenator(opts, "-");

            try
            {
                var lines = File.ReadAllLines(args[0]);
                foreach (var line in lines)
                {
                    Console.WriteLine(nhyphenator.HyphenateText(line));
                }
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"Could not find {args[0]}. Check the file path.");
            }
        }
Beispiel #29
0
        public void TestWord()
        {
            var hyphenator  = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-");
            var stopWatches = new List <long>();

            for (int i = 0; i < 1000; i++)
            {
                var startNew = Stopwatch.StartNew();
                hyphenator.HyphenateText("subdivision");
                hyphenator.HyphenateText("creative");
                hyphenator.HyphenateText("disciplines");
                startNew.Stop();

                if (i > 2)
                {
                    stopWatches.Add(startNew.ElapsedMilliseconds);
                }
            }

            var avg  = stopWatches.Average();
            var disp = stopWatches.Select(x => Math.Abs(avg - x)).Max();

            Console.WriteLine("{0} ± {1}", avg, disp);
        }
Beispiel #30
0
 /** Creates a new hyphenation instance usable in <CODE>Chunk</CODE>.
  * @param lang the language ("en" for english, for example)
  * @param country the country ("GB" for Great-Britain or "none" for no country, for example)
  * @param leftMin the minimun number of letters before the hyphen
  * @param rightMin the minimun number of letters after the hyphen
  */
 public HyphenationAuto(string lang, string country, int leftMin, int rightMin)
 {
     hyphenator = new Hyphenator(lang, country, leftMin, rightMin);
 }
 public void ChangeSymbolTest()
 {
     var hyphenator1 = new Hyphenator(HyphenatePatternsLanguage.EnglishUs);
     Assert.AreEqual("dis&shy;ci&shy;plines", hyphenator1.HyphenateText("disciplines"));
 }
 public void MinLetterCountTest()
 {
     var text = @"disciplines";
     var expected = @"disci-plines";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minLetterCount: 4).HyphenateText(text);
     Assert.AreEqual(expected, hyphenateText);
 }
        public void ChangeSymbolTest()
        {
            var hyphenator1 = new Hyphenator(HyphenatePatternsLanguage.EnglishUs);

            Assert.AreEqual("dis&shy;ci&shy;plines", hyphenator1.HyphenateText("disciplines"));
        }
        public void ExceptionTest()
        {
            var hyphenator = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "•");

            Assert.AreEqual("phil•an•thropic", hyphenator.HyphenateText("philanthropic"));
        }
 public void MinWordLengthDontRaiseExceptionTest()
 {
     var text = @"disciplines";
     var expected = @"dis-ci-plines";
     var hyphenateText = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-", minWordLength:-50).HyphenateText(text);
     Assert.AreEqual(expected, hyphenateText);
 }
Beispiel #36
0
        private List <string> WrapText(string text, double pixels, string fontFamily,
                                       float emSize)
        {
            Hyphenator hyphenator = new Hyphenator(HyphenatePatternsLanguage.EnglishUs, "-");

            string[] originalLines = text.Split(new string[] { " " },
                                                StringSplitOptions.None);

            List <string> wrappedLines = new List <string>();

            StringBuilder actualLine  = new StringBuilder();
            double        actualWidth = 0;

            foreach (var itm in originalLines)
            {
                var item = itm;
                actualWidth = MeasureString(GetVisibleString(actualLine.ToString() + item));

                if (actualWidth > pixels)
                {
                    if (!item.Contains("-"))
                    {
                        // Okay, we have something that's too long. Let's try to hyphenate it.
                        var      result = hyphenator.HyphenateText(item);
                        string[] parts  = result.Split(new string[] { "-" }, StringSplitOptions.None);

                        for (int i = parts.Length - 1; i > 0; i--)
                        {
                            var right = parts[i];
                            var left  = "";
                            for (int j = 0; j < i; j++)
                            {
                                left += parts[j];
                            }
                            left += "-";

                            if (MeasureString(GetVisibleString(actualLine.ToString() + left)) <= pixels)
                            {
                                wrappedLines.Add(actualLine.ToString() + left);
                                actualLine.Clear();

                                item = right;
                                break;
                            }
                        }
                    }

                    if (actualLine.Length > 0)
                    {
                        wrappedLines.Add(actualLine.ToString());
                    }

                    actualLine.Clear();
                    actualLine.Append(item + " ");
                    actualWidth = 0;
                }
                else
                {
                    actualLine.Append(item + " ");
                }
            }

            if (actualLine.Length > 0)
            {
                wrappedLines.Add(actualLine.ToString());
            }

            return(wrappedLines);
        }