示例#1
0
        private Dictionary <string, Word> GenarateWordsIndex(Message message, string words)
        {
            MessageIdentity inmessage = new MessageIdentity(message.User, message.ID);

            string[] wordsArray = SplitWords(words);

            int i = 0;   // count of words
            Dictionary <string, Word> wordsIndex = new Dictionary <string, Word>();

            foreach (string key in wordsArray)
            {
                if (!string.IsNullOrEmpty(key))
                {
                    // ### Make sure the Word object is in the index ONCE only
                    if (wordsIndex.ContainsKey(key))
                    {
                        Word theword = (Word)wordsIndex[key];   // get Word from Index, then add this message reference to the Word
                        theword.Add(inmessage, i);
                    }
                    else
                    {
                        Word theword = new Word(key, inmessage, i);     // create a new Word object and add to Index
                        wordsIndex.Add(key, theword);
                    }
                }
                i++;
            }

            return(wordsIndex);
        }
示例#2
0
        public void Return_Anagram_Word_True()
        {
            //Eventual Tests
            Word wordOne = new Word("TestTwo");

            wordOne.Add("Test");
            string amalWord = wordOne.GetWord(0);

            Assert.AreEqual(true, "Test" == amalWord);
        }
示例#3
0
    public Word CreateWord(KeyValuePair <string, string> pair)
    {
        currentWord = pair;
        string w = pair.Key;

        word = new Word();
        for (int i = 0; i < w.Length; i++)
        {
            word.Add(letterSpawner.CreateLetter(w[i]));
        }

        return(word);
    }
示例#4
0
        private MinMax BuildLines(Surface surface, float maxWidth)
        {
            Graphics g        = surface.Graphics;
            Font     font     = surface.Font();
            float    minWidth = float.MaxValue;

            Stack <Font> fontStack = new Stack <Font>();

            lines       = new List <Line>();
            currentLine = new Line(0); // First line is never indented
            spaces      = new Word(font, g);
            word        = new Word(font, g);

            hangingIndent = CalculateIndent(g, font);

            foreach (Node node in childNodes)
            {
                if (node.Type == NodeType.Text)
                {
                    char[] chars = ((TextNode)node).Chars;
                    foreach (char c in chars)
                    {
                        if (c.Equals(SPACE))
                        {
                            if (word.Length > 0)
                            {
                                if (minWidth > word.Length)
                                {
                                    minWidth = word.Length;
                                }
                                FlushWordBuffer(surface, maxWidth);
                                spaces = new Word(font, g);
                                word   = new Word(font, g);
                            }
                            spaces.Add(SPACE);
                        }
                        else
                        {
                            word.Add(c);
                            if (word.Width > maxWidth) // Word is too long for block width
                            {
                                word.Backspace();      // remove c (just added)
                                char lastChar = word.Backspace();
                                word.Add('-');         // replace lastChar with a hyphen
                                FlushWordBuffer(surface, maxWidth);
                                spaces = new Word(font, g);
                                word   = new Word(font, g);
                                word.Add(lastChar); // move lastChar to new word
                                word.Add(c);        // append c to new word
                            }
                        }
                    }
                }
                else if (node.Type == NodeType.TextFormat)
                {
                    FlushWordBuffer(surface, maxWidth);
                    fontStack.Push(font);
                    font   = ModifyFont(surface, font, node.Tag);
                    spaces = new Word(font, g);
                    word   = new Word(font, g);
                }
                else if (node.Type == NodeType.EndTextFormat)
                {
                    FlushWordBuffer(surface, maxWidth);
                    font   = fontStack.Pop();
                    spaces = new Word(font, g);
                    word   = new Word(font, g);
                }
                else if (node.Type == NodeType.Image || node.Type == NodeType.Barcode ||
                         node.Type == NodeType.Table || node.Type == NodeType.Block)
                {
                    if (currentLine.Width > 0)
                    {
                        lines.Add(currentLine);
                    }

                    currentLine = new Line(hangingIndent, node);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            FlushWordBuffer(surface, maxWidth);
            if (currentLine.Width > 0)
            {
                lines.Add(currentLine);
            }

            maxWidth = 0;
            foreach (Line line in lines)
            {
                var lineWidth = line.Width;
                if (maxWidth < lineWidth)
                {
                    maxWidth = lineWidth;
                }
            }
            return(new MinMax(minWidth, maxWidth));
        }