/// <summary>
        /// Add another style (foreground color, background color, bold etc...) to the collection
        /// of styles that make up this highlighting theme.
        /// </summary>
        /// <param name="brushName"></param>
        /// <param name="wordStyle">color and brush representation (eg.: "#FF00FFFF" etc)</param>
        public void AddWordStyle(string brushName, WordsStyle wordStyle)
        {
            if (this.mHlThemes == null)
            this.mHlThemes = new Dictionary<string, WordsStyle>();

              this.mHlThemes.Add(brushName, wordStyle);
        }
Esempio n. 2
0
        /// <summary>
        /// Add another style (foreground color, background color, bold etc...) to the collection
        /// of styles that make up this highlighting theme.
        /// </summary>
        /// <param name="brushName"></param>
        /// <param name="wordStyle">color and brush representation (eg.: "#FF00FFFF" etc)</param>
        public void AddWordStyle(string brushName, WordsStyle wordStyle)
        {
            if (this.mHlThemes == null)
            {
                this.mHlThemes = new Dictionary <string, WordsStyle>();
            }

            this.mHlThemes.Add(brushName, wordStyle);
        }
Esempio n. 3
0
        /// <summary>
        /// Print highlighting theme color codes in HTML into the console output
        /// </summary>
        /// <param name="hdef"></param>
        /// <param name="hlThemes"></param>
        public static void PrintThemeToHTML(IHighlightingDefinition hdef,
                                            HighlightingThemes hlThemes)
        {
            if (hdef == null || hlThemes == null)
            {
                return;
            }

            HighlightingTheme theme = hlThemes.FindTheme(hdef.Name); // Is the current highlighting (eg.: HTML) themable?

            if (theme != null)
            {
                if (hdef.NamedHighlightingColors != null)
                {
                    Console.WriteLine("<h2>{0}</h2>\n", theme.HlName);

                    Console.WriteLine("<table>");
                    Console.WriteLine("<tr>");
                    Console.WriteLine("<td>Code</td>");
                    Console.WriteLine("<td width=\"100\">Color</td>");
                    Console.WriteLine("<td>Description</td>");
                    Console.WriteLine("</tr>");

                    // Go through each color definition in the highlighting and apply the theme on each match
                    foreach (HighlightingColor c in hdef.NamedHighlightingColors)
                    {
                        WordsStyle s = theme.GetWordsStyle(c.Name);

                        if (s != null)
                        {
                            if (s.fgColor != null)
                            {
                                Console.WriteLine(string.Format("<tr><td>#{0:x2}{1:x2}{2:x2}</td><td bgColor=\"#{0:x2}{1:x2}{2:x2}\"></td><td>{3}</td></tr>",
                                                                s.fgColor.Color.R,
                                                                s.fgColor.Color.G,
                                                                s.fgColor.Color.B, s.Name));
                            }
                        }
                    }
                    Console.WriteLine("</table>");
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Apply highlighting theme to highlighting pattern definition.
        /// This results in re-defined highlighting colors while keeping
        /// rules for regular expression matching.
        /// </summary>
        /// <param name="hdef">Current highlighting pattern</param>
        /// <param name="hlThemes">Collection of highlighting styles to be applied on current highlighting patterns</param>
        public static void ApplyHighlightingTheme(IHighlightingDefinition hdef,
                                                  HighlightingThemes hlThemes)
        {
            if (hdef == null || hlThemes == null)
            {
                return;
            }

            HighlightingTheme theme = hlThemes.FindTheme(hdef.Name); // Is the current highlighting (eg.: HTML) themable?

            if (theme != null)
            {
                if (hdef.NamedHighlightingColors != null)
                {
                    // Go through each color definition in the highlighting and apply the theme on each match
                    foreach (HighlightingColor c in hdef.NamedHighlightingColors)
                    {
                        WordsStyle s = theme.GetWordsStyle(c.Name);

                        if (s != null)
                        {
                            if (s.bgColor != null)
                            {
                                c.Background = new SimpleHighlightingBrush(s.bgColor);
                            }
                            else
                            {
                                c.Background = null;
                            }

                            if (s.fgColor != null)
                            {
                                c.Foreground = new SimpleHighlightingBrush(s.fgColor);
                            }
                            else
                            {
                                c.Foreground = null;
                            }

                            if (s.fontStyle != null)
                            {
                                c.FontStyle = s.fontStyle;
                            }
                            else
                            {
                                c.FontStyle = null;
                            }

                            if (s.fontWeight != null)
                            {
                                c.FontWeight = s.fontWeight;
                            }
                            else
                            {
                                c.FontStyle = null;
                            }
                        }
                        else
                        {
                            logger.WarnFormat("Named Color: '{0}'in '{1}' does not exist in '{2}'.", c.Name, hdef.Name, hlThemes.FileNamePath);
                        }
                    }
                }
            }
            else
            {
                logger.WarnFormat("highlighting definition: '{0}' does not have a style in '{1}'.", hdef.Name, hlThemes.FileNamePath);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Read the WordsStyle XML tag with its attributes (if any) and return
        /// a resulting <seealso cref="WordsStyle"/> object.
        /// </summary>
        internal static WordsStyle ReadNode(XmlReader reader)
        {
            WordsStyle ret = null;
              FontWeightConverter FontWeightConverter = new FontWeightConverter();
              FontStyleConverter FontStyleConverter = new FontStyleConverter();

              string name = string.Empty;
              string fgColor = string.Empty;
              string bgColor = string.Empty;
              string fontWeight = string.Empty;
              string FontStyle = string.Empty;

              reader.ReadToNextSibling(ReadWordsStyle.XMLName);
              while (reader.MoveToNextAttribute())
              {
            switch (reader.Name)
            {
              case ReadWordsStyle.attr_name:
            name = reader.Value;
            break;

              case ReadWordsStyle.attr_fgColor:
            fgColor = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_bgColor:
            bgColor = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_fontWeight:
            fontWeight = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case ReadWordsStyle.attr_FontStyle:
            FontStyle = (reader.Value == null ? string.Empty : reader.Value);
            break;

              case XMLNameSpace:
            break;

              default:
            if (reader.Name.Trim().Length > 0 && reader.Name != XMLComment)
              logger.Warn("Parsing the XML child:'" + reader.Name + "' of '" + ReadLexerType.XMLName + "' is not implemented.");
              break;
            }
              }

              ret = new WordsStyle(name);

              if (fgColor != string.Empty)
            ret.fgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_fgColor, fgColor);

              if (bgColor != string.Empty)
            ret.bgColor = ReadWordsStyle.SetColorFromString(ReadWordsStyle.attr_bgColor, bgColor);

              if (fontWeight != string.Empty)
            ret.fontWeight = ParseFontWeight(ReadWordsStyle.attr_fontWeight, fontWeight, FontWeightConverter);

              if (FontStyle != string.Empty)
            ret.fontStyle = ParseFontStyle(ReadWordsStyle.attr_FontStyle, FontStyle, FontStyleConverter);

              return ret;
        }