private static void ApplyStyle(Lexer lexerType, SortedDictionary<int, ILexerStyle> styles, Queue<string> keyQueue, string var)
        {
            int styleIndex;
            if (keyQueue.Count == 1)
            {
                string strIndex = keyQueue.Dequeue();
                if (!int.TryParse(strIndex, out styleIndex))
                {
                    if (lexerType != Lexer.Null)
                    {
                        object lexStyle = Enum.Parse(Utilities.GetLexerEnumFromLexerType(lexerType), strIndex, true);
                        styleIndex = (int)lexStyle;
                    }
                    else
                    {
                        styleIndex = 0;
                    }
                }
            }
            else
            {
                styleIndex = 0;
            }

            ILexerStyle style = new LexerStyle(styleIndex);
            string styleData = Evaluate(var);
            Dictionary<string, string> dict = PropertiesReader.GetKeyValuePairs(styleData);
            foreach (string styleKey in dict.Keys)
            {
                styleData = dict[styleKey];
                switch (styleKey)
                {
                    case "font":
                        style.FontName = styleData;
                        break;
                    case "size":
                        style.FontSize = Convert.ToInt32(styleData);
                        break;
                    case "fore":
                        style.ForeColor = ColorTranslator.FromHtml(styleData);
                        break;
                    case "back":
                        style.BackColor = ColorTranslator.FromHtml(styleData);
                        break;
                    case "italics":
                        style.Italics = true;
                        break;
                    case "notitalics":
                        style.Italics = false;
                        break;
                    case "bold":
                        style.Bold = true;
                        break;
                    case "notbold":
                        style.Bold = false;
                        break;
                    case "eolfilled":
                        style.EOLFilled = true;
                        break;
                    case "noteolfilled":
                        style.EOLFilled = false;
                        break;
                    case "underlined":
                        style.Underline = true;
                        break;
                    case "notunderlined":
                        style.Underline = false;
                        break;
                    case "case":
                        style.CaseVisibility = ((styleData == "m") ? CaseVisible.Mixed : ((styleData == "u") ? CaseVisible.Upper : CaseVisible.Lower));
                        break;
                }
            }
            styles[styleIndex] = style;
        }
예제 #2
0
        private static void ApplyStyle(Lexer lexerType, SortedDictionary <int, ILexerStyle> styles, Queue <string> keyQueue, string var)
        {
            int styleIndex;

            if (keyQueue.Count == 1)
            {
                string strIndex = keyQueue.Dequeue();
                if (!int.TryParse(strIndex, out styleIndex))
                {
                    if (lexerType != Lexer.Null)
                    {
                        object lexStyle = Enum.Parse(Utilities.GetLexerEnumFromLexerType(lexerType), strIndex, true);
                        styleIndex = (int)lexStyle;
                    }
                    else
                    {
                        styleIndex = 0;
                    }
                }
            }
            else
            {
                styleIndex = 0;
            }

            ILexerStyle style                = new LexerStyle(styleIndex);
            string      styleData            = Evaluate(var);
            Dictionary <string, string> dict = PropertiesReader.GetKeyValuePairs(styleData);

            foreach (string styleKey in dict.Keys)
            {
                styleData = dict[styleKey];
                switch (styleKey)
                {
                case "font":
                    style.FontName = styleData;
                    break;

                case "size":
                    style.FontSize = Convert.ToInt32(styleData);
                    break;

                case "fore":
                    style.ForeColor = ColorTranslator.FromHtml(styleData);
                    break;

                case "back":
                    style.BackColor = ColorTranslator.FromHtml(styleData);
                    break;

                case "italics":
                    style.Italics = true;
                    break;

                case "notitalics":
                    style.Italics = false;
                    break;

                case "bold":
                    style.Bold = true;
                    break;

                case "notbold":
                    style.Bold = false;
                    break;

                case "eolfilled":
                    style.EOLFilled = true;
                    break;

                case "noteolfilled":
                    style.EOLFilled = false;
                    break;

                case "underlined":
                    style.Underline = true;
                    break;

                case "notunderlined":
                    style.Underline = false;
                    break;

                case "case":
                    style.CaseVisibility = ((styleData == "m") ? CaseVisible.Mixed : ((styleData == "u") ? CaseVisible.Upper : CaseVisible.Lower));
                    break;
                }
            }
            styles[styleIndex] = style;
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        public bool PopulateLexerConfig(ILexerConfig config)
        {
            /*--------------------------------------- styles ---------------------------------------
            The lexers determine a style number for each lexical type, such as keyword, comment or number. These settings 
            determine the visual style to be used for each style number of each lexer.
            The value of each setting is a set of ',' separated fields, some of which have a subvalue after a ':'. The fields 
            are font, size, fore, back, italics, notitalics, bold, notbold, eolfilled, noteolfilled, underlined, 
            notunderlined, and case. The font field has a subvalue which is the name of the font, the fore and back 
            have colour subvalues, the size field has a numeric size subvalue, the case field has a subvalue of 'm', 
            'u', or 'l' for mixed, upper or lower case, and the bold, italics and eolfilled fields have no subvalue. 
            The value "fore:#FF0000,font:Courier,size:14" represents 14 point, red Courier text.
            A global style can be set up using style.*.stylenumber. Any style options set in the global style will be 
            inherited by each lexer style unless overridden.
            ----------------------------------------------------------------------------------------*/
            string key, s, lexer = config.LexerName.ToLower();
            ILexerStyle style;
            bool dataIsFound = false;
            Dictionary<string, string> dict;

            for (int i = 0; i < 128; i++)
            {
                if (config.Styles.ContainsKey(i)) 
                    style = config.Styles[i];
                else 
                    style = new LexerStyle(i);

                dataIsFound = true;
                foreach (string lang in new string[] { "*", lexer })
                {
                    key = string.Format("style.{0}.{1}", lang, i);
                    if (properties.ContainsKey(key))
                    {
                        dataIsFound = true;

                        s = this.Evaluate(properties[key]);
                        dict = PropertiesReader.GetKeyValuePairs(s);
                        foreach (string styleKey in dict.Keys)
                        {
                            s = dict[styleKey];
                            switch (styleKey)
                            {
                                case "font":
                                    style.FontName = s;
                                    break;
                                case "size":
                                    style.FontSize = Convert.ToInt32(s);
                                    break;
                                case "fore":
                                    style.ForeColor = ColorTranslator.FromHtml(s);
                                    break;
                                case "back":
                                    style.BackColor = ColorTranslator.FromHtml(s);
                                    break;
                                case "italics":
                                    style.Italics = true;
                                    break;
                                case "notitalics":
                                    style.Italics = false;
                                    break;
                                case "bold":
                                    style.Bold = true;
                                    break;
                                case "notbold":
                                    style.Bold = false;
                                    break;
                                case "eolfilled":
                                    style.EOLFilled = true;
                                    break;
                                case "noteolfilled":
                                    style.EOLFilled = false;
                                    break;
                                case "underlined":
                                    style.Underline = true;
                                    break;
                                case "notunderlined":
                                    style.Underline = false;
                                    break;
                                case "case":
                                    style.CaseVisibility = ((s == "m") ? CaseVisible.Mixed : ((s == "u") ? CaseVisible.Upper : CaseVisible.Lower));
                                    break;
                            }
                        }
                    }
                }

                if (dataIsFound) config.Styles[i] = style;
            }
            return true;
        }