Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the LanguageElement class.
 /// </summary>
 /// <remarks>
 /// Required for the deserialization by the DataContract
 /// </remarks>
 public LanguageElement()
 {
     this.charFormat = new CharacterFormat();
 }
 /// <summary>
 /// Initializes a new instance of the LanguageElement class. 
 /// </summary>
 /// <remarks>
 /// Required for the deserialization by the DataContract
 /// </remarks>
 public LanguageElement()
 {
     this.charFormat = new CharacterFormat();
 }
        /// <summary>
        /// Initializes a new instance of the LanguageElement class. 
        /// </summary>
        /// <param name="name">Name of the language element</param>
        /// <param name="color">The color the element will appear in</param>
        /// <param name="keywords">True if the element is a list of keywords</param>
        /// <param name="mainRegex">The main regex describing the element</param>
        /// <param name="separatorRegex_start">The regex describing what must preceed the element in the text</param>
        /// <param name="separatorRegex_end">The regex describing what must follow the element in the text</param>
        public LanguageElement(string name, Color color, bool keywords, string mainRegex, string separatorRegex_start, string separatorRegex_end)
        {
            this.name = name;
            this.color = color;
            this.keywords = keywords;
            this.mainRegex = mainRegex;
            this.separatorRegex_start = separatorRegex_start;
            this.separatorRegex_end = separatorRegex_end;

            this.charFormat = new CharacterFormat();

            this.Initialize();
        }
        /// <summary>
        /// Colors a range of text in the document with the specified color and character formatting. This is the callback function used by the Colorizer:
        /// Every time it founds a language element that must be colored, it calls back this function, that performs the formatting using the Word API. This way the Word specific code is separated from the syntax processing of the text.
        /// </summary>
        /// <param name="index">The starting position of the range that must be colored (0 is the first character of the selection, that is the text that is colorized)</param>
        /// <param name="length">The length of the range to be colored</param>
        /// <param name="color">Color to use for the range of text</param>
        /// <param name="char_format">Character formatting to use for the range of text</param>
        public void ColorRangeOfText(int index, int length, Color color, CharacterFormat char_format)
        {
            Word.WdColor wd_color = (Word.WdColor)ColorTranslator.ToOle(color);
            if (color.Name == "Control")
                wd_color = Word.WdColor.wdColorAutomatic;

            Word.Range range = wordApp.Selection.Range; //It must look weird, but you have to get an existing Range object first, and then narrow it down. (Range is an abstract class)
            range.SetRange(wordApp.Selection.Start + index, wordApp.Selection.Start + index + length);
            range.Font.Color = wd_color;

            if (char_format.Bold) range.Font.Bold = 1;
            if (char_format.Italic) range.Font.Italic = 1;
            if (char_format.Underlined) range.Font.Underline = Word.WdUnderline.wdUnderlineSingle;
            if (char_format.Capitalletters) range.Font.AllCaps = 1;
        }