Example #1
0
        public override void WriteXml(XmlWriter writer)
        {
            TypeConverter colorConverter = TypeDescriptor.GetConverter(typeof(Color));

            base.WriteXml(writer);
            writer.WriteElementString("KnobImage", KnobImage);
            writer.WriteStartElement("Positions");
            foreach (RotarySwitchPosition position in Positions)
            {
                writer.WriteStartElement("Position");
                writer.WriteAttributeString("Name", position.Name);
                writer.WriteAttributeString("Rotation", position.Rotation.ToString(CultureInfo.InvariantCulture));
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteElementString("DefaultPosition", DefaultPosition.ToString(CultureInfo.InvariantCulture));
            if (DrawLines)
            {
                writer.WriteStartElement("Lines");
                writer.WriteElementString("Thickness", LineThickness.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("Length", LineLength.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("Color", colorConverter.ConvertToInvariantString(LineColor));
                writer.WriteEndElement();
            }
            if (DrawLabels)
            {
                writer.WriteStartElement("Labels");
                writer.WriteElementString("Color", colorConverter.ConvertToInvariantString(LabelColor));
                writer.WriteElementString("MaxWidth", MaxLabelWidth.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("MaxHeight", MaxLabelHeight.ToString(CultureInfo.InvariantCulture));
                writer.WriteElementString("Distance", LabelDistance.ToString(CultureInfo.InvariantCulture));
                LabelFormat.WriteXml(writer);
                writer.WriteEndElement();
            }
            writer.WriteStartElement("ClickType");
            writer.WriteElementString("Type", ClickType.ToString());
            if (ClickType == Controls.ClickType.Swipe)
            {
                writer.WriteElementString("Sensitivity", SwipeSensitivity.ToString(CultureInfo.InvariantCulture));
            }
            writer.WriteEndElement();
            writer.WriteElementString("MouseWheel", MouseWheelAction.ToString(CultureInfo.InvariantCulture));
        }
Example #2
0
        public void DivideText(out int ParagraphsNoOf, ref List <string> Paragraphs, out int SentencesNoOf, ref List <string> Sentences, ref List <int> SentenceInParagraph, out int LinesNoOf, ref List <string> Lines, out string DebugText, int LineWidth, bool Debug, bool EliminateWhiteSpace, bool SplitHeaders, bool SplitOnColon, bool SplitOnLF)
        {
            int    txtPtr, noOfChars, oldLineLength, LineLength, SentenceLength, ParagraphLength, firstWordPtr, secondWordPtr, firstWordLength, secondWordLength, lineEnd;
            char   currChar, lastChar, nextChar, firstWord1stChr, lastCharInLine;
            string line, newLine, sentence, paragraph, firstWord, secondWord, txtText;
            bool   endOfSentence, endOfParagraph, endOfLine, ItsAList, ListItemEndsWithFullStop, HitAColon, FirstLine, firstWordAllCapitals, delimited, LastLineWasAHeading, SkipNextCharacter, SkipTheFollowingText, WordEndsWithDelimiter, WordEndsWithFullStop, WordIsAInteger, WordIsAHexNumber, WordAllCapitals, Format, HitTextYet, WaitTillAngleDelim;

            DebugText = "";

            // Get the text that were formatting

            txtText   = this.TheText;
            noOfChars = txtText.Length;

            // First up ")." is the preferred end of a sentence not ".)" etc

            txtText = txtText.Replace(".)", ").");
            txtText = txtText.Replace("?)", ")?");
            txtText = txtText.Replace("!)", ")!");
            txtText = txtText.Replace(".}", "}.");
            txtText = txtText.Replace("?}", "}?");
            txtText = txtText.Replace("!}", "}!");
            txtText = txtText.Replace(".]", "].");
            txtText = txtText.Replace("?]", "]?");
            txtText = txtText.Replace("!]", "]!");

            // Initial values

            FirstLine                = true;
            endOfLine                = false;
            endOfSentence            = false;
            endOfParagraph           = false;
            HitAColon                = false;
            LastLineWasAHeading      = false;
            ItsAList                 = false;
            ListItemEndsWithFullStop = false;
            Format                = true;
            HitTextYet            = false;
            lastChar              = (Char)10;
            paragraph             = "";
            sentence              = "";
            line                  = "";
            oldLineLength         = 0;
            LineLength            = 0;
            ParagraphsNoOf        = 0;
            SentencesNoOf         = 0;
            LinesNoOf             = 0;
            SkipNextCharacter     = false;
            SkipTheFollowingText  = false;
            firstWordPtr          = 0;
            secondWordPtr         = 0;
            firstWordLength       = 0;
            secondWordLength      = 0;
            firstWordAllCapitals  = false;
            delimited             = false;
            WordEndsWithDelimiter = false;
            WordEndsWithFullStop  = false;
            WordIsAInteger        = false;
            WordIsAHexNumber      = false;
            WordAllCapitals       = false;
            SentenceLength        = 0;
            ParagraphLength       = 0;
            WaitTillAngleDelim    = false;
            lastCharInLine        = (Char)10;

            // Each Character one at a time

            for (txtPtr = 0; txtPtr <= noOfChars - 1; txtPtr++)
            {
                currChar = txtText.Substring(txtPtr, 1).ToCharArray()[0];

                // Some of the decisions below need to know what the next char is

                if (txtPtr < noOfChars - 1)
                {
                    nextChar = txtText.Substring(txtPtr + 1, 1).ToCharArray()[0];
                }
                else
                {
                    nextChar = ' ';
                }

                // Is this character a printable character

                if ((int)currChar > 32 && !HitTextYet)
                {
                    HitTextYet = true;
                }

                // Dont format from <~ to ~>

                // Start Formatting Paragraphs && Sentences

                if (lastChar == '~' && currChar == '>')
                {
                    if (Debug)
                    {
                        DebugText += " - Hitting ~> skipping > Format - ";
                    }
                    Format             = true;
                    WaitTillAngleDelim = false;
                    SkipNextCharacter  = true;
                    endOfSentence      = true;
                    HitTextYet         = false;
                    endOfParagraph     = true;
                }

                // Stop Formatting Text into Paragraphs && Sentences however keep Formatting it into Lines as
                // this doesnt actually change the text of the line

                if (lastChar == '<' && currChar == '~')
                {
                    if (Debug)
                    {
                        DebugText += " - Hitting <~ skipping ~ Dont Format - ";
                    }
                    Format             = false;
                    WaitTillAngleDelim = true;
                    SkipNextCharacter  = true;
                    endOfSentence      = true;
                    HitTextYet         = false;
                    endOfParagraph     = true;
                }
                if (currChar == '~' && nextChar == '>')
                {
                    SkipNextCharacter = true;
                    if (Debug)
                    {
                        DebugText += " - Hitting ~> skipping ~ - ";
                    }
                }
                if (currChar == '<' && nextChar == '~')
                {
                    SkipNextCharacter = true;
                    if (Debug)
                    {
                        DebugText += " - Hitting <~ skipping < - ";
                    }
                }

                // Skip Character in these situations

                // Dont include white space if where eliminating white space && the current char is a space &&
                // the last character was a space

                if (EliminateWhiteSpace && currChar == ' ' && lastChar == ' ' && Format)
                {
                    SkipNextCharacter = true;
                    if (Debug)
                    {
                        DebugText += " - skippng white space - ";
                    }
                }

                // if the current character isnt printable skip it, this includes CR && LF

                // if debugging let us know we skipped them

                // Display LF's && CR's when debugging

                if (currChar == (Char)10 && Debug)
                {
                    DebugText += " - chr is line feed - ";
                }
                if (currChar == (Char)13 && Debug)
                {
                    DebugText += " - chr is carriage return - ";
                }

                // We only want to include CR's + LF's when were not formatting + after we've hit the 1st printable character
                // Also dont skip tabs

                if ((int)currChar < 32)
                {
                    if (HitTextYet && !Format)
                    {
                        SkipNextCharacter = false;
                    }
                    else
                    {
                        if (currChar == (Char)9)
                        {
                            SkipNextCharacter = false;
                            // Convert tabs to spaces on list entries
                            if (ItsAList)
                            {
                                currChar = ' ';
                            }
                            if (Debug)
                            {
                                DebugText += " - Hit a Tab - ";
                            }
                        }
                        else
                        {
                            if (currChar == (Char)10)
                            {
                                if (SplitOnLF)
                                {
                                    SkipNextCharacter = false;
                                }
                                else
                                {
                                    SkipNextCharacter = true;
                                    if (Debug)
                                    {
                                        DebugText += " - skippng line feed - ";
                                    }
                                }
                            }
                            if (currChar == (Char)13)
                            {
                                if (SplitOnLF)
                                {
                                    SkipNextCharacter = false;
                                }
                                else
                                {
                                    SkipNextCharacter = true;
                                    if (Debug)
                                    {
                                        DebugText += " - skippng carriage return - ";
                                    }
                                }
                            }
                        }
                    }
                }

                // The characters we want

                if (!SkipNextCharacter)
                {
                    // if (lastChar is LF were now at a new line

                    if (lastChar == (Char)10)
                    {
                        if (Debug)
                        {
                            DebugText += " - hit new line - ";
                        }
                        ItsAList = false;
                        ListItemEndsWithFullStop = false;
                        lineEnd = WheresNextEndOfLine(txtText.Substring(txtPtr));
                        newLine = txtText.Substring(txtPtr, lineEnd + 1);
                        AnalyseFirstWord(newLine, out firstWordPtr, out secondWordPtr, out firstWordLength, out secondWordLength, out firstWordAllCapitals, out delimited);
                        // these are the positions in the whole text not just the next line
                        firstWordPtr   += txtPtr;
                        secondWordPtr  += txtPtr;
                        firstWord1stChr = txtText.Substring(firstWordPtr, 1).ToCharArray()[0];
                        firstWord       = "";
                        if (firstWordLength > 0)
                        {
                            firstWord = txtText.Substring(firstWordPtr, firstWordLength);
                        }
                        secondWord = "";
                        if (secondWordLength > 0)
                        {
                            secondWord = txtText.Substring(secondWordPtr, secondWordLength);
                        }
                        SkipTheFollowingText = DontFormat(firstWord, secondWord);
                        lastCharInLine       = (Char)10;
                        lastCharInLine       = lastNonBlankChar(newLine);
                        AnalyseWord(firstWord, out WordEndsWithDelimiter, out WordEndsWithFullStop, out WordIsAInteger, out WordIsAHexNumber, out WordAllCapitals);
                        if (Debug)
                        {
                            DebugText += " - first word is - " + firstWord.ToString() + " - first word 1st char is - " + firstWord1stChr.ToString() + " ";
                        }
                        if (Format)
                        {
                            // Is It A List
                            if ((firstWord == "•" || firstWord == "o" || firstWord == "-" || firstWord == "v" || firstWord == "*"))
                            {
                                ItsAList = true;
                            }
                            if (WordIsAInteger && WordEndsWithFullStop)
                            {
                                ItsAList = true;
                            }
                            if ((int)firstWord1stChr >= (int)'a' && (int)firstWord1stChr <= (int)'z' && delimited && firstWordLength == 2) // <=== Shouldnt this be 1 need to test!!
                            {
                                ItsAList = true;
                            }
                            if (ItsAList && WordEndsWithFullStop)
                            {
                                ListItemEndsWithFullStop = true;
                            }
                            if (!FirstLine && ItsAList)
                            {
                                endOfParagraph = true;
                                endOfSentence  = true;
                                if (Debug)
                                {
                                    DebugText += " - its a list - ";
                                }
                            }
                            if (!FirstLine && currChar == ':' && (int)lastChar >= (int)'a' && (int)lastChar <= (int)'z' && SplitOnColon)
                            {
                                endOfParagraph = true;
                                endOfSentence  = true;
                                if (Debug)
                                {
                                    DebugText += " - split on colon - ";
                                }
                            }
                            // Is this new line a new paragraph (and hence a new sentence)

                            // Basically its a new paragraph if the 1st char of the 1st word on a new line is a capital

                            // I have added to this but this alone pretty well works in 99% of the cases

                            // The LineWidth stuff isnt being used LineWidth is always 0 but it is still possible to
                            // specify a LineWidth so leaving this in for the time being

                            // HitTextYet is required as we dont want to start a new paragraph until weve reached the
                            // 1st character of the new paragraph

                            // Included " as there were quite a few cases where a new paragraph started with a word in quotes

                            // SkipTheFollowingText is basically checking for code e.g. C#, HTML etc. which is treated
                            // as a new paragraph but isnt formatted, the setting is determined above when we hit a new line

                            if (!FirstLine && HitTextYet &&
                                (oldLineLength + firstWordLength < LineWidth || oldLineLength > LineWidth || LineWidth == 0) &&
                                (((int)firstWord1stChr >= (int)'A' && (int)firstWord1stChr <= (int)'Z') || firstWord1stChr == '"' || SkipTheFollowingText))
                            {
                                endOfParagraph = true;
                                endOfSentence  = true;
                                if (Debug)
                                {
                                    DebugText += " - its a new paragraph - ";
                                }
                                if (SkipTheFollowingText)
                                {
                                    Format = false;
                                    if (Debug)
                                    {
                                        DebugText += " - Dont Format - ";
                                    }
                                }
                            }
                        }
                        // End of if Format, so else is for !Format
                        else if (!WaitTillAngleDelim && !FirstLine && HitTextYet && StartFormatting(firstWord1stChr, lastCharInLine))
                        {
                            Format = true;
                            SkipTheFollowingText = false;
                            endOfSentence        = true;
                            endOfParagraph       = true;
                            if (Debug)
                            {
                                DebugText += " - its a new paragraph (Formatting again) - ";
                            }
                        }
                        if (Debug)
                        {
                            DebugText += " - old line length = " + LineLength.ToString() + " ";
                        }
                        // Next LF wont be on the First Line and becuase lastChar was LF this is the end of a line
                        if (FirstLine)
                        {
                            FirstLine = false;
                        }
                        else
                        {
                            endOfLine     = true;
                            oldLineLength = LineLength;
                        }
                    }

                    // End of Last Char was a LF so we do the following for every character

                    // Start Newline if (we've reached the end of a line

                    if (endOfLine)
                    {
                        endOfLine = false;
                        StartNewLine(ref LinesNoOf, ref Lines, ref line, currChar, ref LineLength, Debug, DebugText);
                    }
                    else
                    {
                        line       += currChar;
                        LineLength += 1;
                    }

                    // Start new Sentence if we've hit a fullstop and we've now hit text following the full stop

                    if (endOfSentence && HitTextYet)
                    {
                        endOfSentence = false;
                        StartNewSentence(ParagraphsNoOf, ref SentencesNoOf, ref Sentences, ref SentenceInParagraph, ref sentence, ref SentenceLength, currChar, Debug, DebugText, Format);
                    }
                    else
                    {
                        if (!endOfSentence)
                        {
                            sentence       += currChar;
                            SentenceLength += 1;
                        }
                    }

                    // Start New Pragraph if we've reached the 1st printable character after the end of the last paragraph

                    if (endOfParagraph && HitTextYet)
                    {
                        endOfParagraph = false;
                        StartNewParagraph(ref ParagraphsNoOf, ref Paragraphs, sentence, ref paragraph, currChar, ref ParagraphLength, Debug, DebugText, Format);
                    }
                    else
                    {
                        paragraph       += currChar;
                        ParagraphLength += 1;
                        if (Debug)
                        {
                            DebugText += currChar;
                        }
                    }

                    // Have we reached the end of a sentence

                    // Basically if we've hit a full stop the next char is a space (or non-printable) and the previous char
                    // was alphanumeric or a closing bracket weve reached the end of a sentence

                    // The one case where this isnt the end of a sentence is the full-stop follows a list item in a
                    // list (i.e. the 1st word in a line is delimited by a fullstop)
                    // so dont indicate its an end of sentence in this case??

                    if (Format && currChar == '.' && (int)nextChar <= 32 &&
                        ((int)lastChar >= (int)'a' && (int)lastChar <= (int)'z' ||
                         (int)lastChar >= (int)'A' && (int)lastChar <= (int)'Z' ||
                         (int)lastChar >= (int)'0' && (int)lastChar <= (int)'9' ||
                         lastChar == '>' ||
                         lastChar == ')' ||
                         lastChar == '}' ||
                         lastChar == ']'))
                    {
                        if (ListItemEndsWithFullStop)
                        {
                            ListItemEndsWithFullStop = false;
                            if (Debug)
                            {
                                DebugText += " - hit full stop but not treating it as an end of sentence - ";
                            }
                        }
                        else
                        {
                            endOfSentence = true;
                            HitTextYet    = false;
                            if (Debug)
                            {
                                DebugText += " - hit full stop at end of sentence - ";
                            }
                        }
                    }
                }

                // End of Dont skip this character

                lastChar          = currChar;
                SkipNextCharacter = false;
            }

            // End of Character Loop i.e. there are no more characters in the text

            if (Debug)
            {
                DebugText += " - Reached the End of the Text - ";
            }

            if (paragraph.Length > 0)
            {
                ParagraphsNoOf += 1;
                Paragraphs.Add(paragraph);
                if (Debug)
                {
                    DebugText += " - Adding Last Paragraph - ";
                }
            }
            if (sentence.Length > 0)
            {
                SentencesNoOf += 1;
                Sentences.Add(sentence);
                SentenceInParagraph.Add(ParagraphsNoOf);
                if (Debug)
                {
                    DebugText += " - Adding Last Sentence - ";
                }
            }
            if (line.Length > 0)
            {
                LinesNoOf += 1;
                Lines.Add(line);
                if (Debug)
                {
                    DebugText += " - Adding Last Line - ";
                }
            }
        }