Пример #1
0
        /// <summary>
        /// Add a highlighting theme into the collection
        /// of highlighting themes stored in this object.
        /// </summary>
        /// <param name="styleName"></param>
        /// <param name="highlightingTheme"></param>
        public void AddTheme(string styleName, HighlightingTheme highlightingTheme)
        {
            if (this.mHlThemes == null)
            {
                this.mHlThemes = new Dictionary <string, HighlightingTheme>();
            }

            this.mHlThemes.Add(styleName, highlightingTheme);
        }
Пример #2
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>");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Add a highlighting theme into the collection
        /// of highlighting themes stored in this object.
        /// </summary>
        /// <param name="styleName"></param>
        /// <param name="highlightingTheme"></param>
        public void AddTheme(string styleName, HighlightingTheme highlightingTheme)
        {
            if (this.mHlThemes == null)
            this.mHlThemes = new Dictionary<string, HighlightingTheme>();

              this.mHlThemes.Add(styleName, highlightingTheme);
        }
Пример #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);
            }
        }
Пример #5
0
        /// <summary>
        /// Read the LexerType XML tag with its attributes (if any) and return
        /// a resulting <seealso cref="HighlightingTheme"/> object.
        /// </summary>
        internal static HighlightingTheme ReadNode(XmlReader reader)
        {
            HighlightingTheme hlTheme = null;

              string name = string.Empty;
              string desc = string.Empty;

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

              case XMLNameSpace:
            break;

              case ReadLexerType.attr_desc:
            desc = (reader.Value == null ? string.Empty : reader.Value);
            break;
            }
              }

              hlTheme = new HighlightingTheme(name);
              hlTheme.HlDesc = desc;

              while (reader.Read())
              {
            if (reader.IsStartElement() == true)
            {
              switch (reader.Name)
              {
            case ReadWordsStyle.XMLName:
              WordsStyle t = ReadWordsStyle.ReadNode(reader.ReadSubtree());

              hlTheme.AddWordStyle(t.Name, t);
              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;
              }
            }
              }

              return hlTheme;
        }