Exemple #1
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>");
                }
            }
        }
Exemple #2
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);
            }
        }