Example #1
0
 static Color ParserColorName(string name, int startpos, Color c)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(c);
     }
     if (name[startpos] == '#')
     {
         return(Tools.ParseColor(name, startpos + 1, c));
     }
     else
     {
         return(ColorConst.Get(startpos == 0 ? name : name.Substring(startpos), c));
     }
 }
Example #2
0
        static public Color ParserColorName(string text, ref int startpos, Color dc)
        {
            if (startpos >= text.Length - 1)
            {
                return(dc);
            }

            if (text[startpos + 1] == '[')
            {
                int endpos = text.IndexOf(']', startpos + 1);
                if (endpos != -1)
                {
                    string name = text.Substring(startpos + 2, endpos - startpos - 2);
                    startpos = endpos + 1;
                    return(ColorConst.Get(name, dc));
                }

                ++startpos;
                return(dc);
            }
            else
            {
                // c,后面接的字符定义为字体的颜色,如果后面字符不是数字,则颜色恢复为默认的颜色,最多六个数字
                int start_color  = ++startpos;
                int color_lenght = 0;
                int lenght       = text.Length;
                while (lenght > (startpos + color_lenght) && IsHexadecimal(text[startpos + color_lenght]) && color_lenght < 8)
                {
                    ++color_lenght;
                }

                Color newCol;
                if (ParseColor(text.Substring(start_color, color_lenght), 0, out newCol))
                {
                    startpos += color_lenght;
                    return(newCol);
                }
                else
                {
                    startpos += color_lenght;
                    return(dc);
                }
            }
        }